Exemple #1
0
void detected(int code, const char *msg)
{
  char tmp[512] = "";
  struct flag_record fr = { FR_GLOBAL, 0, 0, 0 };
  int act = DET_WARN, do_fatal = 0, killbots = 0;
  
  if (code == DETECT_LOGIN)
    act = login;
  if (code == DETECT_TRACE)
    act = trace;
  if (code == DETECT_PROMISC)
    act = promisc;
#ifdef NOT_USED
  if (code == DETECT_PROCESS)
    act = badprocess;
#endif
  if (code == DETECT_HIJACK)
    act = hijack;

  switch (act) {
  case DET_IGNORE:
    break;
  case DET_WARN:
    putlog(LOG_WARN, "*", msg);
    break;
  case DET_REJECT:
    do_fork();
    putlog(LOG_WARN, "*", STR("Setting myself +d: %s"), msg);
    simple_snprintf(tmp, sizeof(tmp), "+d: %s", msg);
    set_user(&USERENTRY_COMMENT, conf.bot->u, tmp);
    fr.global = USER_DEOP;
    fr.bot = 1;
    set_user_flagrec(conf.bot->u, &fr, 0);
    sleep(1);
    break;
  case DET_DIE:
    putlog(LOG_WARN, "*", STR("Dying: %s"), msg);
    simple_snprintf(tmp, sizeof(tmp), STR("Dying: %s"), msg);
    set_user(&USERENTRY_COMMENT, conf.bot->u, tmp);
    if (!conf.bot->hub)
      nuke_server(STR("BBL"));
    sleep(1);
    killbots++;
    do_fatal++;
    break;
  case DET_SUICIDE:
    suicide(msg);
    break;
  }
  if (killbots && conf.bot->localhub) {
    conf_checkpids(conf.bots);
    conf_killbot(conf.bots, NULL, NULL, SIGKILL);
  }
  if (do_fatal)
    fatal(msg, 0);
}
Exemple #2
0
void chanprog()
{
  struct utsname un;


  sdprintf("I am: %s", conf.bot->nick);

  /* Add the 'default' virtual channel.
     The flags will be overwritten when the userfile is loaded,
     but if there is no userfile yet, or no 'default' channel,
     then it will take on the properties of 'def_chanset',
     and then later save this to the userfile.
   */
  channel_add(NULL, "default", def_chanset, 1);

  if (conf.bot->hub) {
    simple_snprintf(userfile, 121, "%s/.u", dirname(binname));
    loading = 1;
    checkchans(0);
    readuserfile(userfile, &userlist);
    checkchans(1);
    var_parse_my_botset();
    loading = 0;
  }

  load_internal_users();

  add_myself_to_userlist();

  if (conf.bot->localhub)
    add_child_bots();
  else if (!conf.bot->hub)
    add_localhub();

  rehash_ip();

  /* set our shell info */
  uname(&un);
  set_user(&USERENTRY_OS, conf.bot->u, un.sysname);
  set_user(&USERENTRY_USERNAME, conf.bot->u, conf.username);
  set_user(&USERENTRY_NODENAME, conf.bot->u, un.nodename);
  set_user(&USERENTRY_ARCH, conf.bot->u, un.machine);
  set_user(&USERENTRY_OSVER, conf.bot->u, un.release);

  var_parse_my_botset();

  /* We should be safe now */

  reaffirm_owners();
}
Exemple #3
0
static bool pass_set(struct userrec *u, struct user_entry *e, void *buf)
{
  char *newpass = NULL;
  register char *pass = (char *) buf;

  if (e->u.extra)
    free(e->u.extra);
  if (!pass || !pass[0] || (pass[0] == '-'))
    e->u.extra = NULL;
  else {
    unsigned char *p = (unsigned char *) pass;

    if (u->bot || (pass[0] == '+'))
      newpass = strdup(pass);
    else {
      while (*p) {
        if ((*p <= 32) || (*p == 127))
          *p = '?';
        p++;
      }
      newpass = salted_sha1(pass);
    }
    e->u.extra = strdup(newpass);
  }
  if (!noshare)
    shareout("c %s %s %s\n", e->type->name, u->handle, newpass ? newpass : "");
  if (newpass)
    free(newpass);

  /* clear old records */
  noshare = 1;
  set_user(&USERENTRY_PASS1, u, NULL);
  noshare = 0;
  return 1;
}
Exemple #4
0
/*
 * setuid() is implemented like SysV with SAVED_IDS 
 * 
 * Note that SAVED_ID's is deficient in that a setuid root program
 * like sendmail, for example, cannot set its uid to be a normal 
 * user and then switch back, because if you're root, setuid() sets
 * the saved uid too.  If you don't like this, blame the bright people
 * in the POSIX committee and/or USG.  Note that the BSD-style setreuid()
 * will allow a root program to temporarily drop privileges and be able to
 * regain them by swapping the real and effective uid.  
 */
asmlinkage long sys_setuid(uid_t uid)
{
	int old_euid = current->euid;
	int old_ruid, old_suid, new_ruid, new_suid;
	int retval;

	retval = security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_ID);
	if (retval)
		return retval;

	old_ruid = new_ruid = current->uid;
	old_suid = current->suid;
	new_suid = old_suid;
	
	if (capable(CAP_SETUID)) {
		if (uid != old_ruid && set_user(uid, old_euid != uid) < 0)
			return -EAGAIN;
		new_suid = uid;
	} else if ((uid != current->uid) && (uid != new_suid))
		return -EPERM;

	if (old_euid != uid)
	{
		current->mm->dumpable = 0;
		wmb();
	}
	current->fsuid = current->euid = uid;
	current->suid = new_suid;

	return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_ID);
}
Exemple #5
0
void update_mod(char *handle, char *nick, char *cmd, char *par)
{
  char tmp[100] = "";

  simple_snprintf(tmp, sizeof tmp, "%li, %s (%s %s)", (long) now, nick, cmd, (par && par[0]) ? par : "");
  set_user(&USERENTRY_MODIFIED, get_user_by_handle(userlist, handle), tmp);
}
Exemple #6
0
/*%
 * Write a key file to 'keyfile'.  If 'user' is non-NULL,
 * make that user the owner of the file.  The key will have
 * the name 'keyname' and the secret in the buffer 'secret'.
 */
