Пример #1
0
bool load_users()
{
    char *mode = "r";
    char filename[] = USERS_FILE;
    char input[128]; //buffer for input data
    FILE* file;
    file = fopen(filename, mode);
    User *u;

    if (file == NULL)
    {
        perror("fileopen");
        exit(1);
    }

    while (fgets(input, 128, file) != NULL) {
        if (input[0] != '#') //check for the comments
        {

            u = new_user();
            //load in the user details
            sscanf(input, "%s %s", u->name, u->pw);
            new_user_node(u);
            printf("%s\n", u->name);

        }

    }


    fclose(file);

    return 1;
}
Пример #2
0
int main(void){
    int i, null, num_users;
    CLEAR;
    printf("Enter number of user entries: ");
    scanf("%d", &num_users);
    while((null = getchar()) != '\n' && null != EOF);
    CLEAR;
    user user_list[num_users];
    for(i=0;i<num_users;i++){
	user_list[i] = new_user();
    }
    for(i=0;i<num_users;i++)
	display_user(user_list[i]);
    return 0;
}
Пример #3
0
    bool UserService::createUser(const User& user) {
        if (getUser(user.getName()) != empty_user) {
            return false;
        }

        unsigned long new_id = next_id++;
        User new_user(
            new_id,
            user.getName(),
            user.getPasswordHash(),
            user.getRole()
            );

        users.insert(std::make_pair(new_id, new_user));
        user_logins.insert(std::make_pair(new_user.getName(), new_user));

        return save();
    }
