static BOOL opennap_start(Protocol *p) { char alias[16]; if (!(OPENNAP->cfg = gift_config_new("OpenNap"))) { OPN->err(OPN, "Can't load OpenNap configuration!"); return FALSE; } if (!(OPENNAP->con = tcp_bind(OPN_DATAPORT, FALSE))) return FALSE; input_add(OPENNAP->con->fd, OPENNAP->con, INPUT_READ, (InputCallback) opn_upload_connect, TIMEOUT_DEF); if (OPN_RANDOM_USERNAME) { set_username(alias); config_set_str(OPENNAP->cfg, "main/alias", alias); } OPENNAP->nodelist = opn_nodelist_new(); opn_nodelist_load(OPENNAP->nodelist, OPN_USE_NAPIGATOR); return TRUE; }
int main(int argc, char * argv[]) { /* Starts a graphical session and then spins waiting for a kill (logout) signal */ /* Load some session variables */ set_username(); set_homedir(); set_path(); int _wallpaper_pid = fork(); if (!_wallpaper_pid) { char * args[] = {"/bin/wallpaper", NULL}; execvp(args[0], args); } int _panel_pid = fork(); if (!_panel_pid) { char * args[] = {"/bin/panel", NULL}; execvp(args[0], args); } syscall_wait(_panel_pid); printf("Session leader has exited. Sending INT signals to %d.\n", _wallpaper_pid); syscall_send_signal(_wallpaper_pid, 2); printf("Waiting on wallpaper.\n"); syscall_wait(_wallpaper_pid); printf("Session has ended.\n"); }
extern void handle_login_success(const char *username) { /*connect the "Add Contact" button to its handler*/ enable_add_contact_button(); /*set the username that user logged in with*/ set_username(username); /*initialize the users directory*/ if(init_user_directory() != 0 ) { //TODO don't change the GUI to logged in if this step doesn't work... } /*update window title*/ update_window_title(); /*load and show contacts TODO free model? or unref it?*/ GtkListStore *model = create_contact_list_model(); if(model) { toggle_list_view(TRUE, model); } else { edit_label("You don't have any contacts yet."); toggle_list_view(FALSE, NULL); } return; }
user_t make_users(const char * username, const char * password) { api_uri = "api.zoomeye.org"; user_t local = calloc(sizeof (struct user), 1); if (unlikely(local == NULL)) return NULL; INFO_STATUS result = -1; result = set_username(local, username); result = set_password(local, password); result = set_access_token(local); if (result != SET_ACC_TOKEN_SUCCESS) return NULL; #if defined(LIBZEYE_DEBUG) fprintf(stderr, "ACCESS_TOKEN: \n%s\n", local->access_token); #endif return local; }
result_t Url::format(v8::Local<v8::Object> args) { clear(); Isolate* isolate = holder(); exlib::string str; v8::Local<v8::Value> v; if (getString(isolate, args, "protocol", str)) set_protocol(str); if (getString(isolate, args, "username", str)) set_username(str); if (getString(isolate, args, "password", str)) set_password(str); if (getString(isolate, args, "host", str)) set_host(str); if (getString(isolate, args, "port", str)) set_port(str); if (getString(isolate, args, "hostname", str)) set_hostname(str); if (getString(isolate, args, "pathname", str)) set_pathname(str); v = args->Get(holder()->NewString("query")); if (!IsEmpty(v)) set_query(v); if (getString(isolate, args, "hash", str)) set_hash(str); if (m_slashes && m_protocol.compare("file:") && m_hostname.length() == 0) m_slashes = false; v = args->Get(holder()->NewString("slashes")); if (!IsEmpty(v)) set_slashes(v->BooleanValue()); return 0; }
static int get_username_info (void) { char *name = NULL; #if HAS_PASSWORD_CODE struct passwd *pw; #endif #if HAS_PASSWORD_CODE /* I cannot use getlogin under Unix because some implementations * truncate the username to 8 characters. Besides, I suspect that * it is equivalent to the following line. */ /* The man page for getpwuid indicate that the pointer _may_ be to a static * area. So, there is nothing to free here. */ pw = getpwuid (getuid ()); if (pw != NULL) name = pw->pw_name; #endif if (((name == NULL) || (*name == 0)) && ((name = getenv("USER")) == NULL) && ((name = getenv("LOGNAME")) == NULL)) name = "unknown"; if (-1 == set_username (name)) return -1; name = getenv ("NAME"); #if HAS_PASSWORD_CODE if ((name == NULL) && (pw != NULL) && (pw->pw_gecos != NULL)) name = pw->pw_gecos; #endif if (name == NULL) name = ""; if (-1 == set_realname (name)) return -1; return 0; }
static void ndsctl_username(int fd, char *arg) { debug(LOG_DEBUG, "Entering ndsctl_username..."); LOCK_CONFIG(); debug(LOG_DEBUG, "Argument: [%s]", arg); if (!set_username(arg)) { write(fd, "Yes", 3); debug(LOG_NOTICE, "Set username to %s.", arg); } else { write(fd, "No", 2); } UNLOCK_CONFIG(); debug(LOG_DEBUG, "Exiting ndsctl_username."); }
// Initialize connection to server void connection_to_server(connection_info *connection, char *address, char *port) { while(true) { get_username(connection->username); // Create socket if ((connection->socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { perror("Could not create socket"); } connection->address.sin_addr.s_addr = inet_addr(address); connection->address.sin_family = AF_INET; connection->address.sin_port = htons(atoi(port)); // Connect to remote server if (connection( connection->socket, (struct sockaddr )&connection->address, sizeof(connection->address)) < 0) { perror("Connection failed"); exit(1); } set_username(connection); message msg; ssize_t recv_val = recv(connection->socket, &msg, sizeof(message), 0); if (recv_val < 0) { perror("recv failed"); exit(1); } else if (recv_val == 0) { close(connection->socket); printf("The username \"%s\" is taken, please try another name\n", connnection->username); continue; } break; } puts("Connnected to server"); puts("Type /help for usage"); }
int main (){ int pid = 0; command_t cmd = {NULL, 0, {NULL}}; char *commandline = (char *)NULL; char* username = NULL; config_t ag_config; int bg_cmd = AG_FALSE; char prompt[MAX_LINE_LEN]; /* Sets the username */ set_username (&username); /* Opens the syslog file */ openlog (username, LOG_PID, LOG_USER); /* Parses the config files for data */ parse_config (&ag_config, username); /* Initializes GNU Readline */ initialize_readline(&ag_config); /* * Main loop: * - print prompt * - read input and parse it * - either a built-in command ("cd", "?" or "exit) * - or a system command, in which case the program forks and executes it with execvp() */ if (ag_config.welcome_message != NULL && strlen (ag_config.welcome_message) > 0) { fprintf (stdout, "\n%s\n\n", ag_config.welcome_message); } while (AG_TRUE){ /* Set the prompt */ get_prompt(prompt, MAX_LINE_LEN, username); /* * Read a line of input * commandline should be deallocated with free() */ commandline = read_input (prompt); parse_command (commandline, &cmd); switch (get_cmd_code (cmd.name)){ case EMPTY_CMD: break; case CD_CMD: change_directory (cmd.argv[1], ag_config.loglevel); break; case HELP_CMD: print_help(&ag_config); break; case ENV_CMD: print_env (cmd.argv[1]); break; case EXIT_CMD: free (commandline); commandline = (char *)NULL; closelog (); return 0; case OTHER_CMD: /* Determines whether the command should run in the bg or not */ bg_cmd = runs_in_background (&cmd); pid = vfork(); if (pid == 0){ if (!check_validity (cmd, ag_config)){ if (ag_config.loglevel == 3) syslog (LOG_NOTICE, "Using command: %s.", cmd.name); execvp (cmd.argv[0], cmd.argv); fprintf (stderr, "%s: Could not execute command!\nType '?' for help.\n", cmd.name); if (ag_config.loglevel >= 2) syslog (LOG_NOTICE, "Could not execute: %s.", cmd.name); }else { fprintf (stdout, "Not allowed! \n"); if (ag_config.warnings >= 0) decrease_warnings (&ag_config); if (ag_config.loglevel >= 1) syslog (LOG_ERR, "Trying to use forbidden command: %s.", cmd.name); } _exit(EXIT_FAILURE); }else if (pid < 0){ fprintf (stderr, "Error! ... Negative PID. God knows what that means ...\n"); if (ag_config.loglevel >= 1) syslog (LOG_ERR, "Negative PID. Using command: %s.", cmd.name); }else { if (!bg_cmd) wait (0); } break; } free (commandline); commandline = (char *)NULL; } if (commandline) free (commandline); closelog(); return 0; }
/** @param filename Full path of the configuration file to be read */ void config_read(const char *filename) { FILE *fd; char line[MAX_BUF], *s, *p1, *p2; int linenum = 0, opcode, value; debug(LOG_INFO, "Reading configuration file '%s'", filename); if (!(fd = fopen(filename, "r"))) { debug(LOG_ERR, "FATAL: Could not open configuration file '%s', " "exiting...", filename); exit(1); } while (fgets(line, MAX_BUF, fd)) { linenum++; s = _strip_whitespace(line); /* if nothing left, get next line */ if(s[0] == '\0') continue; /* now we require the line must have form: <option><whitespace><arg> * even if <arg> is just a left brace, for example */ /* find first word (i.e. option) end boundary */ p1 = s; while ((*p1 != '\0') && (!isspace(*p1))) p1++; /* if this is end of line, it's a problem */ if(p1[0] == '\0') { debug(LOG_ERR, "Option %s requires argument on line %d in %s", s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } /* terminate option, point past it */ *p1 = '\0'; p1++; /* skip any additional leading whitespace, make p1 point at start of arg */ while (isblank(*p1)) p1++; debug(LOG_DEBUG, "Parsing option: %s, arg: %s", s, p1); opcode = config_parse_opcode(s, filename, linenum); switch(opcode) { case oDaemon: if (config.daemon == -1 && ((value = parse_boolean_value(p1)) != -1)) { config.daemon = value; } break; case oDebugLevel: if(sscanf(p1, "%d", &config.debuglevel) < 1 || config.debuglevel < LOG_EMERG || config.debuglevel > LOG_DEBUG) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s. Valid debuglevel %d..%d", p1, s, linenum, filename, LOG_EMERG, LOG_DEBUG); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oMaxClients: if(sscanf(p1, "%d", &config.maxclients) < 1) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oGatewayName: config.gw_name = safe_strdup(p1); break; case oGatewayInterface: config.gw_interface = safe_strdup(p1); break; case oGatewayIPRange: config.gw_iprange = safe_strdup(p1); break; case oGatewayAddress: config.gw_address = safe_strdup(p1); break; case oGatewayPort: if(sscanf(p1, "%u", &config.gw_port) < 1) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oRemoteAuthenticatorAction: config.remote_auth_action = safe_strdup(p1); break; case oEnablePreAuth: value = parse_boolean_value(p1); if (value != - 1) config.enable_preauth = value; break; case oBinVoucher: config.bin_voucher = safe_strdup(p1); break; case oForceVoucher: value = parse_boolean_value(p1); if (value != - 1) config.force_voucher = value; break; case oFirewallRuleSet: parse_firewall_ruleset(p1, fd, filename, &linenum); break; case oEmptyRuleSetPolicy: parse_empty_ruleset_policy(p1, filename, linenum); break; case oTrustedMACList: parse_trusted_mac_list(p1); break; case oBlockedMACList: parse_blocked_mac_list(p1); break; case oAllowedMACList: parse_allowed_mac_list(p1); break; case oMACmechanism: if(!strcasecmp("allow",p1)) config.macmechanism = MAC_ALLOW; else if(!strcasecmp("block",p1)) config.macmechanism = MAC_BLOCK; else { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oWebRoot: /* remove any trailing slashes from webroot path */ while((p2 = strrchr(p1,'/')) == (p1 + strlen(p1) - 1)) *p2 = '\0'; config.webroot = safe_strdup(p1); break; case oSplashPage: config.splashpage = safe_strdup(p1); break; case oImagesDir: config.imagesdir = safe_strdup(p1); break; case oPagesDir: config.pagesdir = safe_strdup(p1); break; case oRedirectURL: config.redirectURL = safe_strdup(p1); break; case oNdsctlSocket: free(config.ndsctl_sock); config.ndsctl_sock = safe_strdup(p1); break; case oDecongestHttpdThreads: if ((value = parse_boolean_value(p1)) != -1) { config.decongest_httpd_threads = value; } else { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oHttpdThreadThreshold: if(sscanf(p1, "%d", &config.httpd_thread_threshold) < 1) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oHttpdThreadDelayMS: if(sscanf(p1, "%d", &config.httpd_thread_delay_ms) < 1) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oClientIdleTimeout: if(sscanf(p1, "%d", &config.clienttimeout) < 1) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oClientForceTimeout: if(sscanf(p1, "%d", &config.clientforceout) < 1) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oAuthenticateImmediately: if ((value = parse_boolean_value(p1)) != -1) { config.authenticate_immediately = value; } else { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oPasswordAuthentication: if ((value = parse_boolean_value(p1)) != -1) { config.passwordauth = value; } else { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oUsernameAuthentication: if ((value = parse_boolean_value(p1)) != -1) { config.usernameauth = value; } else { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oPasswordAttempts: if(sscanf(p1, "%d", &config.passwordattempts) < 1) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oUsername: set_username(p1); break; case oPassword: set_password(p1); break; case oSetMSS: if ((value = parse_boolean_value(p1)) != -1) { config.set_mss = value; } else { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oMSSValue: if(sscanf(p1, "%d", &config.mss_value) < 1) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oTrafficControl: if ((value = parse_boolean_value(p1)) != -1) { config.traffic_control = value; } else { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oDownloadLimit: if(sscanf(p1, "%d", &config.download_limit) < 1) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oUploadLimit: if(sscanf(p1, "%d", &config.upload_limit) < 1) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oDownloadIMQ: if(sscanf(p1, "%d", &config.download_imq) < 1) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oUploadIMQ: if(sscanf(p1, "%d", &config.upload_imq) < 1) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oFWMarkAuthenticated: if(sscanf(p1, "%x", &config.FW_MARK_AUTHENTICATED) < 1 || config.FW_MARK_AUTHENTICATED == 0 || config.FW_MARK_AUTHENTICATED == config.FW_MARK_BLOCKED || config.FW_MARK_AUTHENTICATED == config.FW_MARK_TRUSTED) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oFWMarkBlocked: if(sscanf(p1, "%x", &config.FW_MARK_BLOCKED) < 1 || config.FW_MARK_BLOCKED == 0 || config.FW_MARK_BLOCKED == config.FW_MARK_AUTHENTICATED || config.FW_MARK_BLOCKED == config.FW_MARK_TRUSTED) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oFWMarkTrusted: if(sscanf(p1, "%x", &config.FW_MARK_TRUSTED) < 1 || config.FW_MARK_TRUSTED == 0 || config.FW_MARK_TRUSTED == config.FW_MARK_AUTHENTICATED || config.FW_MARK_TRUSTED == config.FW_MARK_BLOCKED) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oSyslogFacility: if(sscanf(p1, "%d", &config.syslog_facility) < 1) { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; case oBadOption: debug(LOG_ERR, "Bad option %s on line %d in %s", s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); break; case oPrivoxyMode: if ((value = parse_boolean_value(p1)) != -1) { config.privoxy_mode = value; } else { debug(LOG_ERR, "Bad arg %s to option %s on line %d in %s", p1, s, linenum, filename); debug(LOG_ERR, "Exiting..."); exit(-1); } break; } } fclose(fd); debug(LOG_INFO, "Done reading configuration file '%s'", filename); }
static void set_username_cmd (char *s) { (void) set_username (s); }
void Environment::load_vm_options(int argc, char**argv) { /* We parse -X options from three sources in the following order: * * 1. The file $HOME/.rbxconfig if $HOME is defined. * 2. The file .rbxconfig in the current working directory. * 3. The RBXOPT environment variable. * 4. The command line options. * * This order permits environment and command line options to override * "application" configuration. Likewise, command line options can override * environment configuration. */ char* home = getenv("HOME"); if(home) { std::string config_path(home); config_path += "/.rbxconfig"; if(FILE* fp = fopen(config_path.c_str(), "r")) { read_config_file(fp, config_parser); } } // Configuration file. if(FILE* fp = fopen(".rbxconfig", "r")) { read_config_file(fp, config_parser); } else if(FILE* fp = fopen(".rbxrc", "r")) { std::cerr << "Use of config file .rbxrc is deprecated, use .rbxconfig." << std::endl; read_config_file(fp, config_parser); } // Environment. char* rbxopt = getenv("RBXOPT"); if(rbxopt) { char *e, *b = rbxopt = strdup(rbxopt); char *s = b + strlen(rbxopt); while(b < s) { while(*b && isspace(*b)) b++; e = b; while(*e && !isspace(*e)) e++; if(e - b > 0) { if(strncmp(b, "-X", 2) == 0) { *e = 0; config_parser.import_line(b + 2); } b = e + 1; } } free(rbxopt); } // Command line. for(int i=1; i < argc; i++) { char* arg = argv[i]; if(strcmp(arg, "--") == 0) { break; } if(strncmp(arg, "-X", 2) == 0) { config_parser.import_line(arg + 2); /* If we hit the first non-option, break out so in the following * command line, the first 'rbx' doesn't consume '-Xprofile': * * rbx bundle exec rbx -Xprofile blah */ } else if(arg[0] != '-') { break; } } config_parser.update_configuration(config); set_tmp_path(); set_username(); set_pid(); set_console_path(); set_codedb_paths(); }
int main(int argc, char ** argv) { printf("\n"); system("uname -a"); printf("\n"); syscall_signal(2, sig_int); syscall_signal(11, sig_segv); while (1) { char * username = malloc(sizeof(char) * 1024); char * password = malloc(sizeof(char) * 1024); /* TODO: gethostname() */ char _hostname[256]; syscall_gethostname(_hostname); fprintf(stdout, "%s login: "******"password: \033[1001z"); fflush(stdout); fgets(password, 1024, stdin); password[strlen(password)-1] = '\0'; fprintf(stdout, "\033[1002z\n"); int uid = checkUserPass(username, password); if (uid < 0) { fprintf(stdout, "\nLogin failed.\n"); continue; } system("cat /etc/motd"); pid_t pid = getpid(); uint32_t f = fork(); if (getpid() != pid) { /* TODO: Read appropriate shell from /etc/passwd */ set_username(); set_homedir(); set_path(); char * args[] = { "/bin/sh", NULL }; syscall_setuid(uid); int i = execvp(args[0], args); } else { child = f; syscall_wait(f); } child = 0; free(username); free(password); } return 0; }