diff options
Diffstat (limited to 'source3/lib/util.c')
-rw-r--r-- | source3/lib/util.c | 122 |
1 files changed, 102 insertions, 20 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c index f0ea6c8e33..3d653d9b80 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -57,9 +57,6 @@ extern unsigned int global_clobber_region_line; enum protocol_types Protocol = PROTOCOL_COREPLUS; -/* a default finfo structure to ensure all fields are sensible */ -file_info def_finfo; - /* this is used by the chaining code */ int chain_size = 0; @@ -190,7 +187,7 @@ void gfree_names(void) void gfree_all( void ) { - gfree_names(); + gfree_names(); gfree_loadparm(); gfree_case_tables(); gfree_debugsyms(); @@ -283,6 +280,106 @@ bool init_names(void) } /**************************************************************************n + Code to cope with username/password auth options from the commandline. + Used mainly in client tools. +****************************************************************************/ + +static struct user_auth_info cmdline_auth_info = { + NULL, /* username */ + NULL, /* password */ + false, /* got_pass */ + false, /* use_kerberos */ + Undefined /* signing state */ +}; + +const char *get_cmdline_auth_info_username(void) +{ + if (!cmdline_auth_info.username) { + return ""; + } + return cmdline_auth_info.username; +} + +void set_cmdline_auth_info_username(const char *username) +{ + SAFE_FREE(cmdline_auth_info.username); + cmdline_auth_info.username = SMB_STRDUP(username); + if (!cmdline_auth_info.username) { + exit(ENOMEM); + } +} + +const char *get_cmdline_auth_info_password(void) +{ + if (!cmdline_auth_info.password) { + return ""; + } + return cmdline_auth_info.password; +} + +void set_cmdline_auth_info_password(const char *password) +{ + SAFE_FREE(cmdline_auth_info.password); + cmdline_auth_info.password = SMB_STRDUP(password); + if (!cmdline_auth_info.password) { + exit(ENOMEM); + } + cmdline_auth_info.got_pass = true; +} + +bool set_cmdline_auth_info_signing_state(const char *arg) +{ + 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 { + return false; + } + return true; +} + +int get_cmdline_auth_info_signing_state(void) +{ + return cmdline_auth_info.signing_state; +} + +bool get_cmdline_auth_info_use_kerberos(void) +{ + return cmdline_auth_info.use_kerberos; +} + +/* This should only be used by lib/popt_common.c JRA */ +void set_cmdline_auth_info_use_krb5_ticket(void) +{ + cmdline_auth_info.use_kerberos = true; + cmdline_auth_info.got_pass = true; +} + +bool get_cmdline_auth_info_got_pass(void) +{ + return cmdline_auth_info.got_pass; +} + +bool get_cmdline_auth_info_copy(struct user_auth_info *info) +{ + *info = cmdline_auth_info; + /* Now re-alloc the strings. */ + info->username = SMB_STRDUP(get_cmdline_auth_info_username()); + info->password = SMB_STRDUP(get_cmdline_auth_info_password()); + if (!info->username || !info->password) { + return false; + } + return true; +} + +/**************************************************************************n Find a suitable temporary directory. The result should be copied immediately as it may be overwritten by a subsequent call. ****************************************************************************/ @@ -693,21 +790,6 @@ char *clean_name(TALLOC_CTX *ctx, const char *s) } /******************************************************************* - Horrible temporary hack until pstring is dead. -********************************************************************/ - -char *pstring_clean_name(pstring s) -{ - char *str = clean_name(NULL,s); - if (!str) { - return NULL; - } - pstrcpy(s, str); - TALLOC_FREE(str); - return s; -} - -/******************************************************************* Close the low 3 fd's and open dev/null in their place. ********************************************************************/ @@ -718,7 +800,7 @@ void close_low_fds(bool stderr_too) int i; close(0); - close(1); + close(1); if (stderr_too) close(2); |