int main(int argc,const char *const *argv,const char *const *envp) { struct passwd *pw; const char *account; char strnum[FMT_ULONG]; account = *++argv; if (!account || !*++argv) usage(); pw = getpwnam(account); if (!pw) strerr_die3x(111,FATAL,"unknown account ",account); if (!pathexec_env("HOME",pw->pw_dir)) nomem(); if (!pathexec_env("SHELL",pw->pw_shell)) nomem(); if (!pathexec_env("USER",pw->pw_name)) nomem(); strnum[fmt_ulong(strnum,pw->pw_gid)] = 0; if (!pathexec_env("GID",strnum)) nomem(); strnum[fmt_ulong(strnum,pw->pw_uid)] = 0; if (!pathexec_env("UID",strnum)) nomem(); if (chdir(pw->pw_dir) != 0) strerr_die3sys(111,FATAL,"unable to chdir to ", pw->pw_dir); if (prot_gid(pw->pw_gid) == -1) strerr_die2sys(111,FATAL,"unable to setgid"); if (prot_gids(pw->pw_name, pw->pw_gid) == -1) strerr_die2sys(111,FATAL,"unable to initgroups"); if (prot_uid(pw->pw_uid) == -1) strerr_die2sys(111,FATAL,"unable to setuid"); pathexec_run(*argv,argv,envp); strerr_die3sys(111,FATAL,"unable to run ",*argv); }
void numwrite(void) { int fd; int i; i = fmt_ulong(strnum,msgnum); strnum[i++] = ':'; i += fmt_ulong(strnum+i,cumsize); strnum[i++] = '\n'; if ((fd = open_trunc("numnew")) == -1 || write(fd, strnum, i) != i || fsync(fd) == -1 || close(fd) == -1) strerr_die3sys(111,FATAL,ERR_CREATE,"numnew: "); if (rename("numnew","num") == -1) strerr_die3sys(111,FATAL,ERR_MOVE,"numnew: "); }
int main(int argc,char **argv) { int fd; const char *fnok; if (!argv[1]) strerr_die1x(100,"svok: usage: svok dir"); if (chdir(argv[1]) == -1) strerr_die3sys(111,FATAL,"unable to chdir to ",argv[1]); if (!svpath_init()) strerr_die3sys(111,FATAL,"unable to setup control path for ",argv[1]); if ((fnok = svpath_make("/ok")) == 0) strerr_die2sys(111,FATAL,"unable to allocate memory"); fd = open_write(fnok); if (fd == -1) { if (errno == error_noent) _exit(100); if (errno == error_nodevice) _exit(100); strerr_die3sys(111,FATAL,"unable to open ",fnok); } _exit(0); }
static void forward(const char *rcpt) { char buf[4096]; const char *dtline; const char *err; int r; if (qmail_open(&qq,0) == -1) strerr_die2sys(111,FATAL,ERR_QMAIL_QUEUE); if ((dtline = env_get("DTLINE")) != 0) qmail_puts(&qq,dtline); while ((r = read(0,buf,sizeof buf)) > 0) qmail_put(&qq,buf,r); if (r == -1) strerr_die3sys(111,FATAL,ERR_READ,": "); qmail_from(&qq,sender); qmail_to(&qq,rcpt); if (*(err = qmail_close(&qq)) != '\0') strerr_die3x(111,FATAL,ERR_TMP_QMAIL_QUEUE,err + 1); strnum[fmt_ulong(strnum,qmail_qp(&qq))] = 0; substdio_puts(subfderr,"qp "); substdio_puts(subfderr,strnum); substdio_putsflush(subfderr,"\n"); ++did_forward; }
void fatal(const char *m) { strerr_die3sys(111, FATAL, m, ": "); }
void drop(char *m0) { strerr_die3sys(111, DROP, m0, ": "); }
void fatal(char *m0) { strerr_die3sys(111, FATAL, m0, ": "); }
int main(int argc,const char *const *argv) { int fd; const char *fn; char status[40]; int rd; int opt; int check_log = -1; while ((opt = getopt(argc,argv,"lL")) != opteof) { switch (opt) { case 'L': check_log = 1; break; case 'l': check_log = 0; break; default: die_usage(); } } argv += optind; if (!argv[0]) die_usage(); if (chdir(argv[0]) == -1) strerr_die3sys(111,FATAL,"unable to chdir to ",argv[1]); if (!svpath_init()) strerr_die3sys(111,FATAL,"unable to setup control path for ",argv[1]); if ((fn = svpath_make("/ok")) == 0) strerr_die2sys(111,FATAL,"unable to allocate memory"); fd = open_write(fn); if (fd == -1) { if (errno == error_noent) _exit(100); if (errno == error_nodevice) _exit(100); strerr_die3sys(111,FATAL,"unable to open ",fn); } close(fd); if ((fn = svpath_make("/status")) == 0) strerr_die2sys(111,FATAL,"unable to allocate memory"); fd = open_read(fn); if (fd == -1) { if (errno == error_noent) _exit(100); strerr_die3sys(111,FATAL,"unable to open ",fn); } if ((rd = read(fd,status,sizeof status)) == -1) strerr_die3sys(111,FATAL,"unable to read ",fn); if (rd < 18) strerr_die4(111,FATAL,"bad data in ",fn,": truncated file",0); if (check_log <= 0) if (!checkstatus(status,rd)) _exit(100); if (check_log != 0) { if (rd < 20+18) { if (check_log > 0) _exit(100); } else if (!checkstatus(status+20,rd-20)) _exit(100); } _exit(0); }
int main(int argc,const char *const *argv,const char *const *envp) { int opt; doallenv(); while ((opt = getopt(argc,argv,"a:c:d:f:l:m:o:p:r:s:t:")) != opteof) switch(opt) { case '?': die_usage(); case 'a': #ifdef RLIMIT_AS doit(RLIMIT_AS,optarg); #endif #ifdef RLIMIT_VMEM doit(RLIMIT_VMEM,optarg); #endif break; case 'c': #ifdef RLIMIT_CORE doit(RLIMIT_CORE,optarg); #endif break; case 'd': #ifdef RLIMIT_DATA doit(RLIMIT_DATA,optarg); #endif break; case 'f': #ifdef RLIMIT_FSIZE doit(RLIMIT_FSIZE,optarg); #endif break; case 'l': #ifdef RLIMIT_MEMLOCK doit(RLIMIT_MEMLOCK,optarg); #endif break; case 'm': #ifdef RLIMIT_DATA doit(RLIMIT_DATA,optarg); #endif #ifdef RLIMIT_STACK doit(RLIMIT_STACK,optarg); #endif #ifdef RLIMIT_MEMLOCK doit(RLIMIT_MEMLOCK,optarg); #endif #ifdef RLIMIT_VMEM doit(RLIMIT_VMEM,optarg); #endif #ifdef RLIMIT_AS doit(RLIMIT_AS,optarg); #endif break; case 'o': #ifdef RLIMIT_NOFILE doit(RLIMIT_NOFILE,optarg); #endif #ifdef RLIMIT_OFILE doit(RLIMIT_OFILE,optarg); #endif break; case 'p': #ifdef RLIMIT_NPROC doit(RLIMIT_NPROC,optarg); #endif break; case 'r': #ifdef RLIMIT_RSS doit(RLIMIT_RSS,optarg); #endif break; case 's': #ifdef RLIMIT_STACK doit(RLIMIT_STACK,optarg); #endif break; case 't': #ifdef RLIMIT_CPU doit(RLIMIT_CPU,optarg); #endif break; } argv += optind; if (!*argv) die_usage(); pathexec_run(*argv,argv,envp); strerr_die3sys(111,FATAL,"unable to run ",*argv); }
uint32 get_connection_info6(char *lip, uint16 lport, char *rip, uint16 rport) { int match = 1; int fd = 0; uint32 uid = 0xffffffff; // that's our default for "not found" uint32 kernlport, kernrport; char kernlip[4]; char kernrip[4]; char bspace[1024]; buffer b; stralloc line = {0}; int i; fd = open_read(NETINFOFILE6); if (fd == -1) /* If opening failed quit */ strerr_die3sys(111, FATAL, NETINFOFILE6, ": "); buffer_init(&b, read, fd, bspace, sizeof bspace); while (match) { if (getln(&b, &line, &match, '\n') == -1) strerr_die2sys(111, FATAL, "unable to read line: "); /* example line: sl local_address remote_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode 0: 000BFE3FFF1F180C0000000005020000:004F 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 1000 0 10078742 1: 00000000000000000000000000000000:04D2 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 9215187 5 7 40 45 78 129 */ if((line.s[4] == ':') && (line.len > 130)) { if((line.s[38] != ':') || (line.s[43] != ' ') || (line.s[76] != ':') || (line.s[81] != ' ')) strerr_die3x(111, FATAL, "can't parse file ", NETINFOFILE6); scan_xlong(&line.s[39], &kernlport); scan_xlong(&line.s[77], &kernrport); for(i = 0; i < 16; i++) { /* check this on big endian machines */ kernlip[15-i] = (unsigned char) ((fromhex(line.s[(i*2)+6]) << 4) | fromhex(line.s[(i*2)+7])); kernrip[15-i] = (unsigned char) ((fromhex(line.s[(i*2)+44]) << 4) | fromhex(line.s[(i*2)+45])); } if((kernrport == rport) && (kernlport == lport) && byte_equal(kernrip, 16, rip) && byte_equal(kernlip, 16, lip)) { scan_ulong(&line.s[124], &uid); break; } } } close(fd); return uid; }