Ejemplo n.º 1
0
void normal_bottom(char format)
/* Copies bottom text and the original message to the new message */
{
  if (flagbottom) {
    copy(&qq,"text/bottom",flagcd);
    if (flagcd && format != RFC1153) {
      if (flagcd == 'B') {
	encodeB("",0,&line,2);	/* flush */
	qmail_put(&qq,line.s,line.len);
      }
      hdr_boundary(0);
      hdr_ctype(CTYPE_MESSAGE);
      hdr_adds("Content-Disposition: inline; filename=request.msg");
      qmail_puts(&qq,"\n");
    }
    qmail_puts(&qq,"Return-Path: <");
    if (!quote2(&quoted,sender)) die_nomem();
    qmail_put(&qq,quoted.s,quoted.len);
    qmail_puts(&qq,">\n");
    if (seek_begin(0) == -1)
      strerr_die2sys(111,FATAL,MSG(ERR_SEEK_INPUT));
    if (qmail_copy(&qq,&ssin2,copylines) != 0)
      strerr_die2sys(111,FATAL,MSG(ERR_READ_INPUT));
  } else {
    if (flagcd == 'B' && format != RFC1153) {
      encodeB("",0,&line,2);	/* flush */
      qmail_put(&qq,line.s,line.len);
    }
  }
}
Ejemplo n.º 2
0
void write_ulong(unsigned long num,unsigned long cum,unsigned long dat,
		 const char *fn,const char *fnn)
