/* * func_login logs the user into the remote host. */ void func_login( char *command) { char *User=NULL; if( command && *command) User=&command[5]; if( flag_connected ) { /* ignore leading whitespace */ while(User && (*User == ' ' || *User == 't') && *User) User++; /* if user name was not provided via command line, read it in. */ if(!User || !(*User) ) { printf("Login:"******"n"); /* remove 'n' */ } /* * send user name & password to server & get reply message */ sprintf(tmp_buffer,"USER %srn",User); send_ctrl_msg(tmp_buffer,strlen(tmp_buffer)); k=get_host_reply(); TranslateReply(k); getpassword( ftp_pass ); sprintf(tmp_buffer,"PASS %srn",ftp_pass); send_ctrl_msg(tmp_buffer,strlen(tmp_buffer)); k=get_host_reply(); TranslateReply(k); } else printf("Not connected.n"); }
void login() { showloginform(); getloginid(); getpassword(); enter(); }
/* * login to remote system */ void rlogin(char *rsys, char *keyspec) { char *line; char pass[128]; UserPasswd *up; up = nil; for(;;){ if(up == nil && os != Plan9) up = auth_getuserpasswd(auth_getkey, "proto=pass server=%s service=ftp %s", rsys, keyspec); if(up != nil){ sendrequest("USER", up->user); } else { print("User[default = %s]: ", user); line = Brdline(&stdin, '\n'); if(line == 0) exits(0); line[Blinelen(&stdin)-1] = 0; if(*line){ free(user); user = strdup(line); } sendrequest("USER", user); } switch(getreply(&ctlin, msg, sizeof(msg), 1)){ case Success: goto out; case Incomplete: break; case TempFail: case PermFail: continue; } if(up != nil){ sendrequest("PASS", up->passwd); } else { if(getpassword(pass, pass+sizeof(pass)) < 0) exits(0); sendrequest("PASS", pass); } if(getreply(&ctlin, msg, sizeof(msg), 1) == Success){ if(strstr(msg, "Sess#")) defos = MVS; break; } } out: if(up != nil){ memset(up, 0, sizeof(*up)); free(up); } }
int decode_password(char* pass, char* fname, char* ip, char* uname) { char code[9]; ulong map_size = 0; char* buf = NULL; char* data = NULL; char col[BUFSIZ]; int col_len = 0; getpassword(code, 8, "input encrypt code(8 char): "); map_size = map_file(fname, &buf); data = buf; while(*data != EOF) { // get ip if(col_cmp(data, ip) != 0) { data = next_line(data); continue; } // get username data = next_column(data); if(*data == EOF) break; if(col_cmp(data, uname) != 0) { data = next_line(data); continue; } // get password length data = next_column(data); col_len = column_length(data); strncpy(col, data, col_len); col[col_len] = '\0'; long p_len = atol(col); data += (col_len+1); memcpy(pass, data, p_len); pass[p_len] = '\0'; decode(pass, p_len, code); break; } munmap(buf, map_size); }
/* Root password. */ int handlerootpassword(void) { char password[STRING_SIZE]; char commandstring[STRING_SIZE]; /* Root password. */ if (getpassword(password, _("Enter the 'root' user password. Login as this user for commandline access.")) == 2) return 0; snprintf(commandstring, STRING_SIZE, "/bin/echo 'root:%s' | /usr/sbin/chpasswd", password); if (runhiddencommandwithstatus(commandstring, _("Setting password"), _("Setting 'root' password...."), NULL)) { errorbox(_("Problem setting 'root' password.")); return 0; } return 1; }
int password(char *user) { char message[STRING_SIZE]; char password[STRING_SIZE]; char commandstring[STRING_SIZE]; char *tmpstring; if (!strcmp(user, "root")) { strcpy(message, gettext("TR_ENTER_ROOT_PASSWORD")); } else if (!strcmp(user, "admin")) { /* workaround gcc warning, there is really 2 %s there */ tmpstring = strdup(gettext("TR_ENTER_ADMIN_PASSWORD")); snprintf(message, STRING_SIZE, tmpstring, NAME, NAME); free(tmpstring); } else if (!strcmp(user, "backup")) { strcpy(message, gettext("TR_ENTER_BACKUP_PASSWORD")); } else if (!strcmp(user, "dial")) { strcpy(message, gettext("TR_ENTER_DIAL_PASSWORD")); } else { return FAILURE; } if (getpassword(password, message) == SUCCESS) { if (!strcmp(user, "admin") || !strcmp(user, "dial")) { snprintf(commandstring, STRING_SIZE, "/usr/sbin/htpasswd -m -b /var/ipcop/auth/users %s '%s'", user, password); } else { snprintf(commandstring, STRING_SIZE, "/bin/echo '%s:%s' | /usr/sbin/chpasswd", user, password); } if (mysystemhidden(commandstring)) { snprintf(message, STRING_SIZE, "%s %s", gettext("TR_PROBLEM_SETTING_PASSWORD_FOR"), user); newtWinMessage(get_title(), gettext("TR_OK"), message); return FAILURE; } } return SUCCESS; }
static char * password_cb(PK11SlotInfo *slot, PRBool retry, void *arg) { sighandler_type saveint; char *pass = NULL; (void)&saveint; (void)&pass; saveint = safe_signal(SIGINT, SIG_IGN); if (sigsetjmp(nssjmp, 1) == 0) { if (saveint != SIG_IGN) safe_signal(SIGINT, nsscatch); pass = getpassword(&otio, &reset_tio, arg); } safe_signal(SIGINT, saveint); if (pass == NULL) return NULL; return PL_strdup(pass); }
void LDAPHHA1(RequestData * requestData) { char *password; ldapconnect(); password = getpassword(requestData->user, requestData->realm); if (password != NULL) { if (encrpass) xstrncpy(requestData->HHA1, password, sizeof(requestData->HHA1)); else { HASH HA1; DigestCalcHA1("md5", requestData->user, requestData->realm, password, NULL, NULL, HA1, requestData->HHA1); } free(password); } else { requestData->error = -1; } }
static int initialize(const master_t *master, passwand_entry_t *entries, size_t entry_len) { saved_master = master; saved_entries = entries; saved_entry_len = entry_len; found = false; master_t *confirm = getpassword("confirm master password: "******"out of memory\n"); return -1; } bool r = strcmp(master->master, confirm->master) == 0; discard_master(confirm); if (!r) { eprint("passwords do not match\n"); return -1; } return 0; }
int handleadminpassword(void) { char password[STRING_SIZE]; char commandstring[STRING_SIZE]; char message[1000]; /* web interface admin password. */ sprintf(message, _("Enter %s 'admin' user password. " "This is the user to use for logging into the %s web administration pages."), NAME, NAME); if (getpassword(password, message) == 2) return 0; snprintf(commandstring, STRING_SIZE, "/usr/bin/htpasswd -c -B -C 7 -b " CONFIG_ROOT "/auth/users admin '%s'", password); sprintf(message, _("Setting %s 'admin' user password..."), NAME); if (runhiddencommandwithstatus(commandstring, _("Setting password"), message, NULL)) { sprintf(message, _("Problem setting %s 'admin' user password."), NAME); errorbox(message); return 0; } return 1; }
int main(int argc, char* argv[]) { if(argc < 2) { usage(); return -1; } InitModuleObjects(); const char *action = NULL, *configfile = NULL, *username = NULL, *passwd = NULL, *resource = NULL, *resourcetype = NULL, *newpasswd = NULL, *firstname = NULL, *lastname=NULL; bool stress = false; int numthrds = 0; int numrounds = 0; int numfiles = 0; int i = 1; while(i<argc) { if (stricmp(argv[i], "-ac")==0 || stricmp(argv[i], "-au") == 0 || stricmp(argv[i], "-ar") == 0|| stricmp(argv[i], "-cp") == 0) { action = argv[i++]; } else if (stricmp(argv[i], "-c")==0) { i++; configfile = argv[i++]; } else if (stricmp(argv[i],"-u")==0) { i++; username = argv[i++]; } else if (stricmp(argv[i], "-p")==0) { i++; passwd = argv[i++]; } else if (stricmp(argv[i], "-r")==0) { i++; resource = argv[i++]; } else if (stricmp(argv[i], "-t") == 0) { i++; resourcetype = argv[i++]; } else if (stricmp(argv[i], "-np") == 0) { i++; newpasswd = argv[i++]; } else if (stricmp(argv[i], "-fn") == 0) { i++; firstname = argv[i++]; } else if (stricmp(argv[i], "-ln") == 0) { i++; lastname = argv[i++]; } else if (stricmp(argv[i], "-stress") == 0) { stress = true; i++; numthrds = atoi(argv[i++]); numrounds = atoi(argv[i++]); } else if (stricmp(argv[i], "-open") == 0) { i++; numfiles = atoi(argv[i++]); } else { printf("Error: command format error\n"); usage(); return -1; } } if(configfile == NULL || *configfile == '\0') { printf("You have to specify the config file"); return -1; } try { Owned<IPropertyTree> cfg = createPTreeFromXMLFile(configfile); Owned<IPropertyTree> seccfg = cfg->getPropTree(".//ldapSecurity"); if(seccfg == NULL) { printf("ldapSecurity not found\n"); return -1; } #ifdef _NO_LDAP printf("System was built with _NO_LDAP\n"); return -1; #else Owned<ISecManager> secmgr = newLdapSecManager("test", *LINK(seccfg)); if(secmgr == NULL) { printf("security manager can't be created\n"); return -1; } if(action == NULL || stricmp(action, "-ac") == 0) { if(username == NULL || *username == '\0') { printf("missing username\n"); return -1; } if(resource == NULL || *resource == '\0') { printf("missing resource\n"); return -1; } SecResourceType rtype = RT_DEFAULT; if((resourcetype != NULL) && (stricmp(resourcetype, "filescope") == 0)) rtype = RT_FILE_SCOPE; else if((resourcetype != NULL) && (stricmp(resourcetype, "workunit") == 0)) rtype = RT_WORKUNIT_SCOPE; StringBuffer passbuf; if(passwd == NULL || *passwd == '\0') { getpassword("Enter password: "******"%s's permission = %d \n", resource, access); } else { CPermissionCheckThread** thrds = new CPermissionCheckThread*[numthrds]; for(int i = 0; i < numthrds; i++) thrds[i] = new CPermissionCheckThread(secmgr, username, passwd, resource, rtype, numrounds); for(int j = 0; j < numthrds; j++) thrds[j]->start(); for(int k = 0; k < numthrds; k++) thrds[k]->join(); } } else if(stricmp(action, "-au") == 0) { if(username == NULL || *username == '\0') { printf("missing username\n"); return -1; } Owned<ISecUser> usr = secmgr->createUser(username); if(firstname != NULL) usr->setFirstName(firstname); if(lastname != NULL) usr->setLastName(lastname); usr->credentials().setPassword(passwd); bool ok = usr?secmgr->addUser(*usr):false; if(ok) printf("user %s added\n", username); else printf("user %s not added\n", username); } else if(stricmp(action, "-ar") == 0) { if(resource == NULL || *resource == '\0') { printf("missing resource\n"); return -1; } SecResourceType rtype = RT_DEFAULT; if((resourcetype != NULL) && (stricmp(resourcetype, "filescope") == 0)) rtype = RT_FILE_SCOPE; else if((resourcetype != NULL) && (stricmp(resourcetype, "workunit") == 0)) rtype = RT_WORKUNIT_SCOPE; Owned<ISecUser> usr; if(username != NULL && *username != '\0') usr.setown(secmgr->createUser(username)); bool ok = secmgr->addResourceEx(rtype, *usr, resource, PT_ADMINISTRATORS_ONLY, NULL); if(!ok) printf("resource not added\n"); else printf("resource %s added\n", resource); } else if(stricmp(action, "-cp") == 0) { if(username == NULL || *username == '\0') { printf("missing username\n"); return -1; } StringBuffer passbuf, newpassbuf; if(passwd == NULL || *passwd == '\0') { getpassword("Enter password: "******"\nEnter new password: "******"user password changed\n"); else printf("user password not changed\n"); } #endif } catch(IException* e) { StringBuffer errmsg; e->errorMessage(errmsg); printf("%s\n", errmsg.str()); } catch(...) { printf("Unknown exception\n"); } releaseAtoms(); return 0; }
int main(int argc,char *argv[]) { if(!BaseSock::BaseInit()) { cout << "base init failed\n"; return 0; } int arganz = 0; string arg1 = ""; string arg2 = ""; arganz = argc -1; if(arganz > 0) arg1 = argv[1]; if(arganz > 1) arg2 = argv[2]; cout << "Simple Win32/Linux traffic bouncer v0.2.2 2011/02/07 (c) _hawk_/PPX\n"; cout << "Using " << version << "\n"; if(arganz < 1 && arganz > 2) { cout << "usage: tbnc <configfile> or tbnc -u <configfile> for uncrypted conf\n"; return 0; } if(arganz == 1) { string key; getpassword("Enter blowfish key",key); if(!options.config.Init(arg1,key)) { cout << "error reading conf\n"; return 0; } } else { if(arg1 == "-u") { if(!options.config.Init(arg2,"")) { cout << "error reading conf\n"; return 0; } } else { cout << "usage: tbnc <configfile> or tbnc -u <configfile> for uncrypted conf\n"; return 0; } } options.GetOptional(); if(!options.GetRequired()) { cout << "one or more basic options not set\n"; return 0; } if(options.buffersize > 0) { BaseSock::Buffersize(options.buffersize); } if(options.sndrcvbufsize > 0) { BaseSock::SndRcvBufSize(options.sndrcvbufsize); } if(!BaseSock::BaseSslInit(options.certpath, options.certpath)) { cout << "Ssl server init failed\n"; return 0; } if(options.delay > 0) { BaseSock::Delay(options.delay); } if(options.retrycount > 0) { BaseSock::Retrycount(options.retrycount); } ServerSock ss; if(!ss.Init()) { cout << "socket init failed\n"; return 0; } if(!ss.Bind(options.listenip, options.listenport)) { cout << "could not bind\n"; return 0; } ss.Listen(100); if(!options.logToScreen) { #ifdef _WIN32 cout << "Close console window now - tbnc running in background now\n"; #endif daemon(1,1); #ifdef _WIN32 #else if(options.pidfile != "") { int pid = getpid(); ofstream pidf(options.pidfile.c_str(), ios::out | ios::trunc); if (!pidf) { cout << "can not create pid file\n"; } else { pidf << pid << "\n"; pidf.close(); } } #endif } while(1) { EntryThread *et = NULL; et = new EntryThread(&options); if(et != NULL) { if(et->cs.Init(false)) { if(ss.Accept(et->cs,et->clientip,et->clientport)) { et->start(et); } else { options.Log("main: Accept failed"); delete et; } } else { options.Log("main: init entry thread failed"); delete et; } } else { options.Log("main: failed to create entry thread"); } #ifdef _WIN32 Sleep(10); #else usleep(10 * 1000); #endif } return 1; }
main() { struct passwd *pw_entry ; struct passwd *getpwuid() ; struct stat buf ; int i = 1 ; int uid ; int um ; char pass1[LINESIZE] ; char pass2[LINESIZE] ; char Read_in_Stuff[LINESIZE] ; char **vecptr ; char *tmpdraft ; char home_dir[LINESIZE] ; char *p, *part1, *part2 ; char quipurc_file[100] ; char tailor_file[100] ; char user_name[9] ; char *localptr = Local ; char print_format = EDBOUT ; EntryInfo *ptr ; static CommonArgs ca = default_common_args; vecptr = (char **) malloc(100) ; vecptr[0] = malloc (LINESIZE) ; (void) strcpy(vecptr[0], "showentry") ; (void) strcpy(pass1, "x") ; (void) strcpy(pass2, "y") ; tmpdraft = malloc (LINESIZE) ; (void) strcpy(tmpdraft, "/tmp/dish-") ; if ((opt = ps_alloc (std_open)) == NULLPS) fatal (-62, "ps_alloc failed"); if (std_setup (opt, stderr) == NOTOK) fatal (-63, "std_setup failed"); if ((rps = ps_alloc (std_open)) == NULLPS) fatal (-64, "ps_alloc 2 failed"); if (std_setup (rps, stdout) == NOTOK) fatal (-65, "std_setup 2 failed"); (void) strcpy(filterstring, "userid=") ; /* Sort out files, userids etc. */ uid=getuid() ; if ((pw_entry=getpwuid(uid)) == 0) { ps_printf(rps, "Who are you? (no name for your uid number)\n") ; exit(1) ; } (void) strcpy(user_name, pw_entry->pw_name) ; (void) strcat(tmpdraft, user_name) ; if (getenv("HOME") == 0) { ps_printf(rps, "No home directory?!!") ; (void) strcpy(home_dir, pw_entry->pw_dir) ; } else { (void) strcpy(home_dir, getenv("HOME")) ; } (void) strcpy(quipurc_file, home_dir) ; (void) strcat(quipurc_file, "/.quipurc") ; (void) strcpy(tailor_file, isodefile ("dishinit", 1)); Manager[0] = 0; Password[0] = 0; Local[0] = 0; (void) stat(tailor_file, &buf) ; (void) seteuid(buf.st_uid) ; /* set effective to enable */ /* us to read protected file */ if ((fp_tailor = fopen(tailor_file, "r")) == 0) { ps_print(rps, "Can't open Tailor File. Abort.\n") ; exit(1) ; } while (fgets (Read_in_Stuff, LINESIZE, fp_tailor) != 0) { if (!strcmp(Read_in_Stuff, "##Anything after this line is copied into the users ~/.quipurc file\n")) { break ; } p = SkipSpace (Read_in_Stuff); if (( *p == '#') || (*p == '\0')) continue; /* ignore comments and blanks */ part1 = p; if ((part2 = index (p,':')) == NULLCP) { ps_printf (opt,"Seperator missing '%s'. Ignoring..\n",p); } *part2++ = '\0'; part2 = TidyString (part2); if (lexequ(part1, "manager") == 0) { (void) strcpy(Manager, part2) ; } else if (lexequ(part1, "password") == 0) { (void) strcpy(Password, part2) ; } else if (lexequ(part1, "local") == 0) { (void) strcpy(Local, part2) ; } else { ps_printf(rps, "Error in tailor. What's a %s?\n", part1) ; } } (void) setuid(uid) ; /* Restore Userid to original user. */ /* create ~/.quipurc file. NB this does eradicate anything in there. * (Theoretically nothing.) */ if (Manager[0] == 0) { ps_print(rps, "Can't find out the managers name\n") ; exit(1) ; } if (Password[0] == 0) { ps_print(rps, "Can't find out the managers password\n") ; exit(1) ; } if (Local[0] == 0) { ps_print(rps, "Can't find out where to search\n") ; exit(1) ; } um = umask(0177) ; if ((fp_quipurc = fopen(quipurc_file, "w")) == 0) { ps_printf(rps, "Can't open ~/.quipurc. Aborting..\n") ; exit(1) ; } (void) umask(um) ; if ((fileps = ps_alloc(std_open)) == NULLPS) { fatal (-66, "ps_alloc 2 failed"); } if (std_setup (fileps, fp_quipurc) == NOTOK) { fatal (-67, "std_setup 2 failed"); } /* Sorting out the bind section */ quipu_syntaxes() ; /* set up the needed function pointers */ dsap_init(&i, &vecptr) ; (void) strcpy(bindarg.dba_passwd, Password) ; bindarg.dba_version = DBA_VERSION_V1988; bindarg.dba_passwd_len = strlen(bindarg.dba_passwd) ; if ((bindarg.dba_dn = str2dn (Manager)) == NULLDN) { ps_printf (opt,"Invalid Manager name %s (???!)\n",Manager) ; exit(1) ; } if (ds_bind (&bindarg, &binderr, &bindresult) != OK) { ps_printf(rps, "Can't bind as the manager.\n") ; exit(1); } /* Hopefully, should be successfully bound */ /* * We now call the search stuff with the right bits, to see if we can get a * match of uid='user_name'. Once there, we echo lots of information from * their entry out to the .quipurc file. * Hopefully there should only be one match. This assumes that ALL dir info * up to date, and that SG do not allow multiple users with the same login. */ /* set up the appropriate structures and defaults. */ search_arg.sra_common = ca; /* struct copy */ search_arg.sra_common.ca_servicecontrol.svc_sizelimit = 2 ; search_arg.sra_eis.eis_allattributes = FALSE ; search_arg.sra_searchaliases = FALSE; search_arg.sra_subset = SRA_ONELEVEL; search_arg.sra_eis.eis_infotypes = EIS_ATTRIBUTESANDVALUES ; search_arg.sra_eis.eis_select = NULLATTR ; search_arg.sra_eis.eis_allattributes = TRUE ; search_arg.sra_filter = filter_alloc() ; /* Default filter. */ search_arg.sra_filter->flt_next = NULLFILTER; search_arg.sra_filter->flt_type = FILTER_ITEM; search_arg.sra_filter->FUFILT = NULLFILTER; if (*localptr == '@') { localptr++; } if ((search_arg.sra_baseobject = str2dn(localptr)) == NULLDN) { ps_printf (opt,"Invalid sequence in username %s.\n", localptr); exit(1) ; } (void) strcat(filterstring, user_name) ; search_arg.sra_filter->flt_un.flt_un_item.fi_type = FILTERITEM_EQUALITY ; if ((search_arg.sra_filter->flt_un.flt_un_item.fi_un.fi_un_ava.ava_type = AttrT_new ("userid")) == NULLAttrT) { ps_printf(rps, "Oops, userid is not a valid attr type. ABORT!!\n") ; exit(1) ; } if ((search_arg.sra_filter->flt_un.flt_un_item.fi_un.fi_un_ava.ava_value = str2AttrV (user_name, search_arg.sra_filter->flt_un.flt_un_item.fi_un.fi_un_ava.ava_type->oa_syntax)) == NULLAttrV) { ps_printf(rps, "%s is not a valid attribute value.\n", user_name) ; } /* call search */ /* We now ought to be in the right place, and with the search stuff set, * ready to call search, and receive one (or no) entry back, which then * gets processed accordingly. */ if (ds_search (&search_arg, &search_error, &search_result) != DS_OK) { ps_printf(rps, "Search failed...\n") ; exit (1) ; /* This is not the same as coming back with */ /* message "search failed to find anything. */ } /* If the user does not exist in the DIT, print out the limited .quipurc * and the warning message, and allow the user to play DISH. */ if (search_result.CSR_entries == NULLENTRYINFO) { ps_printf(opt, "Unfortunately, you seem to have no entry in\n") ; ps_printf(opt, "the directory. Contact '%s' who should be able to help.\n", Manager) ; ps_printf(opt, "In the mean time, you can read, but not write.\n") ; } else { ptr = search_result.CSR_entries ; dn = dn_cpy(ptr->ent_dn) ; /* Essence of move user_name. */ /* collect the info and put it into current_entry */ /* Set up the desired attribute type to be read*/ /* from read.c */ if ((at = AttrT_new ("userPassword")) != NULLAttrT) { as_flag = as_merge (as_flag, as_comp_new (AttrT_cpy (at), NULLAV, NULLACL_INFO)); } else { ps_printf(rps, "Oops, Serious error. unknown attribute type 'userPassword'.\n") ; exit(1) ; } if ((current_entry = local_find_entry (dn, FALSE)) == NULLENTRY) { read_arg.rda_common = ca; /* struct copy */ read_arg.rda_object = dn; read_arg.rda_eis.eis_infotypes = EIS_ATTRIBUTESANDVALUES; read_arg.rda_eis.eis_allattributes = TRUE ; read_arg.rda_eis.eis_select = NULLATTR ; if (ds_read (&read_arg, &read_error, &read_result) != DS_OK) { ps_printf(rps, "We even seem to be having problems reading\n" ) ; ps_printf(rps, "an entry we searched and found!! HELP!!\n") ; exit(1) ; } if (read_result.rdr_entry.ent_attr == NULLATTR) { ps_printf(rps, "No attributes present. Even though\n") ; ps_printf(rps, "we found you by userid attribute!!! HELP!!\n") ; exit (1) ; } cache_entry (&(read_result.rdr_entry), read_arg.rda_eis.eis_allattributes, TRUE) ; } if ((current_entry = local_find_entry (dn, FALSE)) == NULLENTRY) { ps_printf(rps, "We still have nothing.Even after reading? Abort.\n") ; exit(1) ; } ps_printf(fileps, "username: "******"\n") ; ps_printf(fileps, "me: ") ; dn_print(fileps, dn, EDBOUT) ; ps_printf(fileps, "\n") ; /* now showattribute -nokey to display it. */ ps_printf(fileps, "password: "******"You need a password...\n") ; (void) strcpy(pass1, getpassword("Enter Password: "******"Re-enter password: "******"\nMismatch - Try again.\n") ; } } ps_printf(fileps, "%s\n", pass1) ; um = umask(0177) ; if ((fp_draft = fopen(tmpdraft, "w")) == 0) { ps_print(rps, "Can't open draft file... Abort.\n") ; exit(1) ; } (void) umask(um) ; (void) fprintf(fp_draft, "UserPassword = %s\n", pass1) ; (void) fprintf(fp_draft, "acl = self # write # attributes # acl $ userPassword\n") ; (void) fprintf(fp_draft, "acl = others # compare # attributes # acl $ userPassword\n\n") ; (void) fclose(fp_draft) ; if ((fp_draft = fopen (tmpdraft, "r")) == NULL) { ps_printf (opt, "Can't open draft entry %s\n", tmpdraft); exit(1) ; } entry_ptr = get_default_entry (NULLENTRY); #ifdef TURBO_DISK entry_ptr->e_attributes = fget_attributes (fp_draft); #else entry_ptr->e_attributes = get_attributes (fp_draft); #endif (void) fclose (fp_draft); mod_arg.mea_common = ca; /* struct copy */ mod_arg.mea_object = dn; for (moddn = dn ; moddn->dn_parent != NULLDN; moddn=moddn->dn_parent) ; entry_ptr->e_name = rdn_cpy (moddn->dn_rdn); /* add rdn as attribute */ avst = avs_comp_new (AttrV_cpy (&entry_ptr->e_name->rdn_av)); temp = as_comp_new (AttrT_cpy (entry_ptr->e_name->rdn_at), avst, NULLACL_INFO); entry_ptr->e_attributes = as_merge (entry_ptr->e_attributes, temp); for (as = entry_ptr->e_attributes; as != NULLATTR; as = as->attr_link) { emnew = NULLMOD; trail = as->attr_link; as->attr_link = NULLATTR; temp = current_entry->e_attributes; for (; temp != NULLATTR; temp = temp->attr_link) if (AttrT_cmp (as->attr_type, temp->attr_type) == 0) { /* found it - does it need changing ? */ if (avs_cmp (as->attr_value, temp->attr_value) != 0) emnew = modify_avs (as->attr_value, temp->attr_value,as->attr_type); break; } if (temp == NULLATTR) { emnew = em_alloc (); emnew->em_type = EM_ADDATTRIBUTE; emnew->em_what = as_cpy(as); emnew->em_next = NULLMOD; } if (emnew != NULLMOD) { mod_arg.mea_changes = ems_append (mod_arg.mea_changes,emnew); } as->attr_link = trail; } while (ds_modifyentry (&mod_arg, &mod_error) != DS_OK) { if (dish_error (opt, &mod_error) == 0) { ps_printf(rps,"We have a dish error. Bye.\n") ; entry_free (entry_ptr); exit(1) ; } mod_arg.mea_object = mod_error.ERR_REFERRAL.DSE_ref_candidates->cr_name; } ps_print (rps, "Modified "); dn_print (rps, dn, EDBOUT); ps_print (rps, "\n"); delete_cache (dn); /* re-cache when next read */ entry_free (entry_ptr); ems_part_free (mod_arg.mea_changes); } } while(fgets(Read_in_Stuff, LINESIZE, fp_tailor) != 0) { fputs(Read_in_Stuff, fp_quipurc) ; } (void) fclose(fp_quipurc) ; (void) fclose(fp_tailor) ; /* (void) fprintf(fp_quipurc, "dsap: local_dit \"%s\"\n", Local) ; (void) fprintf(fp_quipurc, "notype: acl\n") ; (void) fprintf(fp_quipurc, "notype: treestructure\n") ; (void) fprintf(fp_quipurc, "notype: masterdsa\n") ; (void) fprintf(fp_quipurc, "notype: slavedsa\n") ; (void) fprintf(fp_quipurc, "notype: objectclass\n") ; (void) fprintf(fp_quipurc, "cache_time: 30\n") ; (void) fprintf(fp_quipurc, "connect_time: 2\n") ; */ (void) ds_unbind() ; (void) unlink(tmpdraft) ; }
int authenticate(char **p) { FILE *f_key, *f_salt; unsigned char key[AES256_KEY_SIZE], key_stored[AES256_KEY_SIZE]; unsigned char salt[SHA256_SALT_SIZE]; char *password, key_fn[BUFFER_SIZE], salt_fn[BUFFER_SIZE]; int match, i, e, kl, sl, first; first = 0; snprintf(key_fn, BUFFER_SIZE, "%s/key", fn_dir); snprintf(salt_fn, BUFFER_SIZE, "%s/salt", fn_dir); f_key = fopen(key_fn, "rb"); f_salt = fopen(salt_fn, "rb"); first += (f_key == NULL) + (f_salt == NULL); /* A password and salt are stored, so we authenticate */ if(!first) { /* Read salt and stored key for verification */ kl = fread(key_stored, 1, AES256_KEY_SIZE, f_key); sl = fread(salt, 1, SHA256_SALT_SIZE, f_salt); fclose(f_key); fclose(f_salt); /* Check password */ password = getpassword("Password: "******"gcry error: %d\n", e); for(i = 0, match = 1; i < AES256_KEY_SIZE; ++i) match = match && (key[i] == key_stored[i]); if(match) printf("Authentication OK, welcome\n"); else { printf("Authentication failure\n"); return 1; } /* One or both are missing, so we set up new ones */ } else { char *cp; int match = 0; if(f_key) fclose(f_key); if(f_salt) fclose(f_salt); /* Prompt for new password */ printf("No password set, prompting new one.\n"); do { password = getpassword("Password: "******"Confirm password: "******"Passwords do not match, try again.\n"); } while(!match); memset(cp, 0, BUFFER_SIZE); free(cp); /* Generate a salt and key from it */ generate_salt(salt); gcry_kdf_derive(password, strlen(password), GCRY_KDF_PBKDF2, GCRY_MD_SHA256, salt, SHA256_SALT_SIZE, SHA256_ITERATIONS, AES256_KEY_SIZE, key); f_key = fopen(key_fn, "wb"); fwrite(key, 1, AES256_KEY_SIZE, f_key); fclose(f_key); f_salt = fopen(salt_fn, "wb"); fwrite(salt, 1, SHA256_SALT_SIZE, f_salt); fclose(f_salt); printf("New key stored.\n"); } /* Allow the password to be passed back to the caller */ *p = password; return 0; }
int trace( int argc, char **argv ) { uint16_t value_size; struct timeval tv; struct tm *ltime; uint16_t buflen; unsigned char *buf; CEMIFRAME *cemiframe; int enmx_version; int c; int quiet = 0; int total = -1; int count = 0; int spaces = 1; char *user = NULL; char pwd[255]; char *target; char *eis_types; int type; int seconds; unsigned char value[20]; uint32_t *p_int = 0; double *p_real; opterr = 0; while( ( c = getopt( argc, argv, "c:u:q" )) != -1 ) { switch( c ) { case 'c': total = atoi( optarg ); break; case 'u': user = strdup( optarg ); break; case 'q': quiet = 1; break; default: fprintf( stderr, "Invalid option: %c\n", c ); Usage( argv[0] ); exit( -1 ); } } if( optind == argc ) { target = NULL; } else if( optind + 1 == argc ) { target = argv[optind]; } else { Usage( argv[0] ); exit( -1 ); } // catch signals for shutdown signal( SIGINT, Shutdown ); signal( SIGTERM, Shutdown ); // request monitoring connection enmx_version = enmx_init(); sock_con = enmx_open( target, "eibtrace" ); if( sock_con < 0 ) { fprintf( stderr, "Connect to eibnetmux failed (%d): %s\n", sock_con, enmx_errormessage( sock_con )); exit( -2 ); } // authenticate if( user != NULL ) { if( getpassword( pwd ) != 0 ) { fprintf( stderr, "Error reading password - cannot continue\n" ); exit( -6 ); } if( enmx_auth( sock_con, user, pwd ) != 0 ) { fprintf( stderr, "Authentication failure\n" ); exit( -3 ); } } if( quiet == 0 ) { printf( "Connection to eibnetmux '%s' established\n", enmx_gethost( sock_con )); } buf = malloc( 10 ); buflen = 10; if( total != -1 ) { spaces = floor( log10( total )) +1; } while( total == -1 || count < total ) { buf = enmx_monitor( sock_con, 0xffff, buf, &buflen, &value_size ); if( buf == NULL ) { switch( enmx_geterror( sock_con )) { case ENMX_E_COMMUNICATION: case ENMX_E_NO_CONNECTION: case ENMX_E_WRONG_USAGE: case ENMX_E_NO_MEMORY: fprintf( stderr, "Error on write: %s\n", enmx_errormessage( sock_con )); enmx_close( sock_con ); exit( -4 ); break; case ENMX_E_INTERNAL: fprintf( stderr, "Bad status returned\n" ); break; case ENMX_E_SERVER_ABORTED: fprintf( stderr, "EOF reached: %s\n", enmx_errormessage( sock_con )); enmx_close( sock_con ); exit( -4 ); break; case ENMX_E_TIMEOUT: fprintf( stderr, "No value received\n" ); break; } } else { count++; cemiframe = (CEMIFRAME *) buf; gettimeofday( &tv, NULL ); ltime = localtime( &tv.tv_sec ); if( total != -1 ) { printf( "%*d: ", spaces, count ); } printf( "%04d/%02d/%02d %02d:%02d:%02d:%03d - ", ltime->tm_year + 1900, ltime->tm_mon +1, ltime->tm_mday, ltime->tm_hour, ltime->tm_min, ltime->tm_sec, (uint32_t)tv.tv_usec / 1000 ); printf( "%8s ", knx_physical( cemiframe->saddr )); if( cemiframe->apci & A_WRITE_VALUE_REQ ) { printf( "W " ); } else if( cemiframe->apci & A_RESPONSE_VALUE_REQ ) { printf( "A " ); } else { printf( "R " ); } printf( "%8s", (cemiframe->ntwrk & EIB_DAF_GROUP) ? knx_group( cemiframe->daddr ) : knx_physical( cemiframe->daddr )); if( cemiframe->apci & (A_WRITE_VALUE_REQ | A_RESPONSE_VALUE_REQ) ) { printf( " : " ); p_int = (uint32_t *)value; p_real = (double *)value; switch( cemiframe->length ) { case 1: // EIS 1, 2, 7, 8 type = enmx_frame2value( 1, cemiframe, value ); printf( "%s | ", (*p_int == 0) ? "off" : "on" ); type = enmx_frame2value( 2, cemiframe, value ); printf( "%d | ", *p_int ); type = enmx_frame2value( 7, cemiframe, value ); printf( "%d | ", *p_int ); type = enmx_frame2value( 8, cemiframe, value ); printf( "%d", *p_int ); eis_types = "1, 2, 7, 8"; break; case 2: // 6, 13, 14 type = enmx_frame2value( 6, cemiframe, value ); printf( "%d%% | %d", *p_int * 100 / 255, *p_int ); type = enmx_frame2value( 13, cemiframe, value ); if( *p_int >= 0x20 && *p_int < 0x7f ) { printf( " | %c", *p_int ); eis_types = "6, 14, 13"; } else { eis_types = "6, 14"; } break; case 3: // 5, 10 type = enmx_frame2value( 5, cemiframe, value ); printf( "%.2f | ", *p_real ); type = enmx_frame2value( 10, cemiframe, value ); printf( "%d", *p_int ); eis_types = "5, 10"; break; case 4: // 3, 4 type = enmx_frame2value( 3, cemiframe, value ); seconds = *p_int; ltime->tm_hour = seconds / 3600; seconds %= 3600; ltime->tm_min = seconds / 60; seconds %= 60; ltime->tm_sec = seconds; printf( "%02d:%02d:%02d | ", ltime->tm_hour, ltime->tm_min, ltime->tm_sec ); type = enmx_frame2value( 4, cemiframe, value ); ltime = localtime( (time_t *)p_int ); printf( "%04d/%02d/%02d", ltime->tm_year + 1900, ltime->tm_mon +1, ltime->tm_mday ); eis_types = "3, 4"; break; case 5: // 9, 11, 12 type = enmx_frame2value( 11, cemiframe, value ); printf( "%d | ", *p_int ); type = enmx_frame2value( 9, cemiframe, value ); printf( "%.2f", *p_real ); type = enmx_frame2value( 12, cemiframe, value ); // printf( "12: <->" ); eis_types = "9, 11, 12"; break; default: // 15 // printf( "%s", string ); eis_types = "15"; break; } if( cemiframe->length == 1 ) { printf( " (%s", hexdump( &cemiframe->apci, 1, 1 )); } else { printf( " (%s", hexdump( (unsigned char *)(&cemiframe->apci) +1, cemiframe->length -1, 1 )); } printf( " - eis types: %s)", eis_types ); } printf( "\n" ); } } return( 0 ); }
int main( int argc, char **argv ) { int show_usage; uint16_t knxaddress = 0; uint16_t eis; int enmx_version; int quiet = 0; int c; int len; unsigned char value_char; int value_integer; uint32_t value_int32; float value_float; char *string = NULL; unsigned char *data; unsigned char *p_val = NULL; char *user = NULL; char pwd[255]; char *server = NULL; // get parameters show_usage = FALSE; opterr = 0; while( ( c = getopt( argc, argv, "qs:u:" )) != -1 ) { switch( c ) { case 's': server = strdup( optarg ); break; case 'u': user = strdup( optarg ); break; case 'q': quiet = 1; break; default: fprintf( stderr, "Invalid option: %c\n", c ); Usage( argv[0] ); exit( -1 ); } } if( optind + 3 != argc ) { show_usage = TRUE; } else { // knx group address if( strchr( argv[optind +0], '/' ) == NULL ) { if( sscanf( argv[optind +0], "%d", &value_integer ) != 1 ) { show_usage = TRUE; } else { knxaddress = value_integer & 0xffff; } } else { if( (knxaddress = enmx_getaddress( argv[optind +0] )) == 0xffff ) { show_usage = TRUE; } } // eis type if( sscanf( argv[optind +1], "%d", &value_integer ) != 1 || value_integer < 1 || value_integer > 15 ) { show_usage = TRUE; } else { eis = value_integer & 0x0f; //Modification DOMOVISION, Ok c'est degeux mais pour le moment ca fait l'affaire if (eis == 5){ eis=6; } switch( eis ) { case 1: case 2: case 3: case 4: //case 5: case 6: case 7: case 8: case 10: case 14: if( sscanf( argv[optind +2], "%d", &value_integer ) != 1 ) { show_usage = TRUE; } p_val = (unsigned char *)&value_integer; break; case 11: if( sscanf( argv[optind +2], "%d", &value_int32 ) != 1 ) { show_usage = TRUE; } p_val = (unsigned char *)&value_int32; break; case 5: case 9: if( sscanf( argv[optind +2], "%f", &value_float ) != 1 ) { show_usage = TRUE; } p_val = (unsigned char *)&value_float; break; case 13: if( sscanf( argv[optind +2], "%c", &value_char ) != 1 ) { show_usage = TRUE; } p_val = (unsigned char *)&value_char; break; case 15: string = argv[optind +2]; p_val = (unsigned char *)string; break; case 12: break; } } } if( show_usage == TRUE ) { Usage( basename( argv[0] )); exit( -1 ); } // write command to bus if( (enmx_version = enmx_init()) != ENMX_VERSION_API ) { fprintf( stderr, "Incompatible eibnetmux API version (%d, expected %d)\n", enmx_version, ENMX_VERSION_API ); exit( -8 ); } if( (data = malloc( enmx_EISsizeKNX[eis] )) == NULL ) { fprintf( stderr, "Out of memory\n" ); exit( -4 ); } if( enmx_value2eis( eis, (void *)p_val, data ) != 0 ) { fprintf( stderr, "Error in value conversion\n" ); exit( -5 ); } sock_con = enmx_open( server, "eibcommand" ); if( sock_con < 0 ) { fprintf( stderr, "Connect to eibnetmux failed: %s\n", enmx_errormessage( sock_con )); exit( -2 ); } if( quiet == 0 ) printf( "Connecting to eibnetmux server on '%s'\n", enmx_gethost( sock_con )); // authenticate if( user != NULL ) { if( getpassword( pwd ) != 0 ) { fprintf( stderr, "Error reading password - cannot continue\n" ); exit( -6 ); } if( enmx_auth( sock_con, user, pwd ) != 0 ) { fprintf( stderr, "Authentication failure\n" ); exit( -3 ); } } if( quiet == 0 ) printf( "Connection established\n" ); len = (eis != 15) ? enmx_EISsizeKNX[eis] : strlen( string ); if( enmx_write( sock_con, knxaddress, len, data ) != 0 ) { fprintf( stderr, "Unable to send command: %s\n", enmx_errormessage( sock_con )); exit( -7 ); } if( quiet == 0 ) printf( "Request sent to %s\n", enmx_getgroup( knxaddress )); enmx_close( sock_con ); if( quiet == 0 ) printf( "Connection closed\n" ); exit( 0 ); }
int start_TCP_socket(int port) { int result = 0; int pid; int socket_fd; struct sockaddr_in server_address; socklen_t client_addr_len; int buff_size = 255; //Open socket here socket_fd = socket(AF_INET, SOCK_STREAM, 0); if (socket_fd < 0) { printf("Error in creating socket"); log_server("Error in creating socket"); } else { //Declare socket address //First, clear structure memset((char *)&server_address, 0, sizeof(server_address)); //Assign value to server address server_address.sin_family = AF_INET; server_address.sin_port = htons(port); server_address.sin_addr.s_addr = htonl(INADDR_ANY); // socket binding if (bind(socket_fd, (struct sockaddr *)&server_address, sizeof(server_address)) >= 0) { //Create a struct to store peer address: struct sockaddr_in peer_addr; memset((char *)&peer_addr, 0, sizeof(peer_addr)); socklen_t peer_addr_len = sizeof(peer_addr); listen(socket_fd, 5); //Allocate space for the buffer server is about to receive struct tcpquery * buffer = malloc(sizeof(struct tcpquery)); struct tcpquery * buffer2 = malloc(sizeof(struct tcpquery)); while (breaking_signal) { //Accept connection int new_sock = accept(socket_fd, (struct sockaddr *) &peer_addr, &peer_addr_len ); sprintf(ip, "Client IP %s", inet_ntoa(peer_addr.sin_addr)); sprintf(log_c, "New connection accpeted from IP %s\n", ip); log_server(log_c); if (new_sock == -1) { exit(1); } pid = fork(); if (pid < 0) { perror("Erro creating new process\n"); sprintf(log_c, "Erro creating new process\n"); log_server(log_c); } else if (pid == 0) { for (;;) { //Receiving connection request from client.This is an username send for verification int n = recv(new_sock, buffer, sizeof(*buffer), 0 ); if (n < 0) { perror("Data receiving from socket failed. Exit.\n"); sprintf(log_c, "%s :Data receiving from socket failed. Exit.\n", ip); log_server(log_c); exit(1); } else if (n == 0) { printf("Connection closed\n"); sprintf(log_c, "%s :Connection closed\n", ip); log_server(log_c); break; } struct tcpquery incoming = deserialization_tcp(buffer); //Free allocated buffer received //free(buffer); if (verify_tcp_packet(&incoming) == 1) { int password = getpassword(incoming.command); if (password != 0) { if (randomtokenhandling(new_sock) < 0) { perror("Socket writing error.\n"); sprintf(log_c, "%s :Socket writing error.\n", ip); log_server(log_c); exit(1); } int n = recv(new_sock, buffer2, sizeof(*buffer2), 0); if (n < 0) { perror("Data receiving from socket failed. Exit.\n"); sprintf(log_c, "%s :Data receiving from socket failed. Exit.\n", ip); log_server(log_c); exit(1); } else if (n == 0) { printf("Connection closed\n"); sprintf(log_c, "%s :Connection closed\n", ip); log_server(log_c); break; } if (generateH2value(new_sock, password, R)) { if (H_value_compare(buffer2) == 1) { printf("Authentication completed. Success...\n"); sprintf(log_c, "%s :Authentication completed. Success...\n", ip); log_server(log_c); auth_client(new_sock, 1); breaking_signal = 0; result = 1; start_UDP(H2, port); break; } else { printf("Authentication Failed\n"); sprintf(log_c, "%s :Authentication failed\n",ip); log_server(log_c); auth_client(new_sock, 0); //break; } } else { printf("Cannot generate authetication token\n"); sprintf(log_c, "%s :Cannot generate authetication token\n", ip); log_server(log_c); break; } } else { //User not found. Reject connection. printf("User not found. Rejected...\n"); sprintf(log_c, "%s :User not found. Rejected...\n", ip); log_server(log_c); rejectconnection(new_sock); break; } } else { printf("Packet received did not follow defined protocol. Rejected. \n"); sprintf(log_c, "%s :Packet received did not follow defined protocol. Rejected.\n", ip); log_server(log_c); break; } } //Child process suicides here exit(0); } close(new_sock); } close(socket_fd); free(buffer); free(buffer2); } } return result; }
char *getpass_r(const char *prompt, char *buffer, size_t buflen) { return getpassword(prompt, buffer, buflen); }
/* * parse() * * get and execute a command */ static void parse(void) { int i, j, k, flag; while (1) { k = yylex(); switch(k) /* get the token from the input and switch on it */ { case 'h': moveplayer(4); return; /* west */ case 'H': run(4); return; /* west */ case 'l': moveplayer(2); return; /* east */ case 'L': run(2); return; /* east */ case 'j': moveplayer(1); return; /* south */ case 'J': run(1); return; /* south */ case 'k': moveplayer(3); return; /* north */ case 'K': run(3); return; /* north */ case 'u': moveplayer(5); return; /* northeast */ case 'U': run(5); return; /* northeast */ case 'y': moveplayer(6); return; /* northwest */ case 'Y': run(6); return; /* northwest */ case 'n': moveplayer(7); return; /* southeast */ case 'N': run(7); return; /* southeast */ case 'b': moveplayer(8); return; /* southwest */ case 'B': run(8); return; /* southwest */ case '.': /* stay here */ if (yrepcount) viewflag=1; return; case 'c': yrepcount=0; cast(); return; /* cast a spell */ case 'd': yrepcount=0; if (c[TIMESTOP]==0) dropobj(); return; /* to drop an object */ case 'e': yrepcount=0; if (c[TIMESTOP]==0) if (!floor_consume( OCOOKIE, "eat" )) consume( OCOOKIE, "eat", showeat ); return; /* to eat a fortune cookie */ case 'g': yrepcount = 0 ; cursors(); lprintf("\nThe stuff you are carrying presently weighs %d pounds",(long)packweight()); break ; case 'i': /* inventory */ yrepcount=0; nomove=1; showstr(FALSE); return; case 'p': /* pray at an altar */ yrepcount = 0; pray_at_altar(); return; case 'q': /* quaff a potion */ yrepcount=0; if (c[TIMESTOP]==0) if (!floor_consume( OPOTION, "quaff")) consume( OPOTION, "quaff", showquaff ); return; case 'r': yrepcount=0; if (c[BLINDCOUNT]) { cursors(); lprcat("\nYou can't read anything when you're blind!"); } else if (c[TIMESTOP]==0) if (!floor_consume( OSCROLL, "read" )) if (!floor_consume( OBOOK, "read" )) consume( OSCROLL, "read", showread ); return; /* to read a scroll */ case 's': yrepcount = 0 ; sit_on_throne(); return ; case 't': /* Tidy up at fountain */ yrepcount = 0 ; wash_fountain() ; return ; case 'v': yrepcount=0; nomove = 1; cursors(); lprintf("\nLarn, Version %d.%d.%d, Diff=%d",(long)VERSION,(long)SUBVERSION,(long)PATCHLEVEL,(long)c[HARDGAME]); if (wizard) lprcat(" Wizard"); if (cheat) lprcat(" Cheater"); return; case 'w': /* wield a weapon */ yrepcount=0; wield(); return; case 'A': yrepcount = 0; desecrate_altar(); return; case 'C': /* Close something */ yrepcount = 0 ; close_something(); return; case 'D': /* Drink at fountain */ yrepcount = 0 ; drink_fountain() ; return ; case 'E': /* Enter a building */ yrepcount = 0 ; enter() ; break ; case 'I': /* list spells and scrolls */ yrepcount=0; seemagic(0); nomove=1; return; case 'O': /* Open something */ yrepcount = 0 ; open_something(); return; case 'P': cursors(); yrepcount = 0; nomove = 1; if (outstanding_taxes>0) lprintf("\nYou presently owe %d gp in taxes.",(long)outstanding_taxes); else lprcat("\nYou do not owe any taxes."); return; case 'Q': /* quit */ yrepcount=0; quit(); nomove=1; return; case 'R' : /* remove gems from a throne */ yrepcount = 0 ; remove_gems( ); return ; case 'S': /* And do the save. */ cursors(); lprintf("\nSaving to `%s' . . . ", savefilename); lflush(); save_mode = 1; savegame(savefilename); clear(); lflush(); wizard=1; died(-257); /* doesn't return */ break; case 'T': yrepcount=0; cursors(); if (c[SHIELD] != -1) { c[SHIELD] = -1; lprcat("\nYour shield is off"); bottomline(); } else if (c[WEAR] != -1) { c[WEAR] = -1; lprcat("\nYour armor is off"); bottomline(); } else lprcat("\nYou aren't wearing anything"); return; case 'W': yrepcount=0; wear(); return; /* wear armor */ case 'Z': yrepcount=0; if (c[LEVEL]>9) { oteleport(1); return; } cursors(); lprcat("\nAs yet, you don't have enough experience to use teleportation"); return; /* teleport yourself */ case ' ': yrepcount=0; nomove=1; return; case 'L'-64: yrepcount=0; drawscreen(); nomove=1; return; /* look */ #if WIZID #ifdef EXTRA case 'A'-64: yrepcount=0; nomove=1; if (wizard) { diag(); return; } /* create diagnostic file */ return; #endif #endif case '<': /* Go up stairs or vol shaft */ yrepcount = 0; up_stairs(); return ; case '>': /* Go down stairs or vol shaft*/ yrepcount = 0 ; down_stairs(); return ; case '?': /* give the help screen */ yrepcount=0; help(); nomove=1; return; case ',': /* pick up an item */ yrepcount = 0 ; /* pickup, don't identify or prompt for action */ lookforobject( FALSE, TRUE, FALSE ); return; case ':': /* look at object */ yrepcount = 0 ; /* identify, don't pick up or prompt for action */ lookforobject( TRUE, FALSE, FALSE ); nomove = 1; /* assumes look takes no time */ return; case '/': /* identify object/monster */ specify_object(); nomove = 1 ; yrepcount = 0 ; return; case '^': /* identify traps */ flag = yrepcount = 0; cursors(); lprc('\n'); for (j=playery-1; j<playery+2; j++) { if (j < 0) j=0; if (j >= MAXY) break; for (i=playerx-1; i<playerx+2; i++) { if (i < 0) i=0; if (i >= MAXX) break; switch(item[i][j]) { case OTRAPDOOR: case ODARTRAP: case OTRAPARROW: case OTELEPORTER: case OPIT: lprcat("\nIts "); lprcat(objectname[item[i][j]]); flag++; }; } } if (flag==0) lprcat("\nNo traps are visible"); return; #if WIZID case '_': /* this is the fudge player password for wizard mode*/ yrepcount=0; cursors(); nomove=1; if (getpassword()==0) { scbr(); /* system("stty -echo cbreak"); */ return; } wizard=1; scbr(); /* system("stty -echo cbreak"); */ for (i=0; i<6; i++) c[i]=70; iven[0]=iven[1]=0; take(OPROTRING,50); take(OLANCE,25); c[WIELD]=1; c[LANCEDEATH]=1; c[WEAR] = c[SHIELD] = -1; raiseexperience(6000000L); c[AWARENESS] += 25000; { int i,j; for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) know[j][i]=KNOWALL; for (i=0; i<SPNUM; i++) spelknow[i]=1; for (i=0; i<MAXSCROLL; i++) scrollname[i][0]=' '; for (i=0; i<MAXPOTION; i++) potionname[i][0]=' '; } for (i=0; i<MAXSCROLL; i++) if (strlen(scrollname[i])>2) /* no null items */ { item[i][0]=OSCROLL; iarg[i][0]=i; } for (i=MAXX-1; i>MAXX-1-MAXPOTION; i--) if (strlen(potionname[i-MAXX+MAXPOTION])>2) /* no null items */ { item[i][0]=OPOTION; iarg[i][0]=i-MAXX+MAXPOTION; } for (i=1; i<MAXY; i++) { item[0][i]=i; iarg[0][i]=0; } for (i=MAXY; i<MAXY+MAXX; i++) { item[i-MAXY][MAXY-1]=i; iarg[i-MAXY][MAXY-1]=0; } for (i=MAXX+MAXY; i<MAXOBJECT; i++) { item[MAXX-1][i-MAXX-MAXY]=i; iarg[MAXX-1][i-MAXX-MAXY]=0; } c[GOLD]+=250000; drawscreen(); return; #endif }; } }
/* parse() get and execute a command */ static void parse(void) { int i, j, k, flag; while (1) { k = yylex(); switch (k) { /* get the token from the input and switch on * it */ case 'h': moveplayer(4); return; /* west */ case 'H': run(4); return; /* west */ case 'l': moveplayer(2); return; /* east */ case 'L': run(2); return; /* east */ case 'j': moveplayer(1); return; /* south */ case 'J': run(1); return; /* south */ case 'k': moveplayer(3); return; /* north */ case 'K': run(3); return; /* north */ case 'u': moveplayer(5); return; /* northeast */ case 'U': run(5); return; /* northeast */ case 'y': moveplayer(6); return; /* northwest */ case 'Y': run(6); return; /* northwest */ case 'n': moveplayer(7); return; /* southeast */ case 'N': run(7); return; /* southeast */ case 'b': moveplayer(8); return; /* southwest */ case 'B': run(8); return; /* southwest */ case '.': if (yrepcount) viewflag = 1; return; /* stay here */ case 'w': yrepcount = 0; wield(); return; /* wield a weapon */ case 'W': yrepcount = 0; wear(); return; /* wear armor */ case 'r': yrepcount = 0; if (c[BLINDCOUNT]) { cursors(); lprcat("\nYou can't read anything when you're blind!"); } else if (c[TIMESTOP] == 0) readscr(); return; /* to read a scroll */ case 'q': yrepcount = 0; if (c[TIMESTOP] == 0) quaff(); return; /* quaff a potion */ case 'd': yrepcount = 0; if (c[TIMESTOP] == 0) dropobj(); return; /* to drop an object */ case 'c': yrepcount = 0; cast(); return; /* cast a spell */ case 'i': yrepcount = 0; nomove = 1; showstr(); return; /* status */ case 'e': yrepcount = 0; if (c[TIMESTOP] == 0) eatcookie(); return; /* to eat a fortune cookie */ case 'D': yrepcount = 0; seemagic(0); nomove = 1; return; /* list spells and scrolls */ case '?': yrepcount = 0; help(); nomove = 1; return; /* give the help screen */ case 'S': clear(); lprcat("Saving . . ."); lflush(); savegame(savefilename); wizard = 1; died(-257); /* save the game - doesn't return */ case 'Z': yrepcount = 0; if (c[LEVEL] > 9) { oteleport(1); return; } cursors(); lprcat("\nAs yet, you don't have enough experience to use teleportation"); return; /* teleport yourself */ case '^': /* identify traps */ flag = yrepcount = 0; cursors(); lprc('\n'); for (j = playery - 1; j < playery + 2; j++) { if (j < 0) j = 0; if (j >= MAXY) break; for (i = playerx - 1; i < playerx + 2; i++) { if (i < 0) i = 0; if (i >= MAXX) break; switch (item[i][j]) { case OTRAPDOOR: case ODARTRAP: case OTRAPARROW: case OTELEPORTER: lprcat("\nIt's "); lprcat(objectname[item[i][j]]); flag++; }; } } if (flag == 0) lprcat("\nNo traps are visible"); return; #if WIZID case '_': /* this is the fudge player password for * wizard mode */ yrepcount = 0; cursors(); nomove = 1; if (userid != wisid) { lprcat("Sorry, you are not empowered to be a wizard.\n"); scbr(); /* system("stty -echo cbreak"); */ lflush(); return; } if (getpassword() == 0) { scbr(); /* system("stty -echo cbreak"); */ return; } wizard = 1; scbr(); /* system("stty -echo cbreak"); */ for (i = 0; i < 6; i++) c[i] = 70; iven[0] = iven[1] = 0; take(OPROTRING, 50); take(OLANCE, 25); c[WIELD] = 1; c[LANCEDEATH] = 1; c[WEAR] = c[SHIELD] = -1; raiseexperience(6000000L); c[AWARENESS] += 25000; { int i, j; for (i = 0; i < MAXY; i++) for (j = 0; j < MAXX; j++) know[j][i] = 1; for (i = 0; i < SPNUM; i++) spelknow[i] = 1; for (i = 0; i < MAXSCROLL; i++) scrollname[i] = scrollhide[i]; for (i = 0; i < MAXPOTION; i++) potionname[i] = potionhide[i]; } for (i = 0; i < MAXSCROLL; i++) if (strlen(scrollname[i]) > 2) { /* no null items */ item[i][0] = OSCROLL; iarg[i][0] = i; } for (i = MAXX - 1; i > MAXX - 1 - MAXPOTION; i--) if (strlen(potionname[i - MAXX + MAXPOTION]) > 2) { /* no null items */ item[i][0] = OPOTION; iarg[i][0] = i - MAXX + MAXPOTION; } for (i = 1; i < MAXY; i++) { item[0][i] = i; iarg[0][i] = 0; } for (i = MAXY; i < MAXY + MAXX; i++) { item[i - MAXY][MAXY - 1] = i; iarg[i - MAXY][MAXY - 1] = 0; } for (i = MAXX + MAXY; i < MAXX + MAXY + MAXY; i++) { item[MAXX - 1][i - MAXX - MAXY] = i; iarg[MAXX - 1][i - MAXX - MAXY] = 0; } c[GOLD] += 25000; drawscreen(); return; #endif case 'T': yrepcount = 0; cursors(); if (c[SHIELD] != -1) { c[SHIELD] = -1; lprcat("\nYour shield is off"); bottomline(); } else if (c[WEAR] != -1) { c[WEAR] = -1; lprcat("\nYour armor is off"); bottomline(); } else lprcat("\nYou aren't wearing anything"); return; case 'g': cursors(); lprintf("\nThe stuff you are carrying presently weighs %ld pounds", (long) packweight()); case ' ': yrepcount = 0; nomove = 1; return; case 'v': yrepcount = 0; cursors(); lprintf("\nCaverns of Larn, Version %ld.%ld, Diff=%ld", (long) VERSION, (long) SUBVERSION, (long) c[HARDGAME]); if (wizard) lprcat(" Wizard"); nomove = 1; if (cheat) lprcat(" Cheater"); lprcat(copyright); return; case 'Q': yrepcount = 0; quit(); nomove = 1; return; /* quit */ case 'L' - 64: yrepcount = 0; drawscreen(); nomove = 1; return; /* look */ #if WIZID #ifdef EXTRA case 'A': yrepcount = 0; nomove = 1; if (wizard) { diag(); return; } /* create diagnostic file */ return; #endif #endif case 'P': cursors(); if (outstanding_taxes > 0) lprintf("\nYou presently owe %ld gp in taxes.", (long) outstanding_taxes); else lprcat("\nYou do not owe any taxes."); return; }; } }
int main(int argc, char **argv) { FILE *fp = NULL; EVP_PKEY *pkey = NULL; X509 *cert = NULL; STACK_OF(X509) *ca = NULL; PKCS12 *p12 = NULL; char *pass = strdup(""); int i; if (argc != 2) { fprintf(stderr, "[!] Usage: %s certificate.p12\n", argv[0]); exit(1); } printf("[+] Initializing OpenSSL\n"); SSLeay_add_all_algorithms(); ERR_load_crypto_strings(); printf("[+] Opening PKCS#12 certificate\n"); if (!(fp = fopen(argv[1], "r"))) { fprintf(stderr, "[!] Unable to open certificate `%s'\n", argv[1]); goto endpkcs12; } if (chdir(dirname(argv[1])) == -1) { fprintf(stderr, "[!] Unable to change directory to `%s'\n", dirname(argv[1])); goto endpkcs12; } p12 = d2i_PKCS12_fp(fp, NULL); fclose(fp); fp = NULL; if (!p12) { fprintf(stderr, "[!] Unable to parse PKCS#12 certificate: %s\n", ERR_reason_error_string(ERR_get_error())); goto endpkcs12; } while (!PKCS12_parse(p12, pass, &pkey, &cert, &ca)) { ca = NULL; free(pass); if (getpassword("[?] Password: "******"[!] PKCS#12 certificate is incomplete\n"); goto endpkcs12; } #define PEM_w(path, call) \ do { \ if (!(fp = fopen(path, "w"))) { \ fprintf(stderr, "[!] Unable to open `%s'\n", path); \ goto endpkcs12; \ } \ printf("[+] Write certificate to `%s'\n", path); \ call; \ fclose(fp); fp = NULL; \ } while(0) PEM_w("user.pem", PEM_write_X509(fp, cert)); PEM_w("user.key", PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL)); PEM_w("cacert.pem", for (i = 0; i < sk_X509_num(ca); i++) PEM_write_X509(fp, sk_X509_value(ca, i))); sk_free(ca); X509_free(cert); EVP_PKEY_free(pkey); exit(0); endpkcs12: if (pass) free(pass); if (ca) sk_free(ca); if (cert) X509_free(cert); if (pkey) EVP_PKEY_free(pkey); if (p12) PKCS12_free(p12); if (fp) fclose(fp); exit(1); }
int main(int argc, char ** argv){ //if is given parameters for add user if(argc>2){ //check for username in login file FILE * login_file = fopen("login","r"); if(login_file){ //find given username in login file char username[BUFFER_SIZE],password[BUFFER_SIZE]; while(fgets(username,BUFFER_SIZE,login_file)!=NULL){ fgets(password,BUFFER_SIZE,login_file); username[strlen(username)-1]='\0'; password[strlen(password)-1]='\0'; //if we found suitable username and password credentials are OK if(!strcmp(argv[2],username)){ printf("Username already exists !!!!\n"); fclose(login_file); return 0; } } fclose(login_file); } char password[BUFFER_SIZE],password1[BUFFER_SIZE]; //ask for password getpassword("Password: "******"Retype password: "******"login","a"); fprintf(f,"%s\n",argv[2]); fprintf(f,"%s\n",password); fclose(f); } //passwords are not same else printf("Passwords are different!!!\n"); //exiting return 0; } //check for running server FILE * f = fopen(serverLock,"r"); if(f){ printf("Another instance of server is running !!!\n"); fclose(f); return 0; } //create server.lock f = fopen(serverLock,"w"); fclose(f); //print message to server console printf("To quit press q and then enter.\n"); //create child process for processing queries int mypid = 0; int pid = fork(); if(pid > (pid_t)0){ //child process mypid = pid; server_init(); server_run(); } else{ //main process while(1){ char c; scanf("%c",&c); //if q is pressed terminate child process - processing queries if(c=='q'){ printf("Are you sure you want to end the server?\n"); printf("Please confirm (y/n): "); scanf("%s",&c); if(c=='y'){ kill(mypid,SIGTERM); exit(0); } } } } //exit return 0; }
int main(int argc, char* argv[]) { InitModuleObjects(); StringBuffer passwd; if(argc < 2) { usage(); return -1; } else if (stricmp(argv[1], "-?") == 0 || stricmp(argv[1], "-h") == 0 || stricmp(argv[1], "-help") == 0) { usage(); return 0; } bool isBatchMode = false; MysslAction action = CRT; StringBuffer opfname, ocfname, orfname, cbuf, sbuf, lbuf, orgbuf, oubuf, cnbuf, ebuf, daysbuf, pfbuf, cfbuf, rfbuf, pbuf; int i; for (i=1; i<argc; i++) { if (stricmp(argv[i], "-crt") == 0) { action = CRT; } else if (stricmp(argv[i], "-csr") == 0) { action = CSR; } else if (stricmp(argv[i], "-sign") == 0) { action = SIGN; } else if (stricmp(argv[i], "-b") == 0) { isBatchMode = true; } else if(stricmp(argv[i], "-op") == 0) { i++; opfname.append(argv[i]); } else if(stricmp(argv[i], "-oc") == 0) { i++; ocfname.append(argv[i]); } else if(stricmp(argv[i], "-or") == 0) { i++; orfname.append(argv[i]); } else if(stricmp(argv[i], "-c") == 0) { i++; cbuf.append(argv[i]); } else if(stricmp(argv[i], "-s") == 0) { i++; sbuf.append(argv[i]); } else if(stricmp(argv[i], "-l") == 0) { i++; lbuf.append(argv[i]); } else if(stricmp(argv[i], "-org") == 0) { i++; orgbuf.append(argv[i]); } else if(stricmp(argv[i], "-ou") == 0) { i++; oubuf.append(argv[i]); } else if(stricmp(argv[i], "-cn") == 0) { i++; cnbuf.append(argv[i]); } else if(stricmp(argv[i], "-e") == 0) { i++; ebuf.append(argv[i]); } else if(stricmp(argv[i], "-days") == 0) { i++; daysbuf.append(argv[i]); } else if(stricmp(argv[i], "-ip") == 0) { i++; pfbuf.append(argv[i]); } else if(stricmp(argv[i], "-ic") == 0) { i++; cfbuf.append(argv[i]); } else if(stricmp(argv[i], "-ir") == 0) { i++; rfbuf.append(argv[i]); } else if(stricmp(argv[i], "-p") == 0) { i++; pbuf.append(argv[i]); } else { printf("unknown option %s\n", argv[i]); return -1; } } char buf[128]; if(!isBatchMode) { if(action == CSR || action == CRT) { if(cbuf.length() == 0) { printf("Country Name (2 letter code): "); myfgets(buf,128,stdin); if(*buf == '\0') strcpy(buf, "US"); cbuf.append(buf); } if(sbuf.length() == 0) { printf("State (full name): "); myfgets(buf,128,stdin); sbuf.append(buf); } if(lbuf.length() == 0) { printf("Locality Name (eg, city): "); myfgets(buf,128,stdin); lbuf.append(buf); } if(orgbuf.length() == 0) { printf("Organization Name (eg, company): "); myfgets(buf,128,stdin); orgbuf.append(buf); } if(oubuf.length() == 0) { printf("Organizational Unit Name: "); myfgets(buf,128,stdin); oubuf.append(buf); } if(ebuf.length() == 0) { printf("Email: "); myfgets(buf, 128, stdin); ebuf.append(buf); } if(cnbuf.length() == 0) { printf("Common Name (Server's hostname or IP address): "); myfgets(buf, 128, stdin); cnbuf.append(buf); } if(action == CRT) { printf("Number of days for the certificate to be valid: "); myfgets(buf, 128, stdin); if(strlen(buf) > 0) daysbuf.append(buf); printf("Private Key file(leave it blank if you want to generate a private key): "); myfgets(buf,128,stdin); pfbuf.append(buf); getpassword("Enter PEM pass phrase: ", pbuf); } else if(action == CSR) { printf("Private Key file(leave it blank if you want to generate a private key): "); myfgets(buf,128,stdin); pfbuf.append(buf); getpassword("Enter PEM pass phrase: ", pbuf); } } else if(action == SIGN) { printf("csr file: "); myfgets(buf,128,stdin); rfbuf.append(buf); printf("CA certificate file: "); myfgets(buf,128,stdin); cfbuf.append(buf); printf("CA privatekey file: "); myfgets(buf,128,stdin); pfbuf.append(buf); getpassword("CA private key passphrase: ", pbuf); printf("\nNumber of days for the certificate to be valid: "); myfgets(buf,128,stdin); daysbuf.append(buf); } } try { Owned<IFile> opf; Owned<IFileIO> opfio; if(opfname.length() > 0) { opf.setown(createIFile(opfname.str())); opfio.setown(opf->open(IFOcreate)); } Owned<IFile> ocf; Owned<IFileIO> ocfio; if(ocfname.length() > 0) { ocf.setown(createIFile(ocfname.str())); ocfio.setown(ocf->open(IFOcreate)); } Owned<IFile> orf; Owned<IFileIO> orfio; if(orfname.length() > 0) { orf.setown(createIFile(orfname.str())); orfio.setown(orf->open(IFOcreate)); } if(action == CRT || action == CSR) { Owned<ICertificate> cc = createCertificate(); if(cbuf.length() > 0) cc->setCountry(cbuf.str()); if(sbuf.length() > 0) cc->setState(sbuf.str()); if(lbuf.length() > 0) cc->setCity(lbuf.str()); if(orgbuf.length() > 0) cc->setOrganization(orgbuf.str()); if(oubuf.length() > 0) cc->setOrganizationalUnit(oubuf.str()); if(ebuf.length() > 0) cc->setEmail(ebuf.str()); if(cnbuf.length() > 0) cc->setDestAddr(cnbuf.str()); if(action == CSR) { if(pbuf.length() > 0) cc->setPassphrase(pbuf.str()); else throw MakeStringException(-1, "passphrase not specified."); StringBuffer csrbuf, privkey; if(pfbuf.length() == 0) { cc->generateCSR(privkey, csrbuf); if(opfio.get() != NULL) opfio->write(0, privkey.length(), privkey.str()); else printf("\n%s\n", privkey.str()); if(orfio.get() != NULL) orfio->write(0, csrbuf.length(), csrbuf.str()); else printf("\n%s\n", csrbuf.str()); } else { privkey.loadFile(pfbuf.str()); cc->generateCSR(privkey.str(), csrbuf); if(orfio.get() != NULL) orfio->write(0, csrbuf.length(), csrbuf.str()); else printf("\n%s\n", csrbuf.str()); } } else if(action == CRT) { if(daysbuf.length() > 0) { cc->setDays(atoi(daysbuf.str())); } if(pbuf.length() > 0) cc->setPassphrase(pbuf.str()); else throw MakeStringException(-1, "passphrase not specified."); StringBuffer certbuf, privkey; if(pfbuf.length() == 0) { cc->generate(certbuf, privkey); if(opfio.get() != NULL) opfio->write(0, privkey.length(), privkey.str()); else printf("\n%s\n", privkey.str()); if(ocfio.get() != NULL) ocfio->write(0, certbuf.length(), certbuf.str()); else printf("\n%s\n", certbuf.str()); } else { privkey.loadFile(pfbuf.str()); cc->generate(certbuf, privkey.str()); if(ocfio.get() != NULL) ocfio->write(0, certbuf.length(), certbuf.str()); else printf("\n%s\n\n", certbuf.str()); } } } else if(stricmp(argv[1], "-sign") == 0) { StringBuffer csrbuf, ca_cert, ca_privkey, certbuf; if(rfbuf.length() == 0 || cfbuf.length() == 0 || pfbuf.length() == 0) throw MakeStringException(-1, "You need to specify csr file, certificate file and privatekey file"); csrbuf.loadFile(rfbuf.str()); ca_cert.loadFile(cfbuf.str()); ca_privkey.loadFile(pfbuf.str()); if(pbuf.length() == 0) throw MakeStringException(-1, "passphrase not specified."); int days = 365; if(daysbuf.length() > 0) { days = atoi(daysbuf.str()); } signCertificate(csrbuf.str(),ca_cert.str(), ca_privkey.str(), pbuf.str(), days, certbuf); if(ocfio.get() != NULL) ocfio->write(0, certbuf.length(), certbuf.str()); else printf("\n%s\n", certbuf.str()); } else { usage(); return -1; } } catch(IException* e) { StringBuffer errmsg; printf("\nError - %s\n", e->errorMessage(errmsg).str()); e->Release(); } catch(...) { printf("\nUnknown error."); } releaseAtoms(); return 0; }
int main (int argc, char *argv[]) { int sd,res; struct sockaddr_in sin_buf; struct sockaddr_in * sin = &sin_buf; char buffer [BUFSIZ]; char dishname [BUFSIZ]; char * ptr; isodetailor (argv[0], 1); if ((sd = start_tcp_client ((struct sockaddr_in *) 0, 0)) == NOTOK) { perror("start_tcp_client"); exit(-20); } if (get_dish_sock (sin, 0, 1) != 0) exit (-21); if (join_tcp_server (sd, sin) == NOTOK) { int pid; close_tcp_socket (sd); fork_again: ; switch (pid = vfork ()) { case 0: /* child */ close_tcp_socket (sd); strcpy (dishname, _isodefile (isodebinpath, "dish")); { int i, nfds = getdtablesize (); for (i = fileno(stderr) + 1; i < nfds; i++) close (i); } execl (dishname, "dish","-pipe",NULLCP); fprintf (stderr, "unable to exec "); perror (dishname); _exit (-21); case -1: perror ("fork"); close_tcp_socket (sd); exit (-22); default: /* parent */ for (;;) { if ((sd = start_tcp_client ((struct sockaddr_in *) 0, 0)) == NOTOK) { perror("start_tcp_client"); exit(-23); } if (join_tcp_server (sd, sin) != NOTOK) break; /* need to introduce a timeout !!! */ close_tcp_socket (sd); sleep (5); if (kill (pid, 0) == NOTOK) { fprintf (stderr,"Trying again...\n"); goto fork_again; } } break; } } if ((ptr = rindex (argv[0], '/')) == NULLCP) strcpy (buffer,argv[0]); else strcpy (buffer,++ptr); argc--,argv++; while (argc--) { strcat (buffer, " \""); strcat (buffer, *argv++); strcat (buffer, "\""); } strcat (buffer, "\n"); if (send(sd, buffer, strlen(buffer), 0) == -1) { perror("send"); close_tcp_socket (sd); exit (-25); } for (;;) { if ((res = recv(sd, buffer, BUFSIZ - 1, 0)) == -1) { err_recv: ; perror ("recv"); close_tcp_socket (sd); exit (-26); } *(buffer + res) = 0; if (res == 0) { close_tcp_socket (sd); exit (0); } if (*buffer == '2') { if (res > 1) write (2,&buffer[1],--res); while ( (res = recv(sd, buffer, BUFSIZ, 0)) > 0) write (2,buffer,res); close_tcp_socket (sd); exit (1); } else if ((*buffer == '1') || (*buffer == '3')) { int eval; eval = (*buffer == '1' ? 0 : 2); if (res > 1) write (1,&buffer[1],--res); while ( (res = recv(sd, buffer, BUFSIZ, 0)) > 0) write (1,buffer,res); close_tcp_socket (sd); exit (eval); } else { /* 'e', 'y', 'm', or 'p' */ char *cp, *ep; char where[BUFSIZ]; cp = buffer + res - 1; ep = buffer + sizeof buffer - 1; while (*cp != '\n') { ++cp; switch (res = recv (sd, cp, ep - cp, 0)) { case NOTOK: goto err_recv; case OK: fprintf (stderr, "eof reading '%c' directive\n", *buffer); exit (-28); default: cp += res - 1; if (cp < ep) continue; fprintf (stderr, "'%c' directive exceeds %d octets\n", *buffer, sizeof buffer - 1); exit(-29); } } *cp = NULL; if (*buffer == 'e') { if (system (&buffer[1])) strcpy (where, "e"); else getcwd (where, sizeof where); } else if (*buffer == 'm') { fprintf (stderr, "\n%s\n", buffer + 1); strcpy (where, "m"); } else if (*buffer == 'y') { fprintf (stderr,"%s",buffer + 1); fgets (where, sizeof where, stdin); if (cp = index (where, '\n')) *cp = NULL; } else { /* 'p' */ sprintf (where, "Enter password for \"%s\": ", buffer + 1); sprintf (where, "p%s", getpassword (where)); } strcat (where, "\n"); if (send(sd, where, strlen(where), 0) == -1) { perror("send"); close_tcp_socket (sd); exit (-27); } } } }