summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/include/proto.h12
-rw-r--r--source3/lib/util.c67
-rw-r--r--source3/rpc_parse/parse_misc.c20
-rw-r--r--source3/script/mkproto.awk2
4 files changed, 66 insertions, 35 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 711eeb0798..d6b7abba95 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -480,10 +480,16 @@ int set_maxfiles(int requested_max);
void reg_get_subkey(char *full_keyname, char *key_name, char *subkey_name);
BOOL reg_split_key(const char *full_keyname, uint32 *reg_type, char *key_name);
BOOL become_user_permanently(uid_t uid, gid_t gid);
+void free_void_array(uint32 num_entries, void **entries,
+ void(free_item)(void*));
+BOOL add_item_to_array(uint32 *len, void ***array, const void *item,
+ void*(item_dup)(const void*));
void free_char_array(uint32 num_entries, char **entries);
BOOL add_chars_to_array(uint32 *len, char ***array, const char *name);
-BOOL add_sid_to_array(uint32 *len, DOM_SID ***array, const DOM_SID *sid);
+void free_unistr_array(uint32 num_entries, UNISTR2 **entries);
+BOOL add_unistr_to_array(uint32 *len, UNISTR2 ***array, UNISTR2 *name);
void free_sid_array(uint32 num_entries, DOM_SID **entries);
+BOOL add_sid_to_array(uint32 *len, DOM_SID ***array, const DOM_SID *sid);
/*The following definitions come from lib/util_file.c */
@@ -2214,7 +2220,9 @@ BOOL smb_io_buffer5(char *desc, BUFFER5 *buf5, prs_struct *ps, int depth);
BOOL make_buffer2(BUFFER2 *str, const char *buf, int len);
BOOL smb_io_buffer2(char *desc, BUFFER2 *buf2, uint32 buffer, prs_struct *ps, int depth);
BOOL make_buf_unistr2(UNISTR2 *str, uint32 *ptr, char *buf);
-BOOL copy_unistr2(UNISTR2 *str, UNISTR2 *from);
+BOOL copy_unistr2(UNISTR2 *str, const UNISTR2 *from);
+UNISTR2 *unistr2_dup(const UNISTR2 *name);
+void unistr2_free(UNISTR2 *name);
BOOL make_string2(STRING2 *str, char *buf, int len);
BOOL smb_io_string2(char *desc, STRING2 *str2, uint32 buffer, prs_struct *ps, int depth);
BOOL make_unistr2(UNISTR2 *str, const char *buf, int len);
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 9e01f0f095..0ed4e6fe50 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -3228,7 +3228,8 @@ BOOL become_user_permanently(uid_t uid, gid_t gid)
return(True);
}
-void free_char_array(uint32 num_entries, char **entries)
+void free_void_array(uint32 num_entries, void **entries,
+ void(free_item)(void*))
{
uint32 i;
if (entries != NULL)
@@ -3237,62 +3238,66 @@ void free_char_array(uint32 num_entries, char **entries)
{
if (entries[i] != NULL)
{
- free(entries[i]);
+ free_item(entries[i]);
}
}
free(entries);
}
}
-BOOL add_chars_to_array(uint32 *len, char ***array, const char *name)
+BOOL add_item_to_array(uint32 *len, void ***array, const void *item,
+ void*(item_dup)(const void*))
{
- if (len == NULL || array == NULL)
+ if (len == NULL || array == NULL || item_dup == NULL)
{
return False;
}
- (*array) = (char**)Realloc((*array), ((*len)+1) * sizeof((*array)[0]));
+ (*array) = (void**)Realloc((*array), ((*len)+1)*sizeof((*array)[0]));
if ((*array) != NULL)
{
- (*array)[(*len)] = strdup(name);
+ (*array)[(*len)] = item_dup(item);
(*len)++;
return True;
}
return True;
}
-BOOL add_sid_to_array(uint32 *len, DOM_SID ***array, const DOM_SID *sid)
+void free_char_array(uint32 num_entries, char **entries)
{
- if (len == NULL || array == NULL)
- {
- return False;
- }
+ void(*fn)(void*) = (void(*)(void*))&free;
+ free_void_array(num_entries, (void**)entries, *fn);
+}
- (*array) = (char**)Realloc((*array), ((*len)+1) * sizeof((*array)[0]));
+BOOL add_chars_to_array(uint32 *len, char ***array, const char *name)
+{
+ void*(*fn)(const void*) = (void*(*)(const void*))&strdup;
+ return add_item_to_array(len, (void***)array, (const void*)name, *fn);
+
+}
- if ((*array) != NULL)
- {
- (*array)[(*len)] = sid_dup(sid);
- (*len)++;
- return True;
- }
- return True;
+void free_unistr_array(uint32 num_entries, UNISTR2 **entries)
+{
+ void(*fn)(void*) = (void(*)(void*))&unistr2_free;
+ free_void_array(num_entries, (void**)entries, *fn);
+}
+
+BOOL add_unistr_to_array(uint32 *len, UNISTR2 ***array, UNISTR2 *name)
+{
+ void*(*fn)(const void*) = (void*(*)(const void*))&unistr2_dup;
+ return add_item_to_array(len, (void***)array, (const void*)name, *fn);
}
void free_sid_array(uint32 num_entries, DOM_SID **entries)
{
- uint32 i;
- if (entries != NULL)
- {
- for (i = 0; i < num_entries; i++)
- {
- if (entries[i] != NULL)
- {
- free(entries[i]);
- }
- }
- free(entries);
- }
+ void(*fn)(void*) = (void(*)(void*))&free;
+ free_void_array(num_entries, (void**)entries, *fn);
+}
+
+BOOL add_sid_to_array(uint32 *len, DOM_SID ***array, const DOM_SID *sid)
+{
+ void*(*fn)(const void*) = (void*(*)(const void*))&sid_dup;
+ return add_item_to_array(len, (void***)array, (const void*)sid, *fn);
}
diff --git a/source3/rpc_parse/parse_misc.c b/source3/rpc_parse/parse_misc.c
index 69455b7b42..471cb59e1c 100644
--- a/source3/rpc_parse/parse_misc.c
+++ b/source3/rpc_parse/parse_misc.c
@@ -747,7 +747,7 @@ BOOL make_buf_unistr2(UNISTR2 *str, uint32 *ptr, char *buf)
/*******************************************************************
copies a UNISTR2 structure.
********************************************************************/
-BOOL copy_unistr2(UNISTR2 *str, UNISTR2 *from)
+BOOL copy_unistr2(UNISTR2 *str, const UNISTR2 *from)
{
/* set up string lengths. add one if string is not null-terminated */
str->uni_max_len = from->uni_max_len;
@@ -761,6 +761,24 @@ BOOL copy_unistr2(UNISTR2 *str, UNISTR2 *from)
}
/*******************************************************************
+duplicates a UNISTR2 structure.
+********************************************************************/
+UNISTR2 *unistr2_dup(const UNISTR2 *name)
+{
+ UNISTR2 *copy = (UNISTR2*)malloc(sizeof(*copy));
+ copy_unistr2(copy, name);
+ return copy;
+}
+
+/*******************************************************************
+frees a UNISTR2 structure.
+********************************************************************/
+void unistr2_free(UNISTR2 *name)
+{
+ free(name);
+}
+
+/*******************************************************************
creates a STRING2 structure.
********************************************************************/
BOOL make_string2(STRING2 *str, char *buf, int len)
diff --git a/source3/script/mkproto.awk b/source3/script/mkproto.awk
index c35883aec0..bc6f50af99 100644
--- a/source3/script/mkproto.awk
+++ b/source3/script/mkproto.awk
@@ -94,7 +94,7 @@ END {
gotstart = 1;
}
- if( $0 ~ /^LOCAL_GRP|^DOMAIN_GRP|^DOM_SID|^SEC_DESC/ ) {
+ if( $0 ~ /^UNISTR2|^LOCAL_GRP|^DOMAIN_GRP|^DOM_SID|^SEC_DESC/ ) {
gotstart = 1;
}