void
write_key_file(const char *keyfile, const char *user,
	       const char *keyname, isc_buffer_t *secret,
	       dns_secalg_t alg) {
	isc_result_t result;
	const char *algname = alg_totext(alg);
	FILE *fd = NULL;

	DO("create keyfile", isc_file_safecreate(keyfile, &fd));

	if (user != NULL) {
		if (set_user(fd, user) == -1)
			fatal("unable to set file owner\n");
	}

	fprintf(fd, "key \"%s\" {\n\talgorithm %s;\n"
		"\tsecret \"%.*s\";\n};\n",
		keyname, algname,
		(int)isc_buffer_usedlength(secret),
		(char *)isc_buffer_base(secret));
	fflush(fd);
	if (ferror(fd))
		fatal("write to %s failed\n", keyfile);
	if (fclose(fd))
		fatal("fclose(%s) failed\n", keyfile);
	fprintf(stderr, "wrote key file \"%s\"\n", keyfile);
}
Exemple #7
0
/*
 * setuid() is implemented like SysV with SAVED_IDS 
 * 
 * Note that SAVED_ID's is deficient in that a setuid root program
 * like sendmail, for example, cannot set its uid to be a normal 
 * user and then switch back, because if you're root, setuid() sets
 * the saved uid too.  If you don't like this, blame the bright people
 * in the POSIX committee and/or USG.  Note that the BSD-style setreuid()
 * will allow a root program to temporarily drop privileges and be able to
 * regain them by swapping the real and effective uid.  
 */
asmlinkage long sys_setuid(uid_t uid)
{
	int old_euid = current->euid;
	int old_ruid, old_suid, new_suid;
	int retval;

	retval = security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_ID);
	if (retval)
		return retval;

	old_ruid = current->uid;
	old_suid = current->suid;
	new_suid = old_suid;
	
	if (capable(CAP_SETUID)) {
		if (uid != old_ruid && set_user(uid, old_euid != uid) < 0)
			return -EAGAIN;
		new_suid = uid;
	} else if ((uid != current->uid) && (uid != new_suid))
		return -EPERM;

	if (old_euid != uid) {
		set_dumpable(current->mm, suid_dumpable);
		smp_wmb();
	}
	current->fsuid = current->euid = uid;
	current->suid = new_suid;

	key_fsuid_changed(current);
	proc_id_connector(current, PROC_EVENT_UID);

	return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_ID);
}
Exemple #8
0
	void main(){
		int i;
		int read;

		while(1){
			data_sum=save_sum=0;
			printf("使用するユーザ名を入力して下さい\n");
			scanf("%s",login_user);

			set_user();
			set_cate();
			if(set_data(login_user)==-1)printf("データがありません\n");
			else{
				printf("%sさんのデータ\n",login_user);
				for(i=0;i<data_sum;i++){
					printf("%d/%d/%d ",data[i].year,data[i].month,data[i].day);
					printf("%s ",data[i].item);
					printf("%d ",data[i].cate);
					printf("%8d ",data[i].value);
					printf("%d\n",data[i].inout);
				}
				save_dat();
			}
			printf("\n続行-->1 終了-->2\n");
			scanf("%d",&read);
			if(read==2)break;
		}
	}
