s4:dcerpc_netlogon - unify the two workstation object lookups (DNS hostname and suppo...
[ira/wip.git] / nsswitch / wbinfo.c
index 80d267a1bcb1e3aafc85e400dfccf41ba7dbc733..219ec24fbaa72f4777695a7022a916b5b03eda23 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 "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)
 {
@@ -723,15 +724,55 @@ static bool wbinfo_dsgetdcname(const char *domain_name, uint32_t flags)
 
 /* Check trust account password */
 
-static bool wbinfo_check_secret(void)
+static bool wbinfo_check_secret(const char *domain)
 {
        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
        struct wbcAuthErrorInfo *error = NULL;
+       const char *domain_name;
+
+       if (domain) {
+               domain_name = domain;
+       } else {
+               domain_name = get_winbind_domain();
+       }
 
-       wbc_status = wbcCheckTrustCredentials(NULL, &error);
+       wbc_status = wbcCheckTrustCredentials(domain_name, &error);
 
-       d_printf("checking the trust secret via RPC calls %s\n",
-                WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
+       d_printf("checking the trust secret for domain %s via RPC calls %s\n",
+               domain_name,
+               WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
+
+       if (wbc_status == WBC_ERR_AUTH_ERROR) {
+               d_fprintf(stderr, "error code was %s (0x%x)\n",
+                         error->nt_string, error->nt_status);
+               wbcFreeMemory(error);
+       }
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
+               return false;
+       }
+
+       return true;
+}
+
+/* Change trust account password */
+
+static bool wbinfo_change_secret(const char *domain)
+{
+       wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+       struct wbcAuthErrorInfo *error = NULL;
+       const char *domain_name;
+
+       if (domain) {
+               domain_name = domain;
+       } else {
+               domain_name = get_winbind_domain();
+       }
+
+       wbc_status = wbcChangeTrustCredentials(domain_name, &error);
+
+       d_printf("changing the trust secret for domain %s via RPC calls %s\n",
+               domain_name,
+               WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
 
        if (wbc_status == WBC_ERR_AUTH_ERROR) {
                d_fprintf(stderr, "error code was %s (0x%x)\n",
@@ -1120,7 +1161,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;
@@ -1170,7 +1211,7 @@ 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);
 
@@ -1214,6 +1255,7 @@ 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;
@@ -1233,6 +1275,8 @@ static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32_t flags)
                password = wbinfo_prompt_pass(frame, NULL, username);
        }
 
+       local_cctype = talloc_strdup(frame, cctype);
+
        name = s;
 
        uid = geteuid();
@@ -1266,7 +1310,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;
@@ -1314,7 +1358,6 @@ static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32_t flags)
        }
  done:
 
-       TALLOC_FREE(frame);
        wbcFreeMemory(params.blobs);
 
        return WBC_ERROR_IS_OK(wbc_status);
@@ -1359,8 +1402,6 @@ static bool wbinfo_auth(char *username)
                         response.data.auth.error_string);
 #endif
 
-       TALLOC_FREE(frame);
-
        return WBC_ERROR_IS_OK(wbc_status);
 }
 
@@ -1420,7 +1461,7 @@ static bool wbinfo_auth_crap(char *username, bool use_ntlmv2, bool use_lanman)
                                      &lm, &nt, NULL, NULL)) {
                        data_blob_free(&names_blob);
                        data_blob_free(&server_chal);
-                       SAFE_FREE(pass);
+                       TALLOC_FREE(pass);
                        return false;
                }
                data_blob_free(&names_blob);
@@ -1467,11 +1508,11 @@ static bool wbinfo_auth_crap(char *username, bool use_ntlmv2, bool use_lanman)
 
        data_blob_free(&nt);
        data_blob_free(&lm);
-       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)
@@ -1531,6 +1572,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 */
 
@@ -1638,8 +1686,6 @@ 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");
 
-       TALLOC_FREE(frame);
-
        return WBC_ERROR_IS_OK(wbc_status);
 }
 
@@ -1719,6 +1765,7 @@ int main(int argc, char **argv, char **envp)
                { "remove-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_UID_MAPPING, "Remove uid to sid mapping in idmap", "UID,SID" },
                { "remove-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_GID_MAPPING, "Remove gid to sid mapping in idmap", "GID,SID" },
                { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
+               { "change-secret", 'c', POPT_ARG_NONE, 0, 'c', "Change shared secret" },
                { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
                { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
                { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
@@ -1944,11 +1991,17 @@ int main(int argc, char **argv, char **envp)
                        }
                        break;
                case 't':
-                       if (!wbinfo_check_secret()) {
+                       if (!wbinfo_check_secret(opt_domain_name)) {
                                d_fprintf(stderr, "Could not check secret\n");
                                goto done;
                        }
                        break;
+               case 'c':
+                       if (!wbinfo_change_secret(opt_domain_name)) {
+                               d_fprintf(stderr, "Could not change secret\n");
+                               goto done;
+                       }
+                       break;
                case 'm':
                        if (!wbinfo_list_domains(false, verbose)) {
                                d_fprintf(stderr,