diff options
Diffstat (limited to 'source3/lib/util.c')
-rw-r--r-- | source3/lib/util.c | 317 |
1 files changed, 6 insertions, 311 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c index ec43ea7037..820cf376be 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -439,19 +439,6 @@ bool set_cmdline_auth_info_machine_account_creds(void) return true; } -/**************************************************************************n - Find a suitable temporary directory. The result should be copied immediately - as it may be overwritten by a subsequent call. -****************************************************************************/ - -const char *tmpdir(void) -{ - char *p; - if ((p = getenv("TMPDIR"))) - return p; - return "/tmp"; -} - /**************************************************************************** Add a gid to an array of gids if it's not already there. ****************************************************************************/ @@ -540,7 +527,7 @@ const char *get_numlist(const char *p, uint32 **num, int *count) Check if a file exists - call vfs_file_exist for samba files. ********************************************************************/ -bool file_exist(const char *fname,SMB_STRUCT_STAT *sbuf) +bool file_exist_stat(const char *fname,SMB_STRUCT_STAT *sbuf) { SMB_STRUCT_STAT st; if (!sbuf) @@ -566,24 +553,10 @@ bool socket_exist(const char *fname) } /******************************************************************* - Check a files mod time. -********************************************************************/ - -time_t file_modtime(const char *fname) -{ - SMB_STRUCT_STAT st; - - if (sys_stat(fname,&st) != 0) - return(0); - - return(st.st_mtime); -} - -/******************************************************************* Check if a directory exists. ********************************************************************/ -bool directory_exist(char *dname,SMB_STRUCT_STAT *st) +bool directory_exist_stat(char *dname,SMB_STRUCT_STAT *st) { SMB_STRUCT_STAT st2; bool ret; @@ -927,36 +900,6 @@ ssize_t write_data_at_offset(int fd, const char *buffer, size_t N, SMB_OFF_T pos #endif } -/**************************************************************************** - Set a fd into blocking/nonblocking mode. Uses POSIX O_NONBLOCK if available, - else - if SYSV use O_NDELAY - if BSD use FNDELAY -****************************************************************************/ - -int set_blocking(int fd, bool set) -{ - int val; -#ifdef O_NONBLOCK -#define FLAG_TO_SET O_NONBLOCK -#else -#ifdef SYSV -#define FLAG_TO_SET O_NDELAY -#else /* BSD */ -#define FLAG_TO_SET FNDELAY -#endif -#endif - - if((val = sys_fcntl_long(fd, F_GETFL, 0)) == -1) - return -1; - if(set) /* Turn blocking on - ie. clear nonblock flag */ - val &= ~FLAG_TO_SET; - else - val |= FLAG_TO_SET; - return sys_fcntl_long( fd, F_SETFL, val); -#undef FLAG_TO_SET -} - /******************************************************************* Sleep for a specified number of milliseconds. ********************************************************************/ @@ -1130,26 +1073,6 @@ static void *realloc_(void *ptr, size_t size) #endif /* PARANOID_MALLOC_CHECKER */ /**************************************************************************** - Type-safe malloc. -****************************************************************************/ - -void *malloc_array(size_t el_size, unsigned int count) -{ - if (count >= MAX_ALLOC_SIZE/el_size) { - return NULL; - } - - if (el_size == 0 || count == 0) { - return NULL; - } -#if defined(PARANOID_MALLOC_CHECKER) - return malloc_(el_size*count); -#else - return malloc(el_size*count); -#endif -} - -/**************************************************************************** Type-safe memalign ****************************************************************************/ @@ -1250,21 +1173,6 @@ void *Realloc(void *p, size_t size, bool free_old_on_error) } /**************************************************************************** - Type-safe realloc. -****************************************************************************/ - -void *realloc_array(void *p, size_t el_size, unsigned int count, bool free_old_on_error) -{ - if (count >= MAX_ALLOC_SIZE/el_size) { - if (free_old_on_error) { - SAFE_FREE(p); - } - return NULL; - } - return Realloc(p, el_size*count, free_old_on_error); -} - -/**************************************************************************** (Hopefully) efficient array append. ****************************************************************************/ @@ -1320,21 +1228,10 @@ void add_to_large_array(TALLOC_CTX *mem_ctx, size_t element_size, } /**************************************************************************** - Free memory, checks for NULL. - Use directly SAFE_FREE() - Exists only because we need to pass a function pointer somewhere --SSS -****************************************************************************/ - -void safe_free(void *p) -{ - SAFE_FREE(p); -} - -/**************************************************************************** Get my own name and IP. ****************************************************************************/ -char *get_myname(TALLOC_CTX *ctx) +char *talloc_get_myname(TALLOC_CTX *ctx) { char *p; char hostname[HOST_NAME_MAX]; @@ -1549,14 +1446,6 @@ bool process_exists(const struct server_id pid) #endif } -bool process_exists_by_pid(pid_t pid) -{ - /* Doing kill with a non-positive pid causes messages to be - * sent to places we don't want. */ - SMB_ASSERT(pid > 0); - return(kill(pid,0) == 0 || errno != ESRCH); -} - /******************************************************************* Convert a uid into a user name. ********************************************************************/ @@ -2003,42 +1892,6 @@ void free_namearray(name_compare_entry *name_array) #define DBGC_CLASS DBGC_LOCKING /**************************************************************************** - Simple routine to do POSIX file locking. Cruft in NFS and 64->32 bit mapping - is dealt with in posix.c - Returns True if the lock was granted, False otherwise. -****************************************************************************/ - -bool fcntl_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type) -{ - SMB_STRUCT_FLOCK lock; - int ret; - - DEBUG(8,("fcntl_lock fd=%d op=%d offset=%.0f count=%.0f type=%d\n", - fd,op,(double)offset,(double)count,type)); - - lock.l_type = type; - lock.l_whence = SEEK_SET; - lock.l_start = offset; - lock.l_len = count; - lock.l_pid = 0; - - ret = sys_fcntl_ptr(fd,op,&lock); - - if (ret == -1) { - int sav = errno; - DEBUG(3,("fcntl_lock: lock failed at offset %.0f count %.0f op %d type %d (%s)\n", - (double)offset,(double)count,op,type,strerror(errno))); - errno = sav; - return False; - } - - /* everything went OK */ - DEBUG(8,("fcntl_lock: Lock call successful\n")); - - return True; -} - -/**************************************************************************** Simple routine to query existing file locks. Cruft in NFS and 64->32 bit mapping is dealt with in posix.c Returns True if we have information regarding this lock region (and returns @@ -2210,57 +2063,6 @@ enum remote_arch_types get_remote_arch(void) return ra_type; } -void print_asc(int level, const unsigned char *buf,int len) -{ - int i; - for (i=0;i<len;i++) - DEBUG(level,("%c", isprint(buf[i])?buf[i]:'.')); -} - -void dump_data(int level, const unsigned char *buf1,int len) -{ - const unsigned char *buf = (const unsigned char *)buf1; - int i=0; - if (len<=0) return; - - if (!DEBUGLVL(level)) return; - - DEBUGADD(level,("[%03X] ",i)); - for (i=0;i<len;) { - DEBUGADD(level,("%02X ",(int)buf[i])); - i++; - if (i%8 == 0) DEBUGADD(level,(" ")); - if (i%16 == 0) { - print_asc(level,&buf[i-16],8); DEBUGADD(level,(" ")); - print_asc(level,&buf[i-8],8); DEBUGADD(level,("\n")); - if (i<len) DEBUGADD(level,("[%03X] ",i)); - } - } - if (i%16) { - int n; - n = 16 - (i%16); - DEBUGADD(level,(" ")); - if (n>8) DEBUGADD(level,(" ")); - while (n--) DEBUGADD(level,(" ")); - n = MIN(8,i%16); - print_asc(level,&buf[i-(i%16)],n); DEBUGADD(level,( " " )); - n = (i%16) - n; - if (n>0) print_asc(level,&buf[i-n],n); - DEBUGADD(level,("\n")); - } -} - -void dump_data_pw(const char *msg, const uchar * data, size_t len) -{ -#ifdef DEBUG_PASSWORD - DEBUG(11, ("%s", msg)); - if (data != NULL && len > 0) - { - dump_data(11, data, len); - } -#endif -} - const char *tab_depth(int level, int depth) { if( CHECK_DEBUGLVL(level) ) { @@ -2425,78 +2227,6 @@ void *smb_xmalloc_array(size_t size, unsigned int count) return p; } -/** - Memdup with smb_panic on fail. -**/ - -void *smb_xmemdup(const void *p, size_t size) -{ - void *p2; - p2 = SMB_XMALLOC_ARRAY(unsigned char,size); - memcpy(p2, p, size); - return p2; -} - -/** - strdup that aborts on malloc fail. -**/ - -char *smb_xstrdup(const char *s) -{ -#if defined(PARANOID_MALLOC_CHECKER) -#ifdef strdup -#undef strdup -#endif -#endif - -#ifndef HAVE_STRDUP -#define strdup rep_strdup -#endif - - char *s1 = strdup(s); -#if defined(PARANOID_MALLOC_CHECKER) -#ifdef strdup -#undef strdup -#endif -#define strdup(s) __ERROR_DONT_USE_STRDUP_DIRECTLY -#endif - if (!s1) { - smb_panic("smb_xstrdup: malloc failed"); - } - return s1; - -} - -/** - strndup that aborts on malloc fail. -**/ - -char *smb_xstrndup(const char *s, size_t n) -{ -#if defined(PARANOID_MALLOC_CHECKER) -#ifdef strndup -#undef strndup -#endif -#endif - -#if (defined(BROKEN_STRNDUP) || !defined(HAVE_STRNDUP)) -#undef HAVE_STRNDUP -#define strndup rep_strndup -#endif - - char *s1 = strndup(s, n); -#if defined(PARANOID_MALLOC_CHECKER) -#ifdef strndup -#undef strndup -#endif -#define strndup(s,n) __ERROR_DONT_USE_STRNDUP_DIRECTLY -#endif - if (!s1) { - smb_panic("smb_xstrndup: malloc failed"); - } - return s1; -} - /* vasprintf that aborts on malloc fail */ @@ -2506,7 +2236,7 @@ char *smb_xstrndup(const char *s, size_t n) int n; va_list ap2; - VA_COPY(ap2, ap); + va_copy(ap2, ap); n = vasprintf(ptr, format, ap2); if (n == -1 || ! *ptr) { @@ -2517,22 +2247,6 @@ char *smb_xstrndup(const char *s, size_t n) } /***************************************************************** - Like strdup but for memory. -*****************************************************************/ - -void *memdup(const void *p, size_t size) -{ - void *p2; - if (size == 0) - return NULL; - p2 = SMB_MALLOC(size); - if (!p2) - return NULL; - memcpy(p2, p, size); - return p2; -} - -/***************************************************************** Get local hostname and cache result. *****************************************************************/ @@ -2542,7 +2256,7 @@ char *myhostname(void) if (ret == NULL) { /* This is cached forever so * use NULL talloc ctx. */ - ret = get_myname(NULL); + ret = talloc_get_myname(NULL); } return ret; } @@ -2561,7 +2275,7 @@ static char *xx_path(const char *name, const char *rootpath) } trim_string(fname,"","/"); - if (!directory_exist(fname,NULL)) { + if (!directory_exist(fname)) { mkdir(fname,0755); } @@ -2972,25 +2686,6 @@ bool name_to_fqdn(fstring fqdn, const char *name) } /********************************************************************** - Extension to talloc_get_type: Abort on type mismatch -***********************************************************************/ - -void *talloc_check_name_abort(const void *ptr, const char *name) -{ - void *result; - - result = talloc_check_name(ptr, name); - if (result != NULL) - return result; - - DEBUG(0, ("Talloc type mismatch, expected %s, got %s\n", - name, talloc_get_name(ptr))); - smb_panic("talloc type mismatch"); - /* Keep the compiler happy */ - return NULL; -} - -/********************************************************************** Append a DATA_BLOB to a talloc'ed object ***********************************************************************/ |