diff options
Diffstat (limited to 'source3/lib/popt_common.c')
-rw-r--r-- | source3/lib/popt_common.c | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index dbb66b0ba5..99c26106af 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -36,8 +36,6 @@ extern bool AllowDebugChange; extern bool override_logfile; -struct user_auth_info cmdline_auth_info; - static void set_logfile(poptContext con, const char * arg) { @@ -100,7 +98,7 @@ static void popt_common_callback(poptContext con, case 's': if (arg) { - pstrcpy(dyn_CONFIGFILE, arg); + strlcpy(dyn_CONFIGFILE, arg,sizeof(dyn_CONFIGFILE)); } break; @@ -213,13 +211,13 @@ static void popt_dynconfig_callback(poptContext con, case DYN_LMHOSTSFILE: if (arg) { - pstrcpy(dyn_LMHOSTSFILE, arg); + strlcpy(dyn_LMHOSTSFILE, arg,sizeof(dyn_LMHOSTSFILE)); } break; case DYN_LIBDIR: if (arg) { - pstrcpy(dyn_LIBDIR, arg); + strlcpy(dyn_LIBDIR, arg,sizeof(dyn_LIBDIR)); } break; @@ -231,25 +229,25 @@ static void popt_dynconfig_callback(poptContext con, case DYN_LOCKDIR: if (arg) { - pstrcpy(dyn_LOCKDIR, arg); + strlcpy(dyn_LOCKDIR, arg,sizeof(dyn_LOCKDIR)); } break; case DYN_PIDDIR: if (arg) { - pstrcpy(dyn_PIDDIR, arg); + strlcpy(dyn_PIDDIR, arg,sizeof(dyn_PIDDIR)); } break; case DYN_SMB_PASSWD_FILE: if (arg) { - pstrcpy(dyn_SMB_PASSWD_FILE, arg); + strlcpy(dyn_SMB_PASSWD_FILE, arg,sizeof(dyn_SMB_PASSWD_FILE)); } break; case DYN_PRIVATE_DIR: if (arg) { - pstrcpy(dyn_PRIVATE_DIR, arg); + strlcpy(dyn_PRIVATE_DIR, arg, sizeof(dyn_PRIVATE_DIR)); } break; @@ -289,7 +287,7 @@ const struct poptOption popt_common_dynconfig[] = { * exit on failure * ****************************************************************************/ -static void get_password_file(struct user_auth_info *a) +static void get_password_file(void) { int fd = -1; char *p; @@ -342,12 +340,14 @@ static void get_password_file(struct user_auth_info *a) } } SAFE_FREE(spec); - pstrcpy(a->password, pass); - if (close_it) + + set_cmdline_auth_info_password(pass); + if (close_it) { close(fd); + } } -static void get_credentials_file(const char *file, struct user_auth_info *info) +static void get_credentials_file(const char *file) { XFILE *auth; fstring buf; @@ -389,15 +389,13 @@ static void get_credentials_file(const char *file, struct user_auth_info *info) while ((*val!='\0') && ((*val==' ') || (*val=='\t'))) val++; - if (strwicmp("password", param) == 0) - { - pstrcpy(info->password, val); - info->got_pass = True; - } - else if (strwicmp("username", param) == 0) - pstrcpy(info->username, val); - else if (strwicmp("domain", param) == 0) + if (strwicmp("password", param) == 0) { + set_cmdline_auth_info_password(val); + } else if (strwicmp("username", param) == 0) { + set_cmdline_auth_info_username(val); + } else if (strwicmp("domain", param) == 0) { set_global_myworkgroup(val); + } memset(buf, 0, sizeof(buf)); } x_fclose(auth); @@ -413,7 +411,7 @@ static void get_credentials_file(const char *file, struct user_auth_info *info) */ -static void popt_common_credentials_callback(poptContext con, +static void popt_common_credentials_callback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data) @@ -421,32 +419,35 @@ static void popt_common_credentials_callback(poptContext con, char *p; if (reason == POPT_CALLBACK_REASON_PRE) { - cmdline_auth_info.use_kerberos = False; - cmdline_auth_info.got_pass = False; - cmdline_auth_info.signing_state = Undefined; - pstrcpy(cmdline_auth_info.username, "GUEST"); + set_cmdline_auth_info_username("GUEST"); - if (getenv("LOGNAME"))pstrcpy(cmdline_auth_info.username,getenv("LOGNAME")); + if (getenv("LOGNAME")) { + set_cmdline_auth_info_username(getenv("LOGNAME")); + } if (getenv("USER")) { - pstrcpy(cmdline_auth_info.username,getenv("USER")); + char *puser = SMB_STRDUP(getenv("USER")); + if (!puser) { + exit(ENOMEM); + } + set_cmdline_auth_info_username(puser); - if ((p = strchr_m(cmdline_auth_info.username,'%'))) { + if ((p = strchr_m(puser,'%'))) { + size_t len; *p = 0; - pstrcpy(cmdline_auth_info.password,p+1); - cmdline_auth_info.got_pass = True; - memset(strchr_m(getenv("USER"),'%')+1,'X',strlen(cmdline_auth_info.password)); + len = strlen(p+1); + set_cmdline_auth_info_password(p+1); + memset(strchr_m(getenv("USER"),'%')+1,'X',len); } + SAFE_FREE(puser); } if (getenv("PASSWD")) { - pstrcpy(cmdline_auth_info.password,getenv("PASSWD")); - cmdline_auth_info.got_pass = True; + set_cmdline_auth_info_password(getenv("PASSWD")); } if (getenv("PASSWD_FD") || getenv("PASSWD_FILE")) { - get_password_file(&cmdline_auth_info); - cmdline_auth_info.got_pass = True; + get_password_file(); } return; @@ -456,19 +457,24 @@ static void popt_common_credentials_callback(poptContext con, case 'U': { char *lp; + char *puser = SMB_STRDUP(arg); - pstrcpy(cmdline_auth_info.username,arg); - if ((lp=strchr_m(cmdline_auth_info.username,'%'))) { + if ((lp=strchr_m(puser,'%'))) { + size_t len; *lp = 0; - pstrcpy(cmdline_auth_info.password,lp+1); - cmdline_auth_info.got_pass = True; - memset(strchr_m(arg,'%')+1,'X',strlen(cmdline_auth_info.password)); + set_cmdline_auth_info_username(puser); + set_cmdline_auth_info_password(lp+1); + len = strlen(lp+1); + memset(strchr_m(arg,'%')+1,'X',len); + } else { + set_cmdline_auth_info_username(puser); } + SAFE_FREE(puser); } break; case 'A': - get_credentials_file(arg, &cmdline_auth_info); + get_credentials_file(arg); break; case 'k': @@ -476,64 +482,58 @@ static void popt_common_credentials_callback(poptContext con, d_printf("No kerberos support compiled in\n"); exit(1); #else - cmdline_auth_info.use_kerberos = True; - cmdline_auth_info.got_pass = True; + set_cmdline_auth_info_use_krb5_ticket(); #endif break; case 'S': - { - cmdline_auth_info.signing_state = -1; - if (strequal(arg, "off") || strequal(arg, "no") || strequal(arg, "false")) - cmdline_auth_info.signing_state = False; - else if (strequal(arg, "on") || strequal(arg, "yes") || strequal(arg, "true") || - strequal(arg, "auto") ) - cmdline_auth_info.signing_state = True; - else if (strequal(arg, "force") || strequal(arg, "required") || strequal(arg, "forced")) - cmdline_auth_info.signing_state = Required; - else { - fprintf(stderr, "Unknown signing option %s\n", arg ); - exit(1); - } + if (!set_cmdline_auth_info_signing_state(arg)) { + fprintf(stderr, "Unknown signing option %s\n", arg ); + exit(1); } break; case 'P': { char *opt_password = NULL; + char *pwd = NULL; + /* it is very useful to be able to make ads queries as the machine account for testing purposes and for domain leave */ - + if (!secrets_init()) { d_printf("ERROR: Unable to open secrets database\n"); exit(1); } - + opt_password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL); - + if (!opt_password) { d_printf("ERROR: Unable to fetch machine password\n"); exit(1); } - pstr_sprintf(cmdline_auth_info.username, "%s$", - global_myname()); - pstrcpy(cmdline_auth_info.password,opt_password); + if (asprintf(&pwd, "%s$", global_myname()) < 0) { + exit(ENOMEM); + } + set_cmdline_auth_info_username(pwd); + set_cmdline_auth_info_password(opt_password); + SAFE_FREE(pwd); SAFE_FREE(opt_password); /* machine accounts only work with kerberos */ - cmdline_auth_info.use_kerberos = True; - cmdline_auth_info.got_pass = True; + set_cmdline_auth_info_use_krb5_ticket(); } break; + case 'N': + set_cmdline_auth_info_password(""); + break; } } - - struct poptOption popt_common_credentials[] = { { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, (void *)popt_common_credentials_callback }, { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "USERNAME" }, - { "no-pass", 'N', POPT_ARG_NONE, &cmdline_auth_info.got_pass, 0, "Don't ask for a password" }, - { "kerberos", 'k', POPT_ARG_NONE, &cmdline_auth_info.use_kerberos, 'k', "Use kerberos (active directory) authentication" }, + { "no-pass", 'N', POPT_ARG_NONE, NULL, 'N', "Don't ask for a password" }, + { "kerberos", 'k', POPT_ARG_NONE, NULL, 'k', "Use kerberos (active directory) authentication" }, { "authentication-file", 'A', POPT_ARG_STRING, NULL, 'A', "Get the credentials from a file", "FILE" }, { "signing", 'S', POPT_ARG_STRING, NULL, 'S', "Set the client signing state", "on|off|required" }, {"machine-pass", 'P', POPT_ARG_NONE, NULL, 'P', "Use stored machine account password" }, |