Fix immediate bug where the idmap can't tell the difference between an entry
[ira/wip.git] / source3 / nsswitch / winbindd_misc.c
index 448af3ac95783c6dc6ec2fe7cebcc01d1f973ca6..8d7cdc4731721194a0e1a179d1940c7ac98fc651 100644 (file)
 
 #include "winbindd.h"
 
-extern pstring global_myname;
-
-/************************************************************************
- Routine to get the trust account password for a domain
-************************************************************************/
-static BOOL _get_trust_account_password(char *domain, unsigned char *ret_pwd, 
-                                       time_t *pass_last_set_time)
-{
-       if (!secrets_fetch_trust_account_password(domain, ret_pwd, pass_last_set_time)) {
-                return False;
-       }
-
-       return True;
-}
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_WINBIND
 
 /* Check the machine account password is valid */
 
@@ -46,13 +34,14 @@ enum winbindd_result winbindd_check_machine_acct(struct winbindd_cli_state *stat
        uchar trust_passwd[16];
         int num_retries = 0;
         struct cli_state *cli;
+       uint32 sec_channel_type;
        DEBUG(3, ("[%5d]: check machine account\n", state->pid));
 
        /* Get trust account password */
 
  again:
-       if (!_get_trust_account_password(lp_workgroup(), trust_passwd, 
-                                         NULL)) {
+       if (!secrets_fetch_trust_account_password(
+                   lp_workgroup(), trust_passwd, NULL, &sec_channel_type)) {
                result = NT_STATUS_INTERNAL_ERROR;
                goto done;
        }
@@ -60,19 +49,18 @@ enum winbindd_result winbindd_check_machine_acct(struct winbindd_cli_state *stat
         /* This call does a cli_nt_setup_creds() which implicitly checks
            the trust account password. */
 
-        result = cm_get_netlogon_cli(lp_workgroup(), trust_passwd, &cli);
+       /* Don't shut this down - it belongs to the connection cache code */
+        result = cm_get_netlogon_cli(lp_workgroup(), trust_passwd, sec_channel_type, True, &cli);
 
         if (!NT_STATUS_IS_OK(result)) {
                 DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
                 goto done;
         }
 
-        cli_shutdown(cli);
-
         /* There is a race condition between fetching the trust account
-           password and joining the domain so it's possible that the trust
-           account password has been changed on us.  We are returned
-           NT_STATUS_ACCESS_DENIED if this happens. */
+           password and the periodic machine password change.  So it's 
+          possible that the trust account password has been changed on us.  
+          We are returned NT_STATUS_ACCESS_DENIED if this happens. */
 
 #define MAX_RETRIES 8
 
@@ -89,9 +77,15 @@ enum winbindd_result winbindd_check_machine_acct(struct winbindd_cli_state *stat
                   "good" : "bad"));
 
  done:
-       state->response.data.num_entries = NT_STATUS_V(result);
+       state->response.data.auth.nt_status = NT_STATUS_V(result);
+       fstrcpy(state->response.data.auth.nt_status_string, nt_errstr(result));
+       fstrcpy(state->response.data.auth.error_string, nt_errstr(result));
+       state->response.data.auth.pam_error = nt_status_to_pam(result);
 
-       return WINBINDD_OK;
+       DEBUG(NT_STATUS_IS_OK(result) ? 5 : 2, ("Checking the trust account password returned %s\n", 
+                                               state->response.data.auth.nt_status_string));
+
+       return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
 }
 
 enum winbindd_result winbindd_list_trusted_domains(struct winbindd_cli_state
@@ -107,7 +101,11 @@ enum winbindd_result winbindd_list_trusted_domains(struct winbindd_cli_state
           have changed since we last looked.  There may be a sequence
           number or something we should use but I haven't found it yet. */
 
-       init_domain_list();
+       if (!init_domain_list()) {
+               DEBUG(1, ("winbindd_list_trusted_domains: could not "
+                         "refresh trusted domain list\n"));
+               return WINBINDD_ERROR;
+       }
 
        for(domain = domain_list(); domain; domain = domain->next) {
 
@@ -145,6 +143,41 @@ enum winbindd_result winbindd_list_trusted_domains(struct winbindd_cli_state
        return WINBINDD_OK;
 }
 
+
+enum winbindd_result winbindd_show_sequence(struct winbindd_cli_state *state)
+{
+       struct winbindd_domain *domain;
+       char *extra_data = NULL;
+
+       DEBUG(3, ("[%5d]: show sequence\n", state->pid));
+
+       extra_data = strdup("");
+
+       /* this makes for a very simple data format, and is easily parsable as well
+          if that is ever needed */
+       for (domain = domain_list(); domain; domain = domain->next) {
+               char *s;
+
+               domain->methods->sequence_number(domain, &domain->sequence_number);
+               
+               if (DOM_SEQUENCE_NONE == (unsigned)domain->sequence_number) {
+                       asprintf(&s,"%s%s : DISCONNECTED\n", extra_data, 
+                                domain->name);
+               } else {
+                       asprintf(&s,"%s%s : %u\n", extra_data, 
+                                domain->name, (unsigned)domain->sequence_number);
+               }
+               free(extra_data);
+               extra_data = s;
+       }
+
+       state->response.extra_data = extra_data;
+       /* must add one to length to copy the 0 for string termination */
+       state->response.length += strlen(extra_data) + 1;
+
+       return WINBINDD_OK;
+}
+
 enum winbindd_result winbindd_ping(struct winbindd_cli_state
                                                   *state)
 {
@@ -189,3 +222,32 @@ enum winbindd_result winbindd_domain_name(struct winbindd_cli_state *state)
 
        return WINBINDD_OK;
 }
+
+/* What's my name again? */
+
+enum winbindd_result winbindd_netbios_name(struct winbindd_cli_state *state)
+{
+
+       DEBUG(3, ("[%5d]: request netbios name\n", state->pid));
+       
+       fstrcpy(state->response.data.netbios_name, global_myname());
+
+       return WINBINDD_OK;
+}
+
+/* Where can I find the privilaged pipe? */
+
+enum winbindd_result winbindd_priv_pipe_dir(struct winbindd_cli_state *state)
+{
+
+       DEBUG(3, ("[%5d]: request location of privileged pipe\n", state->pid));
+       
+       state->response.extra_data = strdup(get_winbind_priv_pipe_dir());
+       if (!state->response.extra_data)
+               return WINBINDD_ERROR;
+
+       /* must add one to length to copy the 0 for string termination */
+       state->response.length += strlen((char *)state->response.extra_data) + 1;
+
+       return WINBINDD_OK;
+}