void authchain(int argc, char **argv, const char *buf) { int pipes[2]; pid_t p; int l, n; char **vec; char *prog; vec=authcopyargv(argc, argv, &prog); close(3); if (!prog || open("/dev/null", O_RDONLY) != 3) authexit(1); if (pipe(pipes)) { perror("pipe"); authexit(1); } while ((p=fork()) < 0) { perror("fork"); sleep(3); } close(3); if (p) { dup(pipes[0]); close(pipes[0]); close(pipes[1]); execv(prog, vec); perror(prog); authexit(1); } l=strlen(buf); close(pipes[0]); while (l) { n=write(pipes[1], buf, l); if (n <= 0) break; buf += n; l -= n; } close(pipes[1]); authexit(1); }
void authmod_login(int argc, char **argv, const char *service, const char *userid, const char *passwd) { char *p=malloc(strlen(userid)+strlen(passwd)+3); auth_debug_login( 1, "username=%s", userid ); auth_debug_login( 2, "password=%s", passwd ); if (!p) { perror("malloc"); authexit(1); } strcat(strcat(strcat(strcpy(p, userid), "\n"), passwd), "\n"); authmod(argc, argv, service, AUTHTYPE_LOGIN, p); }
int authmoduser(int argc, char **argv, unsigned timeout, unsigned errsleep) { const char *p; int rc; char namebuf[60]; int n; time_t t, expinterval; char *q, *r; int waitstat; signal(SIGCHLD, SIG_DFL); while (wait(&waitstat) >= 0) ; p=getenv("AUTHUSER"); if (!p && argc && argv[0][0] == '/') /* Set AUTHUSER from argv[0] */ { q=malloc(sizeof("AUTHUSER="******"malloc"); authexit(1); } strcat(strcpy(q, "AUTHUSER="******": AUTHUSER is not initialized to a complete path\n", 49); authexit(1); } putenv("AUTHENTICATED="); if (argc < 2) { write(2, "AUTHFAILURE\n", 12); authexit(1); } p=getenv("AUTHARGC"); rc= p && *p && *p != '0' ? 0:1; sprintf(namebuf, "AUTHARGC=%d", argc); r=strdup(namebuf); if (!r) { perror("strdup"); authexit(1); } putenv(r); for (n=0; n<argc; n++) { char *p; sprintf(namebuf, "AUTHARGV%d=", n); p=malloc(strlen(namebuf)+1+strlen(argv[n])); if (!p) { perror("malloc"); authexit(1); } strcat(strcpy(p, namebuf), argv[n]); putenv(p); } if (rc == 0 && errsleep) sleep(errsleep); time(&t); p=getenv("AUTHEXPIRE"); if (p && isdigit((int)(unsigned char)*p)) { expinterval=0; do { expinterval=expinterval * 10 + (*p++ - '0'); } while ( isdigit((int)(unsigned char)*p) ); } else { time_t n; expinterval=t + timeout; q=namebuf+sizeof(namebuf)-1; *q=0; n=expinterval; do { *--q = '0' + ( n % 10 ); } while ( (n = n/10) != 0); q -= sizeof("AUTHEXPIRE=")-1; memcpy(q, "AUTHEXPIRE=", sizeof("AUTHEXPIRE=")-1); q=strdup(q); if (!q) { perror("strdup"); authexit(1); } putenv(q); } if (timeout) { if (expinterval <= t) authexit(1); alarm(expinterval - t); } return (rc); }