Exemple #9
0
static int
console_store(int idx, char *par, bool displaySave)
{
  struct console_info *i = (struct console_info *) get_user(&USERENTRY_CONSOLE, dcc[idx].user);

  if (!i) 
    i = (struct console_info *) my_calloc(1, sizeof(struct console_info));
  
  if (i->channel)
    free(i->channel);
  i->channel = strdup(dcc[idx].u.chat->con_chan);
  i->conflags = dcc[idx].u.chat->con_flags;
  i->stripflags = dcc[idx].u.chat->strip_flags;
  i->echoflags = (dcc[idx].status & STAT_ECHO) ? 1 : 0;
  if (dcc[idx].status & STAT_PAGE)
    i->page = dcc[idx].u.chat->max_line;
  else
    i->page = 0;
  if (dcc[idx].status & STAT_COLOR)
    i->color = 1;
  else
    i->color = 0;
  if (dcc[idx].status & STAT_BANNER)
    i->banner = 1;
  else
    i->banner = 0;
  if (dcc[idx].status & STAT_CHANNELS)
    i->channels = 1;
  else
    i->channels = 0;
  if (dcc[idx].status & STAT_BOTS)
    i->bots = 1;
  else
    i->bots = 0;
  if (dcc[idx].status & STAT_WHOM)
    i->whom = 1;
  else
    i->whom = 0;

  i->conchan = dcc[idx].u.chat->channel;
  if (par) {
    dprintf(idx, "%s\n", "Saved your Console Settings:");
    dprintf(idx, "  %s %s\n", "Channel:", i->channel);
    dprintf(idx, "  %s %s, %s %s, %s %s\n", "Console flags:",
            masktype(i->conflags), "",
            stripmasktype(i->stripflags), "Echo:", i->echoflags ? "yes" : "no");
    dprintf(idx, "  %s %d, %s %d\n", "Page setting:", i->page, "Console channel:", i->conchan);
    dprintf(idx, "    Color: $b%s$b\n", i->color ? "on" : "off");
    dprintf(idx, "    Login settings:\n");
    dprintf(idx, "    Login settings:\n");
    dprintf(idx, "     Banner:   $b%-3s$b   Bots: $b%-3s$b\n", i->banner ? "on" : "off", i->bots ? "on" : "off");
    dprintf(idx, "     Channels: $b%-3s$b   Whom: $b%-3s$b\n", i->channels ? "on" : "off", i->whom ? "on" : "off");

  }
  set_user(&USERENTRY_CONSOLE, dcc[idx].user, i);
  dprintf(idx, "Console setting stored.\n");
  if (conf.bot->hub)
    write_userfile(displaySave ? idx : -1);
  return 0;
}
Exemple #10
0
void stats_add(struct userrec *u, int islogin, int op)
{
  if (!u || u->bot)
    return;

  char *s = (char *) get_user(&USERENTRY_STATS, u), s2[50] = "";
  int sl, so;

  if (s) {
    strlcpy(s2, s, sizeof(s2));
  } else
    strlcpy(s2, "0 0", sizeof(s2));
  s = strchr(s2, ' ');
  if (s) {
    s++;
    so = atoi(s);
  } else
    so = 0;
  sl = atoi(s2);
  if (islogin)
    sl++;
  if (op)
    so++;
  simple_snprintf(s2, sizeof(s2), "%i %i", sl, so);
  set_user(&USERENTRY_STATS, u, s2);
}
static gboolean
hippo_block_blog_person_update_from_xml (HippoBlock           *block,
                                         HippoDataCache       *cache,
                                         LmMessageNode        *node)
{
    HippoBlockBlogPerson *block_blog_person = HIPPO_BLOCK_BLOG_PERSON(block);
    LmMessageNode *blog_node;
    HippoPerson *user;

    if (!HIPPO_BLOCK_CLASS(hippo_block_blog_person_parent_class)->update_from_xml(block, cache, node))
        return FALSE;

#if 0
    if (!hippo_xml_split(cache, node, NULL,
                         "blogPerson", HIPPO_SPLIT_NODE, &blog_node,
                         NULL))
        return FALSE;

    if (!hippo_xml_split(cache, blog_node, NULL,
                         "userId", HIPPO_SPLIT_PERSON, &user,
                         NULL))
        return FALSE;
    
    set_user(block_blog_person, user);
#endif
    
    return TRUE;
}
Exemple #12
0
int main(int argc, char *argv[]) {

	Irc freenode;
	struct pollfd pfd[4];
	int i, ready, murm_listenfd = -1;

	initialize(argc, argv);

	for (i = 0; i < SIZE(pfd); i++) {
		pfd[i].fd = -1;
		pfd[i].events = POLLIN;
	}
	if (add_murmur_callbacks(cfg.murmur_port))
		pfd[MURM_LISTEN].fd = murm_listenfd = sock_listen(LOCALHOST, CB_LISTEN_PORT_S);
	else
		fprintf(stderr, "Could not connect to Murmur\n");

	if ((pfd[MPD].fd = mpdfd = mpd_connect(cfg.mpd_port)) < 0)
		fprintf(stderr, "Could not connect to MPD\n");

	// Connect to server and set IRC details
	if (!(freenode = irc_connect(cfg.server, cfg.port)))
		exit_msg("Irc connection failed");

	pfd[IRC].fd = get_socket(freenode);
	set_nick(freenode, cfg.nick);
	set_user(freenode, cfg.user);
	for (i = 0; i < cfg.channels_set; i++)
		join_channel(freenode, cfg.channels[i]);

	while ((ready = poll(pfd, SIZE(pfd), TIMEOUT)) > 0) {
		// Keep reading & parsing lines as long the connection is active and act on any registered actions found
		if (pfd[IRC].revents & POLLIN)
			while (parse_irc_line(freenode) > 0);

		if (pfd[MURM_LISTEN].revents & POLLIN)
			if ((pfd[MURM_ACCEPT].fd = accept_murmur_connection(murm_listenfd)) > 0)
				pfd[MURM_LISTEN].fd = -1; // Stop listening for connections

		if (pfd[MURM_ACCEPT].revents & POLLIN) {
			if (!listen_murmur_callbacks(freenode, pfd[MURM_ACCEPT].fd)) {
				pfd[MURM_ACCEPT].fd = -1;
				pfd[MURM_LISTEN].fd = murm_listenfd; // Start listening again for Murmur connections
			}
		}
		if (pfd[MPD].revents & POLLIN)
			if (!print_song(freenode, default_channel(freenode)))
				pfd[MPD].fd = mpdfd = mpd_connect(cfg.mpd_port);
	}
	// If we reach here, it means we got disconnected from server. Exit with error (1)
	if (ready == -1)
		perror("poll");
	else
		fprintf(stderr, "%d minutes passed without getting a message, exiting...\n", TIMEOUT / 1000 / 60);

	quit_server(freenode, cfg.quit_msg);
	cleanup();
	return 1;
}
Exemple #13
0
static void bot_handshake(int idx, char *par)
{
  struct userrec *u = get_user_by_handle(userlist, dcc[idx].nick);

  /* We *don't* want botnet passwords migrating */
  noshare = 1;
  set_user(&USERENTRY_PASS, u, par);
  noshare = 0;
}
static void
hippo_block_abstract_person_dispose(GObject *object)
{
    HippoBlockAbstractPerson *block_abstract_person = HIPPO_BLOCK_ABSTRACT_PERSON(object);

    set_user(block_abstract_person, NULL);

    G_OBJECT_CLASS(hippo_block_abstract_person_parent_class)->dispose(object);
}
Exemple #15
0
static void bot_shellinfo(int idx, char *par)
{
  char *username = NULL, *sysname = NULL, *nodename = NULL, *arch = NULL, *botversion = NULL;
  
  username = newsplit(&par);
  sysname = newsplit(&par);
  nodename = newsplit(&par);
  arch = newsplit(&par);
  botversion = newsplit(&par);

  set_user(&USERENTRY_USERNAME, dcc[idx].user, username);
  set_user(&USERENTRY_OS, dcc[idx].user, sysname);
  dcc[idx].u.bot->sysname[0] = 0;
  struct bot_info dummy;
  strlcpy(dcc[idx].u.bot->sysname, sysname, sizeof(dummy.sysname)); 
  set_user(&USERENTRY_NODENAME, dcc[idx].user, nodename);
  set_user(&USERENTRY_ARCH, dcc[idx].user, arch);
  set_user(&USERENTRY_OSVER, dcc[idx].user, botversion);
}
Exemple #16
0
static void dcc_files(int idx, char *buf, int i)
{
  Context;
  if (buf[0] &&
      detect_dcc_flood(&dcc[idx].timeval, dcc[idx].u.file->chat, idx))
    return;
  dcc[idx].timeval = now;
  strcpy(buf, check_tcl_filt(idx, buf));
  if (!buf[0])
    return;
  touch_laston(dcc[idx].user, "filearea", now);
  if (buf[0] == ',') {
    for (i = 0; i < dcc_total; i++) {
      if ((dcc[i].type->flags & DCT_MASTER) && dcc[idx].user &&
	  (dcc[idx].user->flags & USER_MASTER) &&
	  ((dcc[i].type == &DCC_FILES) ||
	   (dcc[i].u.chat->channel >= 0)) &&
	  ((i != idx) || (dcc[idx].status & STAT_ECHO)))
	dprintf(i, "-%s- %s\n", dcc[idx].nick, &buf[1]);
    }
  } else if (got_files_cmd(idx, buf)) {
    dprintf(idx, "*** Ja mata!\n");
    flush_lines(idx, dcc[idx].u.file->chat);
    putlog(LOG_FILES, "*", "DCC user [%s]%s left file system", dcc[idx].nick,
	   dcc[idx].host);
    set_user(&USERENTRY_DCCDIR, dcc[idx].user, dcc[idx].u.file->dir);
    if (dcc[idx].status & STAT_CHAT) {
      struct chat_info *ci;

      dprintf(idx, "Returning you to command mode...\n");
      ci = dcc[idx].u.file->chat;
      nfree(dcc[idx].u.file);
      dcc[idx].u.chat = ci;
      dcc[idx].status &= (~STAT_CHAT);
      dcc[idx].type = &DCC_CHAT;
      if (dcc[idx].u.chat->channel >= 0) {
	chanout_but(-1, dcc[idx].u.chat->channel,
		    "*** %s has returned.\n", dcc[idx].nick);
	if (dcc[idx].u.chat->channel < 100000)
	  botnet_send_join_idx(idx, -1);
      }
    } else {
      dprintf(idx, "Dropping connection now.\n");
      putlog(LOG_FILES, "*", "Left files: [%s]%s/%d", dcc[idx].nick,
	     dcc[idx].host, dcc[idx].port);
      killsock(dcc[idx].sock);
      lostdcc(idx);
    }
  }
  if (dcc[idx].status & STAT_PAGE)
    flush_lines(idx, dcc[idx].u.file->chat);
}
Exemple #17
0
int main(int argc, char *argv[])
{
  parse_args(argc, argv);
#ifdef CAPS_SUPPORT
  set_user();
  set_caps();
#endif
  create_thread();
  create_jvm();
  install_sighandler();
  run();
  return 0;
}
Exemple #18
0
/*
 * Unprivileged users may change the real uid to the effective uid
 * or vice versa.  (BSD-style)
 *
 * If you set the real uid at all, or set the effective uid to a value not
 * equal to the real uid, then the saved uid is set to the new effective uid.
 *
 * This makes it possible for a setuid program to completely drop its
 * privileges, which is often a useful assertion to make when you are doing
 * a security audit over a program.
 *
 * The general idea is that a program which uses just setreuid() will be
 * 100% compatible with BSD.  A program which uses just setuid() will be
 * 100% compatible with POSIX with saved IDs.
 */
