summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/talloc.c13
-rw-r--r--source3/lib/time.c22
-rw-r--r--source3/lib/util.c4
-rw-r--r--source3/lib/util_seaccess.c39
-rw-r--r--source3/lib/util_str.c14
-rw-r--r--source3/lib/util_unistr.c25
6 files changed, 105 insertions, 12 deletions
diff --git a/source3/lib/talloc.c b/source3/lib/talloc.c
index cafe065479..f5e21299b5 100644
--- a/source3/lib/talloc.c
+++ b/source3/lib/talloc.c
@@ -338,6 +338,19 @@ char *talloc_strdup(TALLOC_CTX *t, const char *p)
return NULL;
}
+/* strndup with a talloc */
+char *talloc_strndup(TALLOC_CTX *mem_ctx, const char *str, size_t maxlen)
+{
+ size_t len = strnlen(str, maxlen);
+ void *ret = TALLOC(mem_ctx, len+1);
+
+ if (ret != NULL) {
+ memcpy(ret, str, len);
+ ((char *)ret)[len] = '\0';
+ }
+ return ret;
+}
+
/** strdup_upper with a talloc */
char *talloc_strdup_upper(TALLOC_CTX *t, const char *p)
{
diff --git a/source3/lib/time.c b/source3/lib/time.c
index 84004a099b..9f94791b58 100644
--- a/source3/lib/time.c
+++ b/source3/lib/time.c
@@ -791,3 +791,25 @@ SMB_BIG_INT usec_time_diff(struct timeval *larget, struct timeval *smallt)
SMB_BIG_INT sec_diff = larget->tv_sec - smallt->tv_sec;
return (sec_diff * 1000000) + (SMB_BIG_INT)(larget->tv_usec - smallt->tv_usec);
}
+
+
+/****************************************************************************
+ convert ASN.1 GeneralizedTime string to unix-time
+ returns 0 on failure; Currently ignores timezone.
+****************************************************************************/
+time_t generalized_to_unix_time(const char *str)
+{
+ struct tm tm;
+
+ ZERO_STRUCT(tm);
+
+ if (sscanf(str, "%4d%2d%2d%2d%2d%2d",
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
+ &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
+ return 0;
+ }
+ tm.tm_year -= 1900;
+ tm.tm_mon -= 1;
+
+ return timegm(&tm);
+}
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 42ead313a9..8db7bb38ab 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -2172,8 +2172,12 @@ BOOL reg_split_key(const char *full_keyname, uint32 *reg_type, char *key_name)
if (strequal(tmp, "HKLM") || strequal(tmp, "HKEY_LOCAL_MACHINE"))
(*reg_type) = HKEY_LOCAL_MACHINE;
+ else if (strequal(tmp, "HKCR") || strequal(tmp, "HKEY_CLASSES_ROOT"))
+ (*reg_type) = HKEY_CLASSES_ROOT;
else if (strequal(tmp, "HKU") || strequal(tmp, "HKEY_USERS"))
(*reg_type) = HKEY_USERS;
+ else if (strequal(tmp, "HKPD")||strequal(tmp, "HKEY_PERFORMANCE_DATA"))
+ (*reg_type) = HKEY_PERFORMANCE_DATA;
else {
DEBUG(10,("reg_split_key: unrecognised hive key %s\n", tmp));
return False;
diff --git a/source3/lib/util_seaccess.c b/source3/lib/util_seaccess.c
index b5a9010b5c..cb0f46e2f9 100644
--- a/source3/lib/util_seaccess.c
+++ b/source3/lib/util_seaccess.c
@@ -316,3 +316,42 @@ BOOL se_access_check(const SEC_DESC *sd, const NT_USER_TOKEN *token,
return False;
}
+
+/*******************************************************************
+ samr_make_sam_obj_sd
+ ********************************************************************/
+
+NTSTATUS samr_make_sam_obj_sd(TALLOC_CTX *ctx, SEC_DESC **psd, size_t *sd_size)
+{
+ extern DOM_SID global_sid_World;
+ DOM_SID adm_sid;
+ DOM_SID act_sid;
+
+ SEC_ACE ace[3];
+ SEC_ACCESS mask;
+
+ SEC_ACL *psa = NULL;
+
+ sid_copy(&adm_sid, &global_sid_Builtin);
+ sid_append_rid(&adm_sid, BUILTIN_ALIAS_RID_ADMINS);
+
+ sid_copy(&act_sid, &global_sid_Builtin);
+ sid_append_rid(&act_sid, BUILTIN_ALIAS_RID_ACCOUNT_OPS);
+
+ /*basic access for every one*/
+ init_sec_access(&mask, GENERIC_RIGHTS_SAM_EXECUTE | GENERIC_RIGHTS_SAM_READ);
+ init_sec_ace(&ace[0], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
+
+ /*full access for builtin aliases Administrators and Account Operators*/
+ init_sec_access(&mask, GENERIC_RIGHTS_SAM_ALL_ACCESS);
+ init_sec_ace(&ace[1], &adm_sid, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
+ init_sec_ace(&ace[2], &act_sid, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
+
+ if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, 3, ace)) == NULL)
+ return NT_STATUS_NO_MEMORY;
+
+ if ((*psd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL, psa, sd_size)) == NULL)
+ return NT_STATUS_NO_MEMORY;
+
+ return NT_STATUS_OK;
+}
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 8acdab355a..b13ec1f0da 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -1695,6 +1695,20 @@ void str_list_free(char ***list)
}
/******************************************************************************
+ *****************************************************************************/
+
+int str_list_count( const char **list )
+{
+ int i = 0;
+
+ /* count the number of list members */
+
+ for ( i=0; *list; i++, list++ );
+
+ return i;
+}
+
+/******************************************************************************
version of standard_sub_basic() for string lists; uses alloc_sub_basic()
for the work
*****************************************************************************/
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index 55a21ebcbb..04985c6ab6 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -283,6 +283,19 @@ void unistr2_to_ascii(char *dest, const UNISTR2 *str, size_t maxlen)
}
/*******************************************************************
+ Convert a (little-endian) UNISTR3 structure to an ASCII string
+********************************************************************/
+void unistr3_to_ascii(char *dest, const UNISTR3 *str, size_t maxlen)
+{
+ if (str == NULL) {
+ *dest='\0';
+ return;
+ }
+ pull_ucs2(NULL, dest, str->str.buffer, maxlen, str->uni_str_len*2,
+ STR_NOALIGN);
+}
+
+/*******************************************************************
give a static string for displaying a UNISTR2
********************************************************************/
const char *unistr2_static(const UNISTR2 *str)
@@ -311,18 +324,6 @@ char *unistr2_tdup(TALLOC_CTX *ctx, const UNISTR2 *str)
/*******************************************************************
-Return a number stored in a buffer
-********************************************************************/
-
-uint32 buffer2_to_uint32(BUFFER2 *str)
-{
- if (str->buf_len == 4)
- return IVAL(str->buffer, 0);
- else
- return 0;
-}
-
-/*******************************************************************
Convert a wchar to upper case.
********************************************************************/