s3: Replace sid_binstring and sid_guidstring with PIDL-based alternatives
authorAndrew Bartlett <abartlet@samba.org>
Fri, 17 Sep 2010 02:33:44 +0000 (12:33 +1000)
committerGünther Deschner <gd@samba.org>
Mon, 20 Sep 2010 23:15:03 +0000 (16:15 -0700)
This reduces the manual marshalling of these structures by removing
the duplication here.

Andrew Bartlett

Signed-off-by: Günther Deschner <gd@samba.org>
source3/Makefile.in
source3/include/proto.h
source3/lib/util_sid.c
source3/lib/util_uuid.c
source3/libads/ldap_schema.c
source3/passdb/pdb_ads.c
source3/winbindd/idmap_ad.c
source3/winbindd/idmap_adex/gc_util.c
source3/winbindd/idmap_adex/provider_unified.c
source3/winbindd/winbindd_ads.c
source3/wscript_build

index ce8c865cb39030584c35f2938f5164f8bbe05a4a..20a67969e00642f9f0142b60701ebc3bb67b8f00 100644 (file)
@@ -557,14 +557,14 @@ LIBSAMBA_OBJ = $(LIBSMB_OBJ0) \
               $(LIBSMB_ERR_OBJ)
 
 LIBCLI_LDAP_MESSAGE_OBJ = ../libcli/ldap/ldap_message.o
-LIBCLI_LDAP_NDR_OBJ = ../libcli/ldap/ldap_ndr.o
+LIBCLI_LDAP_NDR_OBJ = ../libcli/ldap/ldap_ndr.o lib/ldb_compat.o
 
 LIBTSOCKET_OBJ = ../lib/tsocket/tsocket.o \
                ../lib/tsocket/tsocket_helpers.o \
                ../lib/tsocket/tsocket_bsd.o
 
 CLDAP_OBJ = libads/cldap.o \
-       ../libcli/cldap/cldap.o lib/ldb_compat.o \
+       ../libcli/cldap/cldap.o \
        ../lib/util/idtree.o \
        $(LIBCLI_LDAP_MESSAGE_OBJ) $(LIBCLI_LDAP_NDR_OBJ) $(LIBTSOCKET_OBJ)
 
@@ -998,6 +998,7 @@ SMBPASSWD_OBJ = utils/smbpasswd.o $(PASSWD_UTIL_OBJ) $(PASSCHANGE_OBJ) \
 PDBEDIT_OBJ = utils/pdbedit.o $(PASSWD_UTIL_OBJ) $(PARAM_OBJ) $(PASSDB_OBJ) \
                $(LIBSAMBA_OBJ) $(LIBTSOCKET_OBJ) \
                $(LIB_NONSMBD_OBJ) $(GROUPDB_OBJ) \
+               $(LIBCLI_LDAP_NDR_OBJ) \
                $(POPT_LIB_OBJ) $(SMBLDAP_OBJ) ../lib/util/asn1.o
 
 SMBGET_OBJ = utils/smbget.o $(POPT_LIB_OBJ) $(LIBSMBCLIENT_OBJ1)
@@ -1443,6 +1444,7 @@ NTLM_AUTH_OBJ = ${NTLM_AUTH_OBJ1} $(LIBSAMBA_OBJ) $(POPT_LIB_OBJ) \
                $(PASSDB_OBJ) $(LIBTSOCKET_OBJ) $(GROUPDB_OBJ) \
                $(SMBLDAP_OBJ) $(LIBNMB_OBJ) \
                $(WBCOMMON_OBJ) \
+               $(LIBCLI_LDAP_NDR_OBJ) \
                $(LIBNDR_GEN_OBJ0) $(LIBNDR_NETLOGON_OBJ) @BUILD_INIPARSER@
 
 
@@ -3013,9 +3015,9 @@ bin/ntlm_auth@EXEEXT@: $(BINARY_PREREQS) $(NTLM_AUTH_OBJ) $(PARAM_OBJ) \
                $(POPT_LIBS) $(KRB5LIBS) $(LDAP_LIBS) $(NSCD_LIBS) \
                $(LIBTALLOC_LIBS) $(LIBTDB_LIBS) $(LIBWBCLIENT_LIBS) @INIPARSERLIBS@
 
-bin/pam_smbpass.@SHLIBEXT@: $(BINARY_PREREQS) $(PAM_SMBPASS_OBJ) $(LIBTALLOC) $(LIBWBCLIENT) $(LIBTDB)
+bin/pam_smbpass.@SHLIBEXT@: $(BINARY_PREREQS) $(PAM_SMBPASS_OBJ) $(LIBCLI_LDAP_NDR_OBJ) $(LIBTALLOC) $(LIBWBCLIENT) $(LIBTDB)
        @echo "Linking shared library $@"
