From 158c89068b5f0ebd10e41f578530e3210fc1d8b3 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Sat, 2 Dec 2017 22:35:36 +0100 Subject: [PATCH] s3/rpc_client: move copy_netr_SamInfo3() to util_netlogon The next commit will add an additional caller that in rpc_client and I don't want to pull in AUTH_COMMON. The natural place to consolidate netlogon related helper functions seems to be util_netlogon.c which already has copy_netr_SamBaseInfo(). No change in behaviour. Signed-off-by: Ralph Boehme Reviewed-by: Stefan Metzmacher --- source3/auth/auth_util.c | 1 + source3/auth/proto.h | 2 -- source3/auth/server_info.c | 42 -------------------------------------- source3/rpc_client/util_netlogon.c | 41 +++++++++++++++++++++++++++++++++++++ source3/rpc_client/util_netlogon.h | 2 ++ source3/winbindd/winbindd_pam.c | 1 + 6 files changed, 45 insertions(+), 44 deletions(-) diff --git a/source3/auth/auth_util.c b/source3/auth/auth_util.c index 464fe25abcc..5bb5a69dfa7 100644 --- a/source3/auth/auth_util.c +++ b/source3/auth/auth_util.c @@ -36,6 +36,7 @@ #include "../librpc/gen_ndr/idmap.h" #include "lib/param/loadparm.h" #include "../lib/tsocket/tsocket.h" +#include "rpc_client/util_netlogon.h" #undef DBGC_CLASS #define DBGC_CLASS DBGC_AUTH diff --git a/source3/auth/proto.h b/source3/auth/proto.h index 996b432f18c..e7746701022 100644 --- a/source3/auth/proto.h +++ b/source3/auth/proto.h @@ -322,8 +322,6 @@ NTSTATUS passwd_to_SamInfo3(TALLOC_CTX *mem_ctx, const struct passwd *pwd, struct netr_SamInfo3 **pinfo3, struct extra_auth_info *extra); -struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx, - const struct netr_SamInfo3 *orig); /* The following definitions come from auth/pampass.c */ diff --git a/source3/auth/server_info.c b/source3/auth/server_info.c index 8461d2089f2..20d43d237fa 100644 --- a/source3/auth/server_info.c +++ b/source3/auth/server_info.c @@ -711,45 +711,3 @@ done: return status; } - -#undef RET_NOMEM - -#define RET_NOMEM(ptr) do { \ - if (!ptr) { \ - TALLOC_FREE(info3); \ - return NULL; \ - } } while(0) - -struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx, - const struct netr_SamInfo3 *orig) -{ - struct netr_SamInfo3 *info3; - unsigned int i; - NTSTATUS status; - - info3 = talloc_zero(mem_ctx, struct netr_SamInfo3); - if (!info3) return NULL; - - status = copy_netr_SamBaseInfo(info3, &orig->base, &info3->base); - if (!NT_STATUS_IS_OK(status)) { - TALLOC_FREE(info3); - return NULL; - } - - if (orig->sidcount) { - info3->sidcount = orig->sidcount; - info3->sids = talloc_array(info3, struct netr_SidAttr, - orig->sidcount); - RET_NOMEM(info3->sids); - for (i = 0; i < orig->sidcount; i++) { - info3->sids[i].sid = dom_sid_dup(info3->sids, - orig->sids[i].sid); - RET_NOMEM(info3->sids[i].sid); - info3->sids[i].attributes = - orig->sids[i].attributes; - } - } - - return info3; -} - diff --git a/source3/rpc_client/util_netlogon.c b/source3/rpc_client/util_netlogon.c index d22078be332..ee2b590b751 100644 --- a/source3/rpc_client/util_netlogon.c +++ b/source3/rpc_client/util_netlogon.c @@ -61,3 +61,44 @@ NTSTATUS copy_netr_SamBaseInfo(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } + +#undef RET_NOMEM + +#define RET_NOMEM(ptr) do { \ + if (!ptr) { \ + TALLOC_FREE(info3); \ + return NULL; \ + } } while(0) + +struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx, + const struct netr_SamInfo3 *orig) +{ + struct netr_SamInfo3 *info3; + unsigned int i; + NTSTATUS status; + + info3 = talloc_zero(mem_ctx, struct netr_SamInfo3); + if (!info3) return NULL; + + status = copy_netr_SamBaseInfo(info3, &orig->base, &info3->base); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(info3); + return NULL; + } + + if (orig->sidcount) { + info3->sidcount = orig->sidcount; + info3->sids = talloc_array(info3, struct netr_SidAttr, + orig->sidcount); + RET_NOMEM(info3->sids); + for (i = 0; i < orig->sidcount; i++) { + info3->sids[i].sid = dom_sid_dup(info3->sids, + orig->sids[i].sid); + RET_NOMEM(info3->sids[i].sid); + info3->sids[i].attributes = + orig->sids[i].attributes; + } + } + + return info3; +} diff --git a/source3/rpc_client/util_netlogon.h b/source3/rpc_client/util_netlogon.h index cea9787acb6..9e717dfe689 100644 --- a/source3/rpc_client/util_netlogon.h +++ b/source3/rpc_client/util_netlogon.h @@ -25,5 +25,7 @@ NTSTATUS copy_netr_SamBaseInfo(TALLOC_CTX *mem_ctx, const struct netr_SamBaseInfo *in, struct netr_SamBaseInfo *out); +struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx, + const struct netr_SamInfo3 *orig); #endif /* _RPC_CLIENT_UTIL_NETLOGON_H_ */ diff --git a/source3/winbindd/winbindd_pam.c b/source3/winbindd/winbindd_pam.c index b6d5b05491b..43060ee32ca 100644 --- a/source3/winbindd/winbindd_pam.c +++ b/source3/winbindd/winbindd_pam.c @@ -43,6 +43,7 @@ #include "librpc/crypto/gse_krb5.h" #include "lib/afs/afs_funcs.h" #include "libsmb/samlogon_cache.h" +#include "rpc_client/util_netlogon.h" #undef DBGC_CLASS #define DBGC_CLASS DBGC_WINBIND -- 2.11.4.GIT