From 5d1cb8e79edea9e8581d3c2c9dd297310cd9a98c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 23 Mar 2005 23:26:33 +0000 Subject: r6014: rather large change set.... pulling back all recent rpc changes from trunk into 3.0. I've tested a compile and so don't think I've missed any files. But if so, just mail me and I'll clean backup in a couple of hours. Changes include \winreg, \eventlog, \svcctl, and general parse_misc.c updates. I am planning on bracketing the event code with an #ifdef ENABLE_EVENTLOG until I finish merging Marcin's changes (very soon). (This used to be commit 4e0ac63c36527cd8c52ef720cae17e84f67e7221) --- source3/lib/talloc.c | 13 +++++++++++++ source3/lib/time.c | 22 ++++++++++++++++++++++ source3/lib/util.c | 4 ++++ source3/lib/util_seaccess.c | 39 +++++++++++++++++++++++++++++++++++++++ source3/lib/util_str.c | 14 ++++++++++++++ source3/lib/util_unistr.c | 25 +++++++++++++------------ 6 files changed, 105 insertions(+), 12 deletions(-) (limited to 'source3/lib') 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 @@ -1694,6 +1694,20 @@ void str_list_free(char ***list) SAFE_FREE(*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 @@ -282,6 +282,19 @@ void unistr2_to_ascii(char *dest, const UNISTR2 *str, size_t maxlen) pull_ucs2(NULL, dest, str->buffer, maxlen, str->uni_str_len*2, STR_NOALIGN); } +/******************************************************************* + 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 ********************************************************************/ @@ -310,18 +323,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. ********************************************************************/ -- cgit