Exemple #1
0
int main(int argc,char **argv,char **envp)
{
  int piin[2];
  int piout[2];

  pid[fmt_ulong(pid,getpid())] = 0;

  if (argc < 2)
    strerr_die1x(100,"recordio: usage: recordio program [ arg ... ]");

  if (pipe(piin) == -1)
    strerr_die2sys(111,FATAL,"unable to create pipe: ");
  if (pipe(piout) == -1)
    strerr_die2sys(111,FATAL,"unable to create pipe: ");

  switch(fork()) {
    case -1:
      strerr_die2sys(111,FATAL,"unable to fork: ");
    case 0:
      sig_ignore(sig_pipe);
      close(piin[0]);
      close(piout[1]);
      doit(piin[1],piout[0]);
  }

  close(piin[1]);
  close(piout[0]);
  if (fd_move(0,piin[0]) == -1)
    strerr_die2sys(111,FATAL,"unable to move descriptors: ");
  if (fd_move(1,piout[1]) == -1)
    strerr_die2sys(111,FATAL,"unable to move descriptors: ");

  pathexec_run(argv[1],argv + 1,envp);
  strerr_die4sys(111,FATAL,"unable to run ",argv[1],": ");
}
Exemple #2
0
int main(int argc,const char * const *argv,const char * const *envp)
{
  if (!argv[1]) strerr_die1x(100,"pgrphack: usage: pgrphack child");
  setsid(); /* shouldn't fail; if it does, too bad */
  pathexec_run(argv[1],argv + 1,envp);
  strerr_die4sys(111,"pgrphack: fatal: ","unable to run ",argv[1],": ");
}
Exemple #3
0
int main(int argc,char **argv)
{
  struct stat st;

  dir = argv[1];
  if (!dir || argv[2])
    strerr_die1x(100,"supervise: usage: supervise dir");

  if (pipe(selfpipe) == -1)
    strerr_die4sys(111,FATAL,"unable to create pipe for ",dir,": ");
  coe(selfpipe[0]);
  coe(selfpipe[1]);
  ndelay_on(selfpipe[0]);
  ndelay_on(selfpipe[1]);

  sig_block(sig_child);
  sig_catch(sig_child,trigger);

  if (chdir(dir) == -1)
    strerr_die4sys(111,FATAL,"unable to chdir to ",dir,": ");

  if (stat("down",&st) != -1)
    flagwantup = 0;
  else
    if (errno != error_noent)
      strerr_die4sys(111,FATAL,"unable to stat ",dir,"/down: ");

  mkdir("supervise",0700);
  fdlock = open_append("supervise/lock");
  if ((fdlock == -1) || (lock_exnb(fdlock) == -1))
    strerr_die4sys(111,FATAL,"unable to acquire ",dir,"/supervise/lock: ");
  coe(fdlock);

  fifo_make("supervise/control",0600);
  fdcontrol = open_read("supervise/control");
  if (fdcontrol == -1)
    strerr_die4sys(111,FATAL,"unable to read ",dir,"/supervise/control: ");
  coe(fdcontrol);
  ndelay_on(fdcontrol); /* shouldn't be necessary */
  fdcontrolwrite = open_write("supervise/control");
  if (fdcontrolwrite == -1)
    strerr_die4sys(111,FATAL,"unable to write ",dir,"/supervise/control: ");
  coe(fdcontrolwrite);

  pidchange();
  announce();

  fifo_make("supervise/ok",0600);
  fdok = open_read("supervise/ok");
  if (fdok == -1)
    strerr_die4sys(111,FATAL,"unable to read ",dir,"/supervise/ok: ");
  coe(fdok);

  if (!flagwant || flagwantup) trystart();

  doit();
  announce();
  _exit(0);
}
Exemple #4
0
/*
void show(const char *desc, stralloc *s)
{
  buffer_puts(buffer_2,desc);
  buffer_puthex(buffer_2,s->s,s->len);
  buffer_putsflush(buffer_2,"\n");
}
*/
int main(int argc, char * argv[])
{
    int r;
    const char* pk0;
    const char* sk0;

    /* Check args */
    pk0 = ((argc<2) ? env_get("NACL_PUBLICKEY_FILE") : argv[1]);
    sk0 = ((argc<3) ? env_get("NACL_SECRETKEY_FILE") : argv[2]);

    if(pk0==0 || sk0==0)
        strerr_die1x(100,"crypto-box: usage: crypto-box [ publickeyfile ] [ secretkeyfile ]");

    /* Read public key */
    if(openreadclose(argv[1],&pk,crypto_box_PUBLICKEYBYTES)<=0)
        strerr_die2sys(111,FATAL,"unable to read public key: ");

    /* Read secret key */
    if(openreadclose(argv[2],&sk,crypto_box_SECRETKEYBYTES)<=0)
        strerr_die2sys(111,FATAL,"unable to read secret key: ");

    /* Create shared key */
    if(crypto_str_box_beforenm(&k,&pk,&sk))
        strerr_die2x(111,FATAL,"failed to create shared-key");

    /* Decrypt each chunk */
    for (;;) {

        /* Read nonce */
        if((r=netstring_read(buffer_0,&n))!=0)
            strerr_die2x(111,FATAL,"failed to read nonce");
        if(n.len==0) break;
        if(n.len!=crypto_box_NONCEBYTES)
            strerr_die2x(111,FATAL,"nonce was incorrect size");

        /* Read cipher */
        if(netstring_read(buffer_0,&c)!=0)
            strerr_die2x(111,FATAL,"failed to read cipher");

        /* Decrypt message */
        if(crypto_str_box_open_afternm(&m,&c,&n,&k)!=0)
            strerr_die2x(111,FATAL,"decryption failed");

        /* Write message */
        if(buffer_put(buffer_1,m.s,m.len)!=0)
            strerr_die2sys(111,FATAL,"failed to output message: ");

    }
    buffer_flush(buffer_1);

    return 0;
}
Exemple #5
0
int main(int argc,const char *const *argv)
{
  int opt;
  int fd;
  const char *dir;

  sig_ignore(sig_pipe);

  while ((opt = getopt(argc,argv,"?vudopchaitkx")) != opteof)
    if (opt == 'v'){
      puts("version: 0.76d");
      exit(0);
    }
    else if (opt == '?')
      strerr_die1x(100,"svc options: u up, d down, o once, x exit, p pause, c continue, h hup, a alarm, i interrupt, t term, k kill");
    else
      if (datalen < sizeof data)
        if (byte_chr(data,datalen,opt) == datalen)
          data[datalen++] = opt;
  argv += optind;

  fdorigdir = open_read(".");
  if (fdorigdir == -1)
    strerr_die2sys(111,FATAL,"unable to open current directory: ");

  while (dir = *argv++) {
    if (chdir(dir) == -1)
      strerr_warn4(WARNING,"unable to chdir to ",dir,": ",&strerr_sys);
    else {
      fd = open_write("supervise/control");
      if (fd == -1)
        if (errno == error_nodevice)
          strerr_warn4(WARNING,"unable to control ",dir,": supervise not running",0);
        else
          strerr_warn4(WARNING,"unable to control ",dir,": ",&strerr_sys);
      else {
        ndelay_off(fd);
        buffer_init(&b,buffer_unixwrite,fd,bspace,sizeof bspace);
        if (buffer_putflush(&b,data,datalen) == -1)
          strerr_warn4(WARNING,"error writing commands to ",dir,": ",&strerr_sys);
        close(fd);
      }
    }
    if (fchdir(fdorigdir) == -1)
      strerr_die2sys(111,FATAL,"unable to set directory: ");
  }

  _exit(0);
}
Exemple #6
0
void usage() {
  strerr_die1x(100,
               "\n"
               "svstart: usage: svstart [ options ] path [ ... pathN ]\n"
               "\n"
               "  -h  help\n"
               "  -L  only start log\n"
               "  -l  start log\n"
               "  -Q  print errors   (default)\n"
               "  -q  quiet\n"
               "  -v  verbose\n"
               "\n"
               "  path: path to the service directory.\n"
              );
}
Exemple #7
0
int main(int argc,char **argv)
{
  umask(077);
  if (!argv[1])
    strerr_die1x(100,"maildirmake: usage: maildirmake name");
  if (mkdir(argv[1],0700) == -1)
    strerr_die4sys(111,FATL,"unable to mkdir ",argv[1],": ");
  if (chdir(argv[1]) == -1)
    strerr_die4sys(111,FATL,"unable to chdir to ",argv[1],": ");
  if (mkdir("tmp",0700) == -1)
    strerr_die4sys(111,FATL,"unable to mkdir ",argv[1],"/tmp: ");
  if (mkdir("new",0700) == -1)
    strerr_die4sys(111,FATL,"unable to mkdir ",argv[1],"/new: ");
  if (mkdir("cur",0700) == -1)
    strerr_die4sys(111,FATL,"unable to mkdir ",argv[1],"/cur: ");
  return(0);
}
Exemple #8
0
int main(int argc,const char *const *argv,const char *const *envp)
{
  account = *++argv;
  if (!account || !*++argv)
    strerr_die1x(100,"setuidgid: usage: setuidgid account child");

  pw = getpwnam(account);
  if (!pw)
    strerr_die3x(111,FATAL,"unknown account ",account);

  if (prot_gid(pw->pw_gid) == -1)
    strerr_die2sys(111,FATAL,"unable to setgid: ");
  if (prot_uid(pw->pw_uid) == -1)
    strerr_die2sys(111,FATAL,"unable to setuid: ");

  pathexec_run(*argv,argv,envp);
  strerr_die4sys(111,FATAL,"unable to run ",*argv,": ");
}
Exemple #9
0
int main(int argc,const char * const *argv,const char * const *envp)
{
  char ch;
  int wstat;
  int pi[2];
  int i;
  int ignored;

  if (!argv[1])
    strerr_die1x(100,"fghack: usage: fghack child");

  if (pipe(pi) == -1)
    strerr_die2sys(111,FATAL,"unable to create pipe: ");

  switch(pid = fork()) {
    case -1:
      strerr_die2sys(111,FATAL,"unable to fork: ");
    case 0:
      close(pi[0]);
      for (i = 0;i < 30;++i)
        ignored = dup(pi[1]);
      pathexec_run(argv[1],argv + 1,envp);
      strerr_die4sys(111,FATAL,"unable to run ",argv[1],": ");
  }

  close(pi[1]);

  for (;;) {
    i = buffer_unixread(pi[0],&ch,1);
    if ((i == -1) && (errno == error_intr)) continue;
    if (i == 1) continue;
    break;
  }

  if (wait_pid(&wstat,pid) == -1)
    strerr_die2sys(111,FATAL,"wait failed: ");
  if (wait_crashed(wstat))
    strerr_die2x(111,FATAL,"child crashed");
  _exit(wait_exitcode(wstat));
}
Exemple #10
0
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 do_ed(char *action)
{
  datetime_sec u;
  int flaggoodfield;
  int fd;
  char *x, *y;
  char *cp,*cplast,*cpnext,*cpafter;
  int flagdone;
  unsigned int len;
  const char *fname;
  unsigned int i;

  x = action + LENGTH_ED;
  x += scan_ulong(x,&u);
  if ((u > when) || (u < when - 100000)) die_cookie();
  if (*x == '.') ++x;
  fname = x;
  x += str_chr(x,'.');
  if (!*x) die_cookie();
  *x = (char) 0;
  ++x;
  stralloc_copys(&fnedit,"text/");
  stralloc_cats(&fnedit,fname);
  stralloc_0(&fnedit);
  y = fnedit.s + 5;		/* after "text/" */
  while (*++y) {		/* Name should be guaranteed by the cookie, */
				/* but better safe than sorry ... */
    if (((*y > 'z') || (*y < 'a')) && (*y != '_'))
      strerr_die2x(100,FATAL,MSG(ERR_BAD_NAME));
    if (*y == '_') *y = '-';
  }

  lock();			/* file must not change while here */

  switch (slurp(fnedit.s,&text,1024)) {
  case -1:
    strerr_die2sys(111,FATAL,MSG1(ERR_READ,fnedit.s));
  case 0:
    strerr_die5x(100,FATAL,dir,"/",fnedit.s,MSG(ERR_NOEXIST));
  }
  stralloc_copy(&line,&text);

  subst_nuls(&line);

  stralloc_cat(&line,&fnedit);	/* including '\0' */
  strnum[fmt_ulong(strnum,(unsigned long) u)] = 0;
  cookie(hash,key.s,key.len,strnum,line.s,"-e");
  if (str_len(x) != COOKIE) die_cookie();
  if (byte_diff(hash,COOKIE,x)) die_cookie();
	/* cookie is ok, file exists, lock's on, new file ends in '_' */
  stralloc_copys(&fneditn,fnedit.s);
  stralloc_append(&fneditn,'_');
  stralloc_0(&fneditn);
  fd = open_trunc(fneditn.s);
  if (fd == -1)
    strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fneditn.s));
  substdio_fdbuf(&sstext,write,fd,textbuf,sizeof(textbuf));
  stralloc_copys(&quoted,"");	/* clear */
  stralloc_copys(&text,"");

  for (;;) {			/* get message body */
    if (getln(&ssin,&line,&match,'\n') == -1)
      strerr_die2sys(111,FATAL,MSG(ERR_READ_INPUT));
    if (!match) break;
    stralloc_cat(&text,&line);
  }
  if (encin) {			/* decode if necessary */
    if (encin == 'B')
      decodeB(text.s,text.len,&line);
    else
      decodeQ(text.s,text.len,&line);
    stralloc_copy(&text,&line);
  }
  cp = text.s;
  cpafter = text.s+text.len;
  flaggoodfield = 0;
  flagdone = 0;
  len = 0;
  while ((cpnext = cp + byte_chr(cp,cpafter-cp,'\n')) != cpafter) {
    i = byte_chr(cp,cpnext-cp,'%');
    if (i != (unsigned int) (cpnext - cp)) {
      if (!flaggoodfield) {	/* MSG(TXT_EDIT_START)/END */
	if (case_startb(cp+i,cpnext-cp-i,MSG(TXT_EDIT_START))) {
		/* start tag. Store users 'quote characters', e.g. '> ' */
	  stralloc_copyb(&quoted,cp,i);
	  flaggoodfield = 1;
	  cp = cpnext + 1;
	  continue;
	}
      } else
	if (case_startb(cp+i,cpnext-cp-i,MSG(TXT_EDIT_END))) {
	  flagdone = 1;
	  break;
	}
    }
    if (flaggoodfield) {
      if ((len += cpnext - cp - quoted.len + 1) > MAXEDIT)
	strerr_die1x(100,MSG(ERR_EDSIZE));

      if (quoted.len && cpnext-cp >= (int) quoted.len &&
	  !str_diffn(cp,quoted.s,quoted.len))
	cp += quoted.len;	/* skip quoting characters */
      cplast = cpnext - 1;
      if (*cplast == '\r')	/* CRLF -> '\n' for base64 encoding */
	*cplast = '\n';
      else
	++cplast;
      if (substdio_put(&sstext,cp,cplast-cp+1) == -1)
	strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fneditn.s));
    }
    cp = cpnext + 1;
  }
  if (!flagdone)
    strerr_die2x(100,FATAL,MSG(ERR_NO_MARK));
  if (substdio_flush(&sstext) == -1)
    strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fneditn.s));
  if (fsync(fd) == -1)
    strerr_die2sys(111,FATAL,MSG1(ERR_SYNC,fneditn.s));
  if (fchmod(fd, 0600) == -1)
    strerr_die2sys(111,FATAL,MSG1(ERR_CHMOD,fneditn.s));
  if (close(fd) == -1)
    strerr_die2sys(111,FATAL,MSG1(ERR_CLOSE,fneditn.s));
  wrap_rename(fneditn.s,fnedit.s);

  unlock();
  hdr_subject(MSG1(SUB_EDIT_SUCCESS,fname));
  hdr_ctboundary();
  copy(&qq,"text/top",flagcd);
  copy_act("text/edit-done");
  copybottom(0);
  qmail_to(&qq,sender);		/* not necessarily from mod */
}
Exemple #12
0
void usage() {
  strerr_die1x(100,
               "\n"
               "check_supervise: usage: check_supervise path\n"
              );
}
static int get_act_ismod(const char *action,unsigned int *actlen)
{
  int act;

  if (case_equals(action,ACTION_LISTN) ||
		case_equals(action,ALT_LISTN))
    act = AC_LISTN;
  else if (case_equals(action,ACTION_LIST) ||
		case_equals(action,ALT_LIST))
    act = AC_LIST;
  else if (case_starts(action,ACTION_GET) ||
		case_starts(action,ALT_GET))
    act = AC_GET;
  else if (case_equals(action,ACTION_HELP) ||
		case_equals(action,ALT_HELP))
    act = AC_HELP;
  else if (case_starts(action,ACTION_EDIT) ||
		case_starts(action,ALT_EDIT))
    act = AC_EDIT;
  else if (case_starts(action,ACTION_LOG))
    { act = AC_LOG; *actlen = str_len(ACTION_LOG); }
  else if (case_starts(action,ALT_LOG))
    { act = AC_LOG; *actlen = str_len(ALT_LOG); }
  else
    act = AC_NONE;

  if (modsub.s != 0 || remote.s != 0) {
    if (modsub.len) {
      stralloc_copy(&moddir,&modsub);
    } else if (remote.len) {
      stralloc_copy(&moddir,&remote);
    } else {
      stralloc_copys(&moddir,"mod");
    }
    stralloc_0(&moddir);
		/* for these the reply is 'secret' and goes to sender  */
		/* This means that they can be triggered from a SENDER */
		/* that is not a mod, but never send to a non-mod */
    if (act == AC_NONE || flagdig == FLD_DENY)	/* None of the above */
      ismod = issub(moddir.s,sender,&mod);
				/* sender = moderator? */
    else
      ismod = issub(moddir.s,target.s,&mod);
				/* target = moderator? */
   } else
     ismod = 0;			/* always 0 for non-mod/remote lists */
				/* if DIR/public is missing, we still respond*/
				/* to requests from moderators for remote    */
				/* admin and modsub lists. Since ismod   */
				/* is false for all non-mod lists, only it   */
				/* needs to be tested. */

  if (!flagpublic && !(ismod && remote.s != 0) &&
                !case_equals(action,ACTION_HELP))
      strerr_die2x(100,FATAL,MSG(ERR_NOT_PUBLIC));

  if (flagdig == FLD_DENY)
    if (!ismod || remote.s == 0)	/* only mods can do */
      strerr_die1x(100,MSG(ERR_NOT_ALLOWED));

  if (act == AC_NONE) {		/* none of the above */
    if (case_equals(action,ACTION_SUBSCRIBE) ||
		case_equals(action,ALT_SUBSCRIBE))
      act = AC_SUBSCRIBE;
    else if (case_equals(action,ACTION_UNSUBSCRIBE)
		|| case_equals(action,ALT_UNSUBSCRIBE))
      act = AC_UNSUBSCRIBE;
    else if (str_start(action,ACTION_SC))
      act = AC_SC;
  }
  return act;
}
Exemple #14
0
void usage() {
  strerr_die1x(100, "\ncdbmake: usage: cdbmake path tmp\n");
}
Exemple #15
0
static void err_usage()
{
    strerr_die1x(100,"crypto-box-keypair: usage: crypto-box-keypair publickeyfile secretkeyfile");
}
Exemple #16
0
void die_usage()
{
  strerr_die1x(100,"tinydns-edit: usage: tinydns-edit data data.new add [ns|childns|host|alias|mx] domain a.b.c.d\n"
                   "tinydns-edit: usage: tinydns-edit data data.new add [host6|alias6] domain a:b:c:d:e:f:g:h");
}
Exemple #17
0
void die_usage(void)
{
  strerr_die1x(111,"cdbget: usage: cdbget key [skip]");
}
Exemple #18
0
void die_usage()
{
  strerr_die1x(100,"ezmlm-make: usage: ezmlm-make [ -aApP ] dir dot local host");
}
Exemple #19
0
void die_usage(void)
{
  strerr_die1x(100,USAGE);
}
Exemple #20
0
static void usage()
{
  strerr_die1x(100,"setuser: usage: setuser account child");
}
Exemple #21
0
void sigalrm ()
{
  tryunlinktmp();
  strerr_die1x(111,"Timeout on maildir delivery. (#4.3.0)");
}
Exemple #22
0
void usage(void)
{
  strerr_die1x(100,"dnsq: usage: dnsq type name server");
}
void usage(void)
{
  strerr_die1x(100,"didentd-static-conf: usage: didentd-static-conf acct logacct /didentd-static myip");
}
Exemple #24
0
static void usage (void)
{
    strerr_die1x(PERM, "qmail-pop3d-conf: usage: qmail-pop3d-conf checkpassword logacct /pop3d [ ip ]");
}
Exemple #25
0
void usage() { strerr_die1x(100,"tomaildir: usage: tomaildir dir"); }
Exemple #26
0
void usage(void)
{
  strerr_die1x(100,"dnstrace: usage: dnstrace type name rootip ...");
}
static void err_usage()
{
    strerr_die1x(100,"crypto-secretbox-key: usage: crypto-secretbox-key secretkeyfile");
}
Exemple #28
0
void usage(void)
{
  strerr_die1x(100,"walldns-conf: usage: walldns-conf acct logacct /walldns myip");
}
void usage(void)
{
  strerr_die1x(100,"pickdns-conf: usage: pickdns-conf acct logacct /pickdns myip");
}
Exemple #30
0
void usage(void)
{
  strerr_die1x(100,"tinydns-get: usage: tinydns-get type name [ip]");
}