s3-talloc Change TALLOC_ZERO_P() to talloc_zero()
[nivanova/samba-autobuild/.git] / source3 / auth / server_info.c
index d288a0c97ca319478c5f1a290aeb450f16c81407..a53e556d283d2b11fca194e8972c7a4dc4f6ee33 100644 (file)
 */
 
 #include "includes.h"
+#include "auth.h"
 #include "../lib/crypto/arcfour.h"
 #include "../librpc/gen_ndr/netlogon.h"
 #include "../libcli/security/security.h"
+#include "rpc_client/util_netlogon.h"
+#include "nsswitch/libwbclient/wbclient.h"
+#include "passdb.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_AUTH
@@ -41,7 +45,7 @@ struct auth_serversupplied_info *make_server_info(TALLOC_CTX *mem_ctx)
 {
        struct auth_serversupplied_info *result;
 
-       result = TALLOC_ZERO_P(mem_ctx, struct auth_serversupplied_info);
+       result = talloc_zero(mem_ctx, struct auth_serversupplied_info);
        if (result == NULL) {
                DEBUG(0, ("talloc failed\n"));
                return NULL;
@@ -76,11 +80,11 @@ NTSTATUS serverinfo_to_SamInfo2(struct auth_serversupplied_info *server_info,
                return NT_STATUS_NO_MEMORY;
        }
 
-       if (server_info->user_session_key.length) {
+       if (server_info->session_key.length) {
                memcpy(info3->base.key.key,
-                      server_info->user_session_key.data,
+                      server_info->session_key.data,
                       MIN(sizeof(info3->base.key.key),
-                          server_info->user_session_key.length));
+                          server_info->session_key.length));
                if (pipe_session_key) {
                        arcfour_crypt(info3->base.key.key,
                                      pipe_session_key, 16);
@@ -119,11 +123,11 @@ NTSTATUS serverinfo_to_SamInfo3(const struct auth_serversupplied_info *server_in
                return NT_STATUS_NO_MEMORY;
        }
 
-       if (server_info->user_session_key.length) {
+       if (server_info->session_key.length) {
                memcpy(info3->base.key.key,
-                      server_info->user_session_key.data,
+                      server_info->session_key.data,
                       MIN(sizeof(info3->base.key.key),
-                          server_info->user_session_key.length));
+                          server_info->session_key.length));
                if (pipe_session_key) {
                        arcfour_crypt(info3->base.key.key,
                                      pipe_session_key, 16);
@@ -177,11 +181,11 @@ NTSTATUS serverinfo_to_SamInfo6(struct auth_serversupplied_info *server_info,
                return NT_STATUS_NO_MEMORY;
        }
 
-       if (server_info->user_session_key.length) {
+       if (server_info->session_key.length) {
                memcpy(info3->base.key.key,
-                      server_info->user_session_key.data,
+                      server_info->session_key.data,
                       MIN(sizeof(info3->base.key.key),
-                          server_info->user_session_key.length));
+                          server_info->session_key.length));
                if (pipe_session_key) {
                        arcfour_crypt(info3->base.key.key,
                                      pipe_session_key, 16);
@@ -310,7 +314,7 @@ NTSTATUS samu_to_SamInfo3(TALLOC_CTX *mem_ctx,
        const struct dom_sid *group_sid;
        struct dom_sid domain_sid;
        struct dom_sid *group_sids;
-       size_t num_group_sids = 0;
+       uint32_t num_group_sids = 0;
        const char *tmp;
        gid_t *gids;
        NTSTATUS status;
@@ -490,66 +494,15 @@ struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx,
 {
        struct netr_SamInfo3 *info3;
        unsigned int i;
+       NTSTATUS status;
 
        info3 = talloc_zero(mem_ctx, struct netr_SamInfo3);
        if (!info3) return NULL;
 
-       /* first copy all, then realloc pointers */
-       info3->base = orig->base;
-
-       if (orig->base.account_name.string) {
-               info3->base.account_name.string =
-                       talloc_strdup(info3, orig->base.account_name.string);
-               RET_NOMEM(info3->base.account_name.string);
-       }
-       if (orig->base.full_name.string) {
-               info3->base.full_name.string =
-                       talloc_strdup(info3, orig->base.full_name.string);
-               RET_NOMEM(info3->base.full_name.string);
-       }
-       if (orig->base.logon_script.string) {
-               info3->base.logon_script.string =
-                       talloc_strdup(info3, orig->base.logon_script.string);
-               RET_NOMEM(info3->base.logon_script.string);
-       }
-       if (orig->base.profile_path.string) {
-               info3->base.profile_path.string =
-                       talloc_strdup(info3, orig->base.profile_path.string);
-               RET_NOMEM(info3->base.profile_path.string);
-       }
-       if (orig->base.home_directory.string) {
-               info3->base.home_directory.string =
-                       talloc_strdup(info3, orig->base.home_directory.string);
-               RET_NOMEM(info3->base.home_directory.string);
-       }
-       if (orig->base.home_drive.string) {
-               info3->base.home_drive.string =
-                       talloc_strdup(info3, orig->base.home_drive.string);
-               RET_NOMEM(info3->base.home_drive.string);
-       }
-
-       if (orig->base.groups.count) {
-               info3->base.groups.rids = (struct samr_RidWithAttribute *)
-                       talloc_memdup(info3, orig->base.groups.rids,
-                               (sizeof(struct samr_RidWithAttribute) *
-                                       orig->base.groups.count));
-               RET_NOMEM(info3->base.groups.rids);
-       }
-
-       if (orig->base.logon_server.string) {
-               info3->base.logon_server.string =
-                       talloc_strdup(info3, orig->base.logon_server.string);
-               RET_NOMEM(info3->base.logon_server.string);
-       }
-       if (orig->base.domain.string) {
-               info3->base.domain.string =
-                       talloc_strdup(info3, orig->base.domain.string);
-               RET_NOMEM(info3->base.domain.string);
-       }
-
-       if (orig->base.domain_sid) {
-               info3->base.domain_sid = dom_sid_dup(info3, orig->base.domain_sid);
-               RET_NOMEM(info3->base.domain_sid);
+       status = copy_netr_SamBaseInfo(info3, &orig->base, &info3->base);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(info3);
+               return NULL;
        }
 
        if (orig->sidcount) {
@@ -620,9 +573,11 @@ struct netr_SamInfo3 *wbcAuthUserInfo_to_netr_SamInfo3(TALLOC_CTX *mem_ctx,
        info3->base.last_logon = info->logon_time;
        info3->base.last_logoff = info->logoff_time;
        info3->base.acct_expiry = info->kickoff_time;
-       info3->base.last_password_change = info->pass_last_set_time;
-       info3->base.allow_password_change = info->pass_can_change_time;
-       info3->base.force_password_change = info->pass_must_change_time;
+       unix_to_nt_time(&info3->base.last_password_change, info->pass_last_set_time);
+       unix_to_nt_time(&info3->base.allow_password_change,
+                       info->pass_can_change_time);
+       unix_to_nt_time(&info3->base.force_password_change,
+                       info->pass_must_change_time);
 
        if (info->account_name) {
                info3->base.account_name.string =