/* write num to "fnn" add ':' & cum if cum <>0, then move "fnn" to "fn" */
{
  int fd;

  fd = open_trunc(fnn);
  if (fd == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_CREATE,fnn));
  substdio_fdbuf(&ssnum,write,fd,numbuf,sizeof(numbuf));
  if (substdio_put(&ssnum,strnum,fmt_ulong(strnum,num)) == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fnn));
  if (substdio_puts(&ssnum,":") == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fnn));
  if (substdio_put(&ssnum,strnum,fmt_ulong(strnum,cum)) == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fnn));
  if (dat) {
    if (substdio_puts(&ssnum,":") == -1)
       strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fnn));
    if (substdio_put(&ssnum,strnum,fmt_ulong(strnum,dat)) == -1)
       strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fnn));
  }
  if (substdio_puts(&ssnum,"\n") == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fnn));
  if (substdio_flush(&ssnum) == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_FLUSH,fnn));
  if (fsync(fd) == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_SYNC,fnn));
  if (close(fd) == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_CLOSE,fnn));
  wrap_rename(fnn,fn);
}
Ejemplo n.º 3
0
main()
{
  char *x;
  int udp53;

  x = env_get("IP");
  if (!x)
    strerr_die2x(111,fatal,"$IP not set");
  if (!ip4_scan(x,ip))
    strerr_die3x(111,fatal,"unable to parse IP address ",x);

  udp53 = socket_udp();
  if (udp53 == -1)
    strerr_die2sys(111,fatal,"unable to create UDP socket: ");
  if (socket_bind4_reuse(udp53,ip,53) == -1)
    strerr_die2sys(111,fatal,"unable to bind UDP socket: ");

  droproot(fatal);

  initialize();
  
  ndelay_off(udp53);
  socket_tryreservein(udp53,65536);

  for (;;) {
    len = socket_recv4(udp53,buf,sizeof buf,ip,&port);
    if (len < 0) continue;
    if (!doit()) continue;
    if (response_len > 512) response_tc();
    socket_send4(udp53,response,response_len,ip,port);
    /* may block for buffer space; if it fails, too bad */
  }
}
Ejemplo n.º 4
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],": ");
}
Ejemplo n.º 5
0
int main(int argc, char **argv, char **envp) {
  uint8_t buf[1024];
  cdb_t cdb;
  char *key;
  uint32_t len;
  uint32_t r;
  uint32_t pos;
  uint32_t skip = 0;
  char *skip_str;
  
  if (!*argv || !*++argv)
    usage();
  key = *argv;
  
  skip_str = *++argv;
  if (skip_str) {
    if (sscanf(skip_str, "%" PRIu32, &skip) != strlen(skip_str))
      usage();
  }
  
  /* Initialize the cdb struct using stdin as it's file descriptor. */
  if (cdb_init(&cdb, 0) == -1)
    strerr_die2x(111, FATAL, "failed to initialize cdb");
    
  for (;;) {
    r = cdb_find_next(&cdb, key, strlen(key));
    if (r == -1)
      strerr_die2sys(111, FATAL, "unable to read input: ");
    if (!r)
      _exit(100);
      
    if (!skip)
      break;
    skip--;
  }
  
  /* If there's a record in the cdb file, then the cdb structs dlen property
   * will be set to a non-zero value and it's position will be set to the
   * offset in the file containing the data.  Read the data in chunks and send
   * it to stdout. */
  len = cdb.dlen;
  pos = cdb.dpos;
  while (len > 0) {
    r = sizeof(buf);
    if (r > len)
      r = len;
    if (cdb_read(buf, r, &cdb, pos) == -1)
      strerr_die2sys(111, FATAL, "unable to read input: ");
    if (bio_put(bio_1, buf, r) == -1)
      strerr_die2sys(111, FATAL, "unable to write output: ");
    pos += r;
    len -= r;
  }
  if (bio_flush(bio_1) == -1)
    strerr_die2sys(111, FATAL, "unable to write output: ");
    
  cdb_free(&cdb);
  
  return 0;
}
Ejemplo n.º 6
0
void copybottom(int forcebottom)
{
  if (!omitbottom || forcebottom) {
    copy(&qq,"text/bottom",flagcd);
    if (flagcd) {
      if (flagcd == 'B') {
	encodeB("",0,&line,2);	/* flush */
	qmail_put(&qq,line.s,line.len);
      }
      hdr_boundary(0);
      hdr_ctype(CTYPE_MESSAGE);
      hdr_adds("Content-Disposition: inline; filename=request.msg");
      qmail_puts(&qq,"\n");
    }
    qmail_puts(&qq,"Return-Path: <");
    quote2(&quoted,sender);
    qmail_put(&qq,quoted.s,quoted.len);
    qmail_puts(&qq,">\n");
    if (seek_begin(0) == -1)
      strerr_die2sys(111,FATAL,MSG(ERR_SEEK_INPUT));
    if (qmail_copy(&qq,&ssin2,copylines) != 0)
      strerr_die2sys(111,FATAL,MSG(ERR_READ_INPUT));
    if (flagcd)
      hdr_boundary(1);
  } else {
    if (flagcd == 'B') {
      encodeB("",0,&line,2);	/* flush even if no bottom */
      qmail_put(&qq,line.s,line.len);
    }
  }

  qmail_from(&qq,from.s);
}
Ejemplo n.º 7
0
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);
}
Ejemplo n.º 8
0
void didentd_init()
{
  char *x;
  unsigned long id;

  x = env_get("ROOT");
  if (!x)
     strerr_die2x(111,FATAL,"$ROOT not set");
  if (chdir(x) == -1)
    strerr_die4sys(111,FATAL,"unable to chdir to ",x,": ");

  x = env_get("GID");
  if (!x)
    strerr_die2x(111,FATAL,"$GID not set");
  scan_ulong(x,&id);
  if (prot_gid((int) id) == -1)
    strerr_die2sys(111,FATAL,"unable to setgid: ");

  x = env_get("UID");
  if (!x)
    strerr_die2x(111,FATAL,"$UID not set");
  scan_ulong(x,&id);
  if (prot_uid((int) id) == -1)
    strerr_die2sys(111,FATAL,"unable to setuid: ");
}
Ejemplo n.º 9
0
void didentd_init()
{
  /* chroot() to /proc/net/ and switch to $UID:$GID */
  char *x;
  unsigned long id;

  if (chdir("/proc/net/") == -1)
    strerr_die2sys(111,FATAL,"unable to chdir to '/proc/net/': ");
  if (chroot(".") == -1)
    strerr_die2sys(111,FATAL,"unable to chdir to '/proc/net/': ");

  x = env_get("GID");
  if (!x)
    strerr_die2x(111,FATAL,"$GID not set");
  scan_ulong(x,&id);
  if (prot_gid((int) id) == -1)
    strerr_die2sys(111,FATAL,"unable to setgid: ");

  x = env_get("UID");
  if (!x)
    strerr_die2x(111,FATAL,"$UID not set");
  scan_ulong(x,&id);
  if (prot_uid((int) id) == -1)
    strerr_die2sys(111,FATAL,"unable to setuid: ");
}
Ejemplo n.º 10
0
static void do_get(const char *action)
{
  unsigned long u;
  struct stat st;
  char ch;
  int r;
  unsigned int pos;
  int fd;

  if (!flagget)
    strerr_die2x(100,FATAL,MSG(ERR_NOT_AVAILABLE));
  hdr_subject(MSG(SUB_GET_MSG));
  hdr_ctboundary();
  copy(&qq,"text/top",flagcd);

  pos = str_len(ACTION_GET);
  if (!case_starts(action,ACTION_GET))
    pos = str_len(ALT_GET);

  if (action[pos] == '.' || action [pos] == '_') pos++;
  scan_ulong(action + pos,&u);

  stralloc_copys(&line,"archive/");
  stralloc_catb(&line,strnum,fmt_ulong(strnum,u / 100));
  stralloc_cats(&line,"/");
  stralloc_catb(&line,strnum,fmt_uint0(strnum,(unsigned int) (u % 100),2));
  stralloc_0(&line);

  fd = open_read(line.s);
  if (fd == -1)
    if (errno != error_noent)
      strerr_die2sys(111,FATAL,MSG1(ERR_OPEN,line.s));
    else
      copy_act("text/get-bad");
  else {
    if (fstat(fd,&st) == -1)
      copy_act("text/get-bad");
    else if (!(st.st_mode & 0100))
      copy_act("text/get-bad");
    else {
      showsend("get");
      substdio_fdbuf(&sstext,read,fd,textbuf,sizeof(textbuf));
      qmail_puts(&qq,"> ");
      for (;;) {
	r = substdio_get(&sstext,&ch,1);
	if (r == -1) strerr_die2sys(111,FATAL,MSG1(ERR_READ,line.s));
	if (r == 0) break;
	qmail_put(&qq,&ch,1);
	if (ch == '\n') qmail_puts(&qq,"> ");
      }
      qmail_puts(&qq,"\n");
    }
    close(fd);
  }
  copybottom(0);
  qmail_to(&qq,target.s);
}
Ejemplo n.º 11
0
void f_close(void)
{
  if (substdio_flush(&ss) == -1)
    strerr_die2sys(111,FATAL,MSG1(ERR_FLUSH,dirplus.s));
  if (fsync(ss.fd) == -1)
    strerr_die2sys(111,FATAL,MSG1(ERR_SYNC,dirplus.s));
  if (close(ss.fd) == -1) /* NFS stupidity */
    strerr_die2sys(111,FATAL,MSG1(ERR_CLOSE,dirplus.s));
  keyaddtime();
}
Ejemplo n.º 12
0
void close_proper(substdio *ss,const char *s,const char *sn)
/* flush,sync,close,move sn->s) */
{
   if (substdio_flush(ss) == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_FLUSH,s));
  if (flagsync)
    if (fsync(ss->fd) == -1)
       strerr_die2sys(111,FATAL,MSG1(ERR_SYNC,s));
  if (close(ss->fd) == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_CLOSE,s));
  wrap_rename(sn,s);
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
const char *get_from(const char *adr, /* target address */
		     const char *act) /* action */
