int queue_init(const char *name, int server) { struct passwd *pwq; struct group *gr; int r; pwq = getpwnam(SMTPD_QUEUE_USER); if (pwq == NULL) errx(1, "unknown user %s", SMTPD_QUEUE_USER); gr = getgrnam(SMTPD_QUEUE_GROUP); if (gr == NULL) errx(1, "unknown group %s", SMTPD_QUEUE_GROUP); tree_init(&evpcache_tree); TAILQ_INIT(&evpcache_list); if (!strcmp(name, "fs")) backend = &queue_backend_fs; else if (!strcmp(name, "null")) backend = &queue_backend_null; else if (!strcmp(name, "ram")) backend = &queue_backend_ram; else backend = &queue_backend_proc; if (server) { if (ckdir(PATH_SPOOL, 0711, 0, 0, 1) == 0) errx(1, "error in spool directory setup"); if (ckdir(PATH_SPOOL PATH_OFFLINE, 0770, 0, gr->gr_gid, 1) == 0) errx(1, "error in offline directory setup"); if (ckdir_quiet(PATH_SPOOL PATH_PURGE, 0700, pwq->pw_uid, 0)) chmod(PATH_SPOOL PATH_PURGE, 0750); if (ckdir(PATH_SPOOL PATH_PURGE, 0750, pwq->pw_uid, 0, 1) == 0) errx(1, "error in purge directory setup"); mvpurge(PATH_SPOOL PATH_TEMPORARY, PATH_SPOOL PATH_PURGE); if (ckdir(PATH_SPOOL PATH_TEMPORARY, 0700, pwq->pw_uid, 0, 1) == 0) errx(1, "error in purge directory setup"); } r = backend->init(pwq, server, name); log_trace(TRACE_QUEUE, "queue-backend: queue_init(%d) -> %d", server, r); return (r); }
int queue_init(const char *name, int server) { struct passwd *pwq; int r; pwq = getpwnam(SMTPD_QUEUE_USER); if (pwq == NULL) pwq = getpwnam(SMTPD_USER); if (pwq == NULL) errx(1, "unknown user %s", SMTPD_USER); tree_init(&evpcache_tree); TAILQ_INIT(&evpcache_list); if (!strcmp(name, "fs")) backend = &queue_backend_fs; if (!strcmp(name, "null")) backend = &queue_backend_null; if (!strcmp(name, "proc")) backend = &queue_backend_proc; if (!strcmp(name, "ram")) backend = &queue_backend_ram; if (backend == NULL) { log_warn("could not find queue backend \"%s\"", name); return (0); } if (server) { if (ckdir(PATH_SPOOL, 0711, 0, 0, 1) == 0) errx(1, "error in spool directory setup"); if (ckdir(PATH_SPOOL PATH_OFFLINE, 01777, 0, 0, 1) == 0) errx(1, "error in offline directory setup"); if (ckdir(PATH_SPOOL PATH_PURGE, 0700, pwq->pw_uid, 0, 1) == 0) errx(1, "error in purge directory setup"); mvpurge(PATH_SPOOL PATH_TEMPORARY, PATH_SPOOL PATH_PURGE); if (ckdir(PATH_SPOOL PATH_TEMPORARY, 0700, pwq->pw_uid, 0, 1) == 0) errx(1, "error in purge directory setup"); } r = backend->init(pwq, server); log_trace(TRACE_QUEUE, "queue-backend: queue_init(%i) -> %i", server, r); return (r); }
void pass4(void) { depth = 0; linkmap[ROOTINODE] = 1; ckdir(ROOTINODE, ROOTINODE, "/"); if (depth != 0) panic("Inconsistent depth"); }
static int enqueue_offline(int argc, char *argv[], FILE *ifile) { char path[SMTPD_MAXPATHLEN]; FILE *fp; int i, fd, ch; mode_t omode; if (ckdir(PATH_SPOOL PATH_OFFLINE, 01777, 0, 0, 0) == 0) errx(EX_UNAVAILABLE, "error in offline directory setup"); if (! bsnprintf(path, sizeof(path), "%s%s/%lld.XXXXXXXXXX", PATH_SPOOL, PATH_OFFLINE, (long long int) time(NULL))) err(EX_UNAVAILABLE, "snprintf"); omode = umask(7077); if ((fd = mkstemp(path)) == -1 || (fp = fdopen(fd, "w+")) == NULL) { warn("cannot create temporary file %s", path); if (fd != -1) unlink(path); exit(EX_UNAVAILABLE); } umask(omode); if (fchmod(fd, 0600) == -1) { unlink(path); exit(EX_SOFTWARE); } for (i = 1; i < argc; i++) { if (strchr(argv[i], '|') != NULL) { warnx("%s contains illegal character", argv[i]); unlink(path); exit(EX_SOFTWARE); } fprintf(fp, "%s%s", i == 1 ? "" : "|", argv[i]); } fprintf(fp, "\n"); while ((ch = fgetc(ifile)) != EOF) if (fputc(ch, fp) == EOF) { warn("write error"); unlink(path); exit(EX_UNAVAILABLE); } if (ferror(ifile)) { warn("read error"); unlink(path); exit(EX_UNAVAILABLE); } fclose(fp); return (EX_TEMPFAIL); }
int enqueue_offline(int argc, char *argv[]) { char path[MAXPATHLEN]; FILE *fp; int i, fd, ch; if (ckdir(PATH_SPOOL PATH_OFFLINE, 01777, 0, 0, 0) == 0) errx(1, "error in offline directory setup"); if (! bsnprintf(path, sizeof(path), "%s%s/%lld.XXXXXXXXXX", PATH_SPOOL, PATH_OFFLINE, (long long int) time(NULL))) err(1, "snprintf"); if ((fd = mkstemp(path)) == -1 || (fp = fdopen(fd, "w+")) == NULL) { warn("cannot create temporary file %s", path); if (fd != -1) unlink(path); exit(1); } for (i = 1; i < argc; i++) { if (strchr(argv[i], '|') != NULL) { warnx("%s contains illegal character", argv[i]); unlink(path); exit(1); } fprintf(fp, "%s%s", i == 1 ? "" : "|", argv[i]); } fprintf(fp, "\n"); while ((ch = fgetc(stdin)) != EOF) if (fputc(ch, fp) == EOF) { warn("write error"); unlink(path); exit(1); } if (ferror(stdin)) { warn("read error"); unlink(path); exit(1); } fclose(fp); return (0); }
void ckdir(uint16_t inum, uint16_t pnum, char *name) { struct dinode ino; struct direct dentry; uint16_t j; int c; int nentries; char ename[150]; iread(inum, &ino); if ((swizzle16(ino.i_mode) & F_MASK) != F_DIR) return; ++depth; if (swizzle32(ino.i_size) % 32 != 0) { printf("Directory inode %d has improper length. Fix? ", inum); if (yes()) { ino.i_size = swizzle32(swizzle32(ino.i_size) & ~0x1f); iwrite(inum, &ino); } } nentries = swizzle32(ino.i_size)/32; for (j = 0; j < nentries; ++j) { dirread(&ino, j, &dentry); #if 1 /**HP**/ { int i; for (i = 0; i < 30; ++i) if (dentry.d_name[i] == '\0') break; for ( ; i < 30; ++i) dentry.d_name[i] = '\0'; dirwrite(&ino, j, &dentry); } #endif if (dentry.d_ino == 0) continue; if (swizzle16(dentry.d_ino) < ROOTINODE || swizzle16(dentry.d_ino) >= 8 * swizzle16(superblock.s_isize)) { printf("Directory entry %s%-1.14s has out-of-range inode %u. Zap? ", name, dentry.d_name, swizzle16(dentry.d_ino)); if (yes()) { dentry.d_ino = 0; dentry.d_name[0] = '\0'; dirwrite(&ino, j, &dentry); continue; } } if (dentry.d_ino && linkmap[swizzle16(dentry.d_ino)] == -1) { printf("Directory entry %s%-1.14s points to bogus inode %u. Zap? ", name, dentry.d_name, swizzle16(dentry.d_ino)); if (yes()) { dentry.d_ino = 0; dentry.d_name[0] = '\0'; dirwrite(&ino, j, &dentry); continue; } } ++linkmap[swizzle16(dentry.d_ino)]; for (c = 0; c < 30 && dentry.d_name[c]; ++c) { if (dentry.d_name[c] == '/') { printf("Directory entry %s%-1.30s contains slash. Fix? ", name, dentry.d_name); if (yes()) { dentry.d_name[c] = 'X'; dirwrite(&ino, j, &dentry); } } } if (strncmp(dentry.d_name, ".", 30) == 0 && swizzle16(dentry.d_ino) != inum) { printf("Dot entry %s%-1.30s points to wrong place. Fix? ", name, dentry.d_name); if (yes()) { dentry.d_ino = swizzle16(inum); dirwrite(&ino, j, &dentry); } } if (strncmp(dentry.d_name, "..", 30) == 0 && swizzle16(dentry.d_ino) != pnum) { printf("DotDot entry %s%-1.30s points to wrong place. Fix? ", name, dentry.d_name); if (yes()) { dentry.d_ino = swizzle16(pnum); dirwrite(&ino, j, &dentry); } } if (swizzle16(dentry.d_ino) != pnum && swizzle16(dentry.d_ino) != inum && depth < MAXDEPTH) { strcpy(ename, name); strcat(ename, dentry.d_name); strcat(ename, "/"); ckdir(swizzle16(dentry.d_ino), inum, ename); } } --depth; }