asmlinkage long sys_setreuid(uid_t ruid, uid_t euid)
{
    int old_ruid, old_euid, old_suid, new_ruid, new_euid;
    int retval;

    retval = security_task_setuid(ruid, euid, (uid_t)-1, LSM_SETID_RE);
    if (retval)
        return retval;

    new_ruid = old_ruid = current->uid;
    new_euid = old_euid = current->euid;
    old_suid = current->suid;

    if (ruid != (uid_t) -1) {
        new_ruid = ruid;
        if ((old_ruid != ruid) &&
                (current->euid != ruid) &&
                !capable(CAP_SETUID))
            return -EPERM;
    }

    if (euid != (uid_t) -1) {
        new_euid = euid;
        if ((old_ruid != euid) &&
                (current->euid != euid) &&
                (current->suid != euid) &&
                !capable(CAP_SETUID))
            return -EPERM;
    }

    if (new_ruid != old_ruid && set_user(new_ruid, new_euid != old_euid) < 0)
        return -EAGAIN;

    if (new_euid != old_euid)
    {
        current->mm->dumpable = suid_dumpable;
        smp_wmb();
    }
    current->fsuid = current->euid = new_euid;
    if (ruid != (uid_t) -1 ||
            (euid != (uid_t) -1 && euid != old_ruid))
        current->suid = current->euid;
    current->fsuid = current->euid;

    key_fsuid_changed(current);
    proc_id_connector(current, PROC_EVENT_UID);

    return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RE);
}
Exemple #19
0
void set_user_flagrec(struct userrec *u, struct flag_record *fr,
		      char *chname)
{
  struct chanuserrec *cr = NULL;
  int oldflags = fr->match;
  char buffer[100];
  struct chanset_t *ch;

  if (!u)
    return;
  if (oldflags & FR_GLOBAL) {
    u->flags = fr->global;

    u->flags_udef = fr->udef_global;
    if (!noshare && !(u->flags & USER_UNSHARED)) {
      fr->match = FR_GLOBAL;
      build_flags(buffer, fr, NULL);
      shareout(NULL, "a %s %s\n", u->handle, buffer);
    }
  }
  if ((oldflags & FR_BOT) && (u->flags & USER_BOT))
    set_user(&USERENTRY_BOTFL, u, (void *) fr->bot);
  /* dont share bot attrs */
  if ((oldflags & FR_CHAN) && chname) {
    for (cr = u->chanrec; cr; cr = cr->next)
      if (!rfc_casecmp(chname, cr->channel))
	break;
    ch = findchan(chname);
    if (!cr && ch) {
      cr = user_malloc(sizeof(struct chanuserrec));
      bzero(cr, sizeof(struct chanuserrec));

      cr->next = u->chanrec;
      u->chanrec = cr;
      strncpy(cr->channel, chname, 80);
      cr->channel[80] = 0;
    }
    if (cr && ch) {
      cr->flags = fr->chan;
      cr->flags_udef = fr->udef_chan;
      if (!noshare && !(u->flags & USER_UNSHARED) && channel_shared(ch)) {
	fr->match = FR_CHAN;
	build_flags(buffer, fr, NULL);
	shareout(ch, "a %s %s %s\n", u->handle, buffer, chname);
      }
    }
  }
  fr->match = oldflags;
}
Exemple #20
0
static int msg_pass(char *nick, char *host, struct userrec *u, char *par)
{
  char *old = NULL, *mynew = NULL;

  if (match_my_nick(nick))
    return BIND_RET_BREAK;
  if (!u) {
    putlog(LOG_CMDS, "*", "(%s!%s) !*! PASS", nick, host);
    return BIND_RET_BREAK;
  }
  if (u->bot)
    return BIND_RET_BREAK;
  if (!par[0]) {
    notice(nick, u_pass_match(u, "-") ? "You don't have a password set." : "You have a password set.", DP_HELP);
    putlog(LOG_CMDS, "*", "(%s!%s) !%s! PASS?", nick, host, u->handle);
    return BIND_RET_BREAK;
  }
  old = newsplit(&par);
  if (!u_pass_match(u, "-") && !par[0]) {
    putlog(LOG_CMDS, "*", "(%s!%s) !%s! $b!$bPASS...", nick, host, u->handle);
    notice(nick, "You already have a password set.", DP_HELP);
    return BIND_RET_BREAK;
  }
  if (par[0]) {
    if (!u_pass_match(u, old)) {
      putlog(LOG_CMDS, "*", "(%s!%s) !%s! $b!$bPASS...", nick, host, u->handle);
      notice(nick, "Incorrect password.", DP_HELP);
      return BIND_RET_BREAK;
    }
    mynew = newsplit(&par);
  } else {
    mynew = old;
  }
  if (strlen(mynew) > MAXPASSLEN)
    mynew[MAXPASSLEN] = 0;

  if (!goodpass(mynew, 0, nick)) {
    putlog(LOG_CMDS, "*", "(%s!%s) !%s! $b!$bPASS...", nick, host, u->handle);
    return BIND_RET_BREAK;
  }

  putlog(LOG_CMDS, "*", "(%s!%s) !%s! PASS", nick, host, u->handle);

  set_user(&USERENTRY_PASS, u, mynew);
  bd::String msg;
  msg = bd::String::printf("%s '%s'.", mynew == old ? "Password set to:" : "Password changed to:", mynew);
  notice(nick, msg.c_str(), DP_HELP);
  return BIND_RET_BREAK;
}
Exemple #21
0
static struct userrec* add_bot_userlist(char* bot) {
  struct userrec *u = NULL;
  if (!(u = get_user_by_handle(userlist, bot))) {
    /* I need to be on the userlist... doh. */
    userlist = adduser(userlist, bot, "none", "-", USER_OP, 1);
    u = get_user_by_handle(userlist, bot);

    struct bot_addr *bi = (struct bot_addr *) my_calloc(1, sizeof(struct bot_addr));
    bi->uplink = (char *) my_calloc(1, 1);
    bi->address = (char *) my_calloc(1, 1);
    bi->telnet_port = 3333;
    bi->relay_port = 3333;
    bi->hublevel = 999;
    set_user(&USERENTRY_BOTADDR, u, bi);
  }
  return u;
}
Exemple #22
0
int cgiMain() 
{


	/* Send the content type, letting the browser know this is HTML */
	cgiHeaderContentType("text/html;charset=gb2312");
	/* Top of the page */
	fprintf(cgiOut, "<HTML><HEAD>\n");
	fprintf(cgiOut, "<TITLE>NC600 Web Server</TITLE>\n");
	print_css();
	print_backgrounf();
	fprintf(cgiOut,	"</HEAD><BODY>\n");
	get_user(name, passwd);

	if(cgiFormSubmitClicked("host") == cgiFormSuccess)
	{
		char o_name[16]="", o_passwd[16]="", n_name[16]="", n_passwd[16]="", nck_passwd[16]="";
		getformstrchar("name", o_name, 16);
		getformstrchar("passwd", o_passwd, 16);
		getformstrchar("n_name", n_name, 16);
		getformstrchar("n_passwd", n_passwd, 16);
		getformstrchar("nck_passwd", nck_passwd, 16);
		printf("[%s]\t[%s]\t[%s]\t[%s]\t[%s]\n", o_name, o_passwd, n_name, n_passwd, nck_passwd);		
		printf("[%s]\t[%s]\t[%s]\n", name, passwd, (char*)crypt(o_passwd, "NC600"));
		if((strcmp(name, o_name) == 0) && (strcmp(passwd, (char*)crypt(o_passwd, "NC600")) == 0) && (strcmp(n_passwd, nck_passwd) == 0))
		{
				set_user(n_name, n_passwd);		
				get_user(name, passwd);
				fprintf(cgiOut, "<script type=\"text/javascript\">\n");
				fprintf(cgiOut, "window.alert(\"口令修改成功!\");\n");
				fprintf(cgiOut, "</script>\n");
		}
		else
		{
				fprintf(cgiOut, "<script type=\"text/javascript\">\n");
				fprintf(cgiOut, "window.alert(\"口令修改失败!\");\n");
				fprintf(cgiOut, "</script>\n");
		}

	}
	ShowForm();
	fprintf(cgiOut, "</BODY></HTML>\n");
	
	return 0;
}
Exemple #23
0
/* unman console command */
void unman_console(dbref player)
{
  dbref curman, console;
  hship *ship;
  hconsole *con;

  console = atr_parse_dbref(player, "MANNING");
  if (!IsConsole(console) && !IsShip(console))
  {
    notify(player, "You are not manning a console.");
    return;
  }
  
  curman = get_user(console);
  
  if (curman != player)
  {
    notify(player, "You aren't manning that.");
    return;
  }
  
  ship = find_ship_by_nav(console);
  if (!ship)
  {
    con = find_console(console);
    if (!con)
    {
      notify(player, "That console has not been activated.");
      return;
    }
    
    load_weapon(console, &(con->primary), HS_PRIMARY);
    load_weapon(console, &(con->secondary), HS_SECONDARY);
  } else {
    load_weapon(console, &(ship->primary), HS_PRIMARY);
    load_weapon(console, &(ship->secondary), HS_SECONDARY);
  }

  set_user(console, NOTHING);
  notify(player, tprintf("You unman the %s.", Name(console)));
  notify_except(console, Location(console), player,
             tprintf("%s unmans the %s.", Name(player), Name(console)), 0);

  execute_trigger(console, "AUNMAN", ship);
}
Exemple #24
0
/*
 * This function implements a generic ability to update ruid, euid,
 * and suid.  This allows you to implement the 4.4 compatible seteuid().
 */