-       @$(SHLD) $(LDSHFLAGS) -o $@ $(PAM_SMBPASS_OBJ) -lpam $(DYNEXP) \
+       @$(SHLD) $(LDSHFLAGS) -o $@ $(PAM_SMBPASS_OBJ) $(LIBCLI_LDAP_NDR_OBJ) -lpam $(DYNEXP) \
                $(LIBS) $(LDAP_LIBS) $(NSCD_LIBS) \
                $(LIBTALLOC_LIBS) $(LIBTDB_LIBS) $(LIBWBCLIENT_LIBS)
 
index 5bb91c53ebcdd67b6060995141f0e4a4148bfcc3..e715b579f65e3d162228e0ffeea38a67e7a9b019 100644 (file)
@@ -1295,7 +1295,6 @@ void sid_copy(struct dom_sid *dst, const struct dom_sid *src);
 bool sid_linearize(char *outbuf, size_t len, const struct dom_sid *sid);
 bool sid_parse(const char *inbuf, size_t len, struct dom_sid *sid);
 bool non_mappable_sid(struct dom_sid *sid);
-char *sid_binstring(TALLOC_CTX *mem_ctx, const struct dom_sid *sid);
 char *sid_binstring_hex(const struct dom_sid *sid);
 NTSTATUS add_sid_to_array(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
                          struct dom_sid **sids, uint32_t *num);
@@ -1587,7 +1586,6 @@ int islower_ascii(int c);
 
 void smb_uuid_pack(const struct GUID uu, UUID_FLAT *ptr);
 void smb_uuid_unpack(const UUID_FLAT in, struct GUID *uu);
-char *guid_binstring(TALLOC_CTX *mem_ctx, const struct GUID *guid);
 
 /* The following definitions come from lib/version.c  */
 
index d75c8e2c9716a4b2ce7fc023025839e610a5ffd7..d28333f9dab7ca3cfb379d192026f341edd32fd7 100644 (file)
@@ -333,26 +333,6 @@ bool non_mappable_sid(struct dom_sid *sid)
  Caller must free.
 *****************************************************************/
 
-char *sid_binstring(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
-{
-       uint8_t *buf;
-       char *s;
-       int len = ndr_size_dom_sid(sid, 0);
-       buf = talloc_array(mem_ctx, uint8_t, len);
-       if (!buf) {
-               return NULL;
-       }
-       sid_linearize((char *)buf, len, sid);
-       s = binary_string_rfc2254(mem_ctx, buf, len);
-       TALLOC_FREE(buf);
-       return s;
-}
-
-/*****************************************************************
- Return the binary string representation of a struct dom_sid.
- Caller must free.
-*****************************************************************/
-
 char *sid_binstring_hex(const struct dom_sid *sid)
 {
        char *buf, *s;
index 656ba2a57cb16bbed501ac949ddd145ea38945e9..225ac72c6c985ac962972f277284c9e21a093359 100644 (file)
@@ -38,16 +38,3 @@ void smb_uuid_unpack(const UUID_FLAT in, struct GUID *uu)
        memcpy(uu->node, in.info+10, 6);
 }
 
-/*****************************************************************
- Return the binary string representation of a GUID.
- Caller must free.
-*****************************************************************/
-
-char *guid_binstring(TALLOC_CTX *mem_ctx, const struct GUID *guid)
-{
-       UUID_FLAT guid_flat;
-
-       smb_uuid_pack(*guid, &guid_flat);
-
-       return binary_string_rfc2254(mem_ctx, guid_flat.info, UUID_FLAT_SIZE);
-}
index 80ec45c73c89862ff80366d8ec942207b7e6fbc8..66c9bf4b57ef95bbb23fc6ba18c3d8ef0687b18b 100644 (file)
@@ -21,6 +21,7 @@
 #include "includes.h"
 #include "ads.h"
 #include "libads/ldap_schema.h"
+#include "../libcli/ldap/ldap_ndr.h"
 
 #ifdef HAVE_LDAP
 
@@ -124,7 +125,7 @@ const char *ads_get_attrname_by_guid(ADS_STRUCT *ads,
                goto done;
        }
 
-       guid_bin = guid_binstring(mem_ctx, schema_guid);
+       guid_bin = ldap_encode_ndr_GUID(mem_ctx, schema_guid);
        if (!guid_bin) {
                goto done;
        }
index 9eb5b6067e2f2e46e3a14620729c0e6afd3ebbf5..fb2a5e3c9dcfbd6990271956df61f260b6393635 100644 (file)
@@ -23,6 +23,7 @@
 #include "../libds/common/flags.h"
 #include "secrets.h"
 #include "../librpc/gen_ndr/samr.h"
+#include "../libcli/ldap/ldap_ndr.h"
 
 struct pdb_ads_state {
        struct sockaddr_un socket_address;
@@ -155,7 +156,7 @@ static struct pdb_ads_samu_private *pdb_ads_get_samu_private(
                        result, struct pdb_ads_samu_private);
        }
 
-       sidstr = sid_binstring(talloc_tos(), pdb_get_user_sid(sam));
+       sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), pdb_get_user_sid(sam));
        if (sidstr == NULL) {
                return NULL;
        }
