/* * Make the temp files. */ static void mktemps(void) { int len, fd, n; char *cp; char buf[MAXPATHLEN]; (void)snprintf(buf, sizeof(buf), "%s/.seq", SD); seteuid(euid); if ((fd = open(buf, O_RDWR|O_CREAT, 0664)) < 0) err(1, "cannot create %s", buf); if (flock(fd, LOCK_EX)) err(1, "cannot lock %s", buf); seteuid(uid); n = 0; if ((len = read(fd, buf, sizeof(buf))) > 0) { for (cp = buf; len--; ) { if (*cp < '0' || *cp > '9') break; n = n * 10 + (*cp++ - '0'); } } reqid = n; len = strlen(SD) + strlen(host) + 8; tfname = lmktemp("tf", n, len); cfname = lmktemp("cf", n, len); dfname = lmktemp("df", n, len); inchar = strlen(SD) + 3; n = (n + 1) % 1000; (void)lseek(fd, (off_t)0, 0); (void)snprintf(buf, sizeof(buf), "%03d\n", n); (void)write(fd, buf, strlen(buf)); (void)close(fd); /* unlocks as well */ }
/* * Make the temp files. */ static void mktemps(void) { int len, fd, n; char *cp; char buf[BUFSIZ]; struct stat stb; if (snprintf(buf, sizeof(buf), "%s/.seq", SD) >= sizeof(buf)) errx(1, "%s/.seq: %s", SD, strerror(ENAMETOOLONG)); PRIV_START; if ((fd = safe_open(buf, O_RDWR|O_CREAT|O_NOFOLLOW, 0661)) < 0) err(1, "cannot open %s", buf); if (flock(fd, LOCK_EX)) err(1, "cannot lock %s", buf); PRIV_END; n = 0; if ((len = read(fd, buf, sizeof(buf))) > 0) { for (cp = buf; len--; ) { if (*cp < '0' || *cp > '9') break; n = n * 10 + (*cp++ - '0'); } } len = strlen(SD) + strlen(host) + 8; do { tfname = lmktemp("tf", n, len); cfname = lmktemp("cf", n, len); dfname = lmktemp("df", n, len); n = (n + 1) % 1000; } while (stat(tfname, &stb) == 0 || stat(cfname, &stb) == 0 || stat(dfname, &stb) == 0); inchar = strlen(SD) + 3; (void)lseek(fd, (off_t)0, 0); snprintf(buf, sizeof(buf), "%03d\n", n); (void)write(fd, buf, strlen(buf)); (void)close(fd); /* unlocks as well */ }
/* * Make the temp files. */ static void mktemps(const struct printer *pp) { register int len, fd, n; register char *cp; char buf[BUFSIZ]; (void) snprintf(buf, sizeof(buf), "%s/.seq", pp->spool_dir); PRIV_START if ((fd = open(buf, O_RDWR|O_CREAT, 0664)) < 0) { printf("%s: cannot create %s\n", progname, buf); exit(1); } if (flock(fd, LOCK_EX)) { printf("%s: cannot lock %s\n", progname, buf); exit(1); } PRIV_END n = 0; if ((len = read(fd, buf, sizeof(buf))) > 0) { for (cp = buf; len--; ) { if (*cp < '0' || *cp > '9') break; n = n * 10 + (*cp++ - '0'); } } len = strlen(pp->spool_dir) + strlen(local_host) + 8; tfname = lmktemp(pp, "tf", n, len); cfname = lmktemp(pp, "cf", n, len); dfname = lmktemp(pp, "df", n, len); inchar = strlen(pp->spool_dir) + 3; n = (n + 1) % 1000; (void) lseek(fd, (off_t)0, 0); snprintf(buf, sizeof(buf), "%03d\n", n); (void) write(fd, buf, strlen(buf)); (void) close(fd); /* unlocks as well */ }