/* Get radius info */ /* For example, get username for given IP address */ /* Useful for WWW scripts */ /* Original source created by Brian Reed @RRL:19-Jan-1999 Some cosmetic changes for exclude of record locking */ #define INIT_SDESC(dsc, len, ptr) {(dsc).dsc$b_dtype = DSC$K_DTYPE_T;\ (dsc).dsc$b_class = DSC$K_CLASS_S; (dsc).dsc$w_length = (len);\ (dsc).dsc$a_pointer = (ptr);} #include #include #include #include #include #include #include void usage (void) { fprintf (stderr, "Usage: radlookup ip-address\n"); } main ( int argc, char ** argv ) { long status; char rad_stat [] = "RADIUS_CURRENT"; struct FAB sfab; struct RAB srab; char buf[200]; int len; $DESCRIPTOR(dsc$usr_sym, "RADIUS_USERNAME"); $DESCRIPTOR(dsc$usr_val,""); $DESCRIPTOR(dsc$space," "); /* ** First, set symbol to null, meaning failure of any kind */ status = LIB$SET_SYMBOL (&dsc$usr_sym, &dsc$usr_val); if (!$VMS_STATUS_SUCCESS(status)) sys$exit (status); if (argc != 2) { usage (); sys$exit (SS$_NORMAL); } len = strnlen(argv[1],15); sfab = cc$rms_fab; sfab.fab$b_fac = FAB$M_GET; sfab.fab$b_shr = FAB$M_SHRGET | FAB$M_SHRPUT | FAB$M_SHRUPD; sfab.fab$l_fna = rad_stat; sfab.fab$b_fns = sizeof(rad_stat)-1; sfab.fab$l_dna = ".DAT"; sfab.fab$b_dns = 4; sfab.fab$v_nef = sfab.fab$v_sqo = 1; status = sys$open(&sfab); if (!$VMS_STATUS_SUCCESS(status)) sys$exit(status); srab = cc$rms_rab; srab.rab$l_fab = &sfab; status = sys$connect(&srab); if (!$VMS_STATUS_SUCCESS(status)) sys$exit(status); status = sys$rewind(&srab); if (!$VMS_STATUS_SUCCESS(status)) sys$exit(status); srab.rab$b_rac = RAB$C_SEQ; srab.rab$b_tmo = 250; srab.rab$v_wat = srab.rab$v_nlk = srab.rab$v_loc = 1; srab.rab$l_ubf = buf; srab.rab$w_usz = sizeof(buf); while ( 1 & (status = sys$get(&srab)) ) { if ( !memcmp (srab.rab$l_rbf+67,argv[1],len) ) { int pos; INIT_SDESC(dsc$usr_val,12,srab.rab$l_rbf+54); if ( len = lib$index (&dsc$usr_val,&dsc$space) ) dsc$usr_val.dsc$w_length = len; dsc$usr_val.dsc$w_length--; status = lib$set_symbol (&dsc$usr_sym,&dsc$usr_val); if (!$VMS_STATUS_SUCCESS(status)) sys$exit(status); break; } } if ( !(1 & status) && (status != RMS$_EOF) ) lib$signal(status,srab.rab$l_stv); sys$exit(sys$close(&sfab)); }