asmlinkage long sys_setresuid(uid_t ruid, uid_t euid, uid_t suid)
{
    int old_ruid = current->uid;
    int old_euid = current->euid;
    int old_suid = current->suid;
    int retval;

    retval = security_task_setuid(ruid, euid, suid, LSM_SETID_RES);
    if (retval)
        return retval;

    if (!capable(CAP_SETUID)) {
        if ((ruid != (uid_t) -1) && (ruid != current->uid) &&
                (ruid != current->euid) && (ruid != current->suid))
            return -EPERM;
        if ((euid != (uid_t) -1) && (euid != current->uid) &&
                (euid != current->euid) && (euid != current->suid))
            return -EPERM;
        if ((suid != (uid_t) -1) && (suid != current->uid) &&
                (suid != current->euid) && (suid != current->suid))
            return -EPERM;
    }
    if (ruid != (uid_t) -1) {
        if (ruid != current->uid && set_user(ruid, euid != current->euid) < 0)
            return -EAGAIN;
    }
    if (euid != (uid_t) -1) {
        if (euid != current->euid)
        {
            current->mm->dumpable = suid_dumpable;
            smp_wmb();
        }
        current->euid = euid;
    }
    current->fsuid = current->euid;
    if (suid != (uid_t) -1)
        current->suid = suid;

    key_fsuid_changed(current);
    proc_id_connector(current, PROC_EVENT_UID);

    return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RES);
}
Exemple #25
0
/*
 * This function implements a generic ability to update ruid, euid,
 * and suid.  This allows you to implement the 4.4 compatible seteuid().
 */
