int main (int argc, char **argv) { char username[128]; char passwd[AUTH_PASS_LEN + 1]; int tries, remaining, c; UINT4 client_port; void (*login_func)(char *); FILE *fp; char buf[4096]; char tty[1024], *p; int noissue = 0; int maxtries = 0; char *ttyn = NULL; char *path_radiusclient_conf = RC_CONFIG_FILE; extern char *optarg; extern int optind; pname = (pname = strrchr(argv[0],'/'))?pname+1:argv[0]; rc_openlog(pname); while ((c = getopt(argc,argv,"f:m:i:nhV")) > 0) { switch(c) { case 'f': path_radiusclient_conf = optarg; break; case 'i': ttyn = optarg; break; case 'n': noissue = 1; break; case 'm': maxtries = atoi(optarg); break; case 'V': version(); break; case 'h': usage(); break; default: exit(ERROR_RC); break; } } if (rc_read_config(path_radiusclient_conf) != 0) exit(ERROR_RC); if (rc_read_dictionary(rc_conf_str("dictionary")) != 0) exit (ERROR_RC); if (rc_read_mapfile(rc_conf_str("mapfile")) != 0) exit (ERROR_RC); if (ttyn != NULL) { client_port = rc_map2id(ttyn); if ((p = strrchr(ttyn, '/')) == NULL) strncpy(tty, ttyn, sizeof(tty)); else strncpy(tty, p+1, sizeof(tty)); } else { ttyn = ttyname(0); if (ttyn) { if ((p = strrchr(ttyn, '/')) == NULL) strncpy(tty, ttyn, sizeof(tty)); else strncpy(tty, p+1, sizeof(tty)); client_port = rc_map2id(ttyn); } else { *tty = '\0'; client_port = 0; } } #ifdef SETVBUF_REVERSED setvbuf(stdout, _IONBF, NULL, 0); #else setvbuf(stdout, NULL, _IONBF, 0); #endif if ((argc - optind) == 1) { strncpy(username,argv[optind], sizeof(username)); } else { *username = '******'; if (!noissue) { if (rc_conf_str("issue") && ((fp = fopen(rc_conf_str("issue"), "r")) != NULL)) { while (fgets(buf, sizeof(buf), fp) != NULL) fputs(subst_placeholders(buf, tty), stdout); fflush(stdout); fclose(fp); } else { fputs(subst_placeholders(SC_DEFAULT_ISSUE, tty), stdout); fflush(stdout); } } } if ((env = rc_new_env(ENV_SIZE)) == NULL) { rc_log(LOG_CRIT, "rc_new_env: FATAL: out of memory"); abort(); } #ifdef SECURITY_DISABLED if (rc_import_env(env,environ) < 0) { rc_log(LOG_CRIT, "rc_import_env: FATAL: not enough space for environment (increase ENV_SIZE)"); abort(); } #else rc_add_env(env, "IFS", " "); rc_add_env(env, "PATH", RC_SECURE_PATH); #endif signal(SIGALRM, alarm_handler); remaining = rc_conf_int("login_timeout"); if (!maxtries) maxtries = rc_conf_int("login_tries"); tries = 1; while (tries <= maxtries) { alarm(remaining); while (!*username) { p = rc_getstr (SC_LOGIN, 1); if (p) strncpy(username, p, sizeof(username)); else exit (ERROR_RC); } p = rc_getstr(SC_PASSWORD,0); if (p) strncpy (passwd, p, sizeof (passwd)); else exit (ERROR_RC); remaining = alarm(0); login_func = NULL; if (rc_conf_int("auth_order") & AUTH_LOCAL_FST) { login_func = auth_local(username, passwd); if (!login_func) if (rc_conf_int("auth_order") & AUTH_RADIUS_SND) login_func = auth_radius(client_port, username, passwd); } else { login_func = auth_radius(client_port, username, passwd); if (!login_func) if (rc_conf_int("auth_order") & AUTH_LOCAL_SND) login_func = auth_local(username, passwd); } memset(passwd, '\0', sizeof(passwd)); if (login_func != NULL) if (login_allowed(tty)) { (*login_func)(username); } else { sleep(1); exit (ERROR_RC); } *username = '******'; if ((++tries) <= maxtries) { alarm(remaining); sleep(tries * 2); remaining = alarm(0); } } fprintf(stderr, SC_EXCEEDED); sleep(1); exit (ERROR_RC); }
int main (int argc, char **argv) { int result = ERROR_RC; VALUE_PAIR *send = NULL; UINT4 client_port; int c; VALUE_PAIR *vp; DICT_VALUE *dval; char *username, *service, *fproto, *type; char *path_radiusclient_conf = RC_CONFIG_FILE; char *ttyn = NULL; rc_handle *rh; extern char *optarg; pname = (pname = strrchr(argv[0],'/'))?pname+1:argv[0]; rc_openlog(pname); while ((c = getopt(argc,argv,"f:i:hV")) > 0) { switch(c) { case 'f': path_radiusclient_conf = optarg; break; case 'i': ttyn = optarg; break; case 'V': version(); break; case 'h': usage(); break; default: exit(ERROR_RC); break; } } if ((rh = rc_read_config(path_radiusclient_conf)) == NULL) exit(ERROR_RC); if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary")) != 0) exit (ERROR_RC); if (rc_read_mapfile(rh, rc_conf_str(rh, "mapfile")) != 0) exit (ERROR_RC); if (ttyn != NULL) { client_port = rc_map2id(rh, ttyn); } else { /* we take stdout here, because stdin is usually connected * to our input file */ if ((ttyn = ttyname(1)) != NULL) { client_port = rc_map2id(rh, ttyn); } else { client_port = 0; } } if ((send = rc_avpair_readin(rh, stdin))) { username = service = type = "(unknown)"; fproto = NULL; if ((vp = rc_avpair_get(send, PW_ACCT_STATUS_TYPE, 0)) != NULL) if ((dval = rc_dict_getval(rh, vp->lvalue, vp->name)) != NULL) { type = dval->name; } if ((vp = rc_avpair_get(send, PW_USER_NAME, 0)) != NULL) username = vp->strvalue; if ((vp = rc_avpair_get(send, PW_SERVICE_TYPE, 0)) != NULL) if ((dval = rc_dict_getval(rh, vp->lvalue, vp->name)) != NULL) { service = dval->name; } if (vp && (vp->lvalue == PW_FRAMED) && ((vp = rc_avpair_get(send, PW_FRAMED_PROTOCOL, 0)) != NULL)) if ((dval = rc_dict_getval(rh, vp->lvalue, vp->name)) != NULL) { fproto = dval->name; } result = rc_acct(rh, client_port, send); if (result == OK_RC) { fprintf(stderr, SC_ACCT_OK); rc_log(LOG_NOTICE, "accounting OK, type %s, username %s, service %s%s%s", type, username, service,(fproto)?"/":"", (fproto)?fproto:""); } else { fprintf(stderr, SC_ACCT_FAILED, result); rc_log(LOG_NOTICE, "accounting FAILED, type %s, username %s, service %s%s%s", type, username, service,(fproto)?"/":"", (fproto)?fproto:""); } rc_avpair_free(send); } exit (result); }