-const char *my_netbios_names(int i)
-{
- return smb_my_netbios_names[i];
-}
-
-bool set_netbios_aliases(const char **str_array)
-{
- size_t namecount;
-
- /* Work out the max number of netbios aliases that we have */
- for( namecount=0; str_array && (str_array[namecount] != NULL); namecount++ )
- ;
-
- if ( global_myname() && *global_myname())
- namecount++;
-
- /* Allocate space for the netbios aliases */
- if (!allocate_my_netbios_names_array(namecount))
- return False;
-
- /* Use the global_myname string first */
- namecount=0;
- if ( global_myname() && *global_myname()) {
- set_my_netbios_names( global_myname(), namecount );
- namecount++;
- }
-
- if (str_array) {
- size_t i;
- for ( i = 0; str_array[i] != NULL; i++) {
- size_t n;
- bool duplicate = False;
-
- /* Look for duplicates */
- for( n=0; n<namecount; n++ ) {
- if( strequal( str_array[i], my_netbios_names(n) ) ) {
- duplicate = True;
- break;
- }
- }
- if (!duplicate) {
- if (!set_my_netbios_names(str_array[i], namecount))
- return False;
- namecount++;
- }
- }
- }
- return True;
-}
-
-/****************************************************************************
- Common name initialization code.
-****************************************************************************/
-
-bool init_names(void)
-{
- int n;
-
- if (global_myname() == NULL || *global_myname() == '\0') {
- if (!set_global_myname(myhostname())) {
- DEBUG( 0, ( "init_names: malloc fail.\n" ) );
- return False;
- }
- }
-
- if (!set_netbios_aliases(lp_netbios_aliases())) {
- DEBUG( 0, ( "init_names: malloc fail.\n" ) );
- return False;
- }
-
- set_local_machine_name(global_myname(),false);
-
- DEBUG( 5, ("Netbios name list:-\n") );
- for( n=0; my_netbios_names(n); n++ ) {
- DEBUGADD( 5, ("my_netbios_names[%d]=\"%s\"\n",
- n, my_netbios_names(n) ) );
- }
-
- return( True );
-}
-
-/**************************************************************************n
- Code to cope with username/password auth options from the commandline.
- Used mainly in client tools.
-****************************************************************************/
-
-struct user_auth_info *user_auth_info_init(TALLOC_CTX *mem_ctx)
-{
- struct user_auth_info *result;
-
- result = TALLOC_ZERO_P(mem_ctx, struct user_auth_info);
- if (result == NULL) {
- return NULL;
- }
-
- result->signing_state = Undefined;
- return result;
-}
-
-const char *get_cmdline_auth_info_username(const struct user_auth_info *auth_info)
-{
- if (!auth_info->username) {
- return "";
- }
- return auth_info->username;
-}
-
-void set_cmdline_auth_info_username(struct user_auth_info *auth_info,
- const char *username)
-{
- TALLOC_FREE(auth_info->username);
- auth_info->username = talloc_strdup(auth_info, username);
- if (!auth_info->username) {
- exit(ENOMEM);
- }
-}
-
-const char *get_cmdline_auth_info_domain(const struct user_auth_info *auth_info)
-{
- if (!auth_info->domain) {
- return "";
- }
- return auth_info->domain;
-}
-
-void set_cmdline_auth_info_domain(struct user_auth_info *auth_info,
- const char *domain)
-{
- TALLOC_FREE(auth_info->domain);
- auth_info->domain = talloc_strdup(auth_info, domain);
- if (!auth_info->domain) {
- exit(ENOMEM);
- }
-}
-
-const char *get_cmdline_auth_info_password(const struct user_auth_info *auth_info)
-{
- if (!auth_info->password) {
- return "";
- }
- return auth_info->password;
-}
-
-void set_cmdline_auth_info_password(struct user_auth_info *auth_info,
- const char *password)
-{
- TALLOC_FREE(auth_info->password);
- if (password == NULL) {
- password = "";
- }
- auth_info->password = talloc_strdup(auth_info, password);
- if (!auth_info->password) {
- exit(ENOMEM);
- }
- auth_info->got_pass = true;
-}
-
-bool set_cmdline_auth_info_signing_state(struct user_auth_info *auth_info,
- const char *arg)
-{
- auth_info->signing_state = -1;
- if (strequal(arg, "off") || strequal(arg, "no") ||
- strequal(arg, "false")) {
- auth_info->signing_state = false;
- } else if (strequal(arg, "on") || strequal(arg, "yes") ||
- strequal(arg, "true") || strequal(arg, "auto")) {
- auth_info->signing_state = true;
- } else if (strequal(arg, "force") || strequal(arg, "required") ||
- strequal(arg, "forced")) {
- auth_info->signing_state = Required;
- } else {
- return false;
- }
- return true;
-}
-
-int get_cmdline_auth_info_signing_state(const struct user_auth_info *auth_info)
-{
- return auth_info->signing_state;
-}
-
-void set_cmdline_auth_info_use_ccache(struct user_auth_info *auth_info, bool b)
-{
- auth_info->use_ccache = b;
-}
-
-bool get_cmdline_auth_info_use_ccache(const struct user_auth_info *auth_info)
-{
- return auth_info->use_ccache;
-}
-
-void set_cmdline_auth_info_use_kerberos(struct user_auth_info *auth_info,
- bool b)
-{
- auth_info->use_kerberos = b;
-}
-
-bool get_cmdline_auth_info_use_kerberos(const struct user_auth_info *auth_info)
-{
- return auth_info->use_kerberos;
-}
-
-void set_cmdline_auth_info_fallback_after_kerberos(struct user_auth_info *auth_info,
- bool b)
-{
- auth_info->fallback_after_kerberos = b;
-}
-
-bool get_cmdline_auth_info_fallback_after_kerberos(const struct user_auth_info *auth_info)
-{
- return auth_info->fallback_after_kerberos;
-}
-
-/* This should only be used by lib/popt_common.c JRA */
-void set_cmdline_auth_info_use_krb5_ticket(struct user_auth_info *auth_info)
-{
- auth_info->use_kerberos = true;
- auth_info->got_pass = true;
-}
-
-/* This should only be used by lib/popt_common.c JRA */
-void set_cmdline_auth_info_smb_encrypt(struct user_auth_info *auth_info)
-{
- auth_info->smb_encrypt = true;
-}
-
-void set_cmdline_auth_info_use_machine_account(struct user_auth_info *auth_info)
-{
- auth_info->use_machine_account = true;
-}
-
-bool get_cmdline_auth_info_got_pass(const struct user_auth_info *auth_info)
-{
- return auth_info->got_pass;
-}
-
-bool get_cmdline_auth_info_smb_encrypt(const struct user_auth_info *auth_info)
-{
- return auth_info->smb_encrypt;
-}
-
-bool get_cmdline_auth_info_use_machine_account(const struct user_auth_info *auth_info)
-{
- return auth_info->use_machine_account;
-}
-
-struct user_auth_info *get_cmdline_auth_info_copy(TALLOC_CTX *mem_ctx,
- const struct user_auth_info *src)
-{
- struct user_auth_info *result;
-
- result = user_auth_info_init(mem_ctx);
- if (result == NULL) {
- return NULL;
- }
-
- *result = *src;
-
- result->username = talloc_strdup(
- result, get_cmdline_auth_info_username(src));
- result->password = talloc_strdup(
- result, get_cmdline_auth_info_password(src));
- if ((result->username == NULL) || (result->password == NULL)) {
- TALLOC_FREE(result);
- return NULL;
- }
-
- return result;
-}
-
-bool set_cmdline_auth_info_machine_account_creds(struct user_auth_info *auth_info)
-{
- char *pass = NULL;
- char *account = NULL;
-
- if (!get_cmdline_auth_info_use_machine_account(auth_info)) {
- return false;
- }
-
- if (!secrets_init()) {
- d_printf("ERROR: Unable to open secrets database\n");
- return false;
- }
-
- if (asprintf(&account, "%s$@%s", global_myname(), lp_realm()) < 0) {
- return false;
- }
-
- pass = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);
- if (!pass) {
- d_printf("ERROR: Unable to fetch machine password for "
- "%s in domain %s\n",
- account, lp_workgroup());
- SAFE_FREE(account);
- return false;
- }
-
- set_cmdline_auth_info_username(auth_info, account);
- set_cmdline_auth_info_password(auth_info, pass);
-
- SAFE_FREE(account);
- SAFE_FREE(pass);
-
- return true;
-}
-
-/****************************************************************************
- Ensure we have a password if one not given.
-****************************************************************************/
-
-void set_cmdline_auth_info_getpass(struct user_auth_info *auth_info)
-{
- char *label = NULL;
- char *pass;
- TALLOC_CTX *frame;
-
- if (get_cmdline_auth_info_got_pass(auth_info) ||
- get_cmdline_auth_info_use_kerberos(auth_info)) {
- /* Already got one... */
- return;
- }
-
- frame = talloc_stackframe();
- label = talloc_asprintf(frame, "Enter %s's password: ",
- get_cmdline_auth_info_username(auth_info));
- pass = getpass(label);
- if (pass) {
- set_cmdline_auth_info_password(auth_info, pass);
- }
- TALLOC_FREE(frame);
-}
-