diff options
Diffstat (limited to 'source/lib')
-rw-r--r-- | source/lib/account_pol.c | 4 | ||||
-rw-r--r-- | source/lib/adt_tree.c | 79 | ||||
-rw-r--r-- | source/lib/afs.c | 4 | ||||
-rw-r--r-- | source/lib/interface.c | 7 | ||||
-rw-r--r-- | source/lib/privileges.c | 14 | ||||
-rw-r--r-- | source/lib/smbldap.c | 21 | ||||
-rw-r--r-- | source/lib/time.c | 544 | ||||
-rw-r--r-- | source/lib/util.c | 9 | ||||
-rw-r--r-- | source/lib/util_seaccess.c | 39 | ||||
-rw-r--r-- | source/lib/util_str.c | 4 | ||||
-rw-r--r-- | source/lib/util_unistr.c | 24 |
11 files changed, 381 insertions, 368 deletions
diff --git a/source/lib/account_pol.c b/source/lib/account_pol.c index 72d6e77ddda..5997d9180ae 100644 --- a/source/lib/account_pol.c +++ b/source/lib/account_pol.c @@ -118,8 +118,8 @@ static const struct { {AP_MIN_PASSWORD_LEN, "min password length"}, {AP_PASSWORD_HISTORY, "password history"}, {AP_USER_MUST_LOGON_TO_CHG_PASS, "user must logon to change password"}, - {AP_MAX_PASSWORD_AGE, "maximum password age"}, - {AP_MIN_PASSWORD_AGE,"minimum password age"}, + {AP_MAX_PASSWORD_AGE, "maximum password age (seconds since 1970)"}, + {AP_MIN_PASSWORD_AGE,"minimum password age (seconds since 1970)"}, {AP_LOCK_ACCOUNT_DURATION, "lockout duration"}, {AP_RESET_COUNT_TIME, "reset count minutes"}, {AP_BAD_ATTEMPT_LOCKOUT, "bad lockout attempt"}, diff --git a/source/lib/adt_tree.c b/source/lib/adt_tree.c index a5d6380377e..ad763c2be19 100644 --- a/source/lib/adt_tree.c +++ b/source/lib/adt_tree.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "adt_tree.h" /************************************************************************** @@ -53,7 +54,7 @@ static BOOL trim_tree_keypath( char *path, char **base, char **new_path ) for comparision of two children *************************************************************************/ -SORTED_TREE* sorted_tree_init( void *data_p, + SORTED_TREE* pathtree_init( void *data_p, int (cmp_fn)(void*, void*), void (free_fn)(void*) ) { @@ -83,7 +84,7 @@ SORTED_TREE* sorted_tree_init( void *data_p, Delete a tree and free all allocated memory *************************************************************************/ -static void sorted_tree_destroy_children( TREE_NODE *root ) +static void pathtree_destroy_children( TREE_NODE *root ) { int i; @@ -92,7 +93,7 @@ static void sorted_tree_destroy_children( TREE_NODE *root ) for ( i=0; i<root->num_children; i++ ) { - sorted_tree_destroy_children( root->children[i] ); + pathtree_destroy_children( root->children[i] ); } SAFE_FREE( root->children ); @@ -105,10 +106,10 @@ static void sorted_tree_destroy_children( TREE_NODE *root ) Delete a tree and free all allocated memory *************************************************************************/ -void sorted_tree_destroy( SORTED_TREE *tree ) + void pathtree_destroy( SORTED_TREE *tree ) { if ( tree->root ) - sorted_tree_destroy_children( tree->root ); + pathtree_destroy_children( tree->root ); if ( tree->free_func ) tree->free_func( tree->root ); @@ -120,7 +121,7 @@ void sorted_tree_destroy( SORTED_TREE *tree ) Find the next child given a key string *************************************************************************/ -static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) +static TREE_NODE* pathtree_birth_child( TREE_NODE *node, char* key ) { TREE_NODE *infant = NULL; TREE_NODE **siblings; @@ -144,7 +145,7 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) /* first child */ if ( node->num_children == 1 ) { - DEBUG(11,("sorted_tree_birth_child: First child of node [%s]! [%s]\n", + DEBUG(11,("pathtree_birth_child: First child of node [%s]! [%s]\n", node->key ? node->key : "NULL", infant->key )); node->children[0] = infant; } @@ -161,14 +162,14 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) for ( i = node->num_children-1; i>=1; i-- ) { - DEBUG(11,("sorted_tree_birth_child: Looking for crib; infant -> [%s], child -> [%s]\n", + DEBUG(11,("pathtree_birth_child: Looking for crib; infant -> [%s], child -> [%s]\n", infant->key, node->children[i-1]->key)); /* the strings should never match assuming that we - have called sorted_tree_find_child() first */ + have called pathtree_find_child() first */ if ( StrCaseCmp( infant->key, node->children[i-1]->key ) > 0 ) { - DEBUG(11,("sorted_tree_birth_child: storing infant in i == [%d]\n", + DEBUG(11,("pathtree_birth_child: storing infant in i == [%d]\n", i)); node->children[i] = infant; break; @@ -179,7 +180,7 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) node->children[i] = node->children[i-1]; } - DEBUG(11,("sorted_tree_birth_child: Exiting loop (i == [%d])\n", i )); + DEBUG(11,("pathtree_birth_child: Exiting loop (i == [%d])\n", i )); /* if we haven't found the correct slot yet, the child will be first in the list */ @@ -195,24 +196,24 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) Find the next child given a key string *************************************************************************/ -static TREE_NODE* sorted_tree_find_child( TREE_NODE *node, char* key ) +static TREE_NODE* pathtree_find_child( TREE_NODE *node, char* key ) { TREE_NODE *next = NULL; int i, result; if ( !node ) { - DEBUG(0,("sorted_tree_find_child: NULL node passed into function!\n")); + DEBUG(0,("pathtree_find_child: NULL node passed into function!\n")); return NULL; } if ( !key ) { - DEBUG(0,("sorted_tree_find_child: NULL key string passed into function!\n")); + DEBUG(0,("pathtree_find_child: NULL key string passed into function!\n")); return NULL; } for ( i=0; i<node->num_children; i++ ) { - DEBUG(11,("sorted_tree_find_child: child key => [%s]\n", + DEBUG(11,("pathtree_find_child: child key => [%s]\n", node->children[i]->key)); result = StrCaseCmp( node->children[i]->key, key ); @@ -228,7 +229,7 @@ static TREE_NODE* sorted_tree_find_child( TREE_NODE *node, char* key ) break; } - DEBUG(11,("sorted_tree_find_child: %s [%s]\n", + DEBUG(11,("pathtree_find_child: %s [%s]\n", next ? "Found" : "Did not find", key )); return next; @@ -238,22 +239,22 @@ static TREE_NODE* sorted_tree_find_child( TREE_NODE *node, char* key ) Add a new node into the tree given a key path and a blob of data *************************************************************************/ -BOOL sorted_tree_add( SORTED_TREE *tree, const char *path, void *data_p ) + BOOL pathtree_add( SORTED_TREE *tree, const char *path, void *data_p ) { char *str, *base, *path2; TREE_NODE *current, *next; BOOL ret = True; - DEBUG(8,("sorted_tree_add: Enter\n")); + DEBUG(8,("pathtree_add: Enter\n")); if ( !path || *path != '/' ) { - DEBUG(0,("sorted_tree_add: Attempt to add a node with a bad path [%s]\n", + DEBUG(0,("pathtree_add: Attempt to add a node with a bad path [%s]\n", path ? path : "NULL" )); return False; } if ( !tree ) { - DEBUG(0,("sorted_tree_add: Attempt to add a node to an uninitialized tree!\n")); + DEBUG(0,("pathtree_add: Attempt to add a node to an uninitialized tree!\n")); return False; } @@ -262,7 +263,7 @@ BOOL sorted_tree_add( SORTED_TREE *tree, const char *path, void *data_p ) path++; path2 = SMB_STRDUP( path ); if ( !path2 ) { - DEBUG(0,("sorted_tree_add: strdup() failed on string [%s]!?!?!\n", path)); + DEBUG(0,("pathtree_add: strdup() failed on string [%s]!?!?!\n", path)); return False; } @@ -286,11 +287,11 @@ BOOL sorted_tree_add( SORTED_TREE *tree, const char *path, void *data_p ) /* iterate to the next child--birth it if necessary */ - next = sorted_tree_find_child( current, base ); + next = pathtree_find_child( current, base ); if ( !next ) { - next = sorted_tree_birth_child( current, base ); + next = pathtree_birth_child( current, base ); if ( !next ) { - DEBUG(0,("sorted_tree_add: Failed to create new child!\n")); + DEBUG(0,("pathtree_add: Failed to create new child!\n")); ret = False; goto done; } @@ -310,10 +311,10 @@ BOOL sorted_tree_add( SORTED_TREE *tree, const char *path, void *data_p ) current->data_p = data_p; - DEBUG(10,("sorted_tree_add: Successfully added node [%s] to tree\n", + DEBUG(10,("pathtree_add: Successfully added node [%s] to tree\n", path )); - DEBUG(8,("sorted_tree_add: Exit\n")); + DEBUG(8,("pathtree_add: Exit\n")); done: SAFE_FREE( path2 ); @@ -325,7 +326,7 @@ done: Recursive routine to print out all children of a TREE_NODE *************************************************************************/ -static void sorted_tree_print_children( TREE_NODE *node, int debug, const char *path ) +static void pathtree_print_children( TREE_NODE *node, int debug, const char *path ) { int i; int num_children; @@ -347,7 +348,7 @@ static void sorted_tree_print_children( TREE_NODE *node, int debug, const char * num_children = node->num_children; for ( i=0; i<num_children; i++ ) - sorted_tree_print_children( node->children[i], debug, path2 ); + pathtree_print_children( node->children[i], debug, path2 ); } @@ -356,7 +357,7 @@ static void sorted_tree_print_children( TREE_NODE *node, int debug, const char * Dump the kys for a tree to the log file *************************************************************************/ -void sorted_tree_print_keys( SORTED_TREE *tree, int debug ) + void pathtree_print_keys( SORTED_TREE *tree, int debug ) { int i; int num_children = tree->root->num_children; @@ -366,7 +367,7 @@ void sorted_tree_print_keys( SORTED_TREE *tree, int debug ) tree->root->data_p ? "data" : "NULL" )); for ( i=0; i<num_children; i++ ) { - sorted_tree_print_children( tree->root->children[i], debug, + pathtree_print_children( tree->root->children[i], debug, tree->root->key ? tree->root->key : "ROOT/" ); } @@ -378,23 +379,23 @@ void sorted_tree_print_keys( SORTED_TREE *tree, int debug ) the tree *************************************************************************/ -void* sorted_tree_find( SORTED_TREE *tree, char *key ) + void* pathtree_find( SORTED_TREE *tree, char *key ) { char *keystr, *base, *str, *p; TREE_NODE *current; void *result = NULL; - DEBUG(10,("sorted_tree_find: Enter [%s]\n", key ? key : "NULL" )); + DEBUG(10,("pathtree_find: Enter [%s]\n", key ? key : "NULL" )); /* sanity checks first */ if ( !key ) { - DEBUG(0,("sorted_tree_find: Attempt to search tree using NULL search string!\n")); + DEBUG(0,("pathtree_find: Attempt to search tree using NULL search string!\n")); return NULL; } if ( !tree ) { - DEBUG(0,("sorted_tree_find: Attempt to search an uninitialized tree using string [%s]!\n", + DEBUG(0,("pathtree_find: Attempt to search an uninitialized tree using string [%s]!\n", key ? key : "NULL" )); return NULL; } @@ -410,7 +411,7 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) keystr = SMB_STRDUP( key ); if ( !keystr ) { - DEBUG(0,("sorted_tree_find: strdup() failed on string [%s]!?!?!\n", key)); + DEBUG(0,("pathtree_find: strdup() failed on string [%s]!?!?!\n", key)); return NULL; } @@ -428,12 +429,12 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) trim_tree_keypath( p, &base, &str ); - DEBUG(11,("sorted_tree_find: [loop] base => [%s], new_path => [%s]\n", + DEBUG(11,("pathtree_find: [loop] base => [%s], new_path => [%s]\n", base, str)); /* iterate to the next child */ - current = sorted_tree_find_child( current, base ); + current = pathtree_find_child( current, base ); /* * the idea is that the data_p for a parent should @@ -452,11 +453,11 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) /* result should be the data_p from the lowest match node in the tree */ if ( result ) - DEBUG(11,("sorted_tree_find: Found data_p!\n")); + DEBUG(11,("pathtree_find: Found data_p!\n")); SAFE_FREE( keystr ); - DEBUG(10,("sorted_tree_find: Exit\n")); + DEBUG(10,("pathtree_find: Exit\n")); return result; } diff --git a/source/lib/afs.c b/source/lib/afs.c index 5ff027ee01d..7f79429b9ed 100644 --- a/source/lib/afs.c +++ b/source/lib/afs.c @@ -214,12 +214,16 @@ BOOL afs_login(connection_struct *conn) char *cell; BOOL result; char *ticket_str; + DOM_SID user_sid; struct ClearToken ct; pstrcpy(afs_username, lp_afs_username_map()); standard_sub_conn(conn, afs_username, sizeof(afs_username)); + if (NT_STATUS_IS_OK(uid_to_sid(&user_sid, conn->uid))) + pstring_sub(afs_username, "%s", sid_string_static(&user_sid)); + /* The pts command always generates completely lower-case user * names. */ strlower_m(afs_username); diff --git a/source/lib/interface.c b/source/lib/interface.c index 8cf11b85039..2bd7d6ddbe0 100644 --- a/source/lib/interface.c +++ b/source/lib/interface.c @@ -60,10 +60,12 @@ static void add_interface(struct in_addr ip, struct in_addr nmask) return; } +#if !defined(__s390__) if (ip_equal(nmask, allones_ip)) { DEBUG(3,("not adding non-broadcast interface %s\n",inet_ntoa(ip))); return; } +#endif iface = SMB_MALLOC_P(struct interface); if (!iface) return; @@ -196,7 +198,10 @@ void load_interfaces(void) exit(1); } for (i=0;i<total_probed;i++) { - if (probed_ifaces[i].netmask.s_addr != allones_ip.s_addr && + if ( +#if !defined(__s390__) + probed_ifaces[i].netmask.s_addr != allones_ip.s_addr && +#endif probed_ifaces[i].ip.s_addr != loopback_ip.s_addr) { add_interface(probed_ifaces[i].ip, probed_ifaces[i].netmask); diff --git a/source/lib/privileges.c b/source/lib/privileges.c index 3960faecaa9..5a5afa4d72c 100644 --- a/source/lib/privileges.c +++ b/source/lib/privileges.c @@ -1,7 +1,7 @@ /* Unix SMB/CIFS implementation. Privileges handling functions - Copyright (C) Jean François Micouleau 1998-2001 + Copyright (C) Jean François Micouleau 1998-2001 Copyright (C) Simo Sorce 2002-2003 Copyright (C) Gerald (Jerry) Carter 2004 @@ -27,8 +27,8 @@ #define GENERATE_LUID_LOW(x) (x)+1; -static SE_PRIV se_priv_all = SE_ALL_PRIVS; -static SE_PRIV se_priv_end = SE_END; +static const SE_PRIV se_priv_all = SE_ALL_PRIVS; +static const SE_PRIV se_priv_end = SE_END; /* Define variables for all privileges so we can use the SE_PRIV* in the various se_priv_XXX() functions */ @@ -230,8 +230,8 @@ static BOOL get_privileges( const DOM_SID *sid, SE_PRIV *mask ) SMB_ASSERT( data.dsize == sizeof( SE_PRIV ) ); se_priv_copy( mask, (SE_PRIV*)data.dptr ); - - + SAFE_FREE(data.dptr); + return True; } @@ -503,7 +503,7 @@ NTSTATUS privilege_enumerate_accounts(DOM_SID **sids, int *num_sids) Add privilege to sid ****************************************************************************/ -BOOL grant_privilege(const DOM_SID *sid, SE_PRIV *priv_mask) +BOOL grant_privilege(const DOM_SID *sid, const SE_PRIV *priv_mask) { SE_PRIV old_mask, new_mask; @@ -548,7 +548,7 @@ BOOL grant_privilege_by_name(DOM_SID *sid, const char *name) Remove privilege from sid ****************************************************************************/ -BOOL revoke_privilege(const DOM_SID *sid, SE_PRIV *priv_mask) +BOOL revoke_privilege(const DOM_SID *sid, const SE_PRIV *priv_mask) { SE_PRIV mask; diff --git a/source/lib/smbldap.c b/source/lib/smbldap.c index 7aeecb89d6f..fec6cc23a89 100644 --- a/source/lib/smbldap.c +++ b/source/lib/smbldap.c @@ -230,16 +230,16 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { Return the list of attribute names from a mapping table **********************************************************************/ - char** get_attr_list( ATTRIB_MAP_ENTRY table[] ) + const char** get_attr_list( ATTRIB_MAP_ENTRY table[] ) { - char **names; + const char **names; int i = 0; while ( table[i].attrib != LDAP_ATTR_LIST_END ) i++; i++; - names = SMB_MALLOC_ARRAY( char*, i ); + names = SMB_MALLOC_ARRAY( const char*, i ); if ( !names ) { DEBUG(0,("get_attr_list: out of memory\n")); return NULL; @@ -259,7 +259,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { Cleanup ********************************************************************/ - void free_attr_list( char **list ) + void free_attr_list( const char **list ) { int i = 0; @@ -888,7 +888,7 @@ static int smbldap_open(struct smbldap_state *ldap_state) socklen_t len = sizeof(addr); int sd; if (ldap_get_option(ldap_state->ldap_struct, LDAP_OPT_DESC, &sd) == 0 && - getpeername(sd, (struct sockaddr *) &addr, &len) < 0) { + ((getpeername(sd, (struct sockaddr *) &addr, &len) < 0) || addr.sun_family == AF_LOCAL)) { /* the other end has died. reopen. */ ldap_unbind_ext(ldap_state->ldap_struct, NULL, NULL); ldap_state->ldap_struct = NULL; @@ -962,8 +962,6 @@ static int another_ldap_try(struct smbldap_state *ldap_state, int *rc, if (*rc != LDAP_SERVER_DOWN) goto no_next; - now = time(NULL); - if (now >= endtime) { smbldap_close(ldap_state); *rc = LDAP_TIMEOUT; @@ -986,7 +984,6 @@ static int another_ldap_try(struct smbldap_state *ldap_state, int *rc, *attempts += 1; - smbldap_close(ldap_state); open_rc = smbldap_open(ldap_state); if (open_rc == LDAP_SUCCESS) { @@ -1017,7 +1014,7 @@ static int another_ldap_try(struct smbldap_state *ldap_state, int *rc, int smbldap_search(struct smbldap_state *ldap_state, const char *base, int scope, const char *filter, - char *attrs[], int attrsonly, + const char *attrs[], int attrsonly, LDAPMessage **res) { int rc = LDAP_SERVER_DOWN; @@ -1154,7 +1151,7 @@ int smbldap_extended_operation(struct smbldap_state *ldap_state, run the search by name. ******************************************************************/ int smbldap_search_suffix (struct smbldap_state *ldap_state, const char *filter, - char **search_attr, LDAPMessage ** result) + const char **search_attr, LDAPMessage ** result) { int scope = LDAP_SCOPE_SUBTREE; int rc; @@ -1261,7 +1258,7 @@ static NTSTATUS add_new_domain_info(struct smbldap_state *ldap_state, int ldap_op; LDAPMessage *result = NULL; int num_result; - char **attr_list; + const char **attr_list; uid_t u_low, u_high; gid_t g_low, g_high; uint32 rid_low, rid_high; @@ -1376,7 +1373,7 @@ NTSTATUS smbldap_search_domain_info(struct smbldap_state *ldap_state, NTSTATUS ret = NT_STATUS_UNSUCCESSFUL; pstring filter; int rc; - char **attr_list; + const char **attr_list; int count; pstr_sprintf(filter, "(&(objectClass=%s)(%s=%s))", diff --git a/source/lib/time.c b/source/lib/time.c index e7b537151ff..84004a099be 100644 --- a/source/lib/time.c +++ b/source/lib/time.c @@ -56,8 +56,9 @@ time_t get_time_t_max(void) } /******************************************************************* -a gettimeofday wrapper + A gettimeofday wrapper. ********************************************************************/ + void GetTimeOfDay(struct timeval *tval) { #ifdef HAVE_GETTIMEOFDAY_TZ @@ -70,43 +71,45 @@ void GetTimeOfDay(struct timeval *tval) #define TM_YEAR_BASE 1900 /******************************************************************* -yield the difference between *A and *B, in seconds, ignoring leap seconds + Yield the difference between *A and *B, in seconds, ignoring leap seconds. ********************************************************************/ + static int tm_diff(struct tm *a, struct tm *b) { - int ay = a->tm_year + (TM_YEAR_BASE - 1); - int by = b->tm_year + (TM_YEAR_BASE - 1); - int intervening_leap_days = - (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); - int years = ay - by; - int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); - int hours = 24*days + (a->tm_hour - b->tm_hour); - int minutes = 60*hours + (a->tm_min - b->tm_min); - int seconds = 60*minutes + (a->tm_sec - b->tm_sec); + int ay = a->tm_year + (TM_YEAR_BASE - 1); + int by = b->tm_year + (TM_YEAR_BASE - 1); + int intervening_leap_days = (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); + int years = ay - by; + int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); + int hours = 24*days + (a->tm_hour - b->tm_hour); + int minutes = 60*hours + (a->tm_min - b->tm_min); + int seconds = 60*minutes + (a->tm_sec - b->tm_sec); - return seconds; + return seconds; } /******************************************************************* - return the UTC offset in seconds west of UTC, or 0 if it cannot be determined - ******************************************************************/ + Return the UTC offset in seconds west of UTC, or 0 if it cannot be determined. +******************************************************************/ + static int TimeZone(time_t t) { - struct tm *tm = gmtime(&t); - struct tm tm_utc; - if (!tm) - return 0; - tm_utc = *tm; - tm = localtime(&t); - if (!tm) - return 0; - return tm_diff(&tm_utc,tm); - + struct tm *tm = gmtime(&t); + struct tm tm_utc; + if (!tm) + return 0; + tm_utc = *tm; + tm = localtime(&t); + if (!tm) + return 0; + return tm_diff(&tm_utc,tm); } static BOOL done_serverzone_init; -/* Return the smb serverzone value */ +/******************************************************************* + Return the smb serverzone value. +******************************************************************/ static int get_serverzone(void) { @@ -127,7 +130,9 @@ static int get_serverzone(void) return serverzone; } -/* Re-read the smb serverzone value */ +/******************************************************************* + Re-read the smb serverzone value. +******************************************************************/ static struct timeval start_time_hires; @@ -161,175 +166,182 @@ void get_process_uptime(struct timeval *ret_time) } /******************************************************************* -return the same value as TimeZone, but it should be more efficient. + Return the same value as TimeZone, but it should be more efficient. -We keep a table of DST offsets to prevent calling localtime() on each -call of this function. This saves a LOT of time on many unixes. + We keep a table of DST offsets to prevent calling localtime() on each + call of this function. This saves a LOT of time on many unixes. -Updated by Paul Eggert <eggert@twinsun.com> + Updated by Paul Eggert <eggert@twinsun.com> ********************************************************************/ + static int TimeZoneFaster(time_t t) { - static struct dst_table {time_t start,end; int zone;} *tdt, *dst_table = NULL; - static int table_size = 0; - int i; - int zone = 0; + static struct dst_table {time_t start,end; int zone;} *tdt, *dst_table = NULL; + static int table_size = 0; + int i; + int zone = 0; - if (t == 0) t = time(NULL); + if (t == 0) + t = time(NULL); - /* Tunis has a 8 day DST region, we need to be careful ... */ + /* Tunis has a 8 day DST region, we need to be careful ... */ #define MAX_DST_WIDTH (365*24*60*60) #define MAX_DST_SKIP (7*24*60*60) - for (i=0;i<table_size;i++) - if (t >= dst_table[i].start && t <= dst_table[i].end) break; - - if (i<table_size) { - zone = dst_table[i].zone; - } else { - time_t low,high; - - zone = TimeZone(t); - tdt = SMB_REALLOC_ARRAY(dst_table, struct dst_table, i+1); - if (!tdt) { - DEBUG(0,("TimeZoneFaster: out of memory!\n")); - SAFE_FREE(dst_table); - table_size = 0; - } else { - dst_table = tdt; - table_size++; - - dst_table[i].zone = zone; - dst_table[i].start = dst_table[i].end = t; + for (i=0;i<table_size;i++) + if (t >= dst_table[i].start && t <= dst_table[i].end) + break; + + if (i<table_size) { + zone = dst_table[i].zone; + } else { + time_t low,high; + + zone = TimeZone(t); + tdt = SMB_REALLOC_ARRAY(dst_table, struct dst_table, i+1); + if (!tdt) { + DEBUG(0,("TimeZoneFaster: out of memory!\n")); + SAFE_FREE(dst_table); + table_size = 0; + } else { + dst_table = tdt; + table_size++; + + dst_table[i].zone = zone; + dst_table[i].start = dst_table[i].end = t; - /* no entry will cover more than 6 months */ - low = t - MAX_DST_WIDTH/2; - if (t < low) - low = TIME_T_MIN; + /* no entry will cover more than 6 months */ + low = t - MAX_DST_WIDTH/2; + if (t < low) + low = TIME_T_MIN; - high = t + MAX_DST_WIDTH/2; - if (high < t) - high = TIME_T_MAX; + high = t + MAX_DST_WIDTH/2; + if (high < t) + high = TIME_T_MAX; - /* widen the new entry using two bisection searches */ - while (low+60*60 < dst_table[i].start) { - if (dst_table[i].start - low > MAX_DST_SKIP*2) - t = dst_table[i].start - MAX_DST_SKIP; - else - t = low + (dst_table[i].start-low)/2; - if (TimeZone(t) == zone) - dst_table[i].start = t; - else - low = t; - } - - while (high-60*60 > dst_table[i].end) { - if (high - dst_table[i].end > MAX_DST_SKIP*2) - t = dst_table[i].end + MAX_DST_SKIP; - else - t = high - (high-dst_table[i].end)/2; - if (TimeZone(t) == zone) - dst_table[i].end = t; - else - high = t; - } + /* widen the new entry using two bisection searches */ + while (low+60*60 < dst_table[i].start) { + if (dst_table[i].start - low > MAX_DST_SKIP*2) + t = dst_table[i].start - MAX_DST_SKIP; + else + t = low + (dst_table[i].start-low)/2; + if (TimeZone(t) == zone) + dst_table[i].start = t; + else + low = t; + } + + while (high-60*60 > dst_table[i].end) { + if (high - dst_table[i].end > MAX_DST_SKIP*2) + t = dst_table[i].end + MAX_DST_SKIP; + else + t = high - (high-dst_table[i].end)/2; + if (TimeZone(t) == zone) + dst_table[i].end = t; + else + high = t; + } #if 0 DEBUG(1,("Added DST entry from %s ", asctime(localtime(&dst_table[i].start)))); DEBUG(1,("to %s (%d)\n",asctime(localtime(&dst_table[i].end)), dst_table[i].zone)); #endif - } - } - return zone; + } + } + return zone; } /**************************************************************************** - return the UTC offset in seconds west of UTC, adjusted for extra time offset - **************************************************************************/ + Return the UTC offset in seconds west of UTC, adjusted for extra time offset. +**************************************************************************/ + int TimeDiff(time_t t) { - return TimeZoneFaster(t) + 60*extra_time_offset; + return TimeZoneFaster(t) + 60*extra_time_offset; } - /**************************************************************************** - return the UTC offset in seconds west of UTC, adjusted for extra time - offset, for a local time value. If ut = lt + LocTimeDiff(lt), then - lt = ut - TimeDiff(ut), but the converse does not necessarily hold near - daylight savings transitions because some local times are ambiguous. - LocTimeDiff(t) equals TimeDiff(t) except near daylight savings transitions. - +**************************************************************************/ + Return the UTC offset in seconds west of UTC, adjusted for extra time + offset, for a local time value. If ut = lt + LocTimeDiff(lt), then + lt = ut - TimeDiff(ut), but the converse does not necessarily hold near + daylight savings transitions because some local times are ambiguous. + LocTimeDiff(t) equals TimeDiff(t) except near daylight savings transitions. +**************************************************************************/ + static int LocTimeDiff(time_t lte) { - time_t lt = lte - 60*extra_time_offset; - int d = TimeZoneFaster(lt); - time_t t = lt + d; + time_t lt = lte - 60*extra_time_offset; + int d = TimeZoneFaster(lt); + time_t t = lt + d; - /* if overflow occurred, ignore all the adjustments so far */ - if (((lte < lt) ^ (extra_time_offset < 0)) | ((t < lt) ^ (d < 0))) - t = lte; + /* if overflow occurred, ignore all the adjustments so far */ + if (((lte < lt) ^ (extra_time_offset < 0)) | ((t < lt) ^ (d < 0))) + t = lte; - /* now t should be close enough to the true UTC to yield the right answer */ - return TimeDiff(t); + /* now t should be close enough to the true UTC to yield the right answer */ + return TimeDiff(t); } - /**************************************************************************** -try to optimise the localtime call, it can be quite expensive on some machines + Try to optimise the localtime call, it can be quite expensive on some machines. ****************************************************************************/ + struct tm *LocalTime(time_t *t) { - time_t t2 = *t; + time_t t2 = *t; - t2 -= TimeDiff(t2); + t2 -= TimeDiff(t2); - return(gmtime(&t2)); + return(gmtime(&t2)); } #define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)) /**************************************************************************** -interpret an 8 byte "filetime" structure to a time_t -It's originally in "100ns units since jan 1st 1601" + Interpret an 8 byte "filetime" structure to a time_t + It's originally in "100ns units since jan 1st 1601" + + An 8 byte value of 0xffffffffffffffff will be returned as (time_t)0. -It appears to be kludge-GMT (at least for file listings). This means -its the GMT you get by taking a localtime and adding the -serverzone. This is NOT the same as GMT in some cases. This routine -converts this to real GMT. + It appears to be kludge-GMT (at least for file listings). This means + its the GMT you get by taking a localtime and adding the + serverzone. This is NOT the same as GMT in some cases. This routine + converts this to real GMT. ****************************************************************************/ + time_t nt_time_to_unix(NTTIME *nt) { - double d; - time_t ret; - /* The next two lines are a fix needed for the - broken SCO compiler. JRA. */ - time_t l_time_min = TIME_T_MIN; - time_t l_time_max = TIME_T_MAX; + double d; + time_t ret; + /* The next two lines are a fix needed for the + broken SCO compiler. JRA. */ + time_t l_time_min = TIME_T_MIN; + time_t l_time_max = TIME_T_MAX; - if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff)) - return(0); + if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff)) + return(0); - d = ((double)nt->high)*4.0*(double)(1<<30); - d += (nt->low&0xFFF00000); - d *= 1.0e-7; + d = ((double)nt->high)*4.0*(double)(1<<30); + d += (nt->low&0xFFF00000); + d *= 1.0e-7; - /* now adjust by 369 years to make the secs since 1970 */ - d -= TIME_FIXUP_CONSTANT; + /* now adjust by 369 years to make the secs since 1970 */ + d -= TIME_FIXUP_CONSTANT; - if (d <= l_time_min) - return (l_time_min); + if (d <= l_time_min) + return (l_time_min); - if (d >= l_time_max) - return (l_time_max); + if (d >= l_time_max) + return (l_time_max); - ret = (time_t)(d+0.5); + ret = (time_t)(d+0.5); - /* this takes us from kludge-GMT to real GMT */ - ret -= get_serverzone(); - ret += LocTimeDiff(ret); + /* this takes us from kludge-GMT to real GMT */ + ret -= get_serverzone(); + ret += LocTimeDiff(ret); - return(ret); + return(ret); } /**************************************************************************** @@ -374,38 +386,42 @@ time_t nt_time_to_unix_abs(NTTIME *nt) } /**************************************************************************** -interprets an nt time into a unix time_t + Interprets an nt time into a unix time_t. + Differs from nt_time_to_unix in that an 8 byte value of 0xffffffffffffffff + will be returned as (time_t)-1, whereas nt_time_to_unix returns 0 in this case. ****************************************************************************/ + time_t interpret_long_date(char *p) { NTTIME nt; nt.low = IVAL(p,0); nt.high = IVAL(p,4); + if (nt.low == 0xFFFFFFFF && nt.high == 0xFFFFFFFF) { + return (time_t)-1; + } return nt_time_to_unix(&nt); } /**************************************************************************** -put a 8 byte filetime from a time_t -This takes real GMT as input and converts to kludge-GMT + Put a 8 byte filetime from a time_t + This takes real GMT as input and converts to kludge-GMT ****************************************************************************/ + void unix_to_nt_time(NTTIME *nt, time_t t) { double d; - if (t==0) - { + if (t==0) { nt->low = 0; nt->high = 0; return; } - if (t == TIME_T_MAX) - { + if (t == TIME_T_MAX) { nt->low = 0xffffffff; nt->high = 0x7fffffff; return; } - if (t == -1) - { + if (t == -1) { nt->low = 0xffffffff; nt->high = 0xffffffff; return; @@ -465,9 +481,10 @@ void unix_to_nt_time_abs(NTTIME *nt, time_t t) } /**************************************************************************** -take a Unix time and convert to an NTTIME structure and place in buffer -pointed to by p. + Take a Unix time and convert to an NTTIME structure and place in buffer + pointed to by p. ****************************************************************************/ + void put_long_date(char *p,time_t t) { NTTIME nt; @@ -477,181 +494,191 @@ void put_long_date(char *p,time_t t) } /**************************************************************************** -check if it's a null mtime + Check if it's a null mtime. ****************************************************************************/ + BOOL null_mtime(time_t mtime) { - if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1) - return(True); - return(False); + if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1) + return(True); + return(False); } /******************************************************************* - create a 16 bit dos packed date + Create a 16 bit dos packed date. ********************************************************************/ + static uint16 make_dos_date1(struct tm *t) { - uint16 ret=0; - ret = (((unsigned)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1); - ret = ((ret&0xFF)<<8) | (t->tm_mday | (((t->tm_mon+1) & 0x7) << 5)); - return(ret); + uint16 ret=0; + ret = (((unsigned)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1); + ret = ((ret&0xFF)<<8) | (t->tm_mday | (((t->tm_mon+1) & 0x7) << 5)); + return(ret); } /******************************************************************* - create a 16 bit dos packed time + Create a 16 bit dos packed time. ********************************************************************/ + static uint16 make_dos_time1(struct tm *t) { - uint16 ret=0; - ret = ((((unsigned)t->tm_min >> 3)&0x7) | (((unsigned)t->tm_hour) << 3)); - ret = ((ret&0xFF)<<8) | ((t->tm_sec/2) | ((t->tm_min & 0x7) << 5)); - return(ret); + uint16 ret=0; + ret = ((((unsigned)t->tm_min >> 3)&0x7) | (((unsigned)t->tm_hour) << 3)); + ret = ((ret&0xFF)<<8) | ((t->tm_sec/2) | ((t->tm_min & 0x7) << 5)); + return(ret); } /******************************************************************* - create a 32 bit dos packed date/time from some parameters - This takes a GMT time and returns a packed localtime structure + Create a 32 bit dos packed date/time from some parameters. + This takes a GMT time and returns a packed localtime structure. ********************************************************************/ + static uint32 make_dos_date(time_t unixdate) { - struct tm *t; - uint32 ret=0; + struct tm *t; + uint32 ret=0; - t = LocalTime(&unixdate); - if (!t) - return 0xFFFFFFFF; + t = LocalTime(&unixdate); + if (!t) + return 0xFFFFFFFF; - ret = make_dos_date1(t); - ret = ((ret&0xFFFF)<<16) | make_dos_time1(t); + ret = make_dos_date1(t); + ret = ((ret&0xFFFF)<<16) | make_dos_time1(t); - return(ret); + return(ret); } /******************************************************************* -put a dos date into a buffer (time/date format) -This takes GMT time and puts local time in the buffer + Put a dos date into a buffer (time/date format). + This takes GMT time and puts local time in the buffer. ********************************************************************/ + void put_dos_date(char *buf,int offset,time_t unixdate) { - uint32 x = make_dos_date(unixdate); - SIVAL(buf,offset,x); + uint32 x = make_dos_date(unixdate); + SIVAL(buf,offset,x); } /******************************************************************* -put a dos date into a buffer (date/time format) -This takes GMT time and puts local time in the buffer + Put a dos date into a buffer (date/time format). + This takes GMT time and puts local time in the buffer. ********************************************************************/ + void put_dos_date2(char *buf,int offset,time_t unixdate) { - uint32 x = make_dos_date(unixdate); - x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); - SIVAL(buf,offset,x); + uint32 x = make_dos_date(unixdate); + x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); + SIVAL(buf,offset,x); } /******************************************************************* -put a dos 32 bit "unix like" date into a buffer. This routine takes -GMT and converts it to LOCAL time before putting it (most SMBs assume -localtime for this sort of date) + Put a dos 32 bit "unix like" date into a buffer. This routine takes + GMT and converts it to LOCAL time before putting it (most SMBs assume + localtime for this sort of date) ********************************************************************/ + void put_dos_date3(char *buf,int offset,time_t unixdate) { - if (!null_mtime(unixdate)) - unixdate -= TimeDiff(unixdate); - SIVAL(buf,offset,unixdate); + if (!null_mtime(unixdate)) + unixdate -= TimeDiff(unixdate); + SIVAL(buf,offset,unixdate); } /******************************************************************* - interpret a 32 bit dos packed date/time to some parameters + Interpret a 32 bit dos packed date/time to some parameters. ********************************************************************/ + static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *hour,int *minute,int *second) { - uint32 p0,p1,p2,p3; + uint32 p0,p1,p2,p3; - p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF; - p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF; + p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF; + p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF; - *second = 2*(p0 & 0x1F); - *minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3); - *hour = (p1>>3)&0xFF; - *day = (p2&0x1F); - *month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1; - *year = ((p3>>1)&0xFF) + 80; + *second = 2*(p0 & 0x1F); + *minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3); + *hour = (p1>>3)&0xFF; + *day = (p2&0x1F); + *month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1; + *year = ((p3>>1)&0xFF) + 80; } /******************************************************************* - create a unix date (int GMT) from a dos date (which is actually in - localtime) + Create a unix date (int GMT) from a dos date (which is actually in + localtime). ********************************************************************/ + time_t make_unix_date(void *date_ptr) { - uint32 dos_date=0; - struct tm t; - time_t ret; + uint32 dos_date=0; + struct tm t; + time_t ret; - dos_date = IVAL(date_ptr,0); + dos_date = IVAL(date_ptr,0); - if (dos_date == 0) return(0); + if (dos_date == 0) + return(0); - interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon, - &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); - t.tm_isdst = -1; + interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon, + &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); + t.tm_isdst = -1; - /* mktime() also does the local to GMT time conversion for us */ - ret = mktime(&t); + /* mktime() also does the local to GMT time conversion for us */ + ret = mktime(&t); - return(ret); + return(ret); } /******************************************************************* -like make_unix_date() but the words are reversed + Like make_unix_date() but the words are reversed. ********************************************************************/ + time_t make_unix_date2(void *date_ptr) { - uint32 x,x2; + uint32 x,x2; - x = IVAL(date_ptr,0); - x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); - SIVAL(&x,0,x2); + x = IVAL(date_ptr,0); + x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); + SIVAL(&x,0,x2); - return(make_unix_date((void *)&x)); + return(make_unix_date((void *)&x)); } /******************************************************************* - create a unix GMT date from a dos date in 32 bit "unix like" format - these generally arrive as localtimes, with corresponding DST - ******************************************************************/ + Create a unix GMT date from a dos date in 32 bit "unix like" format + these generally arrive as localtimes, with corresponding DST. +******************************************************************/ + time_t make_unix_date3(void *date_ptr) { - time_t t = (time_t)IVAL(date_ptr,0); - if (!null_mtime(t)) - t += LocTimeDiff(t); - return(t); + time_t t = (time_t)IVAL(date_ptr,0); + if (!null_mtime(t)) + t += LocTimeDiff(t); + return(t); } - /*************************************************************************** -return a HTTP/1.0 time string - ***************************************************************************/ + Return a HTTP/1.0 time string. +***************************************************************************/ + char *http_timestring(time_t t) { - static fstring buf; - struct tm *tm = LocalTime(&t); + static fstring buf; + struct tm *tm = LocalTime(&t); - if (!tm) - slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t); - else + if (!tm) + slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t); + else #ifndef HAVE_STRFTIME - fstrcpy(buf, asctime(tm)); - if(buf[strlen(buf)-1] == '\n') - buf[strlen(buf)-1] = 0; + fstrcpy(buf, asctime(tm)); + if(buf[strlen(buf)-1] == '\n') + buf[strlen(buf)-1] = 0; #else /* !HAVE_STRFTIME */ - strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); + strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); #endif /* !HAVE_STRFTIME */ - return buf; + return buf; } - - /**************************************************************************** Return the date and time as a string ****************************************************************************/ @@ -710,32 +737,32 @@ char *timestring(BOOL hires) } /**************************************************************************** - return the best approximation to a 'create time' under UNIX from a stat - structure. + Return the best approximation to a 'create time' under UNIX from a stat + structure. ****************************************************************************/ time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs) { - time_t ret, ret1; + time_t ret, ret1; - if(S_ISDIR(st->st_mode) && fake_dirs) - return (time_t)315493200L; /* 1/1/1980 */ + if(S_ISDIR(st->st_mode) && fake_dirs) + return (time_t)315493200L; /* 1/1/1980 */ - ret = MIN(st->st_ctime, st->st_mtime); - ret1 = MIN(ret, st->st_atime); + ret = MIN(st->st_ctime, st->st_mtime); + ret1 = MIN(ret, st->st_atime); - if(ret1 != (time_t)0) - return ret1; + if(ret1 != (time_t)0) + return ret1; - /* - * One of ctime, mtime or atime was zero (probably atime). - * Just return MIN(ctime, mtime). - */ - return ret; + /* + * One of ctime, mtime or atime was zero (probably atime). + * Just return MIN(ctime, mtime). + */ + return ret; } /**************************************************************************** -initialise an NTTIME to -1, which means "unknown" or "don't expire" + Initialise an NTTIME to -1, which means "unknown" or "don't expire". ****************************************************************************/ void init_nt_time(NTTIME *nt) @@ -745,8 +772,9 @@ void init_nt_time(NTTIME *nt) } /**************************************************************************** -check if NTTIME is 0 + Check if NTTIME is 0. ****************************************************************************/ + BOOL nt_time_is_zero(NTTIME *nt) { if(nt->high==0) @@ -754,6 +782,10 @@ BOOL nt_time_is_zero(NTTIME *nt) return False; } +/**************************************************************************** + Return a timeval difference in usec. +****************************************************************************/ + SMB_BIG_INT usec_time_diff(struct timeval *larget, struct timeval *smallt) { SMB_BIG_INT sec_diff = larget->tv_sec - smallt->tv_sec; diff --git a/source/lib/util.c b/source/lib/util.c index 455f87aaab8..42ead313a92 100644 --- a/source/lib/util.c +++ b/source/lib/util.c @@ -617,7 +617,7 @@ void unix_clean_name(char *s) Make a dir struct. ****************************************************************************/ -void make_dir_struct(char *buf, const char *mask, const char *fname,SMB_OFF_T size,int mode,time_t date, BOOL case_sensitive) +void make_dir_struct(char *buf, const char *mask, const char *fname,SMB_OFF_T size,int mode,time_t date) { char *p; pstring mask2; @@ -641,7 +641,7 @@ void make_dir_struct(char *buf, const char *mask, const char *fname,SMB_OFF_T si put_dos_date(buf,22,date); SSVAL(buf,26,size & 0xFFFF); SSVAL(buf,28,(size >> 16)&0xFFFF); - push_ascii(buf+30,fname,12, case_sensitive ? 0 : STR_UPPER); + push_ascii(buf+30,fname,12,0); DEBUG(8,("put name [%s] from [%s] into dir struct\n",buf+30, fname)); } @@ -1534,6 +1534,11 @@ void smb_panic2(const char *why, BOOL decrement_pid_count ) ZERO_ARRAY(names); ZERO_ARRAY(namebuf); + /* We need to be root so we can open our /proc entry to walk + * our stack. It also helps when we want to dump core. + */ + become_root(); + for (i = 0; i < BACKTRACE_STACK_SIZE; i++) { names[i] = namebuf + (i * NAMESIZE); } diff --git a/source/lib/util_seaccess.c b/source/lib/util_seaccess.c index cb0f46e2f9d..b5a9010b5c4 100644 --- a/source/lib/util_seaccess.c +++ b/source/lib/util_seaccess.c @@ -316,42 +316,3 @@ 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/source/lib/util_str.c b/source/lib/util_str.c index 60fe1306c8e..f99c2d1fb32 100644 --- a/source/lib/util_str.c +++ b/source/lib/util_str.c @@ -1558,8 +1558,8 @@ int fstr_sprintf(fstring s, const char *fmt, ...) size_t strnlen(const char *s, size_t n) { - int i; - for (i=0; s[i] && i<n; i++) + size_t i; + for (i=0; i<n && s[i] != '\0'; i++) /* noop */ ; return i; } diff --git a/source/lib/util_unistr.c b/source/lib/util_unistr.c index bb9d69b164d..55a21ebcbbc 100644 --- a/source/lib/util_unistr.c +++ b/source/lib/util_unistr.c @@ -454,16 +454,20 @@ smb_ucs2_t *strnrchr_w(const smb_ucs2_t *s, smb_ucs2_t c, unsigned int n) smb_ucs2_t *strstr_w(const smb_ucs2_t *s, const smb_ucs2_t *ins) { smb_ucs2_t *r; - size_t slen, inslen; + size_t inslen; + + if (!s || !*s || !ins || !*ins) + return NULL; - if (!s || !*s || !ins || !*ins) return NULL; - slen = strlen_w(s); inslen = strlen_w(ins); r = (smb_ucs2_t *)s; + while ((r = strchr_w(r, *ins))) { - if (strncmp_w(r, ins, inslen) == 0) return r; + if (strncmp_w(r, ins, inslen) == 0) + return r; r++; } + return NULL; } @@ -736,16 +740,20 @@ smb_ucs2_t *strpbrk_wa(const smb_ucs2_t *s, const char *p) smb_ucs2_t *strstr_wa(const smb_ucs2_t *s, const char *ins) { smb_ucs2_t *r; - size_t slen, inslen; + size_t inslen; + + if (!s || !*s || !ins || !*ins) + return NULL; - if (!s || !*s || !ins || !*ins) return NULL; - slen = strlen_w(s); inslen = strlen(ins); r = (smb_ucs2_t *)s; + while ((r = strchr_w(r, UCS2_CHAR(*ins)))) { - if (strncmp_wa(r, ins, inslen) == 0) return r; + if (strncmp_wa(r, ins, inslen) == 0) + return r; r++; } + return NULL; } |