The branch, master has been updated
       via  be3e851 Fix some nonempty blank lines
       via  85ee336 wbinfo: Use wbcSidToStringBuf
       via  d34092e wbinfo: Fix a debug message
       via  c97ea59 s3-net: Use wbcSidToStringBuf
       via  e0fae3d pam_winbind: Use wbcSidToStringBuf
       via  7ffa7e4 libwbclient: Use wbcSidToStringBuf
       via  afb6752 libwbclient: Add wbcSidToStringBuf
       via  181b23c nsswitch: wbcFreeMemory deals fine with NULL
      from  dcbfb6f s3: Fix a memory leak in check_sam_security_info3

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit be3e851fea7c279afc879bc4b5923605ba66ad64
Author: Volker Lendecke <[email protected]>
Date:   Fri Mar 4 20:27:57 2011 +0100

    Fix some nonempty blank lines
    
    Autobuild-User: Volker Lendecke <[email protected]>
    Autobuild-Date: Sat Mar  5 15:16:02 CET 2011 on sn-devel-104

commit 85ee3360e1a2c69089a547ff29b9f479f353646c
Author: Volker Lendecke <[email protected]>
Date:   Fri Mar 4 06:02:35 2011 +0100

    wbinfo: Use wbcSidToStringBuf

commit d34092e919fd53276af4c54b7e70fff855f904fb
Author: Volker Lendecke <[email protected]>
Date:   Fri Mar 4 05:55:23 2011 +0100

    wbinfo: Fix a debug message

commit c97ea5976c50ef9d883eafed334ff69b5b43e259
Author: Volker Lendecke <[email protected]>
Date:   Fri Mar 4 05:53:10 2011 +0100

    s3-net: Use wbcSidToStringBuf

commit e0fae3d49483c33329628534591f966d4841e474
Author: Volker Lendecke <[email protected]>
Date:   Fri Mar 4 05:49:20 2011 +0100

    pam_winbind: Use wbcSidToStringBuf

commit 7ffa7e4bcae0c4e55c91a7a4466eae596d982770
Author: Volker Lendecke <[email protected]>
Date:   Fri Mar 4 05:44:23 2011 +0100

    libwbclient: Use wbcSidToStringBuf

commit afb6752fa7903a63c2a1cef704bb9da9bab4b251
Author: Volker Lendecke <[email protected]>
Date:   Fri Mar 4 05:38:04 2011 +0100

    libwbclient: Add wbcSidToStringBuf

commit 181b23ceed77de50c2b9d05a92a795cce1beabb9
Author: Volker Lendecke <[email protected]>
Date:   Thu Mar 3 22:29:39 2011 +0100

    nsswitch: wbcFreeMemory deals fine with NULL

-----------------------------------------------------------------------

Summary of changes:
 libcli/util/ntstatus.h           |    6 +-
 nsswitch/libwbclient/wbc_idmap.c |   14 +-----
 nsswitch/libwbclient/wbc_pwd.c   |    7 +--
 nsswitch/libwbclient/wbc_sid.c   |   95 +++++++++++++++++--------------------
 nsswitch/libwbclient/wbclient.h  |   16 ++++++-
 nsswitch/pam_winbind.c           |   19 ++------
 nsswitch/wbinfo.c                |   98 ++++++++------------------------------
 source3/libsmb/ntlmssp.c         |    4 +-
 source3/utils/net_rpc.c          |   20 +-------
 9 files changed, 92 insertions(+), 187 deletions(-)


Changeset truncated at 500 lines:

diff --git a/libcli/util/ntstatus.h b/libcli/util/ntstatus.h
index d7c6038..a7fc579 100644
--- a/libcli/util/ntstatus.h
+++ b/libcli/util/ntstatus.h
@@ -5,17 +5,17 @@
    Copyright (C) John H Terpstra              1996-2000
    Copyright (C) Luke Kenneth Casson Leighton 1996-2000
    Copyright (C) Paul Ashton                  1998-2000
-   
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
diff --git a/nsswitch/libwbclient/wbc_idmap.c b/nsswitch/libwbclient/wbc_idmap.c
index ab8de9f..a77e7c0 100644
--- a/nsswitch/libwbclient/wbc_idmap.c
+++ b/nsswitch/libwbclient/wbc_idmap.c
@@ -29,7 +29,6 @@ wbcErr wbcSidToUid(const struct wbcDomainSid *sid, uid_t 
*puid)
 {
        struct winbindd_request request;
        struct winbindd_response response;
-       char *sid_string = NULL;
        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
 
        if (!sid || !puid) {
@@ -42,11 +41,7 @@ wbcErr wbcSidToUid(const struct wbcDomainSid *sid, uid_t 
*puid)
        ZERO_STRUCT(request);
        ZERO_STRUCT(response);
 
-       wbc_status = wbcSidToString(sid, &sid_string);
-       BAIL_ON_WBC_ERROR(wbc_status);
-
-       strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1);
-       wbcFreeMemory(sid_string);
+       wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid));
 
        /* Make request */
 