@@ -437,7 +438,7 @@ static NTSTATUS pdb_ads_getsampwsid(struct pdb_methods *m,
                m->private_data, struct pdb_ads_state);
        char *sidstr, *filter;
 
-       sidstr = sid_binstring(talloc_tos(), sid);
+       sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), sid);
        NT_STATUS_HAVE_NO_MEMORY(sidstr);
 
        filter = talloc_asprintf(
@@ -829,7 +830,7 @@ static NTSTATUS pdb_ads_delete_dom_group(struct pdb_methods *m,
 
        sid_compose(&sid, &state->domainsid, rid);
 
-       sidstr = sid_binstring(talloc_tos(), &sid);
+       sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), &sid);
        NT_STATUS_HAVE_NO_MEMORY(sidstr);
 
        rc = pdb_ads_search_fmt(state, state->domaindn, TLDAP_SCOPE_SUB,
@@ -917,7 +918,7 @@ static NTSTATUS pdb_ads_enum_group_members(struct pdb_methods *m,
        DATA_BLOB *blobs;
        uint32_t *members;
 
-       sidstr = sid_binstring(talloc_tos(), group);
+       sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), group);
        NT_STATUS_HAVE_NO_MEMORY(sidstr);
 
        rc = pdb_ads_search_fmt(state, state->domaindn, TLDAP_SCOPE_SUB,
@@ -1201,7 +1202,7 @@ static NTSTATUS pdb_ads_delete_alias(struct pdb_methods *m,
                return NT_STATUS_LDAP(TLDAP_SERVER_DOWN);
        }
 
-       sidstr = sid_binstring(talloc_tos(), sid);
+       sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), sid);
        if (sidstr == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -1260,7 +1261,7 @@ static NTSTATUS pdb_ads_set_aliasinfo(struct pdb_methods *m,
                return NT_STATUS_LDAP(TLDAP_SERVER_DOWN);
        }
 
-       sidstr = sid_binstring(talloc_tos(), sid);
+       sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), sid);
        NT_STATUS_HAVE_NO_MEMORY(sidstr);
 
        rc = pdb_ads_search_fmt(state, state->domaindn, TLDAP_SCOPE_SUB,
@@ -1327,7 +1328,7 @@ static NTSTATUS pdb_ads_sid2dn(struct pdb_ads_state *state,
        char *sidstr, *dn;
        int rc;
 
-       sidstr = sid_binstring(talloc_tos(), sid);
+       sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), sid);
        NT_STATUS_HAVE_NO_MEMORY(sidstr);
 
        rc = pdb_ads_search_fmt(state, state->domaindn, TLDAP_SCOPE_SUB,
@@ -1482,7 +1483,7 @@ static NTSTATUS pdb_ads_enum_aliasmem(struct pdb_methods *m,
        DATA_BLOB *blobs;
        struct dom_sid *members;
 
-       sidstr = sid_binstring(talloc_tos(), alias);
+       sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), alias);
        NT_STATUS_HAVE_NO_MEMORY(sidstr);
 
        rc = pdb_ads_search_fmt(state, state->domaindn, TLDAP_SCOPE_SUB,
@@ -1651,7 +1652,7 @@ static NTSTATUS pdb_ads_lookup_rids(struct pdb_methods *m,
 
                sid_compose(&sid, domain_sid, rids[i]);
 
-               sidstr = sid_binstring(talloc_tos(), &sid);
+               sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), &sid);
                NT_STATUS_HAVE_NO_MEMORY(sidstr);
 
                rc = pdb_ads_search_fmt(state, state->domaindn,
@@ -1954,7 +1955,7 @@ static bool pdb_ads_sid_to_id(struct pdb_methods *m, const struct dom_sid *sid,
 
        sid_peek_rid(sid, &rid);
 
-       sidstr = sid_binstring(talloc_tos(), sid);
+       sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), sid);
        if (sidstr == NULL) {
                return false;
        }
index f2e47a70420c2c6ea0c95aa524a6c62acb65fcad..9f2f2609515d7115f3af859197f2f7cf2824b08e 100644 (file)
@@ -34,6 +34,7 @@
 #include "secrets.h"
 #include "idmap.h"
 #include "../libcli/security/dom_sid.h"