Пример #4
0
Файл: init.c Проект: goXXip/K9
void introduce_user(const char *user)
{
    /* Watch out for infinite loops... */
#define LTSIZE 20
    static int lasttimes[LTSIZE];
    if (lasttimes[0] >= time(NULL)-3)
	fatal("introduce_user() loop detected");
    memmove(lasttimes, lasttimes+1, sizeof(lasttimes)-sizeof(int));
    lasttimes[LTSIZE-1] = time(NULL);
#undef LTSIZE

    if (!user || stricmp(user, s_NickServ) == 0)
	NICK(s_NickServ, desc_NickServ, UMODE_o);
    if (!user || stricmp(user, s_ChanServ) == 0) {
        new_user(s_ChanServ);
	NICK(s_ChanServ, desc_ChanServ, UMODE_o);
    }
}
Пример #5
0
int main(int argc, char * argv[]) {
  int socket_id, e;
  char *hostname, *username;
  int sending = 0;

  if (argc < 3) {
    printf("Usage: client <hostname> <username>\n");
    exit(1);
  } else {
    hostname = argv[1];
    username = argv[2];
    if (argc >= 4) {
      sending = 1;
    };
  }

  struct user me = new_user(username);

  setup_sig_handler();

  e = socket_id = connect_to_server(hostname, PORT);
  if (e < 0) check_errors("Error connecting to server", e);

  e = handshake(socket_id, me);
  if (e < 0) {
    printf("Username already taken\n");
    running = 0;
  } else {
    printf("Handshake succesfull!\n");
  }

  while (running) {
    if (sending) {
      e = send_messages(socket_id, me);
    } else {
      e = receive_messages(socket_id);
    }
    if (e < 0) running = 0;
  }

  cleanup(socket_id);
}
Пример #6
0
bool CEauApi::AddProjectUser(const string &pid, uinfo_t &uinfo)
{
    returnb_assert(m_bSigned);

    map<string, proj_t>::iterator iter = m_vProjs.find(pid);
    if (iter == m_vProjs.end())
        return false;

    proj_t &proj = iter->second;
    map<string, user_t>::iterator uiter = proj.users.find(m_szUser);
    if (uiter == proj.users.end())
        return false;
    user_t &user = uiter->second;
    if (user.role != "owner") // only project owner have permission
        return false; 

    uiter = proj.users.find(uinfo.uid);
    if (uiter != proj.users.end()) 
        return false; // user exist
    
    user_t new_user(uinfo);
    new_user.stat = "approve";
    if (uinfo.role == "owner") {
        // new owner need all owners' permission
        new_user.stat = "wait";
        for(uiter=proj.users.begin(); uiter != proj.users.end(); uiter++) {
            if (uiter->second.role == "owner")
                new_user.todo[uiter->first] = "ing";
        }

        // self owner approve automatically
        if (new_user.todo.find(m_szUser) != new_user.todo.end()) {
            new_user.todo[m_szUser] = "yes";
            if (new_user.todo.size() == 1)
                new_user.stat = "approve";
        }
    }
    proj.users[new_user.uid] = new_user;
    return true;
}
Пример #7
0
int main(int argc, const char **argv)
{
	static int list_users = False;
	static int verbose = False;
	static int spstyle = False;
	static int machine = False;
	static int add_user = False;
	static int delete_user = False;
	static int modify_user = False;
	uint32_t   setparms, checkparms;
	int opt;
	static char *full_name = NULL;
	static char *acct_desc = NULL;
	static const char *user_name = NULL;
	static char *home_dir = NULL;
	static char *home_drive = NULL;
	static const char *backend = NULL;
	static char *backend_in = NULL;
	static char *backend_out = NULL;
	static int transfer_groups = False;
	static int transfer_account_policies = False;
	static int reset_account_policies = False;
	static int  force_initialised_password = False;
	static char *logon_script = NULL;
	static char *profile_path = NULL;
	static char *user_domain = NULL;
	static char *account_control = NULL;
	static char *account_policy = NULL;
	static char *user_sid = NULL;
	static char *machine_sid = NULL;
	static long int account_policy_value = 0;
	bool account_policy_value_set = False;
	static int badpw_reset = False;
	static int hours_reset = False;
	static char *pwd_time_format = NULL;
	static int pw_from_stdin = False;
	struct pdb_methods *bin, *bout;
	static char *kickoff_time = NULL;
	TALLOC_CTX *frame = talloc_stackframe();
	NTSTATUS status;
	poptContext pc;
	struct poptOption long_options[] = {
		POPT_AUTOHELP
		{"list",	'L', POPT_ARG_NONE, &list_users, 0, "list all users", NULL},
		{"verbose",	'v', POPT_ARG_NONE, &verbose, 0, "be verbose", NULL },
		{"smbpasswd-style",	'w',POPT_ARG_NONE, &spstyle, 0, "give output in smbpasswd style", NULL},
		{"user",	'u', POPT_ARG_STRING, &user_name, 0, "use username", "USER" },
		{"account-desc",	'N', POPT_ARG_STRING, &acct_desc, 0, "set account description", NULL},
		{"fullname",	'f', POPT_ARG_STRING, &full_name, 0, "set full name", NULL},
		{"homedir",	'h', POPT_ARG_STRING, &home_dir, 0, "set home directory", NULL},
		{"drive",	'D', POPT_ARG_STRING, &home_drive, 0, "set home drive", NULL},
		{"script",	'S', POPT_ARG_STRING, &logon_script, 0, "set logon script", NULL},
		{"profile",	'p', POPT_ARG_STRING, &profile_path, 0, "set profile path", NULL},
		{"domain",	'I', POPT_ARG_STRING, &user_domain, 0, "set a users' domain", NULL},
		{"user SID",	'U', POPT_ARG_STRING, &user_sid, 0, "set user SID or RID", NULL},
		{"machine SID",	'M', POPT_ARG_STRING, &machine_sid, 0, "set machine SID or RID", NULL},
		{"create",	'a', POPT_ARG_NONE, &add_user, 0, "create user", NULL},
		{"modify",	'r', POPT_ARG_NONE, &modify_user, 0, "modify user", NULL},
		{"machine",	'm', POPT_ARG_NONE, &machine, 0, "account is a machine account", NULL},
		{"delete",	'x', POPT_ARG_NONE, &delete_user, 0, "delete user", NULL},
		{"backend",	'b', POPT_ARG_STRING, &backend, 0, "use different passdb backend as default backend", NULL},
		{"import",	'i', POPT_ARG_STRING, &backend_in, 0, "import user accounts from this backend", NULL},
		{"export",	'e', POPT_ARG_STRING, &backend_out, 0, "export user accounts to this backend", NULL},
		{"group",	'g', POPT_ARG_NONE, &transfer_groups, 0, "use -i and -e for groups", NULL},
		{"policies",	'y', POPT_ARG_NONE, &transfer_account_policies, 0, "use -i and -e to move account policies between backends", NULL},
		{"policies-reset",	0, POPT_ARG_NONE, &reset_account_policies, 0, "restore default policies", NULL},
		{"account-policy",	'P', POPT_ARG_STRING, &account_policy, 0,"value of an account policy (like maximum password age)",NULL},
		{"value",       'C', POPT_ARG_LONG, &account_policy_value, 'C',"set the account policy to this value", NULL},
		{"account-control",	'c', POPT_ARG_STRING, &account_control, 0, "Values of account control", NULL},
		{"force-initialized-passwords", 0, POPT_ARG_NONE, &force_initialised_password, 0, "Force initialization of corrupt password strings in a passdb backend", NULL},
		{"bad-password-count-reset", 'z', POPT_ARG_NONE, &badpw_reset, 0, "reset bad password count", NULL},
		{"logon-hours-reset", 'Z', POPT_ARG_NONE, &hours_reset, 0, "reset logon hours", NULL},
		{"time-format", 0, POPT_ARG_STRING, &pwd_time_format, 0, "The time format for time parameters", NULL },
		{"password-from-stdin", 't', POPT_ARG_NONE, &pw_from_stdin, 0, "get password from standard in", NULL},
		{"kickoff-time", 'K', POPT_ARG_STRING, &kickoff_time, 0, "set the kickoff time", NULL},
		POPT_COMMON_SAMBA
		POPT_TABLEEND
	};

	bin = bout = NULL;

	smb_init_locale();

	setup_logging("pdbedit", DEBUG_STDOUT);

	pc = poptGetContext(NULL, argc, argv, long_options,
			    POPT_CONTEXT_KEEP_FIRST);

	while((opt = poptGetNextOpt(pc)) != -1) {
		switch (opt) {
		case 'C':
			account_policy_value_set = True;
			break;
		}
	}

	poptGetArg(pc); /* Drop argv[0], the program name */

	if (user_name == NULL)
		user_name = poptGetArg(pc);

	if (!lp_load_global(get_dyn_CONFIGFILE())) {
		fprintf(stderr, "Can't load %s - run testparm to debug it\n", get_dyn_CONFIGFILE());
		exit(1);
	}

	if (!init_names())
		exit(1);

	setparms =	(backend ? BIT_BACKEND : 0) +
			(verbose ? BIT_VERBOSE : 0) +
			(spstyle ? BIT_SPSTYLE : 0) +
			(full_name ? BIT_FULLNAME : 0) +
			(home_dir ? BIT_HOMEDIR : 0) +
			(home_drive ? BIT_HDIRDRIVE : 0) +
			(logon_script ? BIT_LOGSCRIPT : 0) +
			(profile_path ? BIT_PROFILE : 0) +
			(user_domain ? BIT_USERDOMAIN : 0) +
			(machine ? BIT_MACHINE : 0) +
			(user_name ? BIT_USER : 0) +
			(list_users ? BIT_LIST : 0) +
			(force_initialised_password ? BIT_FIX_INIT : 0) +
			(user_sid ? BIT_USERSIDS : 0) +
			(machine_sid ? BIT_USERSIDS : 0) +
			(modify_user ? BIT_MODIFY : 0) +
			(add_user ? BIT_CREATE : 0) +
			(delete_user ? BIT_DELETE : 0) +
			(account_control ? BIT_ACCTCTRL : 0) +
			(account_policy ? BIT_ACCPOLICY : 0) +
			(account_policy_value_set ? BIT_ACCPOLVAL : 0) +
			(backend_in ? BIT_IMPORT : 0) +
			(backend_out ? BIT_EXPORT : 0) +
			(badpw_reset ? BIT_BADPWRESET : 0) +
			(hours_reset ? BIT_LOGONHOURS : 0) +
			(kickoff_time ? BIT_KICKOFFTIME : 0) +
			(acct_desc ? BIT_DESCRIPTION : 0);

	if (setparms & BIT_BACKEND) {
		/* HACK: set the global passdb backend by overwriting globals.
		 * This way we can use regular pdb functions for default
		 * operations that do not involve passdb migrations */
		lp_set_cmdline("passdb backend", backend);
	} else {
		backend = lp_passdb_backend();
	}

	if (!initialize_password_db(False, NULL)) {
		fprintf(stderr, "Can't initialize passdb backend.\n");
		exit(1);
	}

	/* the lowest bit options are always accepted */
	checkparms = setparms & ~MASK_ALWAYS_GOOD;

	if (checkparms & BIT_FIX_INIT) {
		return fix_users_list();
	}

	/* account policy operations */
	if ((checkparms & BIT_ACCPOLICY) && !(checkparms & ~(BIT_ACCPOLICY + BIT_ACCPOLVAL))) {
		uint32_t value;
		enum pdb_policy_type field = account_policy_name_to_typenum(account_policy);
		if (field == 0) {
			const char **names;
			int count;
			int i;
			account_policy_names_list(talloc_tos(), &names, &count);
			fprintf(stderr, "No account policy by that name!\n");
			if (count !=0) {
				fprintf(stderr, "Account policy names are:\n");
				for (i = 0; i < count ; i++) {
                        		d_fprintf(stderr, "%s\n", names[i]);
				}
			}
			TALLOC_FREE(names);
			exit(1);
		}
		if (!pdb_get_account_policy(field, &value)) {
			fprintf(stderr, "valid account policy, but unable to fetch value!\n");
			if (!account_policy_value_set)
				exit(1);
		}
		printf("account policy \"%s\" description: %s\n", account_policy, account_policy_get_desc(field));
		if (account_policy_value_set) {
			printf("account policy \"%s\" value was: %u\n", account_policy, value);
			if (!pdb_set_account_policy(field, account_policy_value)) {
				fprintf(stderr, "valid account policy, but unable to set value!\n");
				exit(1);
			}
			printf("account policy \"%s\" value is now: %lu\n", account_policy, account_policy_value);
			exit(0);
		} else {
			printf("account policy \"%s\" value is: %u\n", account_policy, value);
			exit(0);
		}
	}

	if (reset_account_policies) {
		if (reinit_account_policies()) {
			exit(1);
		}

		exit(0);
	}

	/* import and export operations */

	if (((checkparms & BIT_IMPORT) ||
	     (checkparms & BIT_EXPORT)) &&
	    !(checkparms & ~(BIT_IMPORT +BIT_EXPORT +BIT_USER))) {

		if (backend_in) {
			status = make_pdb_method_name(&bin, backend_in);
		} else {
			status = make_pdb_method_name(&bin, backend);
		}

		if (!NT_STATUS_IS_OK(status)) {
			fprintf(stderr, "Unable to initialize %s.\n",
				backend_in ? backend_in : backend);
			return 1;
		}

		if (backend_out) {
			status = make_pdb_method_name(&bout, backend_out);
		} else {
			status = make_pdb_method_name(&bout, backend);
		}

		if (!NT_STATUS_IS_OK(status)) {
			fprintf(stderr, "Unable to initialize %s.\n",
				backend_out ? backend_out : backend);
			return 1;
		}

		if (transfer_account_policies) {

			if (!(checkparms & BIT_USER)) {
				return export_account_policies(bin, bout);
			}

		} else 	if (transfer_groups) {

			if (!(checkparms & BIT_USER)) {
				return export_groups(bin, bout);
			}

		} else {
			return export_database(bin, bout,
				(checkparms & BIT_USER) ? user_name : NULL);
		}
	}

	/* if BIT_USER is defined but nothing else then threat it as -l -u for compatibility */
	/* fake up BIT_LIST if only BIT_USER is defined */
	if ((checkparms & BIT_USER) && !(checkparms & ~BIT_USER)) {
		checkparms += BIT_LIST;
	}

	/* modify flag is optional to maintain backwards compatibility */
	/* fake up BIT_MODIFY if BIT_USER  and at least one of MASK_USER_GOOD is defined */
	if (!((checkparms & ~MASK_USER_GOOD) & ~BIT_USER) && (checkparms & MASK_USER_GOOD)) {
		checkparms += BIT_MODIFY;
	}

	/* list users operations */
	if (checkparms & BIT_LIST) {
		if (!(checkparms & ~BIT_LIST)) {
			return print_users_list(verbose, spstyle);
		}
		if (!(checkparms & ~(BIT_USER + BIT_LIST))) {
			return print_user_info(user_name, verbose, spstyle);
		}
	}

	/* mask out users options */
	checkparms &= ~MASK_USER_GOOD;

	/* if bad password count is reset, we must be modifying */
	if (checkparms & BIT_BADPWRESET) {
		checkparms |= BIT_MODIFY;
		checkparms &= ~BIT_BADPWRESET;
	}

	/* if logon hours is reset, must modify */
	if (checkparms & BIT_LOGONHOURS) {
		checkparms |= BIT_MODIFY;
		checkparms &= ~BIT_LOGONHOURS;
	}

	/* account operation */
	if ((checkparms & BIT_CREATE) || (checkparms & BIT_MODIFY) || (checkparms & BIT_DELETE)) {
		/* check use of -u option */
		if (!(checkparms & BIT_USER)) {
			fprintf (stderr, "Username not specified! (use -u option)\n");
			return -1;
		}

		/* account creation operations */
		if (!(checkparms & ~(BIT_CREATE + BIT_USER + BIT_MACHINE))) {
		       	if (checkparms & BIT_MACHINE) {
				return new_machine(user_name, machine_sid);
			} else {
				return new_user(user_name, full_name,
						home_dir, home_drive,
						logon_script, profile_path,
						user_sid, pw_from_stdin);
			}
		}

		/* account deletion operations */
		if (!(checkparms & ~(BIT_DELETE + BIT_USER + BIT_MACHINE))) {
		       	if (checkparms & BIT_MACHINE) {
				return delete_machine_entry(user_name);
			} else {
				return delete_user_entry(user_name);
			}
		}

		/* account modification operations */
		if (!(checkparms & ~(BIT_MODIFY + BIT_USER + BIT_MACHINE))) {
			if (checkparms & BIT_MACHINE) {
				return set_machine_info(user_name,
							account_control,
							machine_sid);
			} else {
				return set_user_info(user_name, full_name,
						     home_dir, acct_desc,
						     home_drive, logon_script,
						     profile_path, account_control,
						     user_sid, user_domain,
						     badpw_reset, hours_reset,
						     kickoff_time);
			}
		}
	}

	if (setparms >= 0x20) {
		fprintf (stderr, "Incompatible or insufficient options on command line!\n");
	}
	poptPrintHelp(pc, stderr, 0);

	TALLOC_FREE(frame);
	return 1;
}
Пример #8
0
int main(int argc, char **argv) {
    int shmfd,
        shm_seg_size = sizeof(struct msg);
    struct msg *shm_msg;
    
    char buff[MAX_MSG_LENGTH];
    
    sem_t *semfd; // semaphore file descriptor
    
    // open named semaphore
    semfd = sem_open(SEM_PATH, O_RDWR, S_IRWXU | S_IRWXG, 0);
    if(semfd == SEM_FAILED)
        error("sem_open()");

    // open shared memory
    shmfd = shm_open(SHM_PATH, O_RDWR, S_IRWXU | S_IRWXG);
    if(shmfd < 0)
        error("shm_open()");

    // map shared memory to address space
    shm_msg = (struct msg *) mmap(NULL, shm_seg_size, PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0);
    if(shm_msg == NULL)
        error("mmap()");
    
    pid_t pid;
    pid = getpid();
    
    user *usr = new_user(pid, "",""); // this user
    strncpy(usr->channel, "all", 3);;
    
    pid_t fid = fork();

    // input handling
    if(fid > 0) {
        // register client
        sem_wait(semfd);

        shm_msg->read = '_';
        shm_msg->pid = pid;
        shm_msg->type = TYPE_CLIENT_MSG;
        strncpy(shm_msg->cmd, "reg", MAX_CMD_LENGTH);

        sem_post(semfd);

        // get input line by line
        while(getLine("", buff, sizeof(buff)) == IN_OK) {
            while(shm_msg->read && shm_msg->read == '_') sleep(1);

            if(!shm_msg->read || shm_msg->read == '!') {
                sem_wait(semfd);

                shm_msg->pid = pid;
                shm_msg->type = TYPE_CLIENT_MSG;

                shm_msg->read = '_';
                
                if(first_char(buff) == '/') {
                    cmd(buff, shm_msg->cmd);
                    remove_cmd(buff);
                } else {
                    snprintf(shm_msg->cmd, MAX_CMD_LENGTH, "msg");
                }
                
                snprintf(shm_msg->content, MAX_MSG_LENGTH, "%s", buff);
            }
        }
    // reponse handling
    } else {
        while(1) {
            fflush(stdout); fflush(stdin);
            if(shm_msg->read == '*') {
                if(strncmp("resp", shm_msg->cmd, 4) == 0 && shm_msg->pid == pid && shm_msg->type == TYPE_SERVER_MSG) {
                    printf("\n");
                    printf("response: %s\n", shm_msg->content);
                    
                    shm_msg->read = '!';

                    char CMD[MAX_MSG_LENGTH];
                    cmd(shm_msg->content, CMD);
                    remove_cmd(shm_msg->content);

                    if(strncmp(CMD, "join", 4) == 0) {
                        strncpy(usr->channel, shm_msg->content, MAX_CHAN_LEN);
                    } else if(strncmp(CMD, "name", 4) == 0) {
                        strncpy(usr->name, shm_msg->content, MAX_NAME_LEN);
                    }
                    
                    sem_post(semfd);
                } else if(strncmp("pm", shm_msg->cmd, 2) == 0 && shm_msg->pid == pid && shm_msg->type == TYPE_CLIENT_MSG) {
                    printf("[PM -> %d] %s: %s\n", shm_msg->pid, shm_msg->from, shm_msg->content);
                    shm_msg->read = '!';
                } else if(strncmp("msg", shm_msg->cmd, 3) == 0) {
                    if((strncmp(shm_msg->channel, usr->channel, MAX_CHAN_LEN) == 0) && shm_msg->pid != pid && shm_msg->read != '!') {
                        printf("[#%s] <%s> ", shm_msg->channel, shm_msg->from);
                        printf("%s\n", shm_msg->content);
                        shm_msg->read = '!';
                    }
                }
            }
        }
    }
    
    return EXIT_SUCCESS;
}
Пример #9
0
/**
 * Adds a new user to anopes internal userlist.
 *
 * If the SVID passed is 2, the user will not be marked registered or requested to ID.
 * This is an addition to accomodate IRCds where we cannot determine this based on the NICK 
 * or UID command. Some IRCd's keep +r on when changing nicks and do not use SVID (ex. InspIRCd 1.2).
 * Instead we get a METADATA command containing the accountname the user was last identified to.
 * Since this is received after the user is introduced to us we should not yet mark the user
 * as identified or ask him to identify. We will mark him as recognized for the time being and let
 * him keep his +r if he has it.
 * It is the responsibility of the protocol module to make sure that this is either invalidated,
 * or changed to identified. ~ Viper
 **/
