void login_main() { int choice; clrscr(); load_users(); clrscr(); printf("********* MAIN MENU *********\n\n1. Login\n2. Register\n3. Stats\n4. Exit\n\nEnter your choice : "); scanf("%d",&choice); switch(choice) { case 1 : login(); break; case 2 : add_user(); login_main(); break; case 3 : stats(); login_main(); break; case 4 : break; } getch(); //loaddatabase(); //menu_exit(); }
int settings::slogin() { if( is_logged ) return 0; QString prev_user = value("previous_user", "").toString(); login ulogin(main_win_parent, prev_user); QString hash, tmp_dir, user, pass; int u_num, ret; user_info try_user; // login while not logged while ( !is_logged ) { ret = ulogin.exec(); if( ret == QDialog::Accepted ) { ulogin.get_user_pass(user, pass); hash = get_hash(user, pass); u_num = get_user_by_name( user ); if( u_num == -1 ) { // no such user QMessageBox::information(main_win_parent, QString("Login"), QString("Involid username or password.\nTry again.")); continue; } try_user = (*users_info)[u_num]; if( get_hash(user, pass) != try_user.hash) { // login failed QMessageBox::information(main_win_parent, QString("Login"), QString("Involid username or password.\nTry again..")); continue; } // login success // check avalible of data dir tmp_dir = value("users/"+user+"/dir", "").toString(); if( check_data_dir( tmp_dir ) ) { remove("users/"+user); load_users(); QMessageBox::information(main_win_parent, QString("Login"), QString("Involid data dir in your account.\nTry again.")); continue; } user_dir.setPath( tmp_dir ); is_logged = 1; username = user; setValue("previous_user", user); return 0; } else { // not accepted -> exit ret = QMessageBox::question(main_win_parent, QString("Login"), QString("You discard login, application will be closed.\nQuit?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); if( ret == QMessageBox::Yes ) exit(0); } } return 10; }
int loadData(Trans *dest) { int valor=OK; valor=load_users(&(*dest)->cliez,"users.txt"); valor=load_cidades(&(*dest)->cidz,"cities.txt"); valor=load_custos(&(*dest)->cidz,"cost.txt"); valor=load_camioes(&(*dest)->cmz,"trucks.txt"); valor=loadcity_trucks((*dest)->cidz,(*dest)->cmz,"trucks.txt");/*este tem que ser chamado depois de a load camioes e load cidades ja foi chamada*/ return valor; }
/* TODO Main admin rules file */ static void init_rules() { struct r_user *users; struct r_rule *rules; char filename[PATH_MAX]; unsigned int fnln; for(users = load_users(R_GRP); users != NULL; users = users->next) { strcpy(filename, users->pw->pw_dir); fnln = strlen(users->pw->pw_dir); strcpy(&filename[fnln], "/."); fnln += strlen("/."); strcpy(&filename[fnln], RULES_FILE); for(rules = parse_rules_file(filename, r_rule_parse); rules != NULL; rules = rules->next) { reactor_add_rule_handler(&reactor, rules); } rules_free(rules); } }
int settings::init() { //__________________________ [ LOGIN ] _______________________________ // get users count int u_count = load_users(); if( u_count < 1 ) { // registration while( !is_logged ) { if( sregistration() ) return 11; } } else { // login while( !is_logged ) { if( slogin() ) return 12; } //________________________ [ LOGIN END ] _______________________________ } return 0; }
int ocelot_main(int argc, char **argv) { // we don't use printf so make cout/cerr a little bit faster std::ios_base::sync_with_stdio(false); Logger::set_log_level( LogLevel::INFO ); signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); bool verbose = false; for (int i = argc; i > 1; i--) { if (!strcmp(argv[1], "-v")) { verbose = true; } } auto db = mysql::get_instance(); if (!db->connected()) { Logger::fail("Cannot connect to database!"); return 0; } db->m_verbose_flush = verbose; config conf; site_comm sc; sc.verbose_flush = verbose; std::vector<std::string> whitelist; db->load_whitelist(whitelist); Logger::info("Loaded " + std::to_string( whitelist.size() ) + " clients into the whitelist"); if (whitelist.size() == 0) { Logger::info("Assuming no whitelist desired, disabling"); } user_list users_list; db->load_users(users_list); Logger::info("Loaded " + std::to_string( users_list.size() ) + " users"); torrent_list torrents_list; db->load_torrents(torrents_list); Logger::info("Loaded " + std::to_string( torrents_list.size() ) + " torrents"); db->load_tokens(torrents_list); stats.open_connections = 0; stats.opened_connections = 0; stats.connection_rate = 0; stats.leechers = 0; stats.seeders = 0; stats.announcements = 0; stats.succ_announcements = 0; stats.scrapes = 0; stats.bytes_read = 0; stats.bytes_written = 0; stats.start_time = time(NULL); // Set Cache TorrentListCache::set( torrents_list ); UserListCache::set( users_list ); WhitelistCache::set( whitelist ); // Create worker object, which handles announces and scrapes and all that jazz work = new worker(torrents_list, users_list, whitelist, &conf, &sc); // Create connection mother, which binds to its socket and handles the event stuff mother = new connection_mother(work); return 0; }
int main(int argc, char **argv) { struct sockaddr_un addr; pid_t pid, sid; int pipefd[2]; int clfd; char deamonize; if(argc==2 && !strncmp(argv[1], "-f", 3)) { deamonize=0; } else { deamonize=1; } if(deamonize) { if(pipe2(pipefd, O_CLOEXEC)) { print( FATAL, "pipe2: %s", strerror(errno) ); return EXIT_FAILURE; } pid = fork(); if(pid<0) { print( FATAL, "fork: %s", strerror(errno) ); return EXIT_FAILURE; } else if(pid) { close(pipefd[1]); if(!read(pipefd[0], &clfd, 1)) return EXIT_FAILURE; return EXIT_SUCCESS; } close(pipefd[0]); umask(0); if(open_logfile(LOG_PATH)) { print( FATAL, "cannot open logfile"); return EXIT_FAILURE; } close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); set_logger(file_logger); sid = setsid(); if(sid<0) { print( FATAL, "setsid: %s", strerror(errno) ); return EXIT_FAILURE; } } if(init_structs()) return EXIT_FAILURE; if(load_handlers()) return EXIT_FAILURE; if(load_users()) return EXIT_FAILURE; if(remove_old_socket()) return EXIT_FAILURE; sockfd = socket(AF_UNIX, SOCK_STREAM, 0); if(sockfd < 0) { print( FATAL, "socket: %s", strerror(errno) ); return EXIT_FAILURE; } if(register_signal_handlers()) { close(sockfd); return EXIT_FAILURE; } memset(&addr, 0, sizeof(struct sockaddr_un)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, SOCKET_PATH, sizeof(addr.sun_path)-1); if(bind(sockfd, (struct sockaddr*)&addr, sizeof(addr))) { print( FATAL, "bind: %s", strerror(errno) ); close(sockfd); unlink(SOCKET_PATH); return EXIT_FAILURE; } if(listen(sockfd, 5)) { print( FATAL, "listen: %s", strerror(errno) ); close(sockfd); unlink(SOCKET_PATH); return EXIT_FAILURE; } if(start_reaper()) { close(sockfd); unlink(SOCKET_PATH); return EXIT_FAILURE; } #ifndef NDEBUG chmod(SOCKET_PATH, 0666); #endif if(deamonize) { if(write(pipefd[1], "!", 1) != 1) { print( FATAL, "cannot notify that daemon started" ); return EXIT_FAILURE; } close(pipefd[1]); } while(1) { if((clfd=accept(sockfd, NULL, NULL)) < 0) { if(errno == EINVAL) { #ifndef NDEBUG print( DEBUG, "socket closed" ); #endif } print( ERROR, "accept: %s", strerror(errno) ); break; } if(serve_new_client(clfd)) { print( WARNING, "cannot serve new connection" ); close(clfd); } } unlink(SOCKET_PATH); close_connections(); stop_reaper(); destroy_structs(); unload_users(); unload_handlers(); return EXIT_SUCCESS; }
BOOL load_config(const char *config) { char *section = NULL, *p; DWORD n, pids[100]; BOOL result = FALSE; int line, chain, i; if (!read_config(config)) return FALSE; // save config to global variable (for get_host_by_name) g_config_file = config; // load information about users if (!load_users(config)) { error("start: Fatal error! Can't load users information!\n"); goto done; } // parse & add rules default and process-related section = (char *)malloc(MAX_SECTION_SIZE); if (section == NULL) { liberr("malloc"); goto done; } GetPrivateProfileSection("_main_", section, MAX_SECTION_SIZE, config); // get lines chain = 0; for (p = section, line = 1; *p != '\0'; p += strlen(p) + 1, line++) { char *p2; if (*p == ';' || *p == '#') continue; // comment p2 = strchr(p, '='); if (p2 == NULL) { error("%s:[_main_]:%d: invalid line format (no '=' character)", config, line); continue; } if (chain >= MAX_CHAINS_COUNT) { error("%s:[_main_]:%d: too many rules lines!", config, line); break; } *p2 = '\0'; // temporary kill '=' add_rules_name(p, config, chain); *p2 = '='; // recover '=' to make strlen(p) works right chain++; } // try to get names for existing processes if (pEnumProcesses != NULL && pEnumProcesses(pids, sizeof(pids), &n)) { DWORD i; n /= sizeof(DWORD); for (i = 0; i < n; i++) { char pname[MAX_PATH]; if (get_pname_by_pid(pids[i], pname + sizeof(DWORD), sizeof(pname) - sizeof(DWORD))) { // send information to driver about pid and pname DWORD nn; *(DWORD *)pname = pids[i]; if (!DeviceIoControl(g_device, IOCTL_CMD_SETPNAME, pname, sizeof(DWORD) + strlen(pname + sizeof(DWORD)) + 1, NULL, 0, &nn, NULL)) winerr("DeviceIoControl"); } } } // activate all chains! for (i = 0; i < chain; i++) { // activate chain #i if (!DeviceIoControl(g_device, IOCTL_CMD_ACTIVATECHAIN, &i, sizeof(i), NULL, 0, &n, NULL)) winerr("start: DeviceIoControl"); } result = TRUE; done: free(section); return result; }
void load_config (char *filename) { FILE *cfgfile; char string[81], bakstring[81]; /* char *command; */ char command[20]; int i, j; int found=0; line=0; edit_bot = 0; edit_channel =0; cfg_error = 0; if ( (cfgfile = fopen (filename, "r")) != NULL ) { /* Load it */ printf("Parsing main configuration file...\n"); while ( fgets (string, (int) sizeof(string)-1, cfgfile) != 0 ) { line++; strcpy (bakstring, string); sscanf (string, "%s ", command); found=0; for(i=0; configtable[i].Name; i++) { if(strcasecmp(configtable[i].Name, command) == 0) { found=1; (configtable[i].Func)(bakstring + strlen (command)+1); } } if (found == 0 && (strlen (command)!=0) && command[0]!='#' && command[0]!=';') { /* Report than an unknown configuraton command was used */ printf("Error parsing configuration (line %d) - Unknown command %s\n", line, command); } strcpy(string, ""); strcpy(command, ""); } fclose (cfgfile) ; printf("Completed configuration file parsing.\n"); if (cfg_error==1) { exit_nicely(100); } #ifdef PARSE_CONFIG_ONLY exit_nicely(0); #endif /* Now load in the user files as well */ printf("Parsing channel user files...\n"); for (i=1; i<=no_bots (thebots); i++) { for (j=1; j<=get_bot (thebots,i)->no_channels; j++) { load_users ( get_channel ( get_bot (thebots, i), j)); } } printf("All done.\n"); } else { /* Could not be found - this is a fatal error */ /* But we can't do a syslog, so print it */ printf("Fatal Error: Could not load configuration file %s\n", filename); exit_nicely(100); } }