int authenticate(string trial_password) { ACCESS_CHECK(ACCOUNT()); if (!password) { return !trial_password; } if (password == hash_string("crypt", trial_password, password)) { return TRUE; } if (password == hash_string("SHA1", trial_password)) { set_password(trial_password); return TRUE; } if (password == hash_string("MD5", trial_password)) { set_password(trial_password); return TRUE; } if (password == hash_string("crypt", trial_password, name)) { set_password(trial_password); return TRUE; } }
dbref create_player(const char *name, const char *password) { dbref player; if (!ok_player_name(name) || !ok_password(password)) return NOTHING; /* else he doesn't already exist, create him */ player = new_object(); /* initialize everything */ NAME(player) = alloc_string(name); DBFETCH(player)->location = tp_player_start; /* home */ FLAGS(player) = TYPE_PLAYER | PCREATE_FLAGS; OWNER(player) = player; DBFETCH(player)->sp.player.home = tp_player_start; DBFETCH(player)->exits = NOTHING; DBFETCH(player)->sp.player.pennies = tp_start_pennies; DBFETCH(player)->sp.player.password = NULL; // handle this last DBFETCH(player)->sp.player.curr_prog = NOTHING; DBFETCH(player)->sp.player.insert_mode = 0; /* link him to tp_player_start */ PUSH(player, DBFETCH(tp_player_start)->contents); add_player(player); DBDIRTY(player); DBDIRTY(tp_player_start); set_password(player, password); return player; }
User::User(int input_ID, string input_name, string input_password) { set_ID(input_ID); set_name(input_name); set_password(input_password); focus_user_num = 0; }
int bbspwd_main(void) { if (!loginok) return BBS_ELGNREQ; parse_post_data(); xml_header("bbs"); printf("<bbspwd "); print_session(); char *pw1 = getparm("pw1"); if (*pw1 == '\0') { printf(" i='i'></bbspwd>"); return 0; } printf(">", stdout); char *pw2 = getparm("pw2"); char *pw3 = getparm("pw3"); switch (set_password(pw1, pw2, pw3)) { case BBS_EWPSWD: printf("ÃÜÂë´íÎó"); break; case BBS_EINVAL: printf("ÐÂÃÜÂ벻ƥÅä »ò ÐÂÃÜÂëÌ«¶Ì"); break; default: break; } printf("</bbspwd>"); return 0; }
static void ns_cmd_fpass(sourceinfo_t *si, int parc, char *parv[]) { char *target = parv[0]; char *password = parv[1]; char *crypt = parv[2]; myuser_t *mu = si->smu; if (!target || !password || !crypt) { command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "FPASS"); command_fail(si, fault_needmoreparams, "Syntax: FPASS <account> <pass> [PLAIN|CRYPT]"); return; } if (auth_module_loaded) { command_fail(si, fault_noprivs, _("You must change the password in the external system.")); return; } if (!(mu = myuser_find(target))) { command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), target); return; } if (!strcasecmp(crypt, "CRYPT")) { logcommand(si, CMDLOG_SET, "FPASS: \2%s\2 CRYPTED", entity(mu)->name); mowgli_strlcpy(mu->pass, password, PASSLEN); } else if (!strcasecmp(crypt, "PLAIN")) { if (strlen(password) >= PASSLEN) { command_fail(si, fault_badparams, STR_INVALID_PARAMS, "FPASS"); command_fail(si, fault_badparams, _("Passwords can not exceed \2%d\2 characters."), PASSLEN - 1); return; } else { logcommand(si, CMDLOG_SET, "FPASS: \2%s\2", entity(mu)->name); set_password(mu, password); } } else { command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "FPASS"); command_fail(si, fault_needmoreparams, "Syntax: FPASS <account> <pass> [PLAIN|CRYPT]"); return; } command_success_nodata(si, _("The password for \2%s\2 has been changed to \2%s\2."), entity(mu)->name, password); return; }
int main(int argc, char * argv[]) { enum { MODE_GET, MODE_SET } mode; char * name; char * password; g_set_application_name(APPLICATION_NAME); if (argc != 3) usage(); if (g_ascii_strcasecmp(argv[1], "get") == 0) mode = MODE_GET; else if (g_ascii_strcasecmp(argv[1], "set") == 0) mode = MODE_SET; else { fprintf(stderr, "Invalid mode: %s\n", argv[1]); exit(EXIT_FAILURE); } name = argv[2]; switch (mode) { case MODE_GET: password = get_password(name); if (!password) { fprintf(stderr, "Failed to get password: %s\n", name); exit(EXIT_FAILURE); } puts(password); g_free(password); break; case MODE_SET: password = g_malloc(MAX_PASSWORD_LENGTH); *password = '******'; fgets(password, MAX_PASSWORD_LENGTH, stdin); if (!set_password(name, password)) { fprintf(stderr, "Failed to set password: %s\n", name); exit(EXIT_FAILURE); } g_free(password); break; } return 0; }
void suh::add_user(const std::string& name, const std::string& mail, const std::string& password) { if(user_exists(name)) throw error("This nickname is already registered"); users_.insert(std::pair<std::string, user>(name, user())); set_password(name, password); set_mail(name, mail); user_logged_in(name); }
void suh::set_user_detail(const std::string& user, const std::string& detail, const std::string& value) { if(detail == "mail") { set_mail(user, value); } else if (detail == "password") { set_password(user, value); } else if (detail == "realname") { set_realname(user, value); } else { throw error("Invalid usersdetail '" + detail + "'. Valid details are: " + get_valid_details()); } }
static int do_cpw_entry(krb5_principal principal, void *data) { struct cpw_entry_data *e = data; if (e->random_key) return set_random_key (principal, e->keepold); else if (e->random_password) return set_random_password (principal, e->keepold); else if (e->key_data) return set_key_data (principal, e->key_data, e->keepold); else return set_password (principal, e->password, e->keepold); }
void do_password(dbref player, const char *old, const char *newobj) { if (!check_password(player, old)) { notify(player, "Sorry"); } else if (!ok_password(newobj)) { notify(player, "Bad new password."); } else { set_password(player, newobj); notify(player, "Password changed."); } }
LoginDialog::LoginDialog(QWidget *parent) : QDialog(parent) { ui.setupUi(this); ui.passwordEdit->setEchoMode(QLineEdit::Password); setModal(true); set_path(options_get_qstr("login/path")); set_dpri(options_get_qstr("login/dpri")); set_dpub(options_get_qstr("login/dpub")); set_spri(options_get_qstr("login/spri")); set_spub(options_get_qstr("login/spub")); set_password(options_get_qstr("login/password")); if (!get_path().size()) ui.pathEdit->setFocus(); else if (!get_dpri().size()) ui.dpriEdit->setFocus(); else if (!get_dpub().size()) ui.dpubEdit->setFocus(); else ui.passwordEdit->setFocus(); }
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; }
int main(int argc, char *argv[]) { char *option; /* * Catch or ignore as many signal as possible. */ setup_signals(); /* * we establish that this program is running with non-tty stdin. * this is to discourage casual use. It does *NOT* prevent an * intruder from repeatadly running this program to determine the * password of the current user (brute force attack, but one for * which the attacker must already have gained access to the user's * account). */ if (isatty(STDIN_FILENO) || argc != 5 ) { helper_log_err(LOG_NOTICE ,"inappropriate use of Unix helper binary [UID=%d]" ,getuid()); fprintf(stderr ,"This binary is not designed for running in this way\n" "-- the system administrator has been informed\n"); sleep(10); /* this should discourage/annoy the user */ return PAM_SYSTEM_ERR; } /* We must be root to read/update shadow. */ if (geteuid() != 0) { return PAM_CRED_INSUFFICIENT; } option = argv[2]; if (strcmp(option, "update") == 0) { /* Attempting to change the password */ return set_password(argv[1], argv[3], argv[4]); } return PAM_SYSTEM_ERR; }
void do_password(dbref player, const char *old, const char *newobj) { if (Guest(player)) { anotify_fmt(player, CFAIL "%s", tp_noguest_mesg); return; } if (!check_password(player, old)) { anotify_nolisten2(player, CFAIL "Syntax: @password <oldpass>=<newpass>"); } else if (!ok_password(newobj)) { anotify_nolisten2(player, CFAIL "Bad new password."); } else { set_password(player, newobj); anotify_nolisten2(player, CFAIL "Password changed."); } }
int main(int argc, char * argv[]) { char * name; Mode mode; g_set_application_name(APPLICATION_NAME); process_arguments(argc, argv, &mode, &name); if(mode == MODE_GET) { get_password(name); } else if (mode == MODE_SET) { set_password(name); } else { fprintf(stderr, "E: Could not determine which mode. (Assert false)"); exit(EXIT_FAILURE); } return EXIT_SUCCESS; }
static void ndsctl_password(int fd, char *arg) { debug(LOG_DEBUG, "Entering ndsctl_password..."); LOCK_CONFIG(); debug(LOG_DEBUG, "Argument: [%s]", arg); if (!set_password(arg)) { write(fd, "Yes", 3); debug(LOG_NOTICE, "Set password to %s.", arg); } else { write(fd, "No", 2); } UNLOCK_CONFIG(); debug(LOG_DEBUG, "Exiting ndsctl_password."); }
/* SET PASSWORD <password> */ static void ns_cmd_set_password(sourceinfo_t *si, int parc, char *parv[]) { char *password = strtok(parv[0], " "); if (si->smu == NULL) return; if (auth_module_loaded) { command_fail(si, fault_noprivs, _("You must change the password in the external system.")); return; } if (password == NULL) { command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "PASSWORD"); return; } if (strlen(password) > 32) { command_fail(si, fault_badparams, STR_INVALID_PARAMS, "PASSWORD"); return; } if (!strcasecmp(password, entity(si->smu)->name)) { command_fail(si, fault_badparams, _("You cannot use your nickname as a password.")); command_fail(si, fault_badparams, _("Syntax: SET PASSWORD <new password>")); return; } logcommand(si, CMDLOG_SET, "SET:PASSWORD"); set_password(si->smu, password); command_success_nodata(si, _("The password for \2%s\2 has been changed to \2%s\2."), entity(si->smu)->name, password); return; }
void parse_args( int argc, char *argv[]) { int i; for (i = 1; i < argc; ++i) { if (strncmp( argv[i], "--profile=", 10) == 0) { dynamic_profile.profile_id = (uint16_t) strtoul( &argv[i][10], NULL, 16); } else if (strcmp( argv[i], "--aps") == 0) { dynamic_profile.flags = WPAN_CLUST_FLAG_ENCRYPT; } else if (strncmp( argv[i], "--password=", 11) == 0) { set_password( &argv[i][11]); } } profile_changed(); }
bool check_password(dbref player, const char *check_pw) { const char *password = NULL; if (player == NOTHING) return 0; password = DBFETCH(player)->sp.player.password; /* We now do this smartly based on the DB_NEWPASSES */ /* database flag. -Hinoserm */ if (!password || !*password) return 1; if (!db_hash_passwords) return !strcmp(check_pw, password); if (db_hash_compare(password, check_pw)) { switch (db_hash_tagtoval(password)) { case HTYPE_CURRENT: break; /* Our current best, preserve */ case HTYPE_NONE: break; /* If there's no password, preserve */ case HTYPE_DISABLED: break; /* If there's no password, preserve */ case HTYPE_INVALID: break; /* Don't recognize the type, preserve */ default: /* Not our current best, upgrade */ set_password(player, check_pw); break; } return 1; } return 0; }
dbref create_player(dbref creator, const char *name, const char *password) { char buf[BUFFER_LEN]; struct object *newp; dbref player; if (!ok_player_name(name) || !ok_password(password) || tp_db_readonly) return NOTHING; /* remove any existing alias with this name */ clear_alias(0, name); /* else he doesn't already exist, create him */ player = new_object(creator); newp = DBFETCH(player); /* initialize everything */ NAME(player) = alloc_string(name); FLAGS(player) = TYPE_PLAYER; if (OkObj(tp_player_prototype) && (Typeof(tp_player_prototype) == TYPE_PLAYER)) { FLAGS(player) = FLAGS(tp_player_prototype); FLAG2(player) = FLAG2(tp_player_prototype); if (tp_pcreate_copy_props) { newp->properties = copy_prop(tp_player_prototype); #ifdef DISKBASE newp->propsfpos = 0; newp->propsmode = PROPS_UNLOADED; newp->propstime = 0; newp->nextold = NOTHING; newp->prevold = NOTHING; dirtyprops(player); #endif } } if (OkObj(tp_player_start)) { DBFETCH(player)->location = tp_player_start; DBFETCH(player)->sp.player.home = tp_player_start; } else { DBFETCH(player)->location = GLOBAL_ENVIRONMENT; DBFETCH(player)->sp.player.home = GLOBAL_ENVIRONMENT; } OWNER(player) = player; newp->exits = NOTHING; newp->sp.player.pennies = tp_start_pennies; newp->sp.player.password = NULL; /* this has to stay here. -hinoserm */ newp->sp.player.curr_prog = NOTHING; newp->sp.player.insert_mode = 0; #ifdef IGNORE_SUPPORT newp->sp.player.ignoretime = 0; #endif /* IGNORE_SUPPORT */ /* set password */ set_password(player, password); /* link him to tp_player_start */ PUSH(player, DBFETCH(tp_player_start)->contents); add_player(player); DBDIRTY(player); DBDIRTY(tp_player_start); sprintf(buf, CNOTE "%s is born!", NAME(player)); anotify_except(DBFETCH(tp_player_start)->contents, NOTHING, buf, player); return player; }
static void ns_cmd_sendpass(sourceinfo_t *si, int parc, char *parv[]) { myuser_t *mu; char *name = parv[0]; char *newpass = NULL; char *key; metadata_t *md; enum specialoperation op = op_none; bool ismarked = false; char cmdtext[NICKLEN + 20]; hook_user_needforce_t needforce_hdata; if (!name) { command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SENDPASS"); command_fail(si, fault_needmoreparams, _("Syntax: SENDPASS <account>")); return; } if (parc > 1) { if (!strcasecmp(parv[1], "FORCE")) op = op_force; else if (!strcasecmp(parv[1], "CLEAR")) op = op_clear; else { command_fail(si, fault_badparams, STR_INVALID_PARAMS, "SENDPASS"); command_fail(si, fault_badparams, _("Syntax: SENDPASS <account> [FORCE|CLEAR]")); return; } } if (!(mu = myuser_find_by_nick(name))) { command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), name); return; } if (is_soper(mu) && !has_priv(si, PRIV_ADMIN)) { logcommand(si, CMDLOG_ADMIN, "failed SENDPASS \2%s\2 (is SOPER)", name); command_fail(si, fault_badparams, _("\2%s\2 belongs to a services operator; you need %s privilege to send the password."), name, PRIV_ADMIN); return; } if (mu->flags & MU_WAITAUTH) { command_fail(si, fault_badparams, _("\2%s\2 is not verified."), entity(mu)->name); return; } if ((md = metadata_find(mu, "private:mark:setter"))) { ismarked = true; if (op == op_none) { logcommand(si, CMDLOG_ADMIN, "failed SENDPASS \2%s\2 (marked by \2%s\2)", entity(mu)->name, md->value); command_fail(si, fault_badparams, _("This operation cannot be performed on %s, because the account has been marked by %s."), entity(mu)->name, md->value); if (has_priv(si, PRIV_MARK)) { snprintf(cmdtext, sizeof cmdtext, "SENDPASS %s FORCE", entity(mu)->name); command_fail(si, fault_badparams, _("Use %s to override this restriction."), cmdtext); } return; } else if (!has_priv(si, PRIV_MARK)) { logcommand(si, CMDLOG_ADMIN, "failed SENDPASS \2%s\2 (marked by \2%s\2)", entity(mu)->name, md->value); command_fail(si, fault_noprivs, STR_NO_PRIVILEGE, PRIV_MARK); return; } } needforce_hdata.si = si; needforce_hdata.mu = mu; needforce_hdata.allowed = 1; hook_call_user_needforce(&needforce_hdata); if (!needforce_hdata.allowed) { ismarked = true; if (op == op_none) { logcommand(si, CMDLOG_ADMIN, "failed SENDPASS \2%s\2 (marked)", entity(mu)->name); command_fail(si, fault_badparams, _("This operation cannot be performed on %s, because the account has been marked."), entity(mu)->name); if (has_priv(si, PRIV_MARK)) { snprintf(cmdtext, sizeof cmdtext, "SENDPASS %s FORCE", entity(mu)->name); command_fail(si, fault_badparams, _("Use %s to override this restriction."), cmdtext); } return; } else if (!has_priv(si, PRIV_MARK)) { logcommand(si, CMDLOG_ADMIN, "failed SENDPASS \2%s\2 (marked)", entity(mu)->name); command_fail(si, fault_noprivs, STR_NO_PRIVILEGE, PRIV_MARK); return; } } if (op == op_clear) { if (metadata_find(mu, "private:setpass:key")) { metadata_delete(mu, "private:setpass:key"); metadata_delete(mu, "private:sendpass:sender"); metadata_delete(mu, "private:sendpass:timestamp"); logcommand(si, CMDLOG_ADMIN, "SENDPASS:CLEAR: \2%s\2", entity(mu)->name); command_success_nodata(si, _("The password change key for \2%s\2 has been cleared."), entity(mu)->name); } else command_fail(si, fault_nochange, _("\2%s\2 did not have a password change key outstanding."), entity(mu)->name); return; } if (MOWGLI_LIST_LENGTH(&mu->logins) > 0) { command_fail(si, fault_noprivs, _("This operation cannot be performed on %s, because someone is logged in to it."), entity(mu)->name); return; } if (metadata_find(mu, "private:freeze:freezer")) { command_fail(si, fault_noprivs, _("%s has been frozen by the %s administration."), entity(mu)->name, me.netname); return; } if (command_find(si->service->commands, "SETPASS")) { if (metadata_find(mu, "private:setpass:key")) { command_fail(si, fault_alreadyexists, _("\2%s\2 already has a password change key outstanding."), entity(mu)->name); command_fail(si, fault_alreadyexists, _("Use SENDPASS %s CLEAR to clear it so that a new one can be sent."), entity(mu)->name); return; } if (ismarked) { wallops("%s sent the password for the \2MARKED\2 account %s.", get_oper_name(si), entity(mu)->name); if (md) command_success_nodata(si, _("Overriding MARK placed by %s on the account %s."), md->value, entity(mu)->name); else command_success_nodata(si, _("Overriding MARK on the account %s."), entity(mu)->name); } logcommand(si, CMDLOG_ADMIN, "SENDPASS: \2%s\2 (change key)", name); key = random_string(12); metadata_add(mu, "private:sendpass:sender", get_oper_name(si)); metadata_add(mu, "private:sendpass:timestamp", number_to_string(time(NULL))); if (!sendemail(si->su != NULL ? si->su : si->service->me, mu, EMAIL_SETPASS, mu->email, key)) { command_fail(si, fault_emailfail, _("Email send failed.")); free(key); return; } metadata_add(mu, "private:setpass:key", crypt_string(key, gen_salt())); free(key); command_success_nodata(si, _("The password change key for \2%s\2 has been sent to \2%s\2."), entity(mu)->name, mu->email); } else { if (ismarked) { wallops("%s sent the password for the \2MARKED\2 account %s.", get_oper_name(si), entity(mu)->name); if (md) command_success_nodata(si, _("Overriding MARK placed by %s on the account %s."), md->value, entity(mu)->name); else command_success_nodata(si, _("Overriding MARK on the account %s."), entity(mu)->name); } logcommand(si, CMDLOG_ADMIN, "SENDPASS: \2%s\2", name); newpass = random_string(12); metadata_add(mu, "private:sendpass:sender", get_oper_name(si)); metadata_add(mu, "private:sendpass:timestamp", number_to_string(time(NULL))); if (!sendemail(si->su != NULL ? si->su : si->service->me, mu, EMAIL_SENDPASS, mu->email, newpass)) { command_fail(si, fault_emailfail, _("Email send failed.")); free(newpass); return; } set_password(mu, newpass); free(newpass); command_success_nodata(si, _("The password for \2%s\2 has been sent to \2%s\2."), entity(mu)->name, mu->email); if (mu->flags & MU_NOPASSWORD) { mu->flags &= ~MU_NOPASSWORD; command_success_nodata(si, _("The \2%s\2 flag has been removed for account \2%s\2."), "NOPASSWORD", entity(mu)->name); } } }
int main(int argc, char * argv[]) { int i; enum { MODE_GET, MODE_SET } mode; char * password; g_set_application_name(APPLICATION_NAME); if (argc < 3) usage(); if (g_ascii_strcasecmp(argv[1], "get") == 0) mode = MODE_GET; else if (g_ascii_strcasecmp(argv[1], "set") == 0) { if (argc < 4) usage(); mode = MODE_SET; } else { fprintf(stderr, "Invalid mode: %s\n", argv[1]); exit(EXIT_FAILURE); } switch (mode) { case MODE_GET: password = get_password(argc, argv); if (!password) { fprintf(stderr, "Failed to get password\n"); exit(EXIT_FAILURE); } puts(password); g_free(password); break; case MODE_SET: password = g_malloc(MAX_PASSWORD_LENGTH); *password = '******'; fgets(password, MAX_PASSWORD_LENGTH, stdin); /* remove possible '\n' at the end */ i = strlen(password); if (password[i-1] == '\n') { password[i-1] = '\0'; } if (!set_password(argc, argv, password)) { fprintf(stderr, "Failed to set password\n"); exit(EXIT_FAILURE); } g_free(password); break; } return 0; }
static void ns_cmd_setpass(sourceinfo_t *si, int parc, char *parv[]) { myuser_t *mu; metadata_t *md; char *nick = parv[0]; char *key = parv[1]; char *password = parv[2]; if (!nick || !key || !password) { command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SETPASS"); command_fail(si, fault_needmoreparams, _("Syntax: SETPASS <account> <key> <newpass>")); return; } if (strchr(password, ' ')) { command_fail(si, fault_badparams, STR_INVALID_PARAMS, "SETPASS"); command_fail(si, fault_badparams, _("Syntax: SETPASS <account> <key> <newpass>")); return; } if (!(mu = myuser_find(nick))) { command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), nick); return; } if (strlen(password) >= PASSLEN) { command_fail(si, fault_badparams, STR_INVALID_PARAMS, "SETPASS"); command_fail(si, fault_badparams, _("Registration passwords may not be longer than \2%d\2 characters."), PASSLEN - 1); return; } if (!strcasecmp(password, entity(mu)->name)) { command_fail(si, fault_badparams, _("You cannot use your nickname as a password.")); command_fail(si, fault_badparams, _("Syntax: SETPASS <account> <key> <newpass>")); return; } md = metadata_find(mu, "private:setpass:key"); if (md != NULL && crypt_verify_password(key, md->value) != NULL) { logcommand(si, CMDLOG_SET, "SETPASS: \2%s\2", entity(mu)->name); set_password(mu, password); metadata_delete(mu, "private:setpass:key"); command_success_nodata(si, _("The password for \2%s\2 has been changed to \2%s\2."), entity(mu)->name, password); return; } if (md != NULL) { logcommand(si, CMDLOG_SET, "failed SETPASS (invalid key)"); } command_fail(si, fault_badparams, _("Verification failed. Invalid key for \2%s\2."), entity(mu)->name); return; }
static void ns_cmd_resetpass(sourceinfo_t *si, int parc, char *parv[]) { myuser_t *mu; metadata_t *md; char *name = parv[0]; char *newpass; if (!name) { command_fail(si, fault_needmoreparams, STR_INVALID_PARAMS, "RESETPASS"); command_fail(si, fault_needmoreparams, _("Syntax: RESETPASS <account>")); return; } if (!(mu = myuser_find_by_nick(name))) { command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), name); return; } if (is_soper(mu) && !has_priv(si, PRIV_ADMIN)) { logcommand(si, CMDLOG_ADMIN, "failed RESETPASS \2%s\2 (is SOPER)", name); command_fail(si, fault_badparams, _("\2%s\2 belongs to a services operator; you need %s privilege to reset the password."), name, PRIV_ADMIN); return; } if ((md = metadata_find(mu, "private:mark:setter"))) { if (has_priv(si, PRIV_MARK)) { wallops("%s reset the password for the \2MARKED\2 account %s.", get_oper_name(si), entity(mu)->name); logcommand(si, CMDLOG_ADMIN, "RESETPASS: \2%s\2 (overriding mark by \2%s\2)", entity(mu)->name, md->value); command_success_nodata(si, _("Overriding MARK placed by %s on the account %s."), md->value, entity(mu)->name); } else { logcommand(si, CMDLOG_ADMIN, "failed RESETPASS \2%s\2 (marked by \2%s\2)", entity(mu)->name, md->value); command_fail(si, fault_badparams, _("This operation cannot be performed on %s, because the account has been marked by %s."), entity(mu)->name, md->value); return; } } else { wallops("%s reset the password for the account %s", get_oper_name(si), entity(mu)->name); logcommand(si, CMDLOG_ADMIN, "RESETPASS: \2%s\2", entity(mu)->name); } newpass = random_string(12); metadata_delete(mu, "private:setpass:key"); metadata_add(mu, "private:sendpass:sender", get_oper_name(si)); metadata_add(mu, "private:sendpass:timestamp", number_to_string(time(NULL))); set_password(mu, newpass); free(newpass); command_success_nodata(si, _("The password for \2%s\2 has been changed to \2%s\2."), entity(mu)->name, newpass); if (mu->flags & MU_NOPASSWORD) { mu->flags &= ~MU_NOPASSWORD; command_success_nodata(si, _("The \2%s\2 flag has been removed for account \2%s\2."), "NOPASSWORD", entity(mu)->name); } }
int main(int argc, char **argv) { printf("%s\n", set_password("abc123")); return 0; }
static void ns_cmd_setpass(struct sourceinfo *si, int parc, char *parv[]) { struct myuser *mu; struct metadata *md; char *nick = parv[0]; char *key = parv[1]; char *password = parv[2]; if (!nick || !key || !password) { command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SETPASS"); command_fail(si, fault_needmoreparams, _("Syntax: SETPASS <account> <key> <newpass>")); return; } if (strchr(password, ' ')) { command_fail(si, fault_badparams, STR_INVALID_PARAMS, "SETPASS"); command_fail(si, fault_badparams, _("Syntax: SETPASS <account> <key> <newpass>")); return; } if (!(mu = myuser_find(nick))) { command_fail(si, fault_nosuch_target, STR_IS_NOT_REGISTERED, nick); return; } if (si->smu == mu) { command_fail(si, fault_already_authed, _("You are logged in and can change your password using the SET PASSWORD command.")); return; } if (strlen(password) > PASSLEN) { command_fail(si, fault_badparams, STR_INVALID_PARAMS, "SETPASS"); command_fail(si, fault_badparams, _("Registration passwords may not be longer than \2%u\2 characters."), PASSLEN); return; } if (!strcasecmp(password, entity(mu)->name)) { command_fail(si, fault_badparams, _("You cannot use your nickname as a password.")); command_fail(si, fault_badparams, _("Syntax: SETPASS <account> <key> <newpass>")); return; } md = metadata_find(mu, "private:setpass:key"); if (md == NULL || crypt_verify_password(key, md->value, NULL) == NULL) { if (md != NULL) logcommand(si, CMDLOG_SET, "failed SETPASS (invalid key)"); command_fail(si, fault_badparams, _("Verification failed. Invalid key for \2%s\2."), entity(mu)->name); return; } logcommand(si, CMDLOG_SET, "SETPASS: \2%s\2", entity(mu)->name); metadata_delete(mu, "private:setpass:key"); metadata_delete(mu, "private:sendpass:sender"); metadata_delete(mu, "private:sendpass:timestamp"); set_password(mu, password); command_success_nodata(si, _("The password for \2%s\2 has been successfully changed."), entity(mu)->name); if (mu->flags & MU_NOPASSWORD) { mu->flags &= ~MU_NOPASSWORD; command_success_nodata(si, _("The \2%s\2 flag has been removed for account \2%s\2."), "NOPASSWORD", entity(mu)->name); } }
int main( int argc, char *argv[]) { const char *firmware = NULL; char xmodem_buffer[69]; char cmdstr[80]; int status, i; xbee_serial_t XBEE_SERPORT; FILE *fw_file = NULL; #ifdef VERBOSE uint16_t last_state; #endif uint16_t last_packet; target_t *target = NULL; // turn off buffering so status changes (lines ending in \r) display setvbuf( stdout, NULL, _IONBF, 0); memset( target_list, 0, sizeof target_list); // set serial port parse_serial_arguments( argc, argv, &XBEE_SERPORT); // parse args for this program parse_args( argc, argv); // initialize the serial and device layer for this XBee device if (xbee_dev_init( &my_xbee, &XBEE_SERPORT, NULL, NULL)) { printf( "Failed to initialize device.\n"); return 0; } // Initialize the WPAN layer of the XBee device driver. This layer enables // endpoints and clusters, and is required for all ZigBee layers. xbee_wpan_init( &my_xbee, &sample_endpoints.zdo); // Initialize the AT Command layer for this XBee device and have the // driver query it for basic information (hardware version, firmware version, // serial number, IEEE address, etc.) xbee_cmd_init_device( &my_xbee); printf( "Waiting for driver to query the XBee device...\n"); do { xbee_dev_tick( &my_xbee); status = xbee_cmd_query_status( &my_xbee); } while (status == -EBUSY); if (status) { printf( "Error %d waiting for query to complete.\n", status); } // report on the settings xbee_dev_dump_settings( &my_xbee, XBEE_DEV_DUMP_FLAG_DEFAULT); print_help(); if (dynamic_profile.profile_id != 0) { printf( "Using profile ID 0x%04x with%s APS encryption.\n", dynamic_profile.profile_id, (dynamic_profile.flags & WPAN_CLUST_FLAG_ENCRYPT) ? "" : "out"); xbee_ota_find_devices( &my_xbee.wpan_dev, xbee_found, NULL); } while (1) { while (xbee_readline( cmdstr, sizeof cmdstr) == -EAGAIN) { wpan_tick( &my_xbee.wpan_dev); if (fw_file != NULL) { if (xbee_xmodem_tx_tick( &xbee_ota.xbxm) != 0) { uint16_t timer; printf( "upload complete \n"); fclose( fw_file); fw_file = NULL; // wait one second for device to reboot then rediscover it timer = XBEE_SET_TIMEOUT_MS(1000); while (! XBEE_CHECK_TIMEOUT_MS( timer)); xbee_ota_find_devices( &my_xbee.wpan_dev, xbee_found, NULL); } #ifdef VERBOSE if (last_state != xbee_ota.xbxm.state) { printf( "state change from %u to %u\n", last_state, xbee_ota.xbxm.state); last_state = xbee_ota.xbxm.state; } #endif if (last_packet != xbee_ota.xbxm.packet_num) { #ifdef VERBOSE printf( "packet #%u\n", xbee_ota.xbxm.packet_num); #else printf( " %" PRIu32 " bytes\r", UINT32_C(64) * xbee_ota.xbxm.packet_num); #endif last_packet = xbee_ota.xbxm.packet_num; } } } if (! strcmpi( cmdstr, "quit")) { return 0; } else if (! strcmpi( cmdstr, "help") || ! strcmp( cmdstr, "?")) { print_help(); } else if (! strcmpi( cmdstr, "find")) { if (dynamic_profile.profile_id == 0) { puts( "Error: specify a profile via cmd line or 'profile' cmd"); } else { xbee_ota_find_devices( &my_xbee.wpan_dev, xbee_found, NULL); } } else if (! strncmpi( cmdstr, "profile ", 8)) { dynamic_profile.profile_id = strtoul( &cmdstr[8], NULL, 16); printf( "Profile ID set to 0x%04x\n", dynamic_profile.profile_id); profile_changed(); } else if (! strcmpi( cmdstr, "target")) { puts( " #: --IEEE Address--- Ver. --------Application Name--------" " ---Date Code----"); for (i = 0; i < target_index; ++i) { print_target( i); } puts( "End of List"); } else if (! strncmpi( cmdstr, "target ", 7)) { i = (int) strtoul( &cmdstr[7], NULL, 10); if (target_index == 0) { printf( "error, no targets in list, starting search now...\n"); xbee_ota_find_devices( &my_xbee.wpan_dev, xbee_found, NULL); } else if (i < 0 || i >= target_index) { printf( "error, index %d is invalid (must be 0 to %u)\n", i, target_index - 1); } else { target = &target_list[i]; puts( "set target to:"); print_target( i); } } else if (! strcmpi( cmdstr, "F") && target != NULL) { // If the target is stuck in the bootloader, send an 'F' to start // a firmware update. wpan_envelope_t envelope; wpan_envelope_create( &envelope, &my_xbee.wpan_dev, &target->ieee, WPAN_NET_ADDR_UNDEFINED); envelope.options = current_profile->flags; xbee_transparent_serial_str( &envelope, "F"); } else if (! strcmpi( cmdstr, "firmware")) { firmware = get_file(); } else if (! strcmpi( cmdstr, "password")) { set_password( ""); puts( "cleared password (will use default of a single null byte)"); } else if (! strncmpi( cmdstr, "password ", 9)) { set_password( &cmdstr[9]); printf( "set password to [%.*s]\n", xbee_ota.auth_length, xbee_ota.auth_data); } else if (! strcmpi( cmdstr, "aps")) { xbee_ota.flags ^= XBEE_OTA_FLAG_APS_ENCRYPT; printf( "APS encryption %sabled\n", (xbee_ota.flags & XBEE_OTA_FLAG_APS_ENCRYPT) ? "en" : "dis"); } else if (! strcmpi( cmdstr, "go")) { if (target == NULL) { if (target_index > 0) { target = &target_list[0]; } else { puts( "no targets available to send to"); continue; } } if (firmware == NULL) { firmware = get_file(); if (firmware == NULL) { printf( "Canceled.\n"); continue; } } printf( "Starting xmodem upload of\n %s\n", firmware); fw_file = fopen( firmware, "rb"); if (! fw_file) { printf( "Failed to open '%s'\n", firmware); exit( -1); } status = xbee_ota_init( &xbee_ota, &my_xbee.wpan_dev, &target->ieee); if (status) { printf( "%s returned %d\n", "xbee_ota_init", status); continue; } status = xbee_xmodem_set_source( &xbee_ota.xbxm, xmodem_buffer, fw_read, fw_file); if (status) { printf( "%s returned %d\n", "xbee_xmodem_set_source", status); continue; } // reset the xbee_xmodem_state_t state machine, keeping existing flags status = xbee_xmodem_tx_init( &xbee_ota.xbxm, xbee_ota.xbxm.flags); if (status) { printf( "%s returned %d\n", "xbee_xmodem_tx_init", status); continue; } // reset copies of basic cluster -- need to refresh after update memset( &target->basic, 0, sizeof(target->basic)); #ifdef VERBOSE last_state = last_packet = 0; #endif // main loop will tick the xmodem transfre until fw_file == NULL } #ifdef XBEE_XMODEM_TESTING else if (! strcmpi( cmdstr, "ACK")) { xbee_ota.xbxm.flags |= XBEE_XMODEM_FLAG_DROP_ACK; } else if (! strcmpi( cmdstr, "FRAME")) { xbee_ota.xbxm.flags |= XBEE_XMODEM_FLAG_DROP_FRAME; } else if (! strcmpi( cmdstr, "CRC")) { xbee_ota.xbxm.flags |= XBEE_XMODEM_FLAG_BAD_CRC; } #endif else if (! strncmpi( cmdstr, "AT", 2)) { process_command( &my_xbee, &cmdstr[2]); } else { printf( "unknown command: '%s'\n", cmdstr); } } }
/** @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); }