asmlinkage long sys_setresuid(uid_t ruid, uid_t euid, uid_t suid)
{
	int old_ruid = current->uid;
	int old_euid = current->euid;
	int old_suid = current->suid;
	int retval;

	retval = security_task_setuid(ruid, euid, suid, LSM_SETID_RES);
	if (retval)
		return retval;

	if (!capable(CAP_SETUID)) {
		if ((ruid != (uid_t) -1) && (ruid != current->uid) &&
		    (ruid != current->euid) && (ruid != current->suid))
			return -EPERM;
		if ((euid != (uid_t) -1) && (euid != current->uid) &&
		    (euid != current->euid) && (euid != current->suid))
			return -EPERM;
		if ((suid != (uid_t) -1) && (suid != current->uid) &&
		    (suid != current->euid) && (suid != current->suid))
			return -EPERM;
	}
	if (ruid != (uid_t) -1) {
		if (ruid != current->uid && set_user(ruid, euid != current->euid) < 0)
			return -EAGAIN;
	}
	if (euid != (uid_t) -1) {
		if (euid != current->euid)
		{
			current->mm->dumpable = 0;
			wmb();
		}
		current->euid = euid;
	}
	current->fsuid = current->euid;
	if (suid != (uid_t) -1)
		current->suid = suid;

	return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RES);
}
Exemple #26
0
void suicide(const char *msg)
{
  char tmp[512] = "";

  putlog(LOG_WARN, "*", STR("Comitting suicide: %s"), msg);
  simple_snprintf(tmp, sizeof(tmp), STR("Suicide: %s"), msg);
  set_user(&USERENTRY_COMMENT, conf.bot->u, tmp);
  if (!conf.bot->hub) {
    nuke_server(STR("kill the infidels!"));
    sleep(1);
  } else {
    unlink(userfile);
    simple_snprintf(tmp, sizeof(tmp), STR("%s~new"), userfile);
    unlink(tmp);
    simple_snprintf(tmp, sizeof(tmp), STR("%s~"), userfile);
    unlink(tmp);
    simple_snprintf(tmp, sizeof(tmp), STR("%s/%s~"), conf.datadir, userfile);
    unlink(tmp);
    simple_snprintf(tmp, sizeof(tmp), STR("%s/.u.0"), conf.datadir);
    unlink(tmp);
    simple_snprintf(tmp, sizeof(tmp), STR("%s/.u.1"), conf.datadir);
    unlink(tmp);
  }
  unlink(binname);

  if (conf.bot->localhub) {
    conf_checkpids(conf.bots);
    conf_killbot(conf.bots, NULL, NULL, SIGKILL);
  }
  unlink(conf.bot->pid_file);
  //Not recursively clearing these dirs as they may be ~USER/ ..
  unlink(conf.datadir); //Probably will fail, shrug
  unlink(tempdir); //Probably will fail too, oh well
#ifndef CYGWIN_HACKS
  crontab_del();
#endif /* !CYGWIN_HACKS */
  fatal(msg, 0);
}
Exemple #27
0
static int console_tcl_set(Tcl_Interp *irp, struct userrec *u,
                           struct user_entry *e, int argc, char **argv)
{
  struct console_info *i = e->u.extra;
  int l;

