s4 winbind: Quiet down the WINBINDD_DOMAIN_INFO handler stub warning
[metze/samba/wip.git] / nsswitch / wbinfo.c
index 854dbbd516f9bad2e68604b5be825abc8dca3ca5..813846f138833b51d87317743936d4beebb27264 100644 (file)
@@ -4,7 +4,7 @@
    Winbind status program.
 
    Copyright (C) Tim Potter      2000-2003
-   Copyright (C) Andrew Bartlett 2002
+   Copyright (C) Andrew Bartlett 2002-2007
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include "includes.h"
 #include "winbind_client.h"
 #include "libwbclient/wbclient.h"
+#include "lib/popt/popt.h"
 #include "../libcli/auth/libcli_auth.h"
+#if !(_SAMBA_VERSION_) < 4
+#include "lib/cmdline/popt_common.h"
+#endif
 
+#ifdef DBGC_CLASS
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
+#endif
 
 static struct wbcInterfaceDetails *init_interface_details(void)
 {
@@ -87,6 +93,20 @@ static const char *get_winbind_domain(void)
        return details->netbios_domain;
 }
 
+static const char *get_winbind_netbios_name(void)
+{
+       static struct wbcInterfaceDetails *details;
+
+       details = init_interface_details();
+
+       if (!details) {
+               d_fprintf(stderr, "could not obtain winbind netbios name!\n");
+               return 0;
+       }
+
+       return details->netbios_name;
+}
+
 /* Copy of parse_domain_user from winbindd_util.c.  Parse a string of the
    form DOMAIN/user into a domain and a user */
 
@@ -1076,7 +1096,12 @@ static bool wbinfo_lookuprids(const char *domain, const char *arg)
 
        while (next_token_talloc(mem_ctx, &p, &ridstr, " ,\n")) {
                uint32_t rid = strtoul(ridstr, NULL, 10);
-               ADD_TO_ARRAY(mem_ctx, uint32_t, rid, &rids, &num_rids);
+               rids = talloc_realloc(mem_ctx, rids, uint32_t, num_rids + 1);
+               if (rids == NULL) {
+                       d_printf("talloc_realloc failed\n");
+               }
+               rids[num_rids] = rid;
+               num_rids += 1;
        }
 
        if (rids == NULL) {
@@ -1096,7 +1121,7 @@ static bool wbinfo_lookuprids(const char *domain, const char *arg)
 
        for (i=0; i<num_rids; i++) {
                d_printf("%8d: %s (%s)\n", rids[i], names[i],
-                        sid_type_lookup(types[i]));
+                        wbcSidTypeString(types[i]));
        }
 
        ret = true;
@@ -1146,20 +1171,21 @@ static bool wbinfo_lookupname(const char *full_name)
 
        /* Display response */
 
-       d_printf("%s %s (%d)\n", sid_str, sid_type_lookup(type), type);
+       d_printf("%s %s (%d)\n", sid_str, wbcSidTypeString(type), type);
 
        wbcFreeMemory(sid_str);
 
        return true;
 }
 
-static char *wbinfo_prompt_pass(const char *prefix,
+static char *wbinfo_prompt_pass(TALLOC_CTX *mem_ctx,
+                               const char *prefix,
                                const char *username)
 {
        char *prompt;
        const char *ret = NULL;
 
-       prompt = talloc_asprintf(talloc_tos(), "Enter %s's ", username);
+       prompt = talloc_asprintf(mem_ctx, "Enter %s's ", username);
        if (!prompt) {
                return NULL;
        }
@@ -1177,7 +1203,7 @@ static char *wbinfo_prompt_pass(const char *prefix,
        ret = getpass(prompt);
        TALLOC_FREE(prompt);
 
-       return SMB_STRDUP(ret);
+       return talloc_strdup(mem_ctx, ret);
 }
 
 /* Authenticate a user with a plaintext password */
@@ -1189,24 +1215,28 @@ static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32_t flags)
        char *p = NULL;
        char *password = NULL;
        char *name = NULL;
+       char *local_cctype = NULL;
        uid_t uid;
        struct wbcLogonUserParams params;
        struct wbcLogonUserInfo *info;
        struct wbcAuthErrorInfo *error;
        struct wbcUserPasswordPolicyInfo *policy;
+       TALLOC_CTX *frame = talloc_tos();
 
-       if ((s = SMB_STRDUP(username)) == NULL) {
+       if ((s = talloc_strdup(frame, username)) == NULL) {
                return false;
        }
 
        if ((p = strchr(s, '%')) != NULL) {
                *p = 0;
                p++;
-               password = SMB_STRDUP(p);
+               password = talloc_strdup(frame, p);
        } else {
-               password = wbinfo_prompt_pass(NULL, username);
+               password = wbinfo_prompt_pass(frame, NULL, username);
        }
 
+       local_cctype = talloc_strdup(frame, cctype);
+
        name = s;
 
        uid = geteuid();
@@ -1240,7 +1270,7 @@ static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32_t flags)
                                     &params.blobs,
                                     "krb5_cc_type",
                                     0,
-                                    (uint8_t *)cctype,
+                                    (uint8_t *)local_cctype,
                                     strlen(cctype)+1);
        if (!WBC_ERROR_IS_OK(wbc_status)) {
                goto done;
@@ -1288,8 +1318,7 @@ static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32_t flags)
        }
  done:
 
-       SAFE_FREE(s);
-       SAFE_FREE(password);
+       TALLOC_FREE(frame);
        wbcFreeMemory(params.blobs);
 
        return WBC_ERROR_IS_OK(wbc_status);
@@ -1304,17 +1333,18 @@ static bool wbinfo_auth(char *username)
        char *p = NULL;
        char *password = NULL;
        char *name = NULL;