User *do_nick(const char *source, char *nick, char *username, char *host,
              char *server, char *realname, time_t ts, uint32 svid,
              uint32 ip, char *vhost, char *uid)
{
    User *user = NULL;

    char *tmp = NULL;
    NickAlias *old_na;          /* Old nick rec */
    int nc_changed = 1;         /* Did nick core change? */
    int status = 0;             /* Status to apply */
    char mask[USERMAX + HOSTMAX + 2];
    char *logrealname;
    char *oldnick;

    if (!*source) {
        char ipbuf[16];
        struct in_addr addr;

        if (ircd->nickvhost) {
            if (vhost) {
                if (!strcmp(vhost, "*")) {
                    vhost = NULL;
                    if (debug)
                        alog("debug: new user�with no vhost in NICK command: %s", nick);
                }
            }
        }

        /* This is a new user; create a User structure for it. */
        if (debug)
            alog("debug: new user: %s", nick);

        if (ircd->nickip) {
            addr.s_addr = htonl(ip);
            ntoa(addr, ipbuf, sizeof(ipbuf));
        }


        if (LogUsers) {
        /**
         * Ugly swap routine for Flop's bug :)
         **/
            if (realname) {
                tmp = strchr(realname, '%');
                while (tmp) {
                    *tmp = '-';
                    tmp = strchr(realname, '%');
                }
            }
            logrealname = normalizeBuffer(realname);

        /**
         * End of ugly swap
         **/

            if (ircd->nickvhost) {
                if (ircd->nickip) {
                    alog("LOGUSERS: %s (%s@%s => %s) (%s) [%s] connected to the network (%s).", nick, username, host, (vhost ? vhost : "none"), logrealname, ipbuf, server);
                } else {
                    alog("LOGUSERS: %s (%s@%s => %s) (%s) connected to the network (%s).", nick, username, host, (vhost ? vhost : "none"), logrealname, server);
                }
            } else {
                if (ircd->nickip) {
                    alog("LOGUSERS: %s (%s@%s) (%s) [%s] connected to the network (%s).", nick, username, host, logrealname, ipbuf, server);
                } else {
                    alog("LOGUSERS: %s (%s@%s) (%s) connected to the network (%s).", nick, username, host, logrealname, server);
                }
            }
            Anope_Free(logrealname);
        }

        /* We used to ignore the ~ which a lot of ircd's use to indicate no
         * identd response.  That caused channel bans to break, so now we
         * just take what the server gives us.  People are still encouraged
         * to read the RFCs and stop doing anything to usernames depending
         * on the result of an identd lookup.
         */

        /* First check for AKILLs. */
        /* DONT just return null if its an akill match anymore - yes its more efficent to, however, now that ircd's are
         * starting to use things like E/F lines, we cant be 100% sure the client will be removed from the network :/
         * as such, create a user_struct, and if the client is removed, we'll delete it again when the QUIT notice
         * comes in from the ircd.
         **/
        if (check_akill(nick, username, host, vhost, ipbuf)) {
/*            return NULL; */
        }

/**
 * DefCon AKILL system, if we want to akill all connecting user's here's where to do it
 * then force check_akill again on them...
 **/
        /* don't akill on netmerges -Certus */
        /* don't akill clients introduced by ulines. -Viper */
        if (is_sync(findserver(servlist, server))
            && checkDefCon(DEFCON_AKILL_NEW_CLIENTS) && !is_ulined(server)) {
            strncpy(mask, "*@", 3);
            strncat(mask, host, HOSTMAX);
            alog("DEFCON: adding akill for %s", mask);
            add_akill(NULL, mask, s_OperServ,
                      time(NULL) + dotime(DefConAKILL),
                      DefConAkillReason ? DefConAkillReason :
                      "DEFCON AKILL");
            if (check_akill(nick, username, host, vhost, ipbuf)) {
/*            return NULL; */
            }
        }

        /* SGLINE */
        if (ircd->sgline) {
            if (check_sgline(nick, realname))
                return NULL;
        }

        /* SQLINE */
        if (ircd->sqline) {
            if (check_sqline(nick, 0))
                return NULL;
        }

        /* SZLINE */
        if (ircd->szline && ircd->nickip) {
            if (check_szline(nick, ipbuf))
                return NULL;
        }
        /* Now check for session limits */
        if (LimitSessions && !is_ulined(server)
            && !add_session(nick, host, ipbuf))
            return NULL;

        /* Allocate User structure and fill it in. */
        user = new_user(nick);
        user->username = sstrdup(username);
        user->host = sstrdup(host);
        user->server = findserver(servlist, server);
        user->realname = sstrdup(realname);
        user->timestamp = ts;
        user->my_signon = time(NULL);
        user->chost = vhost ? sstrdup(vhost) : sstrdup(host);
        user->vhost = vhost ? sstrdup(vhost) : sstrdup(host);
        if (uid) {
            user->uid = sstrdup(uid);   /* p10/ts6 stuff */
        } else {
            user->uid = NULL;
        }
        user->vident = sstrdup(username);
        /* We now store the user's ip in the user_ struct,
         * because we will use it in serveral places -- DrStein */
        if (ircd->nickip) {
            user->hostip = sstrdup(ipbuf);
        } else {
            user->hostip = NULL;
        }

        if (svid == 0) {
            display_news(user, NEWS_LOGON);
            display_news(user, NEWS_RANDOM);
        }

        if (svid == 2 && user->na) {
            /* We do not yet know if the user should be identified or not.
             * mark him as recognized for now. 
             * It s up to the protocol module to make sure this either becomes ID'd or
             * is invalidated. ~ Viper */
            if (debug) 
                alog("debug: Marking %s as recognized..", user->nick);
            user->svid = 1;
            user->na->status |= NS_RECOGNIZED;
            nc_changed = 0;
        } else if (svid == ts && user->na) {
            /* Timestamp and svid match, and nick is registered; automagically identify the nick */
            user->svid = svid;
            user->na->status |= NS_IDENTIFIED;
            check_memos(user);
            nc_changed = 0;

            /* Start nick tracking if available */
            if (NSNickTracking)
                nsStartNickTracking(user);

        } else if (svid != 1) {
            /* Resets the svid because it doesn't match */
            user->svid = 1;

            anope_cmd_svid_umode(user->nick, user->timestamp);

        } else {
            user->svid = 1;
        }
        send_event(EVENT_NEWNICK, 1, nick);

    } else {
        /* An old user changing nicks. */
        if (UseTS6 && ircd->ts6)
            user = find_byuid(source);

        if (!user)
            user = finduser(source);

        if (!user) {
            alog("user: NICK from nonexistent nick %s", source);
            return NULL;
        }
        user->isSuperAdmin = 0; /* Dont let people nick change and stay SuperAdmins */
        if (debug)
            alog("debug: %s changes nick to %s", source, nick);

        if (LogUsers) {
            logrealname = normalizeBuffer(user->realname);
            if (ircd->vhost) {
                alog("LOGUSERS: %s (%s@%s => %s) (%s) changed nick to %s (%s).", user->nick, user->username, user->host, (user->vhost ? user->vhost : "(none)"), logrealname, nick, user->server->name);
            } else {
                alog("LOGUSERS: %s (%s@%s) (%s) changed nick to %s (%s).",
                     user->nick, user->username, user->host, logrealname,
                     nick, user->server->name);
            }
            if (logrealname) {
                free(logrealname);
            }
        }

        user->timestamp = ts;

        if (stricmp(nick, user->nick) == 0) {
            /* No need to redo things */
            change_user_nick(user, nick);
            nc_changed = 0;
        } else {
            /* Update this only if nicks aren't the same */
            user->my_signon = time(NULL);

            old_na = user->na;
            if (old_na) {
                if (nick_recognized(user))
                    user->na->last_seen = time(NULL);
                status = old_na->status & NS_TRANSGROUP;
                cancel_user(user);
            }

            oldnick = sstrdup(user->nick);
            change_user_nick(user, nick);

            if ((old_na ? old_na->nc : NULL) ==
                (user->na ? user->na->nc : NULL))
                nc_changed = 0;

            if (!nc_changed && (user->na))
                user->na->status |= status;
            else {
                anope_cmd_nc_change(user);
            }

            send_event(EVENT_CHANGE_NICK, 2, nick, oldnick);
            free(oldnick);
        }

        if (ircd->sqline) {
            if (!is_oper(user) && check_sqline(user->nick, 1))
                return NULL;
        }

    }                           /* if (!*source) */

    /* Check for nick tracking to bypass identification */
    if (NSNickTracking && nsCheckNickTracking(user)) {
        user->na->status |= NS_IDENTIFIED;
        nc_changed = 0;
    }

    if (nc_changed || !nick_recognized(user)) {
        if (validate_user(user))
            check_memos(user);

    } else {
        if (nick_identified(user)) {
            char tsbuf[16];
            user->na->last_seen = time(NULL);

            if (user->na->last_usermask)
                free(user->na->last_usermask);
            user->na->last_usermask =
                smalloc(strlen(common_get_vident(user)) +
                        strlen(common_get_vhost(user)) + 2);
            sprintf(user->na->last_usermask, "%s@%s",
                    common_get_vident(user), common_get_vhost(user));

            snprintf(tsbuf, sizeof(tsbuf), "%lu",
                     (unsigned long int) user->timestamp);
            anope_cmd_svid_umode2(user, tsbuf);

            alog("%s: %s!%s@%s automatically identified for nick %s",
                 s_NickServ, user->nick, user->username,
                 user->host, user->nick);
        }
    }

    /* Bahamut sets -r on every nick changes, so we must test it even if nc_changed == 0 */
    if (ircd->check_nick_id) {
        if (nick_identified(user)) {
            char tsbuf[16];
            snprintf(tsbuf, sizeof(tsbuf), "%lu",
                     (unsigned long int) user->timestamp);
            anope_cmd_svid_umode3(user, tsbuf);
        }
    }

    return user;
}
Пример #10
0
/**
 * User thread responsible for handling individual clients
 * @param arg Structure to use to process the thread
 */
