s3:dom_sid Global replace of DOM_SID with struct dom_sid
[abartlet/samba.git/.git] / source3 / winbindd / winbindd_pam.c
index 3f350e3fb2c09906e1c38d2e53c4e4e05da24f9a..cf5ffdf325bf117913e4a718517e291caef824d8 100644 (file)
 #include "winbindd.h"
 #include "../libcli/auth/libcli_auth.h"
 #include "../librpc/gen_ndr/cli_samr.h"
+#include "rpc_client/cli_samr.h"
+#include "../librpc/gen_ndr/ndr_netlogon.h"
+#include "rpc_client/cli_netlogon.h"
 #include "smb_krb5.h"
+#include "../lib/crypto/arcfour.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
@@ -121,7 +125,7 @@ static NTSTATUS append_info3_as_ndr(TALLOC_CTX *mem_ctx,
        DATA_BLOB blob;
        enum ndr_err_code ndr_err;
 
-       ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, info3,
+       ndr_err = ndr_push_struct_blob(&blob, mem_ctx, info3,
                                       (ndr_push_flags_fn_t)ndr_push_netr_SamInfo3);
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
                DEBUG(0,("append_info3_as_ndr: failed to append\n"));
@@ -192,7 +196,7 @@ static NTSTATUS append_afs_token(TALLOC_CTX *mem_ctx,
                                    "%U", name_user);
 
        {
-               DOM_SID user_sid;
+               struct dom_sid user_sid;
                fstring sidstr;
 
                sid_compose(&user_sid, info3->base.domain_sid,
@@ -248,11 +252,11 @@ static NTSTATUS check_info3_in_group(struct netr_SamInfo3 *info3,
  *    or other NT_STATUS_IS_ERR(status) for other kinds of failure.
  */
 {
-       DOM_SID *require_membership_of_sid;
+       struct dom_sid *require_membership_of_sid;
        size_t num_require_membership_of_sid;
        char *req_sid;
        const char *p;
-       DOM_SID sid;
+       struct dom_sid sid;
        size_t i;
        struct nt_user_token *token;
        TALLOC_CTX *frame = talloc_stackframe();
@@ -563,8 +567,7 @@ static NTSTATUS winbindd_raw_kerberos_login(struct winbindd_domain *domain,
        ADS_STRUCT *ads;
        time_t time_offset = 0;
        bool internal_ccache = true;
-
-       ZERO_STRUCTP(info3);
+       struct PAC_LOGON_INFO *logon_info = NULL;
 
        *info3 = NULL;
 
@@ -622,18 +625,18 @@ static NTSTATUS winbindd_raw_kerberos_login(struct winbindd_domain *domain,
                DEBUG(10,("winbindd_raw_kerberos_login: uid is %d\n", uid));
        }
 
-       result = kerberos_return_info3_from_pac(state->mem_ctx,
-                                               principal_s,
-                                               state->request->data.auth.pass,
-                                               time_offset,
-                                               &ticket_lifetime,
-                                               &renewal_until,
-                                               cc,
-                                               true,
-                                               true,
-                                               WINBINDD_PAM_AUTH_KRB5_RENEW_TIME,
-                                               NULL,
-                                               info3);
+       result = kerberos_return_pac(state->mem_ctx,
+                                    principal_s,
+                                    state->request->data.auth.pass,
+                                    time_offset,
+                                    &ticket_lifetime,
+                                    &renewal_until,
+                                    cc,
+                                    true,
+                                    true,
+                                    WINBINDD_PAM_AUTH_KRB5_RENEW_TIME,
+                                    NULL,
+                                    &logon_info);
        if (!internal_ccache) {
                gain_root_privilege();
        }
@@ -644,6 +647,8 @@ static NTSTATUS winbindd_raw_kerberos_login(struct winbindd_domain *domain,
                goto failed;
        }
 
+       *info3 = &logon_info->info3;
+
        DEBUG(10,("winbindd_raw_kerberos_login: winbindd validated ticket of %s\n",
                principal_s));
 
@@ -757,10 +762,11 @@ static NTSTATUS append_auth_data(struct winbindd_cli_state *state,
                       /* 8 */);
        }
 
-       if (flags & WBFLAG_PAM_INFO3_TEXT) {
-               result = append_info3_as_txt(state->mem_ctx, state, info3);
+       if (flags & WBFLAG_PAM_UNIX_NAME) {
+               result = append_unix_username(state->mem_ctx, state, info3,
+                                             name_domain, name_user);
                if (!NT_STATUS_IS_OK(result)) {
-                       DEBUG(10,("Failed to append INFO3 (TXT): %s\n",
+                       DEBUG(10,("Failed to append Unix Username: %s\n",
                                nt_errstr(result)));
                        return result;
                }
@@ -777,11 +783,10 @@ static NTSTATUS append_auth_data(struct winbindd_cli_state *state,
                }
        }
 
-       if (flags & WBFLAG_PAM_UNIX_NAME) {
-               result = append_unix_username(state->mem_ctx, state, info3,
-                                             name_domain, name_user);
+       if (flags & WBFLAG_PAM_INFO3_TEXT) {
+               result = append_info3_as_txt(state->mem_ctx, state, info3);
                if (!NT_STATUS_IS_OK(result)) {
-                       DEBUG(10,("Failed to append Unix Username: %s\n",
+                       DEBUG(10,("Failed to append INFO3 (TXT): %s\n",
                                nt_errstr(result)));
                        return result;
                }
@@ -807,7 +812,7 @@ static NTSTATUS winbindd_dual_pam_auth_cached(struct winbindd_domain *domain,
        NTSTATUS result = NT_STATUS_LOGON_FAILURE;
        uint16 max_allowed_bad_attempts;
        fstring name_domain, name_user;
-       DOM_SID sid;
+       struct dom_sid sid;
        enum lsa_SidType type;
        uchar new_nt_pass[NT_HASH_LEN];
        const uint8 *cached_nt_pass;
@@ -1037,7 +1042,7 @@ static NTSTATUS winbindd_dual_pam_auth_cached(struct winbindd_domain *domain,
                        DEBUG(10,("winbindd_dual_pam_auth_cached: failed to get password properties.\n"));
                }
 
-               if ((my_info3->base.rid != DOMAIN_USER_RID_ADMIN) ||
+               if ((my_info3->base.rid != DOMAIN_RID_ADMINISTRATOR) ||
                    (password_properties & DOMAIN_PASSWORD_LOCKOUT_ADMINS)) {
                        my_info3->base.acct_flags |= ACB_AUTOLOCK;
                }
@@ -1585,7 +1590,7 @@ process_result:
 
        if (NT_STATUS_IS_OK(result)) {
 
-               DOM_SID user_sid;
+               struct dom_sid user_sid;
 
                /* In all codepaths where result == NT_STATUS_OK info3 must have
                   been initialized. */
@@ -2127,48 +2132,6 @@ process_result:
 
 /* Change user password with auth crap*/
 
-void winbindd_pam_chng_pswd_auth_crap(struct winbindd_cli_state *state)
-{
-       struct winbindd_domain *domain = NULL;
-       const char *domain_name = NULL;
-
-       /* Ensure null termination */
-       state->request->data.chng_pswd_auth_crap.user[
-               sizeof(state->request->data.chng_pswd_auth_crap.user)-1]=0;
-       state->request->data.chng_pswd_auth_crap.domain[
-               sizeof(state->request->data.chng_pswd_auth_crap.domain)-1]=0;
-
-       DEBUG(3, ("[%5lu]: pam change pswd auth crap domain: %s user: %s\n",
-                 (unsigned long)state->pid,
-                 state->request->data.chng_pswd_auth_crap.domain,
-                 state->request->data.chng_pswd_auth_crap.user));
-
-       if (*state->request->data.chng_pswd_auth_crap.domain != '\0') {
-               domain_name = state->request->data.chng_pswd_auth_crap.domain;
-       } else if (lp_winbind_use_default_domain()) {
-               domain_name = lp_workgroup();
-       }
-
-       if (domain_name != NULL)
-               domain = find_domain_from_name(domain_name);
-
-       if (domain != NULL) {
-               DEBUG(7, ("[%5lu]: pam auth crap changing pswd in domain: "
-                         "%s\n", (unsigned long)state->pid,domain->name));
-               sendto_domain(state, domain);
-               return;
-       }
-
-       set_auth_errors(state->response, NT_STATUS_NO_SUCH_USER);
-       DEBUG(5, ("CRAP change password  for %s\\%s returned %s (PAM: %d)\n",
-                 state->request->data.chng_pswd_auth_crap.domain,
-                 state->request->data.chng_pswd_auth_crap.user,
-                 state->response->data.auth.nt_status_string,
-                 state->response->data.auth.pam_error));
-       request_error(state);
-       return;
-}
-
 enum winbindd_result winbindd_dual_pam_chng_pswd_auth_crap(struct winbindd_domain *domainSt, struct winbindd_cli_state *state)
 {
        NTSTATUS result;
@@ -2227,25 +2190,36 @@ enum winbindd_result winbindd_dual_pam_chng_pswd_auth_crap(struct winbindd_domai
        DEBUG(3, ("[%5lu]: pam auth crap domain: %s user: %s\n",
                  (unsigned long)state->pid, domain, user));
 
+       if (strequal(domain, get_global_sam_name())) {
+               enum samPwdChangeReason reject_reason;
+
+               result = pass_oem_change(
+                       user,
+                       state->request->data.chng_pswd_auth_crap.new_lm_pswd,
+                       state->request->data.chng_pswd_auth_crap.old_lm_hash_enc,
+                       state->request->data.chng_pswd_auth_crap.new_nt_pswd,
+                       state->request->data.chng_pswd_auth_crap.old_nt_hash_enc,
+                       &reject_reason);
+               DEBUG(10, ("pass_oem_change returned %s\n",
+                          nt_errstr(result)));
+               goto done;
+       }
+
        /* Change password */
-       new_nt_password = data_blob_talloc(
-               state->mem_ctx,
+       new_nt_password = data_blob_const(
                state->request->data.chng_pswd_auth_crap.new_nt_pswd,
                state->request->data.chng_pswd_auth_crap.new_nt_pswd_len);
 
-       old_nt_hash_enc = data_blob_talloc(
-               state->mem_ctx,
+       old_nt_hash_enc = data_blob_const(
                state->request->data.chng_pswd_auth_crap.old_nt_hash_enc,
                state->request->data.chng_pswd_auth_crap.old_nt_hash_enc_len);
 
        if(state->request->data.chng_pswd_auth_crap.new_lm_pswd_len > 0)        {
-               new_lm_password = data_blob_talloc(
-                       state->mem_ctx,
+               new_lm_password = data_blob_const(
                        state->request->data.chng_pswd_auth_crap.new_lm_pswd,
                        state->request->data.chng_pswd_auth_crap.new_lm_pswd_len);
 
-               old_lm_hash_enc = data_blob_talloc(
-                       state->mem_ctx,
+               old_lm_hash_enc = data_blob_const(
                        state->request->data.chng_pswd_auth_crap.old_lm_hash_enc,
                        state->request->data.chng_pswd_auth_crap.old_lm_hash_enc_len);
        } else {