+       TALLOC_CTX *frame = talloc_tos();
 
-       if ((s = SMB_STRDUP(username)) == NULL) {
+       if ((s = talloc_strdup(frame, username)) == NULL) {
                return false;
        }
 
        if ((p = strchr(s, '%')) != NULL) {
                *p = 0;
                p++;
-               password = SMB_STRDUP(p);
+               password = talloc_strdup(frame, p);
        } else {
-               password = wbinfo_prompt_pass(NULL, username);
+               password = wbinfo_prompt_pass(frame, NULL, username);
        }
 
        name = s;
@@ -1333,8 +1363,7 @@ static bool wbinfo_auth(char *username)
                         response.data.auth.error_string);
 #endif
 
-       SAFE_FREE(s);
-       SAFE_FREE(password);
+       TALLOC_FREE(frame);
 
        return WBC_ERROR_IS_OK(wbc_status);
 }
@@ -1353,14 +1382,15 @@ static bool wbinfo_auth_crap(char *username, bool use_ntlmv2, bool use_lanman)
        fstring name_domain;
        char *pass;
        char *p;
+       TALLOC_CTX *frame = talloc_tos();
 
        p = strchr(username, '%');
 
        if (p) {
                *p = 0;
-               pass = SMB_STRDUP(p + 1);
+               pass = talloc_strdup(frame, p + 1);
        } else {
-               pass = wbinfo_prompt_pass(NULL, username);
+               pass = wbinfo_prompt_pass(frame, NULL, username);
        }
 
        parse_wbinfo_domain_user(username, name_domain, name_user);
@@ -1384,8 +1414,9 @@ static bool wbinfo_auth_crap(char *username, bool use_ntlmv2, bool use_lanman)
                server_chal = data_blob(params.password.response.challenge, 8);
 
                /* Pretend this is a login to 'us', for blob purposes */
-               names_blob = NTLMv2_generate_names_blob(NULL, global_myname(),
-                                                       get_winbind_domain());
+               names_blob = NTLMv2_generate_names_blob(NULL,
+                                               get_winbind_netbios_name(),
+                                               get_winbind_domain());
 
                if (!SMBNTLMv2encrypt(NULL, name_user, name_domain, pass,
                                      &server_chal,
@@ -1440,11 +1471,12 @@ static bool wbinfo_auth_crap(char *username, bool use_ntlmv2, bool use_lanman)
 
        data_blob_free(&nt);
        data_blob_free(&lm);
-       SAFE_FREE(pass);
+       TALLOC_FREE(frame);
 
        return WBC_ERROR_IS_OK(wbc_status);
 }
 
+#ifdef WITH_FAKE_KASERVER
 /* Authenticate a user with a plaintext password and set a token */
 
 static bool wbinfo_klog(char *username)
@@ -1504,6 +1536,13 @@ static bool wbinfo_klog(char *username)
        d_printf("Successfully created AFS token\n");
        return true;
 }
+#else
+static bool wbinfo_klog(char *username)
+{
+       d_fprintf(stderr, "No AFS support compiled in.\n");
+       return false;
+}
+#endif
 
 /* Print domain users */
 
@@ -1599,9 +1638,10 @@ static bool wbinfo_change_user_password(const char *username)
        wbcErr wbc_status;
        char *old_password = NULL;
        char *new_password = NULL;
+       TALLOC_CTX *frame = talloc_tos();
 
-       old_password = wbinfo_prompt_pass("old", username);
-       new_password = wbinfo_prompt_pass("new", username);
+       old_password = wbinfo_prompt_pass(frame, "old", username);
+       new_password = wbinfo_prompt_pass(frame, "new", username);
 
        wbc_status = wbcChangeUserPassword(username, old_password,new_password);
 
@@ -1610,8 +1650,7 @@ static bool wbinfo_change_user_password(const char *username)
        d_printf("Password change for user %s %s\n", username,
                WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
 
-       SAFE_FREE(old_password);
-       SAFE_FREE(new_password);
+       TALLOC_FREE(frame);
 
        return WBC_ERROR_IS_OK(wbc_status);
 }
@@ -1729,7 +1768,6 @@ int main(int argc, char **argv, char **envp)
                { "change-user-password", 0, POPT_ARG_STRING, &string_arg, OPT_CHANGE_USER_PASSWORD, "Change the password for a user", NULL },
                { "ntlmv2", 0, POPT_ARG_NONE, 0, OPT_NTLMV2, "Use NTLMv2 cryptography for user authentication", NULL},
                { "lanman", 0, POPT_ARG_NONE, 0, OPT_LANMAN, "Use lanman cryptography for user authentication", NULL},
-               POPT_COMMON_CONFIGFILE
                POPT_COMMON_VERSION
                POPT_TABLEEND
        };
@@ -1754,7 +1792,7 @@ int main(int argc, char **argv, char **envp)
                /* get the generic configuration parameters like --domain */
                switch (opt) {
                case OPT_VERBOSE:
-                       verbose = True;
+                       verbose = true;
                        break;
                case OPT_NTLMV2:
                        use_ntlmv2 = true;
@@ -1767,11 +1805,6 @@ int main(int argc, char **argv, char **envp)
 
        poptFreeContext(pc);
 
-       if (!init_names())
-               return 1;
-
-       load_interfaces();
-
        pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
                            POPT_CONTEXT_KEEP_FIRST);
 
@@ -2146,7 +2179,7 @@ int main(int argc, char **argv, char **envp)
        /* Exit code */
 
  done:
-       talloc_destroy(frame);
+       talloc_free(frame);
 
        poptFreeContext(pc);
        return result;