int main(int argc, char *argv[]) { char *arg; struct passwd *p; uid = getuid(); euid = geteuid(); seteuid(uid); /* be safe */ setprogname(*argv); gethostname(host, sizeof(host)); host[sizeof(host) - 1] = '\0'; openlog("lpd", 0, LOG_LPR); if ((p = getpwuid(getuid())) == NULL) fatal("Who are you?"); if (strlen(p->pw_name) >= sizeof(luser)) fatal("Your name is too long"); strlcpy(luser, p->pw_name, sizeof(luser)); person = luser; while (--argc) { if ((arg = *++argv)[0] == '-') switch (arg[1]) { case 'P': if (arg[2]) printer = &arg[2]; else if (argc > 1) { argc--; printer = *++argv; } break; case 'w': if (arg[2]) wait_time = atoi(&arg[2]); else if (argc > 1) { argc--; wait_time = atoi(*++argv); } if (wait_time < 0) errx(1, "wait time must be positive: %d", wait_time); if (wait_time < 30) warnx("warning: wait time less than 30 seconds"); break; case '\0': if (!users) { users = -1; break; } default: usage(); } else { if (users < 0) usage(); if (isdigit((unsigned char)arg[0])) { if (requests >= MAXREQUESTS) fatal("Too many requests"); requ[requests++] = atoi(arg); } else { if (users >= MAXUSERS) fatal("Too many users"); user[users++] = arg; } } } if (printer == NULL && (printer = getenv("PRINTER")) == NULL) printer = DEFLP; rmjob(); exit(0); }
int main(int argc, char *argv[]) { char *arg; const char *printer; struct passwd *p; static char root[] = "root"; printer = NULL; uid = getuid(); euid = geteuid(); PRIV_END /* be safe */ progname = argv[0]; gethostname(local_host, sizeof(local_host)); openlog("lpd", 0, LOG_LPR); /* * Bogus code later checks for string equality between * `person' and "root", so if we are root, better make sure * that code will succeed. */ if (getuid() == 0) { person = root; } else if ((person = getlogin()) == NULL) { if ((p = getpwuid(getuid())) == NULL) fatal(0, "Who are you?"); if (strlen(p->pw_name) >= sizeof(luser)) fatal(0, "Your name is too long"); strcpy(luser, p->pw_name); person = luser; } while (--argc) { if ((arg = *++argv)[0] == '-') switch (arg[1]) { case 'P': if (arg[2]) printer = &arg[2]; else if (argc > 1) { argc--; printer = *++argv; } break; case '\0': if (!users) { users = -1; break; } default: usage(); } else { if (users < 0) usage(); if (isdigit(arg[0])) { if (requests >= MAXREQUESTS) fatal(0, "Too many requests"); requ[requests++] = atoi(arg); } else { if (users >= MAXUSERS) fatal(0, "Too many users"); user[users++] = arg; } } } if (printer == NULL && (printer = getenv("PRINTER")) == NULL) printer = DEFLP; rmjob(printer); exit(0); }
int main(int argc, char **argv) { struct passwd *pw; char *cp; long l; int ch; /* * Simulate setuid daemon w/ PRIV_END called. * We don't want lpr to actually be setuid daemon since that * requires that the lpr binary be owned by user daemon, which * is potentially unsafe. */ if ((pw = getpwuid(DEFUID)) == NULL) errx(1, "daemon uid (%u) not in password file", DEFUID); effective_uid = pw->pw_uid; real_uid = getuid(); effective_gid = pw->pw_gid; real_gid = getgid(); setresgid(real_gid, real_gid, effective_gid); setresuid(real_uid, real_uid, effective_uid); gethostname(host, sizeof(host)); openlog("lprm", 0, LOG_LPR); if ((pw = getpwuid(real_uid)) == NULL) fatal("Who are you?"); if (strlen(pw->pw_name) >= sizeof(luser)) fatal("Your name is too long"); strlcpy(luser, pw->pw_name, sizeof(luser)); person = luser; while ((ch = getopt(argc, argv, "P:w:-")) != -1) { switch (ch) { case '-': users = -1; break; case 'P': printer = optarg; break; case 'w': l = strtol(optarg, &cp, 10); if (*cp != '\0' || l < 0 || l >= INT_MAX) errx(1, "wait time must be postive integer: %s", optarg); wait_time = (u_int)l; if (wait_time < 30) warnx("warning: wait time less than 30 seconds"); break; default: usage(); } } argc -= optind; argv += optind; if (printer == NULL && (printer = getenv("PRINTER")) == NULL) printer = DEFLP; if (users < 0 && argc != 0) usage(); while (argc > 0) { if (isdigit(*argv[0])) { if (requests >= MAXREQUESTS) fatal("Too many requests"); requ[requests++] = atoi(argv[0]); } else { if (users >= MAXUSERS) fatal("Too many users"); user[users++] = argv[0]; } argc--; argv++; } rmjob(); exit(0); }
int main (int argc, char **argv) { register char *arg; struct passwd *p; #ifndef __HELIOS struct direct **files; int nitems, assasinated = 0; #else extern void rmjob(void); #endif name = argv[0]; #ifndef __HELIOS gethostname(host, sizeof(host)); #else /* -- crf: 09/03/93 -- Exit if gethostname() fails */ if (gethostname(host, sizeof(host))) { perror("lprm: gethostname"); exit(1); } #endif openlog("lpd", 0, LOG_LPR); if ((p = getpwuid(getuid())) == NULL) fatal("Who are you?"); if (strlen(p->pw_name) >= sizeof(luser)) fatal("Your name is too long"); strcpy(luser, p->pw_name); person = luser; while (--argc) { if ((arg = *++argv)[0] == '-') switch (arg[1]) { case 'P': if (arg[2]) printer = &arg[2]; else if (argc > 1) { argc--; printer = *++argv; } break; case '\0': if (!users) { users = -1; break; } default: usage(); } else { if (users < 0) usage(); if (isdigit(arg[0])) { if (requests >= MAXREQUESTS) fatal("Too many requests"); requ[requests++] = atoi(arg); } else { if (users >= MAXUSERS) fatal("Too many users"); user[users++] = arg; } } } if (printer == NULL && (printer = getenv("PRINTER")) == NULL) printer = DEFLP; rmjob(); }
static void doit(void) { char *cp, *printer; int n; int status; struct printer myprinter, *pp = &myprinter; init_printer(&myprinter); for (;;) { cp = cbuf; do { if (cp >= &cbuf[sizeof(cbuf) - 1]) fatal(0, "Command line too long"); if ((n = read(STDOUT_FILENO, cp, 1)) != 1) { if (n < 0) fatal(0, "Lost connection"); return; } } while (*cp++ != '\n'); *--cp = '\0'; cp = cbuf; if (lflag) { if (*cp >= '\1' && *cp <= '\5') syslog(LOG_INFO, "%s requests %s %s", from_host, cmdnames[(u_char)*cp], cp+1); else syslog(LOG_INFO, "bad request (%d) from %s", *cp, from_host); } switch (*cp++) { case CMD_CHECK_QUE: /* check the queue, print any jobs there */ startprinting(cp); break; case CMD_TAKE_THIS: /* receive files to be queued */ if (!from_remote) { syslog(LOG_INFO, "illegal request (%d)", *cp); exit(1); } recvjob(cp); break; case CMD_SHOWQ_SHORT: /* display the queue (short form) */ case CMD_SHOWQ_LONG: /* display the queue (long form) */ /* XXX - this all needs to be redone. */ printer = cp; while (*cp) { if (*cp != ' ') { cp++; continue; } *cp++ = '\0'; while (isspace(*cp)) cp++; if (*cp == '\0') break; if (isdigit(*cp)) { if (requests >= MAXREQUESTS) fatal(0, "Too many requests"); requ[requests++] = atoi(cp); } else { if (users >= MAXUSERS) fatal(0, "Too many users"); user[users++] = cp; } } status = getprintcap(printer, pp); if (status < 0) fatal(pp, "%s", pcaperr(status)); displayq(pp, cbuf[0] == CMD_SHOWQ_LONG); exit(0); case CMD_RMJOB: /* remove a job from the queue */ if (!from_remote) { syslog(LOG_INFO, "illegal request (%d)", *cp); exit(1); } printer = cp; while (*cp && *cp != ' ') cp++; if (!*cp) break; *cp++ = '\0'; person = cp; while (*cp) { if (*cp != ' ') { cp++; continue; } *cp++ = '\0'; while (isspace(*cp)) cp++; if (*cp == '\0') break; if (isdigit(*cp)) { if (requests >= MAXREQUESTS) fatal(0, "Too many requests"); requ[requests++] = atoi(cp); } else { if (users >= MAXUSERS) fatal(0, "Too many users"); user[users++] = cp; } } rmjob(printer); break; } fatal(0, "Illegal service request"); } }