summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2014-04-14 13:12:00 +0200
committerSumit Bose <sbose@redhat.com>2014-06-17 12:55:15 +0200
commitbb3a4dbb2c6456ff21b551b263d59e35bbee5389 (patch)
tree9bbf0dc89445dcb681c035f6aed65718c16821cd
parentbe9a69ac5d85a4bd09f7b87f5fe9d2282d5b91b9 (diff)
downloadsamba-bb3a4dbb2c6456ff21b551b263d59e35bbee5389.zip
samba-bb3a4dbb2c6456ff21b551b263d59e35bbee5389.tar.gz
samba-bb3a4dbb2c6456ff21b551b263d59e35bbee5389.tar.xz
Extract common code from wbc_util.c
-rw-r--r--nsswitch/libwbclient/wbc_util.c70
-rw-r--r--nsswitch/libwbclient/wbc_util_common.c97
-rw-r--r--nsswitch/libwbclient/wscript3
3 files changed, 99 insertions, 71 deletions
diff --git a/nsswitch/libwbclient/wbc_util.c b/nsswitch/libwbclient/wbc_util.c
index 4060e25..2027f32 100644
--- a/nsswitch/libwbclient/wbc_util.c
+++ b/nsswitch/libwbclient/wbc_util.c
@@ -747,73 +747,3 @@ wbcErr wbcLookupDomainControllerEx(const char *domain,
done:
return wbc_status;
}
-
-static void wbcNamedBlobDestructor(void *ptr)
-{
- struct wbcNamedBlob *b = (struct wbcNamedBlob *)ptr;
-
- while (b->name != NULL) {
- free(discard_const_p(char, b->name));
- free(b->blob.data);
- b += 1;
- }
-}
-
-/* Initialize a named blob and add to list of blobs */
-wbcErr wbcAddNamedBlob(size_t *num_blobs,
- struct wbcNamedBlob **pblobs,
- const char *name,
- uint32_t flags,
- uint8_t *data,
- size_t length)
-{
- wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
- struct wbcNamedBlob *blobs, *blob;
-
- if (name == NULL) {
- return WBC_ERR_INVALID_PARAM;
- }
-
- /*
- * Overallocate the b->name==NULL terminator for
- * wbcNamedBlobDestructor
- */
- blobs = (struct wbcNamedBlob *)wbcAllocateMemory(
- *num_blobs + 2, sizeof(struct wbcNamedBlob),
- wbcNamedBlobDestructor);
-
- if (blobs == NULL) {
- return WBC_ERR_NO_MEMORY;
- }
-
- if (*pblobs != NULL) {
- struct wbcNamedBlob *old = *pblobs;
- memcpy(blobs, old, sizeof(struct wbcNamedBlob) * (*num_blobs));
- if (*num_blobs != 0) {
- /* end indicator for wbcNamedBlobDestructor */
- old[0].name = NULL;
- }
- wbcFreeMemory(old);
- }
- *pblobs = blobs;
-
- blob = &blobs[*num_blobs];
-
- blob->name = strdup(name);
- BAIL_ON_PTR_ERROR(blob->name, wbc_status);
- blob->flags = flags;
-
- blob->blob.length = length;
- blob->blob.data = (uint8_t *)malloc(length);
- BAIL_ON_PTR_ERROR(blob->blob.data, wbc_status);
- memcpy(blob->blob.data, data, length);
-
- *num_blobs += 1;
- *pblobs = blobs;
- blobs = NULL;
-
- wbc_status = WBC_ERR_SUCCESS;
-done:
- wbcFreeMemory(blobs);
- return wbc_status;
-}
diff --git a/nsswitch/libwbclient/wbc_util_common.c b/nsswitch/libwbclient/wbc_util_common.c
new file mode 100644
index 0000000..ab226aa
--- /dev/null
+++ b/nsswitch/libwbclient/wbc_util_common.c
@@ -0,0 +1,97 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ Winbind client asynchronous API, utility functions
+
+ Copyright (C) Gerald (Jerry) Carter 2007-2008
+
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* Required Headers */
+
+#include "replace.h"
+#include "libwbclient.h"
+#include "../winbind_client.h"
+
+static void wbcNamedBlobDestructor(void *ptr)
+{
+ struct wbcNamedBlob *b = (struct wbcNamedBlob *)ptr;
+
+ while (b->name != NULL) {
+ free(discard_const_p(char, b->name));
+ free(b->blob.data);
+ b += 1;
+ }
+}
+
+/* Initialize a named blob and add to list of blobs */
+wbcErr wbcAddNamedBlob(size_t *num_blobs,
+ struct wbcNamedBlob **pblobs,
+ const char *name,
+ uint32_t flags,
+ uint8_t *data,
+ size_t length)
+{
+ wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+ struct wbcNamedBlob *blobs, *blob;
+
+ if (name == NULL) {
+ return WBC_ERR_INVALID_PARAM;
+ }
+
+ /*
+ * Overallocate the b->name==NULL terminator for
+ * wbcNamedBlobDestructor
+ */
+ blobs = (struct wbcNamedBlob *)wbcAllocateMemory(
+ *num_blobs + 2, sizeof(struct wbcNamedBlob),
+ wbcNamedBlobDestructor);
+
+ if (blobs == NULL) {
+ return WBC_ERR_NO_MEMORY;
+ }
+
+ if (*pblobs != NULL) {
+ struct wbcNamedBlob *old = *pblobs;
+ memcpy(blobs, old, sizeof(struct wbcNamedBlob) * (*num_blobs));
+ if (*num_blobs != 0) {
+ /* end indicator for wbcNamedBlobDestructor */
+ old[0].name = NULL;
+ }
+ wbcFreeMemory(old);
+ }
+ *pblobs = blobs;
+
+ blob = &blobs[*num_blobs];
+
+ blob->name = strdup(name);
+ BAIL_ON_PTR_ERROR(blob->name, wbc_status);
+ blob->flags = flags;
+
+ blob->blob.length = length;
+ blob->blob.data = (uint8_t *)malloc(length);
+ BAIL_ON_PTR_ERROR(blob->blob.data, wbc_status);
+ memcpy(blob->blob.data, data, length);
+
+ *num_blobs += 1;
+ *pblobs = blobs;
+ blobs = NULL;
+
+ wbc_status = WBC_ERR_SUCCESS;
+done:
+ wbcFreeMemory(blobs);
+ return wbc_status;
+}
diff --git a/nsswitch/libwbclient/wscript b/nsswitch/libwbclient/wscript
index 8f0109c..7632425 100644
--- a/nsswitch/libwbclient/wscript
+++ b/nsswitch/libwbclient/wscript
@@ -39,7 +39,8 @@ def build(bld):
wbc_pwd.c
wbc_sid.c
wbc_sid_common.c
- wbc_util.c''',
+ wbc_util.c
+ wbc_util_common.c''',
deps='winbind-client',
pc_files='wbclient.pc',
public_headers='wbclient.h',