@@ -124,7 +119,6 @@ wbcErr wbcSidToGid(const struct wbcDomainSid *sid, gid_t 
*pgid)
        struct winbindd_request request;
        struct winbindd_response response;
        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
-       char *sid_string = NULL;
 
        if (!sid || !pgid) {
                wbc_status = WBC_ERR_INVALID_PARAM;
@@ -136,11 +130,7 @@ wbcErr wbcSidToGid(const struct wbcDomainSid *sid, gid_t 
*pgid)
        ZERO_STRUCT(request);
        ZERO_STRUCT(response);
 
-       wbc_status = wbcSidToString(sid, &sid_string);
-       BAIL_ON_WBC_ERROR(wbc_status);
-
-       strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1);
-       wbcFreeMemory(sid_string);
+        wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid));
 
        /* Make request */
 
diff --git a/nsswitch/libwbclient/wbc_pwd.c b/nsswitch/libwbclient/wbc_pwd.c
index abd03d7..6df694d 100644
--- a/nsswitch/libwbclient/wbc_pwd.c
+++ b/nsswitch/libwbclient/wbc_pwd.c
@@ -236,22 +236,18 @@ wbcErr wbcGetpwsid(struct wbcDomainSid *sid, struct 
passwd **pwd)
        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
        struct winbindd_request request;
        struct winbindd_response response;
-       char * sid_string = NULL;
 
        if (!pwd) {
                wbc_status = WBC_ERR_INVALID_PARAM;
                BAIL_ON_WBC_ERROR(wbc_status);
        }
 
-       wbc_status = wbcSidToString(sid, &sid_string);
-       BAIL_ON_WBC_ERROR(wbc_status);
-
        /* Initialize request */
 
        ZERO_STRUCT(request);
        ZERO_STRUCT(response);
 
-       strncpy(request.data.sid, sid_string, sizeof(request.data.sid));
+        wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid));
 
        wbc_status = wbcRequestResponse(WINBINDD_GETPWSID,
                                        &request,
@@ -262,7 +258,6 @@ wbcErr wbcGetpwsid(struct wbcDomainSid *sid, struct passwd 
**pwd)
        BAIL_ON_PTR_ERROR(*pwd, wbc_status);
 
  done:
-       wbcFreeMemory(sid_string);
        return wbc_status;
 }
 
diff --git a/nsswitch/libwbclient/wbc_sid.c b/nsswitch/libwbclient/wbc_sid.c
index 73bd416..e94d874 100644
--- a/nsswitch/libwbclient/wbc_sid.c
+++ b/nsswitch/libwbclient/wbc_sid.c
@@ -27,23 +27,17 @@
 #include "libwbclient.h"
 #include "../winbind_client.h"
 