void *user_thread( void *arg ) {

	User user = new_user( ((Environment)arg)->client );
	Management manager = ((Environment)arg)->manager;

    // increase thread count
    manager_up_thread( manager, pthread_self() );

    // lock user for now
    user_lock( user );

	    // add the user to the list of users
	    manager_add_user( manager, user );

	    // turn client on
	    client_ok( user->client );

    // ready user for commo
    user_unlock( user );



	/* ---------------------------------------------
	 * Login screen
	 */

    Room login_room = room_get( manager->rooms, 0 );    

    if( login_room == NULL ){
        printf("Error getting login room\n");
        //return 0;
    }

    char_set_room( user->parent->character, login_room );

    // have a look
    action_look( NULL, user, manager );

    // client_prompt(  )


	// accept input
	
	// initialize
    int buff_len = 256;
	char *buff = (char *) malloc( buff_len );
	memset( buff, 0, 256 );
	if( buff == NULL ){
	    perror("client thread recv buffer malloc");
	    return NULL;
	}

	// user response loop
	while( manager->cease != 1 && (user->flags & USER_FLAG_EXIT) == 0 ){

		// receive response from client
		int length = client_recv( 
		    user->client, 
		    &buff, 
		    &buff_len );

		// handle response
		if( buff != NULL && length > 0 ){

			// parse the response for actionable text
			action_parse_response( 
			    buff,       // buffer with response
			    length,     // length of response
			    user,       // user making response
			    manager );  // manager

            // reset response
            memset(buff,0,length);

		} else {
		    // nothing going on, yield
		    sched_yield();
		}

	}
	
	free( buff );



	// remove from manager list
	manager_remove_user( manager, user );

    // lock user for this    
	user_lock( user );
	
	// close and destory all structs
	// manually manage this part
	close_client( user->client );
	destroy_client( user->client );
	
	// user gone from manager so safe to unlock a head
	user_unlock( user );
	
	// now destroy
	destroy_user( user );
	
	free( ((Environment)arg) );

    // decrease thread count
    manager_down_thread( manager, pthread_self() );
    pthread_exit( 0 );

	return NULL;
}
Пример #11
0
void
do_login(void)
{
register int i;
register int users;
register char *name;
register struct tm *ltm;
register struct user *tmpuser = 0;
register int wrong = 0;
register char *bbsname;
char pas[9];
char temp[128];
char myname[MAXALIAS + 1];

  printf("\nDOC (Dave's Own version of Citadel) Version 1.71\n\nWelcome to the ISCA BBS.\n\n%s", (bbsname = getenv("BBSNAME")) ? "" : "\nLogin as 'Guest' to just look around, or 'New' to create a new account.\n\n");

  for (;;)
  {
    guest = 0;

    if (!bbsname)
      name = get_name("Name: ", 1);
    else
      strcpy(name = myname, bbsname);

    if (strcmp(name, "New"))
    {
      if ((tmpuser = getuser(name)))
        freeuser(tmpuser);
      if (tmpuser && (!bbsname || tty) && strcmp(name, "Guest"))
        get_string("Password: "******"Incorrect login.\n");
	else
	  printf("There is no user %s on this BBS.\n", name);
        if (++wrong > 3 || bbsname)
        {
	  if (!bbsname)
            printf("\n\nToo many attempts.  Goodbye.\n");
          my_exit(3);
        }
        flush_input(wrong);
        continue;
      }
      else
      {
        xinit();
	if (ouruser->keytime)
	{     
	  printf("\n\n\nYou have not yet registered your validation key...\n\n");
	  dokey(ouruser);
	  if (ouruser->keytime && ouruser->f_trouble)
	  {
	    printf("\n\nYou will need to enter your validation key before you may gain access to the\nBBS.  If you have not yet received your key and think you should, you may send\nE-mail to [email protected].  Please include your BBS username in this\nE-mail so the sysop who receives it knows who you are.  Remember that it can\ntake several days from the time your account was originally created for the\nsysops to validate the information you have provided, if it has been less than\nfour days since you created your account please do not send E-mail yet, as it\nlikely they haven't finished with your account yet.  Impatience won't make them\nwork any faster, and quite likely will make them decide to make you a special\ncase and work slower!  Remember, this BBS is a privilege, not a right.\n\n\n");
	    my_exit(15);
	  }
	}

	printf("\nIowa Student Computer Association BBS.\n");

	if (ouruser->f_deleted)
        {
	  if (ouruser->f_namechanged)
	    printf("\a\nThis account has been marked for deletion because of a request to change the\nusername from '%s' to '%s'.\n\nYou may login as '%s' using the same password.\n\n", ouruser->name, ouruser->reminder, ouruser->reminder);
          else
            printf("\a\nThis account has been marked for deletion, either through your choice or\nbecause you violated ISCA BBS rules by doing something such as providing\nobviously bogus profile info.  You will be logged off.\n\n");
          my_exit(10);
        }
	else if (ouruser->f_inactive)
        {
          printf("You seem to have been denied access to the message system.\n");
          printf("Please contact ISCA (e-mail address [email protected]) for more.\n");
          my_exit(10);
        }


	i = ouruser->time;
        ltm = localtime(&ouruser->time);
        users = add_loggedin(ouruser);

        if (!guest && ouruser->time)
        {
	  printf("Last on: %d/%d/%d %d:%02d ", ltm->tm_mon + 1,
                 ltm->tm_mday, 1900 + ltm->tm_year, ltm->tm_hour, ltm->tm_min);
          ltm = localtime(&ouruser->timeoff);
	  if (ouruser->timeoff >= i)
            printf("until %d:%02d from %s\n", ltm->tm_hour, ltm->tm_min, ouruser->remote);
	  else
	    printf("from %s\n", ouruser->remote);
        }

        strcpy(ouruser->loginname, ARGV[1] && ARGV[2] ? ARGV[2] : "");
        strncpy(ouruser->remote, ARGV[1] ? ARGV[1] : "local", sizeof ouruser->remote - 1);

        if (ouruser->f_noclient)
	{
	  printf("\n\nYou have been disallowed use of the BBS client, you must login using telnet.\n\n");
	  my_exit(10);
	}

	sprintf(temp, "%s %s%s%s/%d", client ? "CLIENT" : "LOGIN", ARGV[1] && ARGV[2] ? ARGV[2] : "", ARGV[1] && ARGV[2] ? "@" : "", ouruser->remote, mybtmp->remport);
	logevent(temp);

	++ouruser->timescalled;

	if (!guest)
	  printf("This is call %d.  There are %d users.\n", ouruser->timescalled, users);
        if (ouruser->f_aide)
           validate_users(0);

	/*
	 * Turn off expresses and tell the user this was done if user is
	 * configured for this 
	 */
	if (!guest && mybtmp->xstat)
	  printf("\nNOTE:  You have eXpress messages turned OFF as a default!\n");
        if (mybtmp->elf)
          printf("\nYou are marked as available to help others.\n");

	checkmail(FALSE);

	termset();

        if (*ouruser->reminder)
        {
          printf("\n\aREMINDER:\n%s\n\n", ouruser->reminder);
          printf("Please hit 'Y' to acknowledge having seen this reminder -> ");
          get_single_quiet("yY");
        }

	if (ouruser->f_badinfo || ouruser->f_duplicate)
	{
	  help("badinfo", NO);
	  mysleep(300);
	}

	if (guest)
	{
	  help("guestwelcome", NO);
	  hit_return_now();
	}
	return;
      }
    }
    else
      if (!(i = new_user()))
      {
	printf("\n\nSorry, there was some problem setting up your BBS account.\n\nPlease try again later.\n\n");
        my_exit(10);
      }
      else if (i > 0)
        return;
  }
}
Пример #12
0
/*Description - Prints the main menu in a new window using ncurses library*/
void menu() {
	system("clear");
	WINDOW *menu_win;
	int highlight = 1;
	int choice = 0;
	int c;
	initscr();
	clear();
	noecho();
	cbreak();	/* Line buffering disabled. pass on everything */
	startx = (80 - WIDTH) / 2;
	starty = (24 - HEIGHT) / 2;
	menu_win = newwin(HEIGHT, WIDTH, starty, startx);
	keypad(menu_win, TRUE);
	mvprintw(0, 20, "***************BLACKJACK****************");
	mvprintw(2, 7, "Use arrow keys to go up and down, Press enter to select a choice");
	refresh();
	print_menu(menu_win, highlight);
	while(1)
	{	c = wgetch(menu_win);
		switch(c)
		{	case KEY_UP:
				if(highlight == 1)
					highlight = n_choices;
				else
					--highlight;
				break;
			case KEY_DOWN:
				if(highlight == n_choices)
					highlight = 1;
				else 
					++highlight;
				break;
			case 10:
				choice = highlight;
				break;
			default:
				mvprintw(24, 0, "Charcter pressed is = %3d Hopefully it can be printed as '%c'", c, c);
				refresh();
				break;
		}
		print_menu(menu_win, highlight);
		if(choice != 0)	/* User did a choice come out of the infinite loop */
			break;
	}
	clrtoeol();
	endwin();
	switch(choice) {
		case 1: /*Guide*/
			guide();
			menu();
			break;
		case 2: /*Login*/
			login();
			break;
		case 3: /*New account*/
			new_user();
			menu();
			break;
		case 4: /*Credits*/
			credits();
			menu();
			break;
		case 5: /*Admin*/
			admin_login();
			break;
		case 6: /*exit*/
			exit(0);
			break;
	}
}
Пример #13
0
user user_set::new_user() {
	return new_user(new_token());
}