Beispiel #1
0
const char* ucspi_getenv(const char* name)
{
  if (ucspi_protocol() == 0)
    return 0;
  strncpy(vartmp + protolen, name, MAXNAME);
  return getenv(vartmp);
}
Beispiel #2
0
int main(int argc, char* argv[])
{
  str packet = {0,0,0};
  const char* s;
  uid_t euid = -1;
  const struct passwd* pw;

  if (chdir_bcron() != 0)
    respond("ZCould not change directory");

  if (argc > 1)
    fixup_argv = argv + 1;

  if ((s = ucspi_protocol()) == 0
      || (strcmp(s, "UNIX") != 0 && strcmp(s, "LOCAL") != 0)
      || (s = ucspi_getenv("REMOTEEUID")) == 0
      || (euid = strtoul(s, (char**)&s, 0)) == (unsigned)-1
      || *s != 0)
    respond("DConfiguration error: must be run from unixserver");
  if (!ibuf_getnetstring(&inbuf, &packet)
      || packet.len < 2)
    respond("ZInvalid input data or read error");
  /* Look up and validate username */
  username = packet.s + 1;
  if ((pw = getpwnam(username)) == 0)
    respond("DInvalid or unknown username");
  if (euid != 0 && euid != pw->pw_uid)
    respond("DUsername does not match invoking UID");
  if (!str_copy2s(&filename, CRONTAB_DIR "/", pw->pw_name))
    respond("ZCould not produce filename");
  logcmd(packet.s[0]);
  /* Execute the command. */
  switch (packet.s[0]) {
  case 'S': cmd_store(&packet); break;
  case 'L': cmd_list(); break;
  case 'R': cmd_remove(); break;
  case 'Y':
    if (euid != 0 && euid != getuid())
      respond("DOnly root or cron can list system crontabs");
    cmd_listsys();
    break;
  }
  respond("DInvalid command code");
  return 0;
}