-/* Convert a binary SID to a character string */
-wbcErr wbcSidToString(const struct wbcDomainSid *sid,
-                     char **sid_string)
+/* Convert a sid to a string into a buffer. Return the string
+ * length. If buflen is too small, return the string length that would
+ * result if it was long enough. */
+int wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen)
 {
        uint32_t id_auth;
-       int i, ofs, maxlen;
-       char *result;
+       int i, ofs;
 
        if (!sid) {
-               return WBC_ERR_INVALID_SID;
-       }
-
-       maxlen = sid->num_auths * 11 + 25;
-
-       result = (char *)wbcAllocateMemory(maxlen, 1, NULL);
-       if (result == NULL) {
-               return WBC_ERR_NO_MEMORY;
+               strlcpy(buf, "(NULL SID)", buflen);
+               return 10;      /* strlen("(NULL SID)") */
        }
 
        /*
@@ -56,13 +50,39 @@ wbcErr wbcSidToString(const struct wbcDomainSid *sid,
                (sid->id_auth[3] << 16) +
                (sid->id_auth[2] << 24);
 
-       ofs = snprintf(result, maxlen, "S-%u-%lu",
+       ofs = snprintf(buf, buflen, "S-%u-%lu",
                       (unsigned int)sid->sid_rev_num, (unsigned long)id_auth);
 
        for (i = 0; i < sid->num_auths; i++) {
-               ofs += snprintf(result + ofs, maxlen - ofs, "-%lu",
+               ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "-%lu",
                                (unsigned long)sid->sub_auths[i]);
        }
+       return ofs;
+}
+
+/* Convert a binary SID to a character string */
+wbcErr wbcSidToString(const struct wbcDomainSid *sid,
+                     char **sid_string)
+{
+       char buf[WBC_SID_STRING_BUFLEN];
+       char *result;
+       int len;
+
+       if (!sid) {
+               return WBC_ERR_INVALID_SID;
+       }
+
+       len = wbcSidToStringBuf(sid, buf, sizeof(buf));
+
+       if (len+1 > sizeof(buf)) {
+               return WBC_ERR_INVALID_SID;
+       }
+
+       result = (char *)wbcAllocateMemory(len+1, 1, NULL);
+       if (result == NULL) {
+               return WBC_ERR_NO_MEMORY;
+       }
+       memcpy(result, buf, len+1);
 
        *sid_string = result;
        return WBC_ERR_SUCCESS;
@@ -205,7 +225,6 @@ wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
        struct winbindd_request request;
        struct winbindd_response response;
        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
-       char *sid_string = NULL;
        char *domain, *name;
 
        if (!sid) {
@@ -217,15 +236,7 @@ wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
        ZERO_STRUCT(request);
        ZERO_STRUCT(response);
 
-       /* dst is already null terminated from the memset above */
-
-       wbc_status = wbcSidToString(sid, &sid_string);
-       if (!WBC_ERROR_IS_OK(wbc_status)) {
-               return wbc_status;
-       }
-
-       strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1);
-       wbcFreeMemory(sid_string);
+       wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid));
 
        /* Make request */
 
@@ -281,7 +292,6 @@ wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
        char *p;
        struct winbindd_request request;
        struct winbindd_response response;
-       char *sid_string = NULL;
        char *domain_name = NULL;
        const char **names = NULL;
        enum wbcSidType *types = NULL;
@@ -297,11 +307,7 @@ wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
                BAIL_ON_WBC_ERROR(wbc_status);
        }
 
-       wbc_status = wbcSidToString(dom_sid, &sid_string);
-       BAIL_ON_WBC_ERROR(wbc_status);
-
-       strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1);
-       wbcFreeMemory(sid_string);
+       wbcSidToStringBuf(dom_sid, request.data.sid, sizeof(request.data.sid));
 
        /* Even if all the Rids were of maximum 32bit values,
           we would only have 11 bytes per rid in the final array
@@ -406,7 +412,6 @@ wbcErr wbcLookupUserSids(const struct wbcDomainSid 
*user_sid,
        const char *s;
        struct winbindd_request request;
        struct winbindd_response response;
-       char *sid_string = NULL;
        struct wbcDomainSid *sids = NULL;
        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
        int cmd;
@@ -421,11 +426,7 @@ wbcErr wbcLookupUserSids(const struct wbcDomainSid 
*user_sid,
                BAIL_ON_WBC_ERROR(wbc_status);
        }
 
-       wbc_status = wbcSidToString(user_sid, &sid_string);
-       BAIL_ON_WBC_ERROR(wbc_status);
-
-       strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1);
-       wbcFreeMemory(sid_string);
+       wbcSidToStringBuf(user_sid, request.data.sid, sizeof(request.data.sid));
 
        if (domain_groups_only) {
                cmd = WINBINDD_GETUSERDOMGROUPS;
@@ -496,8 +497,6 @@ wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
        const char *s;
        struct winbindd_request request;
        struct winbindd_response response;
-       char *sid_string = NULL;
-       ssize_t sid_len;
        ssize_t extra_data_len = 0;
        char * extra_data = NULL;
        ssize_t buflen = 0;
@@ -515,12 +514,7 @@ wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
                goto done;
        }
 
-       wbc_status = wbcSidToString(dom_sid, &sid_string);
-       BAIL_ON_WBC_ERROR(wbc_status);
-
-       strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1);
-       wbcFreeMemory(sid_string);
-       sid_string = NULL;
+       wbcSidToStringBuf(dom_sid, request.data.sid, sizeof(request.data.sid));
 
        /* Lets assume each sid is around 57 characters
         * S-1-5-21-AAAAAAAAAAA-BBBBBBBBBBB-CCCCCCCCCCC-DDDDDDDDDDD\n */
