diff options
author | Jeremy Allison <jra@samba.org> | 2001-10-11 09:35:01 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2001-10-11 09:35:01 +0000 |
commit | f0b5382869d12249e593ac2f10fc9f1f9d03bae6 (patch) | |
tree | 97543b143f7e42dfdfd7e6e46ad22d0fd59bcdab /source/lib | |
parent | 8d4870bccd026d059c160de3642bb427338256ec (diff) | |
download | samba-f0b5382869d12249e593ac2f10fc9f1f9d03bae6.tar.gz |
Sync-up with SAMBA_2_2 branch.
Jeremy.
Diffstat (limited to 'source/lib')
-rw-r--r-- | source/lib/debug.c | 13 | ||||
-rw-r--r-- | source/lib/genrand.c | 4 | ||||
-rw-r--r-- | source/lib/hash.c | 40 | ||||
-rw-r--r-- | source/lib/messages.c | 21 | ||||
-rw-r--r-- | source/lib/pidfile.c | 12 | ||||
-rw-r--r-- | source/lib/readline.c | 18 | ||||
-rw-r--r-- | source/lib/sysacls.c | 170 | ||||
-rw-r--r-- | source/lib/talloc.c | 2 | ||||
-rw-r--r-- | source/lib/time.c | 31 | ||||
-rw-r--r-- | source/lib/username.c | 2 | ||||
-rw-r--r-- | source/lib/util.c | 434 | ||||
-rw-r--r-- | source/lib/util_array.c | 14 | ||||
-rw-r--r-- | source/lib/util_file.c | 47 | ||||
-rw-r--r-- | source/lib/util_list.c | 2 | ||||
-rw-r--r-- | source/lib/util_seaccess.c | 23 | ||||
-rw-r--r-- | source/lib/util_sid.c | 27 | ||||
-rw-r--r-- | source/lib/util_sock.c | 137 | ||||
-rw-r--r-- | source/lib/util_str.c | 21 |
18 files changed, 659 insertions, 359 deletions
diff --git a/source/lib/debug.c b/source/lib/debug.c index 4ec70bd118a..982d59acc10 100644 --- a/source/lib/debug.c +++ b/source/lib/debug.c @@ -310,11 +310,20 @@ BOOL reopen_logs( void ) FILE *new_dbf = NULL; BOOL ret = True; + if (stdout_logging) + return True; + oldumask = umask( 022 ); pstrcpy(fname, debugf ); - if (lp_loaded() && (*lp_logfile())) - pstrcpy(fname, lp_logfile()); + + if (lp_loaded()) { + char *logfname; + + logfname = lp_logfile(); + if (*logfname) + pstrcpy(fname, logfname); + } pstrcpy(debugf, fname); diff --git a/source/lib/genrand.c b/source/lib/genrand.c index 7af44118ae5..e5912601182 100644 --- a/source/lib/genrand.c +++ b/source/lib/genrand.c @@ -158,7 +158,11 @@ static int do_reseed(BOOL use_fd, int fd) /* Add in some secret file contents */ do_filehash("/etc/shadow", &seed_inbuf[0]); +#ifdef WITH_TDB_SAM + do_filehash(lp_tdb_passwd_file(), &seed_inbuf[16]); +#else do_filehash(lp_smb_passwd_file(), &seed_inbuf[16]); +#endif /* * Add in the root encrypted password. diff --git a/source/lib/hash.c b/source/lib/hash.c index 92840a4c983..3abdc2ef11b 100644 --- a/source/lib/hash.c +++ b/source/lib/hash.c @@ -30,10 +30,8 @@ extern int DEBUGLEVEL; -#define NUM_PRIMES 11 - static BOOL enlarge_hash_table(hash_table *table); -static int primes[NUM_PRIMES] = +static int primes[] = {17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209, 16411}; /**************************************************************************** @@ -62,7 +60,7 @@ BOOL hash_table_init(hash_table *table, int num_buckets, compare_function compar table->comp_func = compare_func; while (table->size < num_buckets) table->size <<= 1; - for (i = 0; i < NUM_PRIMES; i++) { + for (i = 0; i < ARRAY_SIZE(primes); i++) { if (primes[i] > table->size) { table->size = primes[i]; break; @@ -94,12 +92,16 @@ BOOL hash_table_init(hash_table *table, int num_buckets, compare_function compar static int string_hash(int hash_size, const char *key) { - int j=0; - while (*key) - j = j*10 + *key++; - return(((j>=0)?j:(-j)) % hash_size); + u32 value; /* Used to compute the hash value. */ + u32 i; /* Used to cycle through random values. */ + + for (value = 0x238F13AF, i=0; key[i]; i++) + value = (value + (key[i] << (i*5 % 24))); + + return (1103515243 * value + 12345) % hash_size; } + /* ************************************************************************* * Search the hash table for the entry in the hash chain. * The function returns the pointer to the @@ -192,8 +194,8 @@ hash_element *hash_insert(hash_table *table, char *value, char *key) bucket = hash_elem->bucket; ubi_dlRemThis(&(table->lru_chain), &(hash_elem->lru_link.lru_link)); ubi_dlRemThis(bucket, (ubi_dlNodePtr)hash_elem); - free((char*)(hash_elem->value)); - free(hash_elem); + SAFE_FREE(hash_elem->value); + SAFE_FREE(hash_elem); } else { table->num_elements += 1; } @@ -238,10 +240,8 @@ void hash_remove(hash_table *table, hash_element *hash_elem) if (hash_elem) { ubi_dlRemove(&(table->lru_chain), &(hash_elem->lru_link.lru_link)); ubi_dlRemove(hash_elem->bucket, (ubi_dlNodePtr) hash_elem); - if(hash_elem->value) - free((char *)(hash_elem->value)); - if(hash_elem) - free((char *) hash_elem); + SAFE_FREE(hash_elem->value); + SAFE_FREE(hash_elem); table->num_elements--; } } @@ -285,8 +285,7 @@ static BOOL enlarge_hash_table(hash_table *table) table->num_elements++; } } - if(buckets) - free((char *) buckets); + SAFE_FREE(buckets); return True; } @@ -309,14 +308,11 @@ void hash_clear(hash_table *table) for (i = 0; i < table->size; bucket++, i++) { while (bucket->count != 0) { hash_elem = (hash_element *) ubi_dlRemHead(bucket); - if(hash_elem->value) - free((char *)(hash_elem->value)); - if(hash_elem) - free((char *)hash_elem); + SAFE_FREE(hash_elem->value); + SAFE_FREE(hash_elem); } } table->size = 0; - if(table->buckets) - free((char *) table->buckets); + SAFE_FREE(table->buckets); table->buckets = NULL; } diff --git a/source/lib/messages.c b/source/lib/messages.c index ffa873960e7..f7a5be4c2cc 100644 --- a/source/lib/messages.c +++ b/source/lib/messages.c @@ -90,7 +90,7 @@ BOOL message_init(void) if (tdb) return True; tdb = tdb_open_log(lock_path("messages.tdb"), - 0, TDB_CLEAR_IF_FIRST, + 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, O_RDWR|O_CREAT,0600); if (!tdb) { @@ -299,11 +299,15 @@ void message_dispatch(void) struct dispatch_fns *dfn; if (!received_signal) return; + + DEBUG(10,("message_dispatch: received_signal = %d\n", received_signal)); + received_signal = 0; while (message_recv(&msg_type, &src, &buf, &len)) { for (dfn = dispatch_fns; dfn; dfn = dfn->next) { if (dfn->msg_type == msg_type) { + DEBUG(10,("message_dispatch: processing message of type %d.\n", msg_type)); dfn->fn(msg_type, src, buf, len); } } @@ -322,12 +326,19 @@ void message_register(int msg_type, dfn = (struct dispatch_fns *)malloc(sizeof(*dfn)); - ZERO_STRUCTP(dfn); + if (dfn != NULL) { + + ZERO_STRUCTPN(dfn); - dfn->msg_type = msg_type; - dfn->fn = fn; + dfn->msg_type = msg_type; + dfn->fn = fn; - DLIST_ADD(dispatch_fns, dfn); + DLIST_ADD(dispatch_fns, dfn); + } + else { + + DEBUG(0,("message_register: Not enough memory. malloc failed!\n")); + } } /**************************************************************************** diff --git a/source/lib/pidfile.c b/source/lib/pidfile.c index 25ff85483d0..a26aa12a3c1 100644 --- a/source/lib/pidfile.c +++ b/source/lib/pidfile.c @@ -41,7 +41,7 @@ pid_t pidfile_pid(char *name) slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_lockdir(), name); - fd = sys_open(pidFile, O_NONBLOCK | O_RDWR, 0644); + fd = sys_open(pidFile, O_NONBLOCK | O_RDONLY, 0644); if (fd == -1) { return 0; } @@ -49,24 +49,24 @@ pid_t pidfile_pid(char *name) ZERO_ARRAY(pidstr); if (read(fd, pidstr, sizeof(pidstr)-1) <= 0) { - goto ok; + goto noproc; } ret = atoi(pidstr); if (!process_exists((pid_t)ret)) { - goto ok; + goto noproc; } - if (fcntl_lock(fd,SMB_F_SETLK,0,1,F_WRLCK)) { + if (fcntl_lock(fd,SMB_F_SETLK,0,1,F_RDLCK)) { /* we could get the lock - it can't be a Samba process */ - goto ok; + goto noproc; } close(fd); return (pid_t)ret; - ok: + noproc: close(fd); unlink(pidFile); return 0; diff --git a/source/lib/readline.c b/source/lib/readline.c index 75a38c68521..a1cdbe15872 100644 --- a/source/lib/readline.c +++ b/source/lib/readline.c @@ -22,24 +22,6 @@ #include "includes.h" -#ifdef HAVE_LIBREADLINE -# ifdef HAVE_READLINE_READLINE_H -# include <readline/readline.h> -# ifdef HAVE_READLINE_HISTORY_H -# include <readline/history.h> -# endif -# else -# ifdef HAVE_READLINE_H -# include <readline.h> -# ifdef HAVE_HISTORY_H -# include <history.h> -# endif -# else -# undef HAVE_LIBREADLINE -# endif -# endif -#endif - /**************************************************************************** display the prompt and wait for input. Call callback() regularly ****************************************************************************/ diff --git a/source/lib/sysacls.c b/source/lib/sysacls.c index 0770a8856a2..0f488888a8f 100644 --- a/source/lib/sysacls.c +++ b/source/lib/sysacls.c @@ -64,7 +64,7 @@ extern int DEBUGLEVEL; int sys_acl_free_text(char *text) - free acl_to_text int sys_acl_free_acl(SMB_ACL_T posix_acl) - int sys_acl_free_qualifier(SMB_ACL_T posix_acl) + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype) */ @@ -186,11 +186,167 @@ int sys_acl_free_acl(SMB_ACL_T the_acl) return acl_free(the_acl); } -int sys_acl_free_qualifier(void *qual) +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) { return acl_free(qual); } +#elif defined(HAVE_TRU64_ACLS) +/* + * The interface to DEC/Compaq Tru64 UNIX ACLs + * is based on Draft 13 of the POSIX spec which is + * slightly different from the Draft 16 interface. + * + * Also, some of the permset manipulation functions + * such as acl_clear_perm() and acl_add_perm() appear + * to be broken on Tru64 so we have to manipulate + * the permission bits in the permset directly. + */ +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p) +{ + SMB_ACL_ENTRY_T entry; + + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) { + return -1; + } + + errno = 0; + if ((entry = acl_get_entry(the_acl)) != NULL) { + *entry_p = entry; + return 1; + } + + return errno ? -1 : 0; +} + +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) +{ + return acl_get_tag_type( entry_d, tag_type_p); +} + +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) +{ + return acl_get_permset( entry_d, permset_p); +} + +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) +{ + return acl_get_qualifier( entry_d); +} + +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) +{ + return acl_get_file((char *)path_p, type); +} + +SMB_ACL_T sys_acl_get_fd(int fd) +{ + return acl_get_fd(fd, ACL_TYPE_ACCESS); +} + +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) +{ + *permset = 0; /* acl_clear_perm() is broken on Tru64 */ + + return 0; +} + +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) +{ + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) { + errno = EINVAL; + return -1; + } + + *permset |= perm; /* acl_add_perm() is broken on Tru64 */ + + return 0; +} + +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) +{ + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */ +} + +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen) +{ + return acl_to_text( the_acl, plen); +} + +SMB_ACL_T sys_acl_init( int count) +{ + return acl_init(count); +} + +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) +{ + SMB_ACL_ENTRY_T entry; + + if ((entry = acl_create_entry(pacl)) == NULL) { + return -1; + } + + *pentry = entry; + return 0; +} + +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) +{ + return acl_set_tag_type(entry, tagtype); +} + +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) +{ + return acl_set_qualifier(entry, qual); +} + +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) +{ + return acl_set_permset(entry, permset); +} + +int sys_acl_valid( SMB_ACL_T theacl ) +{ + acl_entry_t entry; + + return acl_valid(theacl, &entry); +} + +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) +{ + return acl_set_file((char *)name, acltype, theacl); +} + +int sys_acl_set_fd( int fd, SMB_ACL_T theacl) +{ + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl); +} + +int sys_acl_delete_def_file(const char *name) +{ + return acl_delete_def_file((char *)name); +} + +int sys_acl_free_text(char *text) +{ + /* + * (void) cast and explicit return 0 are for DEC UNIX + * which just #defines acl_free_text() to be free() + */ + (void) acl_free_text(text); + return 0; +} + +int sys_acl_free_acl(SMB_ACL_T the_acl) +{ + return acl_free(the_acl); +} + +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) +{ + return acl_free_qualifier(qual, tagtype); +} + #elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS) /* @@ -543,7 +699,7 @@ char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) maxlen += nbytes + 20 * (acl_d->count - i); - if ((text = realloc(oldtext, maxlen)) == NULL) { + if ((text = Realloc(oldtext, maxlen)) == NULL) { free(oldtext); errno = ENOMEM; return NULL; @@ -820,7 +976,7 @@ int sys_acl_free_acl(SMB_ACL_T acl_d) return 0; } -int sys_acl_free_qualifier(void *qual) +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) { return 0; } @@ -1075,7 +1231,7 @@ int sys_acl_free_acl(SMB_ACL_T acl_d) return 0; } -int sys_acl_free_qualifier(void *qual) +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) { return 0; } @@ -1960,7 +2116,7 @@ int sys_acl_free_acl(SMB_ACL_T posix_acl) return(0); } -int sys_acl_free_qualifier(void *qual) +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) { return(0); } @@ -2093,7 +2249,7 @@ int sys_acl_free_acl(SMB_ACL_T the_acl) return -1; } -int sys_acl_free_qualifier(void *qual) +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) { errno = ENOSYS; return -1; diff --git a/source/lib/talloc.c b/source/lib/talloc.c index a8ee481744b..cfd130e888b 100644 --- a/source/lib/talloc.c +++ b/source/lib/talloc.c @@ -90,7 +90,7 @@ void *talloc_realloc(TALLOC_CTX *t, void *ptr, size_t size) for (tc=t->list; tc; tc=tc->next) { if (tc->ptr == ptr) { - ptr = realloc(ptr, size); + ptr = Realloc(ptr, size); if (ptr) { t->total_alloc_size += (size - tc->size); tc->size = size; diff --git a/source/lib/time.c b/source/lib/time.c index 9714d4b9f8e..bf58cdd018a 100644 --- a/source/lib/time.c +++ b/source/lib/time.c @@ -44,7 +44,19 @@ extern int DEBUGLEVEL; #define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN) #endif +/******************************************************************* + External access to time_t_min and time_t_max. +********************************************************************/ +time_t get_time_t_min(void) +{ + return TIME_T_MIN; +} + +time_t get_time_t_max(void) +{ + return TIME_T_MAX; +} /******************************************************************* a gettimeofday wrapper @@ -121,7 +133,7 @@ Updated by Paul Eggert <eggert@twinsun.com> ********************************************************************/ static int TimeZoneFaster(time_t t) { - static struct dst_table {time_t start,end; int zone;} *dst_table = NULL; + static struct dst_table {time_t start,end; int zone;} *tdt, *dst_table = NULL; static int table_size = 0; int i; int zone = 0; @@ -141,13 +153,18 @@ static int TimeZoneFaster(time_t t) time_t low,high; zone = TimeZone(t); - dst_table = (struct dst_table *)Realloc(dst_table, + tdt = (struct dst_table *)Realloc(dst_table, sizeof(dst_table[0])*(i+1)); - if (!dst_table) { + if (!tdt) { + DEBUG(0,("TimeZoneFaster: out of memory!\n")); + if (dst_table) + free(dst_table); table_size = 0; } else { - table_size++; + dst_table = tdt; + table_size++; + dst_table[i].zone = zone; dst_table[i].start = dst_table[i].end = t; @@ -304,6 +321,12 @@ void unix_to_nt_time(NTTIME *nt, time_t t) nt->high = 0; return; } + if (t == TIME_T_MAX) + { + nt->low = 0xffffffff; + nt->high = 0x7fffffff; + return; + } if (t == -1) { nt->low = 0xffffffff; diff --git a/source/lib/username.c b/source/lib/username.c index e465cfbf226..5cd57e0ae50 100644 --- a/source/lib/username.c +++ b/source/lib/username.c @@ -262,7 +262,7 @@ static BOOL user_in_netgroup_list(char *user,char *ngname) user, mydomain, ngname)); DEBUG(5,("innetgr is %s\n", innetgr(ngname, NULL, user, mydomain) - ? "TRUE" : "FALSE")); + ? "True" : "False")); if (innetgr(ngname, NULL, user, mydomain)) return (True); diff --git a/source/lib/util.c b/source/lib/util.c index 453bccdd361..26ca621fde2 100644 --- a/source/lib/util.c +++ b/source/lib/util.c @@ -3,6 +3,7 @@ Version 1.9. Samba utility functions Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Jeremy Allison 2001 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -52,7 +53,7 @@ #endif /* HAVE_NETGROUP && WITH_AUTOMOUNT */ #ifdef WITH_SSL -#include <ssl.h> +#include <openssl/ssl.h> #undef Realloc /* SSLeay defines this and samba has a function of this name */ extern SSL *ssl; extern int sslFd; @@ -92,27 +93,28 @@ char **my_netbios_names; /**************************************************************************** - find a suitable temporary directory. The result should be copied immediately - as it may be overwritten by a subsequent call - ****************************************************************************/ + Find a suitable temporary directory. The result should be copied immediately + as it may be overwritten by a subsequent call. +****************************************************************************/ + char *tmpdir(void) { - char *p; - if ((p = getenv("TMPDIR"))) { - return p; - } - return "/tmp"; + char *p; + if ((p = getenv("TMPDIR"))) + return p; + return "/tmp"; } /**************************************************************************** -determine whether we are in the specified group + Determine whether we are in the specified group. ****************************************************************************/ BOOL in_group(gid_t group, gid_t current_gid, int ngroups, gid_t *groups) { int i; - if (group == current_gid) return(True); + if (group == current_gid) + return(True); for (i=0;i<ngroups;i++) if (group == groups[i]) @@ -121,14 +123,13 @@ BOOL in_group(gid_t group, gid_t current_gid, int ngroups, gid_t *groups) return(False); } - /**************************************************************************** -like atoi but gets the value up to the separater character + Like atoi but gets the value up to the separater character. ****************************************************************************/ + char *Atoic(char *p, int *n, char *c) { - if (!isdigit((int)*p)) - { + if (!isdigit((int)*p)) { DEBUG(5, ("Atoic: malformed number\n")); return NULL; } @@ -136,12 +137,9 @@ char *Atoic(char *p, int *n, char *c) (*n) = atoi(p); while ((*p) && isdigit((int)*p)) - { p++; - } - if (strchr(c, *p) == NULL) - { + if (strchr(c, *p) == NULL) { DEBUG(5, ("Atoic: no separator characters (%s) not found\n", c)); return NULL; } @@ -150,27 +148,29 @@ char *Atoic(char *p, int *n, char *c) } /************************************************************************* - reads a list of numbers + Reads a list of numbers. *************************************************************************/ + char *get_numlist(char *p, uint32 **num, int *count) { int val; if (num == NULL || count == NULL) - { return NULL; - } (*count) = 0; (*num ) = NULL; - while ((p = Atoic(p, &val, ":,")) != NULL && (*p) != ':') - { - (*num) = Realloc((*num), ((*count)+1) * sizeof(uint32)); - if ((*num) == NULL) - { + while ((p = Atoic(p, &val, ":,")) != NULL && (*p) != ':') { + uint32 *tn; + + tn = Realloc((*num), ((*count)+1) * sizeof(uint32)); + if (tn == NULL) { + if (*num) + free(*num); return NULL; - } + } else + (*num) = tn; (*num)[(*count)] = val; (*count)++; p++; @@ -179,52 +179,40 @@ char *get_numlist(char *p, uint32 **num, int *count) return p; } - /******************************************************************* - check if a file exists - call vfs_file_exist for samba files + Check if a file exists - call vfs_file_exist for samba files. ********************************************************************/ + BOOL file_exist(char *fname,SMB_STRUCT_STAT *sbuf) { - SMB_STRUCT_STAT st; - if (!sbuf) sbuf = &st; + SMB_STRUCT_STAT st; + if (!sbuf) + sbuf = &st; - if (sys_stat(fname,sbuf) != 0) - return(False); + if (sys_stat(fname,sbuf) != 0) + return(False); - return(S_ISREG(sbuf->st_mode)); + return(S_ISREG(sbuf->st_mode)); } /******************************************************************* - rename a unix file + Check a files mod time. ********************************************************************/ -int file_rename(char *from, char *to) -{ - int rcode = rename (from, to); - - if (errno == EXDEV) - { - /* Rename across filesystems needed. */ - rcode = copy_reg (from, to); - } - return rcode; -} -/******************************************************************* -check a files mod time -********************************************************************/ time_t file_modtime(char *fname) { - SMB_STRUCT_STAT st; + SMB_STRUCT_STAT st; - if (sys_stat(fname,&st) != 0) - return(0); + if (sys_stat(fname,&st) != 0) + return(0); - return(st.st_mtime); + return(st.st_mtime); } /******************************************************************* - check if a directory exists + Check if a directory exists. ********************************************************************/ + BOOL directory_exist(char *dname,SMB_STRUCT_STAT *st) { SMB_STRUCT_STAT st2; @@ -522,111 +510,85 @@ int set_blocking(int fd, BOOL set) } /**************************************************************************** -transfer some data between two fd's + Transfer some data between two fd's. ****************************************************************************/ -SMB_OFF_T transfer_file(int infd,int outfd,SMB_OFF_T n,char *header,int headlen,int align) -{ - static char *buf=NULL; - static int size=0; - char *buf1,*abuf; - SMB_OFF_T total = 0; - - DEBUG(4,("transfer_file n=%.0f (head=%d) called\n",(double)n,headlen)); - - if (size == 0) { - size = lp_readsize(); - size = MAX(size,1024); - } - - while (!buf && size>0) { - buf = (char *)Realloc(buf,size+8); - if (!buf) size /= 2; - } - - if (!buf) { - DEBUG(0,("Can't allocate transfer buffer!\n")); - exit(1); - } - - abuf = buf + (align%8); - if (header) - n += headlen; - - while (n > 0) - { - int s = (int)MIN(n,(SMB_OFF_T)size); - int ret,ret2=0; +ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn)(int, void *, size_t), + ssize_t (*write_fn)(int, const void *, size_t)) +{ + static char buf[16384]; + size_t total = 0; + ssize_t read_ret; + size_t write_total = 0; + ssize_t write_ret; - ret = 0; + while (total < n) { + size_t num_to_read_thistime = MIN((n - total), sizeof(buf)); - if (header && (headlen >= MIN(s,1024))) { - buf1 = header; - s = headlen; - ret = headlen; - headlen = 0; - header = NULL; - } else { - buf1 = abuf; - } + read_ret = (*read_fn)(infd, buf + total, num_to_read_thistime); + if (read_ret == -1) { + DEBUG(0,("transfer_file_internal: read failure. Error = %s\n", strerror(errno) )); + return -1; + } + if (read_ret == 0) + break; - if (header && headlen > 0) - { - ret = MIN(headlen,size); - memcpy(buf1,header,ret); - headlen -= ret; - header += ret; - if (headlen <= 0) header = NULL; - } + write_total = 0; + + while (write_total < read_ret) { + write_ret = (*write_fn)(outfd,buf + total, read_ret); + + if (write_ret == -1) { + DEBUG(0,("transfer_file_internal: write failure. Error = %s\n", strerror(errno) )); + return -1; + } + if (write_ret == 0) + return (ssize_t)total; + + write_total += (size_t)write_ret; + } - if (s > ret) - ret += read(infd,buf1+ret,s-ret); + total += (size_t)read_ret; + } - if (ret > 0) - { - ret2 = (outfd>=0?write_data(outfd,buf1,ret):ret); - if (ret2 > 0) total += ret2; - /* if we can't write then dump excess data */ - if (ret2 != ret) - transfer_file(infd,-1,n-(ret+headlen),NULL,0,0); - } - if (ret <= 0 || ret2 != ret) - return(total); - n -= ret; - } - return(total); + return (ssize_t)total; } +SMB_OFF_T transfer_file(int infd,int outfd,SMB_OFF_T n) +{ + return (SMB_OFF_T)transfer_file_internal(infd, outfd, (size_t)n, read, write); +} /******************************************************************* -sleep for a specified number of milliseconds + Sleep for a specified number of milliseconds. ********************************************************************/ + void msleep(int t) { - int tdiff=0; - struct timeval tval,t1,t2; - fd_set fds; + int tdiff=0; + struct timeval tval,t1,t2; + fd_set fds; - GetTimeOfDay(&t1); - GetTimeOfDay(&t2); + GetTimeOfDay(&t1); + GetTimeOfDay(&t2); - while (tdiff < t) { - tval.tv_sec = (t-tdiff)/1000; - tval.tv_usec = 1000*((t-tdiff)%1000); + while (tdiff < t) { + tval.tv_sec = (t-tdiff)/1000; + tval.tv_usec = 1000*((t-tdiff)%1000); - FD_ZERO(&fds); - errno = 0; - sys_select_intr(0,&fds,&tval); + FD_ZERO(&fds); + errno = 0; + sys_select_intr(0,&fds,&tval); - GetTimeOfDay(&t2); - tdiff = TvalDiff(&t1,&t2); - } + GetTimeOfDay(&t2); + tdiff = TvalDiff(&t1,&t2); + } } - /**************************************************************************** -become a daemon, discarding the controlling terminal + Become a daemon, discarding the controlling terminal. ****************************************************************************/ + void become_daemon(void) { if (sys_fork()) { @@ -650,74 +612,64 @@ void become_daemon(void) close_low_fds(); } - /**************************************************************************** -put up a yes/no prompt + Put up a yes/no prompt ****************************************************************************/ + BOOL yesno(char *p) { - pstring ans; - printf("%s",p); + pstring ans; + printf("%s",p); - if (!fgets(ans,sizeof(ans)-1,stdin)) - return(False); + if (!fgets(ans,sizeof(ans)-1,stdin)) + return(False); - if (*ans == 'y' || *ans == 'Y') - return(True); + if (*ans == 'y' || *ans == 'Y') + return(True); - return(False); + return(False); } -#ifdef HPUX /**************************************************************************** -this is a version of setbuffer() for those machines that only have setvbuf + Expand a pointer to be a particular size. ****************************************************************************/ - void setbuffer(FILE *f,char *buf,int bufsize) -{ - setvbuf(f,buf,_IOFBF,bufsize); -} -#endif -/**************************************************************************** -expand a pointer to be a particular size -****************************************************************************/ void *Realloc(void *p,size_t size) { - void *ret=NULL; + void *ret=NULL; - if (size == 0) { - if (p) free(p); - DEBUG(5,("Realloc asked for 0 bytes\n")); - return NULL; - } + if (size == 0) { + if (p) + free(p); + DEBUG(5,("Realloc asked for 0 bytes\n")); + return NULL; + } - if (!p) - ret = (void *)malloc(size); - else - ret = (void *)realloc(p,size); + if (!p) + ret = (void *)malloc(size); + else + ret = (void *)realloc(p,size); - if (!ret) - DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size)); + if (!ret) + DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size)); - return(ret); + return(ret); } - /**************************************************************************** -free memory, checks for NULL + Free memory, checks for NULL. ****************************************************************************/ + void safe_free(void *p) { if (p != NULL) - { free(p); - } } - /**************************************************************************** -get my own name and IP + Get my own name and IP. ****************************************************************************/ + BOOL get_myname(char *my_name) { pstring hostname; @@ -736,7 +688,8 @@ BOOL get_myname(char *my_name) if (my_name) { /* split off any parts after an initial . */ char *p = strchr(hostname,'.'); - if (p) *p = 0; + if (p) + *p = 0; fstrcpy(my_name,hostname); } @@ -745,8 +698,9 @@ BOOL get_myname(char *my_name) } /**************************************************************************** -interpret a protocol description string, with a default + Interpret a protocol description string, with a default. ****************************************************************************/ + int interpret_protocol(char *str,int def) { if (strequal(str,"NT1")) @@ -1808,7 +1762,131 @@ BOOL mask_match(char *string, char *pattern, BOOL is_case_sensitive) return ms_fnmatch(p2, s2) == 0; } +/********************************************************* + Recursive routine that is called by unix_wild_match. +*********************************************************/ + +static BOOL unix_do_match(char *regexp, char *str) +{ + char *p; + + for( p = regexp; *p && *str; ) { + + switch(*p) { + case '?': + str++; + p++; + break; + + case '*': + + /* + * Look for a character matching + * the one after the '*'. + */ + p++; + if(!*p) + return True; /* Automatic match */ + while(*str) { + + while(*str && (*p != *str)) + str++; + + /* + * Patch from weidel@multichart.de. In the case of the regexp + * '*XX*' we want to ensure there are at least 2 'X' characters + * in the string after the '*' for a match to be made. + */ + + { + int matchcount=0; + + /* + * Eat all the characters that match, but count how many there were. + */ + + while(*str && (*p == *str)) { + str++; + matchcount++; + } + + /* + * Now check that if the regexp had n identical characters that + * matchcount had at least that many matches. + */ + + while ( *(p+1) && (*(p+1) == *p)) { + p++; + matchcount--; + } + + if ( matchcount <= 0 ) + return False; + } + + str--; /* We've eaten the match char after the '*' */ + + if(unix_do_match(p, str)) + return True; + + if(!*str) + return False; + else + str++; + } + return False; + + default: + if(*str != *p) + return False; + str++; + p++; + break; + } + } + + if(!*p && !*str) + return True; + if (!*p && str[0] == '.' && str[1] == 0) + return(True); + + if (!*str && *p == '?') { + while (*p == '?') + p++; + return(!*p); + } + + if(!*str && (*p == '*' && p[1] == '\0')) + return True; + + return False; +} + +/******************************************************************* + Simple case insensitive interface to a UNIX wildcard matcher. +*******************************************************************/ + +BOOL unix_wild_match(char *pattern, char *string) +{ + pstring p2, s2; + char *p; + + pstrcpy(p2, pattern); + pstrcpy(s2, string); + strlower(p2); + strlower(s2); + + /* Remove any *? and ** from the pattern as they are meaningless */ + for(p = p2; *p; p++) + while( *p == '*' && (p[1] == '?' ||p[1] == '*')) + pstrcpy( &p[1], &p[2]); + + if (strequal(p2,"*")) + return True; + + return unix_do_match(p2, s2) == 0; +} #ifdef __INSURE__ diff --git a/source/lib/util_array.c b/source/lib/util_array.c index 567c170834a..dcb2a6b5f08 100644 --- a/source/lib/util_array.c +++ b/source/lib/util_array.c @@ -58,18 +58,20 @@ void* add_copy_to_array(uint32 *len, void ***array, const void *item, void* add_item_to_array(uint32 *len, void ***array, void *item) { + void **tary; + if (len == NULL || array == NULL) - { return NULL; - } - (*array) = (void**)Realloc((*array), ((*len)+1)*sizeof((*array)[0])); - - if ((*array) != NULL) - { + tary = (void**)Realloc((*array), ((*len)+1)*sizeof((*array)[0])); + + if (tary != NULL) { + (*array) = tary; (*array)[(*len)] = item; (*len)++; return item; + } else { + free((char *)*array); } return NULL; } diff --git a/source/lib/util_file.c b/source/lib/util_file.c index 4e2adc97bcc..f3d8afde5d4 100644 --- a/source/lib/util_file.c +++ b/source/lib/util_file.c @@ -282,13 +282,25 @@ char *fgets_slash(char *s2,int maxlen,FILE *f) if (feof(f)) return(NULL); + if (maxlen <2) return(NULL); + if (!s2) { + char *t; + maxlen = MIN(maxlen,8); - s = (char *)Realloc(s,maxlen); + t = (char *)Realloc(s,maxlen); + if (!t) { + DEBUG(0,("fgets_slash: failed to expand buffer!\n")); + if (s) + free(s); + return(NULL); + } else + s = t; } - if (!s || maxlen < 2) return(NULL); + if (!s) + return(NULL); *s = 0; @@ -323,12 +335,19 @@ char *fgets_slash(char *s2,int maxlen,FILE *f) s[len++] = c; s[len] = 0; } - if (!s2 && len > maxlen-3) - { - maxlen *= 2; - s = (char *)Realloc(s,maxlen); - if (!s) return(NULL); - } + if (!s2 && len > maxlen-3) { + char *t; + + maxlen *= 2; + t = (char *)Realloc(s,maxlen); + if (!t) { + DEBUG(0,("fgets_slash: failed to expand buffer!\n")); + if (s) + free(s); + return(NULL); + } else + s = t; + } } return(s); } @@ -340,7 +359,7 @@ load from a pipe into memory char *file_pload(char *syscmd, size_t *size) { int fd, n; - char *p; + char *p, *tp; pstring buf; size_t total; @@ -351,11 +370,15 @@ char *file_pload(char *syscmd, size_t *size) total = 0; while ((n = read(fd, buf, sizeof(buf))) > 0) { - p = Realloc(p, total + n + 1); - if (!p) { + tp = Realloc(p, total + n + 1); + if (!tp) { + DEBUG(0,("file_pload: failed to exand buffer!\n")); close(fd); + if (p) + free(p); return NULL; - } + } else + p = tp; memcpy(p+total, buf, n); total += n; } diff --git a/source/lib/util_list.c b/source/lib/util_list.c index 19354c87843..0175a7c8a16 100644 --- a/source/lib/util_list.c +++ b/source/lib/util_list.c @@ -230,7 +230,7 @@ BOOL compare_rpc_hnd_node(const RPC_HND_NODE *x, { /* only compare valid nodes */ if (x==NULL || y==NULL) - return FALSE; + return False; /* if the POLICY_HND field(s) are ever changed, this will need to be updated. Probably should be a set of diff --git a/source/lib/util_seaccess.c b/source/lib/util_seaccess.c index 8b75a5f4876..860988aad57 100644 --- a/source/lib/util_seaccess.c +++ b/source/lib/util_seaccess.c @@ -30,7 +30,7 @@ extern int DEBUGLEVEL; Check if this ACE has a SID in common with the token. **********************************************************************************/ -static BOOL token_sid_in_ace( NT_USER_TOKEN *token, SEC_ACE *ace) +static BOOL token_sid_in_ace(const NT_USER_TOKEN *token, const SEC_ACE *ace) { size_t i; @@ -154,7 +154,7 @@ static BOOL get_max_access( SEC_ACL *the_acl, NT_USER_TOKEN *token, uint32 *gran */ *granted = acc_granted; - *status = NT_STATUS_NOPROBLEMO; + *status = NT_STATUS_OK; return True; } @@ -201,24 +201,27 @@ void se_map_generic(uint32 *access_mask, struct generic_mapping *mapping) "Access-Checking" document in MSDN. *****************************************************************************/ -BOOL se_access_check(SEC_DESC *sd, struct current_user *user, +BOOL se_access_check(SEC_DESC *sd, NT_USER_TOKEN *token, uint32 acc_desired, uint32 *acc_granted, uint32 *status) { extern NT_USER_TOKEN anonymous_token; size_t i; SEC_ACL *the_acl; fstring sid_str; - NT_USER_TOKEN *token = user->nt_user_token ? user->nt_user_token : &anonymous_token; uint32 tmp_acc_desired = acc_desired; if (!status || !acc_granted) return False; - *status = NT_STATUS_NOPROBLEMO; + if (!token) + token = &anonymous_token; + + *status = NT_STATUS_OK; *acc_granted = 0; - DEBUG(10,("se_access_check: requested access %x, for uid %u\n", - (unsigned int)acc_desired, (unsigned int)user->uid )); + DEBUG(10,("se_access_check: requested access %x, for NT token with %u entries and first sid %s.\n", + (unsigned int)acc_desired, (unsigned int)token->num_sids, + sid_to_string(sid_str, &token->user_sids[0]))); /* * No security descriptor or security descriptor with no DACL @@ -228,7 +231,7 @@ BOOL se_access_check(SEC_DESC *sd, struct current_user *user, /* ACL must have something in it */ if (!sd || (sd && (!(sd->type & SEC_DESC_DACL_PRESENT) || sd->dacl == NULL))) { - *status = NT_STATUS_NOPROBLEMO; + *status = NT_STATUS_OK; *acc_granted = acc_desired; DEBUG(5, ("se_access_check: no sd or blank DACL, access allowed\n")); return True; @@ -276,7 +279,7 @@ BOOL se_access_check(SEC_DESC *sd, struct current_user *user, (unsigned int)tmp_acc_desired )); tmp_acc_desired = check_ace( ace, token, tmp_acc_desired, status); - if (*status != NT_STATUS_NOPROBLEMO) { + if (*status != NT_STATUS_OK) { *acc_granted = 0; DEBUG(5,("se_access_check: ACE %u denied with status %x.\n", (unsigned int)i, (unsigned int)*status )); return False; @@ -290,7 +293,7 @@ BOOL se_access_check(SEC_DESC *sd, struct current_user *user, if (tmp_acc_desired == 0) { *acc_granted = acc_desired; - *status = NT_STATUS_NOPROBLEMO; + *status = NT_STATUS_OK; DEBUG(5,("se_access_check: access (%x) granted.\n", (unsigned int)acc_desired )); return True; } diff --git a/source/lib/util_sid.c b/source/lib/util_sid.c index 70341507cb7..864d8a50d21 100644 --- a/source/lib/util_sid.c +++ b/source/lib/util_sid.c @@ -38,6 +38,7 @@ DOM_SID global_sid_World_Domain; /* Everyone domain */ DOM_SID global_sid_World; /* Everyone */ DOM_SID global_sid_Creator_Owner_Domain; /* Creator Owner domain */ DOM_SID global_sid_Creator_Owner; /* Creator Owner */ +DOM_SID global_sid_Creator_Group; /* Creator Group */ DOM_SID global_sid_NT_Authority; /* NT Authority */ DOM_SID global_sid_NULL; /* NULL sid */ DOM_SID global_sid_Builtin_Guests; /* Builtin guest users */ @@ -61,6 +62,7 @@ static known_sid_users everyone_users[] = { static known_sid_users creator_owner_users[] = { { 0, SID_NAME_ALIAS, "Creator Owner" }, + { 1, SID_NAME_ALIAS, "Creator Group" }, {0, (enum SID_NAME_USE)0, NULL}}; static known_sid_users nt_authority_users[] = { @@ -179,6 +181,7 @@ void generate_wellknown_sids(void) string_to_sid(&global_sid_World, "S-1-1-0"); string_to_sid(&global_sid_Creator_Owner_Domain, "S-1-3"); string_to_sid(&global_sid_Creator_Owner, "S-1-3-0"); + string_to_sid(&global_sid_Creator_Group, "S-1-3-1"); string_to_sid(&global_sid_NT_Authority, "S-1-5"); string_to_sid(&global_sid_NULL, "S-1-0-0"); string_to_sid(&global_sid_Authenticated_Users, "S-1-5-11"); @@ -566,3 +569,27 @@ size_t sid_size(DOM_SID *sid) return sid->num_auths * sizeof(uint32) + 8; } + +/***************************************************************** + Returns true if SID is internal (and non-mappable). +*****************************************************************/ + +BOOL non_mappable_sid(DOM_SID *sid) +{ + DOM_SID dom; + uint32 rid; + + sid_copy(&dom, sid); + sid_split_rid(&dom, &rid); + + if (sid_equal(&dom, &global_sid_Builtin)) + return True; + + if (sid_equal(&dom, &global_sid_Creator_Owner_Domain)) + return True; + + if (sid_equal(&dom, &global_sid_NT_Authority)) + return True; + + return False; +} diff --git a/source/lib/util_sock.c b/source/lib/util_sock.c index 24290e9af44..9058cf9368c 100644 --- a/source/lib/util_sock.c +++ b/source/lib/util_sock.c @@ -22,7 +22,7 @@ #include "includes.h" #ifdef WITH_SSL -#include <ssl.h> +#include <openssl/ssl.h> #undef Realloc /* SSLeay defines this and samba has a function of this name */ extern SSL *ssl; extern int sslFd; @@ -490,30 +490,31 @@ static ssize_t read_socket_data(int fd,char *buffer,size_t N) ssize_t write_data(int fd,char *buffer,size_t N) { - size_t total=0; - ssize_t ret; + size_t total=0; + ssize_t ret; - while (total < N) - { + while (total < N) { #ifdef WITH_SSL - if(fd == sslFd){ - ret = SSL_write(ssl,buffer + total,N - total); - }else{ - ret = write(fd,buffer + total,N - total); - } + if(fd == sslFd){ + ret = SSL_write(ssl,buffer + total,N - total); + } else { + ret = write(fd,buffer + total,N - total); + } #else /* WITH_SSL */ - ret = write(fd,buffer + total,N - total); + ret = write(fd,buffer + total,N - total); #endif /* WITH_SSL */ - if (ret == -1) { - DEBUG(0,("write_data: write failure. Error = %s\n", strerror(errno) )); - return -1; - } - if (ret == 0) return total; + if (ret == -1) { + DEBUG(0,("write_data: write failure. Error = %s\n", strerror(errno) )); + return -1; + } + if (ret == 0) + return (ssize_t)total; - total += ret; - } - return (ssize_t)total; + total += (size_t)ret; + } + + return (ssize_t)total; } /**************************************************************************** @@ -775,64 +776,70 @@ BOOL send_one_packet(char *buf,int len,struct in_addr ip,int port,int type) } /**************************************************************************** -open a socket of the specified type, port and address for incoming data + Open a socket of the specified type, port, and address for incoming data. ****************************************************************************/ -int open_socket_in(int type, int port, int dlevel,uint32 socket_addr, BOOL rebind) +int open_socket_in( int type, int port, int dlevel, uint32 socket_addr, BOOL rebind ) { - struct sockaddr_in sock; - int res; + struct sockaddr_in sock; + int res; - memset((char *)&sock,'\0',sizeof(sock)); + memset( (char *)&sock, '\0', sizeof(sock) ); #ifdef HAVE_SOCK_SIN_LEN - sock.sin_len = sizeof(sock); + sock.sin_len = sizeof(sock); #endif - sock.sin_port = htons( port ); - sock.sin_family = AF_INET; - sock.sin_addr.s_addr = socket_addr; - res = socket(AF_INET, type, 0); - if (res == -1) - { DEBUG(0,("socket failed\n")); return -1; } + sock.sin_port = htons( port ); + sock.sin_family = AF_INET; + sock.sin_addr.s_addr = socket_addr; + + res = socket( AF_INET, type, 0 ); + if( res == -1 ) { + if( DEBUGLVL(0) ) { + dbgtext( "open_socket_in(): socket() call failed: " ); + dbgtext( "%s\n", strerror( errno ) ); + } + return -1; + } - { - int val=1; - if(rebind) - val=1; - else - val=0; - if(setsockopt(res,SOL_SOCKET,SO_REUSEADDR,(char *)&val,sizeof(val)) == -1) - DEBUG(dlevel,("setsockopt: SO_REUSEADDR=%d on port %d failed with error = %s\n", - val, port, strerror(errno) )); + /* This block sets/clears the SO_REUSEADDR and possibly SO_REUSEPORT. */ + { + int val = rebind ? 1 : 0; + if( setsockopt(res,SOL_SOCKET,SO_REUSEADDR,(char *)&val,sizeof(val)) == -1 ) { + if( DEBUGLVL( dlevel ) ) { + dbgtext( "open_socket_in(): setsockopt: " ); + dbgtext( "SO_REUSEADDR = %s ", val?"True":"False" ); + dbgtext( "on port %d failed ", port ); + dbgtext( "with error = %s\n", strerror(errno) ); + } + } #ifdef SO_REUSEPORT - if(setsockopt(res,SOL_SOCKET,SO_REUSEPORT,(char *)&val,sizeof(val)) == -1) - DEBUG(dlevel,("setsockopt: SO_REUSEPORT=%d on port %d failed with error = %s\n", - val, port, strerror(errno) )); + if( setsockopt(res,SOL_SOCKET,SO_REUSEPORT,(char *)&val,sizeof(val)) == -1 ) { + if( DEBUGLVL( dlevel ) ) { + dbgtext( "open_socket_in(): setsockopt: "); + dbgtext( "SO_REUSEPORT = %d ", val?"True":"False" ); + dbgtext( "on port %d failed ", port ); + dbgtext( "with error = %s\n", strerror(errno) ); + } + } #endif /* SO_REUSEPORT */ - } - - /* now we've got a socket - we need to bind it */ - if (bind(res, (struct sockaddr * ) &sock,sizeof(sock)) < 0) - { - if (port) { - if (port == SMB_PORT || port == NMB_PORT) - DEBUG(dlevel,("bind failed on port %d socket_addr=%s (%s)\n", - port,inet_ntoa(sock.sin_addr),strerror(errno))); - close(res); - - if (dlevel > 0 && port < 1000) - port = 7999; + } - if (port >= 1000 && port < 9000) - return(open_socket_in(type,port+1,dlevel,socket_addr,rebind)); - } + /* now we've got a socket - we need to bind it */ + if( bind( res, (struct sockaddr *)&sock, sizeof(sock) ) == -1 ) { + if( DEBUGLVL(dlevel) && (port == SMB_PORT || port == NMB_PORT) ) { + dbgtext( "bind failed on port %d ", port ); + dbgtext( "socket_addr = %s.\n", inet_ntoa( sock.sin_addr ) ); + dbgtext( "Error = %s\n", strerror(errno) ); + } + close( res ); + return( -1 ); + } - return(-1); - } - DEBUG(3,("bind succeeded on port %d\n",port)); + DEBUG( 3, ( "bind succeeded on port %d\n", port ) ); - return res; -} + return( res ); + } /**************************************************************************** create an outgoing socket. timeout is in milliseconds. @@ -889,7 +896,7 @@ connect_again: #endif if (ret < 0) { - DEBUG(1,("error connecting to %s:%d (%s)\n", + DEBUG(2,("error connecting to %s:%d (%s)\n", inet_ntoa(*addr),port,strerror(errno))); close(res); return -1; diff --git a/source/lib/util_str.c b/source/lib/util_str.c index 07c91805cc7..32e2c40a7b4 100644 --- a/source/lib/util_str.c +++ b/source/lib/util_str.c @@ -1288,24 +1288,3 @@ char *string_truncate(char *s, int length) } return s; } - -/* Parse a string of the form DOMAIN/user into a domain and a user */ - -void parse_domain_user(char *domuser, fstring domain, fstring user) -{ - char *p; - char *sep = lp_winbind_separator(); - if (!sep) sep = "\\"; - p = strchr(domuser,*sep); - if (!p) p = strchr(domuser,'\\'); - if (!p) { - fstrcpy(domain,""); - fstrcpy(user, domuser); - return; - } - - fstrcpy(user, p+1); - fstrcpy(domain, domuser); - domain[PTR_DIFF(p, domuser)] = 0; - strupper(domain); -} |