/* If we captured a from line, it will be from the subscriber, except   */
/* when -S is used when it's usually from the subscriber, but of course */
/* could be from anyone. The matching to stored data is required only   */
/* to support moderated lists, and in cases where a new -sc is issued   */
/* because an old one was invalid. In this case, we read through the    */
/* from file trying to match up a timestamp with that starting in       */
/* *(act+3). If the time stamp matches, we compare the target address   */
/* itself. act + 3 must be a legal part of the string returns pointer to*/
/* fromline, NULL if not found. Since the execution time from when to   */
/* storage may differ, we can't assume that the timestamps are in order.*/
{
  int fd;
  const char *fl;
  unsigned int pos;
  unsigned long thistime;
  unsigned long linetime;

  if (!flagstorefrom) return 0;
  if (fromline.len) {	/* easy! We got it in this message */
    stralloc_0(&fromline);
    return fromline.s;
  }			/* need to recover it from DIR/from */
  fl = 0;
  (void) scan_ulong(act+3,&thistime);
  if ((fd = open_read("from")) == -1) {
    if (errno == error_noent)
      return 0;
    else
      strerr_die2sys(111,FATAL,MSG1(ERR_READ,"from"));
  }
  substdio_fdbuf(&sstext,read,fd,textbuf,(int) sizeof(textbuf));
  for (;;) {
    if (getln(&sstext,&fromline,&match,'\n') == -1)
      strerr_die2sys(111,FATAL,MSG1(ERR_READ,"from"));
    if (!match) break;
    fromline.s[fromline.len - 1] = (char) 0;
	/* now:time addr\0fromline\0 read all. They can be out of order! */
    pos = scan_ulong(fromline.s,&linetime);
    if (linetime != thistime) continue;
    if (!str_diff(fromline.s + pos + 1,adr)) {
      pos = str_len(fromline.s);
      if (pos < fromline.len) {
	fl = fromline.s + pos + 1;
	break;
      }
    }
  }
  close(fd);
  return fl;
}
Ejemplo n.º 15
0
void linkdotdir(const char *dash,const char *slash)
{
  stralloc_copy(&dotplus,&dot);
  stralloc_cats(&dotplus,dash);
  stralloc_0(&dotplus);
  dirplusmake(slash);
  if (flags['e' - 'a'])
    if (unlink(dotplus.s) == -1)
      if (errno != error_noent)
        strerr_die2sys(111,FATAL,MSG1(ERR_DELETE,dotplus.s));
  if (symlink(dirplus.s,dotplus.s) == -1)
    strerr_die2sys(111,FATAL,MSG1(ERR_CREATE,dotplus.s));
  keyaddtime();
}
Ejemplo n.º 16
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);
}
Ejemplo n.º 17
0
main()
{
  int pid;
  int wstat;
  char ch;

  sig_ignore(sig_pipe);

  pid = fork();
  if (pid == -1) strerr_die2sys(111,"mconnect-io: fatal: ","unable to fork: ");

  if (!pid) {
    buffer_init(&bin,myread,0,inbuf,sizeof inbuf);
    buffer_init(&bout,write,7,outbuf,sizeof outbuf);

    while (buffer_get(&bin,&ch,1) == 1) {
      if (ch == '\n') buffer_put(&bout,"\r",1);
      buffer_put(&bout,&ch,1);
    }
    _exit(0);
  }

  buffer_init(&bin,myread,6,inbuf,sizeof inbuf);
  buffer_init(&bout,write,1,outbuf,sizeof outbuf);

  while (buffer_get(&bin,&ch,1) == 1)
    buffer_put(&bout,&ch,1);

  kill(pid,sig_term);
  wait_pid(&wstat,pid);

  _exit(0);
}
Ejemplo n.º 18
0
void f_init(char **script)
{
  int i;
  int fd;

  for (i = 0;script[i];++i)
    ;

  f = (int *) alloc(i * sizeof(*f));
  if (!f) strerr_die2x(111,FATAL,"out of memory");

  for (i = 0;script[i];++i) {
    fd = -1;
    if (script[i][0] == '=') {
      if (fchdir(fdstartdir) == -1)
        strerr_die2sys(111,FATAL,"unable to switch to starting directory: ");
      fd = open_append(script[i] + 1);
      if (fd == -1)
        strerr_die4sys(111,FATAL,"unable to create ",script[i] + 1,": ");
      close(fd);
      fd = open_write(script[i] + 1);
      if (fd == -1)
        strerr_die4sys(111,FATAL,"unable to write ",script[i] + 1,": ");
      coe(fd);
    }
    f[i] = fd;
  }
}
Ejemplo n.º 19
0
void get(stralloc *sa)
{
  int match;
  if (getln(subfdin,sa,&match,'\n') == -1)
    strerr_die2sys(111,FATAL,MSG(ERR_READ_INPUT));
  if (!match) _exit(0);
}
Ejemplo n.º 20
0
void frm(const char *slash)
{
  dirplusmake(slash);
  if (unlink(dirplus.s) == -1)
    if (errno != error_noent)
    strerr_die2sys(111,FATAL,MSG1(ERR_DELETE,dirplus.s));
}
Ejemplo n.º 21
0
static int execute_line(const char *fn,const char *line)
{
  int child;
  int code;
  if (seek_begin(0) == -1)
    strerr_die2sys(111,FATAL,MSG(ERR_SEEK_INPUT));
  while (*line
	 && (*line == '\t'
	     || *line == ' '))
      ++line;
  switch (*line) {
  case '#':
    /* ignore comments */
    return 0;
  case '|':
    if ((child = wrap_fork()) == 0)
      wrap_execsh(line+1);
    code = wrap_waitpid(child);
    ++did_program;
    return code;
  case '/':
  case '.':
    strerr_die5x(100,FATAL,basedir.s,"/",fn,": Delivery to files is not supported.");
    return 100;
  default:
    if (*line == '&')
      ++line;
    forward(line);
    return 0;
  }
}
Ejemplo n.º 22
0
static void flushit(int fd)
{
  if (fd > 0)
    if (substdio_flush(&ssarchive) == -1
	|| fchmod(fd,MODE_ARCHIVE|0700) == -1
	|| close(fd) == -1)
      strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fnaf.s));
}
Ejemplo n.º 23
0
int wrap_stat(const char *fn,struct stat *st)
{
  int r;
  if ((r = stat(fn,st)) == -1
      && errno != error_noent)
    strerr_die2sys(111,FATAL,MSG1(ERR_STAT,fn));
  return r;
}
Ejemplo n.º 24
0
void dcreate(const char *slash)
{
  dirplusmake(slash);
  if (mkdir(dirplus.s,0755) == -1)
    if ((errno != error_exist) || !flags['e' - 'a'])
      strerr_die2sys(111,FATAL,MSG1(ERR_CREATE,dirplus.s));
  keyaddtime();
}
Ejemplo n.º 25
0
static int open_template(stralloc *fn)
{
  int fd;
  struct stat st;
  stralloc_0(fn);
  if (stat(fn->s,&st) == -1)
    strerr_die2sys(111,FATAL,MSG1(ERR_STAT,fn->s));
  if (S_ISDIR(st.st_mode)) {
    --fn->len;
    stralloc_cats(fn,TXT_EZMLMRC);
    stralloc_0(fn);
  }
  if ((fd = open_read(fn->s)) == -1) {
    if (errno != error_noent)
      strerr_die2sys(111,FATAL,MSG1(ERR_OPEN,fn->s));
    else
      strerr_die3x(100,FATAL,template.s,MSG(ERR_NOEXIST));
Ejemplo n.º 26
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,": ");
}
Ejemplo n.º 27
0
void read_passwd(void) {
  if (!password.len) {
    buffer_init(&b,buffer_unixread,3,bspace,sizeof bspace);
    if (getln(&b,&password,&match,'\0') == -1)
      strerr_die2sys(111,FATAL,"unable to read password: ");
    close(3);
    if (match) --password.len;
  }
}
Ejemplo n.º 28
0
void defaultsoa_init(int fd)
{
  struct stat st;
  if (fstat(fd,&st) == -1)
    strerr_die2sys(111,FATAL,"unable to stat data: ");
  uint32_pack_big(defaultsoa,st.st_mtime);
  if (byte_equal(defaultsoa,4,"\0\0\0\0"))
    defaultsoa[3] = 1;
  byte_copy(defaultsoa + 4,16,"\0\0\100\000\0\0\010\000\0\020\000\000\0\0\012\000");
}
Ejemplo n.º 29
0
int exists(const char *dpm)
{
  struct stat st;
  dirplusmake(dpm);
  if (stat(dirplus.s,&st) == -1) {
    if (errno == error_noent)
      return 0;
    strerr_die2sys(111,FATAL,MSG1(ERR_STAT,dirplus.s));
  }
  return 1;
}
Ejemplo n.º 30
0
void doit(int resource,const char *arg)
{
  unsigned long u;
  struct rlimit r;

  if (getrlimit(resource,&r) == -1)
    strerr_die2sys(111,FATAL,"getrlimit failed: ");

  if (str_equal(arg,"="))
    r.rlim_cur = r.rlim_max;
  else {
    if (arg[scan_ulong(arg,&u)]) die_usage();
    r.rlim_cur = u;
    if (r.rlim_cur > r.rlim_max)
      r.rlim_cur = r.rlim_max;
  }

  if (setrlimit(resource,&r) == -1)
    strerr_die2sys(111,FATAL,"setrlimit failed: ");
}