+#include "../libcli/ldap/ldap_ndr.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_IDMAP
@@ -563,7 +564,7 @@ again:
 
                ids[idx]->status = ID_UNKNOWN;
 
-               sidstr = sid_binstring(talloc_tos(), ids[idx]->sid);
+               sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), ids[idx]->sid);
                filter = talloc_asprintf_append_buffer(filter, "(objectSid=%s)", sidstr);
                        
                TALLOC_FREE(sidstr);
@@ -885,7 +886,7 @@ static NTSTATUS nss_ad_get_info( struct nss_domain_entry *e,
        attrs[2] = ctx->ad_schema->posix_gecos_attr;
        attrs[3] = ctx->ad_schema->posix_gidnumber_attr;
 
-       sidstr = sid_binstring(mem_ctx, sid);
+       sidstr = ldap_encode_ndr_dom_sid(mem_ctx, sid);
        filter = talloc_asprintf(mem_ctx, "(objectSid=%s)", sidstr);
        TALLOC_FREE(sidstr);
 
index 56bd9542f6682976d82a53969093bf319cdbcaa5..77b318cb2d71f596700fb51ddcdb6ec0b7542e19 100644 (file)
@@ -23,6 +23,7 @@
 #include "idmap.h"
 #include "idmap_adex.h"
 #include "libads/cldap.h"
+#include "../libcli/ldap/ldap_ndr.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_IDMAP
@@ -719,7 +720,7 @@ done:
 
        *name = NULL;
 
-       sid_string = sid_binstring(frame, sid);
+       sid_string = ldap_encode_ndr_dom_sid(frame, sid);
        BAIL_ON_PTR_ERROR(sid_string, nt_status);
 
        filter = talloc_asprintf(frame, "(objectSid=%s)", sid_string);
index 191f77159cefc5f5e5f078d5be2949d947d4733a..9f5cc884a5f0531eb44bcb12ea647765336e369a 100644 (file)
@@ -24,6 +24,7 @@
 #include "ads.h"
 #include "idmap.h"
 #include "idmap_adex.h"
+#include "../libcli/ldap/ldap_ndr.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_IDMAP
@@ -485,7 +486,7 @@ static NTSTATUS search_forest(struct likewise_cell *forest_cell,
 
                switch (fdata->ftype) {
                case SidFilter:
-                       sid_binstr = sid_binstring(frame, &fdata->filter.sid);
+                       sid_binstr = ldap_encode_ndr_dom_sid(frame, &fdata->filter.sid);
                        BAIL_ON_PTR_ERROR(sid_binstr, nt_status);
 
                        filter = talloc_asprintf(frame, "(objectSid=%s)", sid_binstr);
index 367d38ba154da55722bfa1dfc9c9b93f8af1fb53..fa498d63dff0f449a9b8152b188c937e467d36bb 100644 (file)
@@ -27,6 +27,7 @@
 #include "../libds/common/flags.h"
 #include "ads.h"
 #include "secrets.h"
+#include "../libcli/ldap/ldap_ndr.h"
 
 #ifdef HAVE_ADS
 
@@ -542,7 +543,7 @@ static NTSTATUS query_user(struct winbindd_domain *domain,
                return NT_STATUS_SERVER_DISABLED;
        }
 
-       sidstr = sid_binstring(talloc_tos(), sid);
+       sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), sid);
 
        ret = asprintf(&ldap_exp, "(objectSid=%s)", sidstr);
        TALLOC_FREE(sidstr);
@@ -1044,7 +1045,7 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
                goto done;
        }
 
-       if ((sidbinstr = sid_binstring(talloc_tos(), group_sid)) == NULL) {
+       if ((sidbinstr = ldap_encode_ndr_dom_sid(talloc_tos(), group_sid)) == NULL) {
                status = NT_STATUS_NO_MEMORY;
                goto done;
        }
index e5ad33bab40765979caf9d1711c21d5b94859702..6c373484958dcc1b46f89e06f3d587333011c45f 100644 (file)
@@ -321,10 +321,10 @@ LIBSMB_SRC0 = '''
 LIBSAMBA_SRC = '${LIBSMB_SRC0}'
 
 LIBCLI_LDAP_MESSAGE_SRC = '''../libcli/ldap/ldap_message.c'''
-LIBCLI_LDAP_NDR_SRC = '''../libcli/ldap/ldap_ndr.c'''
+LIBCLI_LDAP_NDR_SRC = '''../libcli/ldap/ldap_ndr.c lib/ldb_compat.c'''
 
 CLDAP_SRC = '''libads/cldap.c
-        ../libcli/cldap/cldap.c lib/ldb_compat.c
+        ../libcli/cldap/cldap.c
         ../lib/util/idtree.c
         ${LIBCLI_LDAP_MESSAGE_SRC} ${LIBCLI_LDAP_NDR_SRC}'''