@@ -533,10 +527,10 @@ wbcErr wbcGetSidAliases(const struct wbcDomainSid 
*dom_sid,
 
        /* Build the sid list */
        for (i=0; i<num_sids; i++) {
-               wbc_status = wbcSidToString(&sids[i], &sid_string);
-               BAIL_ON_WBC_ERROR(wbc_status);
+               char sid_str[WBC_SID_STRING_BUFLEN];
+               size_t sid_len;
 
-               sid_len = strlen(sid_string);
+               sid_len = wbcSidToStringBuf(&sids[i], sid_str, sizeof(sid_str));
 
                if (buflen < extra_data_len + sid_len + 2) {
                        buflen *= 2;
@@ -547,13 +541,11 @@ wbcErr wbcGetSidAliases(const struct wbcDomainSid 
*dom_sid,
                        }
                }
 
-               strncpy(&extra_data[extra_data_len], sid_string,
+               strncpy(&extra_data[extra_data_len], sid_str,
                        buflen - extra_data_len);
                extra_data_len += sid_len;
                extra_data[extra_data_len++] = '\n';
                extra_data[extra_data_len] = '\0';
-               wbcFreeMemory(sid_string);
-               sid_string = NULL;
        }
        extra_data_len += 1;
 
@@ -594,7 +586,6 @@ wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
        wbc_status = WBC_ERR_SUCCESS;
 
  done:
-       wbcFreeMemory(sid_string);
        free(extra_data);
        winbindd_free_response(&response);
        wbcFreeMemory(rids);
diff --git a/nsswitch/libwbclient/wbclient.h b/nsswitch/libwbclient/wbclient.h
index bd5a51c..0286e5b 100644
--- a/nsswitch/libwbclient/wbclient.h
+++ b/nsswitch/libwbclient/wbclient.h
@@ -66,9 +66,10 @@ const char *wbcErrorString(wbcErr error);
  *  0.4: Added wbcSidTypeString()
  *  0.5: Added wbcChangeTrustCredentials()
  *  0.6: Made struct wbcInterfaceDetails char* members non-const
+ *  0.7: Added wbcSidToStringBuf()
  **/
 #define WBCLIENT_MAJOR_VERSION 0
-#define WBCLIENT_MINOR_VERSION 6
+#define WBCLIENT_MINOR_VERSION 7
 #define WBCLIENT_VENDOR_VERSION "Samba libwbclient"
 struct wbcLibraryDetails {
        uint16_t major_version;
@@ -529,6 +530,19 @@ void wbcFreeMemory(void*);
  */
 const char* wbcSidTypeString(enum wbcSidType type);
 
+#define WBC_SID_STRING_BUFLEN (15*11+25)
+
+/*
+ * @brief Print a sid into a buffer
+ *
+ * @param sid          Binary Security Identifier
+ * @param buf          Target buffer
+ * @param buflen       Target buffer length
+ *
+ * @return Resulting string length.
+ */
+int wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen);
+
 /**
  * @brief Convert a binary SID to a character string
  *
diff --git a/nsswitch/pam_winbind.c b/nsswitch/pam_winbind.c
index e651ce0..7005c25 100644
--- a/nsswitch/pam_winbind.c
+++ b/nsswitch/pam_winbind.c
@@ -1077,12 +1077,11 @@ static bool winbind_name_to_sid_string(struct 
pwb_context *ctx,
                                       char *sid_list_buffer,
                                       int sid_list_buffer_size)
 {
-       const char* sid_string = NULL;
-       char *sid_str = NULL;
+       char sid_string[WBC_SID_STRING_BUFLEN];
 
        /* lookup name? */
        if (IS_SID_STRING(name)) {
-               sid_string = name;
+               strlcpy(sid_string, name, sizeof(sid_string));
        } else {
                wbcErr wbc_status;
                struct wbcDomainSid sid;
@@ -1098,21 +1097,13 @@ static bool winbind_name_to_sid_string(struct 
pwb_context *ctx,
                        return false;
                }
 
-               wbc_status = wbcSidToString(&sid, &sid_str);
-               if (!WBC_ERROR_IS_OK(wbc_status)) {
-                       return false;
-               }
-
-               sid_string = sid_str;
+               wbcSidToStringBuf(&sid, sid_string, sizeof(sid_string));
        }
 
        if (!safe_append_string(sid_list_buffer, sid_string,
                                sid_list_buffer_size)) {
-               wbcFreeMemory(sid_str);
                return false;
        }
-
-       wbcFreeMemory(sid_str);
        return true;
 }
 
@@ -1899,9 +1890,7 @@ static int winbind_auth_request(struct pwb_context *ctx,
        }
 
  done:
-       if (logon.blobs) {
-               wbcFreeMemory(logon.blobs);
-       }
+       wbcFreeMemory(logon.blobs);
        if (info && info->blobs && !p_info) {
                wbcFreeMemory(info->blobs);
        }
diff --git a/nsswitch/wbinfo.c b/nsswitch/wbinfo.c
index caa37f3..2436b3b 100644
--- a/nsswitch/wbinfo.c
+++ b/nsswitch/wbinfo.c
@@ -357,16 +357,9 @@ static bool wbinfo_get_usersids(const char *user_sid_str)
        }
 
        for (i = 0; i < num_sids; i++) {
-               char *str = NULL;
-               wbc_status = wbcSidToString(&sids[i], &str);
-               if (!WBC_ERROR_IS_OK(wbc_status)) {
-                       d_fprintf(stderr, "failed to call wbcSidToString: "
-                                 "%s\n", wbcErrorString(wbc_status));
-                       wbcFreeMemory(sids);
-                       return false;
-               }
+               char str[WBC_SID_STRING_BUFLEN];
+               wbcSidToStringBuf(&sids[i], str, sizeof(str));
                d_printf("%s\n", str);
-               wbcFreeMemory(str);
        }
 
        wbcFreeMemory(sids);
