void NetworkAccount::readConfig(/*const*/ KConfig/*Base*/ & config) { KMAccount::readConfig(config); setLogin(config.readEntry("login")); if(config.readNumEntry("store-passwd", false)) // ### s/Num/Bool/ { mStorePasswd = true; QString encpasswd = config.readEntry("pass"); if(encpasswd.isEmpty()) { encpasswd = config.readEntry("passwd"); if(!encpasswd.isEmpty()) encpasswd = importPassword(encpasswd); } if(!encpasswd.isEmpty()) { setPasswd(decryptStr(encpasswd), true); // migrate to KWallet if available if(Wallet::isEnabled()) { config.deleteEntry("pass"); config.deleteEntry("passwd"); mPasswdDirty = true; mStorePasswdInConfig = false; } else { mPasswdDirty = false; // set by setPasswd() on first read mStorePasswdInConfig = true; } } else { // read password if wallet is already open, otherwise defer to on-demand loading if(Wallet::isOpen(Wallet::NetworkWallet())) readPassword(); } } else { setPasswd("", false); } setHost(config.readEntry("host")); unsigned int port = config.readUnsignedNumEntry("port", defaultPort()); if(port > USHRT_MAX) port = defaultPort(); setPort(port); setAuth(config.readEntry("auth", "*")); setUseSSL(config.readBoolEntry("use-ssl", false)); setUseTLS(config.readBoolEntry("use-tls", false)); mSieveConfig.readConfig(config); }
/*Identifying phase in menu*/ int userIdentify() { extern char username[20]; char prompt[20]; clearCommander(0); silenceOff(); /*Username step*/ while (1 == 1) { printAndWriteFrom(20, "Username: "******"Type 'exit' to break identifying process "); /*Wait for input*/ flushinp(); getstr(prompt); /*If the player would like to exit the logging menu*/ if (strcmp(prompt, "exit") == 0) { break; } /*If provided username do not exist*/ else if (checkUsername(prompt) == FALSE) { thrillerAnimation("Inconsistency detected", "Invalid username, try " "again", 1); continue; } /*If provided username exist, assign its string into 'username' variab*/ else { int i = 0; for (i = 0; prompt[i] != '\0'; ++i) { username[i] = prompt[i]; } } /*Password step*/ memset (prompt, '\0', sizeof(prompt)); clearCommander(0); while (1 == 1) { printAndWriteFrom(20, "Password: "******"exit") == 0) { showCommanderInfo("Identifying has being canceled",1 ); break; } if (checkPassword(prompt) == FALSE) { thrillerAnimation("Inconsistency detected", "Invalid password, " "try again", 1); continue; } /*If player had successfully logged in*/ else { thrillerAnimation("Logging in", "Successfully logged in", 1); return TRUE; } } break; } return 0; }
/*Account creation phase*/ int createAccount() { /*TODO: Check if provided account currently exist*/ char prompt[20], temp_pass[20], temp_username[20]; clearCommander(0); silenceOff(); while (1 == 1) { /*Username step*/ printAndWriteFrom(20, "Type your username: "******"Type 'exit' to break identifying process "); flushinp(); getstr(prompt); /*If entered different string than exit*/ if (strcmp(prompt, "exit") != 0) { strcpy(temp_username, prompt); } /*If the player want to break account creation process */ else { break; } /*Password step*/ clearCommander(0); while (1 == 1) { printAndWriteFrom(20, "Type your password: "******"Your password should be 4 - 20 characters long"); readPassword(prompt); /*If the player haven't pressed ESC*/ if (strcmp(prompt, "exit") != 0) { while (1 == 1) { strcpy(temp_pass, prompt); clearLine(22); printAndWriteFrom(20, "Type your password again: "); /*Read password again in case of mistypes*/ readPassword(prompt); /*If the player had pressed ESC*/ if (strcmp(prompt, "exit") == 0) { showCommanderInfo("Account creation has being canceled", 1); break; } /*If entered password match*/ else if (strcmp(prompt, temp_pass) == 0) { /*Will form those strings adequately to other lines in * accounts.dat*/ char u[20], p[20]; int i = 0; strcpy(u, "u "); strcpy(p, "p "); for (i = 0; i <= stringLength(temp_username); i++) { u[i+2] = temp_username[i]; } u[i+3] = '\n'; for (i = 0; i <= stringLength(temp_pass); i++) { p[i+2] = temp_pass[i]; } p[i+3] = '\n'; /*Write at the end of file this data*/ FILE *pFile = fopen ("accounts.dat" , "a"); /*If file cannot be opened, show an error and then * crash*/ if (pFile == NULL) { perror ("Error opening file"); assert(!TRUE); } /*If successfully open the file*/ else { /*Jump to the next line*/ fputs("\n", pFile); fputs(u, pFile); /*Jump to the next line*/ fputs("\n", pFile); fputs(p, pFile); showCommanderInfo("Account has been successfully " "created", 1); } fclose (pFile); return 0; } /*If entered password don't match*/ else { showCommanderInfo("Passwords don't match", 1); break; } } } else { showCommanderInfo("Account creation has being canceled", 1); break; } } break; } return 0; }
int main(int argc, char *argv[]) { struct bes_context *ctx; char *endpoint, *command, *user, *pass; char *capath, *x509cert, *x509pass; int ch, ret_code = 0; epr_t endpointepr = NULL, activityepr = NULL; endpoint = "endpoint.xml"; capath = "./certs"; x509cert = NULL; x509pass = NULL; user = NULL; pass = NULL; while ((ch = getopt(argc, argv, "Vc:e:u:p:x:k:")) != -1) { switch (ch) { case 'c': capath = optarg; break; case 'e': endpoint = optarg; break; case 'u': user = optarg; break; case 'p': pass = optarg; break; case 'x': x509cert = optarg; break; case 'k': x509pass = optarg; break; case 'V': printf("besclient, %s\n%s\n", VERSION_STRING, COPYRIGHT); exit(0); break; case '?': default: usage(); } } argc -= optind; argv += optind; if (argc < 1) { usage(); } command = argv[0]; if (bes_init(&ctx)) { ret_code = 1; goto end; } if (user) { if (pass == NULL ) { pass = readPassword("WS-Security password:"******"Key passphrase:"); } } if (bes_security(ctx, x509cert, x509pass, capath, user, pass)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; goto end; } if (bes_readEPRFromFile(ctx, endpoint, &endpointepr)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; goto end; } if (!strcmp(command, "status") || !strcmp(command, "terminate") || !strcmp(command, "activity") || !strcmp(command, "poll")) { if (bes_readEPRFromFile(ctx, argv[1], &activityepr)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; goto end; } } if (!strcmp(command, "create")) { epr_t new_activityepr; if (bes_createActivityFromFile(ctx, endpointepr, argv[1], &new_activityepr)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } else { if (bes_writeEPRToFile(ctx, argv[2], new_activityepr)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } printf("Successfully submitted activity. Wrote EPR to %s\n", argv[2]); bes_freeEPR(&new_activityepr); } } else if (!strcmp(command, "status")) { struct bes_activity_status status; if (bes_getActivityStatuses(ctx, endpointepr, activityepr, &status)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } else { printf("The state of the activity is: %s\n", bes_activity_state[status.state]); if (status.substate) { printf("The substate is %s\n", status.substate); free(status.substate); } } } else if (!strcmp(command, "terminate")) { if (bes_terminateActivities(ctx, endpointepr, activityepr)) { printf("The activity was canceled\n"); } else { printf("The activity was not canceled\n"); fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } } else if (!strcmp(command, "activity")) { char *strDoc; if (bes_getActivityDocumentsXML(ctx, endpointepr, activityepr, &strDoc)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } else { printf("Got result from server:\n"); printf("%s\n", strDoc); free(strDoc); } } else if (!strcmp(command, "factory")) { char *strDoc; if (bes_getFactoryAttributesDocument(ctx, endpointepr, &strDoc)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } else { printf("Got result from server:\n"); printf("%s\n", strDoc); free(strDoc); } } else if (!strcmp(command, "poll")) { struct bes_activity_status status; int poll_interval, ret = 0; if (argc != 3) { fprintf(stderr, "Wrong arguments for poll command.\n", command); goto end; } poll_interval = atoi(argv[2]); while (!(ret = bes_getActivityStatuses(ctx, endpointepr, activityepr, &status))) { if ((status.state == BES_Cancelled) || (status.state == BES_Failed) || (status.state == BES_Finished)) { break; } else { printf("."); fflush(stdout); sleep(poll_interval); if (user) { if (bes_add_usertoken(ctx, user, pass)) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; break; } } } } if (ret) { fprintf(stderr, "%s\n", bes_get_lasterror(ctx)); ret_code = 1; } else { printf("Activity has finished. Final status is: %s\n", bes_activity_state[status.state]); if (status.substate) { printf("The substate is %s\n", status.substate); free(status.substate); } } } else { fprintf(stderr, "Command %s is unknown.\n", command); exit(1); } if (endpointepr) { bes_freeEPR(&endpointepr); } if (activityepr) { bes_freeEPR(&activityepr); } end: bes_finalize(&ctx); return ret_code; }