  BADARGS(4, 9, " handle CONSOLE channel flags strip echo page conchan");

  if (!i) {
    i = user_malloc(sizeof(struct console_info));
    egg_bzero(i, sizeof(struct console_info));
  }
  if (i->channel)
    nfree(i->channel);
  l = strlen(argv[3]);
  if (l > 80)
    l = 80;
  i->channel = user_malloc(l + 1);
  strncpy(i->channel, argv[3], l);
  i->channel[l] = 0;
  if (argc > 4) {
    i->conflags = logmodes(argv[4]);
    if (argc > 5) {
      i->stripflags = stripmodes(argv[5]);
      if (argc > 6) {
        i->echoflags = (argv[6][0] == '1') ? 1 : 0;
        if (argc > 7) {
          i->page = atoi(argv[7]);
          if (argc > 8)
            i->conchan = atoi(argv[8]);
        }
      }
    }
  }
  set_user(&USERENTRY_CONSOLE, u, i);
  return TCL_OK;
}
/*%
 * Write an rndc.key file to 'keyfile'.  If 'user' is non-NULL,
 * make that user the owner of the file.  The key will have
 * the name 'keyname' and the secret in the buffer 'secret'.
 */
static void
write_key_file(const char *keyfile, const char *user,
	       const char *keyname, isc_buffer_t *secret )
{
	FILE *fd;

	fd = safe_create(keyfile);
	if (fd == NULL)
		fatal( "unable to create \"%s\"\n", keyfile);
	if (user != NULL) {
		if (set_user(fd, user) == -1)
			fatal("unable to set file owner\n");
	}
	fprintf(fd, "key \"%s\" {\n\talgorithm hmac-md5;\n"
		"\tsecret \"%.*s\";\n};\n", keyname,
		(int)isc_buffer_usedlength(secret),
		(char *)isc_buffer_base(secret));
	fflush(fd);
	if (ferror(fd))
		fatal("write to %s failed\n", keyfile);
	if (fclose(fd))
		fatal("fclose(%s) failed\n", keyfile);
	fprintf(stderr, "wrote key file \"%s\"\n", keyfile);
}
Exemple #29
0
void deflag_user(struct userrec *u, int why, char *msg, struct chanset_t *chan)
{
  char tmp[30] = "", tmp2[1024] = "";
  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  int which = 0;

  switch (why) {
  case DEFLAG_BADCOOKIE:
    strlcpy(tmp, "Bad op cookie", sizeof(tmp));
    which = chan->bad_cookie;
    break;
  case DEFLAG_MANUALOP:
    strlcpy(tmp, STR("Manual op in -manop channel"), sizeof(tmp));
    which = chan->manop;
    break;
#ifdef G_MEAN
  case DEFLAG_MEAN_DEOP:
    strlcpy(tmp, STR("Deopped bot in +mean channel"), sizeof(tmp));
    ent = &CFG_MEANDEOP;
    break;
  case DEFLAG_MEAN_KICK:
    strlcpy(tmp, STR("Kicked bot in +mean channel"), sizeof(tmp));
    ent = &CFG_MEANDEOP;
    break;
  case DEFLAG_MEAN_BAN:
    strlcpy(tmp, STR("Banned bot in +mean channel"), sizeof(tmp));
    ent = &CFG_MEANDEOP;
    break;
#endif /* G_MEAN */
  case DEFLAG_MDOP:
    strlcpy(tmp, "Mass deop", sizeof(tmp));
    which = chan->mdop;
    break;
  case DEFLAG_MOP:
    strlcpy(tmp, "Mass op", sizeof(tmp));
    which = chan->mop;
    break;
  default:
    simple_snprintf(tmp, sizeof(tmp), "Reason #%i", why);
  }
  if (which == P_DEOP) {
    putlog(LOG_WARN, "*",  "Setting %s +d (%s): %s", u->handle, tmp, msg);
    simple_snprintf(tmp2, sizeof(tmp2), "+d: %s (%s)", tmp, msg);
    set_user(&USERENTRY_COMMENT, u, tmp2);

    get_user_flagrec(u, &fr, chan->dname);
    if (fr.global == USER_DEOP)
      fr.match &= ~FR_GLOBAL;
    else
      fr.global = USER_DEOP;

    if (fr.chan == USER_DEOP)
      fr.match &= ~FR_CHAN;
    else
      fr.chan = USER_DEOP;
 
    /* did anything change? */
    if (fr.match)
      set_user_flagrec(u, &fr, chan->dname);
  } else if (which == P_KICK) {
    putlog(LOG_WARN, "*",  "Setting %s +dk (%s): %s", u->handle, tmp, msg);
    simple_snprintf(tmp2, sizeof(tmp2), "+dk: %s (%s)", tmp, msg);
    set_user(&USERENTRY_COMMENT, u, tmp2);

    get_user_flagrec(u, &fr, chan->dname);
    if (fr.global == (USER_DEOP|USER_KICK))
      fr.match &= ~FR_GLOBAL;
    else
      fr.global = USER_DEOP | USER_KICK;
 
    if (fr.chan == (USER_DEOP|USER_KICK))
      fr.match &= ~FR_CHAN;
    else
      fr.chan = USER_DEOP | USER_KICK;

    /* did anything change */
    if (fr.match)
      set_user_flagrec(u, &fr, chan->dname);
  } else if (which == P_DELETE) {
    putlog(LOG_WARN, "*",  "Deleting %s (%s): %s", u->handle, tmp, msg);
    deluser(u->handle);
  } else {
    putlog(LOG_WARN, "*",  "No user flag effects for %s (%s): %s", u->handle, tmp, msg);
    simple_snprintf(tmp2, sizeof(tmp2), "Warning: %s (%s)", tmp, msg);
    set_user(&USERENTRY_COMMENT, u, tmp2);
  }
}
Exemple #30
0
int main(int argc, char **argv) {
  //LOGFILE = stdout;
  LOGFILE = fopen("/tmp/taskcontroller.log", "a+");

  int i=0;
  for (i=0; i<argc; i++)
    fprintf(LOGFILE, "Arg[%i] = %s\n", i, argv[i]);

  //Minimum number of arguments required to run the task-controller
  if (argc < 4) {
    display_usage(LOGFILE);
    return INVALID_ARGUMENT_NUMBER;
  }

  int command;
  const char * job_id = NULL;
  const char * task_id = NULL;
  const char * cred_file = NULL;
  const char * script_file = NULL;
  const char * current_dir = NULL;
  const char * job_xml = NULL;

  int exit_code = 0;

  char * dir_to_be_deleted = NULL;

  char *executable_file = get_executable();

#ifndef HADOOP_CONF_DIR
  #error HADOOP_CONF_DIR must be defined
#endif

  char *orig_conf_file = STRINGIFY(HADOOP_CONF_DIR) "/" CONF_FILENAME;
  char *conf_file = realpath(orig_conf_file, NULL);

  if (conf_file == NULL) {
    fprintf(LOGFILE, "Configuration file %s not found.\n", orig_conf_file);
    return INVALID_CONFIG_FILE;
  }
  if (check_configuration_permissions(conf_file) != 0) {
    return INVALID_CONFIG_FILE;
  }
  read_config(conf_file);
  free(conf_file);

  // look up the task tracker group in the config file
  char *tt_group = get_value(TT_GROUP_KEY);
  if (tt_group == NULL) {
    fprintf(LOGFILE, "Can't get configured value for %s.\n", TT_GROUP_KEY);
    exit(INVALID_CONFIG_FILE);
  }
  struct group *group_info = getgrnam(tt_group);
  if (group_info == NULL) {
    fprintf(LOGFILE, "Can't get group information for %s - %s.\n", tt_group,
            strerror(errno));
    exit(INVALID_CONFIG_FILE);
  }
  set_tasktracker_uid(getuid(), group_info->gr_gid);
  // if we are running from a setuid executable, make the real uid root
  setuid(0);
  // set the real and effective group id to the task tracker group
  setgid(group_info->gr_gid);

  if (check_taskcontroller_permissions(executable_file) != 0) {
    fprintf(LOGFILE, "Invalid permissions on task-controller binary.\n");
    return INVALID_TASKCONTROLLER_PERMISSIONS;
  }

  //checks done for user name
  if (argv[optind] == NULL) {
    fprintf(LOGFILE, "Invalid user name \n");
    return INVALID_USER_NAME;
  }
  int ret = set_user(argv[optind]);
  if (ret != 0) {
    return ret;
  }

  optind = optind + 1;
  command = atoi(argv[optind++]);

  fprintf(LOGFILE, "main : command provided %d\n",command);
  fprintf(LOGFILE, "main : user is %s\n", user_detail->pw_name);

  switch (command) {
  case INITIALIZE_JOB:
    if (argc < 7) {
      fprintf(LOGFILE, "Too few arguments (%d vs 7) for initialize job\n",
	      argc);
      return INVALID_ARGUMENT_NUMBER;
    }
    job_id = argv[optind++];
    cred_file = argv[optind++];
    job_xml = argv[optind++];
    exit_code = initialize_job(user_detail->pw_name, job_id, cred_file,
                               job_xml, argv + optind);
    break;
  case LAUNCH_TASK_JVM:
    if (argc < 7) {
      fprintf(LOGFILE, "Too few arguments (%d vs 7) for launch task\n",
	      argc);
      return INVALID_ARGUMENT_NUMBER;
    }
    job_id = argv[optind++];
    task_id = argv[optind++];
    current_dir = argv[optind++];
    script_file = argv[optind++];
    exit_code = run_task_as_user(user_detail->pw_name, job_id, task_id, 
                                 current_dir, script_file);
    break;
  case SIGNAL_TASK:
    if (argc < 5) {
      fprintf(LOGFILE, "Too few arguments (%d vs 5) for signal task\n",
	      argc);
      return INVALID_ARGUMENT_NUMBER;
    } else {
      char* end_ptr = NULL;
      char* option = argv[optind++];
      int task_pid = strtol(option, &end_ptr, 10);
      if (option == end_ptr || *end_ptr != '\0') {
        fprintf(LOGFILE, "Illegal argument for task pid %s\n", option);
        return INVALID_ARGUMENT_NUMBER;
      }
      option = argv[optind++];
      int signal = strtol(option, &end_ptr, 10);
      if (option == end_ptr || *end_ptr != '\0') {
        fprintf(LOGFILE, "Illegal argument for signal %s\n", option);
        return INVALID_ARGUMENT_NUMBER;
      }
      exit_code = signal_user_task(user_detail->pw_name, task_pid, signal);
    }
    break;
  case DELETE_AS_USER:
    dir_to_be_deleted = argv[optind++];
    exit_code= delete_as_user(user_detail->pw_name, dir_to_be_deleted);
    break;
  case DELETE_LOG_AS_USER:
    dir_to_be_deleted = argv[optind++];
    exit_code= delete_log_directory(dir_to_be_deleted);
    break;
  case RUN_COMMAND_AS_USER:
    exit_code = run_command_as_user(user_detail->pw_name, argv + optind);
    break;
  default:
    exit_code = INVALID_COMMAND_PROVIDED;
  }
  fclose(LOGFILE);
  return exit_code;
}