@@ -385,7 +378,7 @@ static bool wbinfo_get_userdomgroups(const char 
*user_sid_str)
 
        wbc_status = wbcStringToSid(user_sid_str, &user_sid);
        if (!WBC_ERROR_IS_OK(wbc_status)) {
-               d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
+               d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
                          wbcErrorString(wbc_status));
                return false;
        }
@@ -398,16 +391,9 @@ static bool wbinfo_get_userdomgroups(const char 
*user_sid_str)
        }
 
        for (i = 0; i < num_sids; i++) {
-               char *str = NULL;
-               wbc_status = wbcSidToString(&sids[i], &str);
-               if (!WBC_ERROR_IS_OK(wbc_status)) {
-                       d_fprintf(stderr, "failed to call wbcSidToString: "
-                                 "%s\n", wbcErrorString(wbc_status));
-                       wbcFreeMemory(sids);
-                       return false;
-               }
+               char str[WBC_SID_STRING_BUFLEN];
+               wbcSidToStringBuf(&sids[i], str, sizeof(str));
                d_printf("%s\n", str);
-               wbcFreeMemory(str);
        }
 
        wbcFreeMemory(sids);
@@ -424,7 +410,7 @@ static bool wbinfo_get_sidaliases(const char *domain,
        struct wbcDomainSid user_sid;
        uint32_t *alias_rids = NULL;
        uint32_t num_alias_rids;
-       char *domain_sid_str = NULL;
+       char domain_sid_str[WBC_SID_STRING_BUFLEN];
 
        /* Send request */
        if ((domain == NULL) || (strequal(domain, ".")) ||
@@ -451,10 +437,7 @@ static bool wbinfo_get_sidaliases(const char *domain,
                goto done;
        }
 
-       wbc_status = wbcSidToString(&dinfo->sid, &domain_sid_str);
-       if (!WBC_ERROR_IS_OK(wbc_status)) {
-               goto done;
-       }
+       wbcSidToStringBuf(&dinfo->sid, domain_sid_str, sizeof(domain_sid_str));
 
        for (i = 0; i < num_alias_rids; i++) {
                d_printf("%s-%d\n", domain_sid_str, alias_rids[i]);
@@ -463,12 +446,7 @@ static bool wbinfo_get_sidaliases(const char *domain,
        wbcFreeMemory(alias_rids);
 
 done:
-       if (domain_sid_str) {
-               wbcFreeMemory(domain_sid_str);
-       }
-       if (dinfo) {
-               wbcFreeMemory(dinfo);
-       }
+       wbcFreeMemory(dinfo);
        return (WBC_ERR_SUCCESS == wbc_status);
 }
 
@@ -651,7 +629,7 @@ static bool wbinfo_domain_info(const char *domain)
 {
        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
        struct wbcDomainInfo *dinfo = NULL;
-       char *sid_str = NULL;
+       char sid_str[WBC_SID_STRING_BUFLEN];
 
        if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
                domain = get_winbind_domain();
@@ -666,13 +644,7 @@ static bool wbinfo_domain_info(const char *domain)
                return false;
        }
 
-       wbc_status = wbcSidToString(&dinfo->sid, &sid_str);


-- 
Samba Shared Repository

Reply via email to