From dfc517b05395d925a4d7b1ce9633a849f9468e70 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 23 Feb 2006 15:52:24 +0000 Subject: r13658: More moving around of files: - Collect the generic utility functions into a lib/util/ (a la GLib is for the GNOME folks) - Remove even more files from include/ (This used to be commit ba62880f5b05c2a505dc7f54676b231197a7e707) --- source4/lib/util/README | 296 ++++++++++ source4/lib/util/byteorder.h | 224 ++++++++ source4/lib/util/capability.c | 112 ++++ source4/lib/util/config.mk | 34 ++ source4/lib/util/data_blob.c | 209 +++++++ source4/lib/util/debug.c | 205 +++++++ source4/lib/util/debug.h | 66 +++ source4/lib/util/dprintf.c | 107 ++++ source4/lib/util/fault.c | 213 +++++++ source4/lib/util/fsusage.c | 149 +++++ source4/lib/util/genrand.c | 314 ++++++++++ source4/lib/util/idtree.c | 384 +++++++++++++ source4/lib/util/module.c | 97 ++++ source4/lib/util/ms_fnmatch.c | 219 +++++++ source4/lib/util/mutex.c | 52 ++ source4/lib/util/mutex.h | 71 +++ source4/lib/util/pidfile.c | 116 ++++ source4/lib/util/safe_string.h | 55 ++ source4/lib/util/select.c | 169 ++++++ source4/lib/util/signal.c | 140 +++++ source4/lib/util/substitute.c | 165 ++++++ source4/lib/util/system.c | 98 ++++ source4/lib/util/time.c | 596 +++++++++++++++++++ source4/lib/util/unix_privs.c | 68 +++ source4/lib/util/util.c | 737 ++++++++++++++++++++++++ source4/lib/util/util.h | 81 +++ source4/lib/util/util_file.c | 385 +++++++++++++ source4/lib/util/util_getent.c | 284 +++++++++ source4/lib/util/util_pw.c | 89 +++ source4/lib/util/util_sock.c | 128 +++++ source4/lib/util/util_str.c | 1209 +++++++++++++++++++++++++++++++++++++++ source4/lib/util/util_strlist.c | 292 ++++++++++ source4/lib/util/util_unistr.c | 150 +++++ source4/lib/util/xfile.c | 384 +++++++++++++ source4/lib/util/xfile.h | 49 ++ 35 files changed, 7947 insertions(+) create mode 100644 source4/lib/util/README create mode 100644 source4/lib/util/byteorder.h create mode 100644 source4/lib/util/capability.c create mode 100644 source4/lib/util/config.mk create mode 100644 source4/lib/util/data_blob.c create mode 100644 source4/lib/util/debug.c create mode 100644 source4/lib/util/debug.h create mode 100644 source4/lib/util/dprintf.c create mode 100644 source4/lib/util/fault.c create mode 100644 source4/lib/util/fsusage.c create mode 100644 source4/lib/util/genrand.c create mode 100644 source4/lib/util/idtree.c create mode 100644 source4/lib/util/module.c create mode 100644 source4/lib/util/ms_fnmatch.c create mode 100644 source4/lib/util/mutex.c create mode 100644 source4/lib/util/mutex.h create mode 100644 source4/lib/util/pidfile.c create mode 100644 source4/lib/util/safe_string.h create mode 100644 source4/lib/util/select.c create mode 100644 source4/lib/util/signal.c create mode 100644 source4/lib/util/substitute.c create mode 100644 source4/lib/util/system.c create mode 100644 source4/lib/util/time.c create mode 100644 source4/lib/util/unix_privs.c create mode 100644 source4/lib/util/util.c create mode 100644 source4/lib/util/util.h create mode 100644 source4/lib/util/util_file.c create mode 100644 source4/lib/util/util_getent.c create mode 100644 source4/lib/util/util_pw.c create mode 100644 source4/lib/util/util_sock.c create mode 100644 source4/lib/util/util_str.c create mode 100644 source4/lib/util/util_strlist.c create mode 100644 source4/lib/util/util_unistr.c create mode 100644 source4/lib/util/xfile.c create mode 100644 source4/lib/util/xfile.h (limited to 'source4/lib/util') diff --git a/source4/lib/util/README b/source4/lib/util/README new file mode 100644 index 0000000000..e52e04ed92 --- /dev/null +++ b/source4/lib/util/README @@ -0,0 +1,296 @@ +This directory contains convenience functions that are used heavily +throughout Samba. None of these functions are SMB or Samba-specific. +It's a bit to Samba what GLib is to the GNOME folks. + +(This file should be migrated to doxygen sometime.. ) + +Also TODO: Remove dependency on loadparm + +XFILE wrapper functions +======================= +The XFILE implementation contains a clone of the standard UNIX stdio +functions + +Debug functions +=============== +DEBUG() + +Crash handlers +============== +void smb_panic(const char *why); + +Signal handling +======================== +void BlockSignals(BOOL block,int signum); +void (*CatchSignal(int signum,void (*handler)(int )))(int); +void CatchChild(void); +void CatchChildLeaveStatus(void); + +Wrappers +======== +struct hostent *sys_gethostbyname(const char *name); +const char *sys_inet_ntoa(struct ipv4_addr in); +struct ipv4_addr sys_inet_makeaddr(int net, int host); +void sys_select_signal(void); +int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval); +int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval); + +Time datastructures +=================== +time_t get_time_t_max(void); +void GetTimeOfDay(struct timeval *tval); +time_t nt_time_to_unix(NTTIME nt); +void unix_to_nt_time(NTTIME *nt, time_t t); +BOOL null_time(time_t t); +BOOL null_nttime(NTTIME t); +void push_dos_date(uint8_t *buf, int offset, time_t unixdate, int zone_offset); +void push_dos_date2(uint8_t *buf,int offset,time_t unixdate, int zone_offset); +void push_dos_date3(uint8_t *buf,int offset,time_t unixdate, int zone_offset); +time_t pull_dos_date(const uint8_t *date_ptr, int zone_offset); +time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset); +time_t pull_dos_date3(const uint8_t *date_ptr, int zone_offset); +char *http_timestring(TALLOC_CTX *mem_ctx, time_t t); +char *timestring(TALLOC_CTX *mem_ctx, time_t t); +const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt); +void push_nttime(uint8_t *base, uint16_t offset, NTTIME t); +NTTIME pull_nttime(uint8_t *base, uint16_t offset); +NTTIME nttime_from_string(const char *s); +int64_t usec_time_diff(struct timeval *tv1, struct timeval *tv2); +struct timeval timeval_zero(void); +BOOL timeval_is_zero(const struct timeval *tv); +struct timeval timeval_current(void); +struct timeval timeval_set(uint32_t secs, uint32_t usecs); +struct timeval timeval_add(const struct timeval *tv, + uint32_t secs, uint32_t usecs); +struct timeval timeval_sum(const struct timeval *tv1, + const struct timeval *tv2); +struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs); +int timeval_compare(const struct timeval *tv1, const struct timeval *tv2); +BOOL timeval_expired(const struct timeval *tv); +double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2); +double timeval_elapsed(const struct timeval *tv); +struct timeval timeval_min(const struct timeval *tv1, + const struct timeval *tv2); +struct timeval timeval_max(const struct timeval *tv1, + const struct timeval *tv2); +struct timeval timeval_until(const struct timeval *tv1, + const struct timeval *tv2); +NTTIME timeval_to_nttime(const struct timeval *tv); +int get_time_zone(time_t t); + +Random number generation +======================== +void set_rand_reseed_callback(void (*fn)(int *)); +void set_need_random_reseed(void); +void generate_random_buffer(uint8_t *out, int len); +uint32_t generate_random(void); +BOOL check_password_quality(const char *s); +char *generate_random_str_list(TALLOC_CTX *mem_ctx, size_t len, const char *list); +char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len); + +String manipulation +=================== +BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize); +int strcasecmp_m(const char *s1, const char *s2); +BOOL strequal(const char *s1, const char *s2); +BOOL strcsequal(const char *s1,const char *s2); +int strwicmp(const char *psz1, const char *psz2); +void string_replace(char *s, char oldc, char newc); +BOOL trim_string(char *s,const char *front,const char *back); +size_t count_chars(const char *s, char c); +char *safe_strcpy(char *dest,const char *src, size_t maxlength); +char *safe_strcat(char *dest, const char *src, size_t maxlength); +char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength); +char *StrnCpy(char *dest,const char *src,size_t n); +size_t strhex_to_str(char *p, size_t len, const char *strhex); +DATA_BLOB strhex_to_data_blob(const char *strhex) ; +void hex_encode(const unsigned char *buff_in, size_t len, char **out_hex_buffer); +BOOL in_list(const char *s, const char *list, BOOL casesensitive); +void string_free(char **s); +BOOL string_set(char **dest, const char *src); +void string_sub(char *s,const char *pattern, const char *insert, size_t len); +void all_string_sub(char *s,const char *pattern,const char *insert, size_t len); +char *strchr_m(const char *s, char c); +char *strrchr_m(const char *s, char c); +BOOL strhaslower(const char *string); +BOOL strhasupper(const char *string); +char *strlower_talloc(TALLOC_CTX *ctx, const char *src); +char *strupper_talloc(TALLOC_CTX *ctx, const char *src); +void strlower_m(char *s); +void strupper_m(char *s); +size_t strlen_m(const char *s); +size_t strlen_m_term(const char *s); +void rfc1738_unescape(char *buf); +DATA_BLOB base64_decode_data_blob(TALLOC_CTX *mem_ctx, const char *s); +void base64_decode_inplace(char *s); +char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data); +size_t valgrind_strlen(const char *s); +const char *str_format_nbt_domain(TALLOC_CTX *mem_ctx, const char *s); +BOOL add_string_to_array(TALLOC_CTX *mem_ctx, + const char *str, const char ***strings, int *num); +int strcmp_safe(const char *s1, const char *s2); +size_t ascii_len_n(const char *src, size_t n); +char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib); +BOOL set_boolean(const char *boolean_string, BOOL *boolean); +BOOL conv_str_bool(const char * str, BOOL * val); +BOOL conv_str_size(const char * str, uint64_t * val); +BOOL conv_str_u64(const char * str, uint64_t * val); + +String list manipulation +======================== +const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep); +const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const char *sep); +char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator); +char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep); +size_t str_list_length(const char **list); +const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list); +BOOL str_list_equal(const char **list1, const char **list2); +const char **str_list_add(const char **list, const char *s); +void str_list_remove(const char **list, const char *s); +BOOL str_list_check(const char **list, const char *s); +BOOL str_list_check_ci(const char **list, const char *s); + +Unicode string manipulation +=========================== +codepoint_t toupper_w(codepoint_t val); +codepoint_t tolower_w(codepoint_t val); +size_t utf16_len(const void *buf); +size_t utf16_len_n(const void *src, size_t n); +size_t ucs2_align(const void *base_ptr, const void *p, int flags); +int codepoint_cmpi(codepoint_t c1, codepoint_t c2); + +File manipulation +================= +char *fgets_slash(char *s2,int maxlen,XFILE *f); +char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint); +char *fd_load(int fd, size_t *size, TALLOC_CTX *mem_ctx); +char *file_load(const char *fname, size_t *size, TALLOC_CTX *mem_ctx); +void *map_file(const char *fname, size_t size); +char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx); +char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx); +void file_lines_slashcont(char **lines); +BOOL file_save(const char *fname, const void *packet, size_t length); +BOOL file_exists(const char *path); +int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0); +int fdprintf(int fd, const char *format, ...) _PRINTF_ATTRIBUTE(2,3); + +Data Blob +========= +DATA_BLOB data_blob_named(const void *p, size_t length, const char *name); +DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name); +DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob); +DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length); +void data_blob_free(DATA_BLOB *d); +void data_blob_clear(DATA_BLOB *d); +void data_blob_clear_free(DATA_BLOB *d); +BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2); +char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob); +DATA_BLOB data_blob_string_const(const char *str); +DATA_BLOB data_blob_const(const void *p, size_t length); +NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length); +NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, + const void *p, size_t length); + +Random Utility functions +======================== +const char *tmpdir(void); +BOOL file_exist(const char *fname); +time_t file_modtime(const char *fname); +BOOL directory_exist(const char *dname); +BOOL directory_create_or_exist(const char *dname, uid_t uid, + mode_t dir_perms); +int set_blocking(int fd, BOOL set); +void msleep(uint_t t); +void become_daemon(BOOL Fork); +void safe_free(void *p); +BOOL is_myname(const char *name); +char* get_myname(void); +BOOL is_ipaddress(const char *str); +uint32_t interpret_addr(const char *str); +struct ipv4_addr interpret_addr2(const char *str); +BOOL is_zero_ip(struct ipv4_addr ip); +BOOL same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask); +BOOL process_exists(pid_t pid); +BOOL fcntl_lock(int fd, int op, off_t offset, off_t count, int type); +void dump_data(int level, const uint8_t *buf,int len); +void *smb_xmalloc(size_t size); +void *smb_xmemdup(const void *p, size_t size); +char *smb_xstrdup(const char *s); +void *memdup(const void *p, size_t size); +char *lock_path(TALLOC_CTX* mem_ctx, const char *name); +char *lib_path(TALLOC_CTX* mem_ctx, const char *name); +char *private_path(TALLOC_CTX* mem_ctx, const char *name); +char *smbd_tmp_path(TALLOC_CTX *mem_ctx, const char *name); +init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem); +void dump_data_pw(const char *msg, const uint8_t * data, size_t len); +BOOL all_zero(const uint8_t *ptr, uint_t size); +void *realloc_array(void *ptr, size_t el_size, unsigned count); + +/* The following definitions come from lib/util/util_sock.c */ + +void set_socket_options(int fd, const char *options); + +Variable substitution +===================== +void sub_set_context(struct substitute_context *subptr); +void sub_set_remote_proto(const char *str); +void sub_set_remote_arch(const char *str); +void sub_set_user_name(const char *name); +void standard_sub_basic(char *str,size_t len); +char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name, const char *str); +char *alloc_sub_basic(const char *smb_name, const char *str); +char *talloc_sub_specified(TALLOC_CTX *mem_ctx, + const char *input_string, + const char *username, + const char *domain, + uid_t uid, + gid_t gid); +char *alloc_sub_specified(const char *input_string, + const char *username, + const char *domain, + uid_t uid, + gid_t gid); +char *talloc_sub_advanced(TALLOC_CTX *mem_ctx, + int snum, + const char *user, + const char *connectpath, + gid_t gid, + const char *smb_name, + char *str); +char *alloc_sub_advanced(int snum, const char *user, + const char *connectpath, gid_t gid, + const char *smb_name, char *str); +void standard_sub_tcon(struct smbsrv_tcon *tcon, char *str, size_t len); +char *talloc_sub_tcon(TALLOC_CTX *mem_ctx, struct smbsrv_tcon *tcon, char *str); +char *alloc_sub_tcon(struct smbsrv_tcon *tcon, char *str); +void standard_sub_snum(int snum, char *str, size_t len); + +/* The following definitions come from lib/util/fsusage.c */ + +int sys_fsusage(const char *path, uint64_t *dfree, uint64_t *dsize); + +Microsoft-style filename matching +================================= +int ms_fnmatch(const char *pattern, const char *string, enum protocol_types protocol); +int gen_fnmatch(const char *pattern, const char *string); + +Mutexes +======= +BOOL register_mutex_handlers(const char *name, struct mutex_ops *ops); + +Idtree +====== +very efficient functions to manage mapping a id (such as a fnum) to +a pointer. This is used for fnum and search id allocation. + +struct idr_context *idr_init(TALLOC_CTX *mem_ctx); +int idr_get_new(struct idr_context *idp, void *ptr, int limit); +int idr_get_new_above(struct idr_context *idp, void *ptr, int starting_id, int limit); +int idr_get_new_random(struct idr_context *idp, void *ptr, int limit); +void *idr_find(struct idr_context *idp, int id); +int idr_remove(struct idr_context *idp, int id); + +Module loading +============== +init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path); +BOOL run_init_functions(NTSTATUS (**fns) (void)); diff --git a/source4/lib/util/byteorder.h b/source4/lib/util/byteorder.h new file mode 100644 index 0000000000..941dee9e88 --- /dev/null +++ b/source4/lib/util/byteorder.h @@ -0,0 +1,224 @@ +/* + Unix SMB/CIFS implementation. + SMB Byte handling + Copyright (C) Andrew Tridgell 1992-1998 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef _BYTEORDER_H +#define _BYTEORDER_H + +/* + This file implements macros for machine independent short and + int manipulation + +Here is a description of this file that I emailed to the samba list once: + +> I am confused about the way that byteorder.h works in Samba. I have +> looked at it, and I would have thought that you might make a distinction +> between LE and BE machines, but you only seem to distinguish between 386 +> and all other architectures. +> +> Can you give me a clue? + +sure. + +The distinction between 386 and other architectures is only there as +an optimisation. You can take it out completely and it will make no +difference. The routines (macros) in byteorder.h are totally byteorder +independent. The 386 optimsation just takes advantage of the fact that +the x86 processors don't care about alignment, so we don't have to +align ints on int boundaries etc. If there are other processors out +there that aren't alignment sensitive then you could also define +CAREFUL_ALIGNMENT=0 on those processors as well. + +Ok, now to the macros themselves. I'll take a simple example, say we +want to extract a 2 byte integer from a SMB packet and put it into a +type called uint16_t that is in the local machines byte order, and you +want to do it with only the assumption that uint16_t is _at_least_ 16 +bits long (this last condition is very important for architectures +that don't have any int types that are 2 bytes long) + +You do this: + +#define CVAL(buf,pos) (((uint8_t *)(buf))[pos]) +#define PVAL(buf,pos) ((uint_t)CVAL(buf,pos)) +#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8) + +then to extract a uint16_t value at offset 25 in a buffer you do this: + +char *buffer = foo_bar(); +uint16_t xx = SVAL(buffer,25); + +We are using the byteoder independence of the ANSI C bitshifts to do +the work. A good optimising compiler should turn this into efficient +code, especially if it happens to have the right byteorder :-) + +I know these macros can be made a bit tidier by removing some of the +casts, but you need to look at byteorder.h as a whole to see the +reasoning behind them. byteorder.h defines the following macros: + +SVAL(buf,pos) - extract a 2 byte SMB value +IVAL(buf,pos) - extract a 4 byte SMB value +SVALS(buf,pos) signed version of SVAL() +IVALS(buf,pos) signed version of IVAL() + +SSVAL(buf,pos,val) - put a 2 byte SMB value into a buffer +SIVAL(buf,pos,val) - put a 4 byte SMB value into a buffer +SSVALS(buf,pos,val) - signed version of SSVAL() +SIVALS(buf,pos,val) - signed version of SIVAL() + +RSVAL(buf,pos) - like SVAL() but for NMB byte ordering +RSVALS(buf,pos) - like SVALS() but for NMB byte ordering +RIVAL(buf,pos) - like IVAL() but for NMB byte ordering +RIVALS(buf,pos) - like IVALS() but for NMB byte ordering +RSSVAL(buf,pos,val) - like SSVAL() but for NMB ordering +RSIVAL(buf,pos,val) - like SIVAL() but for NMB ordering +RSIVALS(buf,pos,val) - like SIVALS() but for NMB ordering + +it also defines lots of intermediate macros, just ignore those :-) + +*/ + + +/* + on powerpc we can use the magic instructions to load/store + in little endian +*/ +#if (defined(__powerpc__) && defined(__GNUC__)) +static __inline__ uint16_t ld_le16(const uint16_t *addr) +{ + uint16_t val; + __asm__ ("lhbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr)); + return val; +} + +static __inline__ void st_le16(uint16_t *addr, const uint16_t val) +{ + __asm__ ("sthbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr)); +} + +static __inline__ uint32_t ld_le32(const uint32_t *addr) +{ + uint32_t val; + __asm__ ("lwbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr)); + return val; +} + +static __inline__ void st_le32(uint32_t *addr, const uint32_t val) +{ + __asm__ ("stwbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr)); +} +#define HAVE_ASM_BYTEORDER 1 +#endif + + + +#undef CAREFUL_ALIGNMENT + +/* we know that the 386 can handle misalignment and has the "right" + byteorder */ +#if defined(__i386__) +#define CAREFUL_ALIGNMENT 0 +#endif + +#ifndef CAREFUL_ALIGNMENT +#define CAREFUL_ALIGNMENT 1 +#endif + +#define CVAL(buf,pos) ((uint_t)(((const uint8_t *)(buf))[pos])) +#define CVAL_NC(buf,pos) (((uint8_t *)(buf))[pos]) /* Non-const version of CVAL */ +#define PVAL(buf,pos) (CVAL(buf,pos)) +#define SCVAL(buf,pos,val) (CVAL_NC(buf,pos) = (val)) + +#if HAVE_ASM_BYTEORDER + +#define _PTRPOS(buf,pos) (((const uint8_t *)buf)+(pos)) +#define SVAL(buf,pos) ld_le16((const uint16_t *)_PTRPOS(buf,pos)) +#define IVAL(buf,pos) ld_le32((const uint32_t *)_PTRPOS(buf,pos)) +#define SSVAL(buf,pos,val) st_le16((uint16_t *)_PTRPOS(buf,pos), val) +#define SIVAL(buf,pos,val) st_le32((uint32_t *)_PTRPOS(buf,pos), val) +#define SVALS(buf,pos) ((int16_t)SVAL(buf,pos)) +#define IVALS(buf,pos) ((int32_t)IVAL(buf,pos)) +#define SSVALS(buf,pos,val) SSVAL((buf),(pos),((int16_t)(val))) +#define SIVALS(buf,pos,val) SIVAL((buf),(pos),((int32_t)(val))) + +#elif CAREFUL_ALIGNMENT + +#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8) +#define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16) +#define SSVALX(buf,pos,val) (CVAL_NC(buf,pos)=(uint8_t)((val)&0xFF),CVAL_NC(buf,pos+1)=(uint8_t)((val)>>8)) +#define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16)) +#define SVALS(buf,pos) ((int16_t)SVAL(buf,pos)) +#define IVALS(buf,pos) ((int32_t)IVAL(buf,pos)) +#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16_t)(val))) +#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32_t)(val))) +#define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16_t)(val))) +#define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32_t)(val))) + +#else /* CAREFUL_ALIGNMENT */ + +/* this handles things for architectures like the 386 that can handle + alignment errors */ +/* + WARNING: This section is dependent on the length of int16_t and int32_t + being correct +*/ + +/* get single value from an SMB buffer */ +#define SVAL(buf,pos) (*(const uint16_t *)((const char *)(buf) + (pos))) +#define SVAL_NC(buf,pos) (*(uint16_t *)((char *)(buf) + (pos))) /* Non const version of above. */ +#define IVAL(buf,pos) (*(const uint32_t *)((const char *)(buf) + (pos))) +#define IVAL_NC(buf,pos) (*(uint32_t *)((char *)(buf) + (pos))) /* Non const version of above. */ +#define SVALS(buf,pos) (*(const int16_t *)((const char *)(buf) + (pos))) +#define SVALS_NC(buf,pos) (*(int16_t *)((char *)(buf) + (pos))) /* Non const version of above. */ +#define IVALS(buf,pos) (*(const int32_t *)((const char *)(buf) + (pos))) +#define IVALS_NC(buf,pos) (*(int32_t *)((char *)(buf) + (pos))) /* Non const version of above. */ + +/* store single value in an SMB buffer */ +#define SSVAL(buf,pos,val) SVAL_NC(buf,pos)=((uint16_t)(val)) +#define SIVAL(buf,pos,val) IVAL_NC(buf,pos)=((uint32_t)(val)) +#define SSVALS(buf,pos,val) SVALS_NC(buf,pos)=((int16_t)(val)) +#define SIVALS(buf,pos,val) IVALS_NC(buf,pos)=((int32_t)(val)) + +#endif /* CAREFUL_ALIGNMENT */ + +/* now the reverse routines - these are used in nmb packets (mostly) */ +#define SREV(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF)) +#define IREV(x) ((SREV(x)<<16) | (SREV((x)>>16))) + +#define RSVAL(buf,pos) SREV(SVAL(buf,pos)) +#define RSVALS(buf,pos) SREV(SVALS(buf,pos)) +#define RIVAL(buf,pos) IREV(IVAL(buf,pos)) +#define RIVALS(buf,pos) IREV(IVALS(buf,pos)) +#define RSSVAL(buf,pos,val) SSVAL(buf,pos,SREV(val)) +#define RSSVALS(buf,pos,val) SSVALS(buf,pos,SREV(val)) +#define RSIVAL(buf,pos,val) SIVAL(buf,pos,IREV(val)) +#define RSIVALS(buf,pos,val) SIVALS(buf,pos,IREV(val)) + +/* Alignment macros. */ +#define ALIGN4(p,base) ((p) + ((4 - (PTR_DIFF((p), (base)) & 3)) & 3)) +#define ALIGN2(p,base) ((p) + ((2 - (PTR_DIFF((p), (base)) & 1)) & 1)) + + +/* macros for accessing SMB protocol elements */ +#define VWV(vwv) ((vwv)*2) + +/* 64 bit macros */ +#define SBVAL(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,((uint64_t)(v))>>32)) +#define BVAL(p, ofs) (IVAL(p,ofs) | (((uint64_t)IVAL(p,(ofs)+4)) << 32)) + +#endif /* _BYTEORDER_H */ diff --git a/source4/lib/util/capability.c b/source4/lib/util/capability.c new file mode 100644 index 0000000000..0cebd33303 --- /dev/null +++ b/source4/lib/util/capability.c @@ -0,0 +1,112 @@ +/* + Unix SMB/CIFS implementation. + + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Jeremy Allison 1998-2002 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* + capabilities fns - will be needed when we enable kernel oplocks +*/ + +#include "includes.h" +#include "system/network.h" +#include "system/wait.h" +#include "system/filesys.h" + + +#if defined(HAVE_IRIX_SPECIFIC_CAPABILITIES) +/************************************************************************** + Try and abstract process capabilities (for systems that have them). +****************************************************************************/ +static BOOL set_process_capability( uint32_t cap_flag, BOOL enable ) +{ + if(cap_flag == KERNEL_OPLOCK_CAPABILITY) { + cap_t cap = cap_get_proc(); + + if (cap == NULL) { + DEBUG(0,("set_process_capability: cap_get_proc failed. Error was %s\n", + strerror(errno))); + return False; + } + + if(enable) + cap->cap_effective |= CAP_NETWORK_MGT; + else + cap->cap_effective &= ~CAP_NETWORK_MGT; + + if (cap_set_proc(cap) == -1) { + DEBUG(0,("set_process_capability: cap_set_proc failed. Error was %s\n", + strerror(errno))); + cap_free(cap); + return False; + } + + cap_free(cap); + + DEBUG(10,("set_process_capability: Set KERNEL_OPLOCK_CAPABILITY.\n")); + } + return True; +} + +/************************************************************************** + Try and abstract inherited process capabilities (for systems that have them). +****************************************************************************/ + +static BOOL set_inherited_process_capability( uint32_t cap_flag, BOOL enable ) +{ + if(cap_flag == KERNEL_OPLOCK_CAPABILITY) { + cap_t cap = cap_get_proc(); + + if (cap == NULL) { + DEBUG(0,("set_inherited_process_capability: cap_get_proc failed. Error was %s\n", + strerror(errno))); + return False; + } + + if(enable) + cap->cap_inheritable |= CAP_NETWORK_MGT; + else + cap->cap_inheritable &= ~CAP_NETWORK_MGT; + + if (cap_set_proc(cap) == -1) { + DEBUG(0,("set_inherited_process_capability: cap_set_proc failed. Error was %s\n", + strerror(errno))); + cap_free(cap); + return False; + } + + cap_free(cap); + + DEBUG(10,("set_inherited_process_capability: Set KERNEL_OPLOCK_CAPABILITY.\n")); + } + return True; +} +#endif + +/**************************************************************************** + Gain the oplock capability from the kernel if possible. +****************************************************************************/ + +void oplock_set_capability(BOOL this_process, BOOL inherit) +{ +#if HAVE_KERNEL_OPLOCKS_IRIX + set_process_capability(KERNEL_OPLOCK_CAPABILITY,this_process); + set_inherited_process_capability(KERNEL_OPLOCK_CAPABILITY,inherit); +#endif +} + diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk new file mode 100644 index 0000000000..79e145775d --- /dev/null +++ b/source4/lib/util/config.mk @@ -0,0 +1,34 @@ +[SUBSYSTEM::LIBBASIC] +PRIVATE_PROTO_HEADER = util_proto.h +PUBLIC_HEADERS = util.h +OBJ_FILES = xfile.o \ + debug.o \ + fault.o \ + signal.o \ + system.o \ + time.o \ + genrand.o \ + dprintf.o \ + util_str.o \ + util_strlist.o \ + util_unistr.o \ + util_file.o \ + data_blob.o \ + util.o \ + util_sock.o \ + substitute.o \ + fsusage.o \ + ms_fnmatch.o \ + select.o \ + mutex.o \ + idtree.o \ + module.o +REQUIRED_SUBSYSTEMS = \ + CHARSET LIBREPLACE LIBCRYPTO EXT_LIB_DL LIBTALLOC \ + SOCKET_WRAPPER CONFIG + +[SUBSYSTEM::PIDFILE] +OBJ_FILES = pidfile.o + +[SUBSYSTEM::UNIX_PRIVS] +OBJ_FILES = unix_privs.o diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c new file mode 100644 index 0000000000..c6471fbf54 --- /dev/null +++ b/source4/lib/util/data_blob.c @@ -0,0 +1,209 @@ +/* + Unix SMB/CIFS implementation. + Easy management of byte-length data + Copyright (C) Andrew Tridgell 2001 + Copyright (C) Andrew Bartlett 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/******************************************************************* + construct a data blob, must be freed with data_blob_free() + you can pass NULL for p and get a blank data blob +*******************************************************************/ +DATA_BLOB data_blob_named(const void *p, size_t length, const char *name) +{ + DATA_BLOB ret; + + if (p == NULL && length == 0) { + ZERO_STRUCT(ret); + return ret; + } + + if (p) { + ret.data = talloc_memdup(NULL, p, length); + } else { + ret.data = talloc_size(NULL, length); + } + if (ret.data == NULL) { + ret.length = 0; + return ret; + } + talloc_set_name_const(ret.data, name); + ret.length = length; + return ret; +} + +/******************************************************************* + construct a data blob, using supplied TALLOC_CTX +*******************************************************************/ +DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name) +{ + DATA_BLOB ret = data_blob_named(p, length, name); + + if (ret.data) { + talloc_steal(mem_ctx, ret.data); + } + return ret; +} + + +/******************************************************************* + reference a data blob, to the supplied TALLOC_CTX. + Returns a NULL DATA_BLOB on failure +*******************************************************************/ +DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) +{ + DATA_BLOB ret = *blob; + + ret.data = talloc_reference(mem_ctx, blob->data); + + if (!ret.data) { + return data_blob(NULL, 0); + } + return ret; +} + +/******************************************************************* + construct a zero data blob, using supplied TALLOC_CTX. + use this sparingly as it initialises data - better to initialise + yourself if you want specific data in the blob +*******************************************************************/ +DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) +{ + DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, length); + data_blob_clear(&blob); + return blob; +} + +/******************************************************************* +free a data blob +*******************************************************************/ +void data_blob_free(DATA_BLOB *d) +{ + if (d) { + talloc_free(d->data); + d->data = NULL; + d->length = 0; + } +} + +/******************************************************************* +clear a DATA_BLOB's contents +*******************************************************************/ +void data_blob_clear(DATA_BLOB *d) +{ + if (d->data) { + memset(d->data, 0, d->length); + } +} + +/******************************************************************* +free a data blob and clear its contents +*******************************************************************/ +void data_blob_clear_free(DATA_BLOB *d) +{ + data_blob_clear(d); + data_blob_free(d); +} + + +/******************************************************************* +check if two data blobs are equal +*******************************************************************/ +BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) +{ + if (d1->length != d2->length) { + return False; + } + if (d1->data == d2->data) { + return True; + } + if (d1->data == NULL || d2->data == NULL) { + return False; + } + if (memcmp(d1->data, d2->data, d1->length) == 0) { + return True; + } + return False; +} + +/******************************************************************* +print the data_blob as hex string +*******************************************************************/ +char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) +{ + int i; + char *hex_string; + + hex_string = talloc_array(mem_ctx, char, (blob->length*2)+1); + if (!hex_string) { + return NULL; + } + + for (i = 0; i < blob->length; i++) + slprintf(&hex_string[i*2], 3, "%02X", blob->data[i]); + + return hex_string; +} + +/* + useful for constructing data blobs in test suites, while + avoiding const warnings +*/ +DATA_BLOB data_blob_string_const(const char *str) +{ + DATA_BLOB blob; + blob.data = discard_const(str); + blob.length = strlen(str); + return blob; +} + +DATA_BLOB data_blob_const(const void *p, size_t length) +{ + DATA_BLOB blob; + blob.data = discard_const(p); + blob.length = length; + return blob; +} + + +/* + realloc a data_blob +*/ +NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) +{ + blob->data = talloc_realloc_size(mem_ctx, blob->data, length); + NT_STATUS_HAVE_NO_MEMORY(blob->data); + blob->length = length; + return NT_STATUS_OK; +} + +/* + append some data to a data blob +*/ +NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, + const void *p, size_t length) +{ + blob->data = talloc_realloc_size(mem_ctx, blob->data, + blob->length + length); + NT_STATUS_HAVE_NO_MEMORY(blob->data); + memcpy(blob->data + blob->length, p, length); + blob->length += length; + return NT_STATUS_OK; +} + diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c new file mode 100644 index 0000000000..9df6e573b0 --- /dev/null +++ b/source4/lib/util/debug.c @@ -0,0 +1,205 @@ +/* + Unix SMB/CIFS implementation. + Samba debug functions + Copyright (C) Andrew Tridgell 2003 + Copyright (C) James J Myers 2003 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/filesys.h" +#include "system/time.h" +#include "dynconfig.h" + +/* this global variable determines what messages are printed */ +int DEBUGLEVEL; + + +/* the registered mutex handlers */ +static struct { + const char *name; + struct debug_ops ops; +} debug_handlers; + +/* state variables for the debug system */ +static struct { + int fd; + enum debug_logtype logtype; + const char *prog_name; +} state; + +/* + the backend for debug messages. Note that the DEBUG() macro has already + ensured that the log level has been met before this is called +*/ +void do_debug_header(int level, const char *location, const char *func) +{ + log_timestring(level, location, func); + log_task_id(); +} + +/* + the backend for debug messages. Note that the DEBUG() macro has already + ensured that the log level has been met before this is called +*/ +void do_debug(const char *format, ...) +{ + va_list ap; + char *s = NULL; + + if (state.fd == 0) { + reopen_logs(); + } + + if (state.fd <= 0) return; + + va_start(ap, format); + vasprintf(&s, format, ap); + va_end(ap); + + write(state.fd, s, strlen(s)); + free(s); +} + +/* + reopen the log file (usually called because the log file name might have changed) +*/ +void reopen_logs(void) +{ + const char *logfile = lp_logfile(); + char *fname = NULL; + int old_fd = state.fd; + + switch (state.logtype) { + case DEBUG_STDOUT: + state.fd = 1; + break; + + case DEBUG_STDERR: + state.fd = 2; + break; + + case DEBUG_FILE: + if ((*logfile) == '/') { + fname = strdup(logfile); + } else { + asprintf(&fname, "%s/%s.log", dyn_LOGFILEBASE, state.prog_name); + } + if (fname) { + int newfd = open(fname, O_CREAT|O_APPEND|O_WRONLY, 0600); + if (newfd == -1) { + DEBUG(1, ("Failed to open new logfile: %s\n", fname)); + } else { + state.fd = newfd; + } + free(fname); + } else { + DEBUG(1, ("Failed to find name for file-based logfile!\n")); + } + + break; + } + + if (old_fd > 2) { + close(old_fd); + } +} + +/* + control the name of the logfile and whether logging will be to stdout, stderr + or a file +*/ +void setup_logging(const char *prog_name, enum debug_logtype new_logtype) +{ + if (state.logtype < new_logtype) { + state.logtype = new_logtype; + } + if (prog_name) { + state.prog_name = prog_name; + } + reopen_logs(); +} + +/* + return a string constant containing n tabs + no more than 10 tabs are returned +*/ +const char *do_debug_tab(uint_t n) +{ + const char *tabs[] = {"", "\t", "\t\t", "\t\t\t", "\t\t\t\t", "\t\t\t\t\t", + "\t\t\t\t\t\t", "\t\t\t\t\t\t\t", "\t\t\t\t\t\t\t\t", + "\t\t\t\t\t\t\t\t\t", "\t\t\t\t\t\t\t\t\t\t"}; + return tabs[MIN(n, 10)]; +} + + +/* + log/print suspicious usage - print comments and backtrace +*/ +void log_suspicious_usage(const char *from, const char *info) +{ + if (debug_handlers.ops.log_suspicious_usage) { + debug_handlers.ops.log_suspicious_usage(from, info); + } +} +void print_suspicious_usage(const char* from, const char* info) +{ + if (debug_handlers.ops.print_suspicious_usage) { + debug_handlers.ops.print_suspicious_usage(from, info); + } +} + +void log_timestring(int level, const char *location, const char *func) +{ + char *t = NULL; + char *s = NULL; + + if (state.logtype != DEBUG_FILE) return; + + t = timestring(NULL, time(NULL)); + if (!t) return; + + asprintf(&s, "[%s, %d %s:%s()]\n", t, level, location, func); + talloc_free(t); + if (!s) return; + + write(state.fd, s, strlen(s)); + free(s); +} + +uint32_t get_task_id(void) +{ + if (debug_handlers.ops.get_task_id) { + return debug_handlers.ops.get_task_id(); + } + return getpid(); +} + +void log_task_id(void) +{ + if (debug_handlers.ops.log_task_id) { + debug_handlers.ops.log_task_id(state.fd); + } +} + +/* + register a set of debug handlers. +*/ +void register_debug_handlers(const char *name, struct debug_ops *ops) +{ + debug_handlers.name = name; + debug_handlers.ops = *ops; +} diff --git a/source4/lib/util/debug.h b/source4/lib/util/debug.h new file mode 100644 index 0000000000..8ff937e7b9 --- /dev/null +++ b/source4/lib/util/debug.h @@ -0,0 +1,66 @@ +/* + Unix SMB/CIFS implementation. + Samba debug defines + Copyright (C) Andrew Tridgell 2003 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* If we have these macros, we can add additional info to the header. */ + +#ifdef HAVE_FUNCTION_MACRO +#define FUNCTION_MACRO (__FUNCTION__) +#else +#define FUNCTION_MACRO ("") +#endif + +/* the debug operations structure - contains function pointers to + various debug implementations of each operation */ +struct debug_ops { + /* function to log (using DEBUG) suspicious usage of data structure */ + void (*log_suspicious_usage)(const char* from, const char* info); + + /* function to log (using printf) suspicious usage of data structure. + * To be used in circumstances when using DEBUG would cause loop. */ + void (*print_suspicious_usage)(const char* from, const char* info); + + /* function to return process/thread id */ + uint32_t (*get_task_id)(void); + + /* function to log process/thread id */ + void (*log_task_id)(int fd); +}; + +void do_debug_header(int level, const char *location, const char *func); +void do_debug(const char *, ...) PRINTF_ATTRIBUTE(1,2); + +extern int DEBUGLEVEL; + +#define DEBUGLVL(level) ((level) <= DEBUGLEVEL) +#define _DEBUG(level, body, header) do { \ + if (DEBUGLVL(level)) { \ + if (header) { \ + do_debug_header(level, __location__, FUNCTION_MACRO); \ + } \ + do_debug body; \ + } \ +} while (0) +#define DEBUG(level, body) _DEBUG(level, body, True) +#define DEBUGADD(level, body) _DEBUG(level, body, False) +#define DEBUGC(class, level, body) DEBUG(level, body) +#define DEBUGADDC(class, level, body) DEBUGADD(level, body) +#define DEBUGTAB(n) do_debug_tab(n) + +enum debug_logtype {DEBUG_STDOUT = 0, DEBUG_FILE = 1, DEBUG_STDERR = 2}; diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c new file mode 100644 index 0000000000..64227148fd --- /dev/null +++ b/source4/lib/util/dprintf.c @@ -0,0 +1,107 @@ +/* + Unix SMB/CIFS implementation. + display print functions + Copyright (C) Andrew Tridgell 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + +/* + this module provides functions for printing internal strings in the "display charset" + This charset may be quite different from the chosen unix charset + + Eventually these functions will need to take care of column count constraints + + The d_ prefix on print functions in Samba refers to the display character set + conversion +*/ + +#include "includes.h" + +int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) +{ + char *p, *p2; + int ret, maxlen, clen; + va_list ap2; + + /* do any message translations */ + VA_COPY(ap2, ap); + + ret = vasprintf(&p, format, ap2); + + if (ret <= 0) return ret; + + /* now we have the string in unix format, convert it to the display + charset, but beware of it growing */ + maxlen = ret*2; +again: + p2 = malloc(maxlen); + if (!p2) { + SAFE_FREE(p); + return -1; + } + clen = convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); + + if (clen >= maxlen) { + /* it didn't fit - try a larger buffer */ + maxlen *= 2; + SAFE_FREE(p2); + goto again; + } + + /* good, its converted OK */ + SAFE_FREE(p); + ret = fwrite(p2, 1, clen, f); + SAFE_FREE(p2); + + return ret; +} + + +int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) +{ + int ret; + va_list ap; + + va_start(ap, format); + ret = d_vfprintf(f, format, ap); + va_end(ap); + + return ret; +} + +static FILE *outfile; + +int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) +{ + int ret; + va_list ap; + + if (!outfile) outfile = stdout; + + va_start(ap, format); + ret = d_vfprintf(outfile, format, ap); + va_end(ap); + + return ret; +} + +/* interactive programs need a way of tell d_*() to write to stderr instead + of stdout */ +void display_set_stderr(void) +{ + outfile = stderr; +} diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c new file mode 100644 index 0000000000..3670575dcc --- /dev/null +++ b/source4/lib/util/fault.c @@ -0,0 +1,213 @@ +/* + Unix SMB/CIFS implementation. + Critical Fault handling + Copyright (C) Andrew Tridgell 1992-1998 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "version.h" +#include "system/wait.h" +#include "system/filesys.h" + +/* the registered fault handler */ +static struct { + const char *name; + void (*fault_handler)(int sig); +} fault_handlers; + +static const char *progname; + +#ifdef HAVE_BACKTRACE +#include +#define BACKTRACE_STACK_SIZE 64 +#elif HAVE_LIBEXC_H +#include +#endif + +void call_backtrace(void) +{ +#ifdef HAVE_BACKTRACE +#define BACKTRACE_STACK_SIZE 64 + void *backtrace_stack[BACKTRACE_STACK_SIZE]; + size_t backtrace_size; + char **backtrace_strings; + + /* get the backtrace (stack frames) */ + backtrace_size = backtrace(backtrace_stack,BACKTRACE_STACK_SIZE); + backtrace_strings = backtrace_symbols(backtrace_stack, backtrace_size); + + DEBUG(0, ("BACKTRACE: %lu stack frames:\n", + (unsigned long)backtrace_size)); + + if (backtrace_strings) { + int i; + + for (i = 0; i < backtrace_size; i++) + DEBUGADD(0, (" #%u %s\n", i, backtrace_strings[i])); + + /* Leak the backtrace_strings, rather than risk what free() might do */ + } + +#elif HAVE_LIBEXC + +#define NAMESIZE 32 /* Arbitrary */ + + /* The IRIX libexc library provides an API for unwinding the stack. See + * libexc(3) for details. Apparantly trace_back_stack leaks memory, but + * since we are about to abort anyway, it hardly matters. + * + * Note that if we paniced due to a SIGSEGV or SIGBUS (or similar) this + * will fail with a nasty message upon failing to open the /proc entry. + */ + { + uint64_t addrs[BACKTRACE_STACK_SIZE]; + char * names[BACKTRACE_STACK_SIZE]; + char namebuf[BACKTRACE_STACK_SIZE * NAMESIZE]; + + int i; + int levels; + + ZERO_ARRAY(addrs); + ZERO_ARRAY(names); + ZERO_ARRAY(namebuf); + + for (i = 0; i < BACKTRACE_STACK_SIZE; i++) { + names[i] = namebuf + (i * NAMESIZE); + } + + levels = trace_back_stack(0, addrs, names, + BACKTRACE_STACK_SIZE, NAMESIZE); + + DEBUG(0, ("BACKTRACE: %d stack frames:\n", levels)); + for (i = 0; i < levels; i++) { + DEBUGADD(0, (" #%d 0x%llx %s\n", i, addrs[i], names[i])); + } + } +#undef NAMESIZE +#endif +} + +/******************************************************************* + Something really nasty happened - panic ! +********************************************************************/ +void smb_panic(const char *why) +{ + const char *cmd = lp_panic_action(); + int result; + + if (cmd && *cmd) { + char pidstr[20]; + char cmdstring[200]; + safe_strcpy(cmdstring, cmd, sizeof(cmdstring)); + snprintf(pidstr, sizeof(pidstr), "%u", getpid()); + all_string_sub(cmdstring, "%PID%", pidstr, sizeof(cmdstring)); + if (progname) { + all_string_sub(cmdstring, "%PROG%", progname, sizeof(cmdstring)); + } + DEBUG(0, ("smb_panic(): calling panic action [%s]\n", cmdstring)); + result = system(cmdstring); + + if (result == -1) + DEBUG(0, ("smb_panic(): fork failed in panic action: %s\n", + strerror(errno))); + else + DEBUG(0, ("smb_panic(): action returned status %d\n", + WEXITSTATUS(result))); + } + DEBUG(0,("PANIC: %s\n", why)); + + call_backtrace(); + +#ifdef SIGABRT + CatchSignal(SIGABRT,SIGNAL_CAST SIG_DFL); +#endif + abort(); +} + +/******************************************************************* +report a fault +********************************************************************/ +static void fault_report(int sig) +{ + static int counter; + + if (counter) _exit(1); + + DEBUG(0,("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n")); + DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)getpid(),SAMBA_VERSION_STRING)); + DEBUG(0,("\nPlease read the file BUGS.txt in the distribution\n")); + DEBUG(0,("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n")); + + smb_panic("internal error"); + + exit(1); +} + +/**************************************************************************** +catch serious errors +****************************************************************************/ +static void sig_fault(int sig) +{ + if (fault_handlers.fault_handler) { + /* we have a fault handler, call it. It may not return. */ + fault_handlers.fault_handler(sig); + } + /* If it returns or doean't exist, use regular reporter */ + fault_report(sig); +} + +/******************************************************************* +setup our fault handlers +********************************************************************/ +void fault_setup(const char *pname) +{ + if (progname == NULL) { + progname = pname; + } +#ifdef SIGSEGV + CatchSignal(SIGSEGV,SIGNAL_CAST sig_fault); +#endif +#ifdef SIGBUS + CatchSignal(SIGBUS,SIGNAL_CAST sig_fault); +#endif +#ifdef SIGABRT + CatchSignal(SIGABRT,SIGNAL_CAST sig_fault); +#endif +#ifdef SIGFPE + CatchSignal(SIGFPE,SIGNAL_CAST sig_fault); +#endif +} + +/* + register a fault handler. + Should only be called once in the execution of smbd. +*/ +BOOL register_fault_handler(const char *name, void (*fault_handler)(int sig)) +{ + if (fault_handlers.name != NULL) { + /* it's already registered! */ + DEBUG(2,("fault handler '%s' already registered - failed '%s'\n", + fault_handlers.name, name)); + return False; + } + + fault_handlers.name = name; + fault_handlers.fault_handler = fault_handler; + + DEBUG(2,("fault handler '%s' registered\n", name)); + return True; +} diff --git a/source4/lib/util/fsusage.c b/source4/lib/util/fsusage.c new file mode 100644 index 0000000000..f817672544 --- /dev/null +++ b/source4/lib/util/fsusage.c @@ -0,0 +1,149 @@ +/* + Unix SMB/CIFS implementation. + functions to calculate the free disk space + Copyright (C) Andrew Tridgell 1998-2000 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/filesys.h" + + +/* Return the number of TOSIZE-byte blocks used by + BLOCKS FROMSIZE-byte blocks, rounding away from zero. +*/ +static uint64_t adjust_blocks(uint64_t blocks, uint64_t fromsize, uint64_t tosize) +{ + if (fromsize == tosize) /* e.g., from 512 to 512 */ + return blocks; + else if (fromsize > tosize) /* e.g., from 2048 to 512 */ + return blocks * (fromsize / tosize); + else /* e.g., from 256 to 512 */ + return (blocks + 1) / (tosize / fromsize); +} + +/* this does all of the system specific guff to get the free disk space. + It is derived from code in the GNU fileutils package, but has been + considerably mangled for use here + + results are returned in *dfree and *dsize, in 512 byte units +*/ +int sys_fsusage(const char *path, uint64_t *dfree, uint64_t *dsize) +{ +#ifdef STAT_STATFS3_OSF1 +#define CONVERT_BLOCKS(B) adjust_blocks ((uint64_t)(B), (uint64_t)fsd.f_fsize, (uint64_t)512) + struct statfs fsd; + + if (statfs (path, &fsd, sizeof (struct statfs)) != 0) + return -1; +#endif /* STAT_STATFS3_OSF1 */ + +#ifdef STAT_STATFS2_FS_DATA /* Ultrix */ +#define CONVERT_BLOCKS(B) adjust_blocks ((uint64_t)(B), (uint64_t)1024, (uint64_t)512) + struct fs_data fsd; + + if (statfs (path, &fsd) != 1) + return -1; + + (*dsize) = CONVERT_BLOCKS (fsd.fd_req.btot); + (*dfree) = CONVERT_BLOCKS (fsd.fd_req.bfreen); +#endif /* STAT_STATFS2_FS_DATA */ + +#ifdef STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */ +#define CONVERT_BLOCKS(B) adjust_blocks ((uint64_t)(B), (uint64_t)fsd.f_bsize, (uint64_t)512) + struct statfs fsd; + + if (statfs (path, &fsd) < 0) + return -1; + +#ifdef STATFS_TRUNCATES_BLOCK_COUNTS + /* In SunOS 4.1.2, 4.1.3, and 4.1.3_U1, the block counts in the + struct statfs are truncated to 2GB. These conditions detect that + truncation, presumably without botching the 4.1.1 case, in which + the values are not truncated. The correct counts are stored in + undocumented spare fields. */ + if (fsd.f_blocks == 0x1fffff && fsd.f_spare[0] > 0) { + fsd.f_blocks = fsd.f_spare[0]; + fsd.f_bfree = fsd.f_spare[1]; + fsd.f_bavail = fsd.f_spare[2]; + } +#endif /* STATFS_TRUNCATES_BLOCK_COUNTS */ +#endif /* STAT_STATFS2_BSIZE */ + + +#ifdef STAT_STATFS2_FSIZE /* 4.4BSD */ +#define CONVERT_BLOCKS(B) adjust_blocks ((uint64_t)(B), (uint64_t)fsd.f_fsize, (uint64_t)512) + + struct statfs fsd; + + if (statfs (path, &fsd) < 0) + return -1; +#endif /* STAT_STATFS2_FSIZE */ + +#ifdef STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */ +# if _AIX || defined(_CRAY) +# define CONVERT_BLOCKS(B) adjust_blocks ((uint64_t)(B), (uint64_t)fsd.f_bsize, (uint64_t)512) +# ifdef _CRAY +# define f_bavail f_bfree +# endif +# else +# define CONVERT_BLOCKS(B) ((uint64_t)B) +# ifndef _SEQUENT_ /* _SEQUENT_ is DYNIX/ptx */ +# ifndef DOLPHIN /* DOLPHIN 3.8.alfa/7.18 has f_bavail */ +# define f_bavail f_bfree +# endif +# endif +# endif + + struct statfs fsd; + + if (statfs (path, &fsd, sizeof fsd, 0) < 0) + return -1; + /* Empirically, the block counts on most SVR3 and SVR3-derived + systems seem to always be in terms of 512-byte blocks, + no matter what value f_bsize has. */ + +#endif /* STAT_STATFS4 */ + +#if defined(STAT_STATVFS) || defined(STAT_STATVFS64) /* SVR4 */ +# define CONVERT_BLOCKS(B) \ + adjust_blocks ((uint64_t)(B), fsd.f_frsize ? (uint64_t)fsd.f_frsize : (uint64_t)fsd.f_bsize, (uint64_t)512) + +#ifdef STAT_STATVFS64 + struct statvfs64 fsd; + if (statvfs64(path, &fsd) < 0) return -1; +#else + struct statvfs fsd; + if (statvfs(path, &fsd) < 0) return -1; +#endif + + /* f_frsize isn't guaranteed to be supported. */ + +#endif /* STAT_STATVFS */ + +#ifndef CONVERT_BLOCKS + /* we don't have any dfree code! */ + return -1; +#else +#if !defined(STAT_STATFS2_FS_DATA) + /* !Ultrix */ + (*dsize) = CONVERT_BLOCKS (fsd.f_blocks); + (*dfree) = CONVERT_BLOCKS (fsd.f_bavail); +#endif /* not STAT_STATFS2_FS_DATA */ +#endif + + return 0; +} diff --git a/source4/lib/util/genrand.c b/source4/lib/util/genrand.c new file mode 100644 index 0000000000..1149314d0b --- /dev/null +++ b/source4/lib/util/genrand.c @@ -0,0 +1,314 @@ +/* + Unix SMB/CIFS implementation. + + Functions to create reasonable random numbers for crypto use. + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/iconv.h" +#include "system/filesys.h" +#include "lib/crypto/crypto.h" + +static unsigned char hash[258]; +static uint32_t counter; + +static BOOL done_reseed = False; +static void (*reseed_callback)(int *newseed); + +/**************************************************************** + Copy any user given reseed data. +*****************************************************************/ + +void set_rand_reseed_callback(void (*fn)(int *)) +{ + reseed_callback = fn; + set_need_random_reseed(); +} + +void set_need_random_reseed(void) +{ + done_reseed = False; +} + +static void get_rand_reseed_data(int *reseed_data) +{ + if (reseed_callback) { + reseed_callback(reseed_data); + } else { + *reseed_data = 0; + } +} + +/**************************************************************** + Setup the seed. +*****************************************************************/ + +static void seed_random_stream(unsigned char *seedval, size_t seedlen) +{ + unsigned char j = 0; + size_t ind; + + for (ind = 0; ind < 256; ind++) + hash[ind] = (unsigned char)ind; + + for( ind = 0; ind < 256; ind++) { + unsigned char tc; + + j += (hash[ind] + seedval[ind%seedlen]); + + tc = hash[ind]; + hash[ind] = hash[j]; + hash[j] = tc; + } + + hash[256] = 0; + hash[257] = 0; +} + +/**************************************************************** + Get datasize bytes worth of random data. +*****************************************************************/ + +static void get_random_stream(unsigned char *data, size_t datasize) +{ + unsigned char index_i = hash[256]; + unsigned char index_j = hash[257]; + size_t ind; + + for( ind = 0; ind < datasize; ind++) { + unsigned char tc; + unsigned char t; + + index_i++; + index_j += hash[index_i]; + + tc = hash[index_i]; + hash[index_i] = hash[index_j]; + hash[index_j] = tc; + + t = hash[index_i] + hash[index_j]; + data[ind] = hash[t]; + } + + hash[256] = index_i; + hash[257] = index_j; +} + +/**************************************************************** + Get a 16 byte hash from the contents of a file. + + Note that the hash is initialised, because the extra entropy is not + worth the valgrind pain. +*****************************************************************/ + +static void do_filehash(const char *fname, unsigned char *the_hash) +{ + unsigned char buf[1011]; /* deliberate weird size */ + unsigned char tmp_md4[16]; + int fd, n; + + ZERO_STRUCT(tmp_md4); + + fd = open(fname,O_RDONLY,0); + if (fd == -1) + return; + + while ((n = read(fd, (char *)buf, sizeof(buf))) > 0) { + mdfour(tmp_md4, buf, n); + for (n=0;n<16;n++) + the_hash[n] ^= tmp_md4[n]; + } + close(fd); +} + +/************************************************************** + Try and get a good random number seed. Try a number of + different factors. Firstly, try /dev/urandom - use if exists. + + We use /dev/urandom as a read of /dev/random can block if + the entropy pool dries up. This leads clients to timeout + or be very slow on connect. + + If we can't use /dev/urandom then seed the stream random generator + above... +**************************************************************/ + +static int do_reseed(BOOL use_fd, int fd) +{ + unsigned char seed_inbuf[40]; + uint32_t v1, v2; struct timeval tval; pid_t mypid; + int reseed_data = 0; + + if (use_fd) { + if (fd != -1) + return fd; + + fd = open( "/dev/urandom", O_RDONLY,0); + if(fd >= 0) + return fd; + } + + /* Add in some secret file contents */ + + do_filehash("/etc/shadow", &seed_inbuf[0]); + + /* + * Add the counter, time of day, and pid. + */ + + GetTimeOfDay(&tval); + mypid = getpid(); + v1 = (counter++) + mypid + tval.tv_sec; + v2 = (counter++) * mypid + tval.tv_usec; + + SIVAL(seed_inbuf, 32, v1 ^ IVAL(seed_inbuf, 32)); + SIVAL(seed_inbuf, 36, v2 ^ IVAL(seed_inbuf, 36)); + + /* + * Add any user-given reseed data. + */ + + get_rand_reseed_data(&reseed_data); + if (reseed_data) { + size_t i; + for (i = 0; i < sizeof(seed_inbuf); i++) + seed_inbuf[i] ^= ((char *)(&reseed_data))[i % sizeof(reseed_data)]; + } + + seed_random_stream(seed_inbuf, sizeof(seed_inbuf)); + + return -1; +} + +/* + Interface to the (hopefully) good crypto random number generator. +*/ +void generate_random_buffer(uint8_t *out, int len) +{ + static int urand_fd = -1; + unsigned char md4_buf[64]; + unsigned char tmp_buf[16]; + unsigned char *p; + + if(!done_reseed) { + urand_fd = do_reseed(True, urand_fd); + done_reseed = True; + } + + if (urand_fd != -1 && len > 0) { + + if (read(urand_fd, out, len) == len) + return; /* len bytes of random data read from urandom. */ + + /* Read of urand error, drop back to non urand method. */ + close(urand_fd); + urand_fd = -1; + do_reseed(False, -1); + done_reseed = True; + } + + /* + * Generate random numbers in chunks of 64 bytes, + * then md4 them & copy to the output buffer. + * This way the raw state of the stream is never externally + * seen. + */ + + p = out; + while(len > 0) { + int copy_len = len > 16 ? 16 : len; + + get_random_stream(md4_buf, sizeof(md4_buf)); + mdfour(tmp_buf, md4_buf, sizeof(md4_buf)); + memcpy(p, tmp_buf, copy_len); + p += copy_len; + len -= copy_len; + } +} + +/* + generate a single random uint32_t +*/ +uint32_t generate_random(void) +{ + uint8_t v[4]; + generate_random_buffer(v, 4); + return IVAL(v, 0); +} + + +/* + very basic password quality checker +*/ +BOOL check_password_quality(const char *s) +{ + int has_digit=0, has_capital=0, has_lower=0; + while (*s) { + if (isdigit((unsigned char)*s)) { + has_digit++; + } else if (isupper((unsigned char)*s)) { + has_capital++; + } else if (islower((unsigned char)*s)) { + has_lower++; + } + s++; + } + + return has_digit && has_lower && has_capital; +} + +/******************************************************************* + Use the random number generator to generate a random string. +********************************************************************/ + +char *generate_random_str_list(TALLOC_CTX *mem_ctx, size_t len, const char *list) +{ + size_t i; + size_t list_len = strlen(list); + + char *retstr = talloc_array(mem_ctx, char, len + 1); + if (!retstr) return NULL; + + generate_random_buffer((uint8_t *)retstr, len); + for (i = 0; i < len; i++) { + retstr[i] = list[retstr[i] % list_len]; + } + retstr[i] = '\0'; + + return retstr; +} + +char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len) +{ + char *retstr; + const char *c_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_-#.,"; + +again: + retstr = generate_random_str_list(mem_ctx, len, c_list); + if (!retstr) return NULL; + + /* we need to make sure the random string passes basic quality tests + or it might be rejected by windows as a password */ + if (len >= 7 && !check_password_quality(retstr)) { + talloc_free(retstr); + goto again; + } + + return retstr; +} diff --git a/source4/lib/util/idtree.c b/source4/lib/util/idtree.c new file mode 100644 index 0000000000..a67a80940a --- /dev/null +++ b/source4/lib/util/idtree.c @@ -0,0 +1,384 @@ +/* + Unix SMB/CIFS implementation. + + very efficient functions to manage mapping a id (such as a fnum) to + a pointer. This is used for fnum and search id allocation. + + Copyright (C) Andrew Tridgell 2004 + + This code is derived from lib/idr.c in the 2.6 Linux kernel, which was + written by Jim Houston jim.houston@ccur.com, and is + Copyright (C) 2002 by Concurrent Computer Corporation + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* + see the section marked "public interface" below for documentation +*/ + +#include "includes.h" + +#define IDR_BITS 5 +#define IDR_FULL 0xfffffffful +#define TOP_LEVEL_FULL (IDR_FULL >> 30) +#define IDR_SIZE (1 << IDR_BITS) +#define IDR_MASK ((1 << IDR_BITS)-1) +#define MAX_ID_SHIFT (sizeof(int)*8 - 1) +#define MAX_ID_BIT (1U << MAX_ID_SHIFT) +#define MAX_ID_MASK (MAX_ID_BIT - 1) +#define MAX_LEVEL (MAX_ID_SHIFT + IDR_BITS - 1) / IDR_BITS +#define IDR_FREE_MAX MAX_LEVEL + MAX_LEVEL + +#define set_bit(bit, v) (v) |= (1<<(bit)) +#define clear_bit(bit, v) (v) &= ~(1<<(bit)) +#define test_bit(bit, v) ((v) & (1<<(bit))) + +struct idr_layer { + uint32_t bitmap; + struct idr_layer *ary[IDR_SIZE]; + int count; +}; + +struct idr_context { + struct idr_layer *top; + struct idr_layer *id_free; + int layers; + int id_free_cnt; +}; + +static struct idr_layer *alloc_layer(struct idr_context *idp) +{ + struct idr_layer *p; + + if (!(p = idp->id_free)) + return NULL; + idp->id_free = p->ary[0]; + idp->id_free_cnt--; + p->ary[0] = NULL; + return p; +} + +static int find_next_bit(uint32_t bm, int maxid, int n) +{ + while (nary[0] = idp->id_free; + idp->id_free = p; + idp->id_free_cnt++; +} + +static int idr_pre_get(struct idr_context *idp) +{ + while (idp->id_free_cnt < IDR_FREE_MAX) { + struct idr_layer *new = talloc_zero(idp, struct idr_layer); + if(new == NULL) + return (0); + free_layer(idp, new); + } + return 1; +} + +static int sub_alloc(struct idr_context *idp, void *ptr, int *starting_id) +{ + int n, m, sh; + struct idr_layer *p, *new; + struct idr_layer *pa[MAX_LEVEL]; + int l, id; + uint32_t bm; + + id = *starting_id; + p = idp->top; + l = idp->layers; + pa[l--] = NULL; + while (1) { + /* + * We run around this while until we reach the leaf node... + */ + n = (id >> (IDR_BITS*l)) & IDR_MASK; + bm = ~p->bitmap; + m = find_next_bit(bm, IDR_SIZE, n); + if (m == IDR_SIZE) { + /* no space available go back to previous layer. */ + l++; + id = (id | ((1 << (IDR_BITS*l))-1)) + 1; + if (!(p = pa[l])) { + *starting_id = id; + return -2; + } + continue; + } + if (m != n) { + sh = IDR_BITS*l; + id = ((id >> sh) ^ n ^ m) << sh; + } + if ((id >= MAX_ID_BIT) || (id < 0)) + return -1; + if (l == 0) + break; + /* + * Create the layer below if it is missing. + */ + if (!p->ary[m]) { + if (!(new = alloc_layer(idp))) + return -1; + p->ary[m] = new; + p->count++; + } + pa[l--] = p; + p = p->ary[m]; + } + /* + * We have reached the leaf node, plant the + * users pointer and return the raw id. + */ + p->ary[m] = (struct idr_layer *)ptr; + set_bit(m, p->bitmap); + p->count++; + /* + * If this layer is full mark the bit in the layer above + * to show that this part of the radix tree is full. + * This may complete the layer above and require walking + * up the radix tree. + */ + n = id; + while (p->bitmap == IDR_FULL) { + if (!(p = pa[++l])) + break; + n = n >> IDR_BITS; + set_bit((n & IDR_MASK), p->bitmap); + } + return(id); +} + +static int idr_get_new_above_int(struct idr_context *idp, void *ptr, int starting_id) +{ + struct idr_layer *p, *new; + int layers, v, id; + + idr_pre_get(idp); + + id = starting_id; +build_up: + p = idp->top; + layers = idp->layers; + if (!p) { + if (!(p = alloc_layer(idp))) + return -1; + layers = 1; + } + /* + * Add a new layer to the top of the tree if the requested + * id is larger than the currently allocated space. + */ + while ((layers < MAX_LEVEL) && (id >= (1 << (layers*IDR_BITS)))) { + layers++; + if (!p->count) + continue; + if (!(new = alloc_layer(idp))) { + /* + * The allocation failed. If we built part of + * the structure tear it down. + */ + for (new = p; p && p != idp->top; new = p) { + p = p->ary[0]; + new->ary[0] = NULL; + new->bitmap = new->count = 0; + free_layer(idp, new); + } + return -1; + } + new->ary[0] = p; + new->count = 1; + if (p->bitmap == IDR_FULL) + set_bit(0, new->bitmap); + p = new; + } + idp->top = p; + idp->layers = layers; + v = sub_alloc(idp, ptr, &id); + if (v == -2) + goto build_up; + return(v); +} + +static int sub_remove(struct idr_context *idp, int shift, int id) +{ + struct idr_layer *p = idp->top; + struct idr_layer **pa[MAX_LEVEL]; + struct idr_layer ***paa = &pa[0]; + int n; + + *paa = NULL; + *++paa = &idp->top; + + while ((shift > 0) && p) { + n = (id >> shift) & IDR_MASK; + clear_bit(n, p->bitmap); + *++paa = &p->ary[n]; + p = p->ary[n]; + shift -= IDR_BITS; + } + n = id & IDR_MASK; + if (p != NULL && test_bit(n, p->bitmap)) { + clear_bit(n, p->bitmap); + p->ary[n] = NULL; + while(*paa && ! --((**paa)->count)){ + free_layer(idp, **paa); + **paa-- = NULL; + } + if ( ! *paa ) + idp->layers = 0; + return 0; + } + return -1; +} + +static void *_idr_find(struct idr_context *idp, int id) +{ + int n; + struct idr_layer *p; + + n = idp->layers * IDR_BITS; + p = idp->top; + /* + * This tests to see if bits outside the current tree are + * present. If so, tain't one of ours! + */ + if ((id & ~(~0 << MAX_ID_SHIFT)) >> (n + IDR_BITS)) + return NULL; + + /* Mask off upper bits we don't use for the search. */ + id &= MAX_ID_MASK; + + while (n > 0 && p) { + n -= IDR_BITS; + p = p->ary[(id >> n) & IDR_MASK]; + } + return((void *)p); +} + +static int _idr_remove(struct idr_context *idp, int id) +{ + struct idr_layer *p; + + /* Mask off upper bits we don't use for the search. */ + id &= MAX_ID_MASK; + + if (sub_remove(idp, (idp->layers - 1) * IDR_BITS, id) == -1) { + return -1; + } + + if ( idp->top && idp->top->count == 1 && + (idp->layers > 1) && + idp->top->ary[0]) { + /* We can drop a layer */ + p = idp->top->ary[0]; + idp->top->bitmap = idp->top->count = 0; + free_layer(idp, idp->top); + idp->top = p; + --idp->layers; + } + while (idp->id_free_cnt >= IDR_FREE_MAX) { + p = alloc_layer(idp); + talloc_free(p); + } + return 0; +} + +/************************************************************************ + this is the public interface +**************************************************************************/ + +/* + initialise a idr tree. The context return value must be passed to + all subsequent idr calls. To destroy the idr tree use talloc_free() + on this context + */ +struct idr_context *idr_init(TALLOC_CTX *mem_ctx) +{ + return talloc_zero(mem_ctx, struct idr_context); +} + +/* + allocate the next available id, and assign 'ptr' into its slot. + you can retrieve later this pointer using idr_find() +*/ +int idr_get_new(struct idr_context *idp, void *ptr, int limit) +{ + int ret = idr_get_new_above_int(idp, ptr, 0); + if (ret > limit) { + idr_remove(idp, ret); + return -1; + } + return ret; +} + +/* + allocate a new id, giving the first available value greater than or + equal to the given starting id +*/ +int idr_get_new_above(struct idr_context *idp, void *ptr, int starting_id, int limit) +{ + int ret = idr_get_new_above_int(idp, ptr, starting_id); + if (ret > limit) { + idr_remove(idp, ret); + return -1; + } + return ret; +} + +/* + allocate a new id randomly in the given range +*/ +int idr_get_new_random(struct idr_context *idp, void *ptr, int limit) +{ + int id; + + /* first try a random starting point in the whole range, and if that fails, + then start randomly in the bottom half of the range. This can only + fail if the range is over half full */ + id = idr_get_new_above(idp, ptr, 1+(generate_random() % limit), limit); + if (id == -1) { + id = idr_get_new_above(idp, ptr, 1+(generate_random()%(limit/2)), limit); + } + + return id; +} + +/* + find a pointer value previously set with idr_get_new given an id +*/ +void *idr_find(struct idr_context *idp, int id) +{ + return _idr_find(idp, id); +} + +/* + remove an id from the idr tree +*/ +int idr_remove(struct idr_context *idp, int id) +{ + int ret; + ret = _idr_remove((struct idr_context *)idp, id); + if (ret != 0) { + DEBUG(0,("WARNING: attempt to remove unset id %d in idtree\n", id)); + } + return ret; +} diff --git a/source4/lib/util/module.c b/source4/lib/util/module.c new file mode 100644 index 0000000000..672d8df7ce --- /dev/null +++ b/source4/lib/util/module.c @@ -0,0 +1,97 @@ +/* + Unix SMB/CIFS implementation. + + Copyright (C) Jelmer Vernooij 2005 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/dir.h" + +static void *load_module(TALLOC_CTX *mem_ctx, const char *dir, const char *name) +{ + char *path; + void *handle; + void *init_fn; + + path = talloc_asprintf(mem_ctx, "%s/%s", dir, name); + + handle = dlopen(path, RTLD_NOW); + if (handle == NULL) { + DEBUG(0, ("Unable to open %s: %s\n", path, dlerror())); + talloc_free(path); + return NULL; + } + + init_fn = dlsym(handle, "init_module"); + + if (init_fn == NULL) { + DEBUG(0, ("Unable to find init_module() in %s: %s\n", path, dlerror())); + DEBUG(1, ("Loading module '%s' failed\n", path)); + dlclose(handle); + talloc_free(path); + return NULL; + } + + talloc_free(path); + + return init_fn; +} + +init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path) +{ + DIR *dir; + struct dirent *entry; + int success = 0; + init_module_fn *ret = talloc_array(mem_ctx, init_module_fn, 2); + + ret[0] = NULL; + + dir = opendir(path); + if (dir == NULL) { + talloc_free(ret); + return NULL; + } + + while((entry = readdir(dir))) { + if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) + continue; + + ret[success] = load_module(mem_ctx, path, entry->d_name); + if (ret[success]) { + ret = talloc_realloc(mem_ctx, ret, init_module_fn, success+2); + success++; + ret[success] = NULL; + } + } + + closedir(dir); + + return ret; +} + +BOOL run_init_functions(NTSTATUS (**fns) (void)) +{ + int i; + BOOL ret; + + if (fns == NULL) + return True; + + for (i = 0; fns[i]; i++) { ret &= NT_STATUS_IS_OK(fns[i]()); } + + return ret; +} diff --git a/source4/lib/util/ms_fnmatch.c b/source4/lib/util/ms_fnmatch.c new file mode 100644 index 0000000000..699341bede --- /dev/null +++ b/source4/lib/util/ms_fnmatch.c @@ -0,0 +1,219 @@ +/* + Unix SMB/CIFS implementation. + filename matching routine + Copyright (C) Andrew Tridgell 1992-2004 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* + This module was originally based on fnmatch.c copyright by the Free + Software Foundation. It bears little (if any) resemblence to that + code now +*/ + + +#include "includes.h" + +static int null_match(const char *p) +{ + for (;*p;p++) { + if (*p != '*' && + *p != '<' && + *p != '"' && + *p != '>') return -1; + } + return 0; +} + +/* + the max_n structure is purely for efficiency, it doesn't contribute + to the matching algorithm except by ensuring that the algorithm does + not grow exponentially +*/ +struct max_n { + const char *predot; + const char *postdot; +}; + + +/* + p and n are the pattern and string being matched. The max_n array is + an optimisation only. The ldot pointer is NULL if the string does + not contain a '.', otherwise it points at the last dot in 'n'. +*/ +static int ms_fnmatch_core(const char *p, const char *n, + struct max_n *max_n, const char *ldot) +{ + codepoint_t c, c2; + int i; + size_t size, size_n; + + while ((c = next_codepoint(p, &size))) { + p += size; + + switch (c) { + case '*': + /* a '*' matches zero or more characters of any type */ + if (max_n->predot && max_n->predot <= n) { + return null_match(p); + } + for (i=0; n[i]; i += size_n) { + next_codepoint(n+i, &size_n); + if (ms_fnmatch_core(p, n+i, max_n+1, ldot) == 0) { + return 0; + } + } + if (!max_n->predot || max_n->predot > n) max_n->predot = n; + return null_match(p); + + case '<': + /* a '<' matches zero or more characters of + any type, but stops matching at the last + '.' in the string. */ + if (max_n->predot && max_n->predot <= n) { + return null_match(p); + } + if (max_n->postdot && max_n->postdot <= n && n <= ldot) { + return -1; + } + for (i=0; n[i]; i += size_n) { + next_codepoint(n+i, &size_n); + if (ms_fnmatch_core(p, n+i, max_n+1, ldot) == 0) return 0; + if (n+i == ldot) { + if (ms_fnmatch_core(p, n+i+size_n, max_n+1, ldot) == 0) return 0; + if (!max_n->postdot || max_n->postdot > n) max_n->postdot = n; + return -1; + } + } + if (!max_n->predot || max_n->predot > n) max_n->predot = n; + return null_match(p); + + case '?': + /* a '?' matches any single character */ + if (! *n) { + return -1; + } + next_codepoint(n, &size_n); + n += size_n; + break; + + case '>': + /* a '?' matches any single character, but + treats '.' specially */ + if (n[0] == '.') { + if (! n[1] && null_match(p) == 0) { + return 0; + } + break; + } + if (! *n) return null_match(p); + next_codepoint(n, &size_n); + n += size_n; + break; + + case '"': + /* a bit like a soft '.' */ + if (*n == 0 && null_match(p) == 0) { + return 0; + } + if (*n != '.') return -1; + next_codepoint(n, &size_n); + n += size_n; + break; + + default: + c2 = next_codepoint(n, &size_n); + if (c != c2 && codepoint_cmpi(c, c2) != 0) { + return -1; + } + n += size_n; + break; + } + } + + if (! *n) { + return 0; + } + + return -1; +} + +int ms_fnmatch(const char *pattern, const char *string, enum protocol_types protocol) +{ + int ret, count, i; + struct max_n *max_n = NULL; + + if (strcmp(string, "..") == 0) { + string = "."; + } + + if (strpbrk(pattern, "<>*?\"") == NULL) { + /* this is not just an optmisation - it is essential + for LANMAN1 correctness */ + return strcasecmp_m(pattern, string); + } + + if (protocol <= PROTOCOL_LANMAN2) { + char *p = talloc_strdup(NULL, pattern); + if (p == NULL) { + return -1; + } + /* + for older negotiated protocols it is possible to + translate the pattern to produce a "new style" + pattern that exactly matches w2k behaviour + */ + for (i=0;p[i];i++) { + if (p[i] == '?') { + p[i] = '>'; + } else if (p[i] == '.' && + (p[i+1] == '?' || + p[i+1] == '*' || + p[i+1] == 0)) { + p[i] = '"'; + } else if (p[i] == '*' && + p[i+1] == '.') { + p[i] = '<'; + } + } + ret = ms_fnmatch(p, string, PROTOCOL_NT1); + talloc_free(p); + return ret; + } + + for (count=i=0;pattern[i];i++) { + if (pattern[i] == '*' || pattern[i] == '<') count++; + } + + max_n = talloc_array(NULL, struct max_n, count); + if (!max_n) { + return -1; + } + memset(max_n, 0, sizeof(struct max_n) * count); + + ret = ms_fnmatch_core(pattern, string, max_n, strrchr(string, '.')); + + talloc_free(max_n); + + return ret; +} + + +/* a generic fnmatch function - uses for non-CIFS pattern matching */ +int gen_fnmatch(const char *pattern, const char *string) +{ + return ms_fnmatch(pattern, string, PROTOCOL_NT1); +} diff --git a/source4/lib/util/mutex.c b/source4/lib/util/mutex.c new file mode 100644 index 0000000000..480ba92cc0 --- /dev/null +++ b/source4/lib/util/mutex.c @@ -0,0 +1,52 @@ +/* + Unix SMB/CIFS implementation. + Samba mutex/lock functions + Copyright (C) Andrew Tridgell 2003 + Copyright (C) James J Myers 2003 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include "includes.h" +#include "mutex.h" + +/* the registered mutex handlers */ +static struct { + const char *name; + struct mutex_ops ops; +} mutex_handlers; + +/* read/write lock routines */ + + +/* + register a set of mutex/rwlock handlers. + Should only be called once in the execution of smbd. +*/ +BOOL register_mutex_handlers(const char *name, struct mutex_ops *ops) +{ + if (mutex_handlers.name != NULL) { + /* it's already registered! */ + DEBUG(2,("mutex handler '%s' already registered - failed '%s'\n", + mutex_handlers.name, name)); + return False; + } + + mutex_handlers.name = name; + mutex_handlers.ops = *ops; + + DEBUG(2,("mutex handler '%s' registered\n", name)); + return True; +} + diff --git a/source4/lib/util/mutex.h b/source4/lib/util/mutex.h new file mode 100644 index 0000000000..018c134bcb --- /dev/null +++ b/source4/lib/util/mutex.h @@ -0,0 +1,71 @@ +#ifndef _MUTEX_H_ +#define _MUTEX_H_ +/* + Unix SMB/CIFS implementation. + Samba mutex functions + Copyright (C) Andrew Tridgell 2003 + Copyright (C) James J Myers 2003 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +struct mutex_ops; + +/* To add a new read/write lock, add it to enum rwlock_id + */ +enum rwlock_id { RWLOCK_SMBD, /* global smbd lock */ + + RWLOCK_MAX /* this MUST be kept last */ +}; + +#define MUTEX_LOCK_BY_ID(mutex_index) smb_mutex_lock_by_id(mutex_index, #mutex_index) +#define MUTEX_UNLOCK_BY_ID(mutex_index) smb_mutex_unlock_by_id(mutex_index, #mutex_index) +#define MUTEX_INIT(mutex, name) smb_mutex_init(mutex, #name) +#define MUTEX_DESTROY(mutex, name) smb_mutex_destroy(mutex, #name) +#define MUTEX_LOCK(mutex, name) smb_mutex_lock(mutex, #name) +#define MUTEX_UNLOCK(mutex, name) smb_mutex_unlock(mutex, #name) + +#define RWLOCK_INIT(rwlock, name) smb_rwlock_init(rwlock, #name) +#define RWLOCK_DESTROY(rwlock, name) smb_rwlock_destroy(rwlock, #name) +#define RWLOCK_LOCK_WRITE(rwlock, name) smb_rwlock_lock_write(rwlock, #name) +#define RWLOCK_LOCK_READ(rwlock, name) smb_rwlock_lock_read(rwlock, #name) +#define RWLOCK_UNLOCK(rwlock, name) smb_rwlock_unlock(rwlock, #name) + + + +/* this null typedef ensures we get the types right and avoids the + pitfalls of void* */ +typedef struct smb_mutex { + void *mutex; +} smb_mutex_t; +typedef struct { + void *rwlock; +} smb_rwlock_t; + +/* the mutex model operations structure - contains function pointers to + the model-specific implementations of each operation */ +struct mutex_ops { + int (*mutex_init)(smb_mutex_t *mutex, const char *name); + int (*mutex_lock)(smb_mutex_t *mutex, const char *name); + int (*mutex_unlock)(smb_mutex_t *mutex, const char *name); + int (*mutex_destroy)(smb_mutex_t *mutex, const char *name); + int (*rwlock_init)(smb_rwlock_t *rwlock, const char *name); + int (*rwlock_lock_write)(smb_rwlock_t *rwlock, const char *name); + int (*rwlock_lock_read)(smb_rwlock_t *rwlock, const char *name); + int (*rwlock_unlock)(smb_rwlock_t *rwlock, const char *name); + int (*rwlock_destroy)(smb_rwlock_t *rwlock, const char *name); +}; + +#endif /* endif _MUTEX_H_ */ diff --git a/source4/lib/util/pidfile.c b/source4/lib/util/pidfile.c new file mode 100644 index 0000000000..9a7c197f70 --- /dev/null +++ b/source4/lib/util/pidfile.c @@ -0,0 +1,116 @@ +/* this code is broken - there is a race condition with the unlink (tridge) */ + +/* + Unix SMB/CIFS implementation. + pidfile handling + Copyright (C) Andrew Tridgell 1998 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/filesys.h" + +#ifndef O_NONBLOCK +#define O_NONBLOCK +#endif + +/* return the pid in a pidfile. return 0 if the process (or pidfile) + does not exist */ +pid_t pidfile_pid(const char *name) +{ + int fd; + char pidstr[20]; + uint_t ret; + char *pidFile; + + asprintf(&pidFile, "%s/%s.pid", lp_piddir(), name); + + fd = open(pidFile, O_NONBLOCK | O_RDONLY, 0644); + + if (fd == -1) { + SAFE_FREE(pidFile); + return 0; + } + + ZERO_STRUCT(pidstr); + + if (read(fd, pidstr, sizeof(pidstr)-1) <= 0) { + goto noproc; + } + + ret = atoi(pidstr); + + if (!process_exists((pid_t)ret)) { + goto noproc; + } + + if (fcntl_lock(fd,F_SETLK,0,1,F_RDLCK)) { + /* we could get the lock - it can't be a Samba process */ + goto noproc; + } + + close(fd); + SAFE_FREE(pidFile); + return (pid_t)ret; + + noproc: + close(fd); + unlink(pidFile); + SAFE_FREE(pidFile); + return 0; +} + +/* create a pid file in the pid directory. open it and leave it locked */ +void pidfile_create(const char *name) +{ + int fd; + char buf[20]; + char *pidFile; + pid_t pid; + + asprintf(&pidFile, "%s/%s.pid", lp_piddir(), name); + + pid = pidfile_pid(name); + if (pid != 0) { + DEBUG(0,("ERROR: %s is already running. File %s exists and process id %d is running.\n", + name, pidFile, (int)pid)); + exit(1); + } + + fd = open(pidFile, O_NONBLOCK | O_CREAT | O_WRONLY | O_EXCL, 0644); + if (fd == -1) { + DEBUG(0,("ERROR: can't open %s: Error was %s\n", pidFile, + strerror(errno))); + exit(1); + } + + if (fcntl_lock(fd,F_SETLK,0,1,F_WRLCK)==False) { + DEBUG(0,("ERROR: %s : fcntl lock of file %s failed. Error was %s\n", + name, pidFile, strerror(errno))); + exit(1); + } + + memset(buf, 0, sizeof(buf)); + slprintf(buf, sizeof(buf) - 1, "%u\n", (uint_t) getpid()); + if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) { + DEBUG(0,("ERROR: can't write to file %s: %s\n", + pidFile, strerror(errno))); + exit(1); + } + + /* Leave pid file open & locked for the duration... */ + SAFE_FREE(pidFile); +} diff --git a/source4/lib/util/safe_string.h b/source4/lib/util/safe_string.h new file mode 100644 index 0000000000..43e094467c --- /dev/null +++ b/source4/lib/util/safe_string.h @@ -0,0 +1,55 @@ +/* + Unix SMB/CIFS implementation. + Safe string handling routines. + Copyright (C) Andrew Tridgell 1994-1998 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef _SAFE_STRING_H +#define _SAFE_STRING_H + +#ifndef _SPLINT_ /* http://www.splint.org */ +/* Some macros to ensure people don't use buffer overflow vulnerable string + functions. */ + +#ifdef bcopy +#undef bcopy +#endif /* bcopy */ +#define bcopy(src,dest,size) __ERROR__XX__NEVER_USE_BCOPY___; + +#ifdef strcpy +#undef strcpy +#endif /* strcpy */ +#define strcpy(dest,src) __ERROR__XX__NEVER_USE_STRCPY___; + +#ifdef strcat +#undef strcat +#endif /* strcat */ +#define strcat(dest,src) __ERROR__XX__NEVER_USE_STRCAT___; + +#ifdef sprintf +#undef sprintf +#endif /* sprintf */ +#define sprintf __ERROR__XX__NEVER_USE_SPRINTF__; + +#endif /* !_SPLINT_ */ + +/* replace some string functions with multi-byte + versions */ +#define strlower(s) strlower_m(s) +#define strupper(s) strupper_m(s) + +#endif diff --git a/source4/lib/util/select.c b/source4/lib/util/select.c new file mode 100644 index 0000000000..a1b2e04065 --- /dev/null +++ b/source4/lib/util/select.c @@ -0,0 +1,169 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + Samba select/poll implementation + Copyright (C) Andrew Tridgell 1992-1998 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/filesys.h" + +/* This is here because it allows us to avoid a nasty race in signal handling. + We need to guarantee that when we get a signal we get out of a select immediately + but doing that involves a race condition. We can avoid the race by getting the + signal handler to write to a pipe that is in the select/poll list + + This means all Samba signal handlers should call sys_select_signal(). +*/ + +static pid_t initialised; +static int select_pipe[2]; +static VOLATILE unsigned pipe_written, pipe_read; + +/******************************************************************* + Call this from all Samba signal handlers if you want to avoid a + nasty signal race condition. +********************************************************************/ + +void sys_select_signal(void) +{ + char c = 1; + if (!initialised) return; + + if (pipe_written > pipe_read+256) return; + + if (write(select_pipe[1], &c, 1) == 1) pipe_written++; +} + +/******************************************************************* + Like select() but avoids the signal race using a pipe + it also guarantees that fds on return only ever contains bits set + for file descriptors that were readable. +********************************************************************/ + +int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval) +{ + int ret, saved_errno; + fd_set *readfds2, readfds_buf; + + if (initialised != getpid()) { + pipe(select_pipe); + + /* + * These next two lines seem to fix a bug with the Linux + * 2.0.x kernel (and probably other UNIXes as well) where + * the one byte read below can block even though the + * select returned that there is data in the pipe and + * the pipe_written variable was incremented. Thanks to + * HP for finding this one. JRA. + */ + + if(set_blocking(select_pipe[0],0)==-1) + smb_panic("select_pipe[0]: O_NONBLOCK failed.\n"); + if(set_blocking(select_pipe[1],0)==-1) + smb_panic("select_pipe[1]: O_NONBLOCK failed.\n"); + + initialised = getpid(); + } + + maxfd = MAX(select_pipe[0]+1, maxfd); + + /* If readfds is NULL we need to provide our own set. */ + if (readfds) { + readfds2 = readfds; + } else { + readfds2 = &readfds_buf; + FD_ZERO(readfds2); + } + FD_SET(select_pipe[0], readfds2); + + errno = 0; + ret = select(maxfd,readfds2,writefds,errorfds,tval); + + if (ret <= 0) { + FD_ZERO(readfds2); + if (writefds) + FD_ZERO(writefds); + if (errorfds) + FD_ZERO(errorfds); + } else if (FD_ISSET(select_pipe[0], readfds2)) { + char c; + saved_errno = errno; + if (read(select_pipe[0], &c, 1) == 1) { + pipe_read++; + /* Mark Weaver pointed out a critical + fix to ensure we don't lose signals. We must always + return -1 when the select pipe is set, otherwise if another + fd is also ready (so ret == 2) then we used to eat the + byte in the pipe and lose the signal. JRA. + */ + ret = -1; + errno = EINTR; + } else { + FD_CLR(select_pipe[0], readfds2); + ret--; + errno = saved_errno; + } + } + + return ret; +} + +/******************************************************************* + Similar to sys_select() but catch EINTR and continue. + This is what sys_select() used to do in Samba. +********************************************************************/ + +int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval) +{ + int ret; + fd_set *readfds2, readfds_buf, *writefds2, writefds_buf, *errorfds2, errorfds_buf; + struct timeval tval2, *ptval; + + readfds2 = (readfds ? &readfds_buf : NULL); + writefds2 = (writefds ? &writefds_buf : NULL); + errorfds2 = (errorfds ? &errorfds_buf : NULL); + ptval = (tval ? &tval2 : NULL); + + do { + if (readfds) + readfds_buf = *readfds; + if (writefds) + writefds_buf = *writefds; + if (errorfds) + errorfds_buf = *errorfds; + if (tval) + tval2 = *tval; + + /* We must use select and not sys_select here. If we use + sys_select we'd lose the fact a signal occurred when sys_select + read a byte from the pipe. Fix from Mark Weaver + + */ + + ret = select(maxfd, readfds2, writefds2, errorfds2, ptval); + } while (ret == -1 && errno == EINTR); + + if (readfds) + *readfds = readfds_buf; + if (writefds) + *writefds = writefds_buf; + if (errorfds) + *errorfds = errorfds_buf; + + return ret; +} diff --git a/source4/lib/util/signal.c b/source4/lib/util/signal.c new file mode 100644 index 0000000000..6c0bb4007a --- /dev/null +++ b/source4/lib/util/signal.c @@ -0,0 +1,140 @@ +/* + Unix SMB/CIFS implementation. + signal handling functions + + Copyright (C) Andrew Tridgell 1998 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/wait.h" + +/**************************************************************************** + Catch child exits and reap the child zombie status. +****************************************************************************/ + +static void sig_cld(int signum) +{ + while (waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0) + ; + + /* + * Turns out it's *really* important not to + * restore the signal handler here if we have real POSIX + * signal handling. If we do, then we get the signal re-delivered + * immediately - hey presto - instant loop ! JRA. + */ + +#if !defined(HAVE_SIGACTION) + CatchSignal(SIGCLD, sig_cld); +#endif +} + +/**************************************************************************** +catch child exits - leave status; +****************************************************************************/ + +static void sig_cld_leave_status(int signum) +{ + /* + * Turns out it's *really* important not to + * restore the signal handler here if we have real POSIX + * signal handling. If we do, then we get the signal re-delivered + * immediately - hey presto - instant loop ! JRA. + */ + +#if !defined(HAVE_SIGACTION) + CatchSignal(SIGCLD, sig_cld_leave_status); +#endif +} + +/******************************************************************* + Block sigs. +********************************************************************/ + +void BlockSignals(BOOL block,int signum) +{ +#ifdef HAVE_SIGPROCMASK + sigset_t set; + sigemptyset(&set); + sigaddset(&set,signum); + sigprocmask(block?SIG_BLOCK:SIG_UNBLOCK,&set,NULL); +#elif defined(HAVE_SIGBLOCK) + if (block) { + sigblock(sigmask(signum)); + } else { + sigsetmask(siggetmask() & ~sigmask(signum)); + } +#else + /* yikes! This platform can't block signals? */ + static int done; + if (!done) { + DEBUG(0,("WARNING: No signal blocking available\n")); + done=1; + } +#endif +} + +/******************************************************************* + Catch a signal. This should implement the following semantics: + + 1) The handler remains installed after being called. + 2) The signal should be blocked during handler execution. +********************************************************************/ + +void (*CatchSignal(int signum,void (*handler)(int )))(int) +{ +#ifdef HAVE_SIGACTION + struct sigaction act; + struct sigaction oldact; + + ZERO_STRUCT(act); + + act.sa_handler = handler; +#ifdef SA_RESTART + /* + * We *want* SIGALRM to interrupt a system call. + */ + if(signum != SIGALRM) + act.sa_flags = SA_RESTART; +#endif + sigemptyset(&act.sa_mask); + sigaddset(&act.sa_mask,signum); + sigaction(signum,&act,&oldact); + return oldact.sa_handler; +#else /* !HAVE_SIGACTION */ + /* FIXME: need to handle sigvec and systems with broken signal() */ + return signal(signum, handler); +#endif +} + +/******************************************************************* + Ignore SIGCLD via whatever means is necessary for this OS. +********************************************************************/ + +void CatchChild(void) +{ + CatchSignal(SIGCLD, sig_cld); +} + +/******************************************************************* + Catch SIGCLD but leave the child around so it's status can be reaped. +********************************************************************/ + +void CatchChildLeaveStatus(void) +{ + CatchSignal(SIGCLD, sig_cld_leave_status); +} diff --git a/source4/lib/util/substitute.c b/source4/lib/util/substitute.c new file mode 100644 index 0000000000..34a2ad9f82 --- /dev/null +++ b/source4/lib/util/substitute.c @@ -0,0 +1,165 @@ +/* + Unix SMB/CIFS implementation. + string substitution functions + Copyright (C) Andrew Tridgell 1992-2000 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + +#include "includes.h" +#include "smb_server/smb_server.h" + +/* oh bugger - I really didn't want to have a top-level context + anywhere, but until we change all lp_*() calls to take a context + argument this is needed */ +static struct substitute_context *sub; + +void sub_set_context(struct substitute_context *subptr) +{ + sub = subptr; +} + +/* + setup a string in the negotiate structure, using alpha_strcpy with SAFE_NETBIOS_CHARS +*/ +static void setup_string(char **dest, const char *str) +{ +#define SAFE_NETBIOS_CHARS ". -_" + char *s; + + s = strdup(str); + if (!s) { + return; + } + + alpha_strcpy(s, str, SAFE_NETBIOS_CHARS, strlen(s)+1); + + trim_string(s," "," "); + strlower(s); + + SAFE_FREE(*dest); + (*dest) = s; +} + +void sub_set_remote_proto(const char *str) +{ + if (!sub) return; + setup_string(&sub->remote_proto, str); +} + +void sub_set_remote_arch(const char *str) +{ + if (!sub) return; + setup_string(&sub->remote_arch, str); +} + +/* + setup the string used by %U substitution +*/ +void sub_set_user_name(const char *name) +{ + if (!sub) return; + setup_string(&sub->user_name, name); +} + +/**************************************************************************** +FOO +****************************************************************************/ +void standard_sub_basic(char *str,size_t len) +{ +} + +/**************************************************************************** + Do some standard substitutions in a string. + This function will return an allocated string that have to be freed. +****************************************************************************/ +char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name, const char *str) +{ + return talloc_strdup(mem_ctx, str); +} + +char *alloc_sub_basic(const char *smb_name, const char *str) +{ + return strdup(str); +} + +/**************************************************************************** + Do some specific substitutions in a string. + This function will return an allocated string that have to be freed. +****************************************************************************/ + +char *talloc_sub_specified(TALLOC_CTX *mem_ctx, + const char *input_string, + const char *username, + const char *domain, + uid_t uid, + gid_t gid) +{ + return talloc_strdup(mem_ctx, input_string); +} + +char *alloc_sub_specified(const char *input_string, + const char *username, + const char *domain, + uid_t uid, + gid_t gid) +{ + return strdup(input_string); +} + +char *talloc_sub_advanced(TALLOC_CTX *mem_ctx, + int snum, + const char *user, + const char *connectpath, + gid_t gid, + const char *smb_name, + char *str) +{ + return talloc_strdup(mem_ctx, str); +} + +char *alloc_sub_advanced(int snum, const char *user, + const char *connectpath, gid_t gid, + const char *smb_name, char *str) +{ + return strdup(str); +} + +/**************************************************************************** + Do some standard substitutions in a string. +****************************************************************************/ + +void standard_sub_tcon(struct smbsrv_tcon *tcon, char *str, size_t len) +{ +} + +char *talloc_sub_tcon(TALLOC_CTX *mem_ctx, struct smbsrv_tcon *tcon, char *str) +{ + return talloc_strdup(mem_ctx, str); +} + +char *alloc_sub_tcon(struct smbsrv_tcon *tcon, char *str) +{ + return strdup(str); +} + +/**************************************************************************** + Like standard_sub but by snum. +****************************************************************************/ + +void standard_sub_snum(int snum, char *str, size_t len) +{ +} diff --git a/source4/lib/util/system.c b/source4/lib/util/system.c new file mode 100644 index 0000000000..655b4a1054 --- /dev/null +++ b/source4/lib/util/system.c @@ -0,0 +1,98 @@ +/* + Unix SMB/CIFS implementation. + Samba system utilities + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Jeremy Allison 1998-2002 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/network.h" +#include "system/filesys.h" + +/* + The idea is that this file will eventually have wrappers around all + important system calls in samba. The aims are: + + - to enable easier porting by putting OS dependent stuff in here + + - to allow for hooks into other "pseudo-filesystems" + + - to allow easier integration of things like the japanese extensions + + - to support the philosophy of Samba to expose the features of + the OS within the SMB model. In general whatever file/printer/variable + expansions/etc make sense to the OS should be acceptable to Samba. +*/ + +/************************************************************************** +A wrapper for gethostbyname() that tries avoids looking up hostnames +in the root domain, which can cause dial-on-demand links to come up for no +apparent reason. +****************************************************************************/ + +struct hostent *sys_gethostbyname(const char *name) +{ +#ifdef REDUCE_ROOT_DNS_LOOKUPS + char query[256], hostname[256]; + char *domain; + + /* Does this name have any dots in it? If so, make no change */ + + if (strchr_m(name, '.')) + return(gethostbyname(name)); + + /* Get my hostname, which should have domain name + attached. If not, just do the gethostname on the + original string. + */ + + gethostname(hostname, sizeof(hostname) - 1); + hostname[sizeof(hostname) - 1] = 0; + if ((domain = strchr_m(hostname, '.')) == NULL) + return(gethostbyname(name)); + + /* Attach domain name to query and do modified query. + If names too large, just do gethostname on the + original string. + */ + + if((strlen(name) + strlen(domain)) >= sizeof(query)) + return(gethostbyname(name)); + + slprintf(query, sizeof(query)-1, "%s%s", name, domain); + return(gethostbyname(query)); +#else /* REDUCE_ROOT_DNS_LOOKUPS */ + return(gethostbyname(name)); +#endif /* REDUCE_ROOT_DNS_LOOKUPS */ +} + +const char *sys_inet_ntoa(struct ipv4_addr in) +{ + struct in_addr in2; + in2.s_addr = in.addr; + return inet_ntoa(in2); +} + +struct ipv4_addr sys_inet_makeaddr(int net, int host) +{ + struct in_addr in; + struct ipv4_addr in2; + in = inet_makeaddr(net, host); + in2.addr = in.s_addr; + return in2; +} + diff --git a/source4/lib/util/time.c b/source4/lib/util/time.c new file mode 100644 index 0000000000..7721a2c456 --- /dev/null +++ b/source4/lib/util/time.c @@ -0,0 +1,596 @@ +/* + Unix SMB/CIFS implementation. + time handling functions + + Copyright (C) Andrew Tridgell 1992-2004 + Copyright (C) Stefan (metze) Metzmacher 2002 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/time.h" + +#ifndef TIME_T_MIN +/* we use 0 here, because (time_t)-1 means error */ +#define TIME_T_MIN 0 +#endif + +/* + * we use the INT32_MAX here as on 64 bit systems, + * gmtime() fails with INT64_MAX + */ + +#ifndef TIME_T_MAX +#define TIME_T_MAX MIN(INT32_MAX,_TYPE_MAXIMUM(time_t)) +#endif + +/******************************************************************* + External access to time_t_min and time_t_max. +********************************************************************/ +time_t get_time_t_max(void) +{ + return TIME_T_MAX; +} + +/******************************************************************* +a gettimeofday wrapper +********************************************************************/ +void GetTimeOfDay(struct timeval *tval) +{ +#ifdef HAVE_GETTIMEOFDAY_TZ + gettimeofday(tval,NULL); +#else + gettimeofday(tval); +#endif +} + + +#define TIME_FIXUP_CONSTANT 11644473600LL + +/**************************************************************************** +interpret an 8 byte "filetime" structure to a time_t +It's originally in "100ns units since jan 1st 1601" +****************************************************************************/ +time_t nt_time_to_unix(NTTIME nt) +{ + if (nt == 0) { + return 0; + } + if (nt == -1LL) { + return (time_t)-1; + } + nt += 1000*1000*10/2; + nt /= 1000*1000*10; + nt -= TIME_FIXUP_CONSTANT; + + if (TIME_T_MIN > nt || nt > TIME_T_MAX) { + return 0; + } + + return (time_t)nt; +} + + +/**************************************************************************** +put a 8 byte filetime from a time_t +This takes GMT as input +****************************************************************************/ +void unix_to_nt_time(NTTIME *nt, time_t t) +{ + uint64_t t2; + + if (t == (time_t)-1) { + *nt = (NTTIME)-1LL; + return; + } + if (t == 0) { + *nt = 0; + return; + } + + t2 = t; + t2 += TIME_FIXUP_CONSTANT; + t2 *= 1000*1000*10; + + *nt = t2; +} + + +/**************************************************************************** +check if it's a null unix time +****************************************************************************/ +BOOL null_time(time_t t) +{ + return t == 0 || + t == (time_t)0xFFFFFFFF || + t == (time_t)-1; +} + + +/**************************************************************************** +check if it's a null NTTIME +****************************************************************************/ +BOOL null_nttime(NTTIME t) +{ + return t == 0 || t == (NTTIME)-1; +} + +/******************************************************************* + create a 16 bit dos packed date +********************************************************************/ +static uint16_t make_dos_date1(struct tm *t) +{ + uint16_t ret=0; + ret = (((uint_t)(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 +********************************************************************/ +static uint16_t make_dos_time1(struct tm *t) +{ + uint16_t ret=0; + ret = ((((uint_t)t->tm_min >> 3)&0x7) | (((uint_t)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 +********************************************************************/ +static uint32_t make_dos_date(time_t unixdate, int zone_offset) +{ + struct tm *t; + uint32_t ret=0; + + if (unixdate == 0) { + return 0; + } + + unixdate -= zone_offset; + + t = gmtime(&unixdate); + if (!t) { + return 0xFFFFFFFF; + } + + ret = make_dos_date1(t); + ret = ((ret&0xFFFF)<<16) | make_dos_time1(t); + + return ret; +} + +/******************************************************************* +put a dos date into a buffer (time/date format) +This takes GMT time and puts local time in the buffer +********************************************************************/ +void push_dos_date(uint8_t *buf, int offset, time_t unixdate, int zone_offset) +{ + uint32_t x = make_dos_date(unixdate, zone_offset); + 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 +********************************************************************/ +void push_dos_date2(uint8_t *buf,int offset,time_t unixdate, int zone_offset) +{ + uint32_t x; + x = make_dos_date(unixdate, zone_offset); + 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) +********************************************************************/ +void push_dos_date3(uint8_t *buf,int offset,time_t unixdate, int zone_offset) +{ + if (!null_time(unixdate)) { + unixdate -= zone_offset; + } + SIVAL(buf,offset,unixdate); +} + +/******************************************************************* + interpret a 32 bit dos packed date/time to some parameters +********************************************************************/ +static void interpret_dos_date(uint32_t date,int *year,int *month,int *day,int *hour,int *minute,int *second) +{ + uint32_t p0,p1,p2,p3; + + 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; +} + +/******************************************************************* + create a unix date (int GMT) from a dos date (which is actually in + localtime) +********************************************************************/ +time_t pull_dos_date(const uint8_t *date_ptr, int zone_offset) +{ + uint32_t dos_date=0; + struct tm t; + time_t ret; + + dos_date = IVAL(date_ptr,0); + + if (dos_date == 0) return (time_t)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; + + ret = timegm(&t); + + ret += zone_offset; + + return ret; +} + +/******************************************************************* +like make_unix_date() but the words are reversed +********************************************************************/ +time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset) +{ + uint32_t x,x2; + + x = IVAL(date_ptr,0); + x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); + SIVAL(&x,0,x2); + + return pull_dos_date((void *)&x, zone_offset); +} + +/******************************************************************* + 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 pull_dos_date3(const uint8_t *date_ptr, int zone_offset) +{ + time_t t = (time_t)IVAL(date_ptr,0); + if (!null_time(t)) { + t += zone_offset; + } + return t; +} + + +/*************************************************************************** +return a HTTP/1.0 time string + ***************************************************************************/ +char *http_timestring(TALLOC_CTX *mem_ctx, time_t t) +{ + char *buf; + char tempTime[60]; + struct tm *tm = localtime(&t); + + if (!tm) { + return talloc_asprintf(mem_ctx,"%ld seconds since the Epoch",(long)t); + } + +#ifndef HAVE_STRFTIME + buf = talloc_strdup(mem_ctx, asctime(tm)); + if (buf[strlen(buf)-1] == '\n') { + buf[strlen(buf)-1] = 0; + } +#else + strftime(tempTime, sizeof(tempTime)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); + buf = talloc_strdup(mem_ctx, tempTime); +#endif /* !HAVE_STRFTIME */ + + return buf; +} + +/**************************************************************************** + Return the date and time as a string +****************************************************************************/ +char *timestring(TALLOC_CTX *mem_ctx, time_t t) +{ + char *TimeBuf; + char tempTime[80]; + struct tm *tm; + + tm = localtime(&t); + if (!tm) { + return talloc_asprintf(mem_ctx, + "%ld seconds since the Epoch", + (long)t); + } + +#ifdef HAVE_STRFTIME + /* some versions of gcc complain about using %c. This is a bug + in the gcc warning, not a bug in this code. See a recent + strftime() manual page for details. + */ + strftime(tempTime,sizeof(tempTime)-1,"%c %Z",tm); + TimeBuf = talloc_strdup(mem_ctx, tempTime); +#else + TimeBuf = talloc_strdup(mem_ctx, asctime(tm)); +#endif + + return TimeBuf; +} + +/* + return a talloced string representing a NTTIME for human consumption +*/ +const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt) +{ + time_t t; + if (nt == 0) { + return "NTTIME(0)"; + } + t = nt_time_to_unix(nt); + return timestring(mem_ctx, t); +} + + +/* + put a NTTIME into a packet +*/ +void push_nttime(uint8_t *base, uint16_t offset, NTTIME t) +{ + SBVAL(base, offset, t); +} + +/* + pull a NTTIME from a packet +*/ +NTTIME pull_nttime(uint8_t *base, uint16_t offset) +{ + NTTIME ret = BVAL(base, offset); + return ret; +} + +/* + parse a nttime as a large integer in a string and return a NTTIME +*/ +NTTIME nttime_from_string(const char *s) +{ + return strtoull(s, NULL, 0); +} + +/* + return (tv1 - tv2) in microseconds +*/ +int64_t usec_time_diff(struct timeval *tv1, struct timeval *tv2) +{ + int64_t sec_diff = tv1->tv_sec - tv2->tv_sec; + return (sec_diff * 1000000) + (int64_t)(tv1->tv_usec - tv2->tv_usec); +} + + +/* + return a zero timeval +*/ +struct timeval timeval_zero(void) +{ + struct timeval tv; + tv.tv_sec = 0; + tv.tv_usec = 0; + return tv; +} + +/* + return True if a timeval is zero +*/ +BOOL timeval_is_zero(const struct timeval *tv) +{ + return tv->tv_sec == 0 && tv->tv_usec == 0; +} + +/* + return a timeval for the current time +*/ +struct timeval timeval_current(void) +{ + struct timeval tv; + GetTimeOfDay(&tv); + return tv; +} + +/* + return a timeval struct with the given elements +*/ +struct timeval timeval_set(uint32_t secs, uint32_t usecs) +{ + struct timeval tv; + tv.tv_sec = secs; + tv.tv_usec = usecs; + return tv; +} + + +/* + return a timeval ofs microseconds after tv +*/ +struct timeval timeval_add(const struct timeval *tv, + uint32_t secs, uint32_t usecs) +{ + struct timeval tv2 = *tv; + const uint_t million = 1000000; + tv2.tv_sec += secs; + tv2.tv_usec += usecs; + tv2.tv_sec += tv2.tv_usec / million; + tv2.tv_usec = tv2.tv_usec % million; + return tv2; +} + +/* + return the sum of two timeval structures +*/ +struct timeval timeval_sum(const struct timeval *tv1, + const struct timeval *tv2) +{ + return timeval_add(tv1, tv2->tv_sec, tv2->tv_usec); +} + +/* + return a timeval secs/usecs into the future +*/ +struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs) +{ + struct timeval tv = timeval_current(); + return timeval_add(&tv, secs, usecs); +} + +/* + compare two timeval structures. + Return -1 if tv1 < tv2 + Return 0 if tv1 == tv2 + Return 1 if tv1 > tv2 +*/ +int timeval_compare(const struct timeval *tv1, const struct timeval *tv2) +{ + if (tv1->tv_sec > tv2->tv_sec) return 1; + if (tv1->tv_sec < tv2->tv_sec) return -1; + if (tv1->tv_usec > tv2->tv_usec) return 1; + if (tv1->tv_usec < tv2->tv_usec) return -1; + return 0; +} + +/* + return True if a timer is in the past +*/ +BOOL timeval_expired(const struct timeval *tv) +{ + struct timeval tv2 = timeval_current(); + if (tv2.tv_sec > tv->tv_sec) return True; + if (tv2.tv_sec < tv->tv_sec) return False; + return (tv2.tv_usec >= tv->tv_usec); +} + +/* + return the number of seconds elapsed between two times +*/ +double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2) +{ + return (tv2->tv_sec - tv1->tv_sec) + + (tv2->tv_usec - tv1->tv_usec)*1.0e-6; +} + +/* + return the number of seconds elapsed since a given time +*/ +double timeval_elapsed(const struct timeval *tv) +{ + struct timeval tv2 = timeval_current(); + return timeval_elapsed2(tv, &tv2); +} + +/* + return the lesser of two timevals +*/ +struct timeval timeval_min(const struct timeval *tv1, + const struct timeval *tv2) +{ + if (tv1->tv_sec < tv2->tv_sec) return *tv1; + if (tv1->tv_sec > tv2->tv_sec) return *tv2; + if (tv1->tv_usec < tv2->tv_usec) return *tv1; + return *tv2; +} + +/* + return the greater of two timevals +*/ +struct timeval timeval_max(const struct timeval *tv1, + const struct timeval *tv2) +{ + if (tv1->tv_sec > tv2->tv_sec) return *tv1; + if (tv1->tv_sec < tv2->tv_sec) return *tv2; + if (tv1->tv_usec > tv2->tv_usec) return *tv1; + return *tv2; +} + +/* + return the difference between two timevals as a timeval + if tv1 comes after tv2, then return a zero timeval + (this is *tv2 - *tv1) +*/ +struct timeval timeval_until(const struct timeval *tv1, + const struct timeval *tv2) +{ + struct timeval t; + if (timeval_compare(tv1, tv2) >= 0) { + return timeval_zero(); + } + t.tv_sec = tv2->tv_sec - tv1->tv_sec; + if (tv1->tv_usec > tv2->tv_usec) { + t.tv_sec--; + t.tv_usec = 1000000 - (tv1->tv_usec - tv2->tv_usec); + } else { + t.tv_usec = tv2->tv_usec - tv1->tv_usec; + } + return t; +} + + +/* + convert a timeval to a NTTIME +*/ +NTTIME timeval_to_nttime(const struct timeval *tv) +{ + return 10*(tv->tv_usec + + ((TIME_FIXUP_CONSTANT + (uint64_t)tv->tv_sec) * 1000000)); +} + +/******************************************************************* +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 + (1900 - 1); + int by = b->tm_year + (1900 - 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 the UTC offset in seconds west of UTC, or 0 if it cannot be determined + ******************************************************************/ +int get_time_zone(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); +} diff --git a/source4/lib/util/unix_privs.c b/source4/lib/util/unix_privs.c new file mode 100644 index 0000000000..3c0f319776 --- /dev/null +++ b/source4/lib/util/unix_privs.c @@ -0,0 +1,68 @@ +/* + Unix SMB/CIFS implementation. + + gain/lose root privileges + + Copyright (C) Andrew Tridgell 2004 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/filesys.h" + +/* + there are times when smbd needs to temporarily gain root privileges + to do some operation. To do this you call root_privileges(), which + returns a talloc handle. To restore your previous privileges + talloc_free() this pointer. + + Note that this call is considered successful even if it does not + manage to gain root privileges, but it will call smb_abort() if it + fails to restore the privileges afterwards. The logic is that + failing to gain root access can be caught by whatever operation + needs to be run as root failing, but failing to lose the root + privileges is dangerous. + + This also means that this code is safe to be called from completely + unprivileged processes. +*/ + +struct saved_state { + uid_t uid; +}; + +static int privileges_destructor(void *ptr) +{ + struct saved_state *s = ptr; + if (geteuid() != s->uid && + seteuid(s->uid) != 0) { + smb_panic("Failed to restore privileges"); + } + return 0; +} + +void *root_privileges(void) +{ + struct saved_state *s; + s = talloc(NULL, struct saved_state); + if (!s) return NULL; + s->uid = geteuid(); + if (s->uid != 0) { + seteuid(0); + } + talloc_set_destructor(s, privileges_destructor); + return s; +} diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c new file mode 100644 index 0000000000..17dde332e1 --- /dev/null +++ b/source4/lib/util/util.c @@ -0,0 +1,737 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Jeremy Allison 2001-2002 + Copyright (C) Simo Sorce 2001 + Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003. + Copyright (C) James J Myers 2003 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "dynconfig.h" +#include "system/network.h" +#include "system/iconv.h" +#include "system/filesys.h" + +/*************************************************************************** + 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"; +} + + +/******************************************************************* + Check if a file exists - call vfs_file_exist for samba files. +********************************************************************/ +BOOL file_exist(const char *fname) +{ + struct stat st; + + if (stat(fname, &st) != 0) { + return False; + } + + return ((S_ISREG(st.st_mode)) || (S_ISFIFO(st.st_mode))); +} + +/******************************************************************* + Check a files mod time. +********************************************************************/ + +time_t file_modtime(const char *fname) +{ + struct stat st; + + if (stat(fname,&st) != 0) + return(0); + + return(st.st_mtime); +} + +/******************************************************************* + Check if a directory exists. +********************************************************************/ + +BOOL directory_exist(const char *dname) +{ + struct stat st; + BOOL ret; + + if (stat(dname,&st) != 0) { + return False; + } + + ret = S_ISDIR(st.st_mode); + if(!ret) + errno = ENOTDIR; + return ret; +} + +BOOL directory_create_or_exist(const char *dname, uid_t uid, + mode_t dir_perms) +{ + mode_t old_umask; + struct stat st; + + old_umask = umask(0); + if (lstat(dname, &st) == -1) { + if (errno == ENOENT) { + /* Create directory */ + if (mkdir(dname, dir_perms) == -1) { + DEBUG(0, ("error creating directory " + "%s: %s\n", dname, + strerror(errno))); + umask(old_umask); + return False; + } + } else { + DEBUG(0, ("lstat failed on directory %s: %s\n", + dname, strerror(errno))); + umask(old_umask); + return False; + } + } else { + /* Check ownership and permission on existing directory */ + if (!S_ISDIR(st.st_mode)) { + DEBUG(0, ("directory %s isn't a directory\n", + dname)); + umask(old_umask); + return False; + } + if ((st.st_uid != uid) || + ((st.st_mode & 0777) != dir_perms)) { + DEBUG(0, ("invalid permissions on directory " + "%s\n", dname)); + umask(old_umask); + return False; + } + } + return True; +} + + +/******************************************************************* + Close the low 3 fd's and open dev/null in their place. +********************************************************************/ +static void close_low_fds(BOOL stderr_too) +{ +#ifndef VALGRIND + int fd; + int i; + + close(0); + close(1); + + if (stderr_too) + close(2); + + /* try and use up these file descriptors, so silly + library routines writing to stdout etc won't cause havoc */ + for (i=0;i<3;i++) { + if (i == 2 && !stderr_too) + continue; + + fd = open("/dev/null",O_RDWR,0); + if (fd < 0) + fd = open("/dev/null",O_WRONLY,0); + if (fd < 0) { + DEBUG(0,("Can't open /dev/null\n")); + return; + } + if (fd != i) { + DEBUG(0,("Didn't get file descriptor %d\n",i)); + return; + } + } +#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 = fcntl(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 fcntl( fd, F_SETFL, val); +#undef FLAG_TO_SET +} + + +/******************************************************************* + Sleep for a specified number of milliseconds. +********************************************************************/ + +void msleep(uint_t t) +{ + struct timeval tval; + + tval.tv_sec = t/1000; + tval.tv_usec = 1000*(t%1000); + /* this should be the real select - do NOT replace + with sys_select() */ + select(0,NULL,NULL,NULL,&tval); +} + +/**************************************************************************** + Become a daemon, discarding the controlling terminal. +****************************************************************************/ + +void become_daemon(BOOL Fork) +{ + if (Fork) { + if (fork()) { + _exit(0); + } + } + + /* detach from the terminal */ +#ifdef HAVE_SETSID + setsid(); +#elif defined(TIOCNOTTY) + { + int i = open("/dev/tty", O_RDWR, 0); + if (i != -1) { + ioctl(i, (int) TIOCNOTTY, (char *)0); + close(i); + } + } +#endif /* HAVE_SETSID */ + + /* Close fd's 0,1,2. Needed if started by rsh */ + close_low_fds(False); /* Don't close stderr, let the debug system + attach it to the logfile */ +} + + +/**************************************************************************** + 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); +} + + +/* + see if a string matches either our primary or one of our secondary + netbios aliases. do a case insensitive match +*/ +BOOL is_myname(const char *name) +{ + const char **aliases; + int i; + + if (strcasecmp(name, lp_netbios_name()) == 0) { + return True; + } + + aliases = lp_netbios_aliases(); + for (i=0; aliases && aliases[i]; i++) { + if (strcasecmp(name, aliases[i]) == 0) { + return True; + } + } + + return False; +} + + +/**************************************************************************** + Get my own name, return in malloc'ed storage. +****************************************************************************/ + +char* get_myname(void) +{ + char *hostname; + const int host_name_max = 255; + char *p; + + hostname = malloc(host_name_max+1); + *hostname = 0; + + /* get my host name */ + if (gethostname(hostname, host_name_max+1) == -1) { + DEBUG(0,("gethostname failed\n")); + return NULL; + } + + /* Ensure null termination. */ + hostname[host_name_max] = '\0'; + + /* split off any parts after an initial . */ + p = strchr_m(hostname,'.'); + + if (p) + *p = 0; + + return hostname; +} + +/**************************************************************************** + Return true if a string could be a pure IP address. +****************************************************************************/ + +BOOL is_ipaddress(const char *str) +{ + BOOL pure_address = True; + int i; + + for (i=0; pure_address && str[i]; i++) + if (!(isdigit((int)str[i]) || str[i] == '.')) + pure_address = False; + + /* Check that a pure number is not misinterpreted as an IP */ + pure_address = pure_address && (strchr_m(str, '.') != NULL); + + return pure_address; +} + +/**************************************************************************** + Interpret an internet address or name into an IP address in 4 byte form. +****************************************************************************/ +uint32_t interpret_addr(const char *str) +{ + struct hostent *hp; + uint32_t res; + + if (str == NULL || *str == 0 || + strcmp(str,"0.0.0.0") == 0) { + return 0; + } + if (strcmp(str,"255.255.255.255") == 0) { + return 0xFFFFFFFF; + } + /* recognise 'localhost' as a special name. This fixes problems with + some hosts that don't have localhost in /etc/hosts */ + if (strcasecmp(str,"localhost") == 0) { + str = "127.0.0.1"; + } + + /* if it's in the form of an IP address then get the lib to interpret it */ + if (is_ipaddress(str)) { + res = inet_addr(str); + } else { + /* otherwise assume it's a network name of some sort and use + sys_gethostbyname */ + if ((hp = sys_gethostbyname(str)) == 0) { + DEBUG(3,("sys_gethostbyname: Unknown host. %s\n",str)); + return 0; + } + + if(hp->h_addr == NULL) { + DEBUG(3,("sys_gethostbyname: host address is invalid for host %s\n",str)); + return 0; + } + memcpy((char *)&res,(char *)hp->h_addr, 4); + } + + if (res == (uint32_t)-1) + return(0); + + return(res); +} + +/******************************************************************* + A convenient addition to interpret_addr(). +******************************************************************/ +struct ipv4_addr interpret_addr2(const char *str) +{ + struct ipv4_addr ret; + uint32_t a = interpret_addr(str); + ret.addr = a; + return ret; +} + +/******************************************************************* + Check if an IP is the 0.0.0.0. +******************************************************************/ + +BOOL is_zero_ip(struct ipv4_addr ip) +{ + return ip.addr == 0; +} + +/******************************************************************* + Are two IPs on the same subnet? +********************************************************************/ + +BOOL same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask) +{ + uint32_t net1,net2,nmask; + + nmask = ntohl(mask.addr); + net1 = ntohl(ip1.addr); + net2 = ntohl(ip2.addr); + + return((net1 & nmask) == (net2 & nmask)); +} + + +/**************************************************************************** + Check if a process exists. Does this work on all unixes? +****************************************************************************/ + +BOOL process_exists(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); +} + +/**************************************************************************** + Simple routine to do POSIX file locking. Cruft in NFS and 64->32 bit mapping + is dealt with in posix.c +****************************************************************************/ + +BOOL fcntl_lock(int fd, int op, off_t offset, off_t count, int type) +{ + struct flock lock; + int ret; + + DEBUG(8,("fcntl_lock %d %d %.0f %.0f %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 = fcntl(fd,op,&lock); + + if (ret == -1 && errno != 0) + DEBUG(3,("fcntl_lock: fcntl lock gave errno %d (%s)\n",errno,strerror(errno))); + + /* a lock query */ + if (op == F_GETLK) { + if ((ret != -1) && + (lock.l_type != F_UNLCK) && + (lock.l_pid != 0) && + (lock.l_pid != getpid())) { + DEBUG(3,("fcntl_lock: fd %d is locked by pid %d\n",fd,(int)lock.l_pid)); + return(True); + } + + /* it must be not locked or locked by me */ + return(False); + } + + /* a lock set or unset */ + if (ret == -1) { + 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))); + return(False); + } + + /* everything went OK */ + DEBUG(8,("fcntl_lock: Lock call successful\n")); + + return(True); +} + + +static void print_asc(int level, const uint8_t *buf,int len) +{ + int i; + for (i=0;i8) 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")); + } +} + +/***************************************************************** + malloc that aborts with smb_panic on fail or zero size. + *****************************************************************/ + +void *smb_xmalloc(size_t size) +{ + void *p; + if (size == 0) + smb_panic("smb_xmalloc: called with zero size.\n"); + if ((p = malloc(size)) == NULL) + smb_panic("smb_xmalloc: malloc fail.\n"); + return p; +} + +/** + Memdup with smb_panic on fail. +**/ + +void *smb_xmemdup(const void *p, size_t size) +{ + void *p2; + p2 = smb_xmalloc(size); + memcpy(p2, p, size); + return p2; +} + +/** + strdup that aborts on malloc fail. +**/ + +char *smb_xstrdup(const char *s) +{ + char *s1 = strdup(s); + if (!s1) + smb_panic("smb_xstrdup: malloc fail\n"); + return s1; +} + + +/***************************************************************** + Like strdup but for memory. +*****************************************************************/ + +void *memdup(const void *p, size_t size) +{ + void *p2; + if (size == 0) + return NULL; + p2 = malloc(size); + if (!p2) + return NULL; + memcpy(p2, p, size); + return p2; +} + +/***************************************************************** + A useful function for returning a path in the Samba lock directory. +*****************************************************************/ +char *lock_path(TALLOC_CTX* mem_ctx, const char *name) +{ + char *fname, *dname; + if (name == NULL) { + return NULL; + } + if (name[0] == 0 || name[0] == '/' || strstr(name, ":/")) { + return talloc_strdup(mem_ctx, name); + } + + dname = talloc_strdup(mem_ctx, lp_lockdir()); + trim_string(dname,"","/"); + + if (!directory_exist(dname)) { + mkdir(dname,0755); + } + + fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name); + + talloc_free(dname); + + return fname; +} + + +/***************************************************************** + A useful function for returning a path in the Samba piddir directory. +*****************************************************************/ +static char *pid_path(TALLOC_CTX* mem_ctx, const char *name) +{ + char *fname, *dname; + + dname = talloc_strdup(mem_ctx, lp_piddir()); + trim_string(dname,"","/"); + + if (!directory_exist(dname)) { + mkdir(dname,0755); + } + + fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name); + + talloc_free(dname); + + return fname; +} + + +/** + * @brief Returns an absolute path to a file in the Samba lib directory. + * + * @param name File to find, relative to LIBDIR. + * + * @retval Pointer to a talloc'ed string containing the full path. + **/ + +char *lib_path(TALLOC_CTX* mem_ctx, const char *name) +{ + char *fname; + fname = talloc_asprintf(mem_ctx, "%s/%s", dyn_LIBDIR, name); + return fname; +} + +/** + * @brief Returns an absolute path to a file in the Samba private directory. + * + * @param name File to find, relative to PRIVATEDIR. + * if name is not relative, then use it as-is + * + * @retval Pointer to a talloc'ed string containing the full path. + **/ +char *private_path(TALLOC_CTX* mem_ctx, const char *name) +{ + char *fname; + if (name == NULL) { + return NULL; + } + if (name[0] == 0 || name[0] == '/' || strstr(name, ":/")) { + return talloc_strdup(mem_ctx, name); + } + fname = talloc_asprintf(mem_ctx, "%s/%s", lp_private_dir(), name); + return fname; +} + +/* + return a path in the smbd.tmp directory, where all temporary file + for smbd go. If NULL is passed for name then return the directory + path itself +*/ +char *smbd_tmp_path(TALLOC_CTX *mem_ctx, const char *name) +{ + char *fname, *dname; + + dname = pid_path(mem_ctx, "smbd.tmp"); + if (!directory_exist(dname)) { + mkdir(dname,0755); + } + + if (name == NULL) { + return dname; + } + + fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name); + talloc_free(dname); + + return fname; +} + +static char *modules_path(TALLOC_CTX* mem_ctx, const char *name) +{ + return talloc_asprintf(mem_ctx, "%s/%s", dyn_MODULESDIR, name); +} + +init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem) +{ + char *path = modules_path(mem_ctx, subsystem); + init_module_fn *ret; + + ret = load_modules(mem_ctx, path); + + talloc_free(path); + + return ret; +} + +void dump_data_pw(const char *msg, const uint8_t * data, size_t len) +{ +#ifdef DEBUG_PASSWORD + DEBUG(11, ("%s", msg)); + if (data != NULL && len > 0) + { + dump_data(11, data, len); + } +#endif +} + + +/* see if a range of memory is all zero. A NULL pointer is considered + to be all zero */ +BOOL all_zero(const uint8_t *ptr, uint_t size) +{ + int i; + if (!ptr) return True; + for (i=0;i= MAX_MALLOC_SIZE/el_size) { + return NULL; + } + if (!ptr) { + return malloc(el_size * count); + } + return realloc(ptr, el_size * count); +} + diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h new file mode 100644 index 0000000000..55d775e25c --- /dev/null +++ b/source4/lib/util/util.h @@ -0,0 +1,81 @@ +/* + Unix SMB/CIFS implementation. + Utility functions for Samba + Copyright (C) Andrew Tridgell 1992-1999 + Copyright (C) John H Terpstra 1996-1999 + Copyright (C) Luke Kenneth Casson Leighton 1996-1999 + Copyright (C) Paul Ashton 1998 - 1999 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef _SAMBA_UTIL_H_ +#define _SAMBA_UTIL_H_ + +struct substitute_context; + +#include "util/xfile.h" +#include "util/debug.h" +#include "util/mutex.h" +#include "util/byteorder.h" +#include "util/util_proto.h" + +/* zero a structure */ +#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) + +/* zero a structure given a pointer to the structure */ +#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0) + +/* zero a structure given a pointer to the structure - no zero check */ +#define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x))) + +/* pointer difference macro */ +#define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2))) + +/* work out how many elements there are in a static array */ +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) + +/* assert macros */ +#define SMB_ASSERT(b) do { if (!(b)) { \ + DEBUG(0,("PANIC: assert failed at %s(%d)\n", __FILE__, __LINE__)); \ + smb_panic("assert failed"); }} while (0) + +#ifndef MIN +#define MIN(a,b) ((a)<(b)?(a):(b)) +#endif + +#ifndef MAX +#define MAX(a,b) ((a)>(b)?(a):(b)) +#endif + +#ifndef ABS +#define ABS(a) ((a)>0?(a):(-(a))) +#endif + +#ifndef SAFE_FREE /* Oh no this is also defined in tdb.h */ +/** + * Free memory if the pointer and zero the pointer. + * + * @note You are explicitly allowed to pass NULL pointers -- they will + * always be ignored. + **/ +#define SAFE_FREE(x) do { if ((x) != NULL) {free(discard_const_p(void *, (x))); (x)=NULL;} } while(0) +#endif + +#define malloc_p(type) (type *)malloc(sizeof(type)) +#define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count) +#define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count) + +#endif /* _SAMBA_UTIL_H_ */ diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c new file mode 100644 index 0000000000..246b03b4aa --- /dev/null +++ b/source4/lib/util/util_file.c @@ -0,0 +1,385 @@ +/* + * Unix SMB/CIFS implementation. + * SMB parameters and setup + * Copyright (C) Andrew Tridgell 1992-1998 Modified by Jeremy Allison 1995. + * + * Added afdgets() Jelmer Vernooij 2005 + * + * 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 the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 675 + * Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" +#include "system/shmem.h" +#include "system/filesys.h" + +/**************************************************************************** +read a line from a file with possible \ continuation chars. +Blanks at the start or end of a line are stripped. +The string will be allocated if s2 is NULL +****************************************************************************/ +char *fgets_slash(char *s2,int maxlen,XFILE *f) +{ + char *s=s2; + int len = 0; + int c; + BOOL start_of_line = True; + + if (x_feof(f)) + return(NULL); + + if (maxlen <2) return(NULL); + + if (!s2) + { + maxlen = MIN(maxlen,8); + s = (char *)malloc(maxlen); + } + + if (!s) return(NULL); + + *s = 0; + + while (len < maxlen-1) + { + c = x_getc(f); + switch (c) + { + case '\r': + break; + case '\n': + while (len > 0 && s[len-1] == ' ') + { + s[--len] = 0; + } + if (len > 0 && s[len-1] == '\\') + { + s[--len] = 0; + start_of_line = True; + break; + } + return(s); + case EOF: + if (len <= 0 && !s2) + SAFE_FREE(s); + return(len>0?s:NULL); + case ' ': + if (start_of_line) + break; + default: + start_of_line = False; + s[len++] = c; + s[len] = 0; + } + if (!s2 && len > maxlen-3) + { + char *t; + + maxlen *= 2; + t = realloc_p(s, char, maxlen); + if (!t) { + DEBUG(0,("fgets_slash: failed to expand buffer!\n")); + SAFE_FREE(s); + return(NULL); + } else s = t; + } + } + return(s); +} + +/* Read one line (data until next newline or eof) and allocate it */ +char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint) +{ + char *data = NULL; + ssize_t alloc_size = 0, offset = 0, ret; + int p; + + if (hint <= 0) hint = 0x100; + + do { + alloc_size += hint; + + data = talloc_realloc(mem_ctx, data, char, alloc_size); + + if (!data) + return NULL; + + ret = read(fd, data + offset, hint); + + if (ret == -1) { + talloc_free(data); + return NULL; + } + + /* Find newline */ + for (p = 0; p < ret; p++) { + if (data[offset + p] == '\n') + break; + } + + if (p < ret) { + data[offset + p] = '\0'; + + /* Go back to position of newline */ + lseek(fd, p - ret + 1, SEEK_CUR); + return data; + } + + offset += ret; + + } while (ret == hint); + + data[offset] = '\0'; + + return data; +} + + +/**************************************************************************** +load a file into memory from a fd. +****************************************************************************/ + +char *fd_load(int fd, size_t *size, TALLOC_CTX *mem_ctx) +{ + struct stat sbuf; + char *p; + + if (fstat(fd, &sbuf) != 0) return NULL; + + p = (char *)talloc_size(mem_ctx, sbuf.st_size+1); + if (!p) return NULL; + + if (read(fd, p, sbuf.st_size) != sbuf.st_size) { + talloc_free(p); + return NULL; + } + p[sbuf.st_size] = 0; + + if (size) *size = sbuf.st_size; + + return p; +} + +/**************************************************************************** +load a file into memory +****************************************************************************/ +char *file_load(const char *fname, size_t *size, TALLOC_CTX *mem_ctx) +{ + int fd; + char *p; + + if (!fname || !*fname) return NULL; + + fd = open(fname,O_RDONLY); + if (fd == -1) return NULL; + + p = fd_load(fd, size, mem_ctx); + + close(fd); + + return p; +} + + +/******************************************************************* +mmap (if possible) or read a file +********************************************************************/ +void *map_file(const char *fname, size_t size) +{ + size_t s2 = 0; + void *p = NULL; +#ifdef HAVE_MMAP + int fd; + fd = open(fname, O_RDONLY, 0); + if (fd == -1) { + DEBUG(2,("Failed to load %s - %s\n", fname, strerror(errno))); + return NULL; + } + p = mmap(NULL, size, PROT_READ, MAP_SHARED|MAP_FILE, fd, 0); + close(fd); + if (p == MAP_FAILED) { + DEBUG(1,("Failed to mmap %s - %s\n", fname, strerror(errno))); + return NULL; + } +#endif + if (!p) { + p = file_load(fname, &s2, talloc_autofree_context()); + if (!p) return NULL; + if (s2 != size) { + DEBUG(1,("incorrect size for %s - got %d expected %d\n", + fname, (int)s2, (int)size)); + talloc_free(p); + return NULL; + } + } + + return p; +} + + +/**************************************************************************** +parse a buffer into lines +****************************************************************************/ +static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx) +{ + int i; + char *s, **ret; + + if (!p) return NULL; + + for (s = p, i=0; s < p+size; s++) { + if (s[0] == '\n') i++; + } + + ret = talloc_array(mem_ctx, char *, i+2); + if (!ret) { + talloc_free(p); + return NULL; + } + + talloc_reference(ret, p); + + memset(ret, 0, sizeof(ret[0])*(i+2)); + if (numlines) *numlines = i; + + ret[0] = p; + for (s = p, i=0; s < p+size; s++) { + if (s[0] == '\n') { + s[0] = 0; + i++; + ret[i] = s+1; + } + if (s[0] == '\r') s[0] = 0; + } + + return ret; +} + + +/**************************************************************************** +load a file into memory and return an array of pointers to lines in the file +must be freed with talloc_free(). +****************************************************************************/ +char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx) +{ + char *p; + char **lines; + size_t size; + + p = file_load(fname, &size, mem_ctx); + if (!p) return NULL; + + lines = file_lines_parse(p, size, numlines, mem_ctx); + + talloc_free(p); + + return lines; +} + +/**************************************************************************** +load a fd into memory and return an array of pointers to lines in the file +must be freed with talloc_free(). If convert is true calls unix_to_dos on +the list. +****************************************************************************/ +char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx) +{ + char *p; + char **lines; + size_t size; + + p = fd_load(fd, &size, mem_ctx); + if (!p) return NULL; + + lines = file_lines_parse(p, size, numlines, mem_ctx); + + talloc_free(p); + + return lines; +} + + +/**************************************************************************** +take a list of lines and modify them to produce a list where \ continues +a line +****************************************************************************/ +void file_lines_slashcont(char **lines) +{ + int i, j; + + for (i=0; lines[i];) { + int len = strlen(lines[i]); + if (lines[i][len-1] == '\\') { + lines[i][len-1] = ' '; + if (lines[i+1]) { + char *p = &lines[i][len]; + while (p < lines[i+1]) *p++ = ' '; + for (j = i+1; lines[j]; j++) lines[j] = lines[j+1]; + } + } else { + i++; + } + } +} + +/* + save a lump of data into a file. Mostly used for debugging +*/ +BOOL file_save(const char *fname, const void *packet, size_t length) +{ + int fd; + fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0644); + if (fd == -1) { + return False; + } + if (write(fd, packet, length) != (size_t)length) { + return False; + } + close(fd); + return True; +} + +/* + see if a file exists +*/ +BOOL file_exists(const char *path) +{ + struct stat st; + return (stat(path, &st) == 0); +} + +int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) +{ + char *p; + int len, ret; + va_list ap2; + + VA_COPY(ap2, ap); + + len = vasprintf(&p, format, ap2); + if (len <= 0) return len; + ret = write(fd, p, len); + SAFE_FREE(p); + return ret; +} + +int fdprintf(int fd, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) +{ + va_list ap; + int ret; + + va_start(ap, format); + ret = vfdprintf(fd, format, ap); + va_end(ap); + return ret; +} diff --git a/source4/lib/util/util_getent.c b/source4/lib/util/util_getent.c new file mode 100644 index 0000000000..9f58472fb8 --- /dev/null +++ b/source4/lib/util/util_getent.c @@ -0,0 +1,284 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Simo Sorce 2001 + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + + +/**************************************************************** + Returns a single linked list of group entries. + Use grent_free() to free it after use. +****************************************************************/ + +struct sys_grent * getgrent_list(void) +{ + struct sys_grent *glist; + struct sys_grent *gent; + struct group *grp; + + gent = malloc_p(struct sys_grent); + if (gent == NULL) { + DEBUG (0, ("Out of memory in getgrent_list!\n")); + return NULL; + } + memset(gent, '\0', sizeof(struct sys_grent)); + glist = gent; + + setgrent(); + grp = getgrent(); + if (grp == NULL) { + endgrent(); + SAFE_FREE(glist); + return NULL; + } + + while (grp != NULL) { + int i,num; + + if (grp->gr_name) { + if ((gent->gr_name = strdup(grp->gr_name)) == NULL) + goto err; + } + if (grp->gr_passwd) { + if ((gent->gr_passwd = strdup(grp->gr_passwd)) == NULL) + goto err; + } + gent->gr_gid = grp->gr_gid; + + /* number of strings in gr_mem */ + for (num = 0; grp->gr_mem[num]; num++) + ; + + /* alloc space for gr_mem string pointers */ + if ((gent->gr_mem = malloc_array_p(char *, num+1)) == NULL) + goto err; + + memset(gent->gr_mem, '\0', (num+1) * sizeof(char *)); + + for (i=0; i < num; i++) { + if ((gent->gr_mem[i] = strdup(grp->gr_mem[i])) == NULL) + goto err; + } + gent->gr_mem[num] = NULL; + + grp = getgrent(); + if (grp) { + gent->next = malloc_p(struct sys_grent); + if (gent->next == NULL) + goto err; + gent = gent->next; + memset(gent, '\0', sizeof(struct sys_grent)); + } + } + + endgrent(); + return glist; + + err: + + endgrent(); + DEBUG(0, ("Out of memory in getgrent_list!\n")); + grent_free(glist); + return NULL; +} + +/**************************************************************** + Free the single linked list of group entries made by + getgrent_list() +****************************************************************/ + +void grent_free (struct sys_grent *glist) +{ + while (glist) { + struct sys_grent *prev; + + SAFE_FREE(glist->gr_name); + SAFE_FREE(glist->gr_passwd); + if (glist->gr_mem) { + int i; + for (i = 0; glist->gr_mem[i]; i++) + SAFE_FREE(glist->gr_mem[i]); + SAFE_FREE(glist->gr_mem); + } + prev = glist; + glist = glist->next; + SAFE_FREE(prev); + } +} + +/**************************************************************** + Returns a single linked list of passwd entries. + Use pwent_free() to free it after use. +****************************************************************/ + +struct sys_pwent * getpwent_list(void) +{ + struct sys_pwent *plist; + struct sys_pwent *pent; + struct passwd *pwd; + + pent = malloc_p(struct sys_pwent); + if (pent == NULL) { + DEBUG (0, ("Out of memory in getpwent_list!\n")); + return NULL; + } + plist = pent; + + setpwent(); + pwd = getpwent(); + while (pwd != NULL) { + memset(pent, '\0', sizeof(struct sys_pwent)); + if (pwd->pw_name) { + if ((pent->pw_name = strdup(pwd->pw_name)) == NULL) + goto err; + } + if (pwd->pw_passwd) { + if ((pent->pw_passwd = strdup(pwd->pw_passwd)) == NULL) + goto err; + } + pent->pw_uid = pwd->pw_uid; + pent->pw_gid = pwd->pw_gid; + if (pwd->pw_gecos) { + if ((pent->pw_name = strdup(pwd->pw_gecos)) == NULL) + goto err; + } + if (pwd->pw_dir) { + if ((pent->pw_name = strdup(pwd->pw_dir)) == NULL) + goto err; + } + if (pwd->pw_shell) { + if ((pent->pw_name = strdup(pwd->pw_shell)) == NULL) + goto err; + } + + pwd = getpwent(); + if (pwd) { + pent->next = malloc_p(struct sys_pwent); + if (pent->next == NULL) + goto err; + pent = pent->next; + } + } + + endpwent(); + return plist; + + err: + + endpwent(); + DEBUG(0, ("Out of memory in getpwent_list!\n")); + pwent_free(plist); + return NULL; +} + +/**************************************************************** + Free the single linked list of passwd entries made by + getpwent_list() +****************************************************************/ + +void pwent_free (struct sys_pwent *plist) +{ + while (plist) { + struct sys_pwent *prev; + + SAFE_FREE(plist->pw_name); + SAFE_FREE(plist->pw_passwd); + SAFE_FREE(plist->pw_gecos); + SAFE_FREE(plist->pw_dir); + SAFE_FREE(plist->pw_shell); + + prev = plist; + plist = plist->next; + SAFE_FREE(prev); + } +} + +/**************************************************************** + Add the individual group users onto the list. +****************************************************************/ + +static struct sys_userlist *add_members_to_userlist(struct sys_userlist *list_head, const struct group *grp) +{ + size_t num_users, i; + + /* Count the number of users. */ + for (num_users = 0; grp->gr_mem[num_users]; num_users++) + ; + + for (i = 0; i < num_users; i++) { + struct sys_userlist *entry = malloc_p(struct sys_userlist); + if (entry == NULL) { + free_userlist(list_head); + return NULL; + } + entry->unix_name = (char *)strdup(grp->gr_mem[i]); + if (entry->unix_name == NULL) { + SAFE_FREE(entry); + free_userlist(list_head); + return NULL; + } + DLIST_ADD(list_head, entry); + } + return list_head; +} + +/**************************************************************** + Get the list of UNIX users in a group. + We have to enumerate the /etc/group file as some UNIX getgrnam() + calls won't do that for us (notably Tru64 UNIX). +****************************************************************/ + +struct sys_userlist *get_users_in_group(const char *gname) +{ + struct sys_userlist *list_head = NULL; + struct group *gptr; + +#if !defined(BROKEN_GETGRNAM) + if ((gptr = (struct group *)getgrnam(gname)) == NULL) + return NULL; + return add_members_to_userlist(list_head, gptr); +#else + /* BROKEN_GETGRNAM - True64 */ + setgrent(); + while((gptr = getgrent()) != NULL) { + if (strequal(gname, gptr->gr_name)) { + list_head = add_members_to_userlist(list_head, gptr); + if (list_head == NULL) + return NULL; + } + } + endgrent(); + return list_head; +#endif +} + +/**************************************************************** + Free list allocated above. +****************************************************************/ + +void free_userlist(struct sys_userlist *list_head) +{ + while (list_head) { + struct sys_userlist *old_head = list_head; + DLIST_REMOVE(list_head, list_head); + SAFE_FREE(old_head->unix_name); + SAFE_FREE(old_head); + } +} diff --git a/source4/lib/util/util_pw.c b/source4/lib/util/util_pw.c new file mode 100644 index 0000000000..19893e396f --- /dev/null +++ b/source4/lib/util/util_pw.c @@ -0,0 +1,89 @@ +/* + Unix SMB/CIFS implementation. + + Safe versions of getpw* calls + + Copyright (C) Andrew Bartlett 2002 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +static struct passwd *alloc_copy_passwd(const struct passwd *from) +{ + struct passwd *ret = smb_xmalloc_p(struct passwd); + ZERO_STRUCTP(ret); + ret->pw_name = smb_xstrdup(from->pw_name); + ret->pw_passwd = smb_xstrdup(from->pw_passwd); + ret->pw_uid = from->pw_uid; + ret->pw_gid = from->pw_gid; + ret->pw_gecos = smb_xstrdup(from->pw_gecos); + ret->pw_dir = smb_xstrdup(from->pw_dir); + ret->pw_shell = smb_xstrdup(from->pw_shell); + return ret; +} + +void passwd_free (struct passwd **buf) +{ + if (!*buf) { + DEBUG(0, ("attempted double-free of allocated passwd\n")); + return; + } + + SAFE_FREE((*buf)->pw_name); + SAFE_FREE((*buf)->pw_passwd); + SAFE_FREE((*buf)->pw_gecos); + SAFE_FREE((*buf)->pw_dir); + SAFE_FREE((*buf)->pw_shell); + + SAFE_FREE(*buf); +} + +struct passwd *getpwnam_alloc(const char *name) +{ + struct passwd *temp; + + temp = sys_getpwnam(name); + + if (!temp) { +#if 0 + if (errno == ENOMEM) { + /* what now? */ + } +#endif + return NULL; + } + + return alloc_copy_passwd(temp); +} + +struct passwd *getpwuid_alloc(uid_t uid) +{ + struct passwd *temp; + + temp = sys_getpwuid(uid); + + if (!temp) { +#if 0 + if (errno == ENOMEM) { + /* what now? */ + } +#endif + return NULL; + } + + return alloc_copy_passwd(temp); +} diff --git a/source4/lib/util/util_sock.c b/source4/lib/util/util_sock.c new file mode 100644 index 0000000000..8a65a27d02 --- /dev/null +++ b/source4/lib/util/util_sock.c @@ -0,0 +1,128 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Tim Potter 2000-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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/network.h" + +enum SOCK_OPT_TYPES {OPT_BOOL,OPT_INT,OPT_ON}; + +static const struct { + const char *name; + int level; + int option; + int value; + int opttype; +} socket_options[] = { + {"SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, 0, OPT_BOOL}, + {"SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, 0, OPT_BOOL}, + {"SO_BROADCAST", SOL_SOCKET, SO_BROADCAST, 0, OPT_BOOL}, +#ifdef TCP_NODELAY + {"TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY, 0, OPT_BOOL}, +#endif +#ifdef IPTOS_LOWDELAY + {"IPTOS_LOWDELAY", IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY, OPT_ON}, +#endif +#ifdef IPTOS_THROUGHPUT + {"IPTOS_THROUGHPUT", IPPROTO_IP, IP_TOS, IPTOS_THROUGHPUT, OPT_ON}, +#endif +#ifdef SO_REUSEPORT + {"SO_REUSEPORT", SOL_SOCKET, SO_REUSEPORT, 0, OPT_BOOL}, +#endif +#ifdef SO_SNDBUF + {"SO_SNDBUF", SOL_SOCKET, SO_SNDBUF, 0, OPT_INT}, +#endif +#ifdef SO_RCVBUF + {"SO_RCVBUF", SOL_SOCKET, SO_RCVBUF, 0, OPT_INT}, +#endif +#ifdef SO_SNDLOWAT + {"SO_SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT, 0, OPT_INT}, +#endif +#ifdef SO_RCVLOWAT + {"SO_RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT, 0, OPT_INT}, +#endif +#ifdef SO_SNDTIMEO + {"SO_SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO, 0, OPT_INT}, +#endif +#ifdef SO_RCVTIMEO + {"SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, 0, OPT_INT}, +#endif + {NULL,0,0,0,0}}; + + +/**************************************************************************** + Set user socket options. +****************************************************************************/ +void set_socket_options(int fd, const char *options) +{ + const char **options_list = str_list_make(NULL, options, " \t,"); + int j; + + if (!options_list) + return; + + for (j = 0; options_list[j]; j++) { + const char *tok = options_list[j]; + int ret=0,i; + int value = 1; + char *p; + BOOL got_value = False; + + if ((p = strchr_m(tok,'='))) { + *p = 0; + value = atoi(p+1); + got_value = True; + } + + for (i=0;socket_options[i].name;i++) + if (strequal(socket_options[i].name,tok)) + break; + + if (!socket_options[i].name) { + DEBUG(0,("Unknown socket option %s\n",tok)); + continue; + } + + switch (socket_options[i].opttype) { + case OPT_BOOL: + case OPT_INT: + ret = setsockopt(fd,socket_options[i].level, + socket_options[i].option,(char *)&value,sizeof(int)); + break; + + case OPT_ON: + if (got_value) + DEBUG(0,("syntax error - %s does not take a value\n",tok)); + + { + int on = socket_options[i].value; + ret = setsockopt(fd,socket_options[i].level, + socket_options[i].option,(char *)&on,sizeof(int)); + } + break; + } + + if (ret != 0) + DEBUG(0,("Failed to set socket option %s (Error %s)\n",tok, strerror(errno) )); + } + + talloc_free(options_list); +} + diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c new file mode 100644 index 0000000000..b46787e3ea --- /dev/null +++ b/source4/lib/util/util_str.c @@ -0,0 +1,1209 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + + Copyright (C) Andrew Tridgell 1992-2001 + Copyright (C) Simo Sorce 2001-2002 + Copyright (C) Martin Pool 2003 + Copyright (C) James Peach 2005 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/iconv.h" +#include "smb.h" +#include "pstring.h" +#include "lib/ldb/include/ldb.h" + +/** + * @file + * @brief String utilities. + **/ + +/** + * Get the next token from a string, return False if none found. + * Handles double-quotes. + * + * Based on a routine by GJC@VILLAGE.COM. + * Extensively modified by Andrew.Tridgell@anu.edu.au + **/ +BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize) +{ + const char *s; + BOOL quoted; + size_t len=1; + + if (!ptr) + return(False); + + s = *ptr; + + /* default to simple separators */ + if (!sep) + sep = " \t\n\r"; + + /* find the first non sep char */ + while (*s && strchr_m(sep,*s)) + s++; + + /* nothing left? */ + if (! *s) + return(False); + + /* copy over the token */ + for (quoted = False; len < bufsize && *s && (quoted || !strchr_m(sep,*s)); s++) { + if (*s == '\"') { + quoted = !quoted; + } else { + len++; + *buff++ = *s; + } + } + + *ptr = (*s) ? s+1 : s; + *buff = 0; + + return(True); +} + +/** + Case insensitive string compararison +**/ +int strcasecmp_m(const char *s1, const char *s2) +{ + codepoint_t c1=0, c2=0; + size_t size1, size2; + + while (*s1 && *s2) { + c1 = next_codepoint(s1, &size1); + c2 = next_codepoint(s2, &size2); + + s1 += size1; + s2 += size2; + + if (c1 == c2) { + continue; + } + + if (c1 == INVALID_CODEPOINT || + c2 == INVALID_CODEPOINT) { + /* what else can we do?? */ + return c1 - c2; + } + + if (toupper_w(c1) != toupper_w(c2)) { + return c1 - c2; + } + } + + return *s1 - *s2; +} + +/** + * Compare 2 strings. + * + * @note The comparison is case-insensitive. + **/ +BOOL strequal(const char *s1, const char *s2) +{ + if (s1 == s2) + return(True); + if (!s1 || !s2) + return(False); + + return strcasecmp_m(s1,s2) == 0; +} + +/** + Compare 2 strings (case sensitive). +**/ +BOOL strcsequal(const char *s1,const char *s2) +{ + if (s1 == s2) + return(True); + if (!s1 || !s2) + return(False); + + return strcmp(s1,s2) == 0; +} + + +/** +Do a case-insensitive, whitespace-ignoring string compare. +**/ +int strwicmp(const char *psz1, const char *psz2) +{ + /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */ + /* appropriate value. */ + if (psz1 == psz2) + return (0); + else if (psz1 == NULL) + return (-1); + else if (psz2 == NULL) + return (1); + + /* sync the strings on first non-whitespace */ + while (1) { + while (isspace((int)*psz1)) + psz1++; + while (isspace((int)*psz2)) + psz2++; + if (toupper((unsigned char)*psz1) != toupper((unsigned char)*psz2) + || *psz1 == '\0' + || *psz2 == '\0') + break; + psz1++; + psz2++; + } + return (*psz1 - *psz2); +} + +/** + String replace. + NOTE: oldc and newc must be 7 bit characters +**/ +void string_replace(char *s, char oldc, char newc) +{ + while (*s) { + size_t size; + codepoint_t c = next_codepoint(s, &size); + if (c == oldc) { + *s = newc; + } + s += size; + } +} + +/** + Trim the specified elements off the front and back of a string. +**/ +BOOL trim_string(char *s,const char *front,const char *back) +{ + BOOL ret = False; + size_t front_len; + size_t back_len; + size_t len; + + /* Ignore null or empty strings. */ + if (!s || (s[0] == '\0')) + return False; + + front_len = front? strlen(front) : 0; + back_len = back? strlen(back) : 0; + + len = strlen(s); + + if (front_len) { + while (len && strncmp(s, front, front_len)==0) { + /* Must use memmove here as src & dest can + * easily overlap. Found by valgrind. JRA. */ + memmove(s, s+front_len, (len-front_len)+1); + len -= front_len; + ret=True; + } + } + + if (back_len) { + while ((len >= back_len) && strncmp(s+len-back_len,back,back_len)==0) { + s[len-back_len]='\0'; + len -= back_len; + ret=True; + } + } + return ret; +} + +/** + Find the number of 'c' chars in a string +**/ +size_t count_chars(const char *s, char c) +{ + size_t count = 0; + + while (*s) { + size_t size; + codepoint_t c2 = next_codepoint(s, &size); + if (c2 == c) count++; + s += size; + } + + return count; +} + +/** + Safe string copy into a known length string. maxlength does not + include the terminating zero. +**/ +char *safe_strcpy(char *dest,const char *src, size_t maxlength) +{ + size_t len; + + if (!dest) { + DEBUG(0,("ERROR: NULL dest in safe_strcpy\n")); + return NULL; + } + +#ifdef DEVELOPER + /* We intentionally write out at the extremity of the destination + * string. If the destination is too short (e.g. pstrcpy into mallocd + * or fstring) then this should cause an error under a memory + * checker. */ + dest[maxlength] = '\0'; + if (PTR_DIFF(&len, dest) > 0) { /* check if destination is on the stack, ok if so */ + log_suspicious_usage("safe_strcpy", src); + } +#endif + + if (!src) { + *dest = 0; + return dest; + } + + len = strlen(src); + + if (len > maxlength) { + DEBUG(0,("ERROR: string overflow by %u (%u - %u) in safe_strcpy [%.50s]\n", + (uint_t)(len-maxlength), (unsigned)len, (unsigned)maxlength, src)); + len = maxlength; + } + + memmove(dest, src, len); + dest[len] = 0; + return dest; +} + +/** + Safe string cat into a string. maxlength does not + include the terminating zero. +**/ +char *safe_strcat(char *dest, const char *src, size_t maxlength) +{ + size_t src_len, dest_len; + + if (!dest) { + DEBUG(0,("ERROR: NULL dest in safe_strcat\n")); + return NULL; + } + + if (!src) + return dest; + +#ifdef DEVELOPER + if (PTR_DIFF(&src_len, dest) > 0) { /* check if destination is on the stack, ok if so */ + log_suspicious_usage("safe_strcat", src); + } +#endif + src_len = strlen(src); + dest_len = strlen(dest); + + if (src_len + dest_len > maxlength) { + DEBUG(0,("ERROR: string overflow by %d in safe_strcat [%.50s]\n", + (int)(src_len + dest_len - maxlength), src)); + if (maxlength > dest_len) { + memcpy(&dest[dest_len], src, maxlength - dest_len); + } + dest[maxlength] = 0; + return NULL; + } + + memcpy(&dest[dest_len], src, src_len); + dest[dest_len + src_len] = 0; + return dest; +} + +/** + Paranoid strcpy into a buffer of given length (includes terminating + zero. Strips out all but 'a-Z0-9' and the character in other_safe_chars + and replaces with '_'. Deliberately does *NOT* check for multibyte + characters. Don't change it ! +**/ + +char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength) +{ + size_t len, i; + + if (maxlength == 0) { + /* can't fit any bytes at all! */ + return NULL; + } + + if (!dest) { + DEBUG(0,("ERROR: NULL dest in alpha_strcpy\n")); + return NULL; + } + + if (!src) { + *dest = 0; + return dest; + } + + len = strlen(src); + if (len >= maxlength) + len = maxlength - 1; + + if (!other_safe_chars) + other_safe_chars = ""; + + for(i = 0; i < len; i++) { + int val = (src[i] & 0xff); + if (isupper(val) || islower(val) || isdigit(val) || strchr_m(other_safe_chars, val)) + dest[i] = src[i]; + else + dest[i] = '_'; + } + + dest[i] = '\0'; + + return dest; +} + +/** + Like strncpy but always null terminates. Make sure there is room! + The variable n should always be one less than the available size. +**/ + +char *StrnCpy(char *dest,const char *src,size_t n) +{ + char *d = dest; + if (!dest) + return(NULL); + if (!src) { + *dest = 0; + return(dest); + } + while (n-- && (*d++ = *src++)) + ; + *d = 0; + return(dest); +} + + +/** + Routine to get hex characters and turn them into a 16 byte array. + the array can be variable length, and any non-hex-numeric + characters are skipped. "0xnn" or "0Xnn" is specially catered + for. + + valid examples: "0A5D15"; "0x15, 0x49, 0xa2"; "59\ta9\te3\n" + + +**/ +size_t strhex_to_str(char *p, size_t len, const char *strhex) +{ + size_t i; + size_t num_chars = 0; + uint8_t lonybble, hinybble; + const char *hexchars = "0123456789ABCDEF"; + char *p1 = NULL, *p2 = NULL; + + for (i = 0; i < len && strhex[i] != 0; i++) { + if (strncasecmp(hexchars, "0x", 2) == 0) { + i++; /* skip two chars */ + continue; + } + + if (!(p1 = strchr_m(hexchars, toupper((unsigned char)strhex[i])))) + break; + + i++; /* next hex digit */ + + if (!(p2 = strchr_m(hexchars, toupper((unsigned char)strhex[i])))) + break; + + /* get the two nybbles */ + hinybble = PTR_DIFF(p1, hexchars); + lonybble = PTR_DIFF(p2, hexchars); + + p[num_chars] = (hinybble << 4) | lonybble; + num_chars++; + + p1 = NULL; + p2 = NULL; + } + return num_chars; +} + +DATA_BLOB strhex_to_data_blob(const char *strhex) +{ + DATA_BLOB ret_blob = data_blob(NULL, strlen(strhex)/2+1); + + ret_blob.length = strhex_to_str((char *)ret_blob.data, + strlen(strhex), + strhex); + + return ret_blob; +} + + +/** + * Routine to print a buffer as HEX digits, into an allocated string. + */ +void hex_encode(const unsigned char *buff_in, size_t len, char **out_hex_buffer) +{ + int i; + char *hex_buffer; + + *out_hex_buffer = smb_xmalloc((len*2)+1); + hex_buffer = *out_hex_buffer; + + for (i = 0; i < len; i++) + slprintf(&hex_buffer[i*2], 3, "%02X", buff_in[i]); +} + +/** + Check if a string is part of a list. +**/ +BOOL in_list(const char *s, const char *list, BOOL casesensitive) +{ + pstring tok; + const char *p=list; + + if (!list) + return(False); + + while (next_token(&p,tok,LIST_SEP,sizeof(tok))) { + if (casesensitive) { + if (strcmp(tok,s) == 0) + return(True); + } else { + if (strcasecmp_m(tok,s) == 0) + return(True); + } + } + return(False); +} + +/** + Set a string value, allocing the space for the string +**/ +static BOOL string_init(char **dest,const char *src) +{ + if (!src) src = ""; + + (*dest) = strdup(src); + if ((*dest) == NULL) { + DEBUG(0,("Out of memory in string_init\n")); + return False; + } + return True; +} + +/** + Free a string value. +**/ +void string_free(char **s) +{ + if (s) SAFE_FREE(*s); +} + +/** + Set a string value, deallocating any existing space, and allocing the space + for the string +**/ +BOOL string_set(char **dest, const char *src) +{ + string_free(dest); + return string_init(dest,src); +} + +/** + Substitute a string for a pattern in another string. Make sure there is + enough room! + + This routine looks for pattern in s and replaces it with + insert. It may do multiple replacements. + + Any of " ; ' $ or ` in the insert string are replaced with _ + if len==0 then the string cannot be extended. This is different from the old + use of len==0 which was for no length checks to be done. +**/ + +void string_sub(char *s,const char *pattern, const char *insert, size_t len) +{ + char *p; + ssize_t ls,lp,li, i; + + if (!insert || !pattern || !*pattern || !s) + return; + + ls = (ssize_t)strlen(s); + lp = (ssize_t)strlen(pattern); + li = (ssize_t)strlen(insert); + + if (len == 0) + len = ls + 1; /* len is number of *bytes* */ + + while (lp <= ls && (p = strstr(s,pattern))) { + if (ls + (li-lp) >= len) { + DEBUG(0,("ERROR: string overflow by %d in string_sub(%.50s, %d)\n", + (int)(ls + (li-lp) - len), + pattern, (int)len)); + break; + } + if (li != lp) { + memmove(p+li,p+lp,strlen(p+lp)+1); + } + for (i=0;i= len) { + DEBUG(0,("ERROR: string overflow by %d in all_string_sub(%.50s, %d)\n", + (int)(ls + (li-lp) - len), + pattern, (int)len)); + break; + } + if (li != lp) { + memmove(p+li,p+lp,strlen(p+lp)+1); + } + memcpy(p, insert, li); + s = p + li; + ls += (li-lp); + } +} + + +/** + Strchr and strrchr_m are a bit complex on general multi-byte strings. +**/ +char *strchr_m(const char *s, char c) +{ + /* characters below 0x3F are guaranteed to not appear in + non-initial position in multi-byte charsets */ + if ((c & 0xC0) == 0) { + return strchr(s, c); + } + + while (*s) { + size_t size; + codepoint_t c2 = next_codepoint(s, &size); + if (c2 == c) { + return discard_const(s); + } + s += size; + } + + return NULL; +} + +char *strrchr_m(const char *s, char c) +{ + char *ret = NULL; + + /* characters below 0x3F are guaranteed to not appear in + non-initial position in multi-byte charsets */ + if ((c & 0xC0) == 0) { + return strrchr(s, c); + } + + while (*s) { + size_t size; + codepoint_t c2 = next_codepoint(s, &size); + if (c2 == c) { + ret = discard_const(s); + } + s += size; + } + + return ret; +} + +/* + return True if any (multi-byte) character is lower case +*/ +BOOL strhaslower(const char *string) +{ + while (*string) { + size_t c_size; + codepoint_t s; + codepoint_t t; + + s = next_codepoint(string, &c_size); + string += c_size; + + t = toupper_w(s); + + if (s != t) { + return True; /* that means it has lower case chars */ + } + } + + return False; +} + +/* + return True if any (multi-byte) character is upper case +*/ +BOOL strhasupper(const char *string) +{ + while (*string) { + size_t c_size; + codepoint_t s; + codepoint_t t; + + s = next_codepoint(string, &c_size); + string += c_size; + + t = tolower_w(s); + + if (s != t) { + return True; /* that means it has upper case chars */ + } + } + + return False; +} + +/** + Convert a string to lower case, allocated with talloc +**/ +char *strlower_talloc(TALLOC_CTX *ctx, const char *src) +{ + size_t size=0; + char *dest; + + /* this takes advantage of the fact that upper/lower can't + change the length of a character by more than 1 byte */ + dest = talloc_size(ctx, 2*(strlen(src))+1); + if (dest == NULL) { + return NULL; + } + + while (*src) { + size_t c_size; + codepoint_t c = next_codepoint(src, &c_size); + src += c_size; + + c = tolower_w(c); + + c_size = push_codepoint(dest+size, c); + if (c_size == -1) { + talloc_free(dest); + return NULL; + } + size += c_size; + } + + dest[size] = 0; + + return dest; +} + +/** + Convert a string to UPPER case, allocated with talloc +**/ +char *strupper_talloc(TALLOC_CTX *ctx, const char *src) +{ + size_t size=0; + char *dest; + + if (!src) { + return NULL; + } + + /* this takes advantage of the fact that upper/lower can't + change the length of a character by more than 1 byte */ + dest = talloc_size(ctx, 2*(strlen(src))+1); + if (dest == NULL) { + return NULL; + } + + while (*src) { + size_t c_size; + codepoint_t c = next_codepoint(src, &c_size); + src += c_size; + + c = toupper_w(c); + + c_size = push_codepoint(dest+size, c); + if (c_size == -1) { + talloc_free(dest); + return NULL; + } + size += c_size; + } + + dest[size] = 0; + + return dest; +} + +/** + Convert a string to lower case. +**/ +void strlower_m(char *s) +{ + char *d; + + /* this is quite a common operation, so we want it to be + fast. We optimise for the ascii case, knowing that all our + supported multi-byte character sets are ascii-compatible + (ie. they match for the first 128 chars) */ + while (*s && !(((uint8_t)*s) & 0x80)) { + *s = tolower((uint8_t)*s); + s++; + } + + if (!*s) + return; + + d = s; + + while (*s) { + size_t c_size, c_size2; + codepoint_t c = next_codepoint(s, &c_size); + c_size2 = push_codepoint(d, tolower_w(c)); + if (c_size2 > c_size) { + DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strlower_m\n", + c, tolower_w(c), (int)c_size, (int)c_size2)); + smb_panic("codepoint expansion in strlower_m\n"); + } + s += c_size; + d += c_size2; + } + *d = 0; +} + +/** + Convert a string to UPPER case. +**/ +void strupper_m(char *s) +{ + char *d; + + /* this is quite a common operation, so we want it to be + fast. We optimise for the ascii case, knowing that all our + supported multi-byte character sets are ascii-compatible + (ie. they match for the first 128 chars) */ + while (*s && !(((uint8_t)*s) & 0x80)) { + *s = toupper((uint8_t)*s); + s++; + } + + if (!*s) + return; + + d = s; + + while (*s) { + size_t c_size, c_size2; + codepoint_t c = next_codepoint(s, &c_size); + c_size2 = push_codepoint(d, toupper_w(c)); + if (c_size2 > c_size) { + DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strupper_m\n", + c, toupper_w(c), (int)c_size, (int)c_size2)); + smb_panic("codepoint expansion in strupper_m\n"); + } + s += c_size; + d += c_size2; + } + *d = 0; +} + +/** + Count the number of UCS2 characters in a string. Normally this will + be the same as the number of bytes in a string for single byte strings, + but will be different for multibyte. +**/ +size_t strlen_m(const char *s) +{ + size_t count = 0; + + if (!s) { + return 0; + } + + while (*s && !(((uint8_t)*s) & 0x80)) { + s++; + count++; + } + + if (!*s) { + return count; + } + + while (*s) { + size_t c_size; + codepoint_t c = next_codepoint(s, &c_size); + if (c < 0x10000) { + count += 1; + } else { + count += 2; + } + s += c_size; + } + + return count; +} + +/** + Work out the number of multibyte chars in a string, including the NULL + terminator. +**/ +size_t strlen_m_term(const char *s) +{ + if (!s) { + return 0; + } + + return strlen_m(s) + 1; +} + +/** + Unescape a URL encoded string, in place. +**/ + +void rfc1738_unescape(char *buf) +{ + char *p=buf; + + while ((p=strchr_m(p,'+'))) + *p = ' '; + + p = buf; + + while (p && *p && (p=strchr_m(p,'%'))) { + int c1 = p[1]; + int c2 = p[2]; + + if (c1 >= '0' && c1 <= '9') + c1 = c1 - '0'; + else if (c1 >= 'A' && c1 <= 'F') + c1 = 10 + c1 - 'A'; + else if (c1 >= 'a' && c1 <= 'f') + c1 = 10 + c1 - 'a'; + else {p++; continue;} + + if (c2 >= '0' && c2 <= '9') + c2 = c2 - '0'; + else if (c2 >= 'A' && c2 <= 'F') + c2 = 10 + c2 - 'A'; + else if (c2 >= 'a' && c2 <= 'f') + c2 = 10 + c2 - 'a'; + else {p++; continue;} + + *p = (c1<<4) | c2; + + memmove(p+1, p+3, strlen(p+3)+1); + p++; + } +} + +/** + * Decode a base64 string into a DATA_BLOB - simple and slow algorithm + **/ +DATA_BLOB base64_decode_data_blob(TALLOC_CTX *mem_ctx, const char *s) +{ + DATA_BLOB ret = data_blob_talloc(mem_ctx, s, strlen(s)+1); + ret.length = ldb_base64_decode((char *)ret.data); + return ret; +} + +/** + * Decode a base64 string in-place - wrapper for the above + **/ +void base64_decode_inplace(char *s) +{ + ldb_base64_decode(s); +} + +/** + * Encode a base64 string into a talloc()ed string caller to free. + **/ +char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data) +{ + return ldb_base64_encode(mem_ctx, (const char *)data.data, data.length); +} + +#ifdef VALGRIND +size_t valgrind_strlen(const char *s) +{ + size_t count; + for(count = 0; *s++; count++) + ; + return count; +} +#endif + + +/* + format a string into length-prefixed dotted domain format, as used in NBT + and in some ADS structures +*/ +const char *str_format_nbt_domain(TALLOC_CTX *mem_ctx, const char *s) +{ + char *ret; + int i; + if (!s || !*s) { + return talloc_strdup(mem_ctx, ""); + } + ret = talloc_size(mem_ctx, strlen(s)+2); + if (!ret) { + return ret; + } + + memcpy(ret+1, s, strlen(s)+1); + ret[0] = '.'; + + for (i=0;ret[i];i++) { + if (ret[i] == '.') { + char *p = strchr(ret+i+1, '.'); + if (p) { + ret[i] = p-(ret+i+1); + } else { + ret[i] = strlen(ret+i+1); + } + } + } + + return ret; +} + +BOOL add_string_to_array(TALLOC_CTX *mem_ctx, + const char *str, const char ***strings, int *num) +{ + char *dup_str = talloc_strdup(mem_ctx, str); + + *strings = talloc_realloc(mem_ctx, + *strings, + const char *, ((*num)+1)); + + if ((*strings == NULL) || (dup_str == NULL)) + return False; + + (*strings)[*num] = dup_str; + *num += 1; + + return True; +} + + + +/* + varient of strcmp() that handles NULL ptrs +*/ +int strcmp_safe(const char *s1, const char *s2) +{ + if (s1 == s2) { + return 0; + } + if (s1 == NULL || s2 == NULL) { + return s1?-1:1; + } + return strcmp(s1, s2); +} + + +/******************************************************************* +return the number of bytes occupied by a buffer in ASCII format +the result includes the null termination +limited by 'n' bytes +********************************************************************/ +size_t ascii_len_n(const char *src, size_t n) +{ + size_t len; + + len = strnlen(src, n); + if (len+1 <= n) { + len += 1; + } + + return len; +} + + +/******************************************************************* + Return a string representing a CIFS attribute for a file. +********************************************************************/ +char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib) +{ + int i, len; + const struct { + char c; + uint16_t attr; + } attr_strs[] = { + {'V', FILE_ATTRIBUTE_VOLUME}, + {'D', FILE_ATTRIBUTE_DIRECTORY}, + {'A', FILE_ATTRIBUTE_ARCHIVE}, + {'H', FILE_ATTRIBUTE_HIDDEN}, + {'S', FILE_ATTRIBUTE_SYSTEM}, + {'N', FILE_ATTRIBUTE_NORMAL}, + {'R', FILE_ATTRIBUTE_READONLY}, + {'d', FILE_ATTRIBUTE_DEVICE}, + {'t', FILE_ATTRIBUTE_TEMPORARY}, + {'s', FILE_ATTRIBUTE_SPARSE}, + {'r', FILE_ATTRIBUTE_REPARSE_POINT}, + {'c', FILE_ATTRIBUTE_COMPRESSED}, + {'o', FILE_ATTRIBUTE_OFFLINE}, + {'n', FILE_ATTRIBUTE_NONINDEXED}, + {'e', FILE_ATTRIBUTE_ENCRYPTED} + }; + char *ret; + + ret = talloc_size(mem_ctx, ARRAY_SIZE(attr_strs)+1); + if (!ret) { + return NULL; + } + + for (len=i=0; ibufused) return -1; + + /* on files being read full buffering is the only option */ + if ((f->open_flags & O_ACCMODE) == O_RDONLY) { + mode = X_IOFBF; + } + + /* destroy any earlier buffer */ + SAFE_FREE(f->buf); + f->buf = 0; + f->bufsize = 0; + f->next = NULL; + f->bufused = 0; + f->buftype = mode; + + if (f->buftype == X_IONBF) return 0; + + /* if buffering then we need some size */ + if (size == 0) size = XBUFSIZE; + + f->bufsize = size; + f->bufused = 0; + + return 0; +} + +/* allocate the buffer */ +static int x_allocate_buffer(XFILE *f) +{ + if (f->buf) return 1; + if (f->bufsize == 0) return 0; + f->buf = malloc(f->bufsize); + if (!f->buf) return 0; + f->next = f->buf; + return 1; +} + + +/* this looks more like open() than fopen(), but that is quite deliberate. + I want programmers to *think* about O_EXCL, O_CREAT etc not just + get them magically added +*/ +XFILE *x_fopen(const char *fname, int flags, mode_t mode) +{ + XFILE *ret; + + ret = malloc_p(XFILE); + if (!ret) return NULL; + + memset(ret, 0, sizeof(XFILE)); + + if ((flags & O_ACCMODE) == O_RDWR) { + /* we don't support RDWR in XFILE - use file + descriptors instead */ + errno = EINVAL; + return NULL; + } + + ret->open_flags = flags; + + ret->fd = open(fname, flags, mode); + if (ret->fd == -1) { + SAFE_FREE(ret); + return NULL; + } + + x_setvbuf(ret, NULL, X_IOFBF, XBUFSIZE); + + return ret; +} + +/* simulate fclose() */ +int x_fclose(XFILE *f) +{ + int ret; + + /* make sure we flush any buffered data */ + x_fflush(f); + + ret = close(f->fd); + f->fd = -1; + if (f->buf) { + /* make sure data can't leak into a later malloc */ + memset(f->buf, 0, f->bufsize); + SAFE_FREE(f->buf); + } + /* check the file descriptor given to the function is NOT one of the static + * descriptor of this libreary or we will free unallocated memory + * --sss */ + if (f != x_stdin && f != x_stdout && f != x_stderr) { + SAFE_FREE(f); + } + return ret; +} + +/* simulate fwrite() */ +size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f) +{ + ssize_t ret; + size_t total=0; + + /* we might be writing unbuffered */ + if (f->buftype == X_IONBF || + (!f->buf && !x_allocate_buffer(f))) { + ret = write(f->fd, p, size*nmemb); + if (ret == -1) return -1; + return ret/size; + } + + + while (total < size*nmemb) { + size_t n = f->bufsize - f->bufused; + n = MIN(n, (size*nmemb)-total); + + if (n == 0) { + /* it's full, flush it */ + x_fflush(f); + continue; + } + + memcpy(f->buf + f->bufused, total+(const char *)p, n); + f->bufused += n; + total += n; + } + + /* when line buffered we need to flush at the last linefeed. This can + flush a bit more than necessary, but that is harmless */ + if (f->buftype == X_IOLBF && f->bufused) { + int i; + for (i=(size*nmemb)-1; i>=0; i--) { + if (*(i+(const char *)p) == '\n') { + x_fflush(f); + break; + } + } + } + + return total/size; +} + +/* thank goodness for asprintf() */ + int x_vfprintf(XFILE *f, const char *format, va_list ap) +{ + char *p; + int len, ret; + va_list ap2; + + VA_COPY(ap2, ap); + + len = vasprintf(&p, format, ap2); + if (len <= 0) return len; + ret = x_fwrite(p, 1, len, f); + SAFE_FREE(p); + return ret; +} + + int x_fprintf(XFILE *f, const char *format, ...) +{ + va_list ap; + int ret; + + va_start(ap, format); + ret = x_vfprintf(f, format, ap); + va_end(ap); + return ret; +} + +/* at least fileno() is simple! */ +int x_fileno(XFILE *f) +{ + return f->fd; +} + +/* simulate fflush() */ +int x_fflush(XFILE *f) +{ + int ret; + + if (f->flags & X_FLAG_ERROR) return -1; + + if ((f->open_flags & O_ACCMODE) != O_WRONLY) { + errno = EINVAL; + return -1; + } + + if (f->bufused == 0) return 0; + + ret = write(f->fd, f->buf, f->bufused); + if (ret == -1) return -1; + + f->bufused -= ret; + if (f->bufused > 0) { + f->flags |= X_FLAG_ERROR; + memmove(f->buf, ret + (char *)f->buf, f->bufused); + return -1; + } + + return 0; +} + +/* simulate setbuffer() */ +void x_setbuffer(XFILE *f, char *buf, size_t size) +{ + x_setvbuf(f, buf, buf?X_IOFBF:X_IONBF, size); +} + +/* simulate setbuf() */ +void x_setbuf(XFILE *f, char *buf) +{ + x_setvbuf(f, buf, buf?X_IOFBF:X_IONBF, XBUFSIZE); +} + +/* simulate setlinebuf() */ +void x_setlinebuf(XFILE *f) +{ + x_setvbuf(f, NULL, X_IOLBF, 0); +} + + +/* simulate feof() */ +int x_feof(XFILE *f) +{ + if (f->flags & X_FLAG_EOF) return 1; + return 0; +} + +/* simulate ferror() */ +int x_ferror(XFILE *f) +{ + if (f->flags & X_FLAG_ERROR) return 1; + return 0; +} + +/* fill the read buffer */ +static void x_fillbuf(XFILE *f) +{ + int n; + + if (f->bufused) return; + + if (!f->buf && !x_allocate_buffer(f)) return; + + n = read(f->fd, f->buf, f->bufsize); + if (n <= 0) return; + f->bufused = n; + f->next = f->buf; +} + +/* simulate fgetc() */ +int x_fgetc(XFILE *f) +{ + int ret; + + if (f->flags & (X_FLAG_EOF | X_FLAG_ERROR)) return EOF; + + if (f->bufused == 0) x_fillbuf(f); + + if (f->bufused == 0) { + f->flags |= X_FLAG_EOF; + return EOF; + } + + ret = *(uint8_t *)(f->next); + f->next++; + f->bufused--; + return ret; +} + +/* simulate fread */ +size_t x_fread(void *p, size_t size, size_t nmemb, XFILE *f) +{ + size_t total = 0; + while (total < size*nmemb) { + int c = x_fgetc(f); + if (c == EOF) break; + (total+(char *)p)[0] = (char)c; + total++; + } + return total/size; +} + +/* simulate fgets() */ +char *x_fgets(char *s, int size, XFILE *stream) +{ + char *s0 = s; + int l = size; + while (l>1) { + int c = x_fgetc(stream); + if (c == EOF) break; + *s++ = (char)c; + l--; + if (c == '\n') break; + } + if (l==size || x_ferror(stream)) { + return 0; + } + *s = 0; + return s0; +} + +/* trivial seek, works only for SEEK_SET and SEEK_END if SEEK_CUR is + * set then an error is returned */ +off_t x_tseek(XFILE *f, off_t offset, int whence) +{ + if (f->flags & X_FLAG_ERROR) + return -1; + + /* only SEEK_SET and SEEK_END are supported */ + /* SEEK_CUR needs internal offset counter */ + if (whence != SEEK_SET && whence != SEEK_END) { + f->flags |= X_FLAG_EINVAL; + errno = EINVAL; + return -1; + } + + /* empty the buffer */ + switch (f->open_flags & O_ACCMODE) { + case O_RDONLY: + f->bufused = 0; + break; + case O_WRONLY: + if (x_fflush(f) != 0) + return -1; + break; + default: + errno = EINVAL; + return -1; + } + + f->flags &= ~X_FLAG_EOF; + return lseek(f->fd, offset, whence); +} diff --git a/source4/lib/util/xfile.h b/source4/lib/util/xfile.h new file mode 100644 index 0000000000..89fa9d1e11 --- /dev/null +++ b/source4/lib/util/xfile.h @@ -0,0 +1,49 @@ +/* + Unix SMB/CIFS implementation. + stdio replacement + Copyright (C) Andrew Tridgell 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef _XFILE_H_ +#define _XFILE_H_ +/* + see xfile.c for explanations +*/ + +typedef struct { + int fd; + char *buf; + char *next; + int bufsize; + int bufused; + int open_flags; + int buftype; + int flags; +} XFILE; + +extern XFILE *x_stdin, *x_stdout, *x_stderr; + +/* buffering type */ +#define X_IOFBF 0 +#define X_IOLBF 1 +#define X_IONBF 2 + +#define x_getc(f) x_fgetc(f) + +int x_vfprintf(XFILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2, 0); +int x_fprintf(XFILE *f, const char *format, ...) PRINTF_ATTRIBUTE(2, 3); +#endif /* _XFILE_H_ */ -- cgit From 57a55df196aa12529546c6f2ccc893fe68b32f2a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 23 Feb 2006 20:56:10 +0000 Subject: r13662: Typo fix, add more public headers (This used to be commit d98948716f237c3a501b283a0bbc3837bb3fd3c8) --- source4/lib/util/config.mk | 13 +++++++++++-- source4/lib/util/ms_fnmatch.c | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 79e145775d..81614ed647 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -1,6 +1,15 @@ -[SUBSYSTEM::LIBBASIC] +[LIBRARY::LIBBASIC] +MAJOR_VERSION = 0 +MINOR_VERSION = 0 +RELEASE_VERSION = 1 +DESCRIPTION = Generic utility functions PRIVATE_PROTO_HEADER = util_proto.h -PUBLIC_HEADERS = util.h +PUBLIC_HEADERS = util.h \ + byteorder.h \ + debug.h \ + mutex.h \ + safe_string.h \ + xfile.h OBJ_FILES = xfile.o \ debug.o \ fault.o \ diff --git a/source4/lib/util/ms_fnmatch.c b/source4/lib/util/ms_fnmatch.c index 699341bede..d44c8b87da 100644 --- a/source4/lib/util/ms_fnmatch.c +++ b/source4/lib/util/ms_fnmatch.c @@ -161,7 +161,7 @@ int ms_fnmatch(const char *pattern, const char *string, enum protocol_types prot } if (strpbrk(pattern, "<>*?\"") == NULL) { - /* this is not just an optmisation - it is essential + /* this is not just an optimisation - it is essential for LANMAN1 correctness */ return strcasecmp_m(pattern, string); } -- cgit From aa04388943fe5d7d8c873a6ee8a4cc9af2491532 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 28 Feb 2006 13:12:39 +0000 Subject: r13752: Add doxyfile and fix formatting of comments. Current output is available at http://samba.org/~jelmer/util-api/ (This used to be commit 90812203df151a5e62394306827c72adfe13c63c) --- source4/lib/util/Doxyfile | 1229 +++++++++++++++++++++++++++++++++++++++ source4/lib/util/capability.c | 5 + source4/lib/util/data_blob.c | 53 +- source4/lib/util/debug.c | 23 +- source4/lib/util/fault.c | 26 +- source4/lib/util/fsusage.c | 16 +- source4/lib/util/genrand.c | 25 +- source4/lib/util/idtree.c | 4 + source4/lib/util/module.c | 5 + source4/lib/util/ms_fnmatch.c | 6 +- source4/lib/util/mutex.c | 7 +- source4/lib/util/pidfile.c | 15 +- source4/lib/util/signal.c | 21 +- source4/lib/util/substitute.c | 31 +- source4/lib/util/time.c | 105 ++-- source4/lib/util/unix_privs.c | 5 + source4/lib/util/util.c | 97 +-- source4/lib/util/util_file.c | 45 +- source4/lib/util/util_sock.c | 9 +- source4/lib/util/util_str.c | 24 +- source4/lib/util/util_strlist.c | 34 +- source4/lib/util/util_unistr.c | 23 +- source4/lib/util/xfile.c | 5 + 23 files changed, 1584 insertions(+), 229 deletions(-) create mode 100644 source4/lib/util/Doxyfile (limited to 'source4/lib/util') diff --git a/source4/lib/util/Doxyfile b/source4/lib/util/Doxyfile new file mode 100644 index 0000000000..7205513eb1 --- /dev/null +++ b/source4/lib/util/Doxyfile @@ -0,0 +1,1229 @@ +# Doxyfile 1.4.4 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = SAMBA_UTIL + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = apidocs + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, +# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, +# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, +# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, +# Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for +# all platforms other than Windows). + +USE_WINDOWS_ENCODING = NO + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = include + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explicit @brief command for a brief description. + +JAVADOC_AUTOBRIEF = YES + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = YES + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources +# only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = NO + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is YES. + +SHOW_DIRECTORIES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from the +# version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the progam writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = . + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm + +FILE_PATTERNS = *.c byteorder.h debug.h mutex.h util.h xfile.h *.dox + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = include/config.h include/dlinklist.h \ + include/includes.h + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = examples + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = NO + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = YES + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = YES + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_PREDEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = NO + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = NO + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = NO + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = NO + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that a graph may be further truncated if the graph's +# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH +# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), +# the graph is not depth-constrained. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO diff --git a/source4/lib/util/capability.c b/source4/lib/util/capability.c index 0cebd33303..ae08fab533 100644 --- a/source4/lib/util/capability.c +++ b/source4/lib/util/capability.c @@ -19,6 +19,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/** + * @file + * @brief Capabilities functions + **/ + /* capabilities fns - will be needed when we enable kernel oplocks */ diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index c6471fbf54..dfcfaa41ea 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -21,10 +21,15 @@ #include "includes.h" -/******************************************************************* +/** + * @file + * @brief Manipulation of arbitrary data blobs + **/ + +/** construct a data blob, must be freed with data_blob_free() you can pass NULL for p and get a blank data blob -*******************************************************************/ +**/ DATA_BLOB data_blob_named(const void *p, size_t length, const char *name) { DATA_BLOB ret; @@ -48,9 +53,9 @@ DATA_BLOB data_blob_named(const void *p, size_t length, const char *name) return ret; } -/******************************************************************* +/** construct a data blob, using supplied TALLOC_CTX -*******************************************************************/ +**/ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name) { DATA_BLOB ret = data_blob_named(p, length, name); @@ -62,10 +67,10 @@ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t leng } -/******************************************************************* +/** reference a data blob, to the supplied TALLOC_CTX. Returns a NULL DATA_BLOB on failure -*******************************************************************/ +**/ DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) { DATA_BLOB ret = *blob; @@ -78,11 +83,11 @@ DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) return ret; } -/******************************************************************* +/** construct a zero data blob, using supplied TALLOC_CTX. use this sparingly as it initialises data - better to initialise yourself if you want specific data in the blob -*******************************************************************/ +**/ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) { DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, length); @@ -90,9 +95,9 @@ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) return blob; } -/******************************************************************* +/** free a data blob -*******************************************************************/ +**/ void data_blob_free(DATA_BLOB *d) { if (d) { @@ -102,9 +107,9 @@ void data_blob_free(DATA_BLOB *d) } } -/******************************************************************* +/** clear a DATA_BLOB's contents -*******************************************************************/ +**/ void data_blob_clear(DATA_BLOB *d) { if (d->data) { @@ -112,9 +117,9 @@ void data_blob_clear(DATA_BLOB *d) } } -/******************************************************************* +/** free a data blob and clear its contents -*******************************************************************/ +**/ void data_blob_clear_free(DATA_BLOB *d) { data_blob_clear(d); @@ -122,9 +127,9 @@ void data_blob_clear_free(DATA_BLOB *d) } -/******************************************************************* +/** check if two data blobs are equal -*******************************************************************/ +**/ BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) { if (d1->length != d2->length) { @@ -142,9 +147,9 @@ BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) return False; } -/******************************************************************* +/** print the data_blob as hex string -*******************************************************************/ +**/ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) { int i; @@ -161,10 +166,10 @@ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) return hex_string; } -/* +/** useful for constructing data blobs in test suites, while avoiding const warnings -*/ +**/ DATA_BLOB data_blob_string_const(const char *str) { DATA_BLOB blob; @@ -182,9 +187,9 @@ DATA_BLOB data_blob_const(const void *p, size_t length) } -/* +/** realloc a data_blob -*/ +**/ NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) { blob->data = talloc_realloc_size(mem_ctx, blob->data, length); @@ -193,9 +198,9 @@ NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) return NT_STATUS_OK; } -/* +/** append some data to a data blob -*/ +**/ NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const void *p, size_t length) { diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index 9df6e573b0..3a71ed2df6 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -24,6 +24,11 @@ #include "system/time.h" #include "dynconfig.h" +/** + * @file + * @brief Debug logging + **/ + /* this global variable determines what messages are printed */ int DEBUGLEVEL; @@ -74,7 +79,7 @@ void do_debug(const char *format, ...) free(s); } -/* +/** reopen the log file (usually called because the log file name might have changed) */ void reopen_logs(void) @@ -118,7 +123,7 @@ void reopen_logs(void) } } -/* +/** control the name of the logfile and whether logging will be to stdout, stderr or a file */ @@ -133,7 +138,7 @@ void setup_logging(const char *prog_name, enum debug_logtype new_logtype) reopen_logs(); } -/* +/** return a string constant containing n tabs no more than 10 tabs are returned */ @@ -146,8 +151,8 @@ const char *do_debug_tab(uint_t n) } -/* - log/print suspicious usage - print comments and backtrace +/** + log suspicious usage - print comments and backtrace */ void log_suspicious_usage(const char *from, const char *info) { @@ -155,6 +160,12 @@ void log_suspicious_usage(const char *from, const char *info) debug_handlers.ops.log_suspicious_usage(from, info); } } + + +/** + print suspicious usage - print comments and backtrace +*/ + void print_suspicious_usage(const char* from, const char* info) { if (debug_handlers.ops.print_suspicious_usage) { @@ -195,7 +206,7 @@ void log_task_id(void) } } -/* +/** register a set of debug handlers. */ void register_debug_handlers(const char *name, struct debug_ops *ops) diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index 3670575dcc..abe3f141ce 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -23,6 +23,11 @@ #include "system/wait.h" #include "system/filesys.h" +/** + * @file + * @brief Fault handling + */ + /* the registered fault handler */ static struct { const char *name; @@ -38,6 +43,9 @@ static const char *progname; #include #endif +/** + * Write backtrace to debug log + */ void call_backtrace(void) { #ifdef HAVE_BACKTRACE @@ -101,9 +109,9 @@ void call_backtrace(void) #endif } -/******************************************************************* +/** Something really nasty happened - panic ! -********************************************************************/ +**/ void smb_panic(const char *why) { const char *cmd = lp_panic_action(); @@ -138,9 +146,9 @@ void smb_panic(const char *why) abort(); } -/******************************************************************* +/** report a fault -********************************************************************/ +**/ static void fault_report(int sig) { static int counter; @@ -157,9 +165,9 @@ static void fault_report(int sig) exit(1); } -/**************************************************************************** +/** catch serious errors -****************************************************************************/ +**/ static void sig_fault(int sig) { if (fault_handlers.fault_handler) { @@ -170,9 +178,9 @@ static void sig_fault(int sig) fault_report(sig); } -/******************************************************************* +/** setup our fault handlers -********************************************************************/ +**/ void fault_setup(const char *pname) { if (progname == NULL) { @@ -192,7 +200,7 @@ void fault_setup(const char *pname) #endif } -/* +/** register a fault handler. Should only be called once in the execution of smbd. */ diff --git a/source4/lib/util/fsusage.c b/source4/lib/util/fsusage.c index f817672544..dde9c61eb3 100644 --- a/source4/lib/util/fsusage.c +++ b/source4/lib/util/fsusage.c @@ -21,6 +21,10 @@ #include "includes.h" #include "system/filesys.h" +/** + * @file + * @brief Utility functions for getting the amount of free disk space + */ /* Return the number of TOSIZE-byte blocks used by BLOCKS FROMSIZE-byte blocks, rounding away from zero. @@ -35,11 +39,13 @@ static uint64_t adjust_blocks(uint64_t blocks, uint64_t fromsize, uint64_t tosiz return (blocks + 1) / (tosize / fromsize); } -/* this does all of the system specific guff to get the free disk space. - It is derived from code in the GNU fileutils package, but has been - considerably mangled for use here - - results are returned in *dfree and *dsize, in 512 byte units +/** + * Retrieve amount of free disk space. + * this does all of the system specific guff to get the free disk space. + * It is derived from code in the GNU fileutils package, but has been + * considerably mangled for use here + * + * results are returned in *dfree and *dsize, in 512 byte units */ int sys_fsusage(const char *path, uint64_t *dfree, uint64_t *dsize) { diff --git a/source4/lib/util/genrand.c b/source4/lib/util/genrand.c index 1149314d0b..a264ac4e31 100644 --- a/source4/lib/util/genrand.c +++ b/source4/lib/util/genrand.c @@ -25,15 +25,20 @@ #include "system/filesys.h" #include "lib/crypto/crypto.h" +/** + * @file + * @brief Random number generation + */ + static unsigned char hash[258]; static uint32_t counter; static BOOL done_reseed = False; static void (*reseed_callback)(int *newseed); -/**************************************************************** +/** Copy any user given reseed data. -*****************************************************************/ +**/ void set_rand_reseed_callback(void (*fn)(int *)) { @@ -196,9 +201,9 @@ static int do_reseed(BOOL use_fd, int fd) return -1; } -/* +/** Interface to the (hopefully) good crypto random number generator. -*/ +**/ void generate_random_buffer(uint8_t *out, int len) { static int urand_fd = -1; @@ -242,9 +247,9 @@ void generate_random_buffer(uint8_t *out, int len) } } -/* +/** generate a single random uint32_t -*/ +**/ uint32_t generate_random(void) { uint8_t v[4]; @@ -253,9 +258,9 @@ uint32_t generate_random(void) } -/* +/** very basic password quality checker -*/ +**/ BOOL check_password_quality(const char *s) { int has_digit=0, has_capital=0, has_lower=0; @@ -273,9 +278,9 @@ BOOL check_password_quality(const char *s) return has_digit && has_lower && has_capital; } -/******************************************************************* +/** Use the random number generator to generate a random string. -********************************************************************/ +**/ char *generate_random_str_list(TALLOC_CTX *mem_ctx, size_t len, const char *list) { diff --git a/source4/lib/util/idtree.c b/source4/lib/util/idtree.c index a67a80940a..1ccf6d5e81 100644 --- a/source4/lib/util/idtree.c +++ b/source4/lib/util/idtree.c @@ -29,6 +29,10 @@ see the section marked "public interface" below for documentation */ +/** + * @file + */ + #include "includes.h" #define IDR_BITS 5 diff --git a/source4/lib/util/module.c b/source4/lib/util/module.c index 672d8df7ce..ad8afe2b16 100644 --- a/source4/lib/util/module.c +++ b/source4/lib/util/module.c @@ -18,6 +18,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/** + * @file + * @brief Module initialization function handling + */ + #include "includes.h" #include "system/dir.h" diff --git a/source4/lib/util/ms_fnmatch.c b/source4/lib/util/ms_fnmatch.c index d44c8b87da..a4fca4fa0a 100644 --- a/source4/lib/util/ms_fnmatch.c +++ b/source4/lib/util/ms_fnmatch.c @@ -24,6 +24,10 @@ code now */ +/** + * @file + * @brief MS-style Filename matching + */ #include "includes.h" @@ -212,7 +216,7 @@ int ms_fnmatch(const char *pattern, const char *string, enum protocol_types prot } -/* a generic fnmatch function - uses for non-CIFS pattern matching */ +/** a generic fnmatch function - uses for non-CIFS pattern matching */ int gen_fnmatch(const char *pattern, const char *string) { return ms_fnmatch(pattern, string, PROTOCOL_NT1); diff --git a/source4/lib/util/mutex.c b/source4/lib/util/mutex.c index 480ba92cc0..79c281ff0c 100644 --- a/source4/lib/util/mutex.c +++ b/source4/lib/util/mutex.c @@ -20,6 +20,11 @@ */ #include "includes.h" #include "mutex.h" + +/** + * @file + * @brief Mutex utility functions + */ /* the registered mutex handlers */ static struct { @@ -30,7 +35,7 @@ static struct { /* read/write lock routines */ -/* +/** register a set of mutex/rwlock handlers. Should only be called once in the execution of smbd. */ diff --git a/source4/lib/util/pidfile.c b/source4/lib/util/pidfile.c index 9a7c197f70..7f56fa5641 100644 --- a/source4/lib/util/pidfile.c +++ b/source4/lib/util/pidfile.c @@ -27,8 +27,15 @@ #define O_NONBLOCK #endif -/* return the pid in a pidfile. return 0 if the process (or pidfile) - does not exist */ +/** + * @file + * @brief Pid file handling + */ + +/** + * return the pid in a pidfile. return 0 if the process (or pidfile) + * does not exist + */ pid_t pidfile_pid(const char *name) { int fd; @@ -73,7 +80,9 @@ pid_t pidfile_pid(const char *name) return 0; } -/* create a pid file in the pid directory. open it and leave it locked */ +/** + * create a pid file in the pid directory. open it and leave it locked + */ void pidfile_create(const char *name) { int fd; diff --git a/source4/lib/util/signal.c b/source4/lib/util/signal.c index 6c0bb4007a..a0cb90dbf6 100644 --- a/source4/lib/util/signal.c +++ b/source4/lib/util/signal.c @@ -22,6 +22,11 @@ #include "includes.h" #include "system/wait.h" +/** + * @file + * @brief Signal handling + */ + /**************************************************************************** Catch child exits and reap the child zombie status. ****************************************************************************/ @@ -61,9 +66,9 @@ static void sig_cld_leave_status(int signum) #endif } -/******************************************************************* +/** Block sigs. -********************************************************************/ +**/ void BlockSignals(BOOL block,int signum) { @@ -88,12 +93,12 @@ void BlockSignals(BOOL block,int signum) #endif } -/******************************************************************* +/** Catch a signal. This should implement the following semantics: 1) The handler remains installed after being called. 2) The signal should be blocked during handler execution. -********************************************************************/ +**/ void (*CatchSignal(int signum,void (*handler)(int )))(int) { @@ -121,18 +126,18 @@ void (*CatchSignal(int signum,void (*handler)(int )))(int) #endif } -/******************************************************************* +/** Ignore SIGCLD via whatever means is necessary for this OS. -********************************************************************/ +**/ void CatchChild(void) { CatchSignal(SIGCLD, sig_cld); } -/******************************************************************* +/** Catch SIGCLD but leave the child around so it's status can be reaped. -********************************************************************/ +**/ void CatchChildLeaveStatus(void) { diff --git a/source4/lib/util/substitute.c b/source4/lib/util/substitute.c index 34a2ad9f82..d461cedf4c 100644 --- a/source4/lib/util/substitute.c +++ b/source4/lib/util/substitute.c @@ -22,6 +22,11 @@ #include "includes.h" #include "smb_server/smb_server.h" +/** + * @file + * @brief Substitution handling + */ + /* oh bugger - I really didn't want to have a top-level context anywhere, but until we change all lp_*() calls to take a context argument this is needed */ @@ -66,7 +71,7 @@ void sub_set_remote_arch(const char *str) setup_string(&sub->remote_arch, str); } -/* +/** setup the string used by %U substitution */ void sub_set_user_name(const char *name) @@ -75,17 +80,17 @@ void sub_set_user_name(const char *name) setup_string(&sub->user_name, name); } -/**************************************************************************** -FOO -****************************************************************************/ +/** +FIXME +**/ void standard_sub_basic(char *str,size_t len) { } -/**************************************************************************** +/** Do some standard substitutions in a string. This function will return an allocated string that have to be freed. -****************************************************************************/ +**/ char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name, const char *str) { return talloc_strdup(mem_ctx, str); @@ -96,10 +101,10 @@ char *alloc_sub_basic(const char *smb_name, const char *str) return strdup(str); } -/**************************************************************************** +/** Do some specific substitutions in a string. This function will return an allocated string that have to be freed. -****************************************************************************/ +**/ char *talloc_sub_specified(TALLOC_CTX *mem_ctx, const char *input_string, @@ -138,9 +143,9 @@ char *alloc_sub_advanced(int snum, const char *user, return strdup(str); } -/**************************************************************************** +/** Do some standard substitutions in a string. -****************************************************************************/ +**/ void standard_sub_tcon(struct smbsrv_tcon *tcon, char *str, size_t len) { @@ -156,9 +161,9 @@ char *alloc_sub_tcon(struct smbsrv_tcon *tcon, char *str) return strdup(str); } -/**************************************************************************** - Like standard_sub but by snum. -****************************************************************************/ +/** + Like standard_sub but by snum. FIXME +**/ void standard_sub_snum(int snum, char *str, size_t len) { diff --git a/source4/lib/util/time.c b/source4/lib/util/time.c index 7721a2c456..a56175cda9 100644 --- a/source4/lib/util/time.c +++ b/source4/lib/util/time.c @@ -23,6 +23,11 @@ #include "includes.h" #include "system/time.h" +/** + * @file + * @brief time handling functions + */ + #ifndef TIME_T_MIN /* we use 0 here, because (time_t)-1 means error */ #define TIME_T_MIN 0 @@ -37,17 +42,17 @@ #define TIME_T_MAX MIN(INT32_MAX,_TYPE_MAXIMUM(time_t)) #endif -/******************************************************************* +/** External access to time_t_min and time_t_max. -********************************************************************/ +**/ time_t get_time_t_max(void) { return TIME_T_MAX; } -/******************************************************************* +/** a gettimeofday wrapper -********************************************************************/ +**/ void GetTimeOfDay(struct timeval *tval) { #ifdef HAVE_GETTIMEOFDAY_TZ @@ -60,10 +65,10 @@ void GetTimeOfDay(struct timeval *tval) #define TIME_FIXUP_CONSTANT 11644473600LL -/**************************************************************************** +/** interpret an 8 byte "filetime" structure to a time_t It's originally in "100ns units since jan 1st 1601" -****************************************************************************/ +**/ time_t nt_time_to_unix(NTTIME nt) { if (nt == 0) { @@ -84,10 +89,10 @@ time_t nt_time_to_unix(NTTIME nt) } -/**************************************************************************** +/** put a 8 byte filetime from a time_t This takes GMT as input -****************************************************************************/ +**/ void unix_to_nt_time(NTTIME *nt, time_t t) { uint64_t t2; @@ -109,9 +114,9 @@ void unix_to_nt_time(NTTIME *nt, time_t t) } -/**************************************************************************** +/** check if it's a null unix time -****************************************************************************/ +**/ BOOL null_time(time_t t) { return t == 0 || @@ -120,9 +125,9 @@ BOOL null_time(time_t t) } -/**************************************************************************** +/** check if it's a null NTTIME -****************************************************************************/ +**/ BOOL null_nttime(NTTIME t) { return t == 0 || t == (NTTIME)-1; @@ -176,20 +181,20 @@ static uint32_t make_dos_date(time_t unixdate, int zone_offset) return ret; } -/******************************************************************* +/** put a dos date into a buffer (time/date format) This takes GMT time and puts local time in the buffer -********************************************************************/ +**/ void push_dos_date(uint8_t *buf, int offset, time_t unixdate, int zone_offset) { uint32_t x = make_dos_date(unixdate, zone_offset); 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 -********************************************************************/ +**/ void push_dos_date2(uint8_t *buf,int offset,time_t unixdate, int zone_offset) { uint32_t x; @@ -198,11 +203,11 @@ void push_dos_date2(uint8_t *buf,int offset,time_t unixdate, int zone_offset) 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) -********************************************************************/ +**/ void push_dos_date3(uint8_t *buf,int offset,time_t unixdate, int zone_offset) { if (!null_time(unixdate)) { @@ -229,10 +234,10 @@ static void interpret_dos_date(uint32_t date,int *year,int *month,int *day,int * *year = ((p3>>1)&0xFF) + 80; } -/******************************************************************* +/** create a unix date (int GMT) from a dos date (which is actually in localtime) -********************************************************************/ +**/ time_t pull_dos_date(const uint8_t *date_ptr, int zone_offset) { uint32_t dos_date=0; @@ -254,9 +259,9 @@ time_t pull_dos_date(const uint8_t *date_ptr, int zone_offset) return ret; } -/******************************************************************* +/** like make_unix_date() but the words are reversed -********************************************************************/ +**/ time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset) { uint32_t x,x2; @@ -268,10 +273,10 @@ time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset) return pull_dos_date((void *)&x, zone_offset); } -/******************************************************************* +/** 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 pull_dos_date3(const uint8_t *date_ptr, int zone_offset) { time_t t = (time_t)IVAL(date_ptr,0); @@ -282,9 +287,9 @@ time_t pull_dos_date3(const uint8_t *date_ptr, int zone_offset) } -/*************************************************************************** +/** return a HTTP/1.0 time string - ***************************************************************************/ +**/ char *http_timestring(TALLOC_CTX *mem_ctx, time_t t) { char *buf; @@ -308,9 +313,9 @@ char *http_timestring(TALLOC_CTX *mem_ctx, time_t t) return buf; } -/**************************************************************************** +/** Return the date and time as a string -****************************************************************************/ +**/ char *timestring(TALLOC_CTX *mem_ctx, time_t t) { char *TimeBuf; @@ -338,7 +343,7 @@ char *timestring(TALLOC_CTX *mem_ctx, time_t t) return TimeBuf; } -/* +/** return a talloced string representing a NTTIME for human consumption */ const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt) @@ -352,7 +357,7 @@ const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt) } -/* +/** put a NTTIME into a packet */ void push_nttime(uint8_t *base, uint16_t offset, NTTIME t) @@ -360,7 +365,7 @@ void push_nttime(uint8_t *base, uint16_t offset, NTTIME t) SBVAL(base, offset, t); } -/* +/** pull a NTTIME from a packet */ NTTIME pull_nttime(uint8_t *base, uint16_t offset) @@ -369,7 +374,7 @@ NTTIME pull_nttime(uint8_t *base, uint16_t offset) return ret; } -/* +/** parse a nttime as a large integer in a string and return a NTTIME */ NTTIME nttime_from_string(const char *s) @@ -377,7 +382,7 @@ NTTIME nttime_from_string(const char *s) return strtoull(s, NULL, 0); } -/* +/** return (tv1 - tv2) in microseconds */ int64_t usec_time_diff(struct timeval *tv1, struct timeval *tv2) @@ -387,7 +392,7 @@ int64_t usec_time_diff(struct timeval *tv1, struct timeval *tv2) } -/* +/** return a zero timeval */ struct timeval timeval_zero(void) @@ -398,7 +403,7 @@ struct timeval timeval_zero(void) return tv; } -/* +/** return True if a timeval is zero */ BOOL timeval_is_zero(const struct timeval *tv) @@ -406,7 +411,7 @@ BOOL timeval_is_zero(const struct timeval *tv) return tv->tv_sec == 0 && tv->tv_usec == 0; } -/* +/** return a timeval for the current time */ struct timeval timeval_current(void) @@ -416,7 +421,7 @@ struct timeval timeval_current(void) return tv; } -/* +/** return a timeval struct with the given elements */ struct timeval timeval_set(uint32_t secs, uint32_t usecs) @@ -428,7 +433,7 @@ struct timeval timeval_set(uint32_t secs, uint32_t usecs) } -/* +/** return a timeval ofs microseconds after tv */ struct timeval timeval_add(const struct timeval *tv, @@ -443,7 +448,7 @@ struct timeval timeval_add(const struct timeval *tv, return tv2; } -/* +/** return the sum of two timeval structures */ struct timeval timeval_sum(const struct timeval *tv1, @@ -452,7 +457,7 @@ struct timeval timeval_sum(const struct timeval *tv1, return timeval_add(tv1, tv2->tv_sec, tv2->tv_usec); } -/* +/** return a timeval secs/usecs into the future */ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs) @@ -461,7 +466,7 @@ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs) return timeval_add(&tv, secs, usecs); } -/* +/** compare two timeval structures. Return -1 if tv1 < tv2 Return 0 if tv1 == tv2 @@ -476,7 +481,7 @@ int timeval_compare(const struct timeval *tv1, const struct timeval *tv2) return 0; } -/* +/** return True if a timer is in the past */ BOOL timeval_expired(const struct timeval *tv) @@ -487,7 +492,7 @@ BOOL timeval_expired(const struct timeval *tv) return (tv2.tv_usec >= tv->tv_usec); } -/* +/** return the number of seconds elapsed between two times */ double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2) @@ -496,7 +501,7 @@ double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2) (tv2->tv_usec - tv1->tv_usec)*1.0e-6; } -/* +/** return the number of seconds elapsed since a given time */ double timeval_elapsed(const struct timeval *tv) @@ -505,7 +510,7 @@ double timeval_elapsed(const struct timeval *tv) return timeval_elapsed2(tv, &tv2); } -/* +/** return the lesser of two timevals */ struct timeval timeval_min(const struct timeval *tv1, @@ -517,7 +522,7 @@ struct timeval timeval_min(const struct timeval *tv1, return *tv2; } -/* +/** return the greater of two timevals */ struct timeval timeval_max(const struct timeval *tv1, @@ -529,7 +534,7 @@ struct timeval timeval_max(const struct timeval *tv1, return *tv2; } -/* +/** return the difference between two timevals as a timeval if tv1 comes after tv2, then return a zero timeval (this is *tv2 - *tv1) @@ -552,7 +557,7 @@ struct timeval timeval_until(const struct timeval *tv1, } -/* +/** convert a timeval to a NTTIME */ NTTIME timeval_to_nttime(const struct timeval *tv) @@ -579,9 +584,9 @@ static int tm_diff(struct tm *a, struct tm *b) return seconds; } -/******************************************************************* +/** return the UTC offset in seconds west of UTC, or 0 if it cannot be determined - ******************************************************************/ + */ int get_time_zone(time_t t) { struct tm *tm = gmtime(&t); diff --git a/source4/lib/util/unix_privs.c b/source4/lib/util/unix_privs.c index 3c0f319776..13b0aa203c 100644 --- a/source4/lib/util/unix_privs.c +++ b/source4/lib/util/unix_privs.c @@ -23,6 +23,11 @@ #include "includes.h" #include "system/filesys.h" +/** + * @file + * @brief Gaining/losing root privileges + */ + /* there are times when smbd needs to temporarily gain root privileges to do some operation. To do this you call root_privileges(), which diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index 17dde332e1..074dc000fb 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -28,10 +28,15 @@ #include "system/iconv.h" #include "system/filesys.h" -/*************************************************************************** +/** + * @file + * @brief Misc utility functions + */ + +/** 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; @@ -41,9 +46,9 @@ const char *tmpdir(void) } -/******************************************************************* +/** Check if a file exists - call vfs_file_exist for samba files. -********************************************************************/ +**/ BOOL file_exist(const char *fname) { struct stat st; @@ -55,9 +60,9 @@ BOOL file_exist(const char *fname) return ((S_ISREG(st.st_mode)) || (S_ISFIFO(st.st_mode))); } -/******************************************************************* +/** Check a files mod time. -********************************************************************/ +**/ time_t file_modtime(const char *fname) { @@ -69,9 +74,9 @@ time_t file_modtime(const char *fname) return(st.st_mtime); } -/******************************************************************* +/** Check if a directory exists. -********************************************************************/ +**/ BOOL directory_exist(const char *dname) { @@ -167,12 +172,12 @@ static void close_low_fds(BOOL stderr_too) #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) { @@ -198,9 +203,9 @@ int set_blocking(int fd, BOOL set) } -/******************************************************************* +/** Sleep for a specified number of milliseconds. -********************************************************************/ +**/ void msleep(uint_t t) { @@ -213,9 +218,9 @@ void msleep(uint_t t) select(0,NULL,NULL,NULL,&tval); } -/**************************************************************************** +/** Become a daemon, discarding the controlling terminal. -****************************************************************************/ +**/ void become_daemon(BOOL Fork) { @@ -244,11 +249,11 @@ void become_daemon(BOOL Fork) } -/**************************************************************************** +/** 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) { @@ -256,7 +261,7 @@ void safe_free(void *p) } -/* +/** see if a string matches either our primary or one of our secondary netbios aliases. do a case insensitive match */ @@ -280,9 +285,9 @@ BOOL is_myname(const char *name) } -/**************************************************************************** +/** Get my own name, return in malloc'ed storage. -****************************************************************************/ +**/ char* get_myname(void) { @@ -311,9 +316,9 @@ char* get_myname(void) return hostname; } -/**************************************************************************** +/** Return true if a string could be a pure IP address. -****************************************************************************/ +**/ BOOL is_ipaddress(const char *str) { @@ -330,9 +335,9 @@ BOOL is_ipaddress(const char *str) return pure_address; } -/**************************************************************************** +/** Interpret an internet address or name into an IP address in 4 byte form. -****************************************************************************/ +**/ uint32_t interpret_addr(const char *str) { struct hostent *hp; @@ -375,9 +380,9 @@ uint32_t interpret_addr(const char *str) return(res); } -/******************************************************************* +/** A convenient addition to interpret_addr(). -******************************************************************/ +**/ struct ipv4_addr interpret_addr2(const char *str) { struct ipv4_addr ret; @@ -386,18 +391,18 @@ struct ipv4_addr interpret_addr2(const char *str) return ret; } -/******************************************************************* +/** Check if an IP is the 0.0.0.0. -******************************************************************/ +**/ BOOL is_zero_ip(struct ipv4_addr ip) { return ip.addr == 0; } -/******************************************************************* +/** Are two IPs on the same subnet? -********************************************************************/ +**/ BOOL same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask) { @@ -411,9 +416,9 @@ BOOL same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask) } -/**************************************************************************** +/** Check if a process exists. Does this work on all unixes? -****************************************************************************/ +**/ BOOL process_exists(pid_t pid) { @@ -423,10 +428,10 @@ BOOL process_exists(pid_t pid) return(kill(pid,0) == 0 || errno != ESRCH); } -/**************************************************************************** +/** Simple routine to do POSIX file locking. Cruft in NFS and 64->32 bit mapping is dealt with in posix.c -****************************************************************************/ +**/ BOOL fcntl_lock(int fd, int op, off_t offset, off_t count, int type) { @@ -513,9 +518,9 @@ void dump_data(int level, const uint8_t *buf,int len) } } -/***************************************************************** +/** malloc that aborts with smb_panic on fail or zero size. - *****************************************************************/ +**/ void *smb_xmalloc(size_t size) { @@ -552,9 +557,9 @@ char *smb_xstrdup(const char *s) } -/***************************************************************** +/** Like strdup but for memory. -*****************************************************************/ +**/ void *memdup(const void *p, size_t size) { @@ -568,9 +573,9 @@ void *memdup(const void *p, size_t size) return p2; } -/***************************************************************** +/** A useful function for returning a path in the Samba lock directory. -*****************************************************************/ +**/ char *lock_path(TALLOC_CTX* mem_ctx, const char *name) { char *fname, *dname; @@ -596,9 +601,9 @@ char *lock_path(TALLOC_CTX* mem_ctx, const char *name) } -/***************************************************************** +/** A useful function for returning a path in the Samba piddir directory. -*****************************************************************/ +**/ static char *pid_path(TALLOC_CTX* mem_ctx, const char *name) { char *fname, *dname; @@ -654,7 +659,7 @@ char *private_path(TALLOC_CTX* mem_ctx, const char *name) return fname; } -/* +/** return a path in the smbd.tmp directory, where all temporary file for smbd go. If NULL is passed for name then return the directory path itself @@ -707,8 +712,10 @@ void dump_data_pw(const char *msg, const uint8_t * data, size_t len) } -/* see if a range of memory is all zero. A NULL pointer is considered - to be all zero */ +/** + * see if a range of memory is all zero. A NULL pointer is considered + * to be all zero + */ BOOL all_zero(const uint8_t *ptr, uint_t size) { int i; @@ -719,7 +726,7 @@ BOOL all_zero(const uint8_t *ptr, uint_t size) return True; } -/* +/** realloc an array, checking for integer overflow in the array size */ void *realloc_array(void *ptr, size_t el_size, unsigned count) diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index 246b03b4aa..5e55b81873 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -24,11 +24,16 @@ #include "system/shmem.h" #include "system/filesys.h" -/**************************************************************************** +/** + * @file + * @brief File-related utility functions + */ + +/** read a line from a file with possible \ continuation chars. Blanks at the start or end of a line are stripped. The string will be allocated if s2 is NULL -****************************************************************************/ +**/ char *fgets_slash(char *s2,int maxlen,XFILE *f) { char *s=s2; @@ -98,7 +103,9 @@ char *fgets_slash(char *s2,int maxlen,XFILE *f) return(s); } -/* Read one line (data until next newline or eof) and allocate it */ +/** + * Read one line (data until next newline or eof) and allocate it + */ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint) { char *data = NULL; @@ -146,9 +153,9 @@ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint) } -/**************************************************************************** +/** load a file into memory from a fd. -****************************************************************************/ +**/ char *fd_load(int fd, size_t *size, TALLOC_CTX *mem_ctx) { @@ -171,9 +178,9 @@ char *fd_load(int fd, size_t *size, TALLOC_CTX *mem_ctx) return p; } -/**************************************************************************** +/** load a file into memory -****************************************************************************/ +**/ char *file_load(const char *fname, size_t *size, TALLOC_CTX *mem_ctx) { int fd; @@ -192,9 +199,9 @@ char *file_load(const char *fname, size_t *size, TALLOC_CTX *mem_ctx) } -/******************************************************************* +/** mmap (if possible) or read a file -********************************************************************/ +**/ void *map_file(const char *fname, size_t size) { size_t s2 = 0; @@ -228,9 +235,9 @@ void *map_file(const char *fname, size_t size) } -/**************************************************************************** +/** parse a buffer into lines -****************************************************************************/ +**/ static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx) { int i; @@ -267,10 +274,10 @@ static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX * } -/**************************************************************************** +/** load a file into memory and return an array of pointers to lines in the file must be freed with talloc_free(). -****************************************************************************/ +**/ char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx) { char *p; @@ -287,11 +294,11 @@ char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx) return lines; } -/**************************************************************************** +/** load a fd into memory and return an array of pointers to lines in the file must be freed with talloc_free(). If convert is true calls unix_to_dos on the list. -****************************************************************************/ +**/ char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx) { char *p; @@ -309,10 +316,10 @@ char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx) } -/**************************************************************************** +/** take a list of lines and modify them to produce a list where \ continues a line -****************************************************************************/ +**/ void file_lines_slashcont(char **lines) { int i, j; @@ -332,7 +339,7 @@ void file_lines_slashcont(char **lines) } } -/* +/** save a lump of data into a file. Mostly used for debugging */ BOOL file_save(const char *fname, const void *packet, size_t length) @@ -349,7 +356,7 @@ BOOL file_save(const char *fname, const void *packet, size_t length) return True; } -/* +/** see if a file exists */ BOOL file_exists(const char *path) diff --git a/source4/lib/util/util_sock.c b/source4/lib/util/util_sock.c index 8a65a27d02..e3913f56a9 100644 --- a/source4/lib/util/util_sock.c +++ b/source4/lib/util/util_sock.c @@ -22,6 +22,11 @@ #include "includes.h" #include "system/network.h" +/** + * @file + * @brief Socket utility functions + */ + enum SOCK_OPT_TYPES {OPT_BOOL,OPT_INT,OPT_ON}; static const struct { @@ -67,9 +72,9 @@ static const struct { {NULL,0,0,0,0}}; -/**************************************************************************** +/** Set user socket options. -****************************************************************************/ +**/ void set_socket_options(int fd, const char *options) { const char **options_list = str_list_make(NULL, options, " \t,"); diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index b46787e3ea..11a95731de 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -983,10 +983,10 @@ size_t valgrind_strlen(const char *s) #endif -/* +/** format a string into length-prefixed dotted domain format, as used in NBT and in some ADS structures -*/ +**/ const char *str_format_nbt_domain(TALLOC_CTX *mem_ctx, const char *s) { char *ret; @@ -1036,9 +1036,9 @@ BOOL add_string_to_array(TALLOC_CTX *mem_ctx, -/* +/** varient of strcmp() that handles NULL ptrs -*/ +**/ int strcmp_safe(const char *s1, const char *s2) { if (s1 == s2) { @@ -1051,11 +1051,11 @@ int strcmp_safe(const char *s1, const char *s2) } -/******************************************************************* +/** return the number of bytes occupied by a buffer in ASCII format the result includes the null termination limited by 'n' bytes -********************************************************************/ +**/ size_t ascii_len_n(const char *src, size_t n) { size_t len; @@ -1069,9 +1069,9 @@ size_t ascii_len_n(const char *src, size_t n) } -/******************************************************************* +/** Return a string representing a CIFS attribute for a file. -********************************************************************/ +**/ char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib) { int i, len; @@ -1113,11 +1113,11 @@ char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib) return ret; } -/*************************************************************************** +/** Set a boolean variable from the text value stored in the passed string. Returns True in success, False if the passed string does not correctly represent a boolean. -***************************************************************************/ +**/ BOOL set_boolean(const char *boolean_string, BOOL *boolean) { @@ -1155,7 +1155,9 @@ BOOL conv_str_bool(const char * str, BOOL * val) return True; } -/* Convert a size specification like 16K into an integral number of bytes. */ +/** + * Convert a size specification like 16K into an integral number of bytes. + **/ BOOL conv_str_size(const char * str, uint64_t * val) { char * end = NULL; diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index ec6c58162f..e3d5126029 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -21,7 +21,12 @@ #include "includes.h" -/* +/** + * @file + * @brief String list manipulation + */ + +/** build a null terminated list of strings from a input string and a separator list. The separator list must contain characters less than or equal to 0x2f for this to work correctly on multi-byte strings @@ -71,9 +76,10 @@ const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char * return ret; } -/* build a null terminated list of strings from an argv-like input string - Entries are seperated by spaces and can be enclosed by quotes. - Does NOT support escaping +/** + * build a null terminated list of strings from an argv-like input string + * Entries are seperated by spaces and can be enclosed by quotes. + * Does NOT support escaping */ const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const char *sep) { @@ -131,7 +137,9 @@ const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const } -/* join a list back to one string */ +/** + * join a list back to one string + */ char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator) { char *ret = NULL; @@ -149,7 +157,7 @@ char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator) return ret; } -/* join a list back to one (shell-like) string; entries +/** join a list back to one (shell-like) string; entries * seperated by spaces, using quotes where necessary */ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep) { @@ -174,7 +182,7 @@ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep) return ret; } -/* +/** return the number of elements in a string list */ size_t str_list_length(const char **list) @@ -185,7 +193,7 @@ size_t str_list_length(const char **list) } -/* +/** copy a string list */ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) @@ -205,7 +213,7 @@ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) return ret; } -/* +/** Return true if all the elements of the list match exactly. */ BOOL str_list_equal(const char **list1, const char **list2) @@ -228,7 +236,7 @@ BOOL str_list_equal(const char **list1, const char **list2) } -/* +/** add an entry to a string list */ const char **str_list_add(const char **list, const char *s) @@ -247,7 +255,7 @@ const char **str_list_add(const char **list, const char *s) return ret; } -/* +/** remove an entry from a string list */ void str_list_remove(const char **list, const char *s) @@ -265,7 +273,7 @@ void str_list_remove(const char **list, const char *s) } -/* +/** return True if a string is in a list */ BOOL str_list_check(const char **list, const char *s) @@ -278,7 +286,7 @@ BOOL str_list_check(const char **list, const char *s) return False; } -/* +/** return True if a string is in a list, case insensitively */ BOOL str_list_check_ci(const char **list, const char *s) diff --git a/source4/lib/util/util_unistr.c b/source4/lib/util/util_unistr.c index b35822877c..81aa0d6752 100644 --- a/source4/lib/util/util_unistr.c +++ b/source4/lib/util/util_unistr.c @@ -22,6 +22,11 @@ #include "includes.h" #include "system/iconv.h" +/** + * @file + * @brief Unicode string manipulation + */ + /* these 2 tables define the unicode case handling. They are loaded at startup either via mmap() or read() from the lib directory */ static void *upcase_table; @@ -58,9 +63,9 @@ static void load_case_tables(void) } } -/******************************************************************* +/** Convert a codepoint_t to upper case. -********************************************************************/ +**/ codepoint_t toupper_w(codepoint_t val) { if (val < 128) { @@ -78,9 +83,9 @@ codepoint_t toupper_w(codepoint_t val) return SVAL(upcase_table, val*2); } -/******************************************************************* +/** Convert a codepoint_t to lower case. -********************************************************************/ +**/ codepoint_t tolower_w(codepoint_t val) { if (val < 128) { @@ -98,10 +103,10 @@ codepoint_t tolower_w(codepoint_t val) return SVAL(lowcase_table, val*2); } -/******************************************************************* +/** return the number of bytes occupied by a buffer in CH_UTF16 format the result includes the null termination -********************************************************************/ +**/ size_t utf16_len(const void *buf) { size_t len; @@ -111,11 +116,11 @@ size_t utf16_len(const void *buf) return len + 2; } -/******************************************************************* +/** return the number of bytes occupied by a buffer in CH_UTF16 format the result includes the null termination limited by 'n' bytes -********************************************************************/ +**/ size_t utf16_len_n(const void *src, size_t n) { size_t len; @@ -137,7 +142,7 @@ size_t ucs2_align(const void *base_ptr, const void *p, int flags) return PTR_DIFF(p, base_ptr) & 1; } -/* +/** compare two codepoints case insensitively */ int codepoint_cmpi(codepoint_t c1, codepoint_t c2) diff --git a/source4/lib/util/xfile.c b/source4/lib/util/xfile.c index 794e3f0f5e..43f0f85f52 100644 --- a/source4/lib/util/xfile.c +++ b/source4/lib/util/xfile.c @@ -18,6 +18,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/** + * @file + * @brief scalable FILE replacement + */ + /* stdio is very convenient, but on some systems the file descriptor in FILE* is 8 bits, so it fails when more than 255 files are open. -- cgit From 685b824aa88a03a8b70507d5d2454a744468075a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 1 Mar 2006 15:02:07 +0000 Subject: r13770: - do fsync() on the debug fd, as we do in samba3, I have an report that smbd memory usage grows to 1,5 GB or more without this... - make log_timestamp static metze (This used to be commit 551dd12baf9340ab070c8a8edca6b56770243a61) --- source4/lib/util/debug.c | 40 +++++++++++++++++++++------------------- source4/lib/util/debug.h | 3 --- 2 files changed, 21 insertions(+), 22 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index 3a71ed2df6..4cf7c21641 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -46,6 +46,24 @@ static struct { const char *prog_name; } state; +static void log_timestring(int level, const char *location, const char *func) +{ + char *t = NULL; + char *s = NULL; + + if (state.logtype != DEBUG_FILE) return; + + t = timestring(NULL, time(NULL)); + if (!t) return; + + asprintf(&s, "[%s, %d %s:%s()]\n", t, level, location, func); + talloc_free(t); + if (!s) return; + + write(state.fd, s, strlen(s)); + free(s); +} + /* the backend for debug messages. Note that the DEBUG() macro has already ensured that the log level has been met before this is called @@ -60,7 +78,7 @@ void do_debug_header(int level, const char *location, const char *func) the backend for debug messages. Note that the DEBUG() macro has already ensured that the log level has been met before this is called */ -void do_debug(const char *format, ...) +void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) { va_list ap; char *s = NULL; @@ -76,6 +94,7 @@ void do_debug(const char *format, ...) va_end(ap); write(state.fd, s, strlen(s)); + fsync(state.fd); free(s); } @@ -119,6 +138,7 @@ void reopen_logs(void) } if (old_fd > 2) { + fsync(old_fd); close(old_fd); } } @@ -173,24 +193,6 @@ void print_suspicious_usage(const char* from, const char* info) } } -void log_timestring(int level, const char *location, const char *func) -{ - char *t = NULL; - char *s = NULL; - - if (state.logtype != DEBUG_FILE) return; - - t = timestring(NULL, time(NULL)); - if (!t) return; - - asprintf(&s, "[%s, %d %s:%s()]\n", t, level, location, func); - talloc_free(t); - if (!s) return; - - write(state.fd, s, strlen(s)); - free(s); -} - uint32_t get_task_id(void) { if (debug_handlers.ops.get_task_id) { diff --git a/source4/lib/util/debug.h b/source4/lib/util/debug.h index 8ff937e7b9..4cd5759119 100644 --- a/source4/lib/util/debug.h +++ b/source4/lib/util/debug.h @@ -43,9 +43,6 @@ struct debug_ops { void (*log_task_id)(int fd); }; -void do_debug_header(int level, const char *location, const char *func); -void do_debug(const char *, ...) PRINTF_ATTRIBUTE(1,2); - extern int DEBUGLEVEL; #define DEBUGLVL(level) ((level) <= DEBUGLEVEL) -- cgit From af30a32b6924b0f2b701186e435defbca2ebd1aa Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 5 Mar 2006 17:15:19 +0000 Subject: r13840: Mark some functions as public. (This used to be commit 9a188eb1f48a50d92a67a4fc2b3899b90074059a) --- source4/lib/util/capability.c | 2 +- source4/lib/util/data_blob.c | 26 ++++++------- source4/lib/util/debug.c | 23 ++++++----- source4/lib/util/fault.c | 8 ++-- source4/lib/util/fsusage.c | 2 +- source4/lib/util/genrand.c | 14 +++---- source4/lib/util/idtree.c | 24 ++++++------ source4/lib/util/module.c | 13 ++++++- source4/lib/util/mutex.c | 2 +- source4/lib/util/pidfile.c | 2 +- source4/lib/util/time.c | 68 ++++++++++++++++---------------- source4/lib/util/util.c | 62 ++++++++++++++--------------- source4/lib/util/util_file.c | 21 +++++----- source4/lib/util/util_sock.c | 2 +- source4/lib/util/util_str.c | 86 ++++++++++++++++++++--------------------- source4/lib/util/util_strlist.c | 22 +++++------ 16 files changed, 192 insertions(+), 185 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/capability.c b/source4/lib/util/capability.c index ae08fab533..0062bb5cd6 100644 --- a/source4/lib/util/capability.c +++ b/source4/lib/util/capability.c @@ -107,7 +107,7 @@ static BOOL set_inherited_process_capability( uint32_t cap_flag, BOOL enable ) Gain the oplock capability from the kernel if possible. ****************************************************************************/ -void oplock_set_capability(BOOL this_process, BOOL inherit) +_PUBLIC_ void oplock_set_capability(BOOL this_process, BOOL inherit) { #if HAVE_KERNEL_OPLOCKS_IRIX set_process_capability(KERNEL_OPLOCK_CAPABILITY,this_process); diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index dfcfaa41ea..c1513a1d78 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -30,7 +30,7 @@ construct a data blob, must be freed with data_blob_free() you can pass NULL for p and get a blank data blob **/ -DATA_BLOB data_blob_named(const void *p, size_t length, const char *name) +_PUBLIC_ DATA_BLOB data_blob_named(const void *p, size_t length, const char *name) { DATA_BLOB ret; @@ -56,7 +56,7 @@ DATA_BLOB data_blob_named(const void *p, size_t length, const char *name) /** construct a data blob, using supplied TALLOC_CTX **/ -DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name) +_PUBLIC_ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name) { DATA_BLOB ret = data_blob_named(p, length, name); @@ -71,7 +71,7 @@ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t leng reference a data blob, to the supplied TALLOC_CTX. Returns a NULL DATA_BLOB on failure **/ -DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) +_PUBLIC_ DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) { DATA_BLOB ret = *blob; @@ -88,7 +88,7 @@ DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) use this sparingly as it initialises data - better to initialise yourself if you want specific data in the blob **/ -DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) +_PUBLIC_ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) { DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, length); data_blob_clear(&blob); @@ -98,7 +98,7 @@ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) /** free a data blob **/ -void data_blob_free(DATA_BLOB *d) +_PUBLIC_ void data_blob_free(DATA_BLOB *d) { if (d) { talloc_free(d->data); @@ -110,7 +110,7 @@ void data_blob_free(DATA_BLOB *d) /** clear a DATA_BLOB's contents **/ -void data_blob_clear(DATA_BLOB *d) +_PUBLIC_ void data_blob_clear(DATA_BLOB *d) { if (d->data) { memset(d->data, 0, d->length); @@ -120,7 +120,7 @@ void data_blob_clear(DATA_BLOB *d) /** free a data blob and clear its contents **/ -void data_blob_clear_free(DATA_BLOB *d) +_PUBLIC_ void data_blob_clear_free(DATA_BLOB *d) { data_blob_clear(d); data_blob_free(d); @@ -130,7 +130,7 @@ void data_blob_clear_free(DATA_BLOB *d) /** check if two data blobs are equal **/ -BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) +_PUBLIC_ BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) { if (d1->length != d2->length) { return False; @@ -150,7 +150,7 @@ BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) /** print the data_blob as hex string **/ -char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) +_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) { int i; char *hex_string; @@ -170,7 +170,7 @@ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) useful for constructing data blobs in test suites, while avoiding const warnings **/ -DATA_BLOB data_blob_string_const(const char *str) +_PUBLIC_ DATA_BLOB data_blob_string_const(const char *str) { DATA_BLOB blob; blob.data = discard_const(str); @@ -178,7 +178,7 @@ DATA_BLOB data_blob_string_const(const char *str) return blob; } -DATA_BLOB data_blob_const(const void *p, size_t length) +_PUBLIC_ DATA_BLOB data_blob_const(const void *p, size_t length) { DATA_BLOB blob; blob.data = discard_const(p); @@ -190,7 +190,7 @@ DATA_BLOB data_blob_const(const void *p, size_t length) /** realloc a data_blob **/ -NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) +_PUBLIC_ NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) { blob->data = talloc_realloc_size(mem_ctx, blob->data, length); NT_STATUS_HAVE_NO_MEMORY(blob->data); @@ -201,7 +201,7 @@ NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) /** append some data to a data blob **/ -NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, +_PUBLIC_ NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const void *p, size_t length) { blob->data = talloc_realloc_size(mem_ctx, blob->data, diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index 4cf7c21641..1c5bb25753 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -30,7 +30,7 @@ **/ /* this global variable determines what messages are printed */ -int DEBUGLEVEL; +_PUBLIC_ int DEBUGLEVEL; /* the registered mutex handlers */ @@ -68,7 +68,7 @@ static void log_timestring(int level, const char *location, const char *func) the backend for debug messages. Note that the DEBUG() macro has already ensured that the log level has been met before this is called */ -void do_debug_header(int level, const char *location, const char *func) +_PUBLIC_ void do_debug_header(int level, const char *location, const char *func) { log_timestring(level, location, func); log_task_id(); @@ -78,7 +78,7 @@ void do_debug_header(int level, const char *location, const char *func) the backend for debug messages. Note that the DEBUG() macro has already ensured that the log level has been met before this is called */ -void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) +_PUBLIC_ void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) { va_list ap; char *s = NULL; @@ -101,7 +101,7 @@ void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) /** reopen the log file (usually called because the log file name might have changed) */ -void reopen_logs(void) +_PUBLIC_ void reopen_logs(void) { const char *logfile = lp_logfile(); char *fname = NULL; @@ -147,7 +147,7 @@ void reopen_logs(void) control the name of the logfile and whether logging will be to stdout, stderr or a file */ -void setup_logging(const char *prog_name, enum debug_logtype new_logtype) +_PUBLIC_ void setup_logging(const char *prog_name, enum debug_logtype new_logtype) { if (state.logtype < new_logtype) { state.logtype = new_logtype; @@ -162,7 +162,7 @@ void setup_logging(const char *prog_name, enum debug_logtype new_logtype) return a string constant containing n tabs no more than 10 tabs are returned */ -const char *do_debug_tab(uint_t n) +_PUBLIC_ const char *do_debug_tab(uint_t n) { const char *tabs[] = {"", "\t", "\t\t", "\t\t\t", "\t\t\t\t", "\t\t\t\t\t", "\t\t\t\t\t\t", "\t\t\t\t\t\t\t", "\t\t\t\t\t\t\t\t", @@ -174,7 +174,7 @@ const char *do_debug_tab(uint_t n) /** log suspicious usage - print comments and backtrace */ -void log_suspicious_usage(const char *from, const char *info) +_PUBLIC_ void log_suspicious_usage(const char *from, const char *info) { if (debug_handlers.ops.log_suspicious_usage) { debug_handlers.ops.log_suspicious_usage(from, info); @@ -185,15 +185,14 @@ void log_suspicious_usage(const char *from, const char *info) /** print suspicious usage - print comments and backtrace */ - -void print_suspicious_usage(const char* from, const char* info) +_PUBLIC_ void print_suspicious_usage(const char* from, const char* info) { if (debug_handlers.ops.print_suspicious_usage) { debug_handlers.ops.print_suspicious_usage(from, info); } } -uint32_t get_task_id(void) +_PUBLIC_ uint32_t get_task_id(void) { if (debug_handlers.ops.get_task_id) { return debug_handlers.ops.get_task_id(); @@ -201,7 +200,7 @@ uint32_t get_task_id(void) return getpid(); } -void log_task_id(void) +_PUBLIC_ void log_task_id(void) { if (debug_handlers.ops.log_task_id) { debug_handlers.ops.log_task_id(state.fd); @@ -211,7 +210,7 @@ void log_task_id(void) /** register a set of debug handlers. */ -void register_debug_handlers(const char *name, struct debug_ops *ops) +_PUBLIC_ void register_debug_handlers(const char *name, struct debug_ops *ops) { debug_handlers.name = name; debug_handlers.ops = *ops; diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index abe3f141ce..ff44b8a292 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -46,7 +46,7 @@ static const char *progname; /** * Write backtrace to debug log */ -void call_backtrace(void) +_PUBLIC_ void call_backtrace(void) { #ifdef HAVE_BACKTRACE #define BACKTRACE_STACK_SIZE 64 @@ -112,7 +112,7 @@ void call_backtrace(void) /** Something really nasty happened - panic ! **/ -void smb_panic(const char *why) +_PUBLIC_ void smb_panic(const char *why) { const char *cmd = lp_panic_action(); int result; @@ -181,7 +181,7 @@ static void sig_fault(int sig) /** setup our fault handlers **/ -void fault_setup(const char *pname) +_PUBLIC_ void fault_setup(const char *pname) { if (progname == NULL) { progname = pname; @@ -204,7 +204,7 @@ void fault_setup(const char *pname) register a fault handler. Should only be called once in the execution of smbd. */ -BOOL register_fault_handler(const char *name, void (*fault_handler)(int sig)) +_PUBLIC_ BOOL register_fault_handler(const char *name, void (*fault_handler)(int sig)) { if (fault_handlers.name != NULL) { /* it's already registered! */ diff --git a/source4/lib/util/fsusage.c b/source4/lib/util/fsusage.c index dde9c61eb3..96b5ee4f59 100644 --- a/source4/lib/util/fsusage.c +++ b/source4/lib/util/fsusage.c @@ -47,7 +47,7 @@ static uint64_t adjust_blocks(uint64_t blocks, uint64_t fromsize, uint64_t tosiz * * results are returned in *dfree and *dsize, in 512 byte units */ -int sys_fsusage(const char *path, uint64_t *dfree, uint64_t *dsize) +_PUBLIC_ int sys_fsusage(const char *path, uint64_t *dfree, uint64_t *dsize) { #ifdef STAT_STATFS3_OSF1 #define CONVERT_BLOCKS(B) adjust_blocks ((uint64_t)(B), (uint64_t)fsd.f_fsize, (uint64_t)512) diff --git a/source4/lib/util/genrand.c b/source4/lib/util/genrand.c index a264ac4e31..f2b038f161 100644 --- a/source4/lib/util/genrand.c +++ b/source4/lib/util/genrand.c @@ -40,13 +40,13 @@ static void (*reseed_callback)(int *newseed); Copy any user given reseed data. **/ -void set_rand_reseed_callback(void (*fn)(int *)) +_PUBLIC_ void set_rand_reseed_callback(void (*fn)(int *)) { reseed_callback = fn; set_need_random_reseed(); } -void set_need_random_reseed(void) +_PUBLIC_ void set_need_random_reseed(void) { done_reseed = False; } @@ -204,7 +204,7 @@ static int do_reseed(BOOL use_fd, int fd) /** Interface to the (hopefully) good crypto random number generator. **/ -void generate_random_buffer(uint8_t *out, int len) +_PUBLIC_ void generate_random_buffer(uint8_t *out, int len) { static int urand_fd = -1; unsigned char md4_buf[64]; @@ -250,7 +250,7 @@ void generate_random_buffer(uint8_t *out, int len) /** generate a single random uint32_t **/ -uint32_t generate_random(void) +_PUBLIC_ uint32_t generate_random(void) { uint8_t v[4]; generate_random_buffer(v, 4); @@ -261,7 +261,7 @@ uint32_t generate_random(void) /** very basic password quality checker **/ -BOOL check_password_quality(const char *s) +_PUBLIC_ BOOL check_password_quality(const char *s) { int has_digit=0, has_capital=0, has_lower=0; while (*s) { @@ -282,7 +282,7 @@ BOOL check_password_quality(const char *s) Use the random number generator to generate a random string. **/ -char *generate_random_str_list(TALLOC_CTX *mem_ctx, size_t len, const char *list) +_PUBLIC_ char *generate_random_str_list(TALLOC_CTX *mem_ctx, size_t len, const char *list) { size_t i; size_t list_len = strlen(list); @@ -299,7 +299,7 @@ char *generate_random_str_list(TALLOC_CTX *mem_ctx, size_t len, const char *list return retstr; } -char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len) +_PUBLIC_ char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len) { char *retstr; const char *c_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_-#.,"; diff --git a/source4/lib/util/idtree.c b/source4/lib/util/idtree.c index 1ccf6d5e81..d29c3b8fbd 100644 --- a/source4/lib/util/idtree.c +++ b/source4/lib/util/idtree.c @@ -310,21 +310,21 @@ static int _idr_remove(struct idr_context *idp, int id) this is the public interface **************************************************************************/ -/* +/** initialise a idr tree. The context return value must be passed to all subsequent idr calls. To destroy the idr tree use talloc_free() on this context */ -struct idr_context *idr_init(TALLOC_CTX *mem_ctx) +_PUBLIC_ struct idr_context *idr_init(TALLOC_CTX *mem_ctx) { return talloc_zero(mem_ctx, struct idr_context); } -/* +/** allocate the next available id, and assign 'ptr' into its slot. you can retrieve later this pointer using idr_find() */ -int idr_get_new(struct idr_context *idp, void *ptr, int limit) +_PUBLIC_ int idr_get_new(struct idr_context *idp, void *ptr, int limit) { int ret = idr_get_new_above_int(idp, ptr, 0); if (ret > limit) { @@ -334,11 +334,11 @@ int idr_get_new(struct idr_context *idp, void *ptr, int limit) return ret; } -/* +/** allocate a new id, giving the first available value greater than or equal to the given starting id */ -int idr_get_new_above(struct idr_context *idp, void *ptr, int starting_id, int limit) +_PUBLIC_ int idr_get_new_above(struct idr_context *idp, void *ptr, int starting_id, int limit) { int ret = idr_get_new_above_int(idp, ptr, starting_id); if (ret > limit) { @@ -348,10 +348,10 @@ int idr_get_new_above(struct idr_context *idp, void *ptr, int starting_id, int l return ret; } -/* +/** allocate a new id randomly in the given range */ -int idr_get_new_random(struct idr_context *idp, void *ptr, int limit) +_PUBLIC_ int idr_get_new_random(struct idr_context *idp, void *ptr, int limit) { int id; @@ -366,18 +366,18 @@ int idr_get_new_random(struct idr_context *idp, void *ptr, int limit) return id; } -/* +/** find a pointer value previously set with idr_get_new given an id */ -void *idr_find(struct idr_context *idp, int id) +_PUBLIC_ void *idr_find(struct idr_context *idp, int id) { return _idr_find(idp, id); } -/* +/** remove an id from the idr tree */ -int idr_remove(struct idr_context *idp, int id) +_PUBLIC_ int idr_remove(struct idr_context *idp, int id) { int ret; ret = _idr_remove((struct idr_context *)idp, id); diff --git a/source4/lib/util/module.c b/source4/lib/util/module.c index ad8afe2b16..ef72551570 100644 --- a/source4/lib/util/module.c +++ b/source4/lib/util/module.c @@ -56,7 +56,11 @@ static void *load_module(TALLOC_CTX *mem_ctx, const char *dir, const char *name) return init_fn; } -init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path) +/** + * Obtain list of init functions from the modules in the specified + * directory + */ +_PUBLIC_ init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path) { DIR *dir; struct dirent *entry; @@ -88,7 +92,12 @@ init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path) return ret; } -BOOL run_init_functions(NTSTATUS (**fns) (void)) +/** + * Run the specified init functions. + * + * @return True if all functions ran successfully, False otherwise + */ +_PUBLIC_ BOOL run_init_functions(NTSTATUS (**fns) (void)) { int i; BOOL ret; diff --git a/source4/lib/util/mutex.c b/source4/lib/util/mutex.c index 79c281ff0c..3b64f4929b 100644 --- a/source4/lib/util/mutex.c +++ b/source4/lib/util/mutex.c @@ -39,7 +39,7 @@ static struct { register a set of mutex/rwlock handlers. Should only be called once in the execution of smbd. */ -BOOL register_mutex_handlers(const char *name, struct mutex_ops *ops) +_PUBLIC_ BOOL register_mutex_handlers(const char *name, struct mutex_ops *ops) { if (mutex_handlers.name != NULL) { /* it's already registered! */ diff --git a/source4/lib/util/pidfile.c b/source4/lib/util/pidfile.c index 7f56fa5641..1a46e6e70c 100644 --- a/source4/lib/util/pidfile.c +++ b/source4/lib/util/pidfile.c @@ -36,7 +36,7 @@ * return the pid in a pidfile. return 0 if the process (or pidfile) * does not exist */ -pid_t pidfile_pid(const char *name) +_PUBLIC_ pid_t pidfile_pid(const char *name) { int fd; char pidstr[20]; diff --git a/source4/lib/util/time.c b/source4/lib/util/time.c index a56175cda9..4897d2fa95 100644 --- a/source4/lib/util/time.c +++ b/source4/lib/util/time.c @@ -45,7 +45,7 @@ /** External access to time_t_min and time_t_max. **/ -time_t get_time_t_max(void) +_PUBLIC_ time_t get_time_t_max(void) { return TIME_T_MAX; } @@ -53,7 +53,7 @@ time_t get_time_t_max(void) /** a gettimeofday wrapper **/ -void GetTimeOfDay(struct timeval *tval) +_PUBLIC_ void GetTimeOfDay(struct timeval *tval) { #ifdef HAVE_GETTIMEOFDAY_TZ gettimeofday(tval,NULL); @@ -69,7 +69,7 @@ void GetTimeOfDay(struct timeval *tval) interpret an 8 byte "filetime" structure to a time_t It's originally in "100ns units since jan 1st 1601" **/ -time_t nt_time_to_unix(NTTIME nt) +_PUBLIC_ time_t nt_time_to_unix(NTTIME nt) { if (nt == 0) { return 0; @@ -93,7 +93,7 @@ time_t nt_time_to_unix(NTTIME nt) put a 8 byte filetime from a time_t This takes GMT as input **/ -void unix_to_nt_time(NTTIME *nt, time_t t) +_PUBLIC_ void unix_to_nt_time(NTTIME *nt, time_t t) { uint64_t t2; @@ -117,7 +117,7 @@ void unix_to_nt_time(NTTIME *nt, time_t t) /** check if it's a null unix time **/ -BOOL null_time(time_t t) +_PUBLIC_ BOOL null_time(time_t t) { return t == 0 || t == (time_t)0xFFFFFFFF || @@ -128,7 +128,7 @@ BOOL null_time(time_t t) /** check if it's a null NTTIME **/ -BOOL null_nttime(NTTIME t) +_PUBLIC_ BOOL null_nttime(NTTIME t) { return t == 0 || t == (NTTIME)-1; } @@ -185,7 +185,7 @@ static uint32_t make_dos_date(time_t unixdate, int zone_offset) put a dos date into a buffer (time/date format) This takes GMT time and puts local time in the buffer **/ -void push_dos_date(uint8_t *buf, int offset, time_t unixdate, int zone_offset) +_PUBLIC_ void push_dos_date(uint8_t *buf, int offset, time_t unixdate, int zone_offset) { uint32_t x = make_dos_date(unixdate, zone_offset); SIVAL(buf,offset,x); @@ -195,7 +195,7 @@ void push_dos_date(uint8_t *buf, int offset, time_t unixdate, int zone_offset) put a dos date into a buffer (date/time format) This takes GMT time and puts local time in the buffer **/ -void push_dos_date2(uint8_t *buf,int offset,time_t unixdate, int zone_offset) +_PUBLIC_ void push_dos_date2(uint8_t *buf,int offset,time_t unixdate, int zone_offset) { uint32_t x; x = make_dos_date(unixdate, zone_offset); @@ -208,7 +208,7 @@ 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 push_dos_date3(uint8_t *buf,int offset,time_t unixdate, int zone_offset) +_PUBLIC_ void push_dos_date3(uint8_t *buf,int offset,time_t unixdate, int zone_offset) { if (!null_time(unixdate)) { unixdate -= zone_offset; @@ -238,7 +238,7 @@ static void interpret_dos_date(uint32_t date,int *year,int *month,int *day,int * create a unix date (int GMT) from a dos date (which is actually in localtime) **/ -time_t pull_dos_date(const uint8_t *date_ptr, int zone_offset) +_PUBLIC_ time_t pull_dos_date(const uint8_t *date_ptr, int zone_offset) { uint32_t dos_date=0; struct tm t; @@ -262,7 +262,7 @@ time_t pull_dos_date(const uint8_t *date_ptr, int zone_offset) /** like make_unix_date() but the words are reversed **/ -time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset) +_PUBLIC_ time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset) { uint32_t x,x2; @@ -277,7 +277,7 @@ time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset) 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 pull_dos_date3(const uint8_t *date_ptr, int zone_offset) +_PUBLIC_ time_t pull_dos_date3(const uint8_t *date_ptr, int zone_offset) { time_t t = (time_t)IVAL(date_ptr,0); if (!null_time(t)) { @@ -290,7 +290,7 @@ time_t pull_dos_date3(const uint8_t *date_ptr, int zone_offset) /** return a HTTP/1.0 time string **/ -char *http_timestring(TALLOC_CTX *mem_ctx, time_t t) +_PUBLIC_ char *http_timestring(TALLOC_CTX *mem_ctx, time_t t) { char *buf; char tempTime[60]; @@ -316,7 +316,7 @@ char *http_timestring(TALLOC_CTX *mem_ctx, time_t t) /** Return the date and time as a string **/ -char *timestring(TALLOC_CTX *mem_ctx, time_t t) +_PUBLIC_ char *timestring(TALLOC_CTX *mem_ctx, time_t t) { char *TimeBuf; char tempTime[80]; @@ -346,7 +346,7 @@ char *timestring(TALLOC_CTX *mem_ctx, time_t t) /** return a talloced string representing a NTTIME for human consumption */ -const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt) +_PUBLIC_ const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt) { time_t t; if (nt == 0) { @@ -360,7 +360,7 @@ const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt) /** put a NTTIME into a packet */ -void push_nttime(uint8_t *base, uint16_t offset, NTTIME t) +_PUBLIC_ void push_nttime(uint8_t *base, uint16_t offset, NTTIME t) { SBVAL(base, offset, t); } @@ -368,7 +368,7 @@ void push_nttime(uint8_t *base, uint16_t offset, NTTIME t) /** pull a NTTIME from a packet */ -NTTIME pull_nttime(uint8_t *base, uint16_t offset) +_PUBLIC_ NTTIME pull_nttime(uint8_t *base, uint16_t offset) { NTTIME ret = BVAL(base, offset); return ret; @@ -377,7 +377,7 @@ NTTIME pull_nttime(uint8_t *base, uint16_t offset) /** parse a nttime as a large integer in a string and return a NTTIME */ -NTTIME nttime_from_string(const char *s) +_PUBLIC_ NTTIME nttime_from_string(const char *s) { return strtoull(s, NULL, 0); } @@ -385,7 +385,7 @@ NTTIME nttime_from_string(const char *s) /** return (tv1 - tv2) in microseconds */ -int64_t usec_time_diff(struct timeval *tv1, struct timeval *tv2) +_PUBLIC_ int64_t usec_time_diff(struct timeval *tv1, struct timeval *tv2) { int64_t sec_diff = tv1->tv_sec - tv2->tv_sec; return (sec_diff * 1000000) + (int64_t)(tv1->tv_usec - tv2->tv_usec); @@ -395,7 +395,7 @@ int64_t usec_time_diff(struct timeval *tv1, struct timeval *tv2) /** return a zero timeval */ -struct timeval timeval_zero(void) +_PUBLIC_ struct timeval timeval_zero(void) { struct timeval tv; tv.tv_sec = 0; @@ -406,7 +406,7 @@ struct timeval timeval_zero(void) /** return True if a timeval is zero */ -BOOL timeval_is_zero(const struct timeval *tv) +_PUBLIC_ BOOL timeval_is_zero(const struct timeval *tv) { return tv->tv_sec == 0 && tv->tv_usec == 0; } @@ -414,7 +414,7 @@ BOOL timeval_is_zero(const struct timeval *tv) /** return a timeval for the current time */ -struct timeval timeval_current(void) +_PUBLIC_ struct timeval timeval_current(void) { struct timeval tv; GetTimeOfDay(&tv); @@ -424,7 +424,7 @@ struct timeval timeval_current(void) /** return a timeval struct with the given elements */ -struct timeval timeval_set(uint32_t secs, uint32_t usecs) +_PUBLIC_ struct timeval timeval_set(uint32_t secs, uint32_t usecs) { struct timeval tv; tv.tv_sec = secs; @@ -436,7 +436,7 @@ struct timeval timeval_set(uint32_t secs, uint32_t usecs) /** return a timeval ofs microseconds after tv */ -struct timeval timeval_add(const struct timeval *tv, +_PUBLIC_ struct timeval timeval_add(const struct timeval *tv, uint32_t secs, uint32_t usecs) { struct timeval tv2 = *tv; @@ -460,7 +460,7 @@ struct timeval timeval_sum(const struct timeval *tv1, /** return a timeval secs/usecs into the future */ -struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs) +_PUBLIC_ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs) { struct timeval tv = timeval_current(); return timeval_add(&tv, secs, usecs); @@ -472,7 +472,7 @@ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs) Return 0 if tv1 == tv2 Return 1 if tv1 > tv2 */ -int timeval_compare(const struct timeval *tv1, const struct timeval *tv2) +_PUBLIC_ int timeval_compare(const struct timeval *tv1, const struct timeval *tv2) { if (tv1->tv_sec > tv2->tv_sec) return 1; if (tv1->tv_sec < tv2->tv_sec) return -1; @@ -484,7 +484,7 @@ int timeval_compare(const struct timeval *tv1, const struct timeval *tv2) /** return True if a timer is in the past */ -BOOL timeval_expired(const struct timeval *tv) +_PUBLIC_ BOOL timeval_expired(const struct timeval *tv) { struct timeval tv2 = timeval_current(); if (tv2.tv_sec > tv->tv_sec) return True; @@ -495,7 +495,7 @@ BOOL timeval_expired(const struct timeval *tv) /** return the number of seconds elapsed between two times */ -double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2) +_PUBLIC_ double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2) { return (tv2->tv_sec - tv1->tv_sec) + (tv2->tv_usec - tv1->tv_usec)*1.0e-6; @@ -504,7 +504,7 @@ double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2) /** return the number of seconds elapsed since a given time */ -double timeval_elapsed(const struct timeval *tv) +_PUBLIC_ double timeval_elapsed(const struct timeval *tv) { struct timeval tv2 = timeval_current(); return timeval_elapsed2(tv, &tv2); @@ -513,7 +513,7 @@ double timeval_elapsed(const struct timeval *tv) /** return the lesser of two timevals */ -struct timeval timeval_min(const struct timeval *tv1, +_PUBLIC_ struct timeval timeval_min(const struct timeval *tv1, const struct timeval *tv2) { if (tv1->tv_sec < tv2->tv_sec) return *tv1; @@ -525,7 +525,7 @@ struct timeval timeval_min(const struct timeval *tv1, /** return the greater of two timevals */ -struct timeval timeval_max(const struct timeval *tv1, +_PUBLIC_ struct timeval timeval_max(const struct timeval *tv1, const struct timeval *tv2) { if (tv1->tv_sec > tv2->tv_sec) return *tv1; @@ -539,7 +539,7 @@ struct timeval timeval_max(const struct timeval *tv1, if tv1 comes after tv2, then return a zero timeval (this is *tv2 - *tv1) */ -struct timeval timeval_until(const struct timeval *tv1, +_PUBLIC_ struct timeval timeval_until(const struct timeval *tv1, const struct timeval *tv2) { struct timeval t; @@ -560,7 +560,7 @@ struct timeval timeval_until(const struct timeval *tv1, /** convert a timeval to a NTTIME */ -NTTIME timeval_to_nttime(const struct timeval *tv) +_PUBLIC_ NTTIME timeval_to_nttime(const struct timeval *tv) { return 10*(tv->tv_usec + ((TIME_FIXUP_CONSTANT + (uint64_t)tv->tv_sec) * 1000000)); @@ -587,7 +587,7 @@ static int tm_diff(struct tm *a, struct tm *b) /** return the UTC offset in seconds west of UTC, or 0 if it cannot be determined */ -int get_time_zone(time_t t) +_PUBLIC_ int get_time_zone(time_t t) { struct tm *tm = gmtime(&t); struct tm tm_utc; diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index 074dc000fb..81084878b5 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -37,7 +37,7 @@ Find a suitable temporary directory. The result should be copied immediately as it may be overwritten by a subsequent call. **/ -const char *tmpdir(void) +_PUBLIC_ const char *tmpdir(void) { char *p; if ((p = getenv("TMPDIR"))) @@ -49,7 +49,7 @@ const char *tmpdir(void) /** Check if a file exists - call vfs_file_exist for samba files. **/ -BOOL file_exist(const char *fname) +_PUBLIC_ BOOL file_exist(const char *fname) { struct stat st; @@ -64,7 +64,7 @@ BOOL file_exist(const char *fname) Check a files mod time. **/ -time_t file_modtime(const char *fname) +_PUBLIC_ time_t file_modtime(const char *fname) { struct stat st; @@ -78,7 +78,7 @@ time_t file_modtime(const char *fname) Check if a directory exists. **/ -BOOL directory_exist(const char *dname) +_PUBLIC_ BOOL directory_exist(const char *dname) { struct stat st; BOOL ret; @@ -93,7 +93,7 @@ BOOL directory_exist(const char *dname) return ret; } -BOOL directory_create_or_exist(const char *dname, uid_t uid, +_PUBLIC_ BOOL directory_create_or_exist(const char *dname, uid_t uid, mode_t dir_perms) { mode_t old_umask; @@ -179,7 +179,7 @@ static void close_low_fds(BOOL stderr_too) if BSD use FNDELAY **/ -int set_blocking(int fd, BOOL set) +_PUBLIC_ int set_blocking(int fd, BOOL set) { int val; #ifdef O_NONBLOCK @@ -207,7 +207,7 @@ int set_blocking(int fd, BOOL set) Sleep for a specified number of milliseconds. **/ -void msleep(uint_t t) +_PUBLIC_ void msleep(uint_t t) { struct timeval tval; @@ -222,7 +222,7 @@ void msleep(uint_t t) Become a daemon, discarding the controlling terminal. **/ -void become_daemon(BOOL Fork) +_PUBLIC_ void become_daemon(BOOL Fork) { if (Fork) { if (fork()) { @@ -255,7 +255,7 @@ void become_daemon(BOOL Fork) Exists only because we need to pass a function pointer somewhere --SSS **/ -void safe_free(void *p) +_PUBLIC_ void safe_free(void *p) { SAFE_FREE(p); } @@ -265,7 +265,7 @@ void safe_free(void *p) see if a string matches either our primary or one of our secondary netbios aliases. do a case insensitive match */ -BOOL is_myname(const char *name) +_PUBLIC_ BOOL is_myname(const char *name) { const char **aliases; int i; @@ -289,7 +289,7 @@ BOOL is_myname(const char *name) Get my own name, return in malloc'ed storage. **/ -char* get_myname(void) +_PUBLIC_ char* get_myname(void) { char *hostname; const int host_name_max = 255; @@ -320,7 +320,7 @@ char* get_myname(void) Return true if a string could be a pure IP address. **/ -BOOL is_ipaddress(const char *str) +_PUBLIC_ BOOL is_ipaddress(const char *str) { BOOL pure_address = True; int i; @@ -338,7 +338,7 @@ BOOL is_ipaddress(const char *str) /** Interpret an internet address or name into an IP address in 4 byte form. **/ -uint32_t interpret_addr(const char *str) +_PUBLIC_ uint32_t interpret_addr(const char *str) { struct hostent *hp; uint32_t res; @@ -383,7 +383,7 @@ uint32_t interpret_addr(const char *str) /** A convenient addition to interpret_addr(). **/ -struct ipv4_addr interpret_addr2(const char *str) +_PUBLIC_ struct ipv4_addr interpret_addr2(const char *str) { struct ipv4_addr ret; uint32_t a = interpret_addr(str); @@ -395,7 +395,7 @@ struct ipv4_addr interpret_addr2(const char *str) Check if an IP is the 0.0.0.0. **/ -BOOL is_zero_ip(struct ipv4_addr ip) +_PUBLIC_ BOOL is_zero_ip(struct ipv4_addr ip) { return ip.addr == 0; } @@ -404,7 +404,7 @@ BOOL is_zero_ip(struct ipv4_addr ip) Are two IPs on the same subnet? **/ -BOOL same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask) +_PUBLIC_ BOOL same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask) { uint32_t net1,net2,nmask; @@ -420,7 +420,7 @@ BOOL same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask) Check if a process exists. Does this work on all unixes? **/ -BOOL process_exists(pid_t pid) +_PUBLIC_ BOOL process_exists(pid_t pid) { /* Doing kill with a non-positive pid causes messages to be * sent to places we don't want. */ @@ -433,7 +433,7 @@ BOOL process_exists(pid_t pid) is dealt with in posix.c **/ -BOOL fcntl_lock(int fd, int op, off_t offset, off_t count, int type) +_PUBLIC_ BOOL fcntl_lock(int fd, int op, off_t offset, off_t count, int type) { struct flock lock; int ret; @@ -486,7 +486,7 @@ static void print_asc(int level, const uint8_t *buf,int len) DEBUGADD(level,("%c", isprint(buf[i])?buf[i]:'.')); } -void dump_data(int level, const uint8_t *buf,int len) +_PUBLIC_ void dump_data(int level, const uint8_t *buf,int len) { int i=0; if (len<=0) return; @@ -522,7 +522,7 @@ void dump_data(int level, const uint8_t *buf,int len) malloc that aborts with smb_panic on fail or zero size. **/ -void *smb_xmalloc(size_t size) +_PUBLIC_ void *smb_xmalloc(size_t size) { void *p; if (size == 0) @@ -536,7 +536,7 @@ void *smb_xmalloc(size_t size) Memdup with smb_panic on fail. **/ -void *smb_xmemdup(const void *p, size_t size) +_PUBLIC_ void *smb_xmemdup(const void *p, size_t size) { void *p2; p2 = smb_xmalloc(size); @@ -548,7 +548,7 @@ void *smb_xmemdup(const void *p, size_t size) strdup that aborts on malloc fail. **/ -char *smb_xstrdup(const char *s) +_PUBLIC_ char *smb_xstrdup(const char *s) { char *s1 = strdup(s); if (!s1) @@ -561,7 +561,7 @@ char *smb_xstrdup(const char *s) Like strdup but for memory. **/ -void *memdup(const void *p, size_t size) +_PUBLIC_ void *memdup(const void *p, size_t size) { void *p2; if (size == 0) @@ -576,7 +576,7 @@ void *memdup(const void *p, size_t size) /** A useful function for returning a path in the Samba lock directory. **/ -char *lock_path(TALLOC_CTX* mem_ctx, const char *name) +_PUBLIC_ char *lock_path(TALLOC_CTX* mem_ctx, const char *name) { char *fname, *dname; if (name == NULL) { @@ -631,7 +631,7 @@ static char *pid_path(TALLOC_CTX* mem_ctx, const char *name) * @retval Pointer to a talloc'ed string containing the full path. **/ -char *lib_path(TALLOC_CTX* mem_ctx, const char *name) +_PUBLIC_ char *lib_path(TALLOC_CTX* mem_ctx, const char *name) { char *fname; fname = talloc_asprintf(mem_ctx, "%s/%s", dyn_LIBDIR, name); @@ -646,7 +646,7 @@ char *lib_path(TALLOC_CTX* mem_ctx, const char *name) * * @retval Pointer to a talloc'ed string containing the full path. **/ -char *private_path(TALLOC_CTX* mem_ctx, const char *name) +_PUBLIC_ char *private_path(TALLOC_CTX* mem_ctx, const char *name) { char *fname; if (name == NULL) { @@ -664,7 +664,7 @@ char *private_path(TALLOC_CTX* mem_ctx, const char *name) for smbd go. If NULL is passed for name then return the directory path itself */ -char *smbd_tmp_path(TALLOC_CTX *mem_ctx, const char *name) +_PUBLIC_ char *smbd_tmp_path(TALLOC_CTX *mem_ctx, const char *name) { char *fname, *dname; @@ -688,7 +688,7 @@ static char *modules_path(TALLOC_CTX* mem_ctx, const char *name) return talloc_asprintf(mem_ctx, "%s/%s", dyn_MODULESDIR, name); } -init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem) +_PUBLIC_ init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem) { char *path = modules_path(mem_ctx, subsystem); init_module_fn *ret; @@ -700,7 +700,7 @@ init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem) return ret; } -void dump_data_pw(const char *msg, const uint8_t * data, size_t len) +_PUBLIC_ void dump_data_pw(const char *msg, const uint8_t * data, size_t len) { #ifdef DEBUG_PASSWORD DEBUG(11, ("%s", msg)); @@ -716,7 +716,7 @@ void dump_data_pw(const char *msg, const uint8_t * data, size_t len) * see if a range of memory is all zero. A NULL pointer is considered * to be all zero */ -BOOL all_zero(const uint8_t *ptr, uint_t size) +_PUBLIC_ BOOL all_zero(const uint8_t *ptr, uint_t size) { int i; if (!ptr) return True; @@ -729,7 +729,7 @@ BOOL all_zero(const uint8_t *ptr, uint_t size) /** realloc an array, checking for integer overflow in the array size */ -void *realloc_array(void *ptr, size_t el_size, unsigned count) +_PUBLIC_ void *realloc_array(void *ptr, size_t el_size, unsigned count) { #define MAX_MALLOC_SIZE 0x7fffffff if (count == 0 || diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index 5e55b81873..430472f25a 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -34,7 +34,7 @@ read a line from a file with possible \ continuation chars. Blanks at the start or end of a line are stripped. The string will be allocated if s2 is NULL **/ -char *fgets_slash(char *s2,int maxlen,XFILE *f) +_PUBLIC_ char *fgets_slash(char *s2,int maxlen,XFILE *f) { char *s=s2; int len = 0; @@ -106,7 +106,7 @@ char *fgets_slash(char *s2,int maxlen,XFILE *f) /** * Read one line (data until next newline or eof) and allocate it */ -char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint) +_PUBLIC_ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint) { char *data = NULL; ssize_t alloc_size = 0, offset = 0, ret; @@ -156,8 +156,7 @@ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint) /** load a file into memory from a fd. **/ - -char *fd_load(int fd, size_t *size, TALLOC_CTX *mem_ctx) +_PUBLIC_ char *fd_load(int fd, size_t *size, TALLOC_CTX *mem_ctx) { struct stat sbuf; char *p; @@ -181,7 +180,7 @@ char *fd_load(int fd, size_t *size, TALLOC_CTX *mem_ctx) /** load a file into memory **/ -char *file_load(const char *fname, size_t *size, TALLOC_CTX *mem_ctx) +_PUBLIC_ char *file_load(const char *fname, size_t *size, TALLOC_CTX *mem_ctx) { int fd; char *p; @@ -202,7 +201,7 @@ char *file_load(const char *fname, size_t *size, TALLOC_CTX *mem_ctx) /** mmap (if possible) or read a file **/ -void *map_file(const char *fname, size_t size) +_PUBLIC_ void *map_file(const char *fname, size_t size) { size_t s2 = 0; void *p = NULL; @@ -278,7 +277,7 @@ static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX * load a file into memory and return an array of pointers to lines in the file must be freed with talloc_free(). **/ -char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx) +_PUBLIC_ char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx) { char *p; char **lines; @@ -299,7 +298,7 @@ load a fd into memory and return an array of pointers to lines in the file must be freed with talloc_free(). If convert is true calls unix_to_dos on the list. **/ -char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx) +_PUBLIC_ char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx) { char *p; char **lines; @@ -320,7 +319,7 @@ char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx) take a list of lines and modify them to produce a list where \ continues a line **/ -void file_lines_slashcont(char **lines) +_PUBLIC_ void file_lines_slashcont(char **lines) { int i, j; @@ -342,7 +341,7 @@ void file_lines_slashcont(char **lines) /** save a lump of data into a file. Mostly used for debugging */ -BOOL file_save(const char *fname, const void *packet, size_t length) +_PUBLIC_ BOOL file_save(const char *fname, const void *packet, size_t length) { int fd; fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0644); @@ -359,7 +358,7 @@ BOOL file_save(const char *fname, const void *packet, size_t length) /** see if a file exists */ -BOOL file_exists(const char *path) +_PUBLIC_ BOOL file_exists(const char *path) { struct stat st; return (stat(path, &st) == 0); diff --git a/source4/lib/util/util_sock.c b/source4/lib/util/util_sock.c index e3913f56a9..0a4380faf4 100644 --- a/source4/lib/util/util_sock.c +++ b/source4/lib/util/util_sock.c @@ -75,7 +75,7 @@ static const struct { /** Set user socket options. **/ -void set_socket_options(int fd, const char *options) +_PUBLIC_ void set_socket_options(int fd, const char *options) { const char **options_list = str_list_make(NULL, options, " \t,"); int j; diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 11a95731de..ef6abd6e83 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -40,7 +40,7 @@ * Based on a routine by GJC@VILLAGE.COM. * Extensively modified by Andrew.Tridgell@anu.edu.au **/ -BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize) +_PUBLIC_ BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize) { const char *s; BOOL quoted; @@ -82,7 +82,7 @@ BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize) /** Case insensitive string compararison **/ -int strcasecmp_m(const char *s1, const char *s2) +_PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) { codepoint_t c1=0, c2=0; size_t size1, size2; @@ -117,7 +117,7 @@ int strcasecmp_m(const char *s1, const char *s2) * * @note The comparison is case-insensitive. **/ -BOOL strequal(const char *s1, const char *s2) +_PUBLIC_ BOOL strequal(const char *s1, const char *s2) { if (s1 == s2) return(True); @@ -130,7 +130,7 @@ BOOL strequal(const char *s1, const char *s2) /** Compare 2 strings (case sensitive). **/ -BOOL strcsequal(const char *s1,const char *s2) +_PUBLIC_ BOOL strcsequal(const char *s1,const char *s2) { if (s1 == s2) return(True); @@ -144,7 +144,7 @@ BOOL strcsequal(const char *s1,const char *s2) /** Do a case-insensitive, whitespace-ignoring string compare. **/ -int strwicmp(const char *psz1, const char *psz2) +_PUBLIC_ int strwicmp(const char *psz1, const char *psz2) { /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */ /* appropriate value. */ @@ -175,7 +175,7 @@ int strwicmp(const char *psz1, const char *psz2) String replace. NOTE: oldc and newc must be 7 bit characters **/ -void string_replace(char *s, char oldc, char newc) +_PUBLIC_ void string_replace(char *s, char oldc, char newc) { while (*s) { size_t size; @@ -190,7 +190,7 @@ void string_replace(char *s, char oldc, char newc) /** Trim the specified elements off the front and back of a string. **/ -BOOL trim_string(char *s,const char *front,const char *back) +_PUBLIC_ BOOL trim_string(char *s,const char *front,const char *back) { BOOL ret = False; size_t front_len; @@ -229,7 +229,7 @@ BOOL trim_string(char *s,const char *front,const char *back) /** Find the number of 'c' chars in a string **/ -size_t count_chars(const char *s, char c) +_PUBLIC_ size_t count_chars(const char *s, char c) { size_t count = 0; @@ -247,7 +247,7 @@ size_t count_chars(const char *s, char c) Safe string copy into a known length string. maxlength does not include the terminating zero. **/ -char *safe_strcpy(char *dest,const char *src, size_t maxlength) +_PUBLIC_ char *safe_strcpy(char *dest,const char *src, size_t maxlength) { size_t len; @@ -289,7 +289,7 @@ char *safe_strcpy(char *dest,const char *src, size_t maxlength) Safe string cat into a string. maxlength does not include the terminating zero. **/ -char *safe_strcat(char *dest, const char *src, size_t maxlength) +_PUBLIC_ char *safe_strcat(char *dest, const char *src, size_t maxlength) { size_t src_len, dest_len; @@ -331,7 +331,7 @@ char *safe_strcat(char *dest, const char *src, size_t maxlength) characters. Don't change it ! **/ -char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength) +_PUBLIC_ char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength) { size_t len, i; @@ -375,7 +375,7 @@ char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, si The variable n should always be one less than the available size. **/ -char *StrnCpy(char *dest,const char *src,size_t n) +_PUBLIC_ char *StrnCpy(char *dest,const char *src,size_t n) { char *d = dest; if (!dest) @@ -401,7 +401,7 @@ char *StrnCpy(char *dest,const char *src,size_t n) **/ -size_t strhex_to_str(char *p, size_t len, const char *strhex) +_PUBLIC_ size_t strhex_to_str(char *p, size_t len, const char *strhex) { size_t i; size_t num_chars = 0; @@ -436,7 +436,7 @@ size_t strhex_to_str(char *p, size_t len, const char *strhex) return num_chars; } -DATA_BLOB strhex_to_data_blob(const char *strhex) +_PUBLIC_ DATA_BLOB strhex_to_data_blob(const char *strhex) { DATA_BLOB ret_blob = data_blob(NULL, strlen(strhex)/2+1); @@ -451,7 +451,7 @@ DATA_BLOB strhex_to_data_blob(const char *strhex) /** * Routine to print a buffer as HEX digits, into an allocated string. */ -void hex_encode(const unsigned char *buff_in, size_t len, char **out_hex_buffer) +_PUBLIC_ void hex_encode(const unsigned char *buff_in, size_t len, char **out_hex_buffer) { int i; char *hex_buffer; @@ -466,7 +466,7 @@ void hex_encode(const unsigned char *buff_in, size_t len, char **out_hex_buffer) /** Check if a string is part of a list. **/ -BOOL in_list(const char *s, const char *list, BOOL casesensitive) +_PUBLIC_ BOOL in_list(const char *s, const char *list, BOOL casesensitive) { pstring tok; const char *p=list; @@ -504,7 +504,7 @@ static BOOL string_init(char **dest,const char *src) /** Free a string value. **/ -void string_free(char **s) +_PUBLIC_ void string_free(char **s) { if (s) SAFE_FREE(*s); } @@ -513,7 +513,7 @@ void string_free(char **s) Set a string value, deallocating any existing space, and allocing the space for the string **/ -BOOL string_set(char **dest, const char *src) +_PUBLIC_ BOOL string_set(char **dest, const char *src) { string_free(dest); return string_init(dest,src); @@ -531,7 +531,7 @@ BOOL string_set(char **dest, const char *src) use of len==0 which was for no length checks to be done. **/ -void string_sub(char *s,const char *pattern, const char *insert, size_t len) +_PUBLIC_ void string_sub(char *s,const char *pattern, const char *insert, size_t len) { char *p; ssize_t ls,lp,li, i; @@ -585,7 +585,7 @@ void string_sub(char *s,const char *pattern, const char *insert, size_t len) use of len==0 which was for no length checks to be done. **/ -void all_string_sub(char *s,const char *pattern,const char *insert, size_t len) +_PUBLIC_ void all_string_sub(char *s,const char *pattern,const char *insert, size_t len) { char *p; ssize_t ls,lp,li; @@ -623,7 +623,7 @@ void all_string_sub(char *s,const char *pattern,const char *insert, size_t len) /** Strchr and strrchr_m are a bit complex on general multi-byte strings. **/ -char *strchr_m(const char *s, char c) +_PUBLIC_ char *strchr_m(const char *s, char c) { /* characters below 0x3F are guaranteed to not appear in non-initial position in multi-byte charsets */ @@ -643,7 +643,7 @@ char *strchr_m(const char *s, char c) return NULL; } -char *strrchr_m(const char *s, char c) +_PUBLIC_ char *strrchr_m(const char *s, char c) { char *ret = NULL; @@ -668,7 +668,7 @@ char *strrchr_m(const char *s, char c) /* return True if any (multi-byte) character is lower case */ -BOOL strhaslower(const char *string) +_PUBLIC_ BOOL strhaslower(const char *string) { while (*string) { size_t c_size; @@ -691,7 +691,7 @@ BOOL strhaslower(const char *string) /* return True if any (multi-byte) character is upper case */ -BOOL strhasupper(const char *string) +_PUBLIC_ BOOL strhasupper(const char *string) { while (*string) { size_t c_size; @@ -714,7 +714,7 @@ BOOL strhasupper(const char *string) /** Convert a string to lower case, allocated with talloc **/ -char *strlower_talloc(TALLOC_CTX *ctx, const char *src) +_PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) { size_t size=0; char *dest; @@ -749,7 +749,7 @@ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) /** Convert a string to UPPER case, allocated with talloc **/ -char *strupper_talloc(TALLOC_CTX *ctx, const char *src) +_PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) { size_t size=0; char *dest; @@ -788,7 +788,7 @@ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) /** Convert a string to lower case. **/ -void strlower_m(char *s) +_PUBLIC_ void strlower_m(char *s) { char *d; @@ -824,7 +824,7 @@ void strlower_m(char *s) /** Convert a string to UPPER case. **/ -void strupper_m(char *s) +_PUBLIC_ void strupper_m(char *s) { char *d; @@ -862,7 +862,7 @@ void strupper_m(char *s) be the same as the number of bytes in a string for single byte strings, but will be different for multibyte. **/ -size_t strlen_m(const char *s) +_PUBLIC_ size_t strlen_m(const char *s) { size_t count = 0; @@ -897,7 +897,7 @@ size_t strlen_m(const char *s) Work out the number of multibyte chars in a string, including the NULL terminator. **/ -size_t strlen_m_term(const char *s) +_PUBLIC_ size_t strlen_m_term(const char *s) { if (!s) { return 0; @@ -910,7 +910,7 @@ size_t strlen_m_term(const char *s) Unescape a URL encoded string, in place. **/ -void rfc1738_unescape(char *buf) +_PUBLIC_ void rfc1738_unescape(char *buf) { char *p=buf; @@ -949,7 +949,7 @@ void rfc1738_unescape(char *buf) /** * Decode a base64 string into a DATA_BLOB - simple and slow algorithm **/ -DATA_BLOB base64_decode_data_blob(TALLOC_CTX *mem_ctx, const char *s) +_PUBLIC_ DATA_BLOB base64_decode_data_blob(TALLOC_CTX *mem_ctx, const char *s) { DATA_BLOB ret = data_blob_talloc(mem_ctx, s, strlen(s)+1); ret.length = ldb_base64_decode((char *)ret.data); @@ -959,7 +959,7 @@ DATA_BLOB base64_decode_data_blob(TALLOC_CTX *mem_ctx, const char *s) /** * Decode a base64 string in-place - wrapper for the above **/ -void base64_decode_inplace(char *s) +_PUBLIC_ void base64_decode_inplace(char *s) { ldb_base64_decode(s); } @@ -967,7 +967,7 @@ void base64_decode_inplace(char *s) /** * Encode a base64 string into a talloc()ed string caller to free. **/ -char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data) +_PUBLIC_ char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data) { return ldb_base64_encode(mem_ctx, (const char *)data.data, data.length); } @@ -987,7 +987,7 @@ size_t valgrind_strlen(const char *s) format a string into length-prefixed dotted domain format, as used in NBT and in some ADS structures **/ -const char *str_format_nbt_domain(TALLOC_CTX *mem_ctx, const char *s) +_PUBLIC_ const char *str_format_nbt_domain(TALLOC_CTX *mem_ctx, const char *s) { char *ret; int i; @@ -1016,7 +1016,7 @@ const char *str_format_nbt_domain(TALLOC_CTX *mem_ctx, const char *s) return ret; } -BOOL add_string_to_array(TALLOC_CTX *mem_ctx, +_PUBLIC_ BOOL add_string_to_array(TALLOC_CTX *mem_ctx, const char *str, const char ***strings, int *num) { char *dup_str = talloc_strdup(mem_ctx, str); @@ -1039,7 +1039,7 @@ BOOL add_string_to_array(TALLOC_CTX *mem_ctx, /** varient of strcmp() that handles NULL ptrs **/ -int strcmp_safe(const char *s1, const char *s2) +_PUBLIC_ int strcmp_safe(const char *s1, const char *s2) { if (s1 == s2) { return 0; @@ -1056,7 +1056,7 @@ return the number of bytes occupied by a buffer in ASCII format the result includes the null termination limited by 'n' bytes **/ -size_t ascii_len_n(const char *src, size_t n) +_PUBLIC_ size_t ascii_len_n(const char *src, size_t n) { size_t len; @@ -1072,7 +1072,7 @@ size_t ascii_len_n(const char *src, size_t n) /** Return a string representing a CIFS attribute for a file. **/ -char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib) +_PUBLIC_ char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib) { int i, len; const struct { @@ -1119,7 +1119,7 @@ char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib) represent a boolean. **/ -BOOL set_boolean(const char *boolean_string, BOOL *boolean) +_PUBLIC_ BOOL set_boolean(const char *boolean_string, BOOL *boolean) { if (strwicmp(boolean_string, "yes") == 0 || strwicmp(boolean_string, "true") == 0 || @@ -1137,7 +1137,7 @@ BOOL set_boolean(const char *boolean_string, BOOL *boolean) return False; } -BOOL conv_str_bool(const char * str, BOOL * val) +_PUBLIC_ BOOL conv_str_bool(const char * str, BOOL * val) { char * end = NULL; long lval; @@ -1158,7 +1158,7 @@ BOOL conv_str_bool(const char * str, BOOL * val) /** * Convert a size specification like 16K into an integral number of bytes. **/ -BOOL conv_str_size(const char * str, uint64_t * val) +_PUBLIC_ BOOL conv_str_size(const char * str, uint64_t * val) { char * end = NULL; unsigned long long lval; @@ -1192,7 +1192,7 @@ BOOL conv_str_size(const char * str, uint64_t * val) return True; } -BOOL conv_str_u64(const char * str, uint64_t * val) +_PUBLIC_ BOOL conv_str_u64(const char * str, uint64_t * val) { char * end = NULL; unsigned long long lval; diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index e3d5126029..48ddbde9e1 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -31,7 +31,7 @@ separator list. The separator list must contain characters less than or equal to 0x2f for this to work correctly on multi-byte strings */ -const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep) +_PUBLIC_ const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep) { int num_elements = 0; const char **ret = NULL; @@ -81,7 +81,7 @@ const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char * * Entries are seperated by spaces and can be enclosed by quotes. * Does NOT support escaping */ -const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const char *sep) +_PUBLIC_ const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const char *sep) { int num_elements = 0; const char **ret = NULL; @@ -140,7 +140,7 @@ const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const /** * join a list back to one string */ -char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator) +_PUBLIC_ char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator) { char *ret = NULL; int i; @@ -159,7 +159,7 @@ char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator) /** join a list back to one (shell-like) string; entries * seperated by spaces, using quotes where necessary */ -char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep) +_PUBLIC_ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep) { char *ret = NULL; int i; @@ -185,7 +185,7 @@ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep) /** return the number of elements in a string list */ -size_t str_list_length(const char **list) +_PUBLIC_ size_t str_list_length(const char **list) { size_t ret; for (ret=0;list && list[ret];ret++) /* noop */ ; @@ -196,7 +196,7 @@ size_t str_list_length(const char **list) /** copy a string list */ -const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) +_PUBLIC_ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) { int i; const char **ret = talloc_array(mem_ctx, const char *, str_list_length(list)+1); @@ -216,7 +216,7 @@ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) /** Return true if all the elements of the list match exactly. */ -BOOL str_list_equal(const char **list1, const char **list2) +_PUBLIC_ BOOL str_list_equal(const char **list1, const char **list2) { int i; @@ -239,7 +239,7 @@ BOOL str_list_equal(const char **list1, const char **list2) /** add an entry to a string list */ -const char **str_list_add(const char **list, const char *s) +_PUBLIC_ const char **str_list_add(const char **list, const char *s) { size_t len = str_list_length(list); const char **ret; @@ -258,7 +258,7 @@ const char **str_list_add(const char **list, const char *s) /** remove an entry from a string list */ -void str_list_remove(const char **list, const char *s) +_PUBLIC_ void str_list_remove(const char **list, const char *s) { int i; @@ -276,7 +276,7 @@ void str_list_remove(const char **list, const char *s) /** return True if a string is in a list */ -BOOL str_list_check(const char **list, const char *s) +_PUBLIC_ BOOL str_list_check(const char **list, const char *s) { int i; @@ -289,7 +289,7 @@ BOOL str_list_check(const char **list, const char *s) /** return True if a string is in a list, case insensitively */ -BOOL str_list_check_ci(const char **list, const char *s) +_PUBLIC_ BOOL str_list_check_ci(const char **list, const char *s) { int i; -- cgit From c71c86c52458eefae8a34774ec186c2837f473af Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 5 Mar 2006 17:44:16 +0000 Subject: r13842: Make some more functions public. (This used to be commit aac1b99b362993352d80692afa55c38fc851c016) --- source4/lib/util/substitute.c | 30 +++++++++++++++--------------- source4/lib/util/system.c | 6 +++--- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/substitute.c b/source4/lib/util/substitute.c index d461cedf4c..2e55a7befb 100644 --- a/source4/lib/util/substitute.c +++ b/source4/lib/util/substitute.c @@ -32,7 +32,7 @@ argument this is needed */ static struct substitute_context *sub; -void sub_set_context(struct substitute_context *subptr) +_PUBLIC_ void sub_set_context(struct substitute_context *subptr) { sub = subptr; } @@ -59,13 +59,13 @@ static void setup_string(char **dest, const char *str) (*dest) = s; } -void sub_set_remote_proto(const char *str) +_PUBLIC_ void sub_set_remote_proto(const char *str) { if (!sub) return; setup_string(&sub->remote_proto, str); } -void sub_set_remote_arch(const char *str) +_PUBLIC_ void sub_set_remote_arch(const char *str) { if (!sub) return; setup_string(&sub->remote_arch, str); @@ -74,7 +74,7 @@ void sub_set_remote_arch(const char *str) /** setup the string used by %U substitution */ -void sub_set_user_name(const char *name) +_PUBLIC_ void sub_set_user_name(const char *name) { if (!sub) return; setup_string(&sub->user_name, name); @@ -83,7 +83,7 @@ void sub_set_user_name(const char *name) /** FIXME **/ -void standard_sub_basic(char *str,size_t len) +_PUBLIC_ void standard_sub_basic(char *str,size_t len) { } @@ -91,12 +91,12 @@ void standard_sub_basic(char *str,size_t len) Do some standard substitutions in a string. This function will return an allocated string that have to be freed. **/ -char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name, const char *str) +_PUBLIC_ char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name, const char *str) { return talloc_strdup(mem_ctx, str); } -char *alloc_sub_basic(const char *smb_name, const char *str) +_PUBLIC_ char *alloc_sub_basic(const char *smb_name, const char *str) { return strdup(str); } @@ -106,7 +106,7 @@ char *alloc_sub_basic(const char *smb_name, const char *str) This function will return an allocated string that have to be freed. **/ -char *talloc_sub_specified(TALLOC_CTX *mem_ctx, +_PUBLIC_ char *talloc_sub_specified(TALLOC_CTX *mem_ctx, const char *input_string, const char *username, const char *domain, @@ -116,7 +116,7 @@ char *talloc_sub_specified(TALLOC_CTX *mem_ctx, return talloc_strdup(mem_ctx, input_string); } -char *alloc_sub_specified(const char *input_string, +_PUBLIC_ char *alloc_sub_specified(const char *input_string, const char *username, const char *domain, uid_t uid, @@ -125,7 +125,7 @@ char *alloc_sub_specified(const char *input_string, return strdup(input_string); } -char *talloc_sub_advanced(TALLOC_CTX *mem_ctx, +_PUBLIC_ char *talloc_sub_advanced(TALLOC_CTX *mem_ctx, int snum, const char *user, const char *connectpath, @@ -136,7 +136,7 @@ char *talloc_sub_advanced(TALLOC_CTX *mem_ctx, return talloc_strdup(mem_ctx, str); } -char *alloc_sub_advanced(int snum, const char *user, +_PUBLIC_ char *alloc_sub_advanced(int snum, const char *user, const char *connectpath, gid_t gid, const char *smb_name, char *str) { @@ -147,16 +147,16 @@ char *alloc_sub_advanced(int snum, const char *user, Do some standard substitutions in a string. **/ -void standard_sub_tcon(struct smbsrv_tcon *tcon, char *str, size_t len) +_PUBLIC_ void standard_sub_tcon(struct smbsrv_tcon *tcon, char *str, size_t len) { } -char *talloc_sub_tcon(TALLOC_CTX *mem_ctx, struct smbsrv_tcon *tcon, char *str) +_PUBLIC_ char *talloc_sub_tcon(TALLOC_CTX *mem_ctx, struct smbsrv_tcon *tcon, char *str) { return talloc_strdup(mem_ctx, str); } -char *alloc_sub_tcon(struct smbsrv_tcon *tcon, char *str) +_PUBLIC_ char *alloc_sub_tcon(struct smbsrv_tcon *tcon, char *str) { return strdup(str); } @@ -165,6 +165,6 @@ char *alloc_sub_tcon(struct smbsrv_tcon *tcon, char *str) Like standard_sub but by snum. FIXME **/ -void standard_sub_snum(int snum, char *str, size_t len) +_PUBLIC_ void standard_sub_snum(int snum, char *str, size_t len) { } diff --git a/source4/lib/util/system.c b/source4/lib/util/system.c index 655b4a1054..5f8db9ef63 100644 --- a/source4/lib/util/system.c +++ b/source4/lib/util/system.c @@ -44,7 +44,7 @@ in the root domain, which can cause dial-on-demand links to come up for no apparent reason. ****************************************************************************/ -struct hostent *sys_gethostbyname(const char *name) +_PUBLIC_ struct hostent *sys_gethostbyname(const char *name) { #ifdef REDUCE_ROOT_DNS_LOOKUPS char query[256], hostname[256]; @@ -80,14 +80,14 @@ struct hostent *sys_gethostbyname(const char *name) #endif /* REDUCE_ROOT_DNS_LOOKUPS */ } -const char *sys_inet_ntoa(struct ipv4_addr in) +_PUBLIC_ const char *sys_inet_ntoa(struct ipv4_addr in) { struct in_addr in2; in2.s_addr = in.addr; return inet_ntoa(in2); } -struct ipv4_addr sys_inet_makeaddr(int net, int host) +_PUBLIC_ struct ipv4_addr sys_inet_makeaddr(int net, int host) { struct in_addr in; struct ipv4_addr in2; -- cgit From 4d8fe47f7fcfa1b0f479faf72d7d3fe15f799be5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 5 Mar 2006 20:45:18 +0000 Subject: r13849: More improvements to the libutil docs. (This used to be commit eed16ac3b7f7062a34f09f602db0f828cac7f246) --- source4/lib/util/README | 296 ------------------------------------------ source4/lib/util/mainpage.dox | 11 ++ source4/lib/util/util.h | 63 ++++++++- 3 files changed, 68 insertions(+), 302 deletions(-) delete mode 100644 source4/lib/util/README create mode 100644 source4/lib/util/mainpage.dox (limited to 'source4/lib/util') diff --git a/source4/lib/util/README b/source4/lib/util/README deleted file mode 100644 index e52e04ed92..0000000000 --- a/source4/lib/util/README +++ /dev/null @@ -1,296 +0,0 @@ -This directory contains convenience functions that are used heavily -throughout Samba. None of these functions are SMB or Samba-specific. -It's a bit to Samba what GLib is to the GNOME folks. - -(This file should be migrated to doxygen sometime.. ) - -Also TODO: Remove dependency on loadparm - -XFILE wrapper functions -======================= -The XFILE implementation contains a clone of the standard UNIX stdio -functions - -Debug functions -=============== -DEBUG() - -Crash handlers -============== -void smb_panic(const char *why); - -Signal handling -======================== -void BlockSignals(BOOL block,int signum); -void (*CatchSignal(int signum,void (*handler)(int )))(int); -void CatchChild(void); -void CatchChildLeaveStatus(void); - -Wrappers -======== -struct hostent *sys_gethostbyname(const char *name); -const char *sys_inet_ntoa(struct ipv4_addr in); -struct ipv4_addr sys_inet_makeaddr(int net, int host); -void sys_select_signal(void); -int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval); -int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval); - -Time datastructures -=================== -time_t get_time_t_max(void); -void GetTimeOfDay(struct timeval *tval); -time_t nt_time_to_unix(NTTIME nt); -void unix_to_nt_time(NTTIME *nt, time_t t); -BOOL null_time(time_t t); -BOOL null_nttime(NTTIME t); -void push_dos_date(uint8_t *buf, int offset, time_t unixdate, int zone_offset); -void push_dos_date2(uint8_t *buf,int offset,time_t unixdate, int zone_offset); -void push_dos_date3(uint8_t *buf,int offset,time_t unixdate, int zone_offset); -time_t pull_dos_date(const uint8_t *date_ptr, int zone_offset); -time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset); -time_t pull_dos_date3(const uint8_t *date_ptr, int zone_offset); -char *http_timestring(TALLOC_CTX *mem_ctx, time_t t); -char *timestring(TALLOC_CTX *mem_ctx, time_t t); -const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt); -void push_nttime(uint8_t *base, uint16_t offset, NTTIME t); -NTTIME pull_nttime(uint8_t *base, uint16_t offset); -NTTIME nttime_from_string(const char *s); -int64_t usec_time_diff(struct timeval *tv1, struct timeval *tv2); -struct timeval timeval_zero(void); -BOOL timeval_is_zero(const struct timeval *tv); -struct timeval timeval_current(void); -struct timeval timeval_set(uint32_t secs, uint32_t usecs); -struct timeval timeval_add(const struct timeval *tv, - uint32_t secs, uint32_t usecs); -struct timeval timeval_sum(const struct timeval *tv1, - const struct timeval *tv2); -struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs); -int timeval_compare(const struct timeval *tv1, const struct timeval *tv2); -BOOL timeval_expired(const struct timeval *tv); -double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2); -double timeval_elapsed(const struct timeval *tv); -struct timeval timeval_min(const struct timeval *tv1, - const struct timeval *tv2); -struct timeval timeval_max(const struct timeval *tv1, - const struct timeval *tv2); -struct timeval timeval_until(const struct timeval *tv1, - const struct timeval *tv2); -NTTIME timeval_to_nttime(const struct timeval *tv); -int get_time_zone(time_t t); - -Random number generation -======================== -void set_rand_reseed_callback(void (*fn)(int *)); -void set_need_random_reseed(void); -void generate_random_buffer(uint8_t *out, int len); -uint32_t generate_random(void); -BOOL check_password_quality(const char *s); -char *generate_random_str_list(TALLOC_CTX *mem_ctx, size_t len, const char *list); -char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len); - -String manipulation -=================== -BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize); -int strcasecmp_m(const char *s1, const char *s2); -BOOL strequal(const char *s1, const char *s2); -BOOL strcsequal(const char *s1,const char *s2); -int strwicmp(const char *psz1, const char *psz2); -void string_replace(char *s, char oldc, char newc); -BOOL trim_string(char *s,const char *front,const char *back); -size_t count_chars(const char *s, char c); -char *safe_strcpy(char *dest,const char *src, size_t maxlength); -char *safe_strcat(char *dest, const char *src, size_t maxlength); -char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength); -char *StrnCpy(char *dest,const char *src,size_t n); -size_t strhex_to_str(char *p, size_t len, const char *strhex); -DATA_BLOB strhex_to_data_blob(const char *strhex) ; -void hex_encode(const unsigned char *buff_in, size_t len, char **out_hex_buffer); -BOOL in_list(const char *s, const char *list, BOOL casesensitive); -void string_free(char **s); -BOOL string_set(char **dest, const char *src); -void string_sub(char *s,const char *pattern, const char *insert, size_t len); -void all_string_sub(char *s,const char *pattern,const char *insert, size_t len); -char *strchr_m(const char *s, char c); -char *strrchr_m(const char *s, char c); -BOOL strhaslower(const char *string); -BOOL strhasupper(const char *string); -char *strlower_talloc(TALLOC_CTX *ctx, const char *src); -char *strupper_talloc(TALLOC_CTX *ctx, const char *src); -void strlower_m(char *s); -void strupper_m(char *s); -size_t strlen_m(const char *s); -size_t strlen_m_term(const char *s); -void rfc1738_unescape(char *buf); -DATA_BLOB base64_decode_data_blob(TALLOC_CTX *mem_ctx, const char *s); -void base64_decode_inplace(char *s); -char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data); -size_t valgrind_strlen(const char *s); -const char *str_format_nbt_domain(TALLOC_CTX *mem_ctx, const char *s); -BOOL add_string_to_array(TALLOC_CTX *mem_ctx, - const char *str, const char ***strings, int *num); -int strcmp_safe(const char *s1, const char *s2); -size_t ascii_len_n(const char *src, size_t n); -char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib); -BOOL set_boolean(const char *boolean_string, BOOL *boolean); -BOOL conv_str_bool(const char * str, BOOL * val); -BOOL conv_str_size(const char * str, uint64_t * val); -BOOL conv_str_u64(const char * str, uint64_t * val); - -String list manipulation -======================== -const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep); -const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const char *sep); -char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator); -char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep); -size_t str_list_length(const char **list); -const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list); -BOOL str_list_equal(const char **list1, const char **list2); -const char **str_list_add(const char **list, const char *s); -void str_list_remove(const char **list, const char *s); -BOOL str_list_check(const char **list, const char *s); -BOOL str_list_check_ci(const char **list, const char *s); - -Unicode string manipulation -=========================== -codepoint_t toupper_w(codepoint_t val); -codepoint_t tolower_w(codepoint_t val); -size_t utf16_len(const void *buf); -size_t utf16_len_n(const void *src, size_t n); -size_t ucs2_align(const void *base_ptr, const void *p, int flags); -int codepoint_cmpi(codepoint_t c1, codepoint_t c2); - -File manipulation -================= -char *fgets_slash(char *s2,int maxlen,XFILE *f); -char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint); -char *fd_load(int fd, size_t *size, TALLOC_CTX *mem_ctx); -char *file_load(const char *fname, size_t *size, TALLOC_CTX *mem_ctx); -void *map_file(const char *fname, size_t size); -char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx); -char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx); -void file_lines_slashcont(char **lines); -BOOL file_save(const char *fname, const void *packet, size_t length); -BOOL file_exists(const char *path); -int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0); -int fdprintf(int fd, const char *format, ...) _PRINTF_ATTRIBUTE(2,3); - -Data Blob -========= -DATA_BLOB data_blob_named(const void *p, size_t length, const char *name); -DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name); -DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob); -DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length); -void data_blob_free(DATA_BLOB *d); -void data_blob_clear(DATA_BLOB *d); -void data_blob_clear_free(DATA_BLOB *d); -BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2); -char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob); -DATA_BLOB data_blob_string_const(const char *str); -DATA_BLOB data_blob_const(const void *p, size_t length); -NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length); -NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, - const void *p, size_t length); - -Random Utility functions -======================== -const char *tmpdir(void); -BOOL file_exist(const char *fname); -time_t file_modtime(const char *fname); -BOOL directory_exist(const char *dname); -BOOL directory_create_or_exist(const char *dname, uid_t uid, - mode_t dir_perms); -int set_blocking(int fd, BOOL set); -void msleep(uint_t t); -void become_daemon(BOOL Fork); -void safe_free(void *p); -BOOL is_myname(const char *name); -char* get_myname(void); -BOOL is_ipaddress(const char *str); -uint32_t interpret_addr(const char *str); -struct ipv4_addr interpret_addr2(const char *str); -BOOL is_zero_ip(struct ipv4_addr ip); -BOOL same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask); -BOOL process_exists(pid_t pid); -BOOL fcntl_lock(int fd, int op, off_t offset, off_t count, int type); -void dump_data(int level, const uint8_t *buf,int len); -void *smb_xmalloc(size_t size); -void *smb_xmemdup(const void *p, size_t size); -char *smb_xstrdup(const char *s); -void *memdup(const void *p, size_t size); -char *lock_path(TALLOC_CTX* mem_ctx, const char *name); -char *lib_path(TALLOC_CTX* mem_ctx, const char *name); -char *private_path(TALLOC_CTX* mem_ctx, const char *name); -char *smbd_tmp_path(TALLOC_CTX *mem_ctx, const char *name); -init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem); -void dump_data_pw(const char *msg, const uint8_t * data, size_t len); -BOOL all_zero(const uint8_t *ptr, uint_t size); -void *realloc_array(void *ptr, size_t el_size, unsigned count); - -/* The following definitions come from lib/util/util_sock.c */ - -void set_socket_options(int fd, const char *options); - -Variable substitution -===================== -void sub_set_context(struct substitute_context *subptr); -void sub_set_remote_proto(const char *str); -void sub_set_remote_arch(const char *str); -void sub_set_user_name(const char *name); -void standard_sub_basic(char *str,size_t len); -char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name, const char *str); -char *alloc_sub_basic(const char *smb_name, const char *str); -char *talloc_sub_specified(TALLOC_CTX *mem_ctx, - const char *input_string, - const char *username, - const char *domain, - uid_t uid, - gid_t gid); -char *alloc_sub_specified(const char *input_string, - const char *username, - const char *domain, - uid_t uid, - gid_t gid); -char *talloc_sub_advanced(TALLOC_CTX *mem_ctx, - int snum, - const char *user, - const char *connectpath, - gid_t gid, - const char *smb_name, - char *str); -char *alloc_sub_advanced(int snum, const char *user, - const char *connectpath, gid_t gid, - const char *smb_name, char *str); -void standard_sub_tcon(struct smbsrv_tcon *tcon, char *str, size_t len); -char *talloc_sub_tcon(TALLOC_CTX *mem_ctx, struct smbsrv_tcon *tcon, char *str); -char *alloc_sub_tcon(struct smbsrv_tcon *tcon, char *str); -void standard_sub_snum(int snum, char *str, size_t len); - -/* The following definitions come from lib/util/fsusage.c */ - -int sys_fsusage(const char *path, uint64_t *dfree, uint64_t *dsize); - -Microsoft-style filename matching -================================= -int ms_fnmatch(const char *pattern, const char *string, enum protocol_types protocol); -int gen_fnmatch(const char *pattern, const char *string); - -Mutexes -======= -BOOL register_mutex_handlers(const char *name, struct mutex_ops *ops); - -Idtree -====== -very efficient functions to manage mapping a id (such as a fnum) to -a pointer. This is used for fnum and search id allocation. - -struct idr_context *idr_init(TALLOC_CTX *mem_ctx); -int idr_get_new(struct idr_context *idp, void *ptr, int limit); -int idr_get_new_above(struct idr_context *idp, void *ptr, int starting_id, int limit); -int idr_get_new_random(struct idr_context *idp, void *ptr, int limit); -void *idr_find(struct idr_context *idp, int id); -int idr_remove(struct idr_context *idp, int id); - -Module loading -============== -init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path); -BOOL run_init_functions(NTSTATUS (**fns) (void)); diff --git a/source4/lib/util/mainpage.dox b/source4/lib/util/mainpage.dox new file mode 100644 index 0000000000..464151e771 --- /dev/null +++ b/source4/lib/util/mainpage.dox @@ -0,0 +1,11 @@ +/** + +\mainpage util + +\section Introduction + +This library contains convenience functions that are used heavily +throughout Samba. None of these functions are SMB or Samba-specific. +It's a bit to Samba what GLib is to the GNOME folks. + +*/ diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 55d775e25c..272cc13f4e 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -24,6 +24,11 @@ #ifndef _SAMBA_UTIL_H_ #define _SAMBA_UTIL_H_ +/** + * @file + * @brief Helpful macros + */ + struct substitute_context; #include "util/xfile.h" @@ -32,34 +37,55 @@ struct substitute_context; #include "util/byteorder.h" #include "util/util_proto.h" -/* zero a structure */ +/** + * zero a structure + */ #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) -/* zero a structure given a pointer to the structure */ +/** + * zero a structure given a pointer to the structure + */ #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0) -/* zero a structure given a pointer to the structure - no zero check */ +/** + * zero a structure given a pointer to the structure - no zero check + */ #define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x))) -/* pointer difference macro */ +/** + * pointer difference macro + */ #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2))) -/* work out how many elements there are in a static array */ +/** + * work out how many elements there are in a static array + */ #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) -/* assert macros */ +/** + * assert macros + */ #define SMB_ASSERT(b) do { if (!(b)) { \ DEBUG(0,("PANIC: assert failed at %s(%d)\n", __FILE__, __LINE__)); \ smb_panic("assert failed"); }} while (0) +/** + * determine the lowest of two values + */ #ifndef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) #endif +/** + * determine the highest of two values + */ #ifndef MAX #define MAX(a,b) ((a)>(b)?(a):(b)) #endif +/** + * determine absolute value + */ #ifndef ABS #define ABS(a) ((a)>0?(a):(-(a))) #endif @@ -78,4 +104,29 @@ struct substitute_context; #define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count) #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count) +#if defined(VALGRIND) +#define strlen(x) valgrind_strlen(x) +#endif + +/** + this is a warning hack. The idea is to use this everywhere that we + get the "discarding const" warning from gcc. That doesn't actually + fix the problem of course, but it means that when we do get to + cleaning them up we can do it by searching the code for + discard_const. + + It also means that other error types aren't as swamped by the noise + of hundreds of const warnings, so we are more likely to notice when + we get new errors. + + Please only add more uses of this macro when you find it + _really_ hard to fix const warnings. Our aim is to eventually use + this function in only a very few places. + + Also, please call this via the discard_const_p() macro interface, as that + makes the return type safe. +*/ +#define discard_const(ptr) ((void *)((intptr_t)(ptr))) +#define discard_const_p(type, ptr) ((type *)discard_const(ptr)) + #endif /* _SAMBA_UTIL_H_ */ -- cgit From c287cc247d90c996894cab18e870c992e7f84f85 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 6 Mar 2006 00:24:51 +0000 Subject: r13851: More doc improvements. (This used to be commit 936d26ae64b93ef8f8b2fbc632b1c2fd60840405) --- source4/lib/util/capability.c | 4 ++-- source4/lib/util/data_blob.c | 4 ++++ source4/lib/util/debug.c | 12 ++++++++---- source4/lib/util/debug.h | 20 ++++++++++++++++++-- source4/lib/util/genrand.c | 10 ++++++++++ source4/lib/util/mutex.h | 5 +++++ source4/lib/util/unix_privs.c | 6 ++++++ source4/lib/util/util.c | 23 +++++++++++++++++++++++ source4/lib/util/util.h | 14 ++++++++++++++ source4/lib/util/util_str.c | 30 ++++++++++++++++++++++++++++-- source4/lib/util/xfile.c | 31 ++++++++++++++++--------------- 11 files changed, 134 insertions(+), 25 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/capability.c b/source4/lib/util/capability.c index 0062bb5cd6..09af293087 100644 --- a/source4/lib/util/capability.c +++ b/source4/lib/util/capability.c @@ -103,9 +103,9 @@ static BOOL set_inherited_process_capability( uint32_t cap_flag, BOOL enable ) } #endif -/**************************************************************************** +/** Gain the oplock capability from the kernel if possible. -****************************************************************************/ +**/ _PUBLIC_ void oplock_set_capability(BOOL this_process, BOOL inherit) { diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index c1513a1d78..ac6589aa50 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -178,6 +178,10 @@ _PUBLIC_ DATA_BLOB data_blob_string_const(const char *str) return blob; } +/** + * Create a new data blob from const data + */ + _PUBLIC_ DATA_BLOB data_blob_const(const void *p, size_t length) { DATA_BLOB blob; diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index 1c5bb25753..e4f13ea28e 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -29,10 +29,11 @@ * @brief Debug logging **/ -/* this global variable determines what messages are printed */ +/** + * this global variable determines what messages are printed + */ _PUBLIC_ int DEBUGLEVEL; - /* the registered mutex handlers */ static struct { const char *name; @@ -64,7 +65,7 @@ static void log_timestring(int level, const char *location, const char *func) free(s); } -/* +/** the backend for debug messages. Note that the DEBUG() macro has already ensured that the log level has been met before this is called */ @@ -74,9 +75,12 @@ _PUBLIC_ void do_debug_header(int level, const char *location, const char *func) log_task_id(); } -/* +/** the backend for debug messages. Note that the DEBUG() macro has already ensured that the log level has been met before this is called + + @note You should never have to call this function directly. Call the DEBUG() + macro instead. */ _PUBLIC_ void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) { diff --git a/source4/lib/util/debug.h b/source4/lib/util/debug.h index 4cd5759119..10d7d0697c 100644 --- a/source4/lib/util/debug.h +++ b/source4/lib/util/debug.h @@ -18,6 +18,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/** + * @file + * @brief Debugging macros + */ + /* If we have these macros, we can add additional info to the header. */ #ifdef HAVE_FUNCTION_MACRO @@ -54,10 +59,21 @@ extern int DEBUGLEVEL; do_debug body; \ } \ } while (0) +/** + * Write to the debug log. + */ #define DEBUG(level, body) _DEBUG(level, body, True) +/** + * Add data to an existing debug log entry. + */ #define DEBUGADD(level, body) _DEBUG(level, body, False) -#define DEBUGC(class, level, body) DEBUG(level, body) -#define DEBUGADDC(class, level, body) DEBUGADD(level, body) + +/** + * Obtain indentation string for the debug log. + * + * Level specified by n. + */ #define DEBUGTAB(n) do_debug_tab(n) +/** Possible destinations for the debug log */ enum debug_logtype {DEBUG_STDOUT = 0, DEBUG_FILE = 1, DEBUG_STDERR = 2}; diff --git a/source4/lib/util/genrand.c b/source4/lib/util/genrand.c index f2b038f161..5bdf1f7e08 100644 --- a/source4/lib/util/genrand.c +++ b/source4/lib/util/genrand.c @@ -46,6 +46,9 @@ _PUBLIC_ void set_rand_reseed_callback(void (*fn)(int *)) set_need_random_reseed(); } +/** + * Tell the random number generator it needs to reseed. + */ _PUBLIC_ void set_need_random_reseed(void) { done_reseed = False; @@ -299,6 +302,13 @@ _PUBLIC_ char *generate_random_str_list(TALLOC_CTX *mem_ctx, size_t len, const c return retstr; } +/** + * Generate a random text string consisting of the specified length. + * The returned string will be allocated. + * + * Characters used are: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_-#., + */ + _PUBLIC_ char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len) { char *retstr; diff --git a/source4/lib/util/mutex.h b/source4/lib/util/mutex.h index 018c134bcb..bdc7bc7e7a 100644 --- a/source4/lib/util/mutex.h +++ b/source4/lib/util/mutex.h @@ -21,6 +21,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/** + * @file + * @brief Mutex operations + */ + struct mutex_ops; /* To add a new read/write lock, add it to enum rwlock_id diff --git a/source4/lib/util/unix_privs.c b/source4/lib/util/unix_privs.c index 13b0aa203c..c94cf619a3 100644 --- a/source4/lib/util/unix_privs.c +++ b/source4/lib/util/unix_privs.c @@ -59,6 +59,12 @@ static int privileges_destructor(void *ptr) return 0; } +/** + * Obtain root privileges for the current process. + * + * The privileges can be dropped by talloc_free()-ing the + * token returned by this function + */ void *root_privileges(void) { struct saved_state *s; diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index 81084878b5..ec25a9cbc7 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -93,6 +93,12 @@ _PUBLIC_ BOOL directory_exist(const char *dname) return ret; } +/** + * Try to create the specified directory if it didn't exist. + * + * @retval True if the directory already existed and has the right permissions + * or was successfully created. + */ _PUBLIC_ BOOL directory_create_or_exist(const char *dname, uid_t uid, mode_t dir_perms) { @@ -486,6 +492,11 @@ static void print_asc(int level, const uint8_t *buf,int len) DEBUGADD(level,("%c", isprint(buf[i])?buf[i]:'.')); } +/** + * Write dump of binary data to the log file. + * + * The data is only written if the log level is at least level. + */ _PUBLIC_ void dump_data(int level, const uint8_t *buf,int len) { int i=0; @@ -688,6 +699,12 @@ static char *modules_path(TALLOC_CTX* mem_ctx, const char *name) return talloc_asprintf(mem_ctx, "%s/%s", dyn_MODULESDIR, name); } +/** + * Load the initialization functions from DSO files for a specific subsystem. + * + * Will return an array of function pointers to initialization functions + */ + _PUBLIC_ init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem) { char *path = modules_path(mem_ctx, subsystem); @@ -700,6 +717,12 @@ _PUBLIC_ init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *sub return ret; } +/** + * Write a password to the log file. + * + * @note Only actually does something if DEBUG_PASSWORD was defined during + * compile-time. + */ _PUBLIC_ void dump_data_pw(const char *msg, const uint8_t * data, size_t len) { #ifdef DEBUG_PASSWORD diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 272cc13f4e..1dfd942dd3 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -100,8 +100,20 @@ struct substitute_context; #define SAFE_FREE(x) do { if ((x) != NULL) {free(discard_const_p(void *, (x))); (x)=NULL;} } while(0) #endif +/** + * Type-safe version of malloc. Allocated one copy of the + * specified data type. + */ #define malloc_p(type) (type *)malloc(sizeof(type)) + +/** + * Allocate an array of elements of one data type. Does type-checking. + */ #define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count) + +/** + * Resize an array of elements of one data type. Does type-checking. + */ #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count) #if defined(VALGRIND) @@ -127,6 +139,8 @@ struct substitute_context; makes the return type safe. */ #define discard_const(ptr) ((void *)((intptr_t)(ptr))) + +/** Type-safe version of discard_const */ #define discard_const_p(type, ptr) ((type *)discard_const(ptr)) #endif /* _SAMBA_UTIL_H_ */ diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index ef6abd6e83..4bb3ea1b54 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -436,6 +436,9 @@ _PUBLIC_ size_t strhex_to_str(char *p, size_t len, const char *strhex) return num_chars; } +/** + * Parse a hex string and return a data blob. + */ _PUBLIC_ DATA_BLOB strhex_to_data_blob(const char *strhex) { DATA_BLOB ret_blob = data_blob(NULL, strlen(strhex)/2+1); @@ -643,6 +646,9 @@ _PUBLIC_ char *strchr_m(const char *s, char c) return NULL; } +/** + * Multibyte-character version of strrchr + */ _PUBLIC_ char *strrchr_m(const char *s, char c) { char *ret = NULL; @@ -665,7 +671,7 @@ _PUBLIC_ char *strrchr_m(const char *s, char c) return ret; } -/* +/** return True if any (multi-byte) character is lower case */ _PUBLIC_ BOOL strhaslower(const char *string) @@ -688,7 +694,7 @@ _PUBLIC_ BOOL strhaslower(const char *string) return False; } -/* +/** return True if any (multi-byte) character is upper case */ _PUBLIC_ BOOL strhasupper(const char *string) @@ -1016,6 +1022,12 @@ _PUBLIC_ const char *str_format_nbt_domain(TALLOC_CTX *mem_ctx, const char *s) return ret; } +/** + * Add a string to an array of strings. + * + * num should be a pointer to an integer that holds the current + * number of elements in strings. It will be updated by this function. + */ _PUBLIC_ BOOL add_string_to_array(TALLOC_CTX *mem_ctx, const char *str, const char ***strings, int *num) { @@ -1137,6 +1149,13 @@ _PUBLIC_ BOOL set_boolean(const char *boolean_string, BOOL *boolean) return False; } +/** + * Parse a string containing a boolean value. + * + * val will be set to the read value. + * + * @retval True if a boolean value was parsed, False otherwise. + */ _PUBLIC_ BOOL conv_str_bool(const char * str, BOOL * val) { char * end = NULL; @@ -1192,6 +1211,13 @@ _PUBLIC_ BOOL conv_str_size(const char * str, uint64_t * val) return True; } +/** + * Parse a uint64_t value from a string + * + * val will be set to the value read. + * + * @retval True if parsing was successful, False otherwise + */ _PUBLIC_ BOOL conv_str_u64(const char * str, uint64_t * val) { char * end = NULL; diff --git a/source4/lib/util/xfile.c b/source4/lib/util/xfile.c index 43f0f85f52..97bab2ef9a 100644 --- a/source4/lib/util/xfile.c +++ b/source4/lib/util/xfile.c @@ -51,7 +51,7 @@ XFILE *x_stderr = &_x_stderr; #define X_FLAG_ERROR 2 #define X_FLAG_EINVAL 3 -/* simulate setvbuf() */ +/** simulate setvbuf() */ int x_setvbuf(XFILE *f, char *buf, int mode, size_t size) { x_fflush(f); @@ -93,7 +93,7 @@ static int x_allocate_buffer(XFILE *f) } -/* this looks more like open() than fopen(), but that is quite deliberate. +/** this looks more like open() than fopen(), but that is quite deliberate. I want programmers to *think* about O_EXCL, O_CREAT etc not just get them magically added */ @@ -126,7 +126,7 @@ XFILE *x_fopen(const char *fname, int flags, mode_t mode) return ret; } -/* simulate fclose() */ +/** simulate fclose() */ int x_fclose(XFILE *f) { int ret; @@ -150,7 +150,7 @@ int x_fclose(XFILE *f) return ret; } -/* simulate fwrite() */ +/** simulate fwrite() */ size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f) { ssize_t ret; @@ -195,7 +195,7 @@ size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f) return total/size; } -/* thank goodness for asprintf() */ +/** thank goodness for asprintf() */ int x_vfprintf(XFILE *f, const char *format, va_list ap) { char *p; @@ -228,7 +228,7 @@ int x_fileno(XFILE *f) return f->fd; } -/* simulate fflush() */ +/** simulate fflush() */ int x_fflush(XFILE *f) { int ret; @@ -255,33 +255,33 @@ int x_fflush(XFILE *f) return 0; } -/* simulate setbuffer() */ +/** simulate setbuffer() */ void x_setbuffer(XFILE *f, char *buf, size_t size) { x_setvbuf(f, buf, buf?X_IOFBF:X_IONBF, size); } -/* simulate setbuf() */ +/** simulate setbuf() */ void x_setbuf(XFILE *f, char *buf) { x_setvbuf(f, buf, buf?X_IOFBF:X_IONBF, XBUFSIZE); } -/* simulate setlinebuf() */ +/** simulate setlinebuf() */ void x_setlinebuf(XFILE *f) { x_setvbuf(f, NULL, X_IOLBF, 0); } -/* simulate feof() */ +/** simulate feof() */ int x_feof(XFILE *f) { if (f->flags & X_FLAG_EOF) return 1; return 0; } -/* simulate ferror() */ +/** simulate ferror() */ int x_ferror(XFILE *f) { if (f->flags & X_FLAG_ERROR) return 1; @@ -303,7 +303,7 @@ static void x_fillbuf(XFILE *f) f->next = f->buf; } -/* simulate fgetc() */ +/** simulate fgetc() */ int x_fgetc(XFILE *f) { int ret; @@ -323,7 +323,7 @@ int x_fgetc(XFILE *f) return ret; } -/* simulate fread */ +/** simulate fread */ size_t x_fread(void *p, size_t size, size_t nmemb, XFILE *f) { size_t total = 0; @@ -336,7 +336,7 @@ size_t x_fread(void *p, size_t size, size_t nmemb, XFILE *f) return total/size; } -/* simulate fgets() */ +/** simulate fgets() */ char *x_fgets(char *s, int size, XFILE *stream) { char *s0 = s; @@ -355,7 +355,8 @@ char *x_fgets(char *s, int size, XFILE *stream) return s0; } -/* trivial seek, works only for SEEK_SET and SEEK_END if SEEK_CUR is +/** + * trivial seek, works only for SEEK_SET and SEEK_END if SEEK_CUR is * set then an error is returned */ off_t x_tseek(XFILE *f, off_t offset, int whence) { -- cgit From 1c49d8f794762d0f3828237961012761212cb37e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 6 Mar 2006 13:55:56 +0000 Subject: r13859: - remove useless fsync() calls - make sure we only close the old_fd when the new one was opened metze (This used to be commit 3a6568c3669286d41343293c29c8d00fa78c372f) --- source4/lib/util/debug.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index e4f13ea28e..65f8586eaa 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -98,7 +98,6 @@ _PUBLIC_ void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) va_end(ap); write(state.fd, s, strlen(s)); - fsync(state.fd); free(s); } @@ -130,6 +129,7 @@ _PUBLIC_ void reopen_logs(void) int newfd = open(fname, O_CREAT|O_APPEND|O_WRONLY, 0600); if (newfd == -1) { DEBUG(1, ("Failed to open new logfile: %s\n", fname)); + old_fd = -1; } else { state.fd = newfd; } @@ -142,7 +142,6 @@ _PUBLIC_ void reopen_logs(void) } if (old_fd > 2) { - fsync(old_fd); close(old_fd); } } -- cgit From ba564a901e519b0f2cf2b7651bd260f618506b5c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 6 Mar 2006 23:28:18 +0000 Subject: r13903: Don't generate prototypes for modules and binaries in include/proto.h by default. (This used to be commit c80a8f1102caf744b66c13bebde38fba74983dc4) --- source4/lib/util/config.mk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 81614ed647..0ab0b5f809 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -34,7 +34,9 @@ OBJ_FILES = xfile.o \ module.o REQUIRED_SUBSYSTEMS = \ CHARSET LIBREPLACE LIBCRYPTO EXT_LIB_DL LIBTALLOC \ - SOCKET_WRAPPER CONFIG + SOCKET_WRAPPER CONFIG \ +# for the base64 functions + LIBLDB [SUBSYSTEM::PIDFILE] OBJ_FILES = pidfile.o -- cgit From f8fdbc967c774a1d62f87a534e4990d83ecc6b67 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 7 Mar 2006 14:34:32 +0000 Subject: r13944: Yet another round of splitups. (This used to be commit f87debeb12cebd734b47314554ab671c9e06237e) --- source4/lib/util/config.mk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 0ab0b5f809..2b2c440e4b 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -3,7 +3,7 @@ MAJOR_VERSION = 0 MINOR_VERSION = 0 RELEASE_VERSION = 1 DESCRIPTION = Generic utility functions -PRIVATE_PROTO_HEADER = util_proto.h +PUBLIC_PROTO_HEADER = util_proto.h PUBLIC_HEADERS = util.h \ byteorder.h \ debug.h \ @@ -39,7 +39,9 @@ REQUIRED_SUBSYSTEMS = \ LIBLDB [SUBSYSTEM::PIDFILE] +PRIVATE_PROTO_HEADER = pidfile.h OBJ_FILES = pidfile.o [SUBSYSTEM::UNIX_PRIVS] +PRIVATE_PROTO_HEADER = unix_privs.h OBJ_FILES = unix_privs.o -- cgit From 967bff7d88f478b49bba9e04244fd9239c0cf3c8 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 7 Mar 2006 16:37:35 +0000 Subject: r13959: make more functions public metze (This used to be commit a5b95a7741085a9adb04b8b63066d1b3d0f024ae) --- source4/lib/util/dprintf.c | 8 ++++---- source4/lib/util/util_file.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 64227148fd..916db3af93 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -31,7 +31,7 @@ #include "includes.h" -int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) +_PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) { char *p, *p2; int ret, maxlen, clen; @@ -71,7 +71,7 @@ again: } -int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) +_PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) { int ret; va_list ap; @@ -85,7 +85,7 @@ int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) static FILE *outfile; -int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) +_PUBLIC_ int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) { int ret; va_list ap; @@ -101,7 +101,7 @@ int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) /* interactive programs need a way of tell d_*() to write to stderr instead of stdout */ -void display_set_stderr(void) +_PUBLIC_ void display_set_stderr(void) { outfile = stderr; } diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index 430472f25a..b35d267582 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -364,7 +364,7 @@ _PUBLIC_ BOOL file_exists(const char *path) return (stat(path, &st) == 0); } -int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) +_PUBLIC_ int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) { char *p; int len, ret; @@ -379,7 +379,7 @@ int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) return ret; } -int fdprintf(int fd, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) +_PUBLIC_ int fdprintf(int fd, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) { va_list ap; int ret; -- cgit From ceb6e9717bf8ea5c83a01e159a7006fd8651620c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 7 Mar 2006 16:41:04 +0000 Subject: r13960: Generate makefile rules for installing/removing shared modules. (This used to be commit 2c746980328431ab04852dc668899e3eb042da99) --- source4/lib/util/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 2b2c440e4b..24e36dc72e 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -36,7 +36,7 @@ REQUIRED_SUBSYSTEMS = \ CHARSET LIBREPLACE LIBCRYPTO EXT_LIB_DL LIBTALLOC \ SOCKET_WRAPPER CONFIG \ # for the base64 functions - LIBLDB + ldb [SUBSYSTEM::PIDFILE] PRIVATE_PROTO_HEADER = pidfile.h -- cgit From c29b88c03aecff22f2124cd20d43ed81f0ca73f6 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 7 Mar 2006 18:16:59 +0000 Subject: r13972: fix the build, jelmer can you please take a look at what's going wrong here metze (This used to be commit 737b149546ac0ee93a0d6c4f54ed40dd6dd259c3) --- source4/lib/util/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 24e36dc72e..cf2e038709 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -3,7 +3,7 @@ MAJOR_VERSION = 0 MINOR_VERSION = 0 RELEASE_VERSION = 1 DESCRIPTION = Generic utility functions -PUBLIC_PROTO_HEADER = util_proto.h +PRIVATE_PROTO_HEADER = util_proto.h PUBLIC_HEADERS = util.h \ byteorder.h \ debug.h \ -- cgit From 8bec5a464a88b9762d2dbef359aa7b118a65892f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 8 Mar 2006 12:31:57 +0000 Subject: r14038: reopen log files after a SIGHUP metze (This used to be commit 8e9a69171a03a1f886fcff911e8a923368645a54) --- source4/lib/util/debug.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index 65f8586eaa..2c40064b75 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -47,11 +47,31 @@ static struct { const char *prog_name; } state; +static BOOL reopen_logs_scheduled; +static BOOL check_reopen_logs(void) +{ + if (state.fd == 0 || reopen_logs_scheduled) { + reopen_logs_scheduled = False; + reopen_logs(); + } + + if (state.fd <= 0) return False; + + return True; +} + +_PUBLIC_ void debug_schedule_reopen_logs(void) +{ + reopen_logs_scheduled = True; +} + static void log_timestring(int level, const char *location, const char *func) { char *t = NULL; char *s = NULL; + if (!check_reopen_logs()) return; + if (state.logtype != DEBUG_FILE) return; t = timestring(NULL, time(NULL)); @@ -87,11 +107,7 @@ _PUBLIC_ void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) va_list ap; char *s = NULL; - if (state.fd == 0) { - reopen_logs(); - } - - if (state.fd <= 0) return; + if (!check_reopen_logs()) return; va_start(ap, format); vasprintf(&s, format, ap); @@ -179,9 +195,9 @@ _PUBLIC_ const char *do_debug_tab(uint_t n) */ _PUBLIC_ void log_suspicious_usage(const char *from, const char *info) { - if (debug_handlers.ops.log_suspicious_usage) { - debug_handlers.ops.log_suspicious_usage(from, info); - } + if (!debug_handlers.ops.log_suspicious_usage) return; + + debug_handlers.ops.log_suspicious_usage(from, info); } @@ -190,9 +206,9 @@ _PUBLIC_ void log_suspicious_usage(const char *from, const char *info) */ _PUBLIC_ void print_suspicious_usage(const char* from, const char* info) { - if (debug_handlers.ops.print_suspicious_usage) { - debug_handlers.ops.print_suspicious_usage(from, info); - } + if (!debug_handlers.ops.print_suspicious_usage) return; + + debug_handlers.ops.print_suspicious_usage(from, info); } _PUBLIC_ uint32_t get_task_id(void) @@ -205,9 +221,11 @@ _PUBLIC_ uint32_t get_task_id(void) _PUBLIC_ void log_task_id(void) { - if (debug_handlers.ops.log_task_id) { - debug_handlers.ops.log_task_id(state.fd); - } + if (!debug_handlers.ops.log_task_id) return; + + if (!check_reopen_logs()) return; + + debug_handlers.ops.log_task_id(state.fd); } /** -- cgit From 3ccea395aa3e00e4f9cb0eb2fdee2cb763cc47ac Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 9 Mar 2006 22:01:48 +0000 Subject: r14108: Make the Doxyfiles a bit shorter... (This used to be commit 1004e1521a379ba6afb47e0fd3872d43363bc606) --- source4/lib/util/Doxyfile | 1217 +-------------------------------------------- 1 file changed, 6 insertions(+), 1211 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/Doxyfile b/source4/lib/util/Doxyfile index 7205513eb1..02e36a7af9 100644 --- a/source4/lib/util/Doxyfile +++ b/source4/lib/util/Doxyfile @@ -1,1229 +1,24 @@ -# Doxyfile 1.4.4 - -# This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project -# -# All text after a hash (#) is considered a comment and will be ignored -# The format is: -# TAG = value [value, ...] -# For lists items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (" ") - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- - -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded -# by quotes) that should identify the project. - PROJECT_NAME = SAMBA_UTIL - -# The PROJECT_NUMBER tag can be used to enter a project or revision number. -# This could be handy for archiving the generated documentation or -# if some version control system is used. - -PROJECT_NUMBER = - -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) -# base path where the generated documentation will be put. -# If a relative path is entered, it will be relative to the location -# where doxygen was started. If left blank the current directory will be used. - OUTPUT_DIRECTORY = apidocs - -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create -# 4096 sub-directories (in 2 levels) under the output directory of each output -# format and will distribute the generated files over these directories. -# Enabling this option can be useful when feeding doxygen a huge amount of -# source files, where putting all generated files in the same directory would -# otherwise cause performance problems for the file system. - -CREATE_SUBDIRS = NO - -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# The default language is English, other supported languages are: -# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, -# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, -# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, -# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, -# Swedish, and Ukrainian. - -OUTPUT_LANGUAGE = English - -# This tag can be used to specify the encoding used in the generated output. -# The encoding is not always determined by the language that is chosen, -# but also whether or not the output is meant for Windows or non-Windows users. -# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES -# forces the Windows encoding (this is the default for the Windows binary), -# whereas setting the tag to NO uses a Unix-style encoding (the default for -# all platforms other than Windows). - -USE_WINDOWS_ENCODING = NO - -# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will -# include brief member descriptions after the members that are listed in -# the file and class documentation (similar to JavaDoc). -# Set to NO to disable this. - -BRIEF_MEMBER_DESC = YES - -# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend -# the brief description of a member or function before the detailed description. -# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the -# brief descriptions will be completely suppressed. - +BRIEF_MEMBER_DESC = YES REPEAT_BRIEF = YES - -# This tag implements a quasi-intelligent brief description abbreviator -# that is used to form the text in various listings. Each string -# in this list, if found as the leading text of the brief description, will be -# stripped from the text and the result after processing the whole list, is -# used as the annotated text. Otherwise, the brief description is used as-is. -# If left blank, the following values are used ("$name" is automatically -# replaced with the name of the entity): "The $name class" "The $name widget" -# "The $name file" "is" "provides" "specifies" "contains" -# "represents" "a" "an" "the" - -ABBREVIATE_BRIEF = - -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# Doxygen will generate a detailed section even if there is only a brief -# description. - -ALWAYS_DETAILED_SEC = NO - -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment -# operators of the base classes will not be shown. - -INLINE_INHERITED_MEMB = NO - -# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full -# path before files name in the file list and in the header files. If set -# to NO the shortest path that makes the file name unique will be used. - -FULL_PATH_NAMES = YES - -# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag -# can be used to strip a user-defined part of the path. Stripping is -# only done if one of the specified strings matches the left-hand part of -# the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the -# path to strip. - -STRIP_FROM_PATH = - -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of -# the path mentioned in the documentation of a class, which tells -# the reader which header file to include in order to use a class. -# If left blank only the name of the header file containing the class -# definition is used. Otherwise one should specify the include paths that -# are normally passed to the compiler using the -I flag. - -STRIP_FROM_INC_PATH = include - -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter -# (but less readable) file names. This can be useful is your file systems -# doesn't support long names like on DOS, Mac, or CD-ROM. - -SHORT_NAMES = NO - -# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen -# will interpret the first line (until the first dot) of a JavaDoc-style -# comment as the brief description. If set to NO, the JavaDoc -# comments will behave just like the Qt-style comments (thus requiring an -# explicit @brief command for a brief description. - -JAVADOC_AUTOBRIEF = YES - -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen -# treat a multi-line C++ special comment block (i.e. a block of //! or /// -# comments) as a brief description. This used to be the default behaviour. -# The new default is to treat a multi-line C++ comment block as a detailed -# description. Set this tag to YES if you prefer the old behaviour instead. - -MULTILINE_CPP_IS_BRIEF = NO - -# If the DETAILS_AT_TOP tag is set to YES then Doxygen -# will output the detailed description near the top, like JavaDoc. -# If set to NO, the detailed description appears after the member -# documentation. - -DETAILS_AT_TOP = YES - -# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented -# member inherits the documentation from any documented member that it -# re-implements. - -INHERIT_DOCS = YES - -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. - -DISTRIBUTE_GROUP_DOC = NO - -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce -# a new page for each member. If set to NO, the documentation of a member will -# be part of the file/class/namespace that contains it. - -SEPARATE_MEMBER_PAGES = NO - -# The TAB_SIZE tag can be used to set the number of spaces in a tab. -# Doxygen uses this value to replace tabs by spaces in code fragments. - -TAB_SIZE = 8 - -# This tag can be used to specify a number of aliases that acts -# as commands in the documentation. An alias has the form "name=value". -# For example adding "sideeffect=\par Side Effects:\n" will allow you to -# put the command \sideeffect (or @sideeffect) in the documentation, which -# will result in a user-defined paragraph with heading "Side Effects:". -# You can put \n's in the value part of an alias to insert newlines. - -ALIASES = - -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C -# sources only. Doxygen will then generate output that is more tailored for C. -# For instance, some of the names that are used will be different. The list -# of all members will be omitted, etc. - OPTIMIZE_OUTPUT_FOR_C = YES - -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources -# only. Doxygen will then generate output that is more tailored for Java. -# For instance, namespaces will be presented as packages, qualified scopes -# will look different, etc. - -OPTIMIZE_OUTPUT_JAVA = NO - -# Set the SUBGROUPING tag to YES (the default) to allow class member groups of -# the same type (for instance a group of public functions) to be put as a -# subgroup of that type (e.g. under the Public Functions section). Set it to -# NO to prevent subgrouping. Alternatively, this can be done per class using -# the \nosubgrouping command. - -SUBGROUPING = YES - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. -# Private class members and static file members will be hidden unless -# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES - -EXTRACT_ALL = NO - -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class -# will be included in the documentation. - -EXTRACT_PRIVATE = NO - -# If the EXTRACT_STATIC tag is set to YES all static members of a file -# will be included in the documentation. - -EXTRACT_STATIC = NO - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) -# defined locally in source files will be included in the documentation. -# If set to NO only classes defined in header files are included. - -EXTRACT_LOCAL_CLASSES = NO - -# This flag is only useful for Objective-C code. When set to YES local -# methods, which are defined in the implementation section but not in -# the interface are included in the documentation. -# If set to NO (the default) only methods in the interface are included. - -EXTRACT_LOCAL_METHODS = NO - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all -# undocumented members of documented classes, files or namespaces. -# If set to NO (the default) these members will be included in the -# various overviews, but no documentation section is generated. -# This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. -# If set to NO (the default) these classes will be included in the various -# overviews. This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all -# friend (class|struct|union) declarations. -# If set to NO (the default) these declarations will be included in the -# documentation. - -HIDE_FRIEND_COMPOUNDS = NO - -# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any -# documentation blocks found inside the body of a function. -# If set to NO (the default) these blocks will be appended to the -# function's detailed documentation block. - -HIDE_IN_BODY_DOCS = NO - -# The INTERNAL_DOCS tag determines if documentation -# that is typed after a \internal command is included. If the tag is set -# to NO (the default) then the documentation will be excluded. -# Set it to YES to include the internal documentation. - -INTERNAL_DOCS = NO - -# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate -# file names in lower-case letters. If set to YES upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. - -CASE_SENSE_NAMES = YES - -# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen -# will show members with their full class and namespace scopes in the -# documentation. If set to YES the scope will be hidden. - -HIDE_SCOPE_NAMES = NO - -# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen -# will put a list of the files that are included by a file in the documentation -# of that file. - -SHOW_INCLUDE_FILES = YES - -# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] -# is inserted in the documentation for inline members. - -INLINE_INFO = YES - -# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen -# will sort the (detailed) documentation of file and class members -# alphabetically by member name. If set to NO the members will appear in -# declaration order. - SORT_MEMBER_DOCS = YES - -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the -# brief documentation of file, namespace and class members alphabetically -# by member name. If set to NO (the default) the members will appear in -# declaration order. - SORT_BRIEF_DOCS = NO - -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be -# sorted by fully-qualified names, including namespaces. If set to -# NO (the default), the class list will be sorted only by class name, -# not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the -# alphabetical list. - -SORT_BY_SCOPE_NAME = NO - -# The GENERATE_TODOLIST tag can be used to enable (YES) or -# disable (NO) the todo list. This list is created by putting \todo -# commands in the documentation. - GENERATE_TODOLIST = YES - -# The GENERATE_TESTLIST tag can be used to enable (YES) or -# disable (NO) the test list. This list is created by putting \test -# commands in the documentation. - -GENERATE_TESTLIST = YES - -# The GENERATE_BUGLIST tag can be used to enable (YES) or -# disable (NO) the bug list. This list is created by putting \bug -# commands in the documentation. - GENERATE_BUGLIST = YES - -# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or -# disable (NO) the deprecated list. This list is created by putting -# \deprecated commands in the documentation. - GENERATE_DEPRECATEDLIST= YES - -# The ENABLED_SECTIONS tag can be used to enable conditional -# documentation sections, marked by \if sectionname ... \endif. - -ENABLED_SECTIONS = - -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines -# the initial value of a variable or define consists of for it to appear in -# the documentation. If the initializer consists of more lines than specified -# here it will be hidden. Use a value of 0 to hide initializers completely. -# The appearance of the initializer of individual variables and defines in the -# documentation can be controlled using \showinitializer or \hideinitializer -# command in the documentation regardless of this setting. - -MAX_INITIALIZER_LINES = 30 - -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated -# at the bottom of the documentation of classes and structs. If set to YES the -# list will mention the files that were used to generate the documentation. - -SHOW_USED_FILES = YES - -# If the sources in your project are distributed over multiple directories -# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy -# in the documentation. The default is YES. - -SHOW_DIRECTORIES = YES - -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from the -# version control system). Doxygen will invoke the program by executing (via -# popen()) the command , where is the value of -# the FILE_VERSION_FILTER tag, and is the name of an input file -# provided by doxygen. Whatever the progam writes to standard output -# is used as the file version. See the manual for examples. - -FILE_VERSION_FILTER = - -#--------------------------------------------------------------------------- -# configuration options related to warning and progress messages -#--------------------------------------------------------------------------- - -# The QUIET tag can be used to turn on/off the messages that are generated -# by doxygen. Possible values are YES and NO. If left blank NO is used. - -QUIET = NO - -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated by doxygen. Possible values are YES and NO. If left blank -# NO is used. - +SHOW_USED_FILES = NO +SHOW_DIRECTORIES = NO WARNINGS = YES - -# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings -# for undocumented members. If EXTRACT_ALL is set to YES then this flag will -# automatically be disabled. - WARN_IF_UNDOCUMENTED = YES - -# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some -# parameters in a documented function, or documenting parameters that -# don't exist or using markup commands wrongly. - WARN_IF_DOC_ERROR = YES - -# This WARN_NO_PARAMDOC option can be abled to get warnings for -# functions that are documented, but have no documentation for their parameters -# or return value. If set to NO (the default) doxygen will only warn about -# wrong or incomplete parameter documentation, but not about the absence of -# documentation. - WARN_NO_PARAMDOC = NO - -# The WARN_FORMAT tag determines the format of the warning messages that -# doxygen can produce. The string should contain the $file, $line, and $text -# tags, which will be replaced by the file and line number from which the -# warning originated and the warning text. Optionally the format may contain -# $version, which will be replaced by the version of the file (if it could -# be obtained via FILE_VERSION_FILTER) - WARN_FORMAT = "$file:$line: $text" - -# The WARN_LOGFILE tag can be used to specify a file to which warning -# and error messages should be written. If left blank the output is written -# to stderr. - -WARN_LOGFILE = - -#--------------------------------------------------------------------------- -# configuration options related to the input files -#--------------------------------------------------------------------------- - -# The INPUT tag can be used to specify the files and/or directories that contain -# documented source files. You may enter file names like "myfile.cpp" or -# directories like "/usr/src/myproject". Separate the files or directories -# with spaces. - INPUT = . - -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank the following patterns are tested: -# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx -# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm - -FILE_PATTERNS = *.c byteorder.h debug.h mutex.h util.h xfile.h *.dox - -# The RECURSIVE tag can be used to turn specify whether or not subdirectories -# should be searched for input files as well. Possible values are YES and NO. -# If left blank NO is used. - -RECURSIVE = NO - -# The EXCLUDE tag can be used to specify files and/or directories that should -# excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. - -EXCLUDE = include/config.h include/dlinklist.h \ - include/includes.h - -# The EXCLUDE_SYMLINKS tag can be used select whether or not files or -# directories that are symbolic links (a Unix filesystem feature) are excluded -# from the input. - -EXCLUDE_SYMLINKS = NO - -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. Note that the wildcards are matched -# against the file with absolute path, so to exclude all test directories -# for example use the pattern */test/* - -EXCLUDE_PATTERNS = - -# The EXAMPLE_PATH tag can be used to specify one or more files or -# directories that contain example code fragments that are included (see -# the \include command). - -EXAMPLE_PATH = examples - -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank all files are included. - -EXAMPLE_PATTERNS = - -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude -# commands irrespective of the value of the RECURSIVE tag. -# Possible values are YES and NO. If left blank NO is used. - -EXAMPLE_RECURSIVE = NO - -# The IMAGE_PATH tag can be used to specify one or more files or -# directories that contain image that are included in the documentation (see -# the \image command). - -IMAGE_PATH = - -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command , where -# is the value of the INPUT_FILTER tag, and is the name of an -# input file. Doxygen will then use the output that the filter program writes -# to standard output. If FILTER_PATTERNS is specified, this tag will be -# ignored. - -INPUT_FILTER = - -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. The filters are a list of the form: -# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further -# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER -# is applied to all files. - -FILTER_PATTERNS = - -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER) will be used to filter the input files when producing source -# files to browse (i.e. when SOURCE_BROWSER is set to YES). - -FILTER_SOURCE_FILES = NO - -#--------------------------------------------------------------------------- -# configuration options related to source browsing -#--------------------------------------------------------------------------- - -# If the SOURCE_BROWSER tag is set to YES then a list of source files will -# be generated. Documented entities will be cross-referenced with these sources. -# Note: To get rid of all source code in the generated output, make sure also -# VERBATIM_HEADERS is set to NO. - -SOURCE_BROWSER = NO - -# Setting the INLINE_SOURCES tag to YES will include the body -# of functions and classes directly in the documentation. - -INLINE_SOURCES = NO - -# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct -# doxygen to hide any special comment blocks from generated source code -# fragments. Normal C and C++ comments will always remain visible. - -STRIP_CODE_COMMENTS = YES - -# If the REFERENCED_BY_RELATION tag is set to YES (the default) -# then for each documented function all documented -# functions referencing it will be listed. - -REFERENCED_BY_RELATION = YES - -# If the REFERENCES_RELATION tag is set to YES (the default) -# then for each documented function all documented entities -# called/used by that function will be listed. - -REFERENCES_RELATION = YES - -# If the USE_HTAGS tag is set to YES then the references to source code -# will point to the HTML generated by the htags(1) tool instead of doxygen -# built-in source browser. The htags tool is part of GNU's global source -# tagging system (see http://www.gnu.org/software/global/global.html). You -# will need version 4.8.6 or higher. - -USE_HTAGS = NO - -# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen -# will generate a verbatim copy of the header file for each class for -# which an include is specified. Set to NO to disable this. - -VERBATIM_HEADERS = YES - -#--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- - -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index -# of all compounds will be generated. Enable this if the project -# contains a lot of classes, structs, unions or interfaces. - -ALPHABETICAL_INDEX = NO - -# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then -# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns -# in which this list will be split (can be a number in the range [1..20]) - -COLS_IN_ALPHA_INDEX = 5 - -# In case all classes in a project start with a common prefix, all -# classes will be put under the same header in the alphabetical index. -# The IGNORE_PREFIX tag can be used to specify one or more prefixes that -# should be ignored while generating the index headers. - -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# configuration options related to the HTML output -#--------------------------------------------------------------------------- - -# If the GENERATE_HTML tag is set to YES (the default) Doxygen will -# generate HTML output. - +FILE_PATTERNS = *.c *.h *.dox GENERATE_HTML = YES - -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `html' will be used as the default path. - HTML_OUTPUT = html - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for -# each generated HTML page (for example: .htm,.php,.asp). If it is left blank -# doxygen will generate files with .html extension. - -HTML_FILE_EXTENSION = .html - -# The HTML_HEADER tag can be used to specify a personal HTML header for -# each generated HTML page. If it is left blank doxygen will generate a -# standard header. - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a personal HTML footer for -# each generated HTML page. If it is left blank doxygen will generate a -# standard footer. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading -# style sheet that is used by each HTML page. It can be used to -# fine-tune the look of the HTML output. If the tag is left blank doxygen -# will generate a default style sheet. Note that doxygen will try to copy -# the style sheet file to the HTML output directory, so don't put your own -# stylesheet in the HTML output directory as well, or it will be erased! - -HTML_STYLESHEET = - -# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, -# files or namespaces will be aligned in HTML using tables. If set to -# NO a bullet list will be used. - -HTML_ALIGN_MEMBERS = YES - -# If the GENERATE_HTMLHELP tag is set to YES, additional index files -# will be generated that can be used as input for tools like the -# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) -# of the generated HTML documentation. - -GENERATE_HTMLHELP = NO - -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can -# be used to specify the file name of the resulting .chm file. You -# can add a path in front of the file if the result should not be -# written to the html output directory. - -CHM_FILE = - -# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can -# be used to specify the location (absolute path including file name) of -# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run -# the HTML help compiler on the generated index.hhp. - -HHC_LOCATION = - -# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag -# controls if a separate .chi index file is generated (YES) or that -# it should be included in the master .chm file (NO). - -GENERATE_CHI = NO - -# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag -# controls whether a binary table of contents is generated (YES) or a -# normal table of contents (NO) in the .chm file. - -BINARY_TOC = NO - -# The TOC_EXPAND flag can be set to YES to add extra items for group members -# to the contents of the HTML help documentation and to the tree view. - -TOC_EXPAND = NO - -# The DISABLE_INDEX tag can be used to turn on/off the condensed index at -# top of each HTML page. The value NO (the default) enables the index and -# the value YES disables it. - -DISABLE_INDEX = NO - -# This tag can be used to set the number of enum values (range [1..20]) -# that doxygen will group on one line in the generated HTML documentation. - -ENUM_VALUES_PER_LINE = 4 - -# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be -# generated containing a tree-like index structure (just like the one that -# is generated for HTML Help). For this to work a browser that supports -# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, -# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are -# probably better off using the HTML help feature. - -GENERATE_TREEVIEW = NO - -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be -# used to set the initial width (in pixels) of the frame in which the tree -# is shown. - -TREEVIEW_WIDTH = 250 - -#--------------------------------------------------------------------------- -# configuration options related to the LaTeX output -#--------------------------------------------------------------------------- - -# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will -# generate Latex output. - -GENERATE_LATEX = NO - -# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `latex' will be used as the default path. - -LATEX_OUTPUT = latex - -# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be -# invoked. If left blank `latex' will be used as the default command name. - -LATEX_CMD_NAME = latex - -# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to -# generate index for LaTeX. If left blank `makeindex' will be used as the -# default command name. - -MAKEINDEX_CMD_NAME = makeindex - -# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact -# LaTeX documents. This may be useful for small projects and may help to -# save some trees in general. - -COMPACT_LATEX = NO - -# The PAPER_TYPE tag can be used to set the paper type that is used -# by the printer. Possible values are: a4, a4wide, letter, legal and -# executive. If left blank a4wide will be used. - -PAPER_TYPE = a4wide - -# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX -# packages that should be included in the LaTeX output. - -EXTRA_PACKAGES = - -# The LATEX_HEADER tag can be used to specify a personal LaTeX header for -# the generated latex document. The header should contain everything until -# the first chapter. If it is left blank doxygen will generate a -# standard header. Notice: only use this tag if you know what you are doing! - -LATEX_HEADER = - -# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated -# is prepared for conversion to pdf (using ps2pdf). The pdf file will -# contain links (just like the HTML output) instead of page references -# This makes the output suitable for online browsing using a pdf viewer. - -PDF_HYPERLINKS = NO - -# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of -# plain latex in the generated Makefile. Set this option to YES to get a -# higher quality PDF documentation. - -USE_PDFLATEX = YES - -# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. -# command to the generated LaTeX files. This will instruct LaTeX to keep -# running if errors occur, instead of asking the user for help. -# This option is also used when generating formulas in HTML. - -LATEX_BATCHMODE = NO - -# If LATEX_HIDE_INDICES is set to YES then doxygen will not -# include the index chapters (such as File Index, Compound Index, etc.) -# in the output. - -LATEX_HIDE_INDICES = NO - -#--------------------------------------------------------------------------- -# configuration options related to the RTF output -#--------------------------------------------------------------------------- - -# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output -# The RTF output is optimized for Word 97 and may not look very pretty with -# other RTF readers or editors. - -GENERATE_RTF = NO - -# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `rtf' will be used as the default path. - -RTF_OUTPUT = rtf - -# If the COMPACT_RTF tag is set to YES Doxygen generates more compact -# RTF documents. This may be useful for small projects and may help to -# save some trees in general. - -COMPACT_RTF = NO - -# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated -# will contain hyperlink fields. The RTF file will -# contain links (just like the HTML output) instead of page references. -# This makes the output suitable for online browsing using WORD or other -# programs which support those fields. -# Note: wordpad (write) and others do not support links. - -RTF_HYPERLINKS = NO - -# Load stylesheet definitions from file. Syntax is similar to doxygen's -# config file, i.e. a series of assignments. You only have to provide -# replacements, missing definitions are set to their default value. - -RTF_STYLESHEET_FILE = - -# Set optional variables used in the generation of an rtf document. -# Syntax is similar to doxygen's config file. - -RTF_EXTENSIONS_FILE = - -#--------------------------------------------------------------------------- -# configuration options related to the man page output -#--------------------------------------------------------------------------- - -# If the GENERATE_MAN tag is set to YES (the default) Doxygen will -# generate man pages - GENERATE_MAN = YES - -# The MAN_OUTPUT tag is used to specify where the man pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `man' will be used as the default path. - -MAN_OUTPUT = man - -# The MAN_EXTENSION tag determines the extension that is added to -# the generated man pages (default is the subroutine's section .3) - -MAN_EXTENSION = .3 - -# If the MAN_LINKS tag is set to YES and Doxygen generates man output, -# then it will generate one additional man file for each entity -# documented in the real man page(s). These additional files -# only source the real man page, but without them the man command -# would be unable to find the correct page. The default is NO. - -MAN_LINKS = NO - -#--------------------------------------------------------------------------- -# configuration options related to the XML output -#--------------------------------------------------------------------------- - -# If the GENERATE_XML tag is set to YES Doxygen will -# generate an XML file that captures the structure of -# the code including all documentation. - -GENERATE_XML = NO - -# The XML_OUTPUT tag is used to specify where the XML pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `xml' will be used as the default path. - -XML_OUTPUT = xml - -# The XML_SCHEMA tag can be used to specify an XML schema, -# which can be used by a validating XML parser to check the -# syntax of the XML files. - -XML_SCHEMA = - -# The XML_DTD tag can be used to specify an XML DTD, -# which can be used by a validating XML parser to check the -# syntax of the XML files. - -XML_DTD = - -# If the XML_PROGRAMLISTING tag is set to YES Doxygen will -# dump the program listings (including syntax highlighting -# and cross-referencing information) to the XML output. Note that -# enabling this will significantly increase the size of the XML output. - -XML_PROGRAMLISTING = YES - -#--------------------------------------------------------------------------- -# configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- - -# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will -# generate an AutoGen Definitions (see autogen.sf.net) file -# that captures the structure of the code including all -# documentation. Note that this feature is still experimental -# and incomplete at the moment. - -GENERATE_AUTOGEN_DEF = NO - -#--------------------------------------------------------------------------- -# configuration options related to the Perl module output -#--------------------------------------------------------------------------- - -# If the GENERATE_PERLMOD tag is set to YES Doxygen will -# generate a Perl module file that captures the structure of -# the code including all documentation. Note that this -# feature is still experimental and incomplete at the -# moment. - -GENERATE_PERLMOD = NO - -# If the PERLMOD_LATEX tag is set to YES Doxygen will generate -# the necessary Makefile rules, Perl scripts and LaTeX code to be able -# to generate PDF and DVI output from the Perl module output. - -PERLMOD_LATEX = NO - -# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be -# nicely formatted so it can be parsed by a human reader. This is useful -# if you want to understand what is going on. On the other hand, if this -# tag is set to NO the size of the Perl module output will be much smaller -# and Perl will parse it just the same. - -PERLMOD_PRETTY = YES - -# The names of the make variables in the generated doxyrules.make file -# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. -# This is useful so different doxyrules.make files included by the same -# Makefile don't overwrite each other's variables. - -PERLMOD_MAKEVAR_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- - -# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will -# evaluate all C-preprocessor directives found in the sources and include -# files. - -ENABLE_PREPROCESSING = YES - -# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro -# names in the source code. If set to NO (the default) only conditional -# compilation will be performed. Macro expansion can be done in a controlled -# way by setting EXPAND_ONLY_PREDEF to YES. - -MACRO_EXPANSION = NO - -# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES -# then the macro expansion is limited to the macros specified with the -# PREDEFINED and EXPAND_AS_PREDEFINED tags. - -EXPAND_ONLY_PREDEF = NO - -# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files -# in the INCLUDE_PATH (see below) will be search if a #include is found. - -SEARCH_INCLUDES = YES - -# The INCLUDE_PATH tag can be used to specify one or more directories that -# contain include files that are not input files but should be processed by -# the preprocessor. - -INCLUDE_PATH = - -# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard -# patterns (like *.h and *.hpp) to filter out the header-files in the -# directories. If left blank, the patterns specified with FILE_PATTERNS will -# be used. - -INCLUDE_FILE_PATTERNS = - -# The PREDEFINED tag can be used to specify one or more macro names that -# are defined before the preprocessor is started (similar to the -D option of -# gcc). The argument of the tag is a list of macros of the form: name -# or name=definition (no spaces). If the definition and the = are -# omitted =1 is assumed. To prevent a macro definition from being -# undefined via #undef or recursively expanded use the := operator -# instead of the = operator. - -PREDEFINED = - -# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then -# this tag can be used to specify a list of macro names that should be expanded. -# The macro definition that is found in the sources will be used. -# Use the PREDEFINED tag if you want to use a different macro definition. - -EXPAND_AS_DEFINED = - -# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then -# doxygen's preprocessor will remove all function-like macros that are alone -# on a line, have an all uppercase name, and do not end with a semicolon. Such -# function macros are typically used for boiler-plate code, and will confuse -# the parser if not removed. - -SKIP_FUNCTION_MACROS = YES - -#--------------------------------------------------------------------------- -# Configuration::additions related to external references -#--------------------------------------------------------------------------- - -# The TAGFILES option can be used to specify one or more tagfiles. -# Optionally an initial location of the external documentation -# can be added for each tagfile. The format of a tag file without -# this location is as follows: -# TAGFILES = file1 file2 ... -# Adding location for the tag files is done as follows: -# TAGFILES = file1=loc1 "file2 = loc2" ... -# where "loc1" and "loc2" can be relative or absolute paths or -# URLs. If a location is present for each tag, the installdox tool -# does not have to be run to correct the links. -# Note that each tag file must have a unique name -# (where the name does NOT include the path) -# If a tag file is not located in the directory in which doxygen -# is run, you must also specify the path to the tagfile here. - -TAGFILES = - -# When a file name is specified after GENERATE_TAGFILE, doxygen will create -# a tag file that is based on the input files it reads. - -GENERATE_TAGFILE = - -# If the ALLEXTERNALS tag is set to YES all external classes will be listed -# in the class index. If set to NO only the inherited external classes -# will be listed. - -ALLEXTERNALS = NO - -# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed -# in the modules index. If set to NO, only the current project's groups will -# be listed. - -EXTERNAL_GROUPS = YES - -# The PERL_PATH should be the absolute path and name of the perl script -# interpreter (i.e. the result of `which perl'). - -PERL_PATH = /usr/bin/perl - -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- - -# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will -# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base -# or super classes. Setting the tag to NO turns the diagrams off. Note that -# this option is superseded by the HAVE_DOT option below. This is only a -# fallback. It is recommended to install and use dot, since it yields more -# powerful graphs. - -CLASS_DIAGRAMS = NO - -# If set to YES, the inheritance and collaboration graphs will hide -# inheritance and usage relations if the target is undocumented -# or is not a class. - -HIDE_UNDOC_RELATIONS = YES - -# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is -# available from the path. This tool is part of Graphviz, a graph visualization -# toolkit from AT&T and Lucent Bell Labs. The other options in this section -# have no effect if this option is set to NO (the default) - -HAVE_DOT = NO - -# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect inheritance relations. Setting this tag to YES will force the -# the CLASS_DIAGRAMS tag to NO. - -CLASS_GRAPH = NO - -# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect implementation dependencies (inheritance, containment, and -# class references variables) of the class with other documented classes. - -COLLABORATION_GRAPH = NO - -# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for groups, showing the direct groups dependencies - -GROUP_GRAPHS = YES - -# If the UML_LOOK tag is set to YES doxygen will generate inheritance and -# collaboration diagrams in a style similar to the OMG's Unified Modeling -# Language. - -UML_LOOK = NO - -# If set to YES, the inheritance and collaboration graphs will show the -# relations between templates and their instances. - -TEMPLATE_RELATIONS = NO - -# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT -# tags are set to YES then doxygen will generate a graph for each documented -# file showing the direct and indirect include dependencies of the file with -# other documented files. - -INCLUDE_GRAPH = NO - -# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and -# HAVE_DOT tags are set to YES then doxygen will generate a graph for each -# documented header file showing the documented files that directly or -# indirectly include this file. - -INCLUDED_BY_GRAPH = YES - -# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will -# generate a call dependency graph for every global function or class method. -# Note that enabling this option will significantly increase the time of a run. -# So in most cases it will be better to enable call graphs for selected -# functions only using the \callgraph command. - -CALL_GRAPH = NO - -# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen -# will graphical hierarchy of all classes instead of a textual one. - -GRAPHICAL_HIERARCHY = NO - -# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES -# then doxygen will show the dependencies a directory has on other directories -# in a graphical way. The dependency relations are determined by the #include -# relations between the files in the directories. - -DIRECTORY_GRAPH = YES - -# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images -# generated by dot. Possible values are png, jpg, or gif -# If left blank png will be used. - -DOT_IMAGE_FORMAT = png - -# The tag DOT_PATH can be used to specify the path where the dot tool can be -# found. If left blank, it is assumed the dot tool can be found in the path. - -DOT_PATH = - -# The DOTFILE_DIRS tag can be used to specify one or more directories that -# contain dot files that are included in the documentation (see the -# \dotfile command). - -DOTFILE_DIRS = - -# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width -# (in pixels) of the graphs generated by dot. If a graph becomes larger than -# this value, doxygen will try to truncate the graph, so that it fits within -# the specified constraint. Beware that most browsers cannot cope with very -# large images. - -MAX_DOT_GRAPH_WIDTH = 1024 - -# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height -# (in pixels) of the graphs generated by dot. If a graph becomes larger than -# this value, doxygen will try to truncate the graph, so that it fits within -# the specified constraint. Beware that most browsers cannot cope with very -# large images. - -MAX_DOT_GRAPH_HEIGHT = 1024 - -# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the -# graphs generated by dot. A depth value of 3 means that only nodes reachable -# from the root by following a path via at most 3 edges will be shown. Nodes -# that lay further from the root node will be omitted. Note that setting this -# option to 1 or 2 may greatly reduce the computation time needed for large -# code bases. Also note that a graph may be further truncated if the graph's -# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH -# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), -# the graph is not depth-constrained. - -MAX_DOT_GRAPH_DEPTH = 0 - -# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent -# background. This is disabled by default, which results in a white background. -# Warning: Depending on the platform used, enabling this option may lead to -# badly anti-aliased labels on the edges of a graph (i.e. they become hard to -# read). - -DOT_TRANSPARENT = NO - -# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output -# files in one run (i.e. multiple -o and -T options on the command line). This -# makes dot run faster, but since only newer versions of dot (>1.8.10) -# support this, this feature is disabled by default. - -DOT_MULTI_TARGETS = NO - -# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will -# generate a legend page explaining the meaning of the various boxes and -# arrows in the dot generated graphs. - -GENERATE_LEGEND = YES - -# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will -# remove the intermediate dot files that are used to generate -# the various graphs. - -DOT_CLEANUP = YES - -#--------------------------------------------------------------------------- -# Configuration::additions related to the search engine -#--------------------------------------------------------------------------- - -# The SEARCHENGINE tag specifies whether or not a search engine should be -# used. If set to NO the values of all tags below this one will be ignored. - -SEARCHENGINE = NO +ALWAYS_DETAILED_SEC = YES +JAVADOC_AUTOBRIEF = YES -- cgit From 3cad0b87dc55f8eab9b00cd3aa01e817b39a5d62 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 13 Mar 2006 02:05:39 +0000 Subject: r14281: Pull apart LIBDIR and MODULESDIR Move architecture-independent data to DATADIR (was LIBDIR) (This used to be commit 2c7b62a861f702067e8df4c3239ac7e377631a15) --- source4/lib/util/util.c | 6 +++--- source4/lib/util/util_unistr.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index ec25a9cbc7..a0890d5ba9 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -637,15 +637,15 @@ static char *pid_path(TALLOC_CTX* mem_ctx, const char *name) /** * @brief Returns an absolute path to a file in the Samba lib directory. * - * @param name File to find, relative to LIBDIR. + * @param name File to find, relative to DATADIR. * * @retval Pointer to a talloc'ed string containing the full path. **/ -_PUBLIC_ char *lib_path(TALLOC_CTX* mem_ctx, const char *name) +_PUBLIC_ char *data_path(TALLOC_CTX* mem_ctx, const char *name) { char *fname; - fname = talloc_asprintf(mem_ctx, "%s/%s", dyn_LIBDIR, name); + fname = talloc_asprintf(mem_ctx, "%s/%s", dyn_DATADIR, name); return fname; } diff --git a/source4/lib/util/util_unistr.c b/source4/lib/util/util_unistr.c index 81aa0d6752..b951ea51ad 100644 --- a/source4/lib/util/util_unistr.c +++ b/source4/lib/util/util_unistr.c @@ -44,8 +44,8 @@ static void load_case_tables(void) if (!mem_ctx) { smb_panic("No memory for case_tables"); } - upcase_table = map_file(lib_path(mem_ctx, "upcase.dat"), 0x20000); - lowcase_table = map_file(lib_path(mem_ctx, "lowcase.dat"), 0x20000); + upcase_table = map_file(data_path(mem_ctx, "upcase.dat"), 0x20000); + lowcase_table = map_file(data_path(mem_ctx, "lowcase.dat"), 0x20000); talloc_free(mem_ctx); if (upcase_table == NULL) { /* try also under codepages for testing purposes */ -- cgit From 15ec1f8f00500e8d4a382371c21af4141a75772e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Mar 2006 05:02:30 +0000 Subject: r14296: added an abort() to SMB_ASSERT() so that static analysers know it doesn't return (This used to be commit 72334813087740cba42973bdf787d96d2d140bad) --- source4/lib/util/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 1dfd942dd3..318e497105 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -67,7 +67,7 @@ struct substitute_context; */ #define SMB_ASSERT(b) do { if (!(b)) { \ DEBUG(0,("PANIC: assert failed at %s(%d)\n", __FILE__, __LINE__)); \ - smb_panic("assert failed"); }} while (0) + smb_panic("assert failed"); abort(); }} while (0) /** * determine the lowest of two values -- cgit From 5afe03d9758dedc2d11208b7ed350c3128f9ad2d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Mar 2006 06:58:09 +0000 Subject: r14308: fixed an out of range shift and an uninitialised error (This used to be commit 9acc445a21b7f04eb980a05109f2c73d58221f1a) --- source4/lib/util/idtree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/idtree.c b/source4/lib/util/idtree.c index d29c3b8fbd..c02a2636a1 100644 --- a/source4/lib/util/idtree.c +++ b/source4/lib/util/idtree.c @@ -107,6 +107,8 @@ static int sub_alloc(struct idr_context *idp, void *ptr, int *starting_id) int l, id; uint32_t bm; + memset(pa, 0, sizeof(pa)); + id = *starting_id; p = idp->top; l = idp->layers; @@ -271,7 +273,7 @@ static void *_idr_find(struct idr_context *idp, int id) /* Mask off upper bits we don't use for the search. */ id &= MAX_ID_MASK; - while (n > 0 && p) { + while (n >= IDR_BITS && p) { n -= IDR_BITS; p = p->ary[(id >> n) & IDR_MASK]; } -- cgit From 3b12f543be2d5d351f44fc55f1e9cffe73f1a10e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Mar 2006 06:58:32 +0000 Subject: r14309: make sure ret is initialised (This used to be commit 1f48df6dda390ef09ae0d8efc3332e5001b75952) --- source4/lib/util/module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/module.c b/source4/lib/util/module.c index ef72551570..dc8b353547 100644 --- a/source4/lib/util/module.c +++ b/source4/lib/util/module.c @@ -100,12 +100,12 @@ _PUBLIC_ init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path) _PUBLIC_ BOOL run_init_functions(NTSTATUS (**fns) (void)) { int i; - BOOL ret; + BOOL ret = True; if (fns == NULL) return True; - for (i = 0; fns[i]; i++) { ret &= NT_STATUS_IS_OK(fns[i]()); } + for (i = 0; fns[i]; i++) { ret &= (BOOL)NT_STATUS_IS_OK(fns[i]()); } return ret; } -- cgit From e153a8099e9a187e6bcac6507ed4b1ddfe7cb764 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 13 Mar 2006 16:32:44 +0000 Subject: r14327: Replace MAJOR_VERSION/MINOR_VERSION/RELEASE_VERSION with two parameters: - VERSION: should contain the current version. Will be made part of the filename. - SO_VERSION: should contain the latest version that this on is compatible to. Will be used for setting the soname of the shared library. Fix sonames and use them on platforms that support them Remove symlinking code. ldconfig will take care of creating the symlinks now that we set the soname. (This used to be commit 7871b07e21c85c63d0ecac4c31b98dc112d18af5) --- source4/lib/util/config.mk | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index cf2e038709..9740de2020 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -1,7 +1,6 @@ [LIBRARY::LIBBASIC] -MAJOR_VERSION = 0 -MINOR_VERSION = 0 -RELEASE_VERSION = 1 +VERSION = 0.0.1 +SO_VERSION = 0.0.1 DESCRIPTION = Generic utility functions PRIVATE_PROTO_HEADER = util_proto.h PUBLIC_HEADERS = util.h \ -- cgit From 61933e159cc2a8399f8bb1fa53844a67f8bba55b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 14 Mar 2006 15:22:36 +0000 Subject: r14381: Kill structs.h (This used to be commit 1ffb82a7596f989c90df69573083a2c2e28f8808) --- source4/lib/util/util.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 318e497105..e0255c692c 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -30,6 +30,8 @@ */ struct substitute_context; +struct asn1_data; +struct smbsrv_tcon; #include "util/xfile.h" #include "util/debug.h" -- cgit From 83d8fd3dcfb326354173b585905c4438405d2a74 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 16 Mar 2006 17:51:04 +0000 Subject: r14484: Install more headers (This used to be commit 430c6516d383bfd7f27287394bf8eef9f174b3e6) --- source4/lib/util/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 9740de2020..e4a3784a91 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -2,7 +2,7 @@ VERSION = 0.0.1 SO_VERSION = 0.0.1 DESCRIPTION = Generic utility functions -PRIVATE_PROTO_HEADER = util_proto.h +PUBLIC_PROTO_HEADER = util_proto.h PUBLIC_HEADERS = util.h \ byteorder.h \ debug.h \ -- cgit From b785a7c40c185512207ef8da837a766933073032 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 16 Mar 2006 21:36:36 +0000 Subject: r14492: Fix shared libs - set SO_VERSION to 0 everywhere for now. (This used to be commit 4682bc5ce047d81586447b9df82c91ed1fe677cf) --- source4/lib/util/config.mk | 2 +- source4/lib/util/util.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index e4a3784a91..a0eabaaf31 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -1,6 +1,6 @@ [LIBRARY::LIBBASIC] VERSION = 0.0.1 -SO_VERSION = 0.0.1 +SO_VERSION = 0 DESCRIPTION = Generic utility functions PUBLIC_PROTO_HEADER = util_proto.h PUBLIC_HEADERS = util.h \ diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index e0255c692c..60cba737a9 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -24,6 +24,8 @@ #ifndef _SAMBA_UTIL_H_ #define _SAMBA_UTIL_H_ +#include "charset/charset.h" + /** * @file * @brief Helpful macros -- cgit From 5b0051e0325aea7e46715aa61bba0a1dc025132c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 17 Mar 2006 13:55:10 +0000 Subject: r14511: Install more headers (This used to be commit e1f896948fad8cf5a1aec300865c250c5721ee7d) --- source4/lib/util/util.h | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 60cba737a9..d6b412ee71 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -24,6 +24,7 @@ #ifndef _SAMBA_UTIL_H_ #define _SAMBA_UTIL_H_ +#include "core.h" #include "charset/charset.h" /** -- cgit From 7b01c9e0c464c37ee878ada65fef2c67f1f55e53 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 19 Mar 2006 03:14:56 +0000 Subject: r14556: Fix some dependencies (This used to be commit b5802770322678d3f9c2044039cc254024612f9b) --- source4/lib/util/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index d6b412ee71..73fb675e28 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -40,7 +40,7 @@ struct smbsrv_tcon; #include "util/debug.h" #include "util/mutex.h" #include "util/byteorder.h" -#include "util/util_proto.h" +#include "lib/util/util_proto.h" /** * zero a structure -- cgit From 184955ffd711a5db8b1e1b7c179c232ce0e29145 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 19 Mar 2006 19:47:05 +0000 Subject: r14572: Give libraries saner names, remove some .pc files, make some things subsystems in case a library doesn't make sense. (This used to be commit ed382873fd01457a53e0a1e1f5ba6753dfbc0646) --- source4/lib/util/config.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index a0eabaaf31..5aac291152 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -1,4 +1,4 @@ -[LIBRARY::LIBBASIC] +[LIBRARY::LIBSAMBA-UTIL] VERSION = 0.0.1 SO_VERSION = 0 DESCRIPTION = Generic utility functions @@ -33,7 +33,7 @@ OBJ_FILES = xfile.o \ module.o REQUIRED_SUBSYSTEMS = \ CHARSET LIBREPLACE LIBCRYPTO EXT_LIB_DL LIBTALLOC \ - SOCKET_WRAPPER CONFIG \ + SOCKET_WRAPPER LIBSAMBA-CONFIG \ # for the base64 functions ldb -- cgit From 18cddd580e04344e05593d9f63beb9ead53cfab2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 20 Mar 2006 00:28:12 +0000 Subject: r14575: Move some path-related functions to libsamba-config so libsamba-util doesn't have to depend on the lp_* functions. (This used to be commit f97df7d90a41b77a9edd2d6bdc47c27bf1b6bb07) --- source4/lib/util/config.mk | 2 +- source4/lib/util/debug.c | 3 +- source4/lib/util/fault.c | 7 +- source4/lib/util/util.c | 158 --------------------------------------------- source4/lib/util/util.h | 3 + 5 files changed, 10 insertions(+), 163 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 5aac291152..c598d703c5 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -33,7 +33,7 @@ OBJ_FILES = xfile.o \ module.o REQUIRED_SUBSYSTEMS = \ CHARSET LIBREPLACE LIBCRYPTO EXT_LIB_DL LIBTALLOC \ - SOCKET_WRAPPER LIBSAMBA-CONFIG \ + SOCKET_WRAPPER \ # for the base64 functions ldb diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index 2c40064b75..fa781c823a 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -117,12 +117,13 @@ _PUBLIC_ void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) free(s); } +_PUBLIC_ const char *logfile = NULL; + /** reopen the log file (usually called because the log file name might have changed) */ _PUBLIC_ void reopen_logs(void) { - const char *logfile = lp_logfile(); char *fname = NULL; int old_fd = state.fd; diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index ff44b8a292..8b447851dc 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -109,18 +109,19 @@ _PUBLIC_ void call_backtrace(void) #endif } +_PUBLIC_ const char *panic_action = NULL; + /** Something really nasty happened - panic ! **/ _PUBLIC_ void smb_panic(const char *why) { - const char *cmd = lp_panic_action(); int result; - if (cmd && *cmd) { + if (panic_action && *panic_action) { char pidstr[20]; char cmdstring[200]; - safe_strcpy(cmdstring, cmd, sizeof(cmdstring)); + safe_strcpy(cmdstring, panic_action, sizeof(cmdstring)); snprintf(pidstr, sizeof(pidstr), "%u", getpid()); all_string_sub(cmdstring, "%PID%", pidstr, sizeof(cmdstring)); if (progname) { diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index a0890d5ba9..b7293c0092 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -23,7 +23,6 @@ */ #include "includes.h" -#include "dynconfig.h" #include "system/network.h" #include "system/iconv.h" #include "system/filesys.h" @@ -267,30 +266,6 @@ _PUBLIC_ void safe_free(void *p) } -/** - see if a string matches either our primary or one of our secondary - netbios aliases. do a case insensitive match -*/ -_PUBLIC_ BOOL is_myname(const char *name) -{ - const char **aliases; - int i; - - if (strcasecmp(name, lp_netbios_name()) == 0) { - return True; - } - - aliases = lp_netbios_aliases(); - for (i=0; aliases && aliases[i]; i++) { - if (strcasecmp(name, aliases[i]) == 0) { - return True; - } - } - - return False; -} - - /** Get my own name, return in malloc'ed storage. **/ @@ -584,139 +559,6 @@ _PUBLIC_ void *memdup(const void *p, size_t size) return p2; } -/** - A useful function for returning a path in the Samba lock directory. -**/ -_PUBLIC_ char *lock_path(TALLOC_CTX* mem_ctx, const char *name) -{ - char *fname, *dname; - if (name == NULL) { - return NULL; - } - if (name[0] == 0 || name[0] == '/' || strstr(name, ":/")) { - return talloc_strdup(mem_ctx, name); - } - - dname = talloc_strdup(mem_ctx, lp_lockdir()); - trim_string(dname,"","/"); - - if (!directory_exist(dname)) { - mkdir(dname,0755); - } - - fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name); - - talloc_free(dname); - - return fname; -} - - -/** - A useful function for returning a path in the Samba piddir directory. -**/ -static char *pid_path(TALLOC_CTX* mem_ctx, const char *name) -{ - char *fname, *dname; - - dname = talloc_strdup(mem_ctx, lp_piddir()); - trim_string(dname,"","/"); - - if (!directory_exist(dname)) { - mkdir(dname,0755); - } - - fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name); - - talloc_free(dname); - - return fname; -} - - -/** - * @brief Returns an absolute path to a file in the Samba lib directory. - * - * @param name File to find, relative to DATADIR. - * - * @retval Pointer to a talloc'ed string containing the full path. - **/ - -_PUBLIC_ char *data_path(TALLOC_CTX* mem_ctx, const char *name) -{ - char *fname; - fname = talloc_asprintf(mem_ctx, "%s/%s", dyn_DATADIR, name); - return fname; -} - -/** - * @brief Returns an absolute path to a file in the Samba private directory. - * - * @param name File to find, relative to PRIVATEDIR. - * if name is not relative, then use it as-is - * - * @retval Pointer to a talloc'ed string containing the full path. - **/ -_PUBLIC_ char *private_path(TALLOC_CTX* mem_ctx, const char *name) -{ - char *fname; - if (name == NULL) { - return NULL; - } - if (name[0] == 0 || name[0] == '/' || strstr(name, ":/")) { - return talloc_strdup(mem_ctx, name); - } - fname = talloc_asprintf(mem_ctx, "%s/%s", lp_private_dir(), name); - return fname; -} - -/** - return a path in the smbd.tmp directory, where all temporary file - for smbd go. If NULL is passed for name then return the directory - path itself -*/ -_PUBLIC_ char *smbd_tmp_path(TALLOC_CTX *mem_ctx, const char *name) -{ - char *fname, *dname; - - dname = pid_path(mem_ctx, "smbd.tmp"); - if (!directory_exist(dname)) { - mkdir(dname,0755); - } - - if (name == NULL) { - return dname; - } - - fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name); - talloc_free(dname); - - return fname; -} - -static char *modules_path(TALLOC_CTX* mem_ctx, const char *name) -{ - return talloc_asprintf(mem_ctx, "%s/%s", dyn_MODULESDIR, name); -} - -/** - * Load the initialization functions from DSO files for a specific subsystem. - * - * Will return an array of function pointers to initialization functions - */ - -_PUBLIC_ init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem) -{ - char *path = modules_path(mem_ctx, subsystem); - init_module_fn *ret; - - ret = load_modules(mem_ctx, path); - - talloc_free(path); - - return ret; -} - /** * Write a password to the log file. * diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 73fb675e28..1b48bafc94 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -36,6 +36,9 @@ struct substitute_context; struct asn1_data; struct smbsrv_tcon; +extern const char *logfile; +extern const char *panic_action; + #include "util/xfile.h" #include "util/debug.h" #include "util/mutex.h" -- cgit From 2216af23c70ec8dee7162aaf35be5aed60a1a8ca Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 21 Mar 2006 11:37:11 +0000 Subject: r14612: added strncasecmp_m() and fixed strcasecmp_m() for invalid codepoints (This used to be commit 12b533450bdb31b57154940898f2f02c49e96ed1) --- source4/lib/util/util_str.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 4bb3ea1b54..8f408c00dc 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -101,14 +101,53 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) if (c1 == INVALID_CODEPOINT || c2 == INVALID_CODEPOINT) { /* what else can we do?? */ + return strcasecmp(s1, s2); + } + + if (toupper_w(c1) != toupper_w(c2)) { return c1 - c2; } + } + + return *s1 - *s2; +} + +/** + Case insensitive string compararison, length limited +**/ +_PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) +{ + codepoint_t c1=0, c2=0; + size_t size1, size2; + + while (*s1 && *s2 && n) { + n--; + + c1 = next_codepoint(s1, &size1); + c2 = next_codepoint(s2, &size2); + + s1 += size1; + s2 += size2; + + if (c1 == c2) { + continue; + } + + if (c1 == INVALID_CODEPOINT || + c2 == INVALID_CODEPOINT) { + /* what else can we do?? */ + return strcasecmp(s1, s2); + } if (toupper_w(c1) != toupper_w(c2)) { return c1 - c2; } } + if (n == 0) { + return 0; + } + return *s1 - *s2; } -- cgit From 935af3eb1963761b4c8fd9e0e9902ad592f948bf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 25 Mar 2006 18:47:47 +0000 Subject: r14724: Rearrange some source files, install more headers. (This used to be commit 7146c1600f29c349e5bb78f810e7e170b535dd37) --- source4/lib/util/util.h | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 1b48bafc94..8a2a9163d6 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -33,7 +33,6 @@ */ struct substitute_context; -struct asn1_data; struct smbsrv_tcon; extern const char *logfile; -- cgit From 12e8cea33ffdc2384cfa01ec401eb72a7093726c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Apr 2006 02:40:15 +0000 Subject: r14976: another use of the magic comment recognised by the IBM checker for deliberate fall through in switch (This used to be commit 484cea71100cfeef89c8a5670443734ee14c3b8e) --- source4/lib/util/util_file.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index b35d267582..3f6a6b3a40 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -82,6 +82,7 @@ _PUBLIC_ char *fgets_slash(char *s2,int maxlen,XFILE *f) case ' ': if (start_of_line) break; + /* fall through */ default: start_of_line = False; s[len++] = c; -- cgit From 8a069bcc53bbd0334d58f199e9d81f0f62ab7225 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Apr 2006 13:44:40 +0000 Subject: r14992: Allow load_module() to be used externally (This used to be commit a9d5d7ab5807d8a50ce8f9e3aeedfd5b6530f3a3) --- source4/lib/util/module.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/module.c b/source4/lib/util/module.c index dc8b353547..68962d9780 100644 --- a/source4/lib/util/module.c +++ b/source4/lib/util/module.c @@ -26,18 +26,17 @@ #include "includes.h" #include "system/dir.h" -static void *load_module(TALLOC_CTX *mem_ctx, const char *dir, const char *name) +/** + * Obtain the init function from a shared library file + */ +_PUBLIC_ init_module_fn load_module(TALLOC_CTX *mem_ctx, const char *path) { - char *path; void *handle; void *init_fn; - path = talloc_asprintf(mem_ctx, "%s/%s", dir, name); - handle = dlopen(path, RTLD_NOW); if (handle == NULL) { DEBUG(0, ("Unable to open %s: %s\n", path, dlerror())); - talloc_free(path); return NULL; } @@ -47,13 +46,10 @@ static void *load_module(TALLOC_CTX *mem_ctx, const char *dir, const char *name) DEBUG(0, ("Unable to find init_module() in %s: %s\n", path, dlerror())); DEBUG(1, ("Loading module '%s' failed\n", path)); dlclose(handle); - talloc_free(path); return NULL; } - talloc_free(path); - - return init_fn; + return (init_module_fn)init_fn; } /** @@ -64,6 +60,7 @@ _PUBLIC_ init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path) { DIR *dir; struct dirent *entry; + char *filename; int success = 0; init_module_fn *ret = talloc_array(mem_ctx, init_module_fn, 2); @@ -79,12 +76,16 @@ _PUBLIC_ init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path) if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) continue; - ret[success] = load_module(mem_ctx, path, entry->d_name); + filename = talloc_asprintf(mem_ctx, "%s/%s", path, entry->d_name); + + ret[success] = load_module(mem_ctx, filename); if (ret[success]) { ret = talloc_realloc(mem_ctx, ret, init_module_fn, success+2); success++; ret[success] = NULL; } + + talloc_free(filename); } closedir(dir); -- cgit From 69979ddc6e6a5b36f710ec6155b50c00568f68cf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Apr 2006 15:26:59 +0000 Subject: r14998: Remove unused autoconf test, move others to proper places (This used to be commit bfa396a16056f54163c514da8b34aaf229653765) --- source4/lib/util/fsusage.m4 | 184 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 source4/lib/util/fsusage.m4 (limited to 'source4/lib/util') diff --git a/source4/lib/util/fsusage.m4 b/source4/lib/util/fsusage.m4 new file mode 100644 index 0000000000..ce8489493c --- /dev/null +++ b/source4/lib/util/fsusage.m4 @@ -0,0 +1,184 @@ +################################################# +# these tests are taken from the GNU fileutils package +AC_CHECKING(how to get filesystem space usage) +AC_CHECK_HEADERS(sys/statfs.h sys/statvfs.h) +space=no + +# Test for statvfs64. +if test $space = no; then + # SVR4 + AC_CACHE_CHECK([statvfs64 function (SVR4)], fu_cv_sys_stat_statvfs64, + [AC_TRY_RUN([ +#if defined(HAVE_UNISTD_H) +#include +#endif +#include +#include + main () + { + struct statvfs64 fsd; + exit (statvfs64 (".", &fsd)); + }], + fu_cv_sys_stat_statvfs64=yes, + fu_cv_sys_stat_statvfs64=no, + fu_cv_sys_stat_statvfs64=cross)]) + if test $fu_cv_sys_stat_statvfs64 = yes; then + space=yes + AC_DEFINE(STAT_STATVFS64,1,[Whether statvfs64() is available]) + fi +fi + +# Perform only the link test since it seems there are no variants of the +# statvfs function. This check is more than just AC_CHECK_FUNCS(statvfs) +# because that got a false positive on SCO OSR5. Adding the declaration +# of a `struct statvfs' causes this test to fail (as it should) on such +# systems. That system is reported to work fine with STAT_STATFS4 which +# is what it gets when this test fails. +if test $space = no; then + # SVR4 + AC_CACHE_CHECK([statvfs function (SVR4)], fu_cv_sys_stat_statvfs, + [AC_TRY_LINK([#include +#include ], + [struct statvfs fsd; statvfs (0, &fsd);], + fu_cv_sys_stat_statvfs=yes, + fu_cv_sys_stat_statvfs=no)]) + if test $fu_cv_sys_stat_statvfs = yes; then + space=yes + AC_DEFINE(STAT_STATVFS,1,[Whether statvfs() is available]) + fi +fi + +if test $space = no; then + # DEC Alpha running OSF/1 + AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)]) + AC_CACHE_VAL(fu_cv_sys_stat_statfs3_osf1, + [AC_TRY_RUN([ +#include +#include +#include + main () + { + struct statfs fsd; + fsd.f_fsize = 0; + exit (statfs (".", &fsd, sizeof (struct statfs))); + }], + fu_cv_sys_stat_statfs3_osf1=yes, + fu_cv_sys_stat_statfs3_osf1=no, + fu_cv_sys_stat_statfs3_osf1=no)]) + AC_MSG_RESULT($fu_cv_sys_stat_statfs3_osf1) + if test $fu_cv_sys_stat_statfs3_osf1 = yes; then + space=yes + AC_DEFINE(STAT_STATFS3_OSF1,1,[Whether statfs requires 3 arguments]) + fi +fi + +if test $space = no; then +# AIX + AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl +member (AIX, 4.3BSD)]) + AC_CACHE_VAL(fu_cv_sys_stat_statfs2_bsize, + [AC_TRY_RUN([ +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#ifdef HAVE_SYS_MOUNT_H +#include +#endif +#ifdef HAVE_SYS_VFS_H +#include +#endif + main () + { + struct statfs fsd; + fsd.f_bsize = 0; + exit (statfs (".", &fsd)); + }], + fu_cv_sys_stat_statfs2_bsize=yes, + fu_cv_sys_stat_statfs2_bsize=no, + fu_cv_sys_stat_statfs2_bsize=no)]) + AC_MSG_RESULT($fu_cv_sys_stat_statfs2_bsize) + if test $fu_cv_sys_stat_statfs2_bsize = yes; then + space=yes + AC_DEFINE(STAT_STATFS2_BSIZE,1,[Whether statfs requires two arguments and struct statfs has bsize property]) + fi +fi + +if test $space = no; then +# SVR3 + AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)]) + AC_CACHE_VAL(fu_cv_sys_stat_statfs4, + [AC_TRY_RUN([#include +#include + main () + { + struct statfs fsd; + exit (statfs (".", &fsd, sizeof fsd, 0)); + }], + fu_cv_sys_stat_statfs4=yes, + fu_cv_sys_stat_statfs4=no, + fu_cv_sys_stat_statfs4=no)]) + AC_MSG_RESULT($fu_cv_sys_stat_statfs4) + if test $fu_cv_sys_stat_statfs4 = yes; then + space=yes + AC_DEFINE(STAT_STATFS4,1,[Whether statfs requires 4 arguments]) + fi +fi + +if test $space = no; then +# 4.4BSD and NetBSD + AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl +member (4.4BSD and NetBSD)]) + AC_CACHE_VAL(fu_cv_sys_stat_statfs2_fsize, + [AC_TRY_RUN([#include +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#ifdef HAVE_SYS_MOUNT_H +#include +#endif + main () + { + struct statfs fsd; + fsd.f_fsize = 0; + exit (statfs (".", &fsd)); + }], + fu_cv_sys_stat_statfs2_fsize=yes, + fu_cv_sys_stat_statfs2_fsize=no, + fu_cv_sys_stat_statfs2_fsize=no)]) + AC_MSG_RESULT($fu_cv_sys_stat_statfs2_fsize) + if test $fu_cv_sys_stat_statfs2_fsize = yes; then + space=yes + AC_DEFINE(STAT_STATFS2_FSIZE,1,[Whether statfs requires 2 arguments and struct statfs has fsize]) + fi +fi + +if test $space = no; then + # Ultrix + AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)]) + AC_CACHE_VAL(fu_cv_sys_stat_fs_data, + [AC_TRY_RUN([#include +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#ifdef HAVE_SYS_MOUNT_H +#include +#endif +#ifdef HAVE_SYS_FS_TYPES_H +#include +#endif + main () + { + struct fs_data fsd; + /* Ultrix's statfs returns 1 for success, + 0 for not mounted, -1 for failure. */ + exit (statfs (".", &fsd) != 1); + }], + fu_cv_sys_stat_fs_data=yes, + fu_cv_sys_stat_fs_data=no, + fu_cv_sys_stat_fs_data=no)]) + AC_MSG_RESULT($fu_cv_sys_stat_fs_data) + if test $fu_cv_sys_stat_fs_data = yes; then + space=yes + AC_DEFINE(STAT_STATFS2_FS_DATA,1,[Whether statfs requires 2 arguments and struct fs_data is available]) + fi +fi -- cgit From 4a61e4901ebc751fea57880424f9045e3bdf238e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Apr 2006 16:05:21 +0000 Subject: r14999: Remove more unused autoconf code Simplify va_copy() replacement code a bit (This used to be commit a5c87360a7f14a90b831ea372277f4f89ee4c5f1) --- source4/lib/util/dprintf.c | 2 +- source4/lib/util/select.c | 2 +- source4/lib/util/util_file.c | 2 +- source4/lib/util/xfile.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 916db3af93..62dc2a227a 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -38,7 +38,7 @@ _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBU va_list ap2; /* do any message translations */ - VA_COPY(ap2, ap); + va_copy(ap2, ap); ret = vasprintf(&p, format, ap2); diff --git a/source4/lib/util/select.c b/source4/lib/util/select.c index a1b2e04065..4f906f2454 100644 --- a/source4/lib/util/select.c +++ b/source4/lib/util/select.c @@ -32,7 +32,7 @@ static pid_t initialised; static int select_pipe[2]; -static VOLATILE unsigned pipe_written, pipe_read; +static volatile unsigned pipe_written, pipe_read; /******************************************************************* Call this from all Samba signal handlers if you want to avoid a diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index 3f6a6b3a40..8d8e7c6ec9 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -371,7 +371,7 @@ _PUBLIC_ int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE int len, ret; va_list ap2; - VA_COPY(ap2, ap); + va_copy(ap2, ap); len = vasprintf(&p, format, ap2); if (len <= 0) return len; diff --git a/source4/lib/util/xfile.c b/source4/lib/util/xfile.c index 97bab2ef9a..1cf77a3220 100644 --- a/source4/lib/util/xfile.c +++ b/source4/lib/util/xfile.c @@ -202,7 +202,7 @@ size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f) int len, ret; va_list ap2; - VA_COPY(ap2, ap); + va_copy(ap2, ap); len = vasprintf(&p, format, ap2); if (len <= 0) return len; -- cgit From 4ab73d6045aacd354894fe5edf0c5cfc75784064 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Apr 2006 16:25:53 +0000 Subject: r15000: Move some more autoconf tests out of build/m4/rewrite.m4 Guarantee availability of __FUNCTION__ in libreplace (This used to be commit 76b1576541210f2bb306ae17e0876b254e8dcead) --- source4/lib/util/capability.c | 1 - source4/lib/util/capability.m4 | 17 +++++++++++++++++ source4/lib/util/debug.h | 10 +--------- 3 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 source4/lib/util/capability.m4 (limited to 'source4/lib/util') diff --git a/source4/lib/util/capability.c b/source4/lib/util/capability.c index 09af293087..683bc99723 100644 --- a/source4/lib/util/capability.c +++ b/source4/lib/util/capability.c @@ -114,4 +114,3 @@ _PUBLIC_ void oplock_set_capability(BOOL this_process, BOOL inherit) set_inherited_process_capability(KERNEL_OPLOCK_CAPABILITY,inherit); #endif } - diff --git a/source4/lib/util/capability.m4 b/source4/lib/util/capability.m4 new file mode 100644 index 0000000000..2a95a607d5 --- /dev/null +++ b/source4/lib/util/capability.m4 @@ -0,0 +1,17 @@ +AC_CACHE_CHECK([for irix specific capabilities],samba_cv_HAVE_IRIX_SPECIFIC_CAPABILITIES,[ +AC_TRY_RUN([#include +#include +main() { + cap_t cap; + if ((cap = cap_get_proc()) == NULL) + exit(1); + cap->cap_effective |= CAP_NETWORK_MGT; + cap->cap_inheritable |= CAP_NETWORK_MGT; + cap_set_proc(cap); + exit(0); +} +], +samba_cv_HAVE_IRIX_SPECIFIC_CAPABILITIES=yes,samba_cv_HAVE_IRIX_SPECIFIC_CAPABILITIES=no,samba_cv_HAVE_IRIX_SPECIFIC_CAPABILITIES=cross)]) +if test x"$samba_cv_HAVE_IRIX_SPECIFIC_CAPABILITIES" = x"yes"; then + AC_DEFINE(HAVE_IRIX_SPECIFIC_CAPABILITIES,1,[Whether IRIX specific capabilities are available]) +fi diff --git a/source4/lib/util/debug.h b/source4/lib/util/debug.h index 10d7d0697c..80155cdccf 100644 --- a/source4/lib/util/debug.h +++ b/source4/lib/util/debug.h @@ -23,14 +23,6 @@ * @brief Debugging macros */ -/* If we have these macros, we can add additional info to the header. */ - -#ifdef HAVE_FUNCTION_MACRO -#define FUNCTION_MACRO (__FUNCTION__) -#else -#define FUNCTION_MACRO ("") -#endif - /* the debug operations structure - contains function pointers to various debug implementations of each operation */ struct debug_ops { @@ -54,7 +46,7 @@ extern int DEBUGLEVEL; #define _DEBUG(level, body, header) do { \ if (DEBUGLVL(level)) { \ if (header) { \ - do_debug_header(level, __location__, FUNCTION_MACRO); \ + do_debug_header(level, __location__, __FUNCTION__); \ } \ do_debug body; \ } \ -- cgit From 4480a62ec3845d1e4f7d3f161f542d7cfe748320 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Apr 2006 17:19:32 +0000 Subject: r15002: More cleanups in build/m4/rewrite.m4 (This used to be commit f5e2cc845696b56b9cb6a6c3cad48cd57fcc51c4) --- source4/lib/util/time.m4 | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 source4/lib/util/time.m4 (limited to 'source4/lib/util') diff --git a/source4/lib/util/time.m4 b/source4/lib/util/time.m4 new file mode 100644 index 0000000000..f61ae4cd25 --- /dev/null +++ b/source4/lib/util/time.m4 @@ -0,0 +1,9 @@ +AC_CACHE_CHECK([if gettimeofday takes tz argument],samba_cv_HAVE_GETTIMEOFDAY_TZ,[ +AC_TRY_RUN([ +#include +#include +main() { struct timeval tv; exit(gettimeofday(&tv, NULL));}], + samba_cv_HAVE_GETTIMEOFDAY_TZ=yes,samba_cv_HAVE_GETTIMEOFDAY_TZ=no,samba_cv_HAVE_GETTIMEOFDAY_TZ=cross)]) +if test x"$samba_cv_HAVE_GETTIMEOFDAY_TZ" = x"yes"; then + AC_DEFINE(HAVE_GETTIMEOFDAY_TZ,1,[Whether gettimeofday() is available]) +fi -- cgit From 6ab33938d5239e8688440f65e802f627622d301b Mon Sep 17 00:00:00 2001 From: James Peach Date: Mon, 24 Apr 2006 00:16:51 +0000 Subject: r15186: Introduce ISDOT and ISDOTDOT macros for testing whether a filename is "." for "..". These express the intention better that strcmp or strequal and improve searchability via cscope/ctags. (This used to be commit 7e4ad7e8e5ec266b969e3075c4ad7f021571f24e) --- source4/lib/util/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/module.c b/source4/lib/util/module.c index 68962d9780..597be90478 100644 --- a/source4/lib/util/module.c +++ b/source4/lib/util/module.c @@ -73,7 +73,7 @@ _PUBLIC_ init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path) } while((entry = readdir(dir))) { - if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) + if (ISDOT(entry->d_name) || ISDOTDOT(entry->d_name)) continue; filename = talloc_asprintf(mem_ctx, "%s/%s", path, entry->d_name); -- cgit From 0eddf14b307e905663b95296aa695a10d3fb90f7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 24 Apr 2006 09:36:09 +0000 Subject: r15191: Avoid uint_t as it's not standard. (This used to be commit 7af59357b94e3819415b3a9257be0ced745ce130) --- source4/lib/util/debug.c | 2 +- source4/lib/util/pidfile.c | 10 +++++----- source4/lib/util/util.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index fa781c823a..9084c2b406 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -182,7 +182,7 @@ _PUBLIC_ void setup_logging(const char *prog_name, enum debug_logtype new_logtyp return a string constant containing n tabs no more than 10 tabs are returned */ -_PUBLIC_ const char *do_debug_tab(uint_t n) +_PUBLIC_ const char *do_debug_tab(int n) { const char *tabs[] = {"", "\t", "\t\t", "\t\t\t", "\t\t\t\t", "\t\t\t\t\t", "\t\t\t\t\t\t", "\t\t\t\t\t\t\t", "\t\t\t\t\t\t\t\t", diff --git a/source4/lib/util/pidfile.c b/source4/lib/util/pidfile.c index 1a46e6e70c..dc9ecafae9 100644 --- a/source4/lib/util/pidfile.c +++ b/source4/lib/util/pidfile.c @@ -40,7 +40,7 @@ _PUBLIC_ pid_t pidfile_pid(const char *name) { int fd; char pidstr[20]; - uint_t ret; + pid_t ret; char *pidFile; asprintf(&pidFile, "%s/%s.pid", lp_piddir(), name); @@ -58,9 +58,9 @@ _PUBLIC_ pid_t pidfile_pid(const char *name) goto noproc; } - ret = atoi(pidstr); + ret = (pid_t)atoi(pidstr); - if (!process_exists((pid_t)ret)) { + if (!process_exists(ret)) { goto noproc; } @@ -71,7 +71,7 @@ _PUBLIC_ pid_t pidfile_pid(const char *name) close(fd); SAFE_FREE(pidFile); - return (pid_t)ret; + return ret; noproc: close(fd); @@ -113,7 +113,7 @@ void pidfile_create(const char *name) } memset(buf, 0, sizeof(buf)); - slprintf(buf, sizeof(buf) - 1, "%u\n", (uint_t) getpid()); + slprintf(buf, sizeof(buf) - 1, "%u\n", (unsigned int) getpid()); if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) { DEBUG(0,("ERROR: can't write to file %s: %s\n", pidFile, strerror(errno))); diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index b7293c0092..0354d17097 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -212,7 +212,7 @@ _PUBLIC_ int set_blocking(int fd, BOOL set) Sleep for a specified number of milliseconds. **/ -_PUBLIC_ void msleep(uint_t t) +_PUBLIC_ void msleep(unsigned int t) { struct timeval tval; @@ -581,7 +581,7 @@ _PUBLIC_ void dump_data_pw(const char *msg, const uint8_t * data, size_t len) * see if a range of memory is all zero. A NULL pointer is considered * to be all zero */ -_PUBLIC_ BOOL all_zero(const uint8_t *ptr, uint_t size) +_PUBLIC_ BOOL all_zero(const uint8_t *ptr, size_t size) { int i; if (!ptr) return True; -- cgit From e2e3a8e007ac2a9533f4205622a6e17d57845fcc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 24 Apr 2006 14:09:07 +0000 Subject: r15200: Move MIN/MAX macros to libreplace as some systems have them in sys/param.h (This used to be commit 3f0396aade82a92a375275059baf8500de1b23f0) --- source4/lib/util/util.h | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 8a2a9163d6..302bd06323 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -76,20 +76,6 @@ extern const char *panic_action; DEBUG(0,("PANIC: assert failed at %s(%d)\n", __FILE__, __LINE__)); \ smb_panic("assert failed"); abort(); }} while (0) -/** - * determine the lowest of two values - */ -#ifndef MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif - -/** - * determine the highest of two values - */ -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - /** * determine absolute value */ -- cgit From a30340affe789cd0c001e34c8e523fbba0742cfc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 24 Apr 2006 14:20:44 +0000 Subject: r15201: Use abs() rather then ABS() (This used to be commit 1f3833d041fddaf79cd19d4f236780a02e97f095) --- source4/lib/util/util.h | 7 ------- 1 file changed, 7 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 302bd06323..383323b5ed 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -76,13 +76,6 @@ extern const char *panic_action; DEBUG(0,("PANIC: assert failed at %s(%d)\n", __FILE__, __LINE__)); \ smb_panic("assert failed"); abort(); }} while (0) -/** - * determine absolute value - */ -#ifndef ABS -#define ABS(a) ((a)>0?(a):(-(a))) -#endif - #ifndef SAFE_FREE /* Oh no this is also defined in tdb.h */ /** * Free memory if the pointer and zero the pointer. -- cgit From 69b51f702af1ded825d5c17bdb97014cac12e752 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 24 Apr 2006 15:47:59 +0000 Subject: r15207: Introduce PRIVATE_DEPENDENCIES and PUBLIC_DEPENDENCIES as replacement for REQUIRED_SUBSYSTEMS. (This used to be commit adc8a019b6da256f104abed1b82bfde6998a2ac9) --- source4/lib/util/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index c598d703c5..89e2a4c048 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -31,7 +31,7 @@ OBJ_FILES = xfile.o \ mutex.o \ idtree.o \ module.o -REQUIRED_SUBSYSTEMS = \ +PUBLIC_DEPENDENCIES = \ CHARSET LIBREPLACE LIBCRYPTO EXT_LIB_DL LIBTALLOC \ SOCKET_WRAPPER \ # for the base64 functions -- cgit From 763c0a8983cc39435489cca45389e33278e95e5b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 24 Apr 2006 16:15:29 +0000 Subject: r15213: Remove helper macro for bcopy() - this causes problems with system headers on some system and is not a security threat (This used to be commit 5d2f845acc069b8435026b4f1c660b5bb0a96823) --- source4/lib/util/safe_string.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/safe_string.h b/source4/lib/util/safe_string.h index 43e094467c..92d11ca848 100644 --- a/source4/lib/util/safe_string.h +++ b/source4/lib/util/safe_string.h @@ -25,11 +25,6 @@ /* Some macros to ensure people don't use buffer overflow vulnerable string functions. */ -#ifdef bcopy -#undef bcopy -#endif /* bcopy */ -#define bcopy(src,dest,size) __ERROR__XX__NEVER_USE_BCOPY___; - #ifdef strcpy #undef strcpy #endif /* strcpy */ -- cgit From c40d7ebfe2365229275bcfb778ba41a0ec83d2fe Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 25 Apr 2006 22:57:06 +0000 Subject: r15257: Look for headers before trying to use them in any tests. This should fix the OpenBSD build (This used to be commit 6172731af1f91d4e5f9d49284a179b0966ba19ef) --- source4/lib/util/fsusage.m4 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/fsusage.m4 b/source4/lib/util/fsusage.m4 index ce8489493c..6d5d13fe25 100644 --- a/source4/lib/util/fsusage.m4 +++ b/source4/lib/util/fsusage.m4 @@ -1,7 +1,13 @@ ################################################# # these tests are taken from the GNU fileutils package AC_CHECKING(how to get filesystem space usage) -AC_CHECK_HEADERS(sys/statfs.h sys/statvfs.h) +AC_CHECK_HEADERS(sys/statfs.h sys/statvfs.h sys/vfs.h) + +AC_CHECK_HEADERS(sys/mount.h, , , [AC_INCLUDES_DEFAULT +#ifdef HAVE_SYS_PARAM_H +#include +#endif]) + space=no # Test for statvfs64. -- cgit From 0d5587b5d128d9dd502a3b78c02fb986b33d92c4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 26 Apr 2006 12:22:54 +0000 Subject: r15274: Drop default EXT_LIB_ prefix for external libraries. Fixes issues with local (empty) libpopt.a overriding global one (This used to be commit 2f06305e53478e5030c24550954f221a9a97c83f) --- source4/lib/util/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 89e2a4c048..4e81725ea5 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -32,7 +32,7 @@ OBJ_FILES = xfile.o \ idtree.o \ module.o PUBLIC_DEPENDENCIES = \ - CHARSET LIBREPLACE LIBCRYPTO EXT_LIB_DL LIBTALLOC \ + CHARSET LIBREPLACE LIBCRYPTO DL LIBTALLOC \ SOCKET_WRAPPER \ # for the base64 functions ldb -- cgit From 8d137d97858a618c8c5451bb7b11fb95990540c8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 27 Apr 2006 16:05:05 +0000 Subject: r15295: Fix some dependencies Move unistr-specific code to lib/charset/. Remove _m from some places where it's not needed. (This used to be commit 03224e112424968fc3f547c6159c7ccae2d1aa5b) --- source4/lib/util/config.mk | 7 +- source4/lib/util/safe_string.h | 5 - source4/lib/util/system.c | 4 +- source4/lib/util/util.c | 4 +- source4/lib/util/util_sock.c | 2 +- source4/lib/util/util_str.c | 652 ++++++----------------------------------- source4/lib/util/util_unistr.c | 155 ---------- 7 files changed, 104 insertions(+), 725 deletions(-) delete mode 100644 source4/lib/util/util_unistr.c (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 4e81725ea5..267d7fdbc1 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -19,7 +19,6 @@ OBJ_FILES = xfile.o \ dprintf.o \ util_str.o \ util_strlist.o \ - util_unistr.o \ util_file.o \ data_blob.o \ util.o \ @@ -32,10 +31,8 @@ OBJ_FILES = xfile.o \ idtree.o \ module.o PUBLIC_DEPENDENCIES = \ - CHARSET LIBREPLACE LIBCRYPTO DL LIBTALLOC \ - SOCKET_WRAPPER \ -# for the base64 functions - ldb + LIBREPLACE LIBCRYPTO DL LIBTALLOC \ + SOCKET_WRAPPER [SUBSYSTEM::PIDFILE] PRIVATE_PROTO_HEADER = pidfile.h diff --git a/source4/lib/util/safe_string.h b/source4/lib/util/safe_string.h index 92d11ca848..ff4cd5398f 100644 --- a/source4/lib/util/safe_string.h +++ b/source4/lib/util/safe_string.h @@ -42,9 +42,4 @@ #endif /* !_SPLINT_ */ -/* replace some string functions with multi-byte - versions */ -#define strlower(s) strlower_m(s) -#define strupper(s) strupper_m(s) - #endif diff --git a/source4/lib/util/system.c b/source4/lib/util/system.c index 5f8db9ef63..9fec2a50e3 100644 --- a/source4/lib/util/system.c +++ b/source4/lib/util/system.c @@ -52,7 +52,7 @@ _PUBLIC_ struct hostent *sys_gethostbyname(const char *name) /* Does this name have any dots in it? If so, make no change */ - if (strchr_m(name, '.')) + if (strchr(name, '.')) return(gethostbyname(name)); /* Get my hostname, which should have domain name @@ -62,7 +62,7 @@ _PUBLIC_ struct hostent *sys_gethostbyname(const char *name) gethostname(hostname, sizeof(hostname) - 1); hostname[sizeof(hostname) - 1] = 0; - if ((domain = strchr_m(hostname, '.')) == NULL) + if ((domain = strchr(hostname, '.')) == NULL) return(gethostbyname(name)); /* Attach domain name to query and do modified query. diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index 0354d17097..c674ed23b4 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -289,7 +289,7 @@ _PUBLIC_ char* get_myname(void) hostname[host_name_max] = '\0'; /* split off any parts after an initial . */ - p = strchr_m(hostname,'.'); + p = strchr(hostname,'.'); if (p) *p = 0; @@ -311,7 +311,7 @@ _PUBLIC_ BOOL is_ipaddress(const char *str) pure_address = False; /* Check that a pure number is not misinterpreted as an IP */ - pure_address = pure_address && (strchr_m(str, '.') != NULL); + pure_address = pure_address && (strchr(str, '.') != NULL); return pure_address; } diff --git a/source4/lib/util/util_sock.c b/source4/lib/util/util_sock.c index 0a4380faf4..28a15066b8 100644 --- a/source4/lib/util/util_sock.c +++ b/source4/lib/util/util_sock.c @@ -90,7 +90,7 @@ _PUBLIC_ void set_socket_options(int fd, const char *options) char *p; BOOL got_value = False; - if ((p = strchr_m(tok,'='))) { + if ((p = strchr(tok,'='))) { *p = 0; value = atoi(p+1); got_value = True; diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 8f408c00dc..9de27c0777 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -23,208 +23,16 @@ */ #include "includes.h" -#include "system/iconv.h" #include "smb.h" #include "pstring.h" #include "lib/ldb/include/ldb.h" +#include "system/iconv.h" /** * @file * @brief String utilities. **/ -/** - * Get the next token from a string, return False if none found. - * Handles double-quotes. - * - * Based on a routine by GJC@VILLAGE.COM. - * Extensively modified by Andrew.Tridgell@anu.edu.au - **/ -_PUBLIC_ BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize) -{ - const char *s; - BOOL quoted; - size_t len=1; - - if (!ptr) - return(False); - - s = *ptr; - - /* default to simple separators */ - if (!sep) - sep = " \t\n\r"; - - /* find the first non sep char */ - while (*s && strchr_m(sep,*s)) - s++; - - /* nothing left? */ - if (! *s) - return(False); - - /* copy over the token */ - for (quoted = False; len < bufsize && *s && (quoted || !strchr_m(sep,*s)); s++) { - if (*s == '\"') { - quoted = !quoted; - } else { - len++; - *buff++ = *s; - } - } - - *ptr = (*s) ? s+1 : s; - *buff = 0; - - return(True); -} - -/** - Case insensitive string compararison -**/ -_PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) -{ - codepoint_t c1=0, c2=0; - size_t size1, size2; - - while (*s1 && *s2) { - c1 = next_codepoint(s1, &size1); - c2 = next_codepoint(s2, &size2); - - s1 += size1; - s2 += size2; - - if (c1 == c2) { - continue; - } - - if (c1 == INVALID_CODEPOINT || - c2 == INVALID_CODEPOINT) { - /* what else can we do?? */ - return strcasecmp(s1, s2); - } - - if (toupper_w(c1) != toupper_w(c2)) { - return c1 - c2; - } - } - - return *s1 - *s2; -} - -/** - Case insensitive string compararison, length limited -**/ -_PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) -{ - codepoint_t c1=0, c2=0; - size_t size1, size2; - - while (*s1 && *s2 && n) { - n--; - - c1 = next_codepoint(s1, &size1); - c2 = next_codepoint(s2, &size2); - - s1 += size1; - s2 += size2; - - if (c1 == c2) { - continue; - } - - if (c1 == INVALID_CODEPOINT || - c2 == INVALID_CODEPOINT) { - /* what else can we do?? */ - return strcasecmp(s1, s2); - } - - if (toupper_w(c1) != toupper_w(c2)) { - return c1 - c2; - } - } - - if (n == 0) { - return 0; - } - - return *s1 - *s2; -} - -/** - * Compare 2 strings. - * - * @note The comparison is case-insensitive. - **/ -_PUBLIC_ BOOL strequal(const char *s1, const char *s2) -{ - if (s1 == s2) - return(True); - if (!s1 || !s2) - return(False); - - return strcasecmp_m(s1,s2) == 0; -} - -/** - Compare 2 strings (case sensitive). -**/ -_PUBLIC_ BOOL strcsequal(const char *s1,const char *s2) -{ - if (s1 == s2) - return(True); - if (!s1 || !s2) - return(False); - - return strcmp(s1,s2) == 0; -} - - -/** -Do a case-insensitive, whitespace-ignoring string compare. -**/ -_PUBLIC_ int strwicmp(const char *psz1, const char *psz2) -{ - /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */ - /* appropriate value. */ - if (psz1 == psz2) - return (0); - else if (psz1 == NULL) - return (-1); - else if (psz2 == NULL) - return (1); - - /* sync the strings on first non-whitespace */ - while (1) { - while (isspace((int)*psz1)) - psz1++; - while (isspace((int)*psz2)) - psz2++; - if (toupper((unsigned char)*psz1) != toupper((unsigned char)*psz2) - || *psz1 == '\0' - || *psz2 == '\0') - break; - psz1++; - psz2++; - } - return (*psz1 - *psz2); -} - -/** - String replace. - NOTE: oldc and newc must be 7 bit characters -**/ -_PUBLIC_ void string_replace(char *s, char oldc, char newc) -{ - while (*s) { - size_t size; - codepoint_t c = next_codepoint(s, &size); - if (c == oldc) { - *s = newc; - } - s += size; - } -} /** Trim the specified elements off the front and back of a string. @@ -363,52 +171,6 @@ _PUBLIC_ char *safe_strcat(char *dest, const char *src, size_t maxlength) return dest; } -/** - Paranoid strcpy into a buffer of given length (includes terminating - zero. Strips out all but 'a-Z0-9' and the character in other_safe_chars - and replaces with '_'. Deliberately does *NOT* check for multibyte - characters. Don't change it ! -**/ - -_PUBLIC_ char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength) -{ - size_t len, i; - - if (maxlength == 0) { - /* can't fit any bytes at all! */ - return NULL; - } - - if (!dest) { - DEBUG(0,("ERROR: NULL dest in alpha_strcpy\n")); - return NULL; - } - - if (!src) { - *dest = 0; - return dest; - } - - len = strlen(src); - if (len >= maxlength) - len = maxlength - 1; - - if (!other_safe_chars) - other_safe_chars = ""; - - for(i = 0; i < len; i++) { - int val = (src[i] & 0xff); - if (isupper(val) || islower(val) || isdigit(val) || strchr_m(other_safe_chars, val)) - dest[i] = src[i]; - else - dest[i] = '_'; - } - - dest[i] = '\0'; - - return dest; -} - /** Like strncpy but always null terminates. Make sure there is room! The variable n should always be one less than the available size. @@ -454,12 +216,12 @@ _PUBLIC_ size_t strhex_to_str(char *p, size_t len, const char *strhex) continue; } - if (!(p1 = strchr_m(hexchars, toupper((unsigned char)strhex[i])))) + if (!(p1 = strchr(hexchars, toupper((unsigned char)strhex[i])))) break; i++; /* next hex digit */ - if (!(p2 = strchr_m(hexchars, toupper((unsigned char)strhex[i])))) + if (!(p2 = strchr(hexchars, toupper((unsigned char)strhex[i])))) break; /* get the two nybbles */ @@ -662,294 +424,6 @@ _PUBLIC_ void all_string_sub(char *s,const char *pattern,const char *insert, siz } -/** - Strchr and strrchr_m are a bit complex on general multi-byte strings. -**/ -_PUBLIC_ char *strchr_m(const char *s, char c) -{ - /* characters below 0x3F are guaranteed to not appear in - non-initial position in multi-byte charsets */ - if ((c & 0xC0) == 0) { - return strchr(s, c); - } - - while (*s) { - size_t size; - codepoint_t c2 = next_codepoint(s, &size); - if (c2 == c) { - return discard_const(s); - } - s += size; - } - - return NULL; -} - -/** - * Multibyte-character version of strrchr - */ -_PUBLIC_ char *strrchr_m(const char *s, char c) -{ - char *ret = NULL; - - /* characters below 0x3F are guaranteed to not appear in - non-initial position in multi-byte charsets */ - if ((c & 0xC0) == 0) { - return strrchr(s, c); - } - - while (*s) { - size_t size; - codepoint_t c2 = next_codepoint(s, &size); - if (c2 == c) { - ret = discard_const(s); - } - s += size; - } - - return ret; -} - -/** - return True if any (multi-byte) character is lower case -*/ -_PUBLIC_ BOOL strhaslower(const char *string) -{ - while (*string) { - size_t c_size; - codepoint_t s; - codepoint_t t; - - s = next_codepoint(string, &c_size); - string += c_size; - - t = toupper_w(s); - - if (s != t) { - return True; /* that means it has lower case chars */ - } - } - - return False; -} - -/** - return True if any (multi-byte) character is upper case -*/ -_PUBLIC_ BOOL strhasupper(const char *string) -{ - while (*string) { - size_t c_size; - codepoint_t s; - codepoint_t t; - - s = next_codepoint(string, &c_size); - string += c_size; - - t = tolower_w(s); - - if (s != t) { - return True; /* that means it has upper case chars */ - } - } - - return False; -} - -/** - Convert a string to lower case, allocated with talloc -**/ -_PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) -{ - size_t size=0; - char *dest; - - /* this takes advantage of the fact that upper/lower can't - change the length of a character by more than 1 byte */ - dest = talloc_size(ctx, 2*(strlen(src))+1); - if (dest == NULL) { - return NULL; - } - - while (*src) { - size_t c_size; - codepoint_t c = next_codepoint(src, &c_size); - src += c_size; - - c = tolower_w(c); - - c_size = push_codepoint(dest+size, c); - if (c_size == -1) { - talloc_free(dest); - return NULL; - } - size += c_size; - } - - dest[size] = 0; - - return dest; -} - -/** - Convert a string to UPPER case, allocated with talloc -**/ -_PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) -{ - size_t size=0; - char *dest; - - if (!src) { - return NULL; - } - - /* this takes advantage of the fact that upper/lower can't - change the length of a character by more than 1 byte */ - dest = talloc_size(ctx, 2*(strlen(src))+1); - if (dest == NULL) { - return NULL; - } - - while (*src) { - size_t c_size; - codepoint_t c = next_codepoint(src, &c_size); - src += c_size; - - c = toupper_w(c); - - c_size = push_codepoint(dest+size, c); - if (c_size == -1) { - talloc_free(dest); - return NULL; - } - size += c_size; - } - - dest[size] = 0; - - return dest; -} - -/** - Convert a string to lower case. -**/ -_PUBLIC_ void strlower_m(char *s) -{ - char *d; - - /* this is quite a common operation, so we want it to be - fast. We optimise for the ascii case, knowing that all our - supported multi-byte character sets are ascii-compatible - (ie. they match for the first 128 chars) */ - while (*s && !(((uint8_t)*s) & 0x80)) { - *s = tolower((uint8_t)*s); - s++; - } - - if (!*s) - return; - - d = s; - - while (*s) { - size_t c_size, c_size2; - codepoint_t c = next_codepoint(s, &c_size); - c_size2 = push_codepoint(d, tolower_w(c)); - if (c_size2 > c_size) { - DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strlower_m\n", - c, tolower_w(c), (int)c_size, (int)c_size2)); - smb_panic("codepoint expansion in strlower_m\n"); - } - s += c_size; - d += c_size2; - } - *d = 0; -} - -/** - Convert a string to UPPER case. -**/ -_PUBLIC_ void strupper_m(char *s) -{ - char *d; - - /* this is quite a common operation, so we want it to be - fast. We optimise for the ascii case, knowing that all our - supported multi-byte character sets are ascii-compatible - (ie. they match for the first 128 chars) */ - while (*s && !(((uint8_t)*s) & 0x80)) { - *s = toupper((uint8_t)*s); - s++; - } - - if (!*s) - return; - - d = s; - - while (*s) { - size_t c_size, c_size2; - codepoint_t c = next_codepoint(s, &c_size); - c_size2 = push_codepoint(d, toupper_w(c)); - if (c_size2 > c_size) { - DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strupper_m\n", - c, toupper_w(c), (int)c_size, (int)c_size2)); - smb_panic("codepoint expansion in strupper_m\n"); - } - s += c_size; - d += c_size2; - } - *d = 0; -} - -/** - Count the number of UCS2 characters in a string. Normally this will - be the same as the number of bytes in a string for single byte strings, - but will be different for multibyte. -**/ -_PUBLIC_ size_t strlen_m(const char *s) -{ - size_t count = 0; - - if (!s) { - return 0; - } - - while (*s && !(((uint8_t)*s) & 0x80)) { - s++; - count++; - } - - if (!*s) { - return count; - } - - while (*s) { - size_t c_size; - codepoint_t c = next_codepoint(s, &c_size); - if (c < 0x10000) { - count += 1; - } else { - count += 2; - } - s += c_size; - } - - return count; -} - -/** - Work out the number of multibyte chars in a string, including the NULL - terminator. -**/ -_PUBLIC_ size_t strlen_m_term(const char *s) -{ - if (!s) { - return 0; - } - - return strlen_m(s) + 1; -} /** Unescape a URL encoded string, in place. @@ -991,32 +465,6 @@ _PUBLIC_ void rfc1738_unescape(char *buf) } } -/** - * Decode a base64 string into a DATA_BLOB - simple and slow algorithm - **/ -_PUBLIC_ DATA_BLOB base64_decode_data_blob(TALLOC_CTX *mem_ctx, const char *s) -{ - DATA_BLOB ret = data_blob_talloc(mem_ctx, s, strlen(s)+1); - ret.length = ldb_base64_decode((char *)ret.data); - return ret; -} - -/** - * Decode a base64 string in-place - wrapper for the above - **/ -_PUBLIC_ void base64_decode_inplace(char *s) -{ - ldb_base64_decode(s); -} - -/** - * Encode a base64 string into a talloc()ed string caller to free. - **/ -_PUBLIC_ char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data) -{ - return ldb_base64_encode(mem_ctx, (const char *)data.data, data.length); -} - #ifdef VALGRIND size_t valgrind_strlen(const char *s) { @@ -1274,3 +722,97 @@ _PUBLIC_ BOOL conv_str_u64(const char * str, uint64_t * val) *val = (uint64_t)lval; return True; } + +/** +return the number of bytes occupied by a buffer in CH_UTF16 format +the result includes the null termination +**/ +_PUBLIC_ size_t utf16_len(const void *buf) +{ + size_t len; + + for (len = 0; SVAL(buf,len); len += 2) ; + + return len + 2; +} + +/** +return the number of bytes occupied by a buffer in CH_UTF16 format +the result includes the null termination +limited by 'n' bytes +**/ +_PUBLIC_ size_t utf16_len_n(const void *src, size_t n) +{ + size_t len; + + for (len = 0; (len+2 < n) && SVAL(src, len); len += 2) ; + + if (len+2 <= n) { + len += 2; + } + + return len; +} + +_PUBLIC_ size_t ucs2_align(const void *base_ptr, const void *p, int flags) +{ + if (flags & (STR_NOALIGN|STR_ASCII)) + return 0; + return PTR_DIFF(p, base_ptr) & 1; +} + +/** +Do a case-insensitive, whitespace-ignoring string compare. +**/ +_PUBLIC_ int strwicmp(const char *psz1, const char *psz2) +{ + /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */ + /* appropriate value. */ + if (psz1 == psz2) + return (0); + else if (psz1 == NULL) + return (-1); + else if (psz2 == NULL) + return (1); + + /* sync the strings on first non-whitespace */ + while (1) { + while (isspace((int)*psz1)) + psz1++; + while (isspace((int)*psz2)) + psz2++; + if (toupper((unsigned char)*psz1) != toupper((unsigned char)*psz2) + || *psz1 == '\0' + || *psz2 == '\0') + break; + psz1++; + psz2++; + } + return (*psz1 - *psz2); +} + +/** + String replace. +**/ +_PUBLIC_ void string_replace(char *s, char oldc, char newc) +{ + while (*s) { + s++; + if (*s == oldc) *s = newc; + } +} + +/** + * Compare 2 strings. + * + * @note The comparison is case-insensitive. + **/ +_PUBLIC_ BOOL strequal(const char *s1, const char *s2) +{ + if (s1 == s2) + return(True); + if (!s1 || !s2) + return(False); + + return strcasecmp(s1,s2) == 0; +} diff --git a/source4/lib/util/util_unistr.c b/source4/lib/util/util_unistr.c deleted file mode 100644 index b951ea51ad..0000000000 --- a/source4/lib/util/util_unistr.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba utility functions - Copyright (C) Andrew Tridgell 1992-2001 - Copyright (C) Simo Sorce 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" -#include "system/iconv.h" - -/** - * @file - * @brief Unicode string manipulation - */ - -/* these 2 tables define the unicode case handling. They are loaded - at startup either via mmap() or read() from the lib directory */ -static void *upcase_table; -static void *lowcase_table; - - -/******************************************************************* -load the case handling tables -********************************************************************/ -static void load_case_tables(void) -{ - TALLOC_CTX *mem_ctx; - - mem_ctx = talloc_init("load_case_tables"); - if (!mem_ctx) { - smb_panic("No memory for case_tables"); - } - upcase_table = map_file(data_path(mem_ctx, "upcase.dat"), 0x20000); - lowcase_table = map_file(data_path(mem_ctx, "lowcase.dat"), 0x20000); - talloc_free(mem_ctx); - if (upcase_table == NULL) { - /* try also under codepages for testing purposes */ - upcase_table = map_file("codepages/upcase.dat", 0x20000); - if (upcase_table == NULL) { - upcase_table = (void *)-1; - } - } - if (lowcase_table == NULL) { - /* try also under codepages for testing purposes */ - lowcase_table = map_file("codepages/lowcase.dat", 0x20000); - if (lowcase_table == NULL) { - lowcase_table = (void *)-1; - } - } -} - -/** - Convert a codepoint_t to upper case. -**/ -codepoint_t toupper_w(codepoint_t val) -{ - if (val < 128) { - return toupper(val); - } - if (upcase_table == NULL) { - load_case_tables(); - } - if (upcase_table == (void *)-1) { - return val; - } - if (val & 0xFFFF0000) { - return val; - } - return SVAL(upcase_table, val*2); -} - -/** - Convert a codepoint_t to lower case. -**/ -codepoint_t tolower_w(codepoint_t val) -{ - if (val < 128) { - return tolower(val); - } - if (lowcase_table == NULL) { - load_case_tables(); - } - if (lowcase_table == (void *)-1) { - return val; - } - if (val & 0xFFFF0000) { - return val; - } - return SVAL(lowcase_table, val*2); -} - -/** -return the number of bytes occupied by a buffer in CH_UTF16 format -the result includes the null termination -**/ -size_t utf16_len(const void *buf) -{ - size_t len; - - for (len = 0; SVAL(buf,len); len += 2) ; - - return len + 2; -} - -/** -return the number of bytes occupied by a buffer in CH_UTF16 format -the result includes the null termination -limited by 'n' bytes -**/ -size_t utf16_len_n(const void *src, size_t n) -{ - size_t len; - - for (len = 0; (len+2 < n) && SVAL(src, len); len += 2) ; - - if (len+2 <= n) { - len += 2; - } - - return len; -} - - -size_t ucs2_align(const void *base_ptr, const void *p, int flags) -{ - if (flags & (STR_NOALIGN|STR_ASCII)) - return 0; - return PTR_DIFF(p, base_ptr) & 1; -} - -/** - compare two codepoints case insensitively -*/ -int codepoint_cmpi(codepoint_t c1, codepoint_t c2) -{ - if (c1 == c2 || - toupper_w(c1) == toupper_w(c2)) { - return 0; - } - return c1 - c2; -} -- cgit From 620d759f49f4b648d0fa4a84e67f1cecbbdd0f06 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 27 Apr 2006 19:50:13 +0000 Subject: r15298: Fix the build using a few hacks in the build system. Recursive dependencies are now forbidden (the build system will bail out if there are any). I've split up auth_sam.c into auth_sam.c and sam.c. Andrew, please rename sam.c / move its contents to whatever/wherever you think suits best. (This used to be commit 6646384aaf3e7fa2aa798c3e564b94b0617ec4d0) --- source4/lib/util/util_str.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 9de27c0777..60419e0510 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -81,15 +81,15 @@ _PUBLIC_ size_t count_chars(const char *s, char c) size_t count = 0; while (*s) { - size_t size; - codepoint_t c2 = next_codepoint(s, &size); - if (c2 == c) count++; - s += size; + if (*s == c) count++; + s ++; } return count; } + + /** Safe string copy into a known length string. maxlength does not include the terminating zero. @@ -433,12 +433,12 @@ _PUBLIC_ void rfc1738_unescape(char *buf) { char *p=buf; - while ((p=strchr_m(p,'+'))) + while ((p=strchr(p,'+'))) *p = ' '; p = buf; - while (p && *p && (p=strchr_m(p,'%'))) { + while (p && *p && (p=strchr(p,'%'))) { int c1 = p[1]; int c2 = p[2]; -- cgit From eaaae31d1105a7abe31918c59ae9bfab0010bb51 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 27 Apr 2006 22:59:20 +0000 Subject: r15302: Remove strangely named function "StrnCpy" - strlcpy is available as a replacement. (This used to be commit 72237344cf22dacfaf1d87c3e0b922023fa4afb0) --- source4/lib/util/util_str.c | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 60419e0510..34d37ecfbd 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -171,27 +171,6 @@ _PUBLIC_ char *safe_strcat(char *dest, const char *src, size_t maxlength) return dest; } -/** - Like strncpy but always null terminates. Make sure there is room! - The variable n should always be one less than the available size. -**/ - -_PUBLIC_ char *StrnCpy(char *dest,const char *src,size_t n) -{ - char *d = dest; - if (!dest) - return(NULL); - if (!src) { - *dest = 0; - return(dest); - } - while (n-- && (*d++ = *src++)) - ; - *d = 0; - return(dest); -} - - /** Routine to get hex characters and turn them into a 16 byte array. the array can be variable length, and any non-hex-numeric -- cgit From b4246a73537258bedbec63e37cb120a7d7ebafa8 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 29 Apr 2006 09:11:07 +0000 Subject: r15316: I don't understand quite why this function was ever like this, but we need to replace every instance of the character. Previously we skipped the first. Andrew Bartlett (This used to be commit 5b58ab98d6b47b7cfd47eb5f7d38dc3724e44ca2) --- source4/lib/util/util_str.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 34d37ecfbd..df9fd44cd6 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -775,8 +775,7 @@ _PUBLIC_ int strwicmp(const char *psz1, const char *psz2) **/ _PUBLIC_ void string_replace(char *s, char oldc, char newc) { - while (*s) { - s++; + for (;s && *s; s++) { if (*s == oldc) *s = newc; } } -- cgit From a3b8cfbc8f5b18a342dee79fd9928cbcc2fbb025 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 29 Apr 2006 11:32:54 +0000 Subject: r15318: Don't create empty static libraries as some hosts have trouble with them. (This used to be commit 1505d7c6001f8a35e728a14af2885b813c32ebe7) --- source4/lib/util/util_str.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index df9fd44cd6..ec6a1cbbea 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -775,8 +775,9 @@ _PUBLIC_ int strwicmp(const char *psz1, const char *psz2) **/ _PUBLIC_ void string_replace(char *s, char oldc, char newc) { - for (;s && *s; s++) { + while (*s) { if (*s == oldc) *s = newc; + s++; } } -- cgit From f4e403440a08f5da3328bbbe5601967bf8705137 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 30 Apr 2006 01:32:59 +0000 Subject: r15349: Integrate set_socket_options() into the socket library (This used to be commit 598ea173cd718dad0df24505796ca50cb728a2e9) --- source4/lib/util/config.mk | 1 - source4/lib/util/util_sock.c | 133 ------------------------------------------- 2 files changed, 134 deletions(-) delete mode 100644 source4/lib/util/util_sock.c (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 267d7fdbc1..a14ffb5f79 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -22,7 +22,6 @@ OBJ_FILES = xfile.o \ util_file.o \ data_blob.o \ util.o \ - util_sock.o \ substitute.o \ fsusage.o \ ms_fnmatch.o \ diff --git a/source4/lib/util/util_sock.c b/source4/lib/util/util_sock.c deleted file mode 100644 index 28a15066b8..0000000000 --- a/source4/lib/util/util_sock.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba utility functions - Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) Tim Potter 2000-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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" -#include "system/network.h" - -/** - * @file - * @brief Socket utility functions - */ - -enum SOCK_OPT_TYPES {OPT_BOOL,OPT_INT,OPT_ON}; - -static const struct { - const char *name; - int level; - int option; - int value; - int opttype; -} socket_options[] = { - {"SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, 0, OPT_BOOL}, - {"SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, 0, OPT_BOOL}, - {"SO_BROADCAST", SOL_SOCKET, SO_BROADCAST, 0, OPT_BOOL}, -#ifdef TCP_NODELAY - {"TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY, 0, OPT_BOOL}, -#endif -#ifdef IPTOS_LOWDELAY - {"IPTOS_LOWDELAY", IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY, OPT_ON}, -#endif -#ifdef IPTOS_THROUGHPUT - {"IPTOS_THROUGHPUT", IPPROTO_IP, IP_TOS, IPTOS_THROUGHPUT, OPT_ON}, -#endif -#ifdef SO_REUSEPORT - {"SO_REUSEPORT", SOL_SOCKET, SO_REUSEPORT, 0, OPT_BOOL}, -#endif -#ifdef SO_SNDBUF - {"SO_SNDBUF", SOL_SOCKET, SO_SNDBUF, 0, OPT_INT}, -#endif -#ifdef SO_RCVBUF - {"SO_RCVBUF", SOL_SOCKET, SO_RCVBUF, 0, OPT_INT}, -#endif -#ifdef SO_SNDLOWAT - {"SO_SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT, 0, OPT_INT}, -#endif -#ifdef SO_RCVLOWAT - {"SO_RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT, 0, OPT_INT}, -#endif -#ifdef SO_SNDTIMEO - {"SO_SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO, 0, OPT_INT}, -#endif -#ifdef SO_RCVTIMEO - {"SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, 0, OPT_INT}, -#endif - {NULL,0,0,0,0}}; - - -/** - Set user socket options. -**/ -_PUBLIC_ void set_socket_options(int fd, const char *options) -{ - const char **options_list = str_list_make(NULL, options, " \t,"); - int j; - - if (!options_list) - return; - - for (j = 0; options_list[j]; j++) { - const char *tok = options_list[j]; - int ret=0,i; - int value = 1; - char *p; - BOOL got_value = False; - - if ((p = strchr(tok,'='))) { - *p = 0; - value = atoi(p+1); - got_value = True; - } - - for (i=0;socket_options[i].name;i++) - if (strequal(socket_options[i].name,tok)) - break; - - if (!socket_options[i].name) { - DEBUG(0,("Unknown socket option %s\n",tok)); - continue; - } - - switch (socket_options[i].opttype) { - case OPT_BOOL: - case OPT_INT: - ret = setsockopt(fd,socket_options[i].level, - socket_options[i].option,(char *)&value,sizeof(int)); - break; - - case OPT_ON: - if (got_value) - DEBUG(0,("syntax error - %s does not take a value\n",tok)); - - { - int on = socket_options[i].value; - ret = setsockopt(fd,socket_options[i].level, - socket_options[i].option,(char *)&on,sizeof(int)); - } - break; - } - - if (ret != 0) - DEBUG(0,("Failed to set socket option %s (Error %s)\n",tok, strerror(errno) )); - } - - talloc_free(options_list); -} - -- cgit From a4a2a4b833e7738db2282b3e5a37bc59fc0983dc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 1 May 2006 13:39:36 +0000 Subject: r15376: Add detection of -lnsl, required for building on SUN boxes. (This used to be commit 49bac12767ca59095ad6609a3826f7f17ddb601c) --- source4/lib/util/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index a14ffb5f79..4e00e2d7e2 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -31,7 +31,7 @@ OBJ_FILES = xfile.o \ module.o PUBLIC_DEPENDENCIES = \ LIBREPLACE LIBCRYPTO DL LIBTALLOC \ - SOCKET_WRAPPER + SOCKET_WRAPPER EXT_NSL [SUBSYSTEM::PIDFILE] PRIVATE_PROTO_HEADER = pidfile.h -- cgit From 66a4c270d49bc3807b547ff17423b9d661eb3983 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 1 May 2006 14:33:48 +0000 Subject: r15377: Remove sys_select() code as it's no longer used. (This used to be commit 68004f68a364ce826ed8cbed0977e631ca60594d) --- source4/lib/util/config.mk | 1 - source4/lib/util/select.c | 169 --------------------------------------------- 2 files changed, 170 deletions(-) delete mode 100644 source4/lib/util/select.c (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 4e00e2d7e2..312653c19f 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -25,7 +25,6 @@ OBJ_FILES = xfile.o \ substitute.o \ fsusage.o \ ms_fnmatch.o \ - select.o \ mutex.o \ idtree.o \ module.o diff --git a/source4/lib/util/select.c b/source4/lib/util/select.c deleted file mode 100644 index 4f906f2454..0000000000 --- a/source4/lib/util/select.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - Unix SMB/Netbios implementation. - Version 3.0 - Samba select/poll implementation - Copyright (C) Andrew Tridgell 1992-1998 - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" -#include "system/filesys.h" - -/* This is here because it allows us to avoid a nasty race in signal handling. - We need to guarantee that when we get a signal we get out of a select immediately - but doing that involves a race condition. We can avoid the race by getting the - signal handler to write to a pipe that is in the select/poll list - - This means all Samba signal handlers should call sys_select_signal(). -*/ - -static pid_t initialised; -static int select_pipe[2]; -static volatile unsigned pipe_written, pipe_read; - -/******************************************************************* - Call this from all Samba signal handlers if you want to avoid a - nasty signal race condition. -********************************************************************/ - -void sys_select_signal(void) -{ - char c = 1; - if (!initialised) return; - - if (pipe_written > pipe_read+256) return; - - if (write(select_pipe[1], &c, 1) == 1) pipe_written++; -} - -/******************************************************************* - Like select() but avoids the signal race using a pipe - it also guarantees that fds on return only ever contains bits set - for file descriptors that were readable. -********************************************************************/ - -int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval) -{ - int ret, saved_errno; - fd_set *readfds2, readfds_buf; - - if (initialised != getpid()) { - pipe(select_pipe); - - /* - * These next two lines seem to fix a bug with the Linux - * 2.0.x kernel (and probably other UNIXes as well) where - * the one byte read below can block even though the - * select returned that there is data in the pipe and - * the pipe_written variable was incremented. Thanks to - * HP for finding this one. JRA. - */ - - if(set_blocking(select_pipe[0],0)==-1) - smb_panic("select_pipe[0]: O_NONBLOCK failed.\n"); - if(set_blocking(select_pipe[1],0)==-1) - smb_panic("select_pipe[1]: O_NONBLOCK failed.\n"); - - initialised = getpid(); - } - - maxfd = MAX(select_pipe[0]+1, maxfd); - - /* If readfds is NULL we need to provide our own set. */ - if (readfds) { - readfds2 = readfds; - } else { - readfds2 = &readfds_buf; - FD_ZERO(readfds2); - } - FD_SET(select_pipe[0], readfds2); - - errno = 0; - ret = select(maxfd,readfds2,writefds,errorfds,tval); - - if (ret <= 0) { - FD_ZERO(readfds2); - if (writefds) - FD_ZERO(writefds); - if (errorfds) - FD_ZERO(errorfds); - } else if (FD_ISSET(select_pipe[0], readfds2)) { - char c; - saved_errno = errno; - if (read(select_pipe[0], &c, 1) == 1) { - pipe_read++; - /* Mark Weaver pointed out a critical - fix to ensure we don't lose signals. We must always - return -1 when the select pipe is set, otherwise if another - fd is also ready (so ret == 2) then we used to eat the - byte in the pipe and lose the signal. JRA. - */ - ret = -1; - errno = EINTR; - } else { - FD_CLR(select_pipe[0], readfds2); - ret--; - errno = saved_errno; - } - } - - return ret; -} - -/******************************************************************* - Similar to sys_select() but catch EINTR and continue. - This is what sys_select() used to do in Samba. -********************************************************************/ - -int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval) -{ - int ret; - fd_set *readfds2, readfds_buf, *writefds2, writefds_buf, *errorfds2, errorfds_buf; - struct timeval tval2, *ptval; - - readfds2 = (readfds ? &readfds_buf : NULL); - writefds2 = (writefds ? &writefds_buf : NULL); - errorfds2 = (errorfds ? &errorfds_buf : NULL); - ptval = (tval ? &tval2 : NULL); - - do { - if (readfds) - readfds_buf = *readfds; - if (writefds) - writefds_buf = *writefds; - if (errorfds) - errorfds_buf = *errorfds; - if (tval) - tval2 = *tval; - - /* We must use select and not sys_select here. If we use - sys_select we'd lose the fact a signal occurred when sys_select - read a byte from the pipe. Fix from Mark Weaver - - */ - - ret = select(maxfd, readfds2, writefds2, errorfds2, ptval); - } while (ret == -1 && errno == EINTR); - - if (readfds) - *readfds = readfds_buf; - if (writefds) - *writefds = writefds_buf; - if (errorfds) - *errorfds = errorfds_buf; - - return ret; -} -- cgit From b56789c3491d227dd4107a37de701101c780a0f9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 5 May 2006 13:02:14 +0000 Subject: r15457: Get rid of more usages of uint_t (This used to be commit 849818dcdeb8eaf2eb22fea3896a4f7c777d8c5f) --- source4/lib/util/time.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/time.c b/source4/lib/util/time.c index 4897d2fa95..6ad3a229e3 100644 --- a/source4/lib/util/time.c +++ b/source4/lib/util/time.c @@ -139,7 +139,7 @@ _PUBLIC_ BOOL null_nttime(NTTIME t) static uint16_t make_dos_date1(struct tm *t) { uint16_t ret=0; - ret = (((uint_t)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1); + ret = (((unsigned int)(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; } @@ -150,7 +150,7 @@ static uint16_t make_dos_date1(struct tm *t) static uint16_t make_dos_time1(struct tm *t) { uint16_t ret=0; - ret = ((((uint_t)t->tm_min >> 3)&0x7) | (((uint_t)t->tm_hour) << 3)); + ret = ((((unsigned int)t->tm_min >> 3)&0x7) | (((unsigned int)t->tm_hour) << 3)); ret = ((ret&0xFF)<<8) | ((t->tm_sec/2) | ((t->tm_min & 0x7) << 5)); return ret; } @@ -440,7 +440,7 @@ _PUBLIC_ struct timeval timeval_add(const struct timeval *tv, uint32_t secs, uint32_t usecs) { struct timeval tv2 = *tv; - const uint_t million = 1000000; + const unsigned int million = 1000000; tv2.tv_sec += secs; tv2.tv_usec += usecs; tv2.tv_sec += tv2.tv_usec / million; -- cgit From 962039a81ce715a9b74d5790b418a22965e2dddd Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 13 May 2006 12:57:14 +0000 Subject: r15564: Fix copyrights (this file was originally based on just a few lines from smb.h) (This used to be commit 045bd55dd992f054606ffacae1580afb817b1e33) --- source4/lib/util/util.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 383323b5ed..f1a6fc4c30 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -2,9 +2,7 @@ Unix SMB/CIFS implementation. Utility functions for Samba Copyright (C) Andrew Tridgell 1992-1999 - Copyright (C) John H Terpstra 1996-1999 - Copyright (C) Luke Kenneth Casson Leighton 1996-1999 - Copyright (C) Paul Ashton 1998 - 1999 + Copyright (C) Jelmer Vernooij 2005 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 -- cgit From 53f005f6aaa2aa2eb599e6787e2c700a1d44d2a2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 13 May 2006 18:12:53 +0000 Subject: r15572: Trim build/m4/rewrite.m4 a bit more, remove unused tests. (This used to be commit d72c5c8f755277eb22e1f6834d98202f00c09934) --- source4/lib/util/capability.c | 12 ------------ source4/lib/util/fault.m4 | 2 ++ source4/lib/util/signal.m4 | 1 + source4/lib/util/util.m4 | 1 + 4 files changed, 4 insertions(+), 12 deletions(-) create mode 100644 source4/lib/util/fault.m4 create mode 100644 source4/lib/util/signal.m4 create mode 100644 source4/lib/util/util.m4 (limited to 'source4/lib/util') diff --git a/source4/lib/util/capability.c b/source4/lib/util/capability.c index 683bc99723..7d8222fe11 100644 --- a/source4/lib/util/capability.c +++ b/source4/lib/util/capability.c @@ -102,15 +102,3 @@ static BOOL set_inherited_process_capability( uint32_t cap_flag, BOOL enable ) return True; } #endif - -/** - Gain the oplock capability from the kernel if possible. -**/ - -_PUBLIC_ void oplock_set_capability(BOOL this_process, BOOL inherit) -{ -#if HAVE_KERNEL_OPLOCKS_IRIX - set_process_capability(KERNEL_OPLOCK_CAPABILITY,this_process); - set_inherited_process_capability(KERNEL_OPLOCK_CAPABILITY,inherit); -#endif -} diff --git a/source4/lib/util/fault.m4 b/source4/lib/util/fault.m4 new file mode 100644 index 0000000000..6d2c4f2a6a --- /dev/null +++ b/source4/lib/util/fault.m4 @@ -0,0 +1,2 @@ +AC_CHECK_HEADER(execinfo.h) +AC_CHECK_FUNCS(backtrace) diff --git a/source4/lib/util/signal.m4 b/source4/lib/util/signal.m4 new file mode 100644 index 0000000000..c6d7f72f68 --- /dev/null +++ b/source4/lib/util/signal.m4 @@ -0,0 +1 @@ +AC_CHECK_FUNCS(sigprocmask sigblock sigaction) diff --git a/source4/lib/util/util.m4 b/source4/lib/util/util.m4 new file mode 100644 index 0000000000..9e362954cd --- /dev/null +++ b/source4/lib/util/util.m4 @@ -0,0 +1 @@ +AC_CHECK_FUNCS(setsid) -- cgit From 172a83d72491f90f6191be1040ef8b2e1789bd2e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 13 May 2006 19:14:12 +0000 Subject: r15573: Fix build of systems that have iconv headers in non-standard locations Split of system/locale.h header from system/iconv.h Previously, iconv wasn't being used on these systems (This used to be commit aa6d66fda69779d1c2948a1aca85dbd5208f1cba) --- source4/lib/util/genrand.c | 2 +- source4/lib/util/util.c | 2 +- source4/lib/util/util_str.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/genrand.c b/source4/lib/util/genrand.c index 5bdf1f7e08..8424ad8fd7 100644 --- a/source4/lib/util/genrand.c +++ b/source4/lib/util/genrand.c @@ -21,9 +21,9 @@ */ #include "includes.h" -#include "system/iconv.h" #include "system/filesys.h" #include "lib/crypto/crypto.h" +#include "system/locale.h" /** * @file diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index c674ed23b4..5948cd7ecb 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -24,8 +24,8 @@ #include "includes.h" #include "system/network.h" -#include "system/iconv.h" #include "system/filesys.h" +#include "system/locale.h" /** * @file diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index ec6a1cbbea..62869198c3 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -26,7 +26,7 @@ #include "smb.h" #include "pstring.h" #include "lib/ldb/include/ldb.h" -#include "system/iconv.h" +#include "system/locale.h" /** * @file -- cgit From 971d30bb201f5c3faff5f575d26882eb79f7955a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 May 2006 07:34:11 +0000 Subject: r15854: more talloc_set_destructor() typesafe fixes (This used to be commit 61c6100617589ac6df4f527877241464cacbf8b3) --- source4/lib/util/unix_privs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/unix_privs.c b/source4/lib/util/unix_privs.c index c94cf619a3..bf3e61ba2d 100644 --- a/source4/lib/util/unix_privs.c +++ b/source4/lib/util/unix_privs.c @@ -49,9 +49,8 @@ struct saved_state { uid_t uid; }; -static int privileges_destructor(void *ptr) +static int privileges_destructor(struct saved_state *s) { - struct saved_state *s = ptr; if (geteuid() != s->uid && seteuid(s->uid) != 0) { smb_panic("Failed to restore privileges"); -- cgit From ca62ddd8d901cce923d1cda958793054f80b1f57 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 5 Jun 2006 21:48:29 +0000 Subject: r16051: Move the XATTR compatability code into a new file, so I can use it for the getntacl utility. Andrew Bartlett (This used to be commit b1e0d4747b412929e1d4e24d6d9e504df3ddc824) --- source4/lib/util/config.mk | 11 ++++ source4/lib/util/wrap_xattr.c | 121 ++++++++++++++++++++++++++++++++++++++++++ source4/lib/util/wrap_xattr.h | 25 +++++++++ 3 files changed, 157 insertions(+) create mode 100644 source4/lib/util/wrap_xattr.c create mode 100644 source4/lib/util/wrap_xattr.h (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 312653c19f..84598be4d0 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -39,3 +39,14 @@ OBJ_FILES = pidfile.o [SUBSYSTEM::UNIX_PRIVS] PRIVATE_PROTO_HEADER = unix_privs.h OBJ_FILES = unix_privs.o + +################################################ +# Start SUBSYSTEM WRAP_XATTR +[SUBSYSTEM::WRAP_XATTR] +PUBLIC_PROTO_HEADER = wrap_xattr.h +OBJ_FILES = \ + wrap_xattr.o +PUBLIC_DEPENDENCIES = XATTR +# +# End SUBSYSTEM WRAP_XATTR +################################################ diff --git a/source4/lib/util/wrap_xattr.c b/source4/lib/util/wrap_xattr.c new file mode 100644 index 0000000000..21c8f90635 --- /dev/null +++ b/source4/lib/util/wrap_xattr.c @@ -0,0 +1,121 @@ +/* + Unix SMB/CIFS implementation. + + POSIX NTVFS backend - xattr support using filesystem xattrs + + Copyright (C) Andrew Tridgell 2004 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/filesys.h" +#include "wrap_xattr.h" + +#if defined(HAVE_XATTR_SUPPORT) && defined(XATTR_ADDITIONAL_OPTIONS) +static ssize_t _wrap_darwin_fgetxattr(int fd, const char *name, void *value, size_t size) +{ + return fgetxattr(fd, name, value, size, 0, 0); +} +static ssize_t _wrap_darwin_getxattr(const char *path, const char *name, void *value, size_t size) +{ + return getxattr(path, name, value, size, 0, 0); +} +static int _wrap_darwin_fsetxattr(int fd, const char *name, void *value, size_t size, int flags) +{ + return fsetxattr(fd, name, value, size, 0, flags); +} +static int _wrap_darwin_setxattr(const char *path, const char *name, void *value, size_t size, int flags) +{ + return setxattr(path, name, value, size, 0, flags); +} +static int _wrap_darwin_fremovexattr(int fd, const char *name) +{ + return fremovexattr(fd, name, 0); +} +static int _wrap_darwin_removexattr(const char *path, const char *name) +{ + return removexattr(path, name, 0); +} +#define fgetxattr _wrap_darwin_fgetxattr +#define getxattr _wrap_darwin_getxattr +#define fsetxattr _wrap_darwin_fsetxattr +#define setxattr _wrap_darwin_setxattr +#define fremovexattr _wrap_darwin_fremovexattr +#define removexattr _wrap_darwin_removexattr +#elif !defined(HAVE_XATTR_SUPPORT) +static ssize_t _none_fgetxattr(int fd, const char *name, void *value, size_t size) +{ + errno = ENOSYS; + return -1; +} +static ssize_t _none_getxattr(const char *path, const char *name, void *value, size_t size) +{ + errno = ENOSYS; + return -1; +} +static int _none_fsetxattr(int fd, const char *name, void *value, size_t size, int flags) +{ + errno = ENOSYS; + return -1; +} +static int _none_setxattr(const char *path, const char *name, void *value, size_t size, int flags) +{ + errno = ENOSYS; + return -1; +} +static int _none_fremovexattr(int fd, const char *name) +{ + errno = ENOSYS; + return -1; +} +static int _none_removexattr(const char *path, const char *name) +{ + errno = ENOSYS; + return -1; +} +#define fgetxattr _none_fgetxattr +#define getxattr _none_getxattr +#define fsetxattr _none_fsetxattr +#define setxattr _none_setxattr +#define fremovexattr _none_fremovexattr +#define removexattr _none_removexattr +#endif + +_PUBLIC_ ssize_t wrap_fgetxattr(int fd, const char *name, void *value, size_t size) +{ + return fgetxattr(fd, name, value, size); +} +_PUBLIC_ ssize_t wrap_getxattr(const char *path, const char *name, void *value, size_t size) +{ + return getxattr(path, name, value, size); +} +_PUBLIC_ int wrap_fsetxattr(int fd, const char *name, void *value, size_t size, int flags) +{ + return fsetxattr(fd, name, value, size, flags); +} +_PUBLIC_ int wrap_setxattr(const char *path, const char *name, void *value, size_t size, int flags) +{ + return setxattr(path, name, value, size, flags); +} +_PUBLIC_ int wrap_fremovexattr(int fd, const char *name) +{ + return fremovexattr(fd, name); +} +_PUBLIC_ int wrap_removexattr(const char *path, const char *name) +{ + return removexattr(path, name); +} + diff --git a/source4/lib/util/wrap_xattr.h b/source4/lib/util/wrap_xattr.h new file mode 100644 index 0000000000..58f920704b --- /dev/null +++ b/source4/lib/util/wrap_xattr.h @@ -0,0 +1,25 @@ +#ifndef __LIB_UTIL_WRAP_XATTR_H__ +#define __LIB_UTIL_WRAP_XATTR_H__ + +#undef _PRINTF_ATTRIBUTE +#define _PRINTF_ATTRIBUTE(a1, a2) PRINTF_ATTRIBUTE(a1, a2) +/* This file was automatically generated by mkproto.pl. DO NOT EDIT */ + +#ifndef _PUBLIC_ +#define _PUBLIC_ +#endif + + +/* The following definitions come from lib/util/wrap_xattr.c */ + +_PUBLIC_ ssize_t wrap_fgetxattr(int fd, const char *name, void *value, size_t size); +_PUBLIC_ ssize_t wrap_getxattr(const char *path, const char *name, void *value, size_t size); +_PUBLIC_ int wrap_fsetxattr(int fd, const char *name, void *value, size_t size, int flags); +_PUBLIC_ int wrap_setxattr(const char *path, const char *name, void *value, size_t size, int flags); +_PUBLIC_ int wrap_fremovexattr(int fd, const char *name); +_PUBLIC_ int wrap_removexattr(const char *path, const char *name); +#undef _PRINTF_ATTRIBUTE +#define _PRINTF_ATTRIBUTE(a1, a2) + +#endif /* __LIB_UTIL_WRAP_XATTR_H__ */ + -- cgit From d70d6727dd1d7c4ae9dd897d23864665476b3884 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 5 Jun 2006 21:51:10 +0000 Subject: r16052: Add .m4 file for XATTR detection (from ntvfs/posix/config.m4) Andrew Bartlett (This used to be commit 9a9c2bc4aaa4afc947fb490f48bf037e03d2f223) --- source4/lib/util/xattr.m4 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 source4/lib/util/xattr.m4 (limited to 'source4/lib/util') diff --git a/source4/lib/util/xattr.m4 b/source4/lib/util/xattr.m4 new file mode 100644 index 0000000000..497809a47a --- /dev/null +++ b/source4/lib/util/xattr.m4 @@ -0,0 +1,32 @@ +dnl ############################################ +dnl use flistxattr as the key function for having +dnl sufficient xattr support for posix xattr backend +AC_CHECK_HEADERS(sys/attributes.h attr/xattr.h sys/xattr.h) +AC_SEARCH_LIBS_EXT(flistxattr, [attr], XATTR_LIBS) +AC_CHECK_FUNC_EXT(flistxattr, $XATTR_LIBS) +SMB_EXT_LIB(XATTR,[${XATTR_LIBS}],[${XATTR_CFLAGS}],[${XATTR_CPPFLAGS}],[${XATTR_LDFLAGS}]) +if test x"$ac_cv_func_ext_flistxattr" = x"yes"; then + AC_CACHE_CHECK([whether xattr interface takes additional options], smb_attr_cv_xattr_add_opt, + [old_LIBS=$LIBS + LIBS="$LIBS $XATTRLIBS" + AC_TRY_COMPILE([ + #include + #if HAVE_ATTR_XATTR_H + #include + #elif HAVE_SYS_XATTR_H + #include + #endif + #ifndef NULL + #define NULL ((void *)0) + #endif + ],[ + getxattr(NULL, NULL, NULL, 0, 0, 0); + ],smb_attr_cv_xattr_add_opt=yes,smb_attr_cv_xattr_add_opt=no) + LIBS=$old_LIBS]) + if test x"$smb_attr_cv_xattr_add_opt" = x"yes"; then + AC_DEFINE(XATTR_ADDITIONAL_OPTIONS, 1, [xattr functions have additional options]) + fi + AC_DEFINE(HAVE_XATTR_SUPPORT,1,[Whether we have xattr support]) + SMB_ENABLE(XATTR,YES) +fi + -- cgit From fdc5a3aeb5558bb52d59eb5cb4624cd4505c8ce3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 13 Jun 2006 10:21:52 +0000 Subject: r16185: Remove autogenerated file from SVN. (This used to be commit a975f11d452deb2c5e06b8ba02f528b08d2842e1) --- source4/lib/util/wrap_xattr.h | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 source4/lib/util/wrap_xattr.h (limited to 'source4/lib/util') diff --git a/source4/lib/util/wrap_xattr.h b/source4/lib/util/wrap_xattr.h deleted file mode 100644 index 58f920704b..0000000000 --- a/source4/lib/util/wrap_xattr.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __LIB_UTIL_WRAP_XATTR_H__ -#define __LIB_UTIL_WRAP_XATTR_H__ - -#undef _PRINTF_ATTRIBUTE -#define _PRINTF_ATTRIBUTE(a1, a2) PRINTF_ATTRIBUTE(a1, a2) -/* This file was automatically generated by mkproto.pl. DO NOT EDIT */ - -#ifndef _PUBLIC_ -#define _PUBLIC_ -#endif - - -/* The following definitions come from lib/util/wrap_xattr.c */ - -_PUBLIC_ ssize_t wrap_fgetxattr(int fd, const char *name, void *value, size_t size); -_PUBLIC_ ssize_t wrap_getxattr(const char *path, const char *name, void *value, size_t size); -_PUBLIC_ int wrap_fsetxattr(int fd, const char *name, void *value, size_t size, int flags); -_PUBLIC_ int wrap_setxattr(const char *path, const char *name, void *value, size_t size, int flags); -_PUBLIC_ int wrap_fremovexattr(int fd, const char *name); -_PUBLIC_ int wrap_removexattr(const char *path, const char *name); -#undef _PRINTF_ATTRIBUTE -#define _PRINTF_ATTRIBUTE(a1, a2) - -#endif /* __LIB_UTIL_WRAP_XATTR_H__ */ - -- cgit From a64980dd4008ba5e13d81374ee3f3073e875c33f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 13 Jun 2006 10:47:08 +0000 Subject: r16186: Use full include path to make sure it's being picked up by the dependency generator. (This used to be commit fbbc3b11683d594d31e6487873946b68c2c46923) --- source4/lib/util/wrap_xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/wrap_xattr.c b/source4/lib/util/wrap_xattr.c index 21c8f90635..4e4470839e 100644 --- a/source4/lib/util/wrap_xattr.c +++ b/source4/lib/util/wrap_xattr.c @@ -22,7 +22,7 @@ #include "includes.h" #include "system/filesys.h" -#include "wrap_xattr.h" +#include "lib/util/wrap_xattr.h" #if defined(HAVE_XATTR_SUPPORT) && defined(XATTR_ADDITIONAL_OPTIONS) static ssize_t _wrap_darwin_fgetxattr(int fd, const char *name, void *value, size_t size) -- cgit From 4bd40183afd6d423ccbe5f43dac83bd299f86c50 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 Jun 2006 11:23:06 +0000 Subject: r16516: Get rid of file_exists() as there already is a file_exist(). (This used to be commit c4b3c2b18c6df43c8a4808fab72bc45439ba9421) --- source4/lib/util/util_file.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index 8d8e7c6ec9..99432ad8bb 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -356,15 +356,6 @@ _PUBLIC_ BOOL file_save(const char *fname, const void *packet, size_t length) return True; } -/** - see if a file exists -*/ -_PUBLIC_ BOOL file_exists(const char *path) -{ - struct stat st; - return (stat(path, &st) == 0); -} - _PUBLIC_ int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) { char *p; -- cgit From 9bd4cfad47b8b2e1e60a49478c92cf8490802a18 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 Jun 2006 11:29:48 +0000 Subject: r16517: Get rid of pointless safe_free() (not SAFE_FREE()!) function. (This used to be commit 6bc91497827a66af6d9adf26c689e9cc458d8ecf) --- source4/lib/util/util.c | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index 5948cd7ecb..33215a81fb 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -253,19 +253,6 @@ _PUBLIC_ void become_daemon(BOOL Fork) attach it to the logfile */ } - -/** - Free memory, checks for NULL. - Use directly SAFE_FREE() - Exists only because we need to pass a function pointer somewhere --SSS -**/ - -_PUBLIC_ void safe_free(void *p) -{ - SAFE_FREE(p); -} - - /** Get my own name, return in malloc'ed storage. **/ -- cgit From ec2b3baf09ebff97bc958e73591e128f14c7a378 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 10 Jul 2006 16:47:47 +0000 Subject: r16922: move some macros out of talloc.h as the don't belong to talloc metze (This used to be commit 4c68e315e2288eef97527911daf18622a994ac31) --- source4/lib/util/util.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index f1a6fc4c30..2517966d90 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -100,6 +100,10 @@ extern const char *panic_action; */ #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count) +#define data_blob(ptr, size) data_blob_named(ptr, size, "DATA_BLOB: "__location__) +#define data_blob_talloc(ctx, ptr, size) data_blob_talloc_named(ctx, ptr, size, "DATA_BLOB: "__location__) +#define data_blob_dup_talloc(ctx, blob) data_blob_talloc_named(ctx, (blob)->data, (blob)->length, "DATA_BLOB: "__location__) + #if defined(VALGRIND) #define strlen(x) valgrind_strlen(x) #endif -- cgit From 54fba07f0183d2e45eaf8658f2900445a312524d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 10 Jul 2006 18:15:24 +0000 Subject: r16923: remove unused substitude code metze (This used to be commit ea88c8c99eff2203d13f9877e590d9d7f2fbb910) --- source4/lib/util/config.mk | 1 - source4/lib/util/substitute.c | 170 ------------------------------------------ 2 files changed, 171 deletions(-) delete mode 100644 source4/lib/util/substitute.c (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 84598be4d0..cc3b1930c5 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -22,7 +22,6 @@ OBJ_FILES = xfile.o \ util_file.o \ data_blob.o \ util.o \ - substitute.o \ fsusage.o \ ms_fnmatch.o \ mutex.o \ diff --git a/source4/lib/util/substitute.c b/source4/lib/util/substitute.c deleted file mode 100644 index 2e55a7befb..0000000000 --- a/source4/lib/util/substitute.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - Unix SMB/CIFS implementation. - string substitution functions - Copyright (C) Andrew Tridgell 1992-2000 - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - - -#include "includes.h" -#include "smb_server/smb_server.h" - -/** - * @file - * @brief Substitution handling - */ - -/* oh bugger - I really didn't want to have a top-level context - anywhere, but until we change all lp_*() calls to take a context - argument this is needed */ -static struct substitute_context *sub; - -_PUBLIC_ void sub_set_context(struct substitute_context *subptr) -{ - sub = subptr; -} - -/* - setup a string in the negotiate structure, using alpha_strcpy with SAFE_NETBIOS_CHARS -*/ -static void setup_string(char **dest, const char *str) -{ -#define SAFE_NETBIOS_CHARS ". -_" - char *s; - - s = strdup(str); - if (!s) { - return; - } - - alpha_strcpy(s, str, SAFE_NETBIOS_CHARS, strlen(s)+1); - - trim_string(s," "," "); - strlower(s); - - SAFE_FREE(*dest); - (*dest) = s; -} - -_PUBLIC_ void sub_set_remote_proto(const char *str) -{ - if (!sub) return; - setup_string(&sub->remote_proto, str); -} - -_PUBLIC_ void sub_set_remote_arch(const char *str) -{ - if (!sub) return; - setup_string(&sub->remote_arch, str); -} - -/** - setup the string used by %U substitution -*/ -_PUBLIC_ void sub_set_user_name(const char *name) -{ - if (!sub) return; - setup_string(&sub->user_name, name); -} - -/** -FIXME -**/ -_PUBLIC_ void standard_sub_basic(char *str,size_t len) -{ -} - -/** - Do some standard substitutions in a string. - This function will return an allocated string that have to be freed. -**/ -_PUBLIC_ char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name, const char *str) -{ - return talloc_strdup(mem_ctx, str); -} - -_PUBLIC_ char *alloc_sub_basic(const char *smb_name, const char *str) -{ - return strdup(str); -} - -/** - Do some specific substitutions in a string. - This function will return an allocated string that have to be freed. -**/ - -_PUBLIC_ char *talloc_sub_specified(TALLOC_CTX *mem_ctx, - const char *input_string, - const char *username, - const char *domain, - uid_t uid, - gid_t gid) -{ - return talloc_strdup(mem_ctx, input_string); -} - -_PUBLIC_ char *alloc_sub_specified(const char *input_string, - const char *username, - const char *domain, - uid_t uid, - gid_t gid) -{ - return strdup(input_string); -} - -_PUBLIC_ char *talloc_sub_advanced(TALLOC_CTX *mem_ctx, - int snum, - const char *user, - const char *connectpath, - gid_t gid, - const char *smb_name, - char *str) -{ - return talloc_strdup(mem_ctx, str); -} - -_PUBLIC_ char *alloc_sub_advanced(int snum, const char *user, - const char *connectpath, gid_t gid, - const char *smb_name, char *str) -{ - return strdup(str); -} - -/** - Do some standard substitutions in a string. -**/ - -_PUBLIC_ void standard_sub_tcon(struct smbsrv_tcon *tcon, char *str, size_t len) -{ -} - -_PUBLIC_ char *talloc_sub_tcon(TALLOC_CTX *mem_ctx, struct smbsrv_tcon *tcon, char *str) -{ - return talloc_strdup(mem_ctx, str); -} - -_PUBLIC_ char *alloc_sub_tcon(struct smbsrv_tcon *tcon, char *str) -{ - return strdup(str); -} - -/** - Like standard_sub but by snum. FIXME -**/ - -_PUBLIC_ void standard_sub_snum(int snum, char *str, size_t len) -{ -} -- cgit From dc2715b49c477adb4ba95149a3bfdf79457fa6c0 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 21 Jul 2006 00:56:48 +0000 Subject: r17167: indent (This used to be commit 4dcdc5a3ad6847be6c6199854121ae4ccadaa673) --- source4/lib/util/data_blob.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index ac6589aa50..118d78ca60 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -206,7 +206,7 @@ _PUBLIC_ NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t append some data to a data blob **/ _PUBLIC_ NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, - const void *p, size_t length) + const void *p, size_t length) { blob->data = talloc_realloc_size(mem_ctx, blob->data, blob->length + length); -- cgit From c047a88f41ffed47e2eb422f8efb594aae80d61e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 25 Jul 2006 00:53:03 +0000 Subject: r17221: Add some integer wrap parinoia to data_blob_append(). Andrew Bartlett (This used to be commit 7c5a25a423da3db982396ac507df985fa934be73) --- source4/lib/util/data_blob.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index 118d78ca60..3253d52ee7 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -202,17 +202,30 @@ _PUBLIC_ NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t return NT_STATUS_OK; } + /** append some data to a data blob **/ _PUBLIC_ NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const void *p, size_t length) { - blob->data = talloc_realloc_size(mem_ctx, blob->data, - blob->length + length); - NT_STATUS_HAVE_NO_MEMORY(blob->data); - memcpy(blob->data + blob->length, p, length); - blob->length += length; + NTSTATUS status; + size_t old_len = blob->length; + size_t new_len = old_len + length; + if (new_len < length || new_len < old_len) { + return NT_STATUS_NO_MEMORY; + } + + if ((const uint8_t *)p + length < (const uint8_t *)p) { + return NT_STATUS_NO_MEMORY; + } + + status = data_blob_realloc(mem_ctx, blob, new_len); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + memcpy(blob->data + old_len, p, length); return NT_STATUS_OK; } -- cgit From 3d603bdd66643ce1d9b530978644c7aa747145fd Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 20 Aug 2006 21:57:08 +0000 Subject: r17633: Return NULL at the end of the file, or else we can't tell the difference between end of file and a blank line. Andrew Bartlett (This used to be commit 6fd6239a0f16154c13713bf1398b2873d1103335) --- source4/lib/util/util_file.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index 99432ad8bb..3451712053 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -125,6 +125,10 @@ _PUBLIC_ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint) ret = read(fd, data + offset, hint); + if (ret == 0) { + return NULL; + } + if (ret == -1) { talloc_free(data); return NULL; -- cgit From 9fd23a6e918d5184eaf6814e4abb51a348e566a3 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 24 Aug 2006 09:48:40 +0000 Subject: r17782: fix compiler warning metze (This used to be commit 97f6980372e2d06bdae461c737f9e0279f30b9b9) --- source4/lib/util/idtree.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/idtree.c b/source4/lib/util/idtree.c index c02a2636a1..46c979f546 100644 --- a/source4/lib/util/idtree.c +++ b/source4/lib/util/idtree.c @@ -37,7 +37,9 @@ #define IDR_BITS 5 #define IDR_FULL 0xfffffffful +#if 0 /* unused */ #define TOP_LEVEL_FULL (IDR_FULL >> 30) +#endif #define IDR_SIZE (1 << IDR_BITS) #define IDR_MASK ((1 << IDR_BITS)-1) #define MAX_ID_SHIFT (sizeof(int)*8 - 1) -- cgit From a485fa050c1b210847bb4867ade25afc5ca941c7 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 24 Aug 2006 09:49:09 +0000 Subject: r17783: fix compiler warnings metze (This used to be commit c999dd02100e59bfd34585850c354ac2e9708cbb) --- source4/lib/util/fault.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index 8b447851dc..c7d6b7ede6 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -38,7 +38,6 @@ static const char *progname; #ifdef HAVE_BACKTRACE #include -#define BACKTRACE_STACK_SIZE 64 #elif HAVE_LIBEXC_H #include #endif @@ -49,7 +48,9 @@ static const char *progname; _PUBLIC_ void call_backtrace(void) { #ifdef HAVE_BACKTRACE +#ifndef BACKTRACE_STACK_SIZE #define BACKTRACE_STACK_SIZE 64 +#endif void *backtrace_stack[BACKTRACE_STACK_SIZE]; size_t backtrace_size; char **backtrace_strings; @@ -73,6 +74,9 @@ _PUBLIC_ void call_backtrace(void) #elif HAVE_LIBEXC #define NAMESIZE 32 /* Arbitrary */ +#ifndef BACKTRACE_STACK_SIZE +#define BACKTRACE_STACK_SIZE 64 +#endif /* The IRIX libexc library provides an API for unwinding the stack. See * libexc(3) for details. Apparantly trace_back_stack leaks memory, but -- cgit From 1d8fa3ccac93d5307cbf63f7f02c46ae6ec268d8 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 24 Aug 2006 10:55:17 +0000 Subject: r17790: replace uses -ldl and should directly depend on it metze (This used to be commit 560a3058e53479133015d1b0a7cd149393c45438) --- source4/lib/util/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index cc3b1930c5..0287021caa 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -28,7 +28,7 @@ OBJ_FILES = xfile.o \ idtree.o \ module.o PUBLIC_DEPENDENCIES = \ - LIBREPLACE LIBCRYPTO DL LIBTALLOC \ + LIBREPLACE LIBCRYPTO LIBTALLOC \ SOCKET_WRAPPER EXT_NSL [SUBSYSTEM::PIDFILE] -- cgit From 0329d755a7611ba3897fc1ee9bdce410cc33d7f8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 30 Aug 2006 11:29:34 +0000 Subject: r17930: Merge noinclude branch: * Move dlinklist.h, smb.h to subsystem-specific directories * Clean up ads.h and move what is left of it to dsdb/ (only place where it's used) (This used to be commit f7afa1cb77f3cfa7020b57de12e6003db7cfcc42) --- source4/lib/util/dlinklist.h | 109 +++++++++++++++++++++++++++++++++++++++++++ source4/lib/util/util.h | 1 - source4/lib/util/util_str.c | 2 +- 3 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 source4/lib/util/dlinklist.h (limited to 'source4/lib/util') diff --git a/source4/lib/util/dlinklist.h b/source4/lib/util/dlinklist.h new file mode 100644 index 0000000000..527b211cd3 --- /dev/null +++ b/source4/lib/util/dlinklist.h @@ -0,0 +1,109 @@ +/* + Unix SMB/CIFS implementation. + some simple double linked list macros + Copyright (C) Andrew Tridgell 1998 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* To use these macros you must have a structure containing a next and + prev pointer */ + + +/* hook into the front of the list */ +#define DLIST_ADD(list, p) \ +do { \ + if (!(list)) { \ + (list) = (p); \ + (p)->next = (p)->prev = NULL; \ + } else { \ + (list)->prev = (p); \ + (p)->next = (list); \ + (p)->prev = NULL; \ + (list) = (p); \ + }\ +} while (0) + +/* remove an element from a list - element doesn't have to be in list. */ +#define DLIST_REMOVE(list, p) \ +do { \ + if ((p) == (list)) { \ + (list) = (p)->next; \ + if (list) (list)->prev = NULL; \ + } else { \ + if ((p)->prev) (p)->prev->next = (p)->next; \ + if ((p)->next) (p)->next->prev = (p)->prev; \ + } \ + if ((p) != (list)) (p)->next = (p)->prev = NULL; \ +} while (0) + +/* promote an element to the top of the list */ +#define DLIST_PROMOTE(list, p) \ +do { \ + DLIST_REMOVE(list, p); \ + DLIST_ADD(list, p); \ +} while (0) + +/* hook into the end of the list - needs a tmp pointer */ +#define DLIST_ADD_END(list, p, type) \ +do { \ + if (!(list)) { \ + (list) = (p); \ + (p)->next = (p)->prev = NULL; \ + } else { \ + type tmp; \ + for (tmp = (list); tmp->next; tmp = tmp->next) ; \ + tmp->next = (p); \ + (p)->next = NULL; \ + (p)->prev = tmp; \ + } \ +} while (0) + +/* insert 'p' after the given element 'el' in a list. If el is NULL then + this is the same as a DLIST_ADD() */ +#define DLIST_ADD_AFTER(list, p, el) \ +do { \ + if (!(list) || !(el)) { \ + DLIST_ADD(list, p); \ + } else { \ + p->prev = el; \ + p->next = el->next; \ + el->next = p; \ + if (p->next) p->next->prev = p; \ + }\ +} while (0) + +/* demote an element to the end of the list, needs a tmp pointer */ +#define DLIST_DEMOTE(list, p, tmp) \ +do { \ + DLIST_REMOVE(list, p); \ + DLIST_ADD_END(list, p, tmp); \ +} while (0) + +/* concatenate two lists - putting all elements of the 2nd list at the + end of the first list */ +#define DLIST_CONCATENATE(list1, list2, type) \ +do { \ + if (!(list1)) { \ + (list1) = (list2); \ + } else { \ + type tmp; \ + for (tmp = (list1); tmp->next; tmp = tmp->next) ; \ + tmp->next = (list2); \ + if (list2) { \ + (list2)->prev = tmp; \ + } \ + } \ +} while (0) diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 2517966d90..c7acc2ea33 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -22,7 +22,6 @@ #ifndef _SAMBA_UTIL_H_ #define _SAMBA_UTIL_H_ -#include "core.h" #include "charset/charset.h" /** diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 62869198c3..163ef3828e 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -23,7 +23,7 @@ */ #include "includes.h" -#include "smb.h" +#include "libcli/raw/smb.h" #include "pstring.h" #include "lib/ldb/include/ldb.h" #include "system/locale.h" -- cgit From 0e8d1e9412b4538ceb008b82ddec423c2019757f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 6 Sep 2006 02:04:30 +0000 Subject: r18126: Fix -ldl dependency problem (This used to be commit ce31b736a9418889538b5778ceb0b18071cdfebd) --- source4/lib/util/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 0287021caa..0a05c67226 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -29,7 +29,7 @@ OBJ_FILES = xfile.o \ module.o PUBLIC_DEPENDENCIES = \ LIBREPLACE LIBCRYPTO LIBTALLOC \ - SOCKET_WRAPPER EXT_NSL + SOCKET_WRAPPER EXT_NSL DL [SUBSYSTEM::PIDFILE] PRIVATE_PROTO_HEADER = pidfile.h -- cgit From 014f70008fcfdb631031c48aa9654ad5b42e62f9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 6 Sep 2006 04:58:06 +0000 Subject: r18130: the move to system/ in libreplace broke some things ... should be happier now (This used to be commit 18542f184f75074e56a9793a9e3b6c6d747bb9e6) --- source4/lib/util/config.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 0a05c67226..3a8eb78e50 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -38,6 +38,7 @@ OBJ_FILES = pidfile.o [SUBSYSTEM::UNIX_PRIVS] PRIVATE_PROTO_HEADER = unix_privs.h OBJ_FILES = unix_privs.o +PUBLIC_DEPENDENCIES = LIBREPLACE ################################################ # Start SUBSYSTEM WRAP_XATTR @@ -45,7 +46,7 @@ OBJ_FILES = unix_privs.o PUBLIC_PROTO_HEADER = wrap_xattr.h OBJ_FILES = \ wrap_xattr.o -PUBLIC_DEPENDENCIES = XATTR +PUBLIC_DEPENDENCIES = XATTR LIBREPLACE # # End SUBSYSTEM WRAP_XATTR ################################################ -- cgit From bbc78c9c148b62d271d731666e0d48d9195e35f0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 6 Sep 2006 05:59:10 +0000 Subject: r18137: more LIBREPLACE deps (This used to be commit 2d813d1e6deb99b06e43462885be848a5399b9a8) --- source4/lib/util/config.mk | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 3a8eb78e50..ecc74a57e3 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -34,6 +34,7 @@ PUBLIC_DEPENDENCIES = \ [SUBSYSTEM::PIDFILE] PRIVATE_PROTO_HEADER = pidfile.h OBJ_FILES = pidfile.o +PUBLIC_DEPENDENCIES = LIBREPLACE [SUBSYSTEM::UNIX_PRIVS] PRIVATE_PROTO_HEADER = unix_privs.h -- cgit From 01dee6e3dd80ace0bd341adb613fc25874e57764 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 6 Sep 2006 06:05:58 +0000 Subject: r18138: LIBREPLACE provides stuff from -ldl so it should depend on it metze (This used to be commit b4e4c115ab23bcc3b116a3736ddf2e88bab6f4cf) --- source4/lib/util/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index ecc74a57e3..9694e8cf6c 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -29,7 +29,7 @@ OBJ_FILES = xfile.o \ module.o PUBLIC_DEPENDENCIES = \ LIBREPLACE LIBCRYPTO LIBTALLOC \ - SOCKET_WRAPPER EXT_NSL DL + SOCKET_WRAPPER EXT_NSL [SUBSYSTEM::PIDFILE] PRIVATE_PROTO_HEADER = pidfile.h -- cgit From a46e12d0e07e1630f8ef15aff0f97cb2f1f4c273 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 7 Sep 2006 10:02:32 +0000 Subject: r18213: don't list LIBREPLACE depdendecies explicit and always at it as first private dependencies metze (This used to be commit 135d096776b53ae09ffc2b4f767dfbd18139570f) --- source4/lib/util/config.mk | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 9694e8cf6c..401b4df005 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -28,18 +28,16 @@ OBJ_FILES = xfile.o \ idtree.o \ module.o PUBLIC_DEPENDENCIES = \ - LIBREPLACE LIBCRYPTO LIBTALLOC \ + LIBCRYPTO LIBTALLOC \ SOCKET_WRAPPER EXT_NSL [SUBSYSTEM::PIDFILE] PRIVATE_PROTO_HEADER = pidfile.h OBJ_FILES = pidfile.o -PUBLIC_DEPENDENCIES = LIBREPLACE [SUBSYSTEM::UNIX_PRIVS] PRIVATE_PROTO_HEADER = unix_privs.h OBJ_FILES = unix_privs.o -PUBLIC_DEPENDENCIES = LIBREPLACE ################################################ # Start SUBSYSTEM WRAP_XATTR @@ -47,7 +45,7 @@ PUBLIC_DEPENDENCIES = LIBREPLACE PUBLIC_PROTO_HEADER = wrap_xattr.h OBJ_FILES = \ wrap_xattr.o -PUBLIC_DEPENDENCIES = XATTR LIBREPLACE +PUBLIC_DEPENDENCIES = XATTR # # End SUBSYSTEM WRAP_XATTR ################################################ -- cgit From 4a854fe809ba617336db3e1d277e00c7ef95c55f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 17 Sep 2006 05:11:57 +0000 Subject: r18593: try to get the same socket_wrapper file building in samba3 and samba4 this is preparation of adding libreplace to samba3 later. metze (This used to be commit 26228e4b2e8debd84caebe84bb34bfbbf2ad405c) --- source4/lib/util/dlinklist.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/dlinklist.h b/source4/lib/util/dlinklist.h index 527b211cd3..f267e77ea6 100644 --- a/source4/lib/util/dlinklist.h +++ b/source4/lib/util/dlinklist.h @@ -21,6 +21,9 @@ /* To use these macros you must have a structure containing a next and prev pointer */ +#ifndef _DLINKLIST_H +#define _DLINKLIST_H + /* hook into the front of the list */ #define DLIST_ADD(list, p) \ @@ -107,3 +110,5 @@ do { \ } \ } \ } while (0) + +#endif /* _DLINKLIST_H */ -- cgit From d630105b563aca913750200ea6e9ad17241ac51d Mon Sep 17 00:00:00 2001 From: Rafal Szczesniak Date: Mon, 18 Sep 2006 17:32:13 +0000 Subject: r18614: a bit of work done while on the plane. a new function converting NTTIME to struct timeval rafal (This used to be commit e9ebbb8661ac6efc5bf07798a64cdb9f7c7eea50) --- source4/lib/util/time.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/time.c b/source4/lib/util/time.c index 6ad3a229e3..d3cdecdfe3 100644 --- a/source4/lib/util/time.c +++ b/source4/lib/util/time.c @@ -566,6 +566,28 @@ _PUBLIC_ NTTIME timeval_to_nttime(const struct timeval *tv) ((TIME_FIXUP_CONSTANT + (uint64_t)tv->tv_sec) * 1000000)); } +/** + convert a NTTIME to a timeval +*/ +_PUBLIC_ void nttime_to_timeval(struct timeval *tv, NTTIME t) +{ + if (tv == NULL) return; + + t += 10/2; + t /= 10; + t -= TIME_FIXUP_CONSTANT*1000*1000; + + tv->tv_sec = t / 1000000; + + if (TIME_T_MIN > tv->tv_sec || tv->tv_sec > TIME_T_MAX) { + tv->tv_sec = 0; + tv->tv_usec = 0; + return; + } + + tv->tv_usec = t - tv->tv_sec*1000000; +} + /******************************************************************* yield the difference between *A and *B, in seconds, ignoring leap seconds ********************************************************************/ -- cgit From af870da6194b47c6cd09445c1e03832d00e951bb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 20 Oct 2006 23:32:23 +0000 Subject: r19428: moved tdbutil.c from lib/tdb/common/ to lib/util/util_tdb.c tdbutil.c is Samba specific, so should not be part of the generic tdb library (This used to be commit 979dd24f5e44605fc1603b690913b8c31be7478f) --- source4/lib/util/config.mk | 10 + source4/lib/util/util_tdb.c | 541 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 551 insertions(+) create mode 100644 source4/lib/util/util_tdb.c (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 401b4df005..5e49eb839a 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -49,3 +49,13 @@ PUBLIC_DEPENDENCIES = XATTR # # End SUBSYSTEM WRAP_XATTR ################################################ + +################################################ +# Start SUBSYSTEM UTIL_TDB +[SUBSYSTEM::UTIL_TDB] +PUBLIC_PROTO_HEADER = util_tdb.h +OBJ_FILES = \ + util_tdb.o +PUBLIC_DEPENDENCIES = LIBTDB +# End SUBSYSTEM UTIL_TDB +################################################ diff --git a/source4/lib/util/util_tdb.c b/source4/lib/util/util_tdb.c new file mode 100644 index 0000000000..820fc2dbb1 --- /dev/null +++ b/source4/lib/util/util_tdb.c @@ -0,0 +1,541 @@ +/* + Unix SMB/CIFS implementation. + + tdb utility functions + + Copyright (C) Andrew Tridgell 1992-2006 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "lib/tdb/include/tdb.h" +#include "pstring.h" + +/* these are little tdb utility functions that are meant to make + dealing with a tdb database a little less cumbersome in Samba */ + +/*************************************************************** + Make a TDB_DATA and keep the const warning in one place +****************************************************************/ + +static TDB_DATA make_tdb_data(const char *dptr, size_t dsize) +{ + TDB_DATA ret; + ret.dptr = discard_const_p(unsigned char, dptr); + ret.dsize = dsize; + return ret; +} + +/**************************************************************************** + Lock a chain by string. Return -1 if lock failed. +****************************************************************************/ + +int tdb_lock_bystring(struct tdb_context *tdb, const char *keyval) +{ + TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1); + + return tdb_chainlock(tdb, key); +} + +/**************************************************************************** + Unlock a chain by string. +****************************************************************************/ + +void tdb_unlock_bystring(struct tdb_context *tdb, const char *keyval) +{ + TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1); + + tdb_chainunlock(tdb, key); +} + +/**************************************************************************** + Read lock a chain by string. Return -1 if lock failed. +****************************************************************************/ + +int tdb_read_lock_bystring(struct tdb_context *tdb, const char *keyval) +{ + TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1); + + return tdb_chainlock_read(tdb, key); +} + +/**************************************************************************** + Read unlock a chain by string. +****************************************************************************/ + +void tdb_read_unlock_bystring(struct tdb_context *tdb, const char *keyval) +{ + TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1); + + tdb_chainunlock_read(tdb, key); +} + + +/**************************************************************************** + Fetch a int32_t value by a arbitrary blob key, return -1 if not found. + Output is int32_t in native byte order. +****************************************************************************/ + +int32_t tdb_fetch_int32_byblob(struct tdb_context *tdb, const char *keyval, size_t len) +{ + TDB_DATA key = make_tdb_data(keyval, len); + TDB_DATA data; + int32_t ret; + + data = tdb_fetch(tdb, key); + if (!data.dptr || data.dsize != sizeof(int32_t)) { + SAFE_FREE(data.dptr); + return -1; + } + + ret = IVAL(data.dptr,0); + SAFE_FREE(data.dptr); + return ret; +} + +/**************************************************************************** + Fetch a int32_t value by string key, return -1 if not found. + Output is int32_t in native byte order. +****************************************************************************/ + +int32_t tdb_fetch_int32(struct tdb_context *tdb, const char *keystr) +{ + return tdb_fetch_int32_byblob(tdb, keystr, strlen(keystr) + 1); +} + +/**************************************************************************** + Store a int32_t value by an arbitary blob key, return 0 on success, -1 on failure. + Input is int32_t in native byte order. Output in tdb is in little-endian. +****************************************************************************/ + +int tdb_store_int32_byblob(struct tdb_context *tdb, const char *keystr, size_t len, int32_t v) +{ + TDB_DATA key = make_tdb_data(keystr, len); + TDB_DATA data; + int32_t v_store; + + SIVAL(&v_store,0,v); + data.dptr = (void *)&v_store; + data.dsize = sizeof(int32_t); + + return tdb_store(tdb, key, data, TDB_REPLACE); +} + +/**************************************************************************** + Store a int32_t value by string key, return 0 on success, -1 on failure. + Input is int32_t in native byte order. Output in tdb is in little-endian. +****************************************************************************/ + +int tdb_store_int32(struct tdb_context *tdb, const char *keystr, int32_t v) +{ + return tdb_store_int32_byblob(tdb, keystr, strlen(keystr) + 1, v); +} + +/**************************************************************************** + Fetch a uint32_t value by a arbitrary blob key, return -1 if not found. + Output is uint32_t in native byte order. +****************************************************************************/ + +BOOL tdb_fetch_uint32_byblob(struct tdb_context *tdb, const char *keyval, size_t len, uint32_t *value) +{ + TDB_DATA key = make_tdb_data(keyval, len); + TDB_DATA data; + + data = tdb_fetch(tdb, key); + if (!data.dptr || data.dsize != sizeof(uint32_t)) { + SAFE_FREE(data.dptr); + return False; + } + + *value = IVAL(data.dptr,0); + SAFE_FREE(data.dptr); + return True; +} + +/**************************************************************************** + Fetch a uint32_t value by string key, return -1 if not found. + Output is uint32_t in native byte order. +****************************************************************************/ + +BOOL tdb_fetch_uint32(struct tdb_context *tdb, const char *keystr, uint32_t *value) +{ + return tdb_fetch_uint32_byblob(tdb, keystr, strlen(keystr) + 1, value); +} + +/**************************************************************************** + Store a uint32_t value by an arbitary blob key, return 0 on success, -1 on failure. + Input is uint32_t in native byte order. Output in tdb is in little-endian. +****************************************************************************/ + +BOOL tdb_store_uint32_byblob(struct tdb_context *tdb, const char *keystr, size_t len, uint32_t value) +{ + TDB_DATA key = make_tdb_data(keystr, len); + TDB_DATA data; + uint32_t v_store; + BOOL ret = True; + + SIVAL(&v_store, 0, value); + data.dptr = (void *)&v_store; + data.dsize = sizeof(uint32_t); + + if (tdb_store(tdb, key, data, TDB_REPLACE) == -1) + ret = False; + + return ret; +} + +/**************************************************************************** + Store a uint32_t value by string key, return 0 on success, -1 on failure. + Input is uint32_t in native byte order. Output in tdb is in little-endian. +****************************************************************************/ + +BOOL tdb_store_uint32(struct tdb_context *tdb, const char *keystr, uint32_t value) +{ + return tdb_store_uint32_byblob(tdb, keystr, strlen(keystr) + 1, value); +} +/**************************************************************************** + Store a buffer by a null terminated string key. Return 0 on success, -1 + on failure. +****************************************************************************/ + +int tdb_store_bystring(struct tdb_context *tdb, const char *keystr, TDB_DATA data, int flags) +{ + TDB_DATA key = make_tdb_data(keystr, strlen(keystr)+1); + + return tdb_store(tdb, key, data, flags); +} + +/**************************************************************************** + Fetch a buffer using a null terminated string key. Don't forget to call + free() on the result dptr. +****************************************************************************/ + +TDB_DATA tdb_fetch_bystring(struct tdb_context *tdb, const char *keystr) +{ + TDB_DATA key = make_tdb_data(keystr, strlen(keystr)+1); + + return tdb_fetch(tdb, key); +} + +/**************************************************************************** + Delete an entry using a null terminated string key. +****************************************************************************/ + +int tdb_delete_bystring(struct tdb_context *tdb, const char *keystr) +{ + TDB_DATA key = make_tdb_data(keystr, strlen(keystr)+1); + + return tdb_delete(tdb, key); +} + +/**************************************************************************** + Atomic integer change. Returns old value. To create, set initial value in *oldval. +****************************************************************************/ + +int32_t tdb_change_int32_atomic(struct tdb_context *tdb, const char *keystr, int32_t *oldval, int32_t change_val) +{ + int32_t val; + int32_t ret = -1; + + if (tdb_lock_bystring(tdb, keystr) == -1) + return -1; + + if ((val = tdb_fetch_int32(tdb, keystr)) == -1) { + /* The lookup failed */ + if (tdb_error(tdb) != TDB_ERR_NOEXIST) { + /* but not because it didn't exist */ + goto err_out; + } + + /* Start with 'old' value */ + val = *oldval; + + } else { + /* It worked, set return value (oldval) to tdb data */ + *oldval = val; + } + + /* Increment value for storage and return next time */ + val += change_val; + + if (tdb_store_int32(tdb, keystr, val) == -1) + goto err_out; + + ret = 0; + + err_out: + + tdb_unlock_bystring(tdb, keystr); + return ret; +} + +/**************************************************************************** + Atomic unsigned integer change. Returns old value. To create, set initial value in *oldval. +****************************************************************************/ + +BOOL tdb_change_uint32_atomic(struct tdb_context *tdb, const char *keystr, uint32_t *oldval, uint32_t change_val) +{ + uint32_t val; + BOOL ret = False; + + if (tdb_lock_bystring(tdb, keystr) == -1) + return False; + + if (!tdb_fetch_uint32(tdb, keystr, &val)) { + /* It failed */ + if (tdb_error(tdb) != TDB_ERR_NOEXIST) { + /* and not because it didn't exist */ + goto err_out; + } + + /* Start with 'old' value */ + val = *oldval; + + } else { + /* it worked, set return value (oldval) to tdb data */ + *oldval = val; + + } + + /* get a new value to store */ + val += change_val; + + if (!tdb_store_uint32(tdb, keystr, val)) + goto err_out; + + ret = True; + + err_out: + + tdb_unlock_bystring(tdb, keystr); + return ret; +} + +/**************************************************************************** + Allow tdb_delete to be used as a tdb_traversal_fn. +****************************************************************************/ + +int tdb_traverse_delete_fn(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA dbuf, + void *state) +{ + return tdb_delete(the_tdb, key); +} + + + +/**************************************************************************** + Useful pair of routines for packing/unpacking data consisting of + integers and strings. +****************************************************************************/ + +size_t tdb_pack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...) +{ + va_list ap; + uint8_t bt; + uint16_t w; + uint32_t d; + int i; + void *p; + int len; + char *s; + char c; + char *buf0 = buf; + const char *fmt0 = fmt; + int bufsize0 = bufsize; + tdb_log_func log_fn = tdb_log_fn(tdb); + + va_start(ap, fmt); + + while (*fmt) { + switch ((c = *fmt++)) { + case 'b': /* unsigned 8-bit integer */ + len = 1; + bt = (uint8_t)va_arg(ap, int); + if (bufsize && bufsize >= len) + SSVAL(buf, 0, bt); + break; + case 'w': /* unsigned 16-bit integer */ + len = 2; + w = (uint16_t)va_arg(ap, int); + if (bufsize && bufsize >= len) + SSVAL(buf, 0, w); + break; + case 'd': /* signed 32-bit integer (standard int in most systems) */ + len = 4; + d = va_arg(ap, uint32_t); + if (bufsize && bufsize >= len) + SIVAL(buf, 0, d); + break; + case 'p': /* pointer */ + len = 4; + p = va_arg(ap, void *); + d = p?1:0; + if (bufsize && bufsize >= len) + SIVAL(buf, 0, d); + break; + case 'P': /* null-terminated string */ + s = va_arg(ap,char *); + w = strlen(s); + len = w + 1; + if (bufsize && bufsize >= len) + memcpy(buf, s, len); + break; + case 'f': /* null-terminated string */ + s = va_arg(ap,char *); + w = strlen(s); + len = w + 1; + if (bufsize && bufsize >= len) + memcpy(buf, s, len); + break; + case 'B': /* fixed-length string */ + i = va_arg(ap, int); + s = va_arg(ap, char *); + len = 4+i; + if (bufsize && bufsize >= len) { + SIVAL(buf, 0, i); + memcpy(buf+4, s, i); + } + break; + default: + log_fn(tdb, 0,"Unknown tdb_pack format %c in %s\n", + c, fmt); + len = 0; + break; + } + + buf += len; + if (bufsize) + bufsize -= len; + if (bufsize < 0) + bufsize = 0; + } + + va_end(ap); + + log_fn(tdb, 18,"tdb_pack(%s, %d) -> %d\n", + fmt0, bufsize0, (int)PTR_DIFF(buf, buf0)); + + return PTR_DIFF(buf, buf0); +} + +/**************************************************************************** + Useful pair of routines for packing/unpacking data consisting of + integers and strings. +****************************************************************************/ + +int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...) +{ + va_list ap; + uint8_t *bt; + uint16_t *w; + uint32_t *d; + int len; + int *i; + void **p; + char *s, **b; + char c; + char *buf0 = buf; + const char *fmt0 = fmt; + int bufsize0 = bufsize; + tdb_log_func log_fn = tdb_log_fn(tdb); + + va_start(ap, fmt); + + while (*fmt) { + switch ((c=*fmt++)) { + case 'b': + len = 1; + bt = va_arg(ap, uint8_t *); + if (bufsize < len) + goto no_space; + *bt = SVAL(buf, 0); + break; + case 'w': + len = 2; + w = va_arg(ap, uint16_t *); + if (bufsize < len) + goto no_space; + *w = SVAL(buf, 0); + break; + case 'd': + len = 4; + d = va_arg(ap, uint32_t *); + if (bufsize < len) + goto no_space; + *d = IVAL(buf, 0); + break; + case 'p': + len = 4; + p = va_arg(ap, void **); + if (bufsize < len) + goto no_space; + *p = (void *)IVAL(buf, 0); + break; + case 'P': + s = va_arg(ap,char *); + len = strlen(buf) + 1; + if (bufsize < len || len > sizeof(pstring)) + goto no_space; + memcpy(s, buf, len); + break; + case 'f': + s = va_arg(ap,char *); + len = strlen(buf) + 1; + if (bufsize < len || len > sizeof(fstring)) + goto no_space; + memcpy(s, buf, len); + break; + case 'B': + i = va_arg(ap, int *); + b = va_arg(ap, char **); + len = 4; + if (bufsize < len) + goto no_space; + *i = IVAL(buf, 0); + if (! *i) { + *b = NULL; + break; + } + len += *i; + if (bufsize < len) + goto no_space; + *b = (char *)malloc(*i); + if (! *b) + goto no_space; + memcpy(*b, buf+4, *i); + break; + default: + log_fn(tdb, 0, "Unknown tdb_unpack format %c in %s\n", + c, fmt); + + len = 0; + break; + } + + buf += len; + bufsize -= len; + } + + va_end(ap); + + log_fn(tdb, 18, "tdb_unpack(%s, %d) -> %d\n", + fmt0, bufsize0, (int)PTR_DIFF(buf, buf0)); + + return PTR_DIFF(buf, buf0); + + no_space: + return -1; +} -- cgit From 9cd2b012f3bf9f21f321d44c43eb5a8a781d68fc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 28 Oct 2006 06:06:15 +0000 Subject: r19504: - fixed a free error in file_lines_parse - added a function to test for large file support - enable CAP_LARGE_FILES only if the test passes - don't test at large offsets if the server doesn't set CAP_LARGE_FILES (This used to be commit c5423ea22bdaa055807d4e6f7ac4be934194fe45) --- source4/lib/util/util_file.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index 3451712053..5d7ec40b30 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -241,6 +241,7 @@ _PUBLIC_ void *map_file(const char *fname, size_t size) /** parse a buffer into lines +'p' will be freed on error, and otherwise will be made a child of the returned array **/ static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx) { @@ -259,7 +260,7 @@ static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX * return NULL; } - talloc_reference(ret, p); + talloc_steal(ret, p); memset(ret, 0, sizeof(ret[0])*(i+2)); if (numlines) *numlines = i; @@ -285,17 +286,12 @@ must be freed with talloc_free(). _PUBLIC_ char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx) { char *p; - char **lines; size_t size; p = file_load(fname, &size, mem_ctx); if (!p) return NULL; - lines = file_lines_parse(p, size, numlines, mem_ctx); - - talloc_free(p); - - return lines; + return file_lines_parse(p, size, numlines, mem_ctx); } /** @@ -306,17 +302,12 @@ the list. _PUBLIC_ char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx) { char *p; - char **lines; size_t size; p = fd_load(fd, &size, mem_ctx); if (!p) return NULL; - lines = file_lines_parse(p, size, numlines, mem_ctx); - - talloc_free(p); - - return lines; + return file_lines_parse(p, size, numlines, mem_ctx); } @@ -385,3 +376,24 @@ _PUBLIC_ int fdprintf(int fd, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) va_end(ap); return ret; } + + +/* + try to determine if the filesystem supports large files +*/ +_PUBLIC_ bool large_file_support(const char *path) +{ + int fd; + ssize_t ret; + char c; + + fd = open(path, O_RDWR|O_CREAT, 0600); + unlink(path); + if (fd == -1) { + /* have to assume large files are OK */ + return true; + } + ret = pread(fd, &c, 1, ((uint64_t)1)<<32); + close(fd); + return ret == 0; +} -- cgit From 1b4b2a291d9a8e2ad2fa0771e7386a3f6d89512d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 3 Nov 2006 01:49:19 +0000 Subject: r19539: Move pidfile to smbd/ (This used to be commit eefa64cbe392c4c4dcbf71b8bcf5128cce0339ba) --- source4/lib/util/config.mk | 6 +-- source4/lib/util/pidfile.c | 125 --------------------------------------------- 2 files changed, 1 insertion(+), 130 deletions(-) delete mode 100644 source4/lib/util/pidfile.c (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 5e49eb839a..5d3e2cc4ca 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -28,13 +28,9 @@ OBJ_FILES = xfile.o \ idtree.o \ module.o PUBLIC_DEPENDENCIES = \ - LIBCRYPTO LIBTALLOC \ + LIBTALLOC LIBCRYPTO \ SOCKET_WRAPPER EXT_NSL -[SUBSYSTEM::PIDFILE] -PRIVATE_PROTO_HEADER = pidfile.h -OBJ_FILES = pidfile.o - [SUBSYSTEM::UNIX_PRIVS] PRIVATE_PROTO_HEADER = unix_privs.h OBJ_FILES = unix_privs.o diff --git a/source4/lib/util/pidfile.c b/source4/lib/util/pidfile.c deleted file mode 100644 index dc9ecafae9..0000000000 --- a/source4/lib/util/pidfile.c +++ /dev/null @@ -1,125 +0,0 @@ -/* this code is broken - there is a race condition with the unlink (tridge) */ - -/* - Unix SMB/CIFS implementation. - pidfile handling - Copyright (C) Andrew Tridgell 1998 - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" -#include "system/filesys.h" - -#ifndef O_NONBLOCK -#define O_NONBLOCK -#endif - -/** - * @file - * @brief Pid file handling - */ - -/** - * return the pid in a pidfile. return 0 if the process (or pidfile) - * does not exist - */ -_PUBLIC_ pid_t pidfile_pid(const char *name) -{ - int fd; - char pidstr[20]; - pid_t ret; - char *pidFile; - - asprintf(&pidFile, "%s/%s.pid", lp_piddir(), name); - - fd = open(pidFile, O_NONBLOCK | O_RDONLY, 0644); - - if (fd == -1) { - SAFE_FREE(pidFile); - return 0; - } - - ZERO_STRUCT(pidstr); - - if (read(fd, pidstr, sizeof(pidstr)-1) <= 0) { - goto noproc; - } - - ret = (pid_t)atoi(pidstr); - - if (!process_exists(ret)) { - goto noproc; - } - - if (fcntl_lock(fd,F_SETLK,0,1,F_RDLCK)) { - /* we could get the lock - it can't be a Samba process */ - goto noproc; - } - - close(fd); - SAFE_FREE(pidFile); - return ret; - - noproc: - close(fd); - unlink(pidFile); - SAFE_FREE(pidFile); - return 0; -} - -/** - * create a pid file in the pid directory. open it and leave it locked - */ -void pidfile_create(const char *name) -{ - int fd; - char buf[20]; - char *pidFile; - pid_t pid; - - asprintf(&pidFile, "%s/%s.pid", lp_piddir(), name); - - pid = pidfile_pid(name); - if (pid != 0) { - DEBUG(0,("ERROR: %s is already running. File %s exists and process id %d is running.\n", - name, pidFile, (int)pid)); - exit(1); - } - - fd = open(pidFile, O_NONBLOCK | O_CREAT | O_WRONLY | O_EXCL, 0644); - if (fd == -1) { - DEBUG(0,("ERROR: can't open %s: Error was %s\n", pidFile, - strerror(errno))); - exit(1); - } - - if (fcntl_lock(fd,F_SETLK,0,1,F_WRLCK)==False) { - DEBUG(0,("ERROR: %s : fcntl lock of file %s failed. Error was %s\n", - name, pidFile, strerror(errno))); - exit(1); - } - - memset(buf, 0, sizeof(buf)); - slprintf(buf, sizeof(buf) - 1, "%u\n", (unsigned int) getpid()); - if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) { - DEBUG(0,("ERROR: can't write to file %s: %s\n", - pidFile, strerror(errno))); - exit(1); - } - - /* Leave pid file open & locked for the duration... */ - SAFE_FREE(pidFile); -} -- cgit From 273d5f866653db0190c334c086bbfbd88d0ac3cb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 11 Nov 2006 23:14:58 +0000 Subject: r19671: Fix remaining unresolved symbols in shared library build. Fix starting tests in shared library build. (This used to be commit 3b65a0d6e491a57ed216dc0cd9c31d46e0cb6a35) --- source4/lib/util/config.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 5d3e2cc4ca..4f3a17d505 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -29,7 +29,8 @@ OBJ_FILES = xfile.o \ module.o PUBLIC_DEPENDENCIES = \ LIBTALLOC LIBCRYPTO \ - SOCKET_WRAPPER EXT_NSL + SOCKET_WRAPPER EXT_NSL \ + CHARSET [SUBSYSTEM::UNIX_PRIVS] PRIVATE_PROTO_HEADER = unix_privs.h -- cgit From 153349788cc643135b347eec80620ce958877f4b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 12 Nov 2006 00:54:43 +0000 Subject: r19672: Make LIBSAMBA-UTIL a subsystem again for now because it has interdependencies with LIBSAMBA-CONFIG. (This used to be commit 4a044fb529075044755a0b5cc21446bf24bec72e) --- source4/lib/util/config.mk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 4f3a17d505..cda42c105a 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -1,7 +1,7 @@ -[LIBRARY::LIBSAMBA-UTIL] -VERSION = 0.0.1 -SO_VERSION = 0 -DESCRIPTION = Generic utility functions +[SUBSYSTEM::LIBSAMBA-UTIL] +#VERSION = 0.0.1 +#SO_VERSION = 0 +#DESCRIPTION = Generic utility functions PUBLIC_PROTO_HEADER = util_proto.h PUBLIC_HEADERS = util.h \ byteorder.h \ -- cgit From 5235e6518cd9d9f5edac9424a4cc43023dd96b7f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 9 Dec 2006 03:12:33 +0000 Subject: r20091: remove blank lines at the end of text lines loaded from a file (This used to be commit afcc797e8a25d99269f67e05fe57e952dd5d65bc) --- source4/lib/util/util_file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index 5d7ec40b30..887efb9836 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -263,7 +263,6 @@ static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX * talloc_steal(ret, p); memset(ret, 0, sizeof(ret[0])*(i+2)); - if (numlines) *numlines = i; ret[0] = p; for (s = p, i=0; s < p+size; s++) { @@ -275,6 +274,13 @@ static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX * if (s[0] == '\r') s[0] = 0; } + /* remove any blank lines at the end */ + while (i > 0 && ret[i-1][0] == 0) { + i--; + } + + if (numlines) *numlines = i; + return ret; } -- cgit From 4a40f0310c5a3c375874ef42f12a5c434994f8e9 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 22 Dec 2006 18:53:39 +0000 Subject: r20325: handle NULL strings in is_ipaddress() metze (This used to be commit b8b69ff6bec0c1d412b1f935721b45ef07e9c9f5) --- source4/lib/util/util.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index 33215a81fb..afa9adbc18 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -292,7 +292,9 @@ _PUBLIC_ BOOL is_ipaddress(const char *str) { BOOL pure_address = True; int i; - + + if (str == NULL) return False; + for (i=0; pure_address && str[i]; i++) if (!(isdigit((int)str[i]) || str[i] == '.')) pure_address = False; -- cgit From e57c36ecba516992d70592a1a35fc8bc466b5faa Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 31 Dec 2006 12:28:16 +0000 Subject: r20436: add more comments and add macros signed versions of the 64 bit macros metze (This used to be commit e77d0d1532e800e0a7b0a4a30cf9b4d97761ee52) --- source4/lib/util/byteorder.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/byteorder.h b/source4/lib/util/byteorder.h index 941dee9e88..823287f075 100644 --- a/source4/lib/util/byteorder.h +++ b/source4/lib/util/byteorder.h @@ -73,13 +73,17 @@ reasoning behind them. byteorder.h defines the following macros: SVAL(buf,pos) - extract a 2 byte SMB value IVAL(buf,pos) - extract a 4 byte SMB value -SVALS(buf,pos) signed version of SVAL() -IVALS(buf,pos) signed version of IVAL() +BVAL(buf,pos) - extract a 8 byte SMB value +SVALS(buf,pos) - signed version of SVAL() +IVALS(buf,pos) - signed version of IVAL() +BVALS(buf,pos) - signed version of BVAL() SSVAL(buf,pos,val) - put a 2 byte SMB value into a buffer SIVAL(buf,pos,val) - put a 4 byte SMB value into a buffer +SBVAL(buf,pos,val) - put a 8 byte SMB value into a buffer SSVALS(buf,pos,val) - signed version of SSVAL() SIVALS(buf,pos,val) - signed version of SIVAL() +SBVALS(buf,pos,val) - signed version of SBVAL() RSVAL(buf,pos) - like SVAL() but for NMB byte ordering RSVALS(buf,pos) - like SVALS() but for NMB byte ordering @@ -218,7 +222,9 @@ static __inline__ void st_le32(uint32_t *addr, const uint32_t val) #define VWV(vwv) ((vwv)*2) /* 64 bit macros */ -#define SBVAL(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,((uint64_t)(v))>>32)) #define BVAL(p, ofs) (IVAL(p,ofs) | (((uint64_t)IVAL(p,(ofs)+4)) << 32)) +#define BVALS(p, ofs) ((int64_t)BVAL(p,ofs)) +#define SBVAL(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,((uint64_t)(v))>>32)) +#define SBVALS(p, ofs, v) (SBVAL(p,ofs,(uint64_t)v)) #endif /* _BYTEORDER_H */ -- cgit From bc4af8dd5ef900f0ab46f4ddaf91e33772a3e029 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 13 Jan 2007 15:01:39 +0000 Subject: r20730: this can be const metze (This used to be commit 181db920476a9ebddeee1ebea17be0baf85ea59e) --- source4/lib/util/data_blob.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index 3253d52ee7..7230aa9d99 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -150,7 +150,7 @@ _PUBLIC_ BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) /** print the data_blob as hex string **/ -_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, DATA_BLOB *blob) +_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob) { int i; char *hex_string; -- cgit From c186fb94637f2cd502327c38d95c6d7a2b2dbd11 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 13 Jan 2007 15:39:49 +0000 Subject: r20734: always terminate the string... so that an empty data_blob gets '\0' as "" string metze (This used to be commit 4f5daa830a3c02a05ba1bc7f32eedbe1d52640a1) --- source4/lib/util/data_blob.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index 7230aa9d99..e04bd65331 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -163,6 +163,7 @@ _PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob) for (i = 0; i < blob->length; i++) slprintf(&hex_string[i*2], 3, "%02X", blob->data[i]); + hex_string[(blob->length*2)] = '\0'; return hex_string; } -- cgit From 8538af1107a6e894d4941708b77e79fac587e35d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 6 Feb 2007 05:26:25 +0000 Subject: r21174: many thanks to Paul Wayper for pointing out that C99 requires a matching va_end() for each va_copy(). This doesn't matter for most architectures, but there could be some obscure ones where it does matter. some of this should be ported to Samba3 (This used to be commit 21eb316473486cb6b73bb3ff9c5f3a44ecd57e4a) --- source4/lib/util/dprintf.c | 2 +- source4/lib/util/util_file.c | 2 +- source4/lib/util/xfile.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 62dc2a227a..79b90ec3e1 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -39,8 +39,8 @@ _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBU /* do any message translations */ va_copy(ap2, ap); - ret = vasprintf(&p, format, ap2); + va_end(ap2); if (ret <= 0) return ret; diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index 887efb9836..3c44351c50 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -364,8 +364,8 @@ _PUBLIC_ int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE va_list ap2; va_copy(ap2, ap); - len = vasprintf(&p, format, ap2); + va_end(ap2); if (len <= 0) return len; ret = write(fd, p, len); SAFE_FREE(p); diff --git a/source4/lib/util/xfile.c b/source4/lib/util/xfile.c index 1cf77a3220..870cd4c136 100644 --- a/source4/lib/util/xfile.c +++ b/source4/lib/util/xfile.c @@ -203,8 +203,8 @@ size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f) va_list ap2; va_copy(ap2, ap); - len = vasprintf(&p, format, ap2); + va_end(ap2); if (len <= 0) return len; ret = x_fwrite(p, 1, len, f); SAFE_FREE(p); -- cgit From 1afda7bdde90948027e3230c19753280afb16e96 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 2 Mar 2007 14:53:09 +0000 Subject: r21656: Move tests a bit closer to the things they test, should make syncing with samba3 easier. (This used to be commit 4d755fb5d7adedd1dd8bad917b921324411bfd59) --- source4/lib/util/tests/file.c | 95 +++++++++++++++++++++++++++++++++++ source4/lib/util/tests/idtree.c | 104 +++++++++++++++++++++++++++++++++++++++ source4/lib/util/tests/strlist.c | 80 ++++++++++++++++++++++++++++++ 3 files changed, 279 insertions(+) create mode 100644 source4/lib/util/tests/file.c create mode 100644 source4/lib/util/tests/idtree.c create mode 100644 source4/lib/util/tests/strlist.c (limited to 'source4/lib/util') diff --git a/source4/lib/util/tests/file.c b/source4/lib/util/tests/file.c new file mode 100644 index 0000000000..87d25b222e --- /dev/null +++ b/source4/lib/util/tests/file.c @@ -0,0 +1,95 @@ +/* + Unix SMB/CIFS implementation. + + util_file testing + + Copyright (C) Jelmer Vernooij 2005 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/filesys.h" +#include "torture/torture.h" + +#define TEST_FILENAME "utilfile.test" +#define TEST_LINE1 "This is list line 1..." +#define TEST_LINE2 ".. and this is line 2" +#define TEST_LINE3 "and end of the file" + +#define TEST_DATA TEST_LINE1 "\n" TEST_LINE2 "\n" TEST_LINE3 + +static bool test_file_load_save(struct torture_context *tctx) +{ + size_t len; + char *data; + TALLOC_CTX *mem_ctx = tctx; + + torture_assert(tctx, file_save(TEST_FILENAME, TEST_DATA, strlen(TEST_DATA)), + "saving file"); + + data = file_load(TEST_FILENAME, &len, mem_ctx); + torture_assert(tctx, data, "loading file"); + + torture_assert(tctx, len == strlen(TEST_DATA), "Length"); + + torture_assert(tctx, memcmp(data, TEST_DATA, len) == 0, "Contents"); + + unlink(TEST_FILENAME); + return true; +} + + +static bool test_afdgets(struct torture_context *tctx) +{ + int fd; + char *line; + TALLOC_CTX *mem_ctx = tctx; + + torture_assert(tctx, file_save(TEST_FILENAME, (const void *)TEST_DATA, + strlen(TEST_DATA)), + "saving file"); + + fd = open(TEST_FILENAME, O_RDONLY); + + torture_assert(tctx, fd != -1, "opening file"); + + line = afdgets(fd, mem_ctx, 8); + torture_assert(tctx, strcmp(line, TEST_LINE1) == 0, "line 1 mismatch"); + + line = afdgets(fd, mem_ctx, 8); + torture_assert(tctx, strcmp(line, TEST_LINE2) == 0, "line 2 mismatch"); + + line = afdgets(fd, mem_ctx, 8); + torture_assert(tctx, strcmp(line, TEST_LINE3) == 0, "line 3 mismatch"); + + close(fd); + + unlink(TEST_FILENAME); + return true; +} + +struct torture_suite *torture_local_util_file(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = torture_suite_create(mem_ctx, "FILE"); + + torture_suite_add_simple_test(suite, "file_load_save", + test_file_load_save); + + torture_suite_add_simple_test(suite, "afdgets", + test_afdgets); + + return suite; +} diff --git a/source4/lib/util/tests/idtree.c b/source4/lib/util/tests/idtree.c new file mode 100644 index 0000000000..dd8618d0db --- /dev/null +++ b/source4/lib/util/tests/idtree.c @@ -0,0 +1,104 @@ +/* + Unix SMB/CIFS implementation. + + local testing of idtree routines. + + Copyright (C) Andrew Tridgell 2004 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "torture/torture.h" + +static bool torture_local_idtree_simple(struct torture_context *tctx) +{ + struct idr_context *idr; + int i; + int *ids; + int *present; + extern int torture_numops; + int n = torture_numops; + TALLOC_CTX *mem_ctx = tctx; + + idr = idr_init(mem_ctx); + + ids = talloc_zero_array(mem_ctx, int, n); + present = talloc_zero_array(mem_ctx, int, n); + + for (i=0;i Date: Sun, 4 Mar 2007 22:36:41 +0000 Subject: r21688: Add simple tests for genrand (This used to be commit 90f23f0de86bb63ad65556ff2dab8b066236f300) --- source4/lib/util/tests/genrand.c | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 source4/lib/util/tests/genrand.c (limited to 'source4/lib/util') diff --git a/source4/lib/util/tests/genrand.c b/source4/lib/util/tests/genrand.c new file mode 100644 index 0000000000..6160e1d156 --- /dev/null +++ b/source4/lib/util/tests/genrand.c @@ -0,0 +1,66 @@ +/* + Unix SMB/CIFS implementation. + + local testing of random data routines. + + Copyright (C) Jelmer Vernooij + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "torture/torture.h" + +static void dummy_reseed(int *d) +{ + *d = 42; +} + +static bool test_reseed_callback(struct torture_context *tctx) +{ + set_rand_reseed_callback(dummy_reseed); + return true; +} + +static bool test_check_password_quality(struct torture_context *tctx) +{ + torture_assert(tctx, !check_password_quality(""), "empty password"); + torture_assert(tctx, !check_password_quality("a"), "one char password"); + torture_assert(tctx, !check_password_quality("aaaaaaaaaaaa"), "same char password"); + torture_assert(tctx, !check_password_quality("BLA"), "multiple upcases password"); + torture_assert(tctx, !check_password_quality("123"), "digits only"); + torture_assert(tctx, check_password_quality("A2e"), "valid"); + torture_assert(tctx, check_password_quality("BA2eLi443"), "valid"); + return true; +} + +static bool test_generate_random_str(struct torture_context *tctx) +{ + TALLOC_CTX *mem_ctx = talloc_init(__FUNCTION__); + char *r = generate_random_str(mem_ctx, 10); + torture_assert_int_equal(tctx, strlen(r), 10, "right length generated"); + r = generate_random_str(mem_ctx, 5); + torture_assert_int_equal(tctx, strlen(r), 5, "right length generated"); + return true; +} + +struct torture_suite *torture_local_genrand(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = torture_suite_create(mem_ctx, "GENRAND"); + torture_suite_add_simple_test(suite, "reseed_callback", test_reseed_callback); + torture_suite_add_simple_test(suite, "check_password_quality", test_check_password_quality); + torture_suite_add_simple_test(suite, "generate_random_str", test_generate_random_str); + return suite; +} -- cgit From 793db3bc5073083e223d084437c6e751d422416d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 7 Mar 2007 10:00:14 +0000 Subject: r21740: this fixes the real cause of the large log files we had. The problem was we were not checking the result of a convert_string() call, and it was giving -1. We then passed -1 to fwrite() on stdout, which on aix and macosx wrote all of available memory to stdout :) To fix this, replace non-printing chars with ? in d_printf if the string cannot be converted (This used to be commit d20102d363f4b9214e29296ad8ec45c8d95614b5) --- source4/lib/util/dprintf.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 79b90ec3e1..209fb8da36 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -30,6 +30,7 @@ */ #include "includes.h" +#include "system/locale.h" _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) { @@ -54,6 +55,22 @@ again: return -1; } clen = convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); + if (clen == -1) { + /* the string can't be converted - do the best we can, + filling in non-printing chars with '?' */ + int i; + for (i=0;i= maxlen) { /* it didn't fit - try a larger buffer */ -- cgit From bb36705c8d360a2ba865a3d8118c52afa1e46f4e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 15 Apr 2007 21:13:13 +0000 Subject: r22226: move discard_const macros to librelace metze (This used to be commit c2cfee6d25718fac35bd4ed982c7424f1c3ed0b7) --- source4/lib/util/util.h | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index c7acc2ea33..dd6c1499bd 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -107,27 +107,4 @@ extern const char *panic_action; #define strlen(x) valgrind_strlen(x) #endif -/** - this is a warning hack. The idea is to use this everywhere that we - get the "discarding const" warning from gcc. That doesn't actually - fix the problem of course, but it means that when we do get to - cleaning them up we can do it by searching the code for - discard_const. - - It also means that other error types aren't as swamped by the noise - of hundreds of const warnings, so we are more likely to notice when - we get new errors. - - Please only add more uses of this macro when you find it - _really_ hard to fix const warnings. Our aim is to eventually use - this function in only a very few places. - - Also, please call this via the discard_const_p() macro interface, as that - makes the return type safe. -*/ -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) - -/** Type-safe version of discard_const */ -#define discard_const_p(type, ptr) ((type *)discard_const(ptr)) - #endif /* _SAMBA_UTIL_H_ */ -- cgit From 4047b20c368f473081eeb951dff119a6c060c9f7 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 17 Apr 2007 08:03:01 +0000 Subject: r22297: move ZERO_*, ARRAY_SIZE and PTR_DIFF macros into libreplace metze (This used to be commit b69c950858d837d7bd734d418129ade69106a00d) --- source4/lib/util/util.h | 25 ------------------------- 1 file changed, 25 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index dd6c1499bd..cfd77e5a13 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -41,31 +41,6 @@ extern const char *panic_action; #include "util/byteorder.h" #include "lib/util/util_proto.h" -/** - * zero a structure - */ -#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) - -/** - * zero a structure given a pointer to the structure - */ -#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0) - -/** - * zero a structure given a pointer to the structure - no zero check - */ -#define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x))) - -/** - * pointer difference macro - */ -#define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2))) - -/** - * work out how many elements there are in a static array - */ -#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) - /** * assert macros */ -- cgit From f21cdbc9425478674b1624f5d2b23c477f6de316 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 19 Apr 2007 12:51:04 +0000 Subject: r22369: add ZERO_STRUCT() ... macros to lib/util/util.h again to fix the openchange build... we need to remove them from libreplace, but I'll think about that next week. metze (This used to be commit 2243142b46e20825339b4f6ed0e878c18e50e45f) --- source4/lib/util/util.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index cfd77e5a13..f2531aaa85 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -82,4 +82,45 @@ extern const char *panic_action; #define strlen(x) valgrind_strlen(x) #endif +/** + * zero a structure + */ +#ifndef ZERO_STRUCT +#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) +#endif + +/** + * zero a structure given a pointer to the structure + */ +#ifndef ZERO_STRUCTP +#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0) +#endif + +/** + * zero a structure given a pointer to the structure - no zero check + */ +#ifndef ZERO_STRUCTPN +#define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x))) +#endif + +/* zero an array - note that sizeof(array) must work - ie. it must not be a + pointer */ +#ifndef ZERO_ARRAY +#define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x)) +#endif + +/** + * work out how many elements there are in a static array + */ +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) +#endif + +/** + * pointer difference macro + */ +#ifndef PTR_DIFF +#define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2))) +#endif + #endif /* _SAMBA_UTIL_H_ */ -- cgit From 4bb0cb7449960620052cd555854e59d8d8a9babe Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 19 Apr 2007 13:30:07 +0000 Subject: r22371: readd discard_const() to lib/util/util.h metze (This used to be commit 76fbe90596f5f26c09185129d9a4f3e2b42428e1) --- source4/lib/util/util.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index f2531aaa85..8fde661cb7 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -41,6 +41,33 @@ extern const char *panic_action; #include "util/byteorder.h" #include "lib/util/util_proto.h" +/** + this is a warning hack. The idea is to use this everywhere that we + get the "discarding const" warning from gcc. That doesn't actually + fix the problem of course, but it means that when we do get to + cleaning them up we can do it by searching the code for + discard_const. + + It also means that other error types aren't as swamped by the noise + of hundreds of const warnings, so we are more likely to notice when + we get new errors. + + Please only add more uses of this macro when you find it + _really_ hard to fix const warnings. Our aim is to eventually use + this function in only a very few places. + + Also, please call this via the discard_const_p() macro interface, as that + makes the return type safe. +*/ +#ifndef discard_const +#define discard_const(ptr) ((void *)((intptr_t)(ptr))) +#endif + +/** Type-safe version of discard_const */ +#ifndef discard_const_p +#define discard_const_p(type, ptr) ((type *)discard_const(ptr)) +#endif + /** * assert macros */ -- cgit From 6bc249edbfd59532978543fbbb54a98c5853e6ab Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 19 Apr 2007 14:14:11 +0000 Subject: r22372: split out become_daemon() into it's own function this remove the dependency of util.o to swrap_close which causes sometrouble with the pidl tests on some hosts metze (This used to be commit 8cd36c47aaf1098876bceb314cb0a1f39369cb46) --- source4/lib/util/config.mk | 3 ++- source4/lib/util/util.c | 66 ---------------------------------------------- 2 files changed, 2 insertions(+), 67 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index cda42c105a..5ec110e68d 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -26,7 +26,8 @@ OBJ_FILES = xfile.o \ ms_fnmatch.o \ mutex.o \ idtree.o \ - module.o + module.o \ + become_daemon.o PUBLIC_DEPENDENCIES = \ LIBTALLOC LIBCRYPTO \ SOCKET_WRAPPER EXT_NSL \ diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index afa9adbc18..b0eebb0bc7 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -141,42 +141,6 @@ _PUBLIC_ BOOL directory_create_or_exist(const char *dname, uid_t uid, } -/******************************************************************* - Close the low 3 fd's and open dev/null in their place. -********************************************************************/ -static void close_low_fds(BOOL stderr_too) -{ -#ifndef VALGRIND - int fd; - int i; - - close(0); - close(1); - - if (stderr_too) - close(2); - - /* try and use up these file descriptors, so silly - library routines writing to stdout etc won't cause havoc */ - for (i=0;i<3;i++) { - if (i == 2 && !stderr_too) - continue; - - fd = open("/dev/null",O_RDWR,0); - if (fd < 0) - fd = open("/dev/null",O_WRONLY,0); - if (fd < 0) { - DEBUG(0,("Can't open /dev/null\n")); - return; - } - if (fd != i) { - DEBUG(0,("Didn't get file descriptor %d\n",i)); - return; - } - } -#endif -} - /** Set a fd into blocking/nonblocking mode. Uses POSIX O_NONBLOCK if available, else @@ -223,36 +187,6 @@ _PUBLIC_ void msleep(unsigned int t) select(0,NULL,NULL,NULL,&tval); } -/** - Become a daemon, discarding the controlling terminal. -**/ - -_PUBLIC_ void become_daemon(BOOL Fork) -{ - if (Fork) { - if (fork()) { - _exit(0); - } - } - - /* detach from the terminal */ -#ifdef HAVE_SETSID - setsid(); -#elif defined(TIOCNOTTY) - { - int i = open("/dev/tty", O_RDWR, 0); - if (i != -1) { - ioctl(i, (int) TIOCNOTTY, (char *)0); - close(i); - } - } -#endif /* HAVE_SETSID */ - - /* Close fd's 0,1,2. Needed if started by rsh */ - close_low_fds(False); /* Don't close stderr, let the debug system - attach it to the logfile */ -} - /** Get my own name, return in malloc'ed storage. **/ -- cgit From 3c5618fb1b5cf484c528a7c957a5a9f260d75a4a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 19 Apr 2007 14:21:56 +0000 Subject: r22373: move in_list() to util_strlist.c to remove the dependency from util.o to next_token() and strcasecmp_m() with this the pidl tests link better on some hosts metze (This used to be commit 54bfc1dccc40883d602402865eff3cfae676e9af) --- source4/lib/util/util_str.c | 24 ------------------------ source4/lib/util/util_strlist.c | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 24 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 163ef3828e..86cd3176c5 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -25,7 +25,6 @@ #include "includes.h" #include "libcli/raw/smb.h" #include "pstring.h" -#include "lib/ldb/include/ldb.h" #include "system/locale.h" /** @@ -246,29 +245,6 @@ _PUBLIC_ void hex_encode(const unsigned char *buff_in, size_t len, char **out_he slprintf(&hex_buffer[i*2], 3, "%02X", buff_in[i]); } -/** - Check if a string is part of a list. -**/ -_PUBLIC_ BOOL in_list(const char *s, const char *list, BOOL casesensitive) -{ - pstring tok; - const char *p=list; - - if (!list) - return(False); - - while (next_token(&p,tok,LIST_SEP,sizeof(tok))) { - if (casesensitive) { - if (strcmp(tok,s) == 0) - return(True); - } else { - if (strcasecmp_m(tok,s) == 0) - return(True); - } - } - return(False); -} - /** Set a string value, allocing the space for the string **/ diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index 48ddbde9e1..0e9fcd9db9 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -20,6 +20,8 @@ */ #include "includes.h" +#include "pstring.h" +#include "system/locale.h" /** * @file @@ -298,3 +300,26 @@ _PUBLIC_ BOOL str_list_check_ci(const char **list, const char *s) } return False; } + +/** + Check if a string is part of a list. +**/ +_PUBLIC_ BOOL in_list(const char *s, const char *list, BOOL casesensitive) +{ + pstring tok; + const char *p=list; + + if (!list) + return(False); + + while (next_token(&p,tok,LIST_SEP,sizeof(tok))) { + if (casesensitive) { + if (strcmp(tok,s) == 0) + return(True); + } else { + if (strcasecmp_m(tok,s) == 0) + return(True); + } + } + return(False); +} -- cgit From b0ddff0324daf349fa3f779d1bdf96f8c1709462 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 19 Apr 2007 15:56:44 +0000 Subject: r22379: add missing file metze (This used to be commit 893b6f56b6aef14de7b54c57c23b8a2f885ba6ce) --- source4/lib/util/become_daemon.c | 94 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 source4/lib/util/become_daemon.c (limited to 'source4/lib/util') diff --git a/source4/lib/util/become_daemon.c b/source4/lib/util/become_daemon.c new file mode 100644 index 0000000000..a16b081239 --- /dev/null +++ b/source4/lib/util/become_daemon.c @@ -0,0 +1,94 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Jeremy Allison 2001-2002 + Copyright (C) Simo Sorce 2001 + Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003. + Copyright (C) James J Myers 2003 + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/filesys.h" +#include "system/locale.h" + +/******************************************************************* + Close the low 3 fd's and open dev/null in their place. +********************************************************************/ +static void close_low_fds(BOOL stderr_too) +{ +#ifndef VALGRIND + int fd; + int i; + + close(0); + close(1); + + if (stderr_too) + close(2); + + /* try and use up these file descriptors, so silly + library routines writing to stdout etc won't cause havoc */ + for (i=0;i<3;i++) { + if (i == 2 && !stderr_too) + continue; + + fd = open("/dev/null",O_RDWR,0); + if (fd < 0) + fd = open("/dev/null",O_WRONLY,0); + if (fd < 0) { + DEBUG(0,("Can't open /dev/null\n")); + return; + } + if (fd != i) { + DEBUG(0,("Didn't get file descriptor %d\n",i)); + return; + } + } +#endif +} + +/** + Become a daemon, discarding the controlling terminal. +**/ + +_PUBLIC_ void become_daemon(BOOL Fork) +{ + if (Fork) { + if (fork()) { + _exit(0); + } + } + + /* detach from the terminal */ +#ifdef HAVE_SETSID + setsid(); +#elif defined(TIOCNOTTY) + { + int i = open("/dev/tty", O_RDWR, 0); + if (i != -1) { + ioctl(i, (int) TIOCNOTTY, (char *)0); + close(i); + } + } +#endif /* HAVE_SETSID */ + + /* Close fd's 0,1,2. Needed if started by rsh */ + close_low_fds(False); /* Don't close stderr, let the debug system + attach it to the logfile */ +} + -- cgit From 36d7186e72adea723f67a706106c0d07d5f01379 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 20 May 2007 10:21:14 +0000 Subject: r23021: test some boundary conditions for idtree, after I saw some suspicious behaviour (This used to be commit e862cf17b891885f3a733819869a06895c1fb324) --- source4/lib/util/tests/idtree.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/tests/idtree.c b/source4/lib/util/tests/idtree.c index dd8618d0db..a9770d789b 100644 --- a/source4/lib/util/tests/idtree.c +++ b/source4/lib/util/tests/idtree.c @@ -26,7 +26,7 @@ static bool torture_local_idtree_simple(struct torture_context *tctx) { struct idr_context *idr; - int i; + int i, ret; int *ids; int *present; extern int torture_numops; @@ -92,6 +92,23 @@ static bool torture_local_idtree_simple(struct torture_context *tctx) } } + /* now test some limits */ + for (i=0;i<25000;i++) { + ret = idr_get_new_above(idr, &ids[0], random() % 25000, 0x10000-3); + torture_assert(tctx, ret != -1, "idr_get_new_above failed"); + } + + ret = idr_get_new_above(idr, &ids[0], 0x10000-2, 0x10000); + torture_assert_int_equal(tctx, ret, 0x10000-2, "idr_get_new_above failed"); + ret = idr_get_new_above(idr, &ids[0], 0x10000-1, 0x10000); + torture_assert_int_equal(tctx, ret, 0x10000-1, "idr_get_new_above failed"); + ret = idr_get_new_above(idr, &ids[0], 0x10000, 0x10000); + torture_assert_int_equal(tctx, ret, 0x10000, "idr_get_new_above failed"); + ret = idr_get_new_above(idr, &ids[0], 0x10000+1, 0x10000); + torture_assert_int_equal(tctx, ret, -1, "idr_get_new_above succeeded above limit"); + ret = idr_get_new_above(idr, &ids[0], 0x10000+2, 0x10000); + torture_assert_int_equal(tctx, ret, -1, "idr_get_new_above succeeded above limit"); + torture_comment(tctx, "cleaned up\n"); return true; } -- cgit From c2781df0d5477be58c3189c6d3c17b261d7b8b89 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 1 Jun 2007 12:01:53 +0000 Subject: r23289: Provide support for GCC attributes _PURE_, _NONNULL_, _DEPRECATED_, _NORETURN_ and _WARN_UNUSED_RESULT_. (This used to be commit 44248f662f0b609dad6a7b437948f12d661a28f7) --- source4/lib/util/fault.c | 2 +- source4/lib/util/util_str.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index c7d6b7ede6..86a0b61a76 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -118,7 +118,7 @@ _PUBLIC_ const char *panic_action = NULL; /** Something really nasty happened - panic ! **/ -_PUBLIC_ void smb_panic(const char *why) +_PUBLIC_ _NORETURN_ void smb_panic(const char *why) { int result; diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 86cd3176c5..c088e26fe5 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -36,16 +36,16 @@ /** Trim the specified elements off the front and back of a string. **/ -_PUBLIC_ BOOL trim_string(char *s,const char *front,const char *back) +_PUBLIC_ bool trim_string(char *s, const char *front, const char *back) { - BOOL ret = False; + bool ret = false; size_t front_len; size_t back_len; size_t len; /* Ignore null or empty strings. */ if (!s || (s[0] == '\0')) - return False; + return false; front_len = front? strlen(front) : 0; back_len = back? strlen(back) : 0; @@ -58,7 +58,7 @@ _PUBLIC_ BOOL trim_string(char *s,const char *front,const char *back) * easily overlap. Found by valgrind. JRA. */ memmove(s, s+front_len, (len-front_len)+1); len -= front_len; - ret=True; + ret=true; } } @@ -66,7 +66,7 @@ _PUBLIC_ BOOL trim_string(char *s,const char *front,const char *back) while ((len >= back_len) && strncmp(s+len-back_len,back,back_len)==0) { s[len-back_len]='\0'; len -= back_len; - ret=True; + ret=true; } } return ret; @@ -75,7 +75,7 @@ _PUBLIC_ BOOL trim_string(char *s,const char *front,const char *back) /** Find the number of 'c' chars in a string **/ -_PUBLIC_ size_t count_chars(const char *s, char c) +_PUBLIC_ _PURE_ size_t count_chars(const char *s, char c) { size_t count = 0; @@ -218,7 +218,7 @@ _PUBLIC_ size_t strhex_to_str(char *p, size_t len, const char *strhex) /** * Parse a hex string and return a data blob. */ -_PUBLIC_ DATA_BLOB strhex_to_data_blob(const char *strhex) +_PUBLIC_ _PURE_ DATA_BLOB strhex_to_data_blob(const char *strhex) { DATA_BLOB ret_blob = data_blob(NULL, strlen(strhex)/2+1); -- cgit From d291b8bf933e7595ac2967602d90918c286e3429 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 20 Jun 2007 04:15:39 +0000 Subject: r23551: Change data_blob_equal to data_blob_cmp, suitable for sorting with qsort(). Andrew Bartlett (This used to be commit 96ef5259c63ad6245c94c40d6059d736b1534183) --- source4/lib/util/data_blob.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index e04bd65331..ca04b70eb2 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -130,21 +130,23 @@ _PUBLIC_ void data_blob_clear_free(DATA_BLOB *d) /** check if two data blobs are equal **/ -_PUBLIC_ BOOL data_blob_equal(const DATA_BLOB *d1, const DATA_BLOB *d2) +_PUBLIC_ int data_blob_cmp(const DATA_BLOB *d1, const DATA_BLOB *d2) { - if (d1->length != d2->length) { - return False; + int ret; + if (d1->data == NULL && d2->data != NULL) { + return -1; } - if (d1->data == d2->data) { - return True; + if (d1->data != NULL && d2->data == NULL) { + return 1; } - if (d1->data == NULL || d2->data == NULL) { - return False; + if (d1->data == d2->data) { + return d1->length - d2->length; } - if (memcmp(d1->data, d2->data, d1->length) == 0) { - return True; + ret = memcmp(d1->data, d2->data, MIN(d1->length, d2->length)); + if (ret == 0) { + return d1->length - d2->length; } - return False; + return ret; } /** -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/lib/util/become_daemon.c | 5 ++--- source4/lib/util/byteorder.h | 5 ++--- source4/lib/util/capability.c | 5 ++--- source4/lib/util/data_blob.c | 5 ++--- source4/lib/util/debug.c | 5 ++--- source4/lib/util/debug.h | 5 ++--- source4/lib/util/dlinklist.h | 5 ++--- source4/lib/util/dprintf.c | 5 ++--- source4/lib/util/fault.c | 5 ++--- source4/lib/util/fsusage.c | 5 ++--- source4/lib/util/genrand.c | 5 ++--- source4/lib/util/idtree.c | 5 ++--- source4/lib/util/module.c | 5 ++--- source4/lib/util/ms_fnmatch.c | 5 ++--- source4/lib/util/mutex.c | 5 ++--- source4/lib/util/mutex.h | 5 ++--- source4/lib/util/safe_string.h | 5 ++--- source4/lib/util/signal.c | 5 ++--- source4/lib/util/system.c | 5 ++--- source4/lib/util/tests/file.c | 5 ++--- source4/lib/util/tests/genrand.c | 5 ++--- source4/lib/util/tests/idtree.c | 5 ++--- source4/lib/util/tests/strlist.c | 5 ++--- source4/lib/util/time.c | 5 ++--- source4/lib/util/unix_privs.c | 5 ++--- source4/lib/util/util.c | 5 ++--- source4/lib/util/util.h | 5 ++--- source4/lib/util/util_getent.c | 5 ++--- source4/lib/util/util_pw.c | 5 ++--- source4/lib/util/util_str.c | 5 ++--- source4/lib/util/util_strlist.c | 5 ++--- source4/lib/util/util_tdb.c | 5 ++--- source4/lib/util/wrap_xattr.c | 5 ++--- source4/lib/util/xfile.c | 5 ++--- source4/lib/util/xfile.h | 5 ++--- 35 files changed, 70 insertions(+), 105 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/become_daemon.c b/source4/lib/util/become_daemon.c index a16b081239..2a01cea286 100644 --- a/source4/lib/util/become_daemon.c +++ b/source4/lib/util/become_daemon.c @@ -9,7 +9,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -18,8 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/byteorder.h b/source4/lib/util/byteorder.h index 823287f075..857bd1d50b 100644 --- a/source4/lib/util/byteorder.h +++ b/source4/lib/util/byteorder.h @@ -5,7 +5,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #ifndef _BYTEORDER_H diff --git a/source4/lib/util/capability.c b/source4/lib/util/capability.c index 7d8222fe11..d42d13e008 100644 --- a/source4/lib/util/capability.c +++ b/source4/lib/util/capability.c @@ -6,7 +6,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ /** diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index ca04b70eb2..df8e793835 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -6,7 +6,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index 9084c2b406..c29b3bfaec 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -6,7 +6,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/debug.h b/source4/lib/util/debug.h index 80155cdccf..2f090359a5 100644 --- a/source4/lib/util/debug.h +++ b/source4/lib/util/debug.h @@ -5,7 +5,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ /** diff --git a/source4/lib/util/dlinklist.h b/source4/lib/util/dlinklist.h index f267e77ea6..5624124459 100644 --- a/source4/lib/util/dlinklist.h +++ b/source4/lib/util/dlinklist.h @@ -5,7 +5,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ /* To use these macros you must have a structure containing a next and diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 209fb8da36..a7770f364d 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -5,7 +5,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index 86a0b61a76..8bfcdff0d1 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -5,7 +5,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/fsusage.c b/source4/lib/util/fsusage.c index 96b5ee4f59..43c8787216 100644 --- a/source4/lib/util/fsusage.c +++ b/source4/lib/util/fsusage.c @@ -5,7 +5,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/genrand.c b/source4/lib/util/genrand.c index 8424ad8fd7..b1fde41ee3 100644 --- a/source4/lib/util/genrand.c +++ b/source4/lib/util/genrand.c @@ -7,7 +7,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/idtree.c b/source4/lib/util/idtree.c index 46c979f546..1e2cc2976a 100644 --- a/source4/lib/util/idtree.c +++ b/source4/lib/util/idtree.c @@ -12,7 +12,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -21,8 +21,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ /* diff --git a/source4/lib/util/module.c b/source4/lib/util/module.c index 597be90478..096b21b8a9 100644 --- a/source4/lib/util/module.c +++ b/source4/lib/util/module.c @@ -5,7 +5,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ /** diff --git a/source4/lib/util/ms_fnmatch.c b/source4/lib/util/ms_fnmatch.c index a4fca4fa0a..8e216b0226 100644 --- a/source4/lib/util/ms_fnmatch.c +++ b/source4/lib/util/ms_fnmatch.c @@ -5,7 +5,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ /* diff --git a/source4/lib/util/mutex.c b/source4/lib/util/mutex.c index 3b64f4929b..ec7e9dfd2e 100644 --- a/source4/lib/util/mutex.c +++ b/source4/lib/util/mutex.c @@ -6,7 +6,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" #include "mutex.h" diff --git a/source4/lib/util/mutex.h b/source4/lib/util/mutex.h index bdc7bc7e7a..bf845906f2 100644 --- a/source4/lib/util/mutex.h +++ b/source4/lib/util/mutex.h @@ -8,7 +8,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -17,8 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ /** diff --git a/source4/lib/util/safe_string.h b/source4/lib/util/safe_string.h index ff4cd5398f..a6c052f874 100644 --- a/source4/lib/util/safe_string.h +++ b/source4/lib/util/safe_string.h @@ -5,7 +5,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #ifndef _SAFE_STRING_H diff --git a/source4/lib/util/signal.c b/source4/lib/util/signal.c index a0cb90dbf6..5639f98416 100644 --- a/source4/lib/util/signal.c +++ b/source4/lib/util/signal.c @@ -6,7 +6,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/system.c b/source4/lib/util/system.c index 9fec2a50e3..1ebc6e7e0f 100644 --- a/source4/lib/util/system.c +++ b/source4/lib/util/system.c @@ -6,7 +6,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/tests/file.c b/source4/lib/util/tests/file.c index 87d25b222e..66a3b81dca 100644 --- a/source4/lib/util/tests/file.c +++ b/source4/lib/util/tests/file.c @@ -7,7 +7,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/tests/genrand.c b/source4/lib/util/tests/genrand.c index 6160e1d156..205a66352f 100644 --- a/source4/lib/util/tests/genrand.c +++ b/source4/lib/util/tests/genrand.c @@ -7,7 +7,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/tests/idtree.c b/source4/lib/util/tests/idtree.c index a9770d789b..448abb5c04 100644 --- a/source4/lib/util/tests/idtree.c +++ b/source4/lib/util/tests/idtree.c @@ -7,7 +7,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/tests/strlist.c b/source4/lib/util/tests/strlist.c index 7dbb5f8ce6..689e03e54a 100644 --- a/source4/lib/util/tests/strlist.c +++ b/source4/lib/util/tests/strlist.c @@ -7,7 +7,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/time.c b/source4/lib/util/time.c index d3cdecdfe3..e5d7e2bca5 100644 --- a/source4/lib/util/time.c +++ b/source4/lib/util/time.c @@ -7,7 +7,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/unix_privs.c b/source4/lib/util/unix_privs.c index bf3e61ba2d..47c172dcfa 100644 --- a/source4/lib/util/unix_privs.c +++ b/source4/lib/util/unix_privs.c @@ -7,7 +7,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index b0eebb0bc7..e43bb98c1e 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -9,7 +9,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -18,8 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 8fde661cb7..f19b243f64 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -6,7 +6,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #ifndef _SAMBA_UTIL_H_ diff --git a/source4/lib/util/util_getent.c b/source4/lib/util/util_getent.c index 9f58472fb8..b9b2658f59 100644 --- a/source4/lib/util/util_getent.c +++ b/source4/lib/util/util_getent.c @@ -6,7 +6,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/util_pw.c b/source4/lib/util/util_pw.c index 19893e396f..0e0675571e 100644 --- a/source4/lib/util/util_pw.c +++ b/source4/lib/util/util_pw.c @@ -7,7 +7,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index c088e26fe5..80a22773d4 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -9,7 +9,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -18,8 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index 0e9fcd9db9..cd0e1cdac0 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -6,7 +6,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/util_tdb.c b/source4/lib/util/util_tdb.c index 820fc2dbb1..6c95b58893 100644 --- a/source4/lib/util/util_tdb.c +++ b/source4/lib/util/util_tdb.c @@ -7,7 +7,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/wrap_xattr.c b/source4/lib/util/wrap_xattr.c index 4e4470839e..955f39a7eb 100644 --- a/source4/lib/util/wrap_xattr.c +++ b/source4/lib/util/wrap_xattr.c @@ -7,7 +7,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/lib/util/xfile.c b/source4/lib/util/xfile.c index 870cd4c136..8b90e30868 100644 --- a/source4/lib/util/xfile.c +++ b/source4/lib/util/xfile.c @@ -5,7 +5,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ /** diff --git a/source4/lib/util/xfile.h b/source4/lib/util/xfile.h index 89fa9d1e11..ffe4481a64 100644 --- a/source4/lib/util/xfile.h +++ b/source4/lib/util/xfile.h @@ -5,7 +5,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #ifndef _XFILE_H_ -- cgit From 4b71c210d5aa01fc5934ea1777a1c8a7ed1e1f37 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 03:04:16 +0000 Subject: r23796: main COPYING file for samba4, plus some formatting varients (This used to be commit 76c6bfdeb51b5673bbabe0ca3d8bff3b74a327ee) --- source4/lib/util/util_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index 3c44351c50..df4cb902f0 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -7,7 +7,7 @@ * * 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 the Free - * Software Foundation; either version 2 of the License, or (at your option) + * Software Foundation; either version 3 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT -- cgit From cd1217ff5ff18e53c6c9fa3d4f4fd56193fe2a17 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 5c9b19271e0e3ad897499707003ce4703ffa4870) --- source4/lib/util/util_file.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index df4cb902f0..a7ba048692 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -16,8 +16,7 @@ * more details. * * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 675 - * Mass Ave, Cambridge, MA 02139, USA. + * this program; if not, see . */ #include "includes.h" -- cgit From 702372b343cd764b51f29fc0d6bf512197d2372d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 08:07:42 +0000 Subject: r23807: added hex_encode_talloc() (This used to be commit 1b105097e3f4a8475d3a2623205ecdea2aef91cf) --- source4/lib/util/util_str.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 80a22773d4..baa42e806a 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -244,6 +244,22 @@ _PUBLIC_ void hex_encode(const unsigned char *buff_in, size_t len, char **out_he slprintf(&hex_buffer[i*2], 3, "%02X", buff_in[i]); } +/** + * talloc version of hex_encode() + */ +_PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len) +{ + int i; + char *hex_buffer; + + hex_buffer = talloc_array(mem_ctx, char, (len*2)+1); + + for (i = 0; i < len; i++) + slprintf(&hex_buffer[i*2], 3, "%02X", buff_in[i]); + + return hex_buffer; +} + /** Set a string value, allocing the space for the string **/ -- cgit From edca65915afbfde51ab75a27d5ebcb5ab0c85f20 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 8 Aug 2007 02:41:12 +0000 Subject: r24273: Fix bug #4817 by . (Unable to add a computer from MMC Active Directory Users and Computers). Windows sets a 14 UCS2 char buffer as the password in this case. We need to allow random buffers to be accepted as complex passwords, even if they don't have ASCII upper or lower case characters. (If half the bytes are > 127, then it's likely a random buffer). Also make the test match the documented windows behaviour of '3 of the 4 classes: upper, lower, digit, special'. Andrew Bartlett (This used to be commit 5ef26a2ba3561580f0a73ee61eb707573cc98cd3) --- source4/lib/util/genrand.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/genrand.c b/source4/lib/util/genrand.c index b1fde41ee3..2c3875750e 100644 --- a/source4/lib/util/genrand.c +++ b/source4/lib/util/genrand.c @@ -265,19 +265,24 @@ _PUBLIC_ uint32_t generate_random(void) **/ _PUBLIC_ BOOL check_password_quality(const char *s) { - int has_digit=0, has_capital=0, has_lower=0; + int has_digit=0, has_capital=0, has_lower=0, has_special=0, has_high=0; while (*s) { if (isdigit((unsigned char)*s)) { - has_digit++; + has_digit |= 1; } else if (isupper((unsigned char)*s)) { - has_capital++; + has_capital |= 1; } else if (islower((unsigned char)*s)) { - has_lower++; + has_lower |= 1; + } else if (isascii((unsigned char)*s)) { + has_special |= 1; + } else { + has_high++; } s++; } - return has_digit && has_lower && has_capital; + return ((has_digit + has_lower + has_capital + has_special) >= 3 + || (has_high > strlen(s)/2)); } /** -- cgit From a43b026ef0e9c1ffd24130c35275f02326bfc9c7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 11 Aug 2007 17:08:22 +0000 Subject: r24333: Add convenience function for checking the contents of a file in tests. (This used to be commit 4e304101241ea7bcb9111b757bb51b16665d492d) --- source4/lib/util/tests/file.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/tests/file.c b/source4/lib/util/tests/file.c index 66a3b81dca..0fe117a300 100644 --- a/source4/lib/util/tests/file.c +++ b/source4/lib/util/tests/file.c @@ -39,6 +39,9 @@ static bool test_file_load_save(struct torture_context *tctx) torture_assert(tctx, file_save(TEST_FILENAME, TEST_DATA, strlen(TEST_DATA)), "saving file"); + torture_assert_file_contains_text(tctx, TEST_FILENAME, TEST_DATA, + "file contents"); + data = file_load(TEST_FILENAME, &len, mem_ctx); torture_assert(tctx, data, "loading file"); -- cgit From dfa4e5f78440e375a9c47eab913c5980c1aa640b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 23 Aug 2007 02:10:17 +0000 Subject: r24631: Fix up format warnings, found on my Fedora 7 x86_64 workstation. Andrew Bartlett (This used to be commit 3d74d178bfd89127ff387939e848b240e638cc35) --- source4/lib/util/tests/idtree.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/tests/idtree.c b/source4/lib/util/tests/idtree.c index 448abb5c04..d89fb8c489 100644 --- a/source4/lib/util/tests/idtree.c +++ b/source4/lib/util/tests/idtree.c @@ -61,10 +61,11 @@ static bool torture_local_idtree_simple(struct torture_context *tctx) } } else { if (p != NULL) { - torture_fail(tctx, talloc_asprintf(tctx, - "non-present at %d gave %p (would be %d)", - ii, p, - (int)(((char *)p) - (char *)(&ids[0])) / sizeof(int))); + torture_fail(tctx, + talloc_asprintf(tctx, + "non-present at %d gave %p (would be %d)", + ii, p, + (int)((((char *)p) - (char *)(&ids[0])) / sizeof(int)))); } if (random() % 5) { ids[ii] = idr_get_new(idr, &ids[ii], n); -- cgit From b409d4120f9ae451f93a2322267c0f346531d9f3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 26 Aug 2007 15:16:40 +0000 Subject: r24667: Finally merge the registry improvements that Wilco Baan Hofman and I have been working on for at least half a year now. Contains the following improvements: * proper layering (finally!) for the registry library. Distinction is now made between 'real' backends (local, remote, wine, etc) and the low-level hive backends (regf, creg, ldb, ...) that are only used by the local registry backend * tests for all important hive and registry operations * re-enable RPC-WINREG tests (still needs more work though, as some return values aren't checked yet) * write support for REGF files * dir backend now supports setting/reading values, creating keys * support for storing security descriptors * remove CREG backend as it was incomplete, didn't match the data model and wasn't used at all anyway * support for parsing ADM files as used by the policy editor (see lib/policy) * support for parsing PREG files (format used by .POL files) * new streaming interface for registry diffs (improves speed and memory usage for regdiff/regpatch significantly) ... and fixes a large number of bugs in the registry code (This used to be commit 7a1eec6358bc863dfc671c542b7185d3e39d7b5a) --- source4/lib/util/become_daemon.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/become_daemon.c b/source4/lib/util/become_daemon.c index 2a01cea286..034114eade 100644 --- a/source4/lib/util/become_daemon.c +++ b/source4/lib/util/become_daemon.c @@ -28,7 +28,7 @@ /******************************************************************* Close the low 3 fd's and open dev/null in their place. ********************************************************************/ -static void close_low_fds(BOOL stderr_too) +static void close_low_fds(bool stderr_too) { #ifndef VALGRIND int fd; @@ -65,7 +65,7 @@ static void close_low_fds(BOOL stderr_too) Become a daemon, discarding the controlling terminal. **/ -_PUBLIC_ void become_daemon(BOOL Fork) +_PUBLIC_ void become_daemon(bool Fork) { if (Fork) { if (fork()) { @@ -87,7 +87,7 @@ _PUBLIC_ void become_daemon(BOOL Fork) #endif /* HAVE_SETSID */ /* Close fd's 0,1,2. Needed if started by rsh */ - close_low_fds(False); /* Don't close stderr, let the debug system + close_low_fds(false); /* Don't close stderr, let the debug system attach it to the logfile */ } -- cgit From 4fb038b0b8e7a4bb69ac0d9022684eeaca8a491a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 27 Aug 2007 17:21:16 +0000 Subject: r24710: Use standard boolean type for easier use by external users. (This used to be commit 99f4124137d4a61216e8189f26d4da32882c0f4a) --- source4/lib/util/capability.c | 16 +++++----- source4/lib/util/debug.c | 13 ++++---- source4/lib/util/debug.h | 4 +-- source4/lib/util/fault.c | 6 ++-- source4/lib/util/genrand.c | 16 +++++----- source4/lib/util/module.c | 10 +++---- source4/lib/util/mutex.c | 6 ++-- source4/lib/util/signal.c | 2 +- source4/lib/util/tests/strlist.c | 8 ++--- source4/lib/util/time.c | 16 +++++----- source4/lib/util/util.c | 58 ++++++++++++++++++------------------ source4/lib/util/util_file.c | 14 ++++----- source4/lib/util/util_str.c | 64 ++++++++++++++++++++-------------------- source4/lib/util/util_strlist.c | 34 ++++++++++----------- source4/lib/util/util_tdb.c | 24 +++++++-------- 15 files changed, 146 insertions(+), 145 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/capability.c b/source4/lib/util/capability.c index d42d13e008..2d13826c14 100644 --- a/source4/lib/util/capability.c +++ b/source4/lib/util/capability.c @@ -37,7 +37,7 @@ /************************************************************************** Try and abstract process capabilities (for systems that have them). ****************************************************************************/ -static BOOL set_process_capability( uint32_t cap_flag, BOOL enable ) +static bool set_process_capability( uint32_t cap_flag, bool enable ) { if(cap_flag == KERNEL_OPLOCK_CAPABILITY) { cap_t cap = cap_get_proc(); @@ -45,7 +45,7 @@ static BOOL set_process_capability( uint32_t cap_flag, BOOL enable ) if (cap == NULL) { DEBUG(0,("set_process_capability: cap_get_proc failed. Error was %s\n", strerror(errno))); - return False; + return false; } if(enable) @@ -57,21 +57,21 @@ static BOOL set_process_capability( uint32_t cap_flag, BOOL enable ) DEBUG(0,("set_process_capability: cap_set_proc failed. Error was %s\n", strerror(errno))); cap_free(cap); - return False; + return false; } cap_free(cap); DEBUG(10,("set_process_capability: Set KERNEL_OPLOCK_CAPABILITY.\n")); } - return True; + return true; } /************************************************************************** Try and abstract inherited process capabilities (for systems that have them). ****************************************************************************/ -static BOOL set_inherited_process_capability( uint32_t cap_flag, BOOL enable ) +static bool set_inherited_process_capability( uint32_t cap_flag, bool enable ) { if(cap_flag == KERNEL_OPLOCK_CAPABILITY) { cap_t cap = cap_get_proc(); @@ -79,7 +79,7 @@ static BOOL set_inherited_process_capability( uint32_t cap_flag, BOOL enable ) if (cap == NULL) { DEBUG(0,("set_inherited_process_capability: cap_get_proc failed. Error was %s\n", strerror(errno))); - return False; + return false; } if(enable) @@ -91,13 +91,13 @@ static BOOL set_inherited_process_capability( uint32_t cap_flag, BOOL enable ) DEBUG(0,("set_inherited_process_capability: cap_set_proc failed. Error was %s\n", strerror(errno))); cap_free(cap); - return False; + return false; } cap_free(cap); DEBUG(10,("set_inherited_process_capability: Set KERNEL_OPLOCK_CAPABILITY.\n")); } - return True; + return true; } #endif diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index c29b3bfaec..67663cb6ce 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -46,22 +46,23 @@ static struct { const char *prog_name; } state; -static BOOL reopen_logs_scheduled; -static BOOL check_reopen_logs(void) +static bool reopen_logs_scheduled; +static bool check_reopen_logs(void) { if (state.fd == 0 || reopen_logs_scheduled) { - reopen_logs_scheduled = False; + reopen_logs_scheduled = false; reopen_logs(); } - if (state.fd <= 0) return False; + if (state.fd <= 0) + return false; - return True; + return true; } _PUBLIC_ void debug_schedule_reopen_logs(void) { - reopen_logs_scheduled = True; + reopen_logs_scheduled = true; } static void log_timestring(int level, const char *location, const char *func) diff --git a/source4/lib/util/debug.h b/source4/lib/util/debug.h index 2f090359a5..4fa2e9f598 100644 --- a/source4/lib/util/debug.h +++ b/source4/lib/util/debug.h @@ -53,11 +53,11 @@ extern int DEBUGLEVEL; /** * Write to the debug log. */ -#define DEBUG(level, body) _DEBUG(level, body, True) +#define DEBUG(level, body) _DEBUG(level, body, true) /** * Add data to an existing debug log entry. */ -#define DEBUGADD(level, body) _DEBUG(level, body, False) +#define DEBUGADD(level, body) _DEBUG(level, body, false) /** * Obtain indentation string for the debug log. diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index 8bfcdff0d1..5cc9445407 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -208,18 +208,18 @@ _PUBLIC_ void fault_setup(const char *pname) register a fault handler. Should only be called once in the execution of smbd. */ -_PUBLIC_ BOOL register_fault_handler(const char *name, void (*fault_handler)(int sig)) +_PUBLIC_ bool register_fault_handler(const char *name, void (*fault_handler)(int sig)) { if (fault_handlers.name != NULL) { /* it's already registered! */ DEBUG(2,("fault handler '%s' already registered - failed '%s'\n", fault_handlers.name, name)); - return False; + return false; } fault_handlers.name = name; fault_handlers.fault_handler = fault_handler; DEBUG(2,("fault handler '%s' registered\n", name)); - return True; + return true; } diff --git a/source4/lib/util/genrand.c b/source4/lib/util/genrand.c index 2c3875750e..4d976cecf8 100644 --- a/source4/lib/util/genrand.c +++ b/source4/lib/util/genrand.c @@ -32,7 +32,7 @@ static unsigned char hash[258]; static uint32_t counter; -static BOOL done_reseed = False; +static bool done_reseed = false; static void (*reseed_callback)(int *newseed); /** @@ -50,7 +50,7 @@ _PUBLIC_ void set_rand_reseed_callback(void (*fn)(int *)) */ _PUBLIC_ void set_need_random_reseed(void) { - done_reseed = False; + done_reseed = false; } static void get_rand_reseed_data(int *reseed_data) @@ -156,7 +156,7 @@ static void do_filehash(const char *fname, unsigned char *the_hash) above... **************************************************************/ -static int do_reseed(BOOL use_fd, int fd) +static int do_reseed(bool use_fd, int fd) { unsigned char seed_inbuf[40]; uint32_t v1, v2; struct timeval tval; pid_t mypid; @@ -214,8 +214,8 @@ _PUBLIC_ void generate_random_buffer(uint8_t *out, int len) unsigned char *p; if(!done_reseed) { - urand_fd = do_reseed(True, urand_fd); - done_reseed = True; + urand_fd = do_reseed(true, urand_fd); + done_reseed = true; } if (urand_fd != -1 && len > 0) { @@ -226,8 +226,8 @@ _PUBLIC_ void generate_random_buffer(uint8_t *out, int len) /* Read of urand error, drop back to non urand method. */ close(urand_fd); urand_fd = -1; - do_reseed(False, -1); - done_reseed = True; + do_reseed(false, -1); + done_reseed = true; } /* @@ -263,7 +263,7 @@ _PUBLIC_ uint32_t generate_random(void) /** very basic password quality checker **/ -_PUBLIC_ BOOL check_password_quality(const char *s) +_PUBLIC_ bool check_password_quality(const char *s) { int has_digit=0, has_capital=0, has_lower=0, has_special=0, has_high=0; while (*s) { diff --git a/source4/lib/util/module.c b/source4/lib/util/module.c index 096b21b8a9..170ea0bacb 100644 --- a/source4/lib/util/module.c +++ b/source4/lib/util/module.c @@ -95,17 +95,17 @@ _PUBLIC_ init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path) /** * Run the specified init functions. * - * @return True if all functions ran successfully, False otherwise + * @return true if all functions ran successfully, false otherwise */ -_PUBLIC_ BOOL run_init_functions(NTSTATUS (**fns) (void)) +_PUBLIC_ bool run_init_functions(NTSTATUS (**fns) (void)) { int i; - BOOL ret = True; + bool ret = true; if (fns == NULL) - return True; + return true; - for (i = 0; fns[i]; i++) { ret &= (BOOL)NT_STATUS_IS_OK(fns[i]()); } + for (i = 0; fns[i]; i++) { ret &= (bool)NT_STATUS_IS_OK(fns[i]()); } return ret; } diff --git a/source4/lib/util/mutex.c b/source4/lib/util/mutex.c index ec7e9dfd2e..4d0df68eed 100644 --- a/source4/lib/util/mutex.c +++ b/source4/lib/util/mutex.c @@ -38,19 +38,19 @@ static struct { register a set of mutex/rwlock handlers. Should only be called once in the execution of smbd. */ -_PUBLIC_ BOOL register_mutex_handlers(const char *name, struct mutex_ops *ops) +_PUBLIC_ bool register_mutex_handlers(const char *name, struct mutex_ops *ops) { if (mutex_handlers.name != NULL) { /* it's already registered! */ DEBUG(2,("mutex handler '%s' already registered - failed '%s'\n", mutex_handlers.name, name)); - return False; + return false; } mutex_handlers.name = name; mutex_handlers.ops = *ops; DEBUG(2,("mutex handler '%s' registered\n", name)); - return True; + return true; } diff --git a/source4/lib/util/signal.c b/source4/lib/util/signal.c index 5639f98416..ead947eb5e 100644 --- a/source4/lib/util/signal.c +++ b/source4/lib/util/signal.c @@ -69,7 +69,7 @@ static void sig_cld_leave_status(int signum) Block sigs. **/ -void BlockSignals(BOOL block,int signum) +void BlockSignals(bool block, int signum) { #ifdef HAVE_SIGPROCMASK sigset_t set; diff --git a/source4/lib/util/tests/strlist.c b/source4/lib/util/tests/strlist.c index 689e03e54a..41accd4bd2 100644 --- a/source4/lib/util/tests/strlist.c +++ b/source4/lib/util/tests/strlist.c @@ -37,7 +37,7 @@ static bool test_lists_shell(struct torture_context *tctx, { const char *data = test_data; const char **ret1, **ret2, *tmp; - BOOL match = True; + bool match = true; TALLOC_CTX *mem_ctx = tctx; ret1 = str_list_make_shell(mem_ctx, data, " "); @@ -45,18 +45,18 @@ static bool test_lists_shell(struct torture_context *tctx, ret2 = str_list_make_shell(mem_ctx, tmp, " "); if ((ret1 == NULL || ret2 == NULL) && ret2 != ret1) { - match = False; + match = false; } else { int j; for (j = 0; ret1[j] && ret2[j]; j++) { if (strcmp(ret1[j], ret2[j]) != 0) { - match = False; + match = false; break; } } if (ret1[j] || ret2[j]) - match = False; + match = false; } torture_assert(tctx, match, talloc_asprintf(tctx, diff --git a/source4/lib/util/time.c b/source4/lib/util/time.c index e5d7e2bca5..c800fffea0 100644 --- a/source4/lib/util/time.c +++ b/source4/lib/util/time.c @@ -116,7 +116,7 @@ _PUBLIC_ void unix_to_nt_time(NTTIME *nt, time_t t) /** check if it's a null unix time **/ -_PUBLIC_ BOOL null_time(time_t t) +_PUBLIC_ bool null_time(time_t t) { return t == 0 || t == (time_t)0xFFFFFFFF || @@ -127,7 +127,7 @@ _PUBLIC_ BOOL null_time(time_t t) /** check if it's a null NTTIME **/ -_PUBLIC_ BOOL null_nttime(NTTIME t) +_PUBLIC_ bool null_nttime(NTTIME t) { return t == 0 || t == (NTTIME)-1; } @@ -403,9 +403,9 @@ _PUBLIC_ struct timeval timeval_zero(void) } /** - return True if a timeval is zero + return true if a timeval is zero */ -_PUBLIC_ BOOL timeval_is_zero(const struct timeval *tv) +_PUBLIC_ bool timeval_is_zero(const struct timeval *tv) { return tv->tv_sec == 0 && tv->tv_usec == 0; } @@ -481,13 +481,13 @@ _PUBLIC_ int timeval_compare(const struct timeval *tv1, const struct timeval *tv } /** - return True if a timer is in the past + return true if a timer is in the past */ -_PUBLIC_ BOOL timeval_expired(const struct timeval *tv) +_PUBLIC_ bool timeval_expired(const struct timeval *tv) { struct timeval tv2 = timeval_current(); - if (tv2.tv_sec > tv->tv_sec) return True; - if (tv2.tv_sec < tv->tv_sec) return False; + if (tv2.tv_sec > tv->tv_sec) return true; + if (tv2.tv_sec < tv->tv_sec) return false; return (tv2.tv_usec >= tv->tv_usec); } diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index e43bb98c1e..aa7a571585 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -47,12 +47,12 @@ _PUBLIC_ const char *tmpdir(void) /** Check if a file exists - call vfs_file_exist for samba files. **/ -_PUBLIC_ BOOL file_exist(const char *fname) +_PUBLIC_ bool file_exist(const char *fname) { struct stat st; if (stat(fname, &st) != 0) { - return False; + return false; } return ((S_ISREG(st.st_mode)) || (S_ISFIFO(st.st_mode))); @@ -76,13 +76,13 @@ _PUBLIC_ time_t file_modtime(const char *fname) Check if a directory exists. **/ -_PUBLIC_ BOOL directory_exist(const char *dname) +_PUBLIC_ bool directory_exist(const char *dname) { struct stat st; - BOOL ret; + bool ret; if (stat(dname,&st) != 0) { - return False; + return false; } ret = S_ISDIR(st.st_mode); @@ -94,10 +94,10 @@ _PUBLIC_ BOOL directory_exist(const char *dname) /** * Try to create the specified directory if it didn't exist. * - * @retval True if the directory already existed and has the right permissions + * @retval true if the directory already existed and has the right permissions * or was successfully created. */ -_PUBLIC_ BOOL directory_create_or_exist(const char *dname, uid_t uid, +_PUBLIC_ bool directory_create_or_exist(const char *dname, uid_t uid, mode_t dir_perms) { mode_t old_umask; @@ -112,13 +112,13 @@ _PUBLIC_ BOOL directory_create_or_exist(const char *dname, uid_t uid, "%s: %s\n", dname, strerror(errno))); umask(old_umask); - return False; + return false; } } else { DEBUG(0, ("lstat failed on directory %s: %s\n", dname, strerror(errno))); umask(old_umask); - return False; + return false; } } else { /* Check ownership and permission on existing directory */ @@ -126,17 +126,17 @@ _PUBLIC_ BOOL directory_create_or_exist(const char *dname, uid_t uid, DEBUG(0, ("directory %s isn't a directory\n", dname)); umask(old_umask); - return False; + return false; } if ((st.st_uid != uid) || ((st.st_mode & 0777) != dir_perms)) { DEBUG(0, ("invalid permissions on directory " "%s\n", dname)); umask(old_umask); - return False; + return false; } } - return True; + return true; } @@ -147,7 +147,7 @@ _PUBLIC_ BOOL directory_create_or_exist(const char *dname, uid_t uid, if BSD use FNDELAY **/ -_PUBLIC_ int set_blocking(int fd, BOOL set) +_PUBLIC_ int set_blocking(int fd, bool set) { int val; #ifdef O_NONBLOCK @@ -221,16 +221,16 @@ _PUBLIC_ char* get_myname(void) Return true if a string could be a pure IP address. **/ -_PUBLIC_ BOOL is_ipaddress(const char *str) +_PUBLIC_ bool is_ipaddress(const char *str) { - BOOL pure_address = True; + bool pure_address = true; int i; - if (str == NULL) return False; + if (str == NULL) return false; for (i=0; pure_address && str[i]; i++) if (!(isdigit((int)str[i]) || str[i] == '.')) - pure_address = False; + pure_address = false; /* Check that a pure number is not misinterpreted as an IP */ pure_address = pure_address && (strchr(str, '.') != NULL); @@ -298,7 +298,7 @@ _PUBLIC_ struct ipv4_addr interpret_addr2(const char *str) Check if an IP is the 0.0.0.0. **/ -_PUBLIC_ BOOL is_zero_ip(struct ipv4_addr ip) +_PUBLIC_ bool is_zero_ip(struct ipv4_addr ip) { return ip.addr == 0; } @@ -307,7 +307,7 @@ _PUBLIC_ BOOL is_zero_ip(struct ipv4_addr ip) Are two IPs on the same subnet? **/ -_PUBLIC_ BOOL same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask) +_PUBLIC_ bool same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask) { uint32_t net1,net2,nmask; @@ -323,7 +323,7 @@ _PUBLIC_ BOOL same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_add Check if a process exists. Does this work on all unixes? **/ -_PUBLIC_ BOOL process_exists(pid_t pid) +_PUBLIC_ bool process_exists(pid_t pid) { /* Doing kill with a non-positive pid causes messages to be * sent to places we don't want. */ @@ -336,7 +336,7 @@ _PUBLIC_ BOOL process_exists(pid_t pid) is dealt with in posix.c **/ -_PUBLIC_ BOOL fcntl_lock(int fd, int op, off_t offset, off_t count, int type) +_PUBLIC_ bool fcntl_lock(int fd, int op, off_t offset, off_t count, int type) { struct flock lock; int ret; @@ -361,24 +361,24 @@ _PUBLIC_ BOOL fcntl_lock(int fd, int op, off_t offset, off_t count, int type) (lock.l_pid != 0) && (lock.l_pid != getpid())) { DEBUG(3,("fcntl_lock: fd %d is locked by pid %d\n",fd,(int)lock.l_pid)); - return(True); + return true; } /* it must be not locked or locked by me */ - return(False); + return false; } /* a lock set or unset */ if (ret == -1) { 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))); - return(False); + return false; } /* everything went OK */ DEBUG(8,("fcntl_lock: Lock call successful\n")); - return(True); + return true; } @@ -503,14 +503,14 @@ _PUBLIC_ void dump_data_pw(const char *msg, const uint8_t * data, size_t len) * see if a range of memory is all zero. A NULL pointer is considered * to be all zero */ -_PUBLIC_ BOOL all_zero(const uint8_t *ptr, size_t size) +_PUBLIC_ bool all_zero(const uint8_t *ptr, size_t size) { int i; - if (!ptr) return True; + if (!ptr) return true; for (i=0;i 0 && s[len-1] == '\\') { s[--len] = 0; - start_of_line = True; + start_of_line = true; break; } return(s); @@ -83,7 +83,7 @@ _PUBLIC_ char *fgets_slash(char *s2,int maxlen,XFILE *f) break; /* fall through */ default: - start_of_line = False; + start_of_line = false; s[len++] = c; s[len] = 0; } @@ -342,18 +342,18 @@ _PUBLIC_ void file_lines_slashcont(char **lines) /** save a lump of data into a file. Mostly used for debugging */ -_PUBLIC_ BOOL file_save(const char *fname, const void *packet, size_t length) +_PUBLIC_ bool file_save(const char *fname, const void *packet, size_t length) { int fd; fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0644); if (fd == -1) { - return False; + return false; } if (write(fd, packet, length) != (size_t)length) { - return False; + return false; } close(fd); - return True; + return true; } _PUBLIC_ int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index baa42e806a..67e59474fd 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -263,16 +263,16 @@ _PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_ /** Set a string value, allocing the space for the string **/ -static BOOL string_init(char **dest,const char *src) +static bool string_init(char **dest,const char *src) { if (!src) src = ""; (*dest) = strdup(src); if ((*dest) == NULL) { DEBUG(0,("Out of memory in string_init\n")); - return False; + return false; } - return True; + return true; } /** @@ -287,7 +287,7 @@ _PUBLIC_ void string_free(char **s) Set a string value, deallocating any existing space, and allocing the space for the string **/ -_PUBLIC_ BOOL string_set(char **dest, const char *src) +_PUBLIC_ bool string_set(char **dest, const char *src) { string_free(dest); return string_init(dest,src); @@ -485,7 +485,7 @@ _PUBLIC_ const char *str_format_nbt_domain(TALLOC_CTX *mem_ctx, const char *s) * num should be a pointer to an integer that holds the current * number of elements in strings. It will be updated by this function. */ -_PUBLIC_ BOOL add_string_to_array(TALLOC_CTX *mem_ctx, +_PUBLIC_ bool add_string_to_array(TALLOC_CTX *mem_ctx, const char *str, const char ***strings, int *num) { char *dup_str = talloc_strdup(mem_ctx, str); @@ -495,12 +495,12 @@ _PUBLIC_ BOOL add_string_to_array(TALLOC_CTX *mem_ctx, const char *, ((*num)+1)); if ((*strings == NULL) || (dup_str == NULL)) - return False; + return false; (*strings)[*num] = dup_str; *num += 1; - return True; + return true; } @@ -584,26 +584,26 @@ _PUBLIC_ char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib) /** Set a boolean variable from the text value stored in the passed string. - Returns True in success, False if the passed string does not correctly + Returns true in success, false if the passed string does not correctly represent a boolean. **/ -_PUBLIC_ BOOL set_boolean(const char *boolean_string, BOOL *boolean) +_PUBLIC_ bool set_boolean(const char *boolean_string, bool *boolean) { if (strwicmp(boolean_string, "yes") == 0 || strwicmp(boolean_string, "true") == 0 || strwicmp(boolean_string, "on") == 0 || strwicmp(boolean_string, "1") == 0) { - *boolean = True; - return True; + *boolean = true; + return true; } else if (strwicmp(boolean_string, "no") == 0 || strwicmp(boolean_string, "false") == 0 || strwicmp(boolean_string, "off") == 0 || strwicmp(boolean_string, "0") == 0) { - *boolean = False; - return True; + *boolean = false; + return true; } - return False; + return false; } /** @@ -611,15 +611,15 @@ _PUBLIC_ BOOL set_boolean(const char *boolean_string, BOOL *boolean) * * val will be set to the read value. * - * @retval True if a boolean value was parsed, False otherwise. + * @retval true if a boolean value was parsed, false otherwise. */ -_PUBLIC_ BOOL conv_str_bool(const char * str, BOOL * val) +_PUBLIC_ bool conv_str_bool(const char * str, bool * val) { char * end = NULL; long lval; if (str == NULL || *str == '\0') { - return False; + return false; } lval = strtol(str, &end, 10 /* base */); @@ -627,25 +627,25 @@ _PUBLIC_ BOOL conv_str_bool(const char * str, BOOL * val) return set_boolean(str, val); } - *val = (lval) ? True : False; - return True; + *val = (lval) ? true : false; + return true; } /** * Convert a size specification like 16K into an integral number of bytes. **/ -_PUBLIC_ BOOL conv_str_size(const char * str, uint64_t * val) +_PUBLIC_ bool conv_str_size(const char * str, uint64_t * val) { char * end = NULL; unsigned long long lval; if (str == NULL || *str == '\0') { - return False; + return false; } lval = strtoull(str, &end, 10 /* base */); if (end == NULL || end == str) { - return False; + return false; } if (*end) { @@ -660,12 +660,12 @@ _PUBLIC_ BOOL conv_str_size(const char * str, uint64_t * val) } else if (strwicmp(end, "P") == 0) { lval *= (1024ULL * 1024ULL * 1024ULL * 1024ULL * 1024ULL); } else { - return False; + return false; } } *val = (uint64_t)lval; - return True; + return true; } /** @@ -673,24 +673,24 @@ _PUBLIC_ BOOL conv_str_size(const char * str, uint64_t * val) * * val will be set to the value read. * - * @retval True if parsing was successful, False otherwise + * @retval true if parsing was successful, false otherwise */ -_PUBLIC_ BOOL conv_str_u64(const char * str, uint64_t * val) +_PUBLIC_ bool conv_str_u64(const char * str, uint64_t * val) { char * end = NULL; unsigned long long lval; if (str == NULL || *str == '\0') { - return False; + return false; } lval = strtoull(str, &end, 10 /* base */); if (end == NULL || *end != '\0' || end == str) { - return False; + return false; } *val = (uint64_t)lval; - return True; + return true; } /** @@ -777,12 +777,12 @@ _PUBLIC_ void string_replace(char *s, char oldc, char newc) * * @note The comparison is case-insensitive. **/ -_PUBLIC_ BOOL strequal(const char *s1, const char *s2) +_PUBLIC_ bool strequal(const char *s1, const char *s2) { if (s1 == s2) - return(True); + return true; if (!s1 || !s2) - return(False); + return false; return strcasecmp(s1,s2) == 0; } diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index cd0e1cdac0..ab73fb2d15 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -217,7 +217,7 @@ _PUBLIC_ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) /** Return true if all the elements of the list match exactly. */ -_PUBLIC_ BOOL str_list_equal(const char **list1, const char **list2) +_PUBLIC_ bool str_list_equal(const char **list1, const char **list2) { int i; @@ -227,13 +227,13 @@ _PUBLIC_ BOOL str_list_equal(const char **list1, const char **list2) for (i=0;list1[i] && list2[i];i++) { if (strcmp(list1[i], list2[i]) != 0) { - return False; + return false; } } if (list1[i] || list2[i]) { - return False; + return false; } - return True; + return true; } @@ -275,50 +275,50 @@ _PUBLIC_ void str_list_remove(const char **list, const char *s) /** - return True if a string is in a list + return true if a string is in a list */ -_PUBLIC_ BOOL str_list_check(const char **list, const char *s) +_PUBLIC_ bool str_list_check(const char **list, const char *s) { int i; for (i=0;list[i];i++) { - if (strcmp(list[i], s) == 0) return True; + if (strcmp(list[i], s) == 0) return true; } - return False; + return false; } /** - return True if a string is in a list, case insensitively + return true if a string is in a list, case insensitively */ -_PUBLIC_ BOOL str_list_check_ci(const char **list, const char *s) +_PUBLIC_ bool str_list_check_ci(const char **list, const char *s) { int i; for (i=0;list[i];i++) { - if (strcasecmp(list[i], s) == 0) return True; + if (strcasecmp(list[i], s) == 0) return true; } - return False; + return false; } /** Check if a string is part of a list. **/ -_PUBLIC_ BOOL in_list(const char *s, const char *list, BOOL casesensitive) +_PUBLIC_ bool in_list(const char *s, const char *list, bool casesensitive) { pstring tok; const char *p=list; if (!list) - return(False); + return false; while (next_token(&p,tok,LIST_SEP,sizeof(tok))) { if (casesensitive) { if (strcmp(tok,s) == 0) - return(True); + return true; } else { if (strcasecmp_m(tok,s) == 0) - return(True); + return true; } } - return(False); + return false; } diff --git a/source4/lib/util/util_tdb.c b/source4/lib/util/util_tdb.c index 6c95b58893..1112f1587c 100644 --- a/source4/lib/util/util_tdb.c +++ b/source4/lib/util/util_tdb.c @@ -148,7 +148,7 @@ int tdb_store_int32(struct tdb_context *tdb, const char *keystr, int32_t v) Output is uint32_t in native byte order. ****************************************************************************/ -BOOL tdb_fetch_uint32_byblob(struct tdb_context *tdb, const char *keyval, size_t len, uint32_t *value) +bool tdb_fetch_uint32_byblob(struct tdb_context *tdb, const char *keyval, size_t len, uint32_t *value) { TDB_DATA key = make_tdb_data(keyval, len); TDB_DATA data; @@ -156,12 +156,12 @@ BOOL tdb_fetch_uint32_byblob(struct tdb_context *tdb, const char *keyval, size_t data = tdb_fetch(tdb, key); if (!data.dptr || data.dsize != sizeof(uint32_t)) { SAFE_FREE(data.dptr); - return False; + return false; } *value = IVAL(data.dptr,0); SAFE_FREE(data.dptr); - return True; + return true; } /**************************************************************************** @@ -169,7 +169,7 @@ BOOL tdb_fetch_uint32_byblob(struct tdb_context *tdb, const char *keyval, size_t Output is uint32_t in native byte order. ****************************************************************************/ -BOOL tdb_fetch_uint32(struct tdb_context *tdb, const char *keystr, uint32_t *value) +bool tdb_fetch_uint32(struct tdb_context *tdb, const char *keystr, uint32_t *value) { return tdb_fetch_uint32_byblob(tdb, keystr, strlen(keystr) + 1, value); } @@ -179,19 +179,19 @@ BOOL tdb_fetch_uint32(struct tdb_context *tdb, const char *keystr, uint32_t *val Input is uint32_t in native byte order. Output in tdb is in little-endian. ****************************************************************************/ -BOOL tdb_store_uint32_byblob(struct tdb_context *tdb, const char *keystr, size_t len, uint32_t value) +bool tdb_store_uint32_byblob(struct tdb_context *tdb, const char *keystr, size_t len, uint32_t value) { TDB_DATA key = make_tdb_data(keystr, len); TDB_DATA data; uint32_t v_store; - BOOL ret = True; + bool ret = true; SIVAL(&v_store, 0, value); data.dptr = (void *)&v_store; data.dsize = sizeof(uint32_t); if (tdb_store(tdb, key, data, TDB_REPLACE) == -1) - ret = False; + ret = false; return ret; } @@ -201,7 +201,7 @@ BOOL tdb_store_uint32_byblob(struct tdb_context *tdb, const char *keystr, size_t Input is uint32_t in native byte order. Output in tdb is in little-endian. ****************************************************************************/ -BOOL tdb_store_uint32(struct tdb_context *tdb, const char *keystr, uint32_t value) +bool tdb_store_uint32(struct tdb_context *tdb, const char *keystr, uint32_t value) { return tdb_store_uint32_byblob(tdb, keystr, strlen(keystr) + 1, value); } @@ -285,13 +285,13 @@ int32_t tdb_change_int32_atomic(struct tdb_context *tdb, const char *keystr, int Atomic unsigned integer change. Returns old value. To create, set initial value in *oldval. ****************************************************************************/ -BOOL tdb_change_uint32_atomic(struct tdb_context *tdb, const char *keystr, uint32_t *oldval, uint32_t change_val) +bool tdb_change_uint32_atomic(struct tdb_context *tdb, const char *keystr, uint32_t *oldval, uint32_t change_val) { uint32_t val; - BOOL ret = False; + bool ret = false; if (tdb_lock_bystring(tdb, keystr) == -1) - return False; + return false; if (!tdb_fetch_uint32(tdb, keystr, &val)) { /* It failed */ @@ -315,7 +315,7 @@ BOOL tdb_change_uint32_atomic(struct tdb_context *tdb, const char *keystr, uint3 if (!tdb_store_uint32(tdb, keystr, val)) goto err_out; - ret = True; + ret = true; err_out: -- cgit From 0b91f3916430d0271eab867675d44c5439de40c2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 29 Aug 2007 13:07:03 +0000 Subject: r24780: More work allowing libutil to be used by external users. (This used to be commit 31993cf67b816a184a4a4e92ef8ca2532c797190) --- source4/lib/util/config.mk | 3 +- source4/lib/util/data_blob.c | 21 +- source4/lib/util/data_blob.h | 108 +++++++ source4/lib/util/time.h | 225 ++++++++++++++ source4/lib/util/util.h | 710 ++++++++++++++++++++++++++++++++++++++++++- source4/lib/util/xfile.h | 51 ++++ 6 files changed, 1101 insertions(+), 17 deletions(-) create mode 100644 source4/lib/util/data_blob.h create mode 100644 source4/lib/util/time.h (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 5ec110e68d..0912c897db 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -2,12 +2,13 @@ #VERSION = 0.0.1 #SO_VERSION = 0 #DESCRIPTION = Generic utility functions -PUBLIC_PROTO_HEADER = util_proto.h PUBLIC_HEADERS = util.h \ byteorder.h \ + data_blob.h \ debug.h \ mutex.h \ safe_string.h \ + time.h \ xfile.h OBJ_FILES = xfile.o \ debug.o \ diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index df8e793835..117043f95c 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -196,38 +196,37 @@ _PUBLIC_ DATA_BLOB data_blob_const(const void *p, size_t length) /** realloc a data_blob **/ -_PUBLIC_ NTSTATUS data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) +_PUBLIC_ bool data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) { blob->data = talloc_realloc_size(mem_ctx, blob->data, length); - NT_STATUS_HAVE_NO_MEMORY(blob->data); + if (blob->data == NULL) + return false; blob->length = length; - return NT_STATUS_OK; + return true; } /** append some data to a data blob **/ -_PUBLIC_ NTSTATUS data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, +_PUBLIC_ bool data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const void *p, size_t length) { - NTSTATUS status; size_t old_len = blob->length; size_t new_len = old_len + length; if (new_len < length || new_len < old_len) { - return NT_STATUS_NO_MEMORY; + return false; } if ((const uint8_t *)p + length < (const uint8_t *)p) { - return NT_STATUS_NO_MEMORY; + return false; } - status = data_blob_realloc(mem_ctx, blob, new_len); - if (!NT_STATUS_IS_OK(status)) { - return status; + if (!data_blob_realloc(mem_ctx, blob, new_len)) { + return false; } memcpy(blob->data + old_len, p, length); - return NT_STATUS_OK; + return true; } diff --git a/source4/lib/util/data_blob.h b/source4/lib/util/data_blob.h new file mode 100644 index 0000000000..acecb88132 --- /dev/null +++ b/source4/lib/util/data_blob.h @@ -0,0 +1,108 @@ +/* + Unix SMB/CIFS implementation. + DATA BLOB + + 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef _SAMBA_DATABLOB_H_ +#define _SAMBA_DATABLOB_H_ + +/* used to hold an arbitrary blob of data */ +typedef struct datablob { + uint8_t *data; + size_t length; +} DATA_BLOB; + +struct data_blob_list_item { + struct data_blob_list_item *prev,*next; + DATA_BLOB blob; +}; + +#define data_blob(ptr, size) data_blob_named(ptr, size, "DATA_BLOB: "__location__) +#define data_blob_talloc(ctx, ptr, size) data_blob_talloc_named(ctx, ptr, size, "DATA_BLOB: "__location__) +#define data_blob_dup_talloc(ctx, blob) data_blob_talloc_named(ctx, (blob)->data, (blob)->length, "DATA_BLOB: "__location__) + +/** + construct a data blob, must be freed with data_blob_free() + you can pass NULL for p and get a blank data blob +**/ +_PUBLIC_ DATA_BLOB data_blob_named(const void *p, size_t length, const char *name); + +/** + construct a data blob, using supplied TALLOC_CTX +**/ +_PUBLIC_ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name); + +/** + reference a data blob, to the supplied TALLOC_CTX. + Returns a NULL DATA_BLOB on failure +**/ +_PUBLIC_ DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob); + +/** + construct a zero data blob, using supplied TALLOC_CTX. + use this sparingly as it initialises data - better to initialise + yourself if you want specific data in the blob +**/ +_PUBLIC_ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length); + +/** +free a data blob +**/ +_PUBLIC_ void data_blob_free(DATA_BLOB *d); + +/** +clear a DATA_BLOB's contents +**/ +_PUBLIC_ void data_blob_clear(DATA_BLOB *d); + +/** +free a data blob and clear its contents +**/ +_PUBLIC_ void data_blob_clear_free(DATA_BLOB *d); + +/** +check if two data blobs are equal +**/ +_PUBLIC_ int data_blob_cmp(const DATA_BLOB *d1, const DATA_BLOB *d2); + +/** +print the data_blob as hex string +**/ +_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob); + +/** + useful for constructing data blobs in test suites, while + avoiding const warnings +**/ +_PUBLIC_ DATA_BLOB data_blob_string_const(const char *str); + +/** + * Create a new data blob from const data + */ +_PUBLIC_ DATA_BLOB data_blob_const(const void *p, size_t length); + +/** + realloc a data_blob +**/ +_PUBLIC_ bool data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length); + +/** + append some data to a data blob +**/ +_PUBLIC_ bool data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, + const void *p, size_t length); + +#endif /* _SAMBA_DATABLOB_H_ */ diff --git a/source4/lib/util/time.h b/source4/lib/util/time.h new file mode 100644 index 0000000000..a1b3facf24 --- /dev/null +++ b/source4/lib/util/time.h @@ -0,0 +1,225 @@ +/* + Unix SMB/CIFS implementation. + time utility functions + + 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef _SAMBA_TIME_H_ +#define _SAMBA_TIME_H_ + +/* 64 bit time (100 nanosec) 1601 - cifs6.txt, section 3.5, page 30, 4 byte aligned */ +typedef uint64_t NTTIME; + +/** + External access to time_t_min and time_t_max. +**/ +_PUBLIC_ time_t get_time_t_max(void); + +/** +a gettimeofday wrapper +**/ +_PUBLIC_ void GetTimeOfDay(struct timeval *tval); + +/** +interpret an 8 byte "filetime" structure to a time_t +It's originally in "100ns units since jan 1st 1601" +**/ +_PUBLIC_ time_t nt_time_to_unix(NTTIME nt); + +/** +put a 8 byte filetime from a time_t +This takes GMT as input +**/ +_PUBLIC_ void unix_to_nt_time(NTTIME *nt, time_t t); + +/** +check if it's a null unix time +**/ +_PUBLIC_ bool null_time(time_t t); + +/** +check if it's a null NTTIME +**/ +_PUBLIC_ bool null_nttime(NTTIME t); + +/** +put a dos date into a buffer (time/date format) +This takes GMT time and puts local time in the buffer +**/ +_PUBLIC_ void push_dos_date(uint8_t *buf, int offset, time_t unixdate, int zone_offset); + +/** +put a dos date into a buffer (date/time format) +This takes GMT time and puts local time in the buffer +**/ +_PUBLIC_ void push_dos_date2(uint8_t *buf,int offset,time_t unixdate, int zone_offset); + +/** +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) +**/ +_PUBLIC_ void push_dos_date3(uint8_t *buf,int offset,time_t unixdate, int zone_offset); + +/** + create a unix date (int GMT) from a dos date (which is actually in + localtime) +**/ +_PUBLIC_ time_t pull_dos_date(const uint8_t *date_ptr, int zone_offset); + +/** +like make_unix_date() but the words are reversed +**/ +_PUBLIC_ time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset); + +/** + create a unix GMT date from a dos date in 32 bit "unix like" format + these generally arrive as localtimes, with corresponding DST +**/ +_PUBLIC_ time_t pull_dos_date3(const uint8_t *date_ptr, int zone_offset); + +/** +return a HTTP/1.0 time string +**/ +_PUBLIC_ char *http_timestring(TALLOC_CTX *mem_ctx, time_t t); + +/** + Return the date and time as a string +**/ +_PUBLIC_ char *timestring(TALLOC_CTX *mem_ctx, time_t t); + +/** + return a talloced string representing a NTTIME for human consumption +*/ +_PUBLIC_ const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt); + +/** + put a NTTIME into a packet +*/ +_PUBLIC_ void push_nttime(uint8_t *base, uint16_t offset, NTTIME t); + +/** + pull a NTTIME from a packet +*/ +_PUBLIC_ NTTIME pull_nttime(uint8_t *base, uint16_t offset); + +/** + parse a nttime as a large integer in a string and return a NTTIME +*/ +_PUBLIC_ NTTIME nttime_from_string(const char *s); + +/** + return (tv1 - tv2) in microseconds +*/ +_PUBLIC_ int64_t usec_time_diff(struct timeval *tv1, struct timeval *tv2); + +/** + return a zero timeval +*/ +_PUBLIC_ struct timeval timeval_zero(void); + +/** + return true if a timeval is zero +*/ +_PUBLIC_ bool timeval_is_zero(const struct timeval *tv); + +/** + return a timeval for the current time +*/ +_PUBLIC_ struct timeval timeval_current(void); + +/** + return a timeval struct with the given elements +*/ +_PUBLIC_ struct timeval timeval_set(uint32_t secs, uint32_t usecs); + +/** + return a timeval ofs microseconds after tv +*/ +_PUBLIC_ struct timeval timeval_add(const struct timeval *tv, + uint32_t secs, uint32_t usecs); + +/** + return the sum of two timeval structures +*/ +struct timeval timeval_sum(const struct timeval *tv1, + const struct timeval *tv2); + +/** + return a timeval secs/usecs into the future +*/ +_PUBLIC_ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs); + +/** + compare two timeval structures. + Return -1 if tv1 < tv2 + Return 0 if tv1 == tv2 + Return 1 if tv1 > tv2 +*/ +_PUBLIC_ int timeval_compare(const struct timeval *tv1, const struct timeval *tv2); + +/** + return true if a timer is in the past +*/ +_PUBLIC_ bool timeval_expired(const struct timeval *tv); + +/** + return the number of seconds elapsed between two times +*/ +_PUBLIC_ double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2); + +/** + return the number of seconds elapsed since a given time +*/ +_PUBLIC_ double timeval_elapsed(const struct timeval *tv); + +/** + return the lesser of two timevals +*/ +_PUBLIC_ struct timeval timeval_min(const struct timeval *tv1, + const struct timeval *tv2); + +/** + return the greater of two timevals +*/ +_PUBLIC_ struct timeval timeval_max(const struct timeval *tv1, + const struct timeval *tv2); + +/** + return the difference between two timevals as a timeval + if tv1 comes after tv2, then return a zero timeval + (this is *tv2 - *tv1) +*/ +_PUBLIC_ struct timeval timeval_until(const struct timeval *tv1, + const struct timeval *tv2); + +/** + convert a timeval to a NTTIME +*/ +_PUBLIC_ NTTIME timeval_to_nttime(const struct timeval *tv); + +/** + convert a NTTIME to a timeval +*/ +_PUBLIC_ void nttime_to_timeval(struct timeval *tv, NTTIME t); + +/** + return the UTC offset in seconds west of UTC, or 0 if it cannot be determined + */ +_PUBLIC_ int get_time_zone(time_t t); + + + +#endif /* _SAMBA_TIME_H_ */ diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index f19b243f64..0c784d1c97 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -34,11 +34,12 @@ struct smbsrv_tcon; extern const char *logfile; extern const char *panic_action; +#include "util/time.h" +#include "util/data_blob.h" #include "util/xfile.h" #include "util/debug.h" #include "util/mutex.h" #include "util/byteorder.h" -#include "lib/util/util_proto.h" /** this is a warning hack. The idea is to use this everywhere that we @@ -100,10 +101,6 @@ extern const char *panic_action; */ #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count) -#define data_blob(ptr, size) data_blob_named(ptr, size, "DATA_BLOB: "__location__) -#define data_blob_talloc(ctx, ptr, size) data_blob_talloc_named(ctx, ptr, size, "DATA_BLOB: "__location__) -#define data_blob_dup_talloc(ctx, blob) data_blob_talloc_named(ctx, (blob)->data, (blob)->length, "DATA_BLOB: "__location__) - #if defined(VALGRIND) #define strlen(x) valgrind_strlen(x) #endif @@ -149,4 +146,707 @@ extern const char *panic_action; #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2))) #endif + +/** + * this global variable determines what messages are printed + */ +_PUBLIC_ void debug_schedule_reopen_logs(void); + +/** + the backend for debug messages. Note that the DEBUG() macro has already + ensured that the log level has been met before this is called +*/ +_PUBLIC_ void do_debug_header(int level, const char *location, const char *func); + +/** + the backend for debug messages. Note that the DEBUG() macro has already + ensured that the log level has been met before this is called + + @note You should never have to call this function directly. Call the DEBUG() + macro instead. +*/ +_PUBLIC_ void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2); + +/** + reopen the log file (usually called because the log file name might have changed) +*/ +_PUBLIC_ void reopen_logs(void); + +/** + control the name of the logfile and whether logging will be to stdout, stderr + or a file +*/ +_PUBLIC_ void setup_logging(const char *prog_name, enum debug_logtype new_logtype); + +/** + return a string constant containing n tabs + no more than 10 tabs are returned +*/ +_PUBLIC_ const char *do_debug_tab(int n); + +/** + log suspicious usage - print comments and backtrace +*/ +_PUBLIC_ void log_suspicious_usage(const char *from, const char *info); + +/** + print suspicious usage - print comments and backtrace +*/ +_PUBLIC_ void print_suspicious_usage(const char* from, const char* info); +_PUBLIC_ uint32_t get_task_id(void); +_PUBLIC_ void log_task_id(void); + +/** + register a set of debug handlers. +*/ +_PUBLIC_ void register_debug_handlers(const char *name, struct debug_ops *ops); + +/* The following definitions come from lib/util/fault.c */ + + +/** + * Write backtrace to debug log + */ +_PUBLIC_ void call_backtrace(void); + +/** + Something really nasty happened - panic ! +**/ +_PUBLIC_ _NORETURN_ void smb_panic(const char *why); + +/** +setup our fault handlers +**/ +_PUBLIC_ void fault_setup(const char *pname); + +/** + register a fault handler. + Should only be called once in the execution of smbd. +*/ +_PUBLIC_ bool register_fault_handler(const char *name, void (*fault_handler)(int sig)); + +/* The following definitions come from lib/util/signal.c */ + + +/** + Block sigs. +**/ +void BlockSignals(bool block, int signum); + +/** + Catch a signal. This should implement the following semantics: + + 1) The handler remains installed after being called. + 2) The signal should be blocked during handler execution. +**/ +void (*CatchSignal(int signum,void (*handler)(int )))(int); + +/** + Ignore SIGCLD via whatever means is necessary for this OS. +**/ +void CatchChild(void); + +/** + Catch SIGCLD but leave the child around so it's status can be reaped. +**/ +void CatchChildLeaveStatus(void); + +/* The following definitions come from lib/util/system.c */ + + +/************************************************************************** +A wrapper for gethostbyname() that tries avoids looking up hostnames +in the root domain, which can cause dial-on-demand links to come up for no +apparent reason. +****************************************************************************/ +_PUBLIC_ struct hostent *sys_gethostbyname(const char *name); +_PUBLIC_ const char *sys_inet_ntoa(struct ipv4_addr in); +_PUBLIC_ struct ipv4_addr sys_inet_makeaddr(int net, int host); + +/* The following definitions come from lib/util/genrand.c */ + +/** + Copy any user given reseed data. +**/ +_PUBLIC_ void set_rand_reseed_callback(void (*fn)(int *)); + +/** + * Tell the random number generator it needs to reseed. + */ +_PUBLIC_ void set_need_random_reseed(void); + +/** + Interface to the (hopefully) good crypto random number generator. +**/ +_PUBLIC_ void generate_random_buffer(uint8_t *out, int len); + +/** + generate a single random uint32_t +**/ +_PUBLIC_ uint32_t generate_random(void); + +/** + very basic password quality checker +**/ +_PUBLIC_ bool check_password_quality(const char *s); + +/** + Use the random number generator to generate a random string. +**/ +_PUBLIC_ char *generate_random_str_list(TALLOC_CTX *mem_ctx, size_t len, const char *list); + +/** + * Generate a random text string consisting of the specified length. + * The returned string will be allocated. + * + * Characters used are: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_-#., + */ +_PUBLIC_ char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len); + +/* The following definitions come from lib/util/dprintf.c */ + +_PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0); +_PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3); +_PUBLIC_ int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2); +_PUBLIC_ void display_set_stderr(void); + +/* The following definitions come from lib/util/util_str.c */ + + +/** + Trim the specified elements off the front and back of a string. +**/ +_PUBLIC_ bool trim_string(char *s, const char *front, const char *back); + +/** + Find the number of 'c' chars in a string +**/ +_PUBLIC_ _PURE_ size_t count_chars(const char *s, char c); + +/** + Safe string copy into a known length string. maxlength does not + include the terminating zero. +**/ +_PUBLIC_ char *safe_strcpy(char *dest,const char *src, size_t maxlength); + +/** + Safe string cat into a string. maxlength does not + include the terminating zero. +**/ +_PUBLIC_ char *safe_strcat(char *dest, const char *src, size_t maxlength); + +/** + Routine to get hex characters and turn them into a 16 byte array. + the array can be variable length, and any non-hex-numeric + characters are skipped. "0xnn" or "0Xnn" is specially catered + for. + + valid examples: "0A5D15"; "0x15, 0x49, 0xa2"; "59\ta9\te3\n" + + +**/ +_PUBLIC_ size_t strhex_to_str(char *p, size_t len, const char *strhex); + +/** + * Parse a hex string and return a data blob. + */ +_PUBLIC_ _PURE_ DATA_BLOB strhex_to_data_blob(const char *strhex) ; + +/** + * Routine to print a buffer as HEX digits, into an allocated string. + */ +_PUBLIC_ void hex_encode(const unsigned char *buff_in, size_t len, char **out_hex_buffer); + +/** + * talloc version of hex_encode() + */ +_PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len); + +/** + Free a string value. +**/ +_PUBLIC_ void string_free(char **s); + +/** + Set a string value, deallocating any existing space, and allocing the space + for the string +**/ +_PUBLIC_ bool string_set(char **dest, const char *src); + +/** + Substitute a string for a pattern in another string. Make sure there is + enough room! + + This routine looks for pattern in s and replaces it with + insert. It may do multiple replacements. + + Any of " ; ' $ or ` in the insert string are replaced with _ + if len==0 then the string cannot be extended. This is different from the old + use of len==0 which was for no length checks to be done. +**/ +_PUBLIC_ void string_sub(char *s,const char *pattern, const char *insert, size_t len); + +/** + Similar to string_sub() but allows for any character to be substituted. + Use with caution! + if len==0 then the string cannot be extended. This is different from the old + use of len==0 which was for no length checks to be done. +**/ +_PUBLIC_ void all_string_sub(char *s,const char *pattern,const char *insert, size_t len); + +/** + Unescape a URL encoded string, in place. +**/ +_PUBLIC_ void rfc1738_unescape(char *buf); +size_t valgrind_strlen(const char *s); + +/** + format a string into length-prefixed dotted domain format, as used in NBT + and in some ADS structures +**/ +_PUBLIC_ const char *str_format_nbt_domain(TALLOC_CTX *mem_ctx, const char *s); + +/** + * Add a string to an array of strings. + * + * num should be a pointer to an integer that holds the current + * number of elements in strings. It will be updated by this function. + */ +_PUBLIC_ bool add_string_to_array(TALLOC_CTX *mem_ctx, + const char *str, const char ***strings, int *num); + +/** + varient of strcmp() that handles NULL ptrs +**/ +_PUBLIC_ int strcmp_safe(const char *s1, const char *s2); + +/** +return the number of bytes occupied by a buffer in ASCII format +the result includes the null termination +limited by 'n' bytes +**/ +_PUBLIC_ size_t ascii_len_n(const char *src, size_t n); + +/** + Return a string representing a CIFS attribute for a file. +**/ +_PUBLIC_ char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib); + +/** + Set a boolean variable from the text value stored in the passed string. + Returns true in success, false if the passed string does not correctly + represent a boolean. +**/ +_PUBLIC_ bool set_boolean(const char *boolean_string, bool *boolean); + +/** + * Parse a string containing a boolean value. + * + * val will be set to the read value. + * + * @retval true if a boolean value was parsed, false otherwise. + */ +_PUBLIC_ bool conv_str_bool(const char * str, bool * val); + +/** + * Convert a size specification like 16K into an integral number of bytes. + **/ +_PUBLIC_ bool conv_str_size(const char * str, uint64_t * val); + +/** + * Parse a uint64_t value from a string + * + * val will be set to the value read. + * + * @retval true if parsing was successful, false otherwise + */ +_PUBLIC_ bool conv_str_u64(const char * str, uint64_t * val); + +/** +return the number of bytes occupied by a buffer in CH_UTF16 format +the result includes the null termination +**/ +_PUBLIC_ size_t utf16_len(const void *buf); + +/** +return the number of bytes occupied by a buffer in CH_UTF16 format +the result includes the null termination +limited by 'n' bytes +**/ +_PUBLIC_ size_t utf16_len_n(const void *src, size_t n); +_PUBLIC_ size_t ucs2_align(const void *base_ptr, const void *p, int flags); + +/** +Do a case-insensitive, whitespace-ignoring string compare. +**/ +_PUBLIC_ int strwicmp(const char *psz1, const char *psz2); + +/** + String replace. +**/ +_PUBLIC_ void string_replace(char *s, char oldc, char newc); + +/** + * Compare 2 strings. + * + * @note The comparison is case-insensitive. + **/ +_PUBLIC_ bool strequal(const char *s1, const char *s2); + +/* The following definitions come from lib/util/util_strlist.c */ + + +/** + build a null terminated list of strings from a input string and a + separator list. The separator list must contain characters less than + or equal to 0x2f for this to work correctly on multi-byte strings +*/ +_PUBLIC_ const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep); + +/** + * build a null terminated list of strings from an argv-like input string + * Entries are seperated by spaces and can be enclosed by quotes. + * Does NOT support escaping + */ +_PUBLIC_ const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const char *sep); + +/** + * join a list back to one string + */ +_PUBLIC_ char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator); + +/** join a list back to one (shell-like) string; entries + * seperated by spaces, using quotes where necessary */ +_PUBLIC_ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep); + +/** + return the number of elements in a string list +*/ +_PUBLIC_ size_t str_list_length(const char **list); + +/** + copy a string list +*/ +_PUBLIC_ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list); + +/** + Return true if all the elements of the list match exactly. + */ +_PUBLIC_ bool str_list_equal(const char **list1, const char **list2); + +/** + add an entry to a string list +*/ +_PUBLIC_ const char **str_list_add(const char **list, const char *s); + +/** + remove an entry from a string list +*/ +_PUBLIC_ void str_list_remove(const char **list, const char *s); + +/** + return true if a string is in a list +*/ +_PUBLIC_ bool str_list_check(const char **list, const char *s); + +/** + return true if a string is in a list, case insensitively +*/ +_PUBLIC_ bool str_list_check_ci(const char **list, const char *s); + +/** + Check if a string is part of a list. +**/ +_PUBLIC_ bool in_list(const char *s, const char *list, bool casesensitive); + +/* The following definitions come from lib/util/util_file.c */ + + +/** +read a line from a file with possible \ continuation chars. +Blanks at the start or end of a line are stripped. +The string will be allocated if s2 is NULL +**/ +_PUBLIC_ char *fgets_slash(char *s2,int maxlen,XFILE *f); + +/** + * Read one line (data until next newline or eof) and allocate it + */ +_PUBLIC_ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint); + +/** +load a file into memory from a fd. +**/ +_PUBLIC_ char *fd_load(int fd, size_t *size, TALLOC_CTX *mem_ctx); + +/** +load a file into memory +**/ +_PUBLIC_ char *file_load(const char *fname, size_t *size, TALLOC_CTX *mem_ctx); + +/** +mmap (if possible) or read a file +**/ +_PUBLIC_ void *map_file(const char *fname, size_t size); + +/** +load a file into memory and return an array of pointers to lines in the file +must be freed with talloc_free(). +**/ +_PUBLIC_ char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx); + +/** +load a fd into memory and return an array of pointers to lines in the file +must be freed with talloc_free(). If convert is true calls unix_to_dos on +the list. +**/ +_PUBLIC_ char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx); + +/** +take a list of lines and modify them to produce a list where \ continues +a line +**/ +_PUBLIC_ void file_lines_slashcont(char **lines); + +/** + save a lump of data into a file. Mostly used for debugging +*/ +_PUBLIC_ bool file_save(const char *fname, const void *packet, size_t length); +_PUBLIC_ int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0); +_PUBLIC_ int fdprintf(int fd, const char *format, ...) _PRINTF_ATTRIBUTE(2,3); +_PUBLIC_ bool large_file_support(const char *path); + +/* The following definitions come from lib/util/util.c */ + + +/** + Find a suitable temporary directory. The result should be copied immediately + as it may be overwritten by a subsequent call. +**/ +_PUBLIC_ const char *tmpdir(void); + +/** + Check if a file exists - call vfs_file_exist for samba files. +**/ +_PUBLIC_ bool file_exist(const char *fname); + +/** + Check a files mod time. +**/ +_PUBLIC_ time_t file_modtime(const char *fname); + +/** + Check if a directory exists. +**/ +_PUBLIC_ bool directory_exist(const char *dname); + +/** + * Try to create the specified directory if it didn't exist. + * + * @retval true if the directory already existed and has the right permissions + * or was successfully created. + */ +_PUBLIC_ bool directory_create_or_exist(const char *dname, uid_t uid, + mode_t dir_perms); + +/** + Set a fd into blocking/nonblocking mode. Uses POSIX O_NONBLOCK if available, + else + if SYSV use O_NDELAY + if BSD use FNDELAY +**/ +_PUBLIC_ int set_blocking(int fd, bool set); + +/** + Sleep for a specified number of milliseconds. +**/ +_PUBLIC_ void msleep(unsigned int t); + +/** + Get my own name, return in malloc'ed storage. +**/ +_PUBLIC_ char* get_myname(void); + +/** + Return true if a string could be a pure IP address. +**/ +_PUBLIC_ bool is_ipaddress(const char *str); + +/** + Interpret an internet address or name into an IP address in 4 byte form. +**/ +_PUBLIC_ uint32_t interpret_addr(const char *str); + +/** + A convenient addition to interpret_addr(). +**/ +_PUBLIC_ struct ipv4_addr interpret_addr2(const char *str); + +/** + Check if an IP is the 0.0.0.0. +**/ +_PUBLIC_ bool is_zero_ip(struct ipv4_addr ip); + +/** + Are two IPs on the same subnet? +**/ +_PUBLIC_ bool same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask); + +/** + Check if a process exists. Does this work on all unixes? +**/ +_PUBLIC_ bool process_exists(pid_t pid); + +/** + Simple routine to do POSIX file locking. Cruft in NFS and 64->32 bit mapping + is dealt with in posix.c +**/ +_PUBLIC_ bool fcntl_lock(int fd, int op, off_t offset, off_t count, int type); + +/** + * Write dump of binary data to the log file. + * + * The data is only written if the log level is at least level. + */ +_PUBLIC_ void dump_data(int level, const uint8_t *buf,int len); + +/** + malloc that aborts with smb_panic on fail or zero size. +**/ +_PUBLIC_ void *smb_xmalloc(size_t size); + +/** + Memdup with smb_panic on fail. +**/ +_PUBLIC_ void *smb_xmemdup(const void *p, size_t size); + +/** + strdup that aborts on malloc fail. +**/ +_PUBLIC_ char *smb_xstrdup(const char *s); + +/** + Like strdup but for memory. +**/ +_PUBLIC_ void *memdup(const void *p, size_t size); + +/** + * Write a password to the log file. + * + * @note Only actually does something if DEBUG_PASSWORD was defined during + * compile-time. + */ +_PUBLIC_ void dump_data_pw(const char *msg, const uint8_t * data, size_t len); + +/** + * see if a range of memory is all zero. A NULL pointer is considered + * to be all zero + */ +_PUBLIC_ bool all_zero(const uint8_t *ptr, size_t size); + +/** + realloc an array, checking for integer overflow in the array size +*/ +_PUBLIC_ void *realloc_array(void *ptr, size_t el_size, unsigned count); + +/* The following definitions come from lib/util/fsusage.c */ + + +/** + * Retrieve amount of free disk space. + * this does all of the system specific guff to get the free disk space. + * It is derived from code in the GNU fileutils package, but has been + * considerably mangled for use here + * + * results are returned in *dfree and *dsize, in 512 byte units +*/ +_PUBLIC_ int sys_fsusage(const char *path, uint64_t *dfree, uint64_t *dsize); + +/* The following definitions come from lib/util/ms_fnmatch.c */ + + +/** + * @file + * @brief MS-style Filename matching + */ +int ms_fnmatch(const char *pattern, const char *string, enum protocol_types protocol); + +/** a generic fnmatch function - uses for non-CIFS pattern matching */ +int gen_fnmatch(const char *pattern, const char *string); + +/* The following definitions come from lib/util/mutex.c */ + + +/** + register a set of mutex/rwlock handlers. + Should only be called once in the execution of smbd. +*/ +_PUBLIC_ bool register_mutex_handlers(const char *name, struct mutex_ops *ops); + +/* The following definitions come from lib/util/idtree.c */ + + +/** + initialise a idr tree. The context return value must be passed to + all subsequent idr calls. To destroy the idr tree use talloc_free() + on this context + */ +_PUBLIC_ struct idr_context *idr_init(TALLOC_CTX *mem_ctx); + +/** + allocate the next available id, and assign 'ptr' into its slot. + you can retrieve later this pointer using idr_find() +*/ +_PUBLIC_ int idr_get_new(struct idr_context *idp, void *ptr, int limit); + +/** + allocate a new id, giving the first available value greater than or + equal to the given starting id +*/ +_PUBLIC_ int idr_get_new_above(struct idr_context *idp, void *ptr, int starting_id, int limit); + +/** + allocate a new id randomly in the given range +*/ +_PUBLIC_ int idr_get_new_random(struct idr_context *idp, void *ptr, int limit); + +/** + find a pointer value previously set with idr_get_new given an id +*/ +_PUBLIC_ void *idr_find(struct idr_context *idp, int id); + +/** + remove an id from the idr tree +*/ +_PUBLIC_ int idr_remove(struct idr_context *idp, int id); + +/* The following definitions come from lib/util/module.c */ + + +/** + * Obtain the init function from a shared library file + */ +_PUBLIC_ init_module_fn load_module(TALLOC_CTX *mem_ctx, const char *path); + +/** + * Obtain list of init functions from the modules in the specified + * directory + */ +_PUBLIC_ init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path); + +/** + * Run the specified init functions. + * + * @return true if all functions ran successfully, false otherwise + */ +_PUBLIC_ bool run_init_functions(NTSTATUS (**fns) (void)); + +/* The following definitions come from lib/util/become_daemon.c */ + + +/** + Become a daemon, discarding the controlling terminal. +**/ +_PUBLIC_ void become_daemon(bool Fork); + #endif /* _SAMBA_UTIL_H_ */ diff --git a/source4/lib/util/xfile.h b/source4/lib/util/xfile.h index ffe4481a64..2cc369d8d8 100644 --- a/source4/lib/util/xfile.h +++ b/source4/lib/util/xfile.h @@ -45,4 +45,55 @@ extern XFILE *x_stdin, *x_stdout, *x_stderr; int x_vfprintf(XFILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2, 0); int x_fprintf(XFILE *f, const char *format, ...) PRINTF_ATTRIBUTE(2, 3); + +/** simulate setvbuf() */ +int x_setvbuf(XFILE *f, char *buf, int mode, size_t size); + +/** this looks more like open() than fopen(), but that is quite deliberate. + I want programmers to *think* about O_EXCL, O_CREAT etc not just + get them magically added +*/ +XFILE *x_fopen(const char *fname, int flags, mode_t mode); + +/** simulate fclose() */ +int x_fclose(XFILE *f); + +/** simulate fwrite() */ +size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f); + +/** thank goodness for asprintf() */ +int x_fileno(XFILE *f); + +/** simulate fflush() */ +int x_fflush(XFILE *f); + +/** simulate setbuffer() */ +void x_setbuffer(XFILE *f, char *buf, size_t size); + +/** simulate setbuf() */ +void x_setbuf(XFILE *f, char *buf); + +/** simulate setlinebuf() */ +void x_setlinebuf(XFILE *f); + +/** simulate feof() */ +int x_feof(XFILE *f); + +/** simulate ferror() */ +int x_ferror(XFILE *f); + +/** simulate fgetc() */ +int x_fgetc(XFILE *f); + +/** simulate fread */ +size_t x_fread(void *p, size_t size, size_t nmemb, XFILE *f); + +/** simulate fgets() */ +char *x_fgets(char *s, int size, XFILE *stream) ; + +/** + * trivial seek, works only for SEEK_SET and SEEK_END if SEEK_CUR is + * set then an error is returned */ +off_t x_tseek(XFILE *f, off_t offset, int whence); + #endif /* _XFILE_H_ */ -- cgit From 09c188e7353a74d05a674935c85e548bd09073ae Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 30 Aug 2007 22:25:59 +0000 Subject: r24812: Fix headers for external users. (This used to be commit ff6684adfd96b59381dd941e54070ab9f8984912) --- source4/lib/util/data_blob.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/data_blob.h b/source4/lib/util/data_blob.h index acecb88132..e39b2eaf45 100644 --- a/source4/lib/util/data_blob.h +++ b/source4/lib/util/data_blob.h @@ -19,6 +19,12 @@ #ifndef _SAMBA_DATABLOB_H_ #define _SAMBA_DATABLOB_H_ +#ifndef _PUBLIC_ +#define _PUBLIC_ +#endif + +#include + /* used to hold an arbitrary blob of data */ typedef struct datablob { uint8_t *data; @@ -30,6 +36,10 @@ struct data_blob_list_item { DATA_BLOB blob; }; +/* by making struct ldb_val and DATA_BLOB the same, we can simplify + a fair bit of code */ +#define ldb_val datablob + #define data_blob(ptr, size) data_blob_named(ptr, size, "DATA_BLOB: "__location__) #define data_blob_talloc(ctx, ptr, size) data_blob_talloc_named(ctx, ptr, size, "DATA_BLOB: "__location__) #define data_blob_dup_talloc(ctx, blob) data_blob_talloc_named(ctx, (blob)->data, (blob)->length, "DATA_BLOB: "__location__) -- cgit From 82037a75eae9deaf6ec80b5ecc3bb89aab6e6dd8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 30 Aug 2007 23:15:12 +0000 Subject: r24814: Fix headers, trim core.h even more. (This used to be commit 9647f860bdd5c0a74583e886182bd041a45e7655) --- source4/lib/util/config.mk | 1 - source4/lib/util/module.c | 111 --------------------------------------------- source4/lib/util/util.h | 45 +++++++++--------- 3 files changed, 23 insertions(+), 134 deletions(-) delete mode 100644 source4/lib/util/module.c (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 0912c897db..702e3df5aa 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -27,7 +27,6 @@ OBJ_FILES = xfile.o \ ms_fnmatch.o \ mutex.o \ idtree.o \ - module.o \ become_daemon.o PUBLIC_DEPENDENCIES = \ LIBTALLOC LIBCRYPTO \ diff --git a/source4/lib/util/module.c b/source4/lib/util/module.c deleted file mode 100644 index 170ea0bacb..0000000000 --- a/source4/lib/util/module.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - Copyright (C) Jelmer Vernooij 2005 - - 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 - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file - * @brief Module initialization function handling - */ - -#include "includes.h" -#include "system/dir.h" - -/** - * Obtain the init function from a shared library file - */ -_PUBLIC_ init_module_fn load_module(TALLOC_CTX *mem_ctx, const char *path) -{ - void *handle; - void *init_fn; - - handle = dlopen(path, RTLD_NOW); - if (handle == NULL) { - DEBUG(0, ("Unable to open %s: %s\n", path, dlerror())); - return NULL; - } - - init_fn = dlsym(handle, "init_module"); - - if (init_fn == NULL) { - DEBUG(0, ("Unable to find init_module() in %s: %s\n", path, dlerror())); - DEBUG(1, ("Loading module '%s' failed\n", path)); - dlclose(handle); - return NULL; - } - - return (init_module_fn)init_fn; -} - -/** - * Obtain list of init functions from the modules in the specified - * directory - */ -_PUBLIC_ init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path) -{ - DIR *dir; - struct dirent *entry; - char *filename; - int success = 0; - init_module_fn *ret = talloc_array(mem_ctx, init_module_fn, 2); - - ret[0] = NULL; - - dir = opendir(path); - if (dir == NULL) { - talloc_free(ret); - return NULL; - } - - while((entry = readdir(dir))) { - if (ISDOT(entry->d_name) || ISDOTDOT(entry->d_name)) - continue; - - filename = talloc_asprintf(mem_ctx, "%s/%s", path, entry->d_name); - - ret[success] = load_module(mem_ctx, filename); - if (ret[success]) { - ret = talloc_realloc(mem_ctx, ret, init_module_fn, success+2); - success++; - ret[success] = NULL; - } - - talloc_free(filename); - } - - closedir(dir); - - return ret; -} - -/** - * Run the specified init functions. - * - * @return true if all functions ran successfully, false otherwise - */ -_PUBLIC_ bool run_init_functions(NTSTATUS (**fns) (void)) -{ - int i; - bool ret = true; - - if (fns == NULL) - return true; - - for (i = 0; fns[i]; i++) { ret &= (bool)NT_STATUS_IS_OK(fns[i]()); } - - return ret; -} diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 0c784d1c97..8259e08512 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -254,6 +254,14 @@ void CatchChildLeaveStatus(void); /* The following definitions come from lib/util/system.c */ +/* + we use struct ipv4_addr to avoid having to include all the + system networking headers everywhere +*/ +struct ipv4_addr { + uint32_t addr; +}; + /************************************************************************** A wrapper for gethostbyname() that tries avoids looking up hostnames in the root domain, which can cause dial-on-demand links to come up for no @@ -769,6 +777,21 @@ _PUBLIC_ int sys_fsusage(const char *path, uint64_t *dfree, uint64_t *dsize); * @file * @brief MS-style Filename matching */ + +/* protocol types. It assumes that higher protocols include lower protocols + as subsets. FIXME: Move to one of the smb-specific headers */ +enum protocol_types { + PROTOCOL_NONE, + PROTOCOL_CORE, + PROTOCOL_COREPLUS, + PROTOCOL_LANMAN1, + PROTOCOL_LANMAN2, + PROTOCOL_NT1, + PROTOCOL_SMB2 +}; + + + int ms_fnmatch(const char *pattern, const char *string, enum protocol_types protocol); /** a generic fnmatch function - uses for non-CIFS pattern matching */ @@ -820,30 +843,8 @@ _PUBLIC_ void *idr_find(struct idr_context *idp, int id); */ _PUBLIC_ int idr_remove(struct idr_context *idp, int id); -/* The following definitions come from lib/util/module.c */ - - -/** - * Obtain the init function from a shared library file - */ -_PUBLIC_ init_module_fn load_module(TALLOC_CTX *mem_ctx, const char *path); - -/** - * Obtain list of init functions from the modules in the specified - * directory - */ -_PUBLIC_ init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path); - -/** - * Run the specified init functions. - * - * @return true if all functions ran successfully, false otherwise - */ -_PUBLIC_ bool run_init_functions(NTSTATUS (**fns) (void)); - /* The following definitions come from lib/util/become_daemon.c */ - /** Become a daemon, discarding the controlling terminal. **/ -- cgit From bb84655d65bf22305cfab26a6b14b148cb060722 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 4 Sep 2007 02:08:36 +0000 Subject: r24941: Simplify samdb_result_nttime(), and remove nttime_from_string() Andrew Bartlett (This used to be commit bcd994a139e2e8fb2e97c8b897c987ff234e0b0a) --- source4/lib/util/time.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/time.c b/source4/lib/util/time.c index c800fffea0..4601833a3d 100644 --- a/source4/lib/util/time.c +++ b/source4/lib/util/time.c @@ -373,14 +373,6 @@ _PUBLIC_ NTTIME pull_nttime(uint8_t *base, uint16_t offset) return ret; } -/** - parse a nttime as a large integer in a string and return a NTTIME -*/ -_PUBLIC_ NTTIME nttime_from_string(const char *s) -{ - return strtoull(s, NULL, 0); -} - /** return (tv1 - tv2) in microseconds */ -- cgit From cd962355abad90a2161765a7be7d26e63572cab7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 15:08:14 +0000 Subject: r25000: Fix some more C++ compatibility warnings. (This used to be commit 08bb1ef643ab906f1645cf6f32763dc73b1884e4) --- source4/lib/util/fault.c | 4 ++-- source4/lib/util/time.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index 5cc9445407..e9cd040ee6 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -153,7 +153,7 @@ _PUBLIC_ _NORETURN_ void smb_panic(const char *why) /** report a fault **/ -static void fault_report(int sig) +_NORETURN_ static void fault_report(int sig) { static int counter; @@ -172,7 +172,7 @@ static void fault_report(int sig) /** catch serious errors **/ -static void sig_fault(int sig) +_NORETURN_ static void sig_fault(int sig) { if (fault_handlers.fault_handler) { /* we have a fault handler, call it. It may not return. */ diff --git a/source4/lib/util/time.c b/source4/lib/util/time.c index 4601833a3d..fc51498009 100644 --- a/source4/lib/util/time.c +++ b/source4/lib/util/time.c @@ -269,7 +269,7 @@ _PUBLIC_ time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset) x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); SIVAL(&x,0,x2); - return pull_dos_date((void *)&x, zone_offset); + return pull_dos_date((const uint8_t *)&x, zone_offset); } /** -- cgit From 307a45127b863836d4c301722ccc04ee94c457cb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 16:45:06 +0000 Subject: r25006: Use system constant. (This used to be commit d9b2464598efe0f0cbecd4d8a90fbd137fad0daf) --- source4/lib/util/util.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index aa7a571585..624315f99e 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -190,28 +190,27 @@ _PUBLIC_ void msleep(unsigned int t) Get my own name, return in malloc'ed storage. **/ -_PUBLIC_ char* get_myname(void) +_PUBLIC_ char *get_myname(void) { char *hostname; - const int host_name_max = 255; char *p; - hostname = malloc(host_name_max+1); + hostname = (char *)malloc(MAXHOSTNAMELEN+1); *hostname = 0; /* get my host name */ - if (gethostname(hostname, host_name_max+1) == -1) { + if (gethostname(hostname, MAXHOSTNAMELEN+1) == -1) { DEBUG(0,("gethostname failed\n")); return NULL; } /* Ensure null termination. */ - hostname[host_name_max] = '\0'; + hostname[MAXHOSTNAMELEN] = '\0'; /* split off any parts after an initial . */ - p = strchr(hostname,'.'); + p = strchr(hostname, '.'); - if (p) + if (p != NULL) *p = 0; return hostname; -- cgit From b50ef4caef44e3b45445728818f3bca09273249d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 16:54:39 +0000 Subject: r25007: Remove more uses of pstring, move ntlmauth-specific utility function to ntlm-auth.c (This used to be commit 6f224480b230ab7ccfc0417c13e7f4fc3f6f2a13) --- source4/lib/util/util.h | 5 ----- source4/lib/util/util_str.c | 7 +++---- source4/lib/util/util_strlist.c | 21 --------------------- 3 files changed, 3 insertions(+), 30 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 8259e08512..8d71ad1a64 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -562,11 +562,6 @@ _PUBLIC_ bool str_list_check(const char **list, const char *s); */ _PUBLIC_ bool str_list_check_ci(const char **list, const char *s); -/** - Check if a string is part of a list. -**/ -_PUBLIC_ bool in_list(const char *s, const char *list, bool casesensitive); - /* The following definitions come from lib/util/util_file.c */ diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 67e59474fd..eb8155cc7c 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -23,7 +23,6 @@ #include "includes.h" #include "libcli/raw/smb.h" -#include "pstring.h" #include "system/locale.h" /** @@ -237,7 +236,7 @@ _PUBLIC_ void hex_encode(const unsigned char *buff_in, size_t len, char **out_he int i; char *hex_buffer; - *out_hex_buffer = smb_xmalloc((len*2)+1); + *out_hex_buffer = malloc_array_p(char, (len*2)+1); hex_buffer = *out_hex_buffer; for (i = 0; i < len; i++) @@ -457,7 +456,7 @@ _PUBLIC_ const char *str_format_nbt_domain(TALLOC_CTX *mem_ctx, const char *s) if (!s || !*s) { return talloc_strdup(mem_ctx, ""); } - ret = talloc_size(mem_ctx, strlen(s)+2); + ret = talloc_array(mem_ctx, char, strlen(s)+2); if (!ret) { return ret; } @@ -566,7 +565,7 @@ _PUBLIC_ char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib) }; char *ret; - ret = talloc_size(mem_ctx, ARRAY_SIZE(attr_strs)+1); + ret = talloc_array(mem_ctx, char, ARRAY_SIZE(attr_strs)+1); if (!ret) { return NULL; } diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index ab73fb2d15..a8b106a567 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -300,25 +300,4 @@ _PUBLIC_ bool str_list_check_ci(const char **list, const char *s) return false; } -/** - Check if a string is part of a list. -**/ -_PUBLIC_ bool in_list(const char *s, const char *list, bool casesensitive) -{ - pstring tok; - const char *p=list; - if (!list) - return false; - - while (next_token(&p,tok,LIST_SEP,sizeof(tok))) { - if (casesensitive) { - if (strcmp(tok,s) == 0) - return true; - } else { - if (strcasecmp_m(tok,s) == 0) - return true; - } - } - return false; -} -- cgit From 3b6186a67630cf05bc33e6e9288e132f39173ef4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 17:59:53 +0000 Subject: r25008: Remove use of pstring. (This used to be commit c57869e2620de30c303b0cb2f70cd07b32f269fc) --- source4/lib/util/util_strlist.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index a8b106a567..ed4ab00031 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -19,7 +19,6 @@ */ #include "includes.h" -#include "pstring.h" #include "system/locale.h" /** -- cgit From e73df517c877add667cc36e889282d129eebe3b9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 00:38:22 +0000 Subject: r25014: Use talloc for allocating values as well. (This used to be commit 43f0e2622ef61bd865fcf17191118c050ec8cfcb) --- source4/lib/util/util.h | 7 +------ source4/lib/util/util_str.c | 33 ++++++++++----------------------- 2 files changed, 11 insertions(+), 29 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 8d71ad1a64..a2e0954517 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -370,16 +370,11 @@ _PUBLIC_ void hex_encode(const unsigned char *buff_in, size_t len, char **out_he */ _PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len); -/** - Free a string value. -**/ -_PUBLIC_ void string_free(char **s); - /** Set a string value, deallocating any existing space, and allocing the space for the string **/ -_PUBLIC_ bool string_set(char **dest, const char *src); +_PUBLIC_ bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src); /** Substitute a string for a pattern in another string. Make sure there is diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index eb8155cc7c..4bec469f87 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -260,36 +260,23 @@ _PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_ } /** - Set a string value, allocing the space for the string + Set a string value, deallocating any existing space, and allocing the space + for the string **/ -static bool string_init(char **dest,const char *src) +_PUBLIC_ bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src) { - if (!src) src = ""; + talloc_free(*dest); - (*dest) = strdup(src); + if (src == NULL) + src = ""; + + *dest = talloc_strdup(mem_ctx, src); if ((*dest) == NULL) { DEBUG(0,("Out of memory in string_init\n")); return false; } - return true; -} - -/** - Free a string value. -**/ -_PUBLIC_ void string_free(char **s) -{ - if (s) SAFE_FREE(*s); -} -/** - Set a string value, deallocating any existing space, and allocing the space - for the string -**/ -_PUBLIC_ bool string_set(char **dest, const char *src) -{ - string_free(dest); - return string_init(dest,src); + return true; } /** @@ -304,7 +291,7 @@ _PUBLIC_ bool string_set(char **dest, const char *src) use of len==0 which was for no length checks to be done. **/ -_PUBLIC_ void string_sub(char *s,const char *pattern, const char *insert, size_t len) +_PUBLIC_ void string_sub(char *s, const char *pattern, const char *insert, size_t len) { char *p; ssize_t ls,lp,li, i; -- cgit From dccf3f99e45137b6cd18c1de1c79808ad67130d1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 13:27:14 +0000 Subject: r25027: Fix more warnings. (This used to be commit 5085c53fcfade614e83d21fc2c1a5bc43bb2a729) --- source4/lib/util/data_blob.c | 10 +++++----- source4/lib/util/dprintf.c | 2 +- source4/lib/util/util_tdb.c | 5 +++-- source4/lib/util/xfile.c | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index 117043f95c..b258e47bba 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -39,9 +39,9 @@ _PUBLIC_ DATA_BLOB data_blob_named(const void *p, size_t length, const char *nam } if (p) { - ret.data = talloc_memdup(NULL, p, length); + ret.data = (uint8_t *)talloc_memdup(NULL, p, length); } else { - ret.data = talloc_size(NULL, length); + ret.data = talloc_array(NULL, uint8_t, length); } if (ret.data == NULL) { ret.length = 0; @@ -175,7 +175,7 @@ _PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob) _PUBLIC_ DATA_BLOB data_blob_string_const(const char *str) { DATA_BLOB blob; - blob.data = discard_const(str); + blob.data = discard_const_p(uint8_t, str); blob.length = strlen(str); return blob; } @@ -187,7 +187,7 @@ _PUBLIC_ DATA_BLOB data_blob_string_const(const char *str) _PUBLIC_ DATA_BLOB data_blob_const(const void *p, size_t length) { DATA_BLOB blob; - blob.data = discard_const(p); + blob.data = discard_const_p(uint8_t, p); blob.length = length; return blob; } @@ -198,7 +198,7 @@ _PUBLIC_ DATA_BLOB data_blob_const(const void *p, size_t length) **/ _PUBLIC_ bool data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length) { - blob->data = talloc_realloc_size(mem_ctx, blob->data, length); + blob->data = talloc_realloc(mem_ctx, blob->data, uint8_t, length); if (blob->data == NULL) return false; blob->length = length; diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index a7770f364d..91665e7bdd 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -48,7 +48,7 @@ _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBU charset, but beware of it growing */ maxlen = ret*2; again: - p2 = malloc(maxlen); + p2 = (char *)malloc(maxlen); if (!p2) { SAFE_FREE(p); return -1; diff --git a/source4/lib/util/util_tdb.c b/source4/lib/util/util_tdb.c index 1112f1587c..d7bddbde01 100644 --- a/source4/lib/util/util_tdb.c +++ b/source4/lib/util/util_tdb.c @@ -22,6 +22,7 @@ #include "includes.h" #include "lib/tdb/include/tdb.h" #include "pstring.h" +#include "lib/util/util_tdb.h" /* these are little tdb utility functions that are meant to make dealing with a tdb database a little less cumbersome in Samba */ @@ -127,7 +128,7 @@ int tdb_store_int32_byblob(struct tdb_context *tdb, const char *keystr, size_t l int32_t v_store; SIVAL(&v_store,0,v); - data.dptr = (void *)&v_store; + data.dptr = (unsigned char *)&v_store; data.dsize = sizeof(int32_t); return tdb_store(tdb, key, data, TDB_REPLACE); @@ -187,7 +188,7 @@ bool tdb_store_uint32_byblob(struct tdb_context *tdb, const char *keystr, size_t bool ret = true; SIVAL(&v_store, 0, value); - data.dptr = (void *)&v_store; + data.dptr = (unsigned char *)&v_store; data.dsize = sizeof(uint32_t); if (tdb_store(tdb, key, data, TDB_REPLACE) == -1) diff --git a/source4/lib/util/xfile.c b/source4/lib/util/xfile.c index 8b90e30868..a016031a77 100644 --- a/source4/lib/util/xfile.c +++ b/source4/lib/util/xfile.c @@ -85,7 +85,7 @@ static int x_allocate_buffer(XFILE *f) { if (f->buf) return 1; if (f->bufsize == 0) return 0; - f->buf = malloc(f->bufsize); + f->buf = (char *)malloc(f->bufsize); if (!f->buf) return 0; f->next = f->buf; return 1; -- cgit From 98b57d5eb61094a9c88e2f7d90d3e21b7e74e9d8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 16:46:30 +0000 Subject: r25035: Fix some more warnings, use service pointer rather than service number in more places. (This used to be commit df9cebcb97e20564359097148665bd519f31bc6f) --- source4/lib/util/tests/strlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/tests/strlist.c b/source4/lib/util/tests/strlist.c index 41accd4bd2..437d9d741a 100644 --- a/source4/lib/util/tests/strlist.c +++ b/source4/lib/util/tests/strlist.c @@ -35,7 +35,7 @@ static const char *test_lists_shell_strings[] = { static bool test_lists_shell(struct torture_context *tctx, const void *test_data) { - const char *data = test_data; + const char *data = (const char *)test_data; const char **ret1, **ret2, *tmp; bool match = true; TALLOC_CTX *mem_ctx = tctx; -- cgit From 7e297ecfa4db2c7ab720a63c7764bc0e20f8058c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 9 Sep 2007 19:34:30 +0000 Subject: r25047: Fix more warnings. (This used to be commit 69de86d2d2e49439760fbc61901eb87fb7fc5d55) --- source4/lib/util/ms_fnmatch.c | 5 ++--- source4/lib/util/util.h | 13 ++----------- source4/lib/util/util_pw.c | 45 ++++++++++++++++--------------------------- source4/lib/util/util_str.c | 20 ------------------- 4 files changed, 21 insertions(+), 62 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/ms_fnmatch.c b/source4/lib/util/ms_fnmatch.c index 8e216b0226..73fb0e0966 100644 --- a/source4/lib/util/ms_fnmatch.c +++ b/source4/lib/util/ms_fnmatch.c @@ -201,11 +201,10 @@ int ms_fnmatch(const char *pattern, const char *string, enum protocol_types prot if (pattern[i] == '*' || pattern[i] == '<') count++; } - max_n = talloc_array(NULL, struct max_n, count); - if (!max_n) { + max_n = talloc_zero_array(NULL, struct max_n, count); + if (max_n == NULL) { return -1; } - memset(max_n, 0, sizeof(struct max_n) * count); ret = ms_fnmatch_core(pattern, string, max_n, strrchr(string, '.')); diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index a2e0954517..004c453a64 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -28,7 +28,6 @@ * @brief Helpful macros */ -struct substitute_context; struct smbsrv_tcon; extern const char *logfile; @@ -73,7 +72,7 @@ extern const char *panic_action; */ #define SMB_ASSERT(b) do { if (!(b)) { \ DEBUG(0,("PANIC: assert failed at %s(%d)\n", __FILE__, __LINE__)); \ - smb_panic("assert failed"); abort(); }} while (0) + smb_panic("assert failed"); }} while (0) #ifndef SAFE_FREE /* Oh no this is also defined in tdb.h */ /** @@ -370,12 +369,6 @@ _PUBLIC_ void hex_encode(const unsigned char *buff_in, size_t len, char **out_he */ _PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len); -/** - Set a string value, deallocating any existing space, and allocing the space - for the string -**/ -_PUBLIC_ bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src); - /** Substitute a string for a pattern in another string. Make sure there is enough room! @@ -780,8 +773,6 @@ enum protocol_types { PROTOCOL_SMB2 }; - - int ms_fnmatch(const char *pattern, const char *string, enum protocol_types protocol); /** a generic fnmatch function - uses for non-CIFS pattern matching */ @@ -838,6 +829,6 @@ _PUBLIC_ int idr_remove(struct idr_context *idp, int id); /** Become a daemon, discarding the controlling terminal. **/ -_PUBLIC_ void become_daemon(bool Fork); +_PUBLIC_ void become_daemon(bool fork); #endif /* _SAMBA_UTIL_H_ */ diff --git a/source4/lib/util/util_pw.c b/source4/lib/util/util_pw.c index 0e0675571e..11e46ec4e3 100644 --- a/source4/lib/util/util_pw.c +++ b/source4/lib/util/util_pw.c @@ -21,37 +21,26 @@ #include "includes.h" -static struct passwd *alloc_copy_passwd(const struct passwd *from) +static struct passwd *alloc_copy_passwd(TALLOC_CTX *mem_ctx, + const struct passwd *from) { - struct passwd *ret = smb_xmalloc_p(struct passwd); - ZERO_STRUCTP(ret); - ret->pw_name = smb_xstrdup(from->pw_name); - ret->pw_passwd = smb_xstrdup(from->pw_passwd); - ret->pw_uid = from->pw_uid; - ret->pw_gid = from->pw_gid; - ret->pw_gecos = smb_xstrdup(from->pw_gecos); - ret->pw_dir = smb_xstrdup(from->pw_dir); - ret->pw_shell = smb_xstrdup(from->pw_shell); - return ret; -} + struct passwd *ret = talloc_zero(mem_ctx, struct passwd); -void passwd_free (struct passwd **buf) -{ - if (!*buf) { - DEBUG(0, ("attempted double-free of allocated passwd\n")); - return; - } + if (ret == NULL) + return NULL; - SAFE_FREE((*buf)->pw_name); - SAFE_FREE((*buf)->pw_passwd); - SAFE_FREE((*buf)->pw_gecos); - SAFE_FREE((*buf)->pw_dir); - SAFE_FREE((*buf)->pw_shell); + ret->pw_name = talloc_strdup(ret, from->pw_name); + ret->pw_passwd = talloc_strdup(ret, from->pw_passwd); + ret->pw_uid = from->pw_uid; + ret->pw_gid = from->pw_gid; + ret->pw_gecos = talloc_strdup(ret, from->pw_gecos); + ret->pw_dir = talloc_strdup(ret, from->pw_dir); + ret->pw_shell = talloc_strdup(ret, from->pw_shell); - SAFE_FREE(*buf); + return ret; } -struct passwd *getpwnam_alloc(const char *name) +struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name) { struct passwd *temp; @@ -66,10 +55,10 @@ struct passwd *getpwnam_alloc(const char *name) return NULL; } - return alloc_copy_passwd(temp); + return alloc_copy_passwd(mem_ctx, temp); } -struct passwd *getpwuid_alloc(uid_t uid) +struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid) { struct passwd *temp; @@ -84,5 +73,5 @@ struct passwd *getpwuid_alloc(uid_t uid) return NULL; } - return alloc_copy_passwd(temp); + return alloc_copy_passwd(mem_ctx, temp); } diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 4bec469f87..0f1f2d5a1c 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -259,26 +259,6 @@ _PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_ return hex_buffer; } -/** - Set a string value, deallocating any existing space, and allocing the space - for the string -**/ -_PUBLIC_ bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src) -{ - talloc_free(*dest); - - if (src == NULL) - src = ""; - - *dest = talloc_strdup(mem_ctx, src); - if ((*dest) == NULL) { - DEBUG(0,("Out of memory in string_init\n")); - return false; - } - - return true; -} - /** Substitute a string for a pattern in another string. Make sure there is enough room! -- cgit From 9a012df08ee829c1d40fc88ba12a0ea479f60be0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 14 Sep 2007 23:21:00 +0000 Subject: r25175: Change to talloc_asprintf_append_buffer(). Jeremy. (This used to be commit 0844dbf597191b3e4d35a696695b229e986daec4) --- source4/lib/util/util_strlist.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index ed4ab00031..1f1cc17d00 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -151,7 +151,7 @@ _PUBLIC_ char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char sepera ret = talloc_strdup(mem_ctx, list[0]); for (i = 1; list[i]; i++) { - ret = talloc_asprintf_append(ret, "%c%s", seperator, list[i]); + ret = talloc_asprintf_append_buffer(ret, "%c%s", seperator, list[i]); } return ret; @@ -174,9 +174,9 @@ _PUBLIC_ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char for (i = 1; list[i]; i++) { if (strchr(list[i], ' ') || strlen(list[i]) == 0) - ret = talloc_asprintf_append(ret, "%c\"%s\"", sep, list[i]); + ret = talloc_asprintf_append_buffer(ret, "%c\"%s\"", sep, list[i]); else - ret = talloc_asprintf_append(ret, "%c%s", sep, list[i]); + ret = talloc_asprintf_append_buffer(ret, "%c%s", sep, list[i]); } return ret; -- cgit From ffbb7e40604b9cffeb0c226279b929497b03a964 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 16 Sep 2007 19:14:46 +0000 Subject: r25193: Update headers to easy use by external apps. (This used to be commit 20b70fbb7af6b6759c3b8c8aa56e10944b32bfdf) --- source4/lib/util/data_blob.h | 1 + source4/lib/util/time.h | 4 ++++ 2 files changed, 5 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/data_blob.h b/source4/lib/util/data_blob.h index e39b2eaf45..1442438dd7 100644 --- a/source4/lib/util/data_blob.h +++ b/source4/lib/util/data_blob.h @@ -24,6 +24,7 @@ #endif #include +#include /* used to hold an arbitrary blob of data */ typedef struct datablob { diff --git a/source4/lib/util/time.h b/source4/lib/util/time.h index a1b3facf24..557c5d4eab 100644 --- a/source4/lib/util/time.h +++ b/source4/lib/util/time.h @@ -19,6 +19,10 @@ #ifndef _SAMBA_TIME_H_ #define _SAMBA_TIME_H_ +#ifndef _PUBLIC_ +#define _PUBLIC_ +#endif + /* 64 bit time (100 nanosec) 1601 - cifs6.txt, section 3.5, page 30, 4 byte aligned */ typedef uint64_t NTTIME; -- cgit From 6a167124cdad339814ec6499aab30094e8cc43a6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 21 Sep 2007 00:09:13 +0000 Subject: r25265: Move attribute definitions to lib/util. (This used to be commit 5bb9f041f47a1b7e03c3dc02e38546bc43bcc856) --- source4/lib/util/attr.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ source4/lib/util/util.h | 1 + 2 files changed, 81 insertions(+) create mode 100644 source4/lib/util/attr.h (limited to 'source4/lib/util') diff --git a/source4/lib/util/attr.h b/source4/lib/util/attr.h new file mode 100644 index 0000000000..1357d902af --- /dev/null +++ b/source4/lib/util/attr.h @@ -0,0 +1,80 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij 2007 + + 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef __UTIL_ATTR_H__ +#define __UTIL_ATTR_H__ + +#ifdef __GNUC__ +/** gcc attribute used on function parameters so that it does not emit + * warnings about them being unused. **/ +# define UNUSED(param) param __attribute__ ((unused)) +#else +# define UNUSED(param) param +/** Feel free to add definitions for other compilers here. */ +#endif + +#ifndef _PUBLIC_ +#ifdef HAVE_VISIBILITY_ATTR +# define _PUBLIC_ __attribute__((visibility("default"))) +#else +# define _PUBLIC_ +#endif +#endif + +#ifndef _DEPRECATED_ +#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) +#define _DEPRECATED_ __attribute__ ((deprecated)) +#else +#define _DEPRECATED_ +#endif +#endif + +#ifndef _WARN_UNUSED_RESULT_ +#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) +#define _WARN_UNUSED_RESULT_ __attribute__ ((warn_unused_result)) +#else +#define _WARN_UNUSED_RESULT_ +#endif +#endif + +#ifndef _NORETURN_ +#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) +#define _NORETURN_ __attribute__ ((noreturn)) +#else +#define _NORETURN_ +#endif +#endif + +#ifndef _PURE_ +#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1) +#define _PURE_ __attribute__((pure)) +#else +#define _PURE_ +#endif +#endif + +#ifndef NONNULL +#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1) +#define NONNULL(param) param __attribute__((nonnull)) +#else +#define NONNULL(param) param +#endif +#endif + +#endif /* __UTIL_ATTR_H__ */ diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 004c453a64..b37812602f 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -33,6 +33,7 @@ struct smbsrv_tcon; extern const char *logfile; extern const char *panic_action; +#include "util/attr.h" #include "util/time.h" #include "util/data_blob.h" #include "util/xfile.h" -- cgit From f415ba5bcfdbf22571526ce4e5e103d1eebab5c5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 21 Sep 2007 02:00:50 +0000 Subject: r25267: Move PRINTF_ATTRIBUTE to lib/util as well. (This used to be commit 72b9d6c03661d72e83a5d60d43b75bb9bd5f5285) --- source4/lib/util/attr.h | 12 ++++++++++++ source4/lib/util/util.h | 12 ++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/attr.h b/source4/lib/util/attr.h index 1357d902af..8f6c4f5d8a 100644 --- a/source4/lib/util/attr.h +++ b/source4/lib/util/attr.h @@ -77,4 +77,16 @@ #endif #endif +#ifndef PRINTF_ATTRIBUTE +#if __GNUC__ >= 3 +/** Use gcc attribute to check printf fns. a1 is the 1-based index of + * the parameter containing the format, and a2 the index of the first + * argument. Note that some gcc 2.x versions don't handle this + * properly **/ +#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2))) +#else +#define PRINTF_ATTRIBUTE(a1, a2) +#endif +#endif + #endif /* __UTIL_ATTR_H__ */ diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index b37812602f..68bf326d87 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -165,7 +165,7 @@ _PUBLIC_ void do_debug_header(int level, const char *location, const char *func) @note You should never have to call this function directly. Call the DEBUG() macro instead. */ -_PUBLIC_ void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2); +_PUBLIC_ void do_debug(const char *format, ...) PRINTF_ATTRIBUTE(1,2); /** reopen the log file (usually called because the log file name might have changed) @@ -313,9 +313,9 @@ _PUBLIC_ char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len); /* The following definitions come from lib/util/dprintf.c */ -_PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0); -_PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3); -_PUBLIC_ int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2); +_PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0); +_PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) PRINTF_ATTRIBUTE(2,3); +_PUBLIC_ int d_printf(const char *format, ...) PRINTF_ATTRIBUTE(1,2); _PUBLIC_ void display_set_stderr(void); /* The following definitions come from lib/util/util_str.c */ @@ -604,8 +604,8 @@ _PUBLIC_ void file_lines_slashcont(char **lines); save a lump of data into a file. Mostly used for debugging */ _PUBLIC_ bool file_save(const char *fname, const void *packet, size_t length); -_PUBLIC_ int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0); -_PUBLIC_ int fdprintf(int fd, const char *format, ...) _PRINTF_ATTRIBUTE(2,3); +_PUBLIC_ int vfdprintf(int fd, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0); +_PUBLIC_ int fdprintf(int fd, const char *format, ...) PRINTF_ATTRIBUTE(2,3); _PUBLIC_ bool large_file_support(const char *path); /* The following definitions come from lib/util/util.c */ -- cgit From f2d64e1c45994e4b519454c071e90e0cd8240c8a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 24 Sep 2007 15:55:26 +0000 Subject: r25306: Add tests for string_sub(). (This used to be commit 2d37ddcbd1243f48d81af17d8ea3cdd6e8e35b8d) --- source4/lib/util/tests/file.c | 4 +-- source4/lib/util/tests/str.c | 78 +++++++++++++++++++++++++++++++++++++++++++ source4/lib/util/util_str.c | 4 +-- 3 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 source4/lib/util/tests/str.c (limited to 'source4/lib/util') diff --git a/source4/lib/util/tests/file.c b/source4/lib/util/tests/file.c index 0fe117a300..fe87293671 100644 --- a/source4/lib/util/tests/file.c +++ b/source4/lib/util/tests/file.c @@ -88,10 +88,10 @@ struct torture_suite *torture_local_util_file(TALLOC_CTX *mem_ctx) struct torture_suite *suite = torture_suite_create(mem_ctx, "FILE"); torture_suite_add_simple_test(suite, "file_load_save", - test_file_load_save); + test_file_load_save); torture_suite_add_simple_test(suite, "afdgets", - test_afdgets); + test_afdgets); return suite; } diff --git a/source4/lib/util/tests/str.c b/source4/lib/util/tests/str.c new file mode 100644 index 0000000000..4a964af0ee --- /dev/null +++ b/source4/lib/util/tests/str.c @@ -0,0 +1,78 @@ +/* + Unix SMB/CIFS implementation. + + util_str testing + + Copyright (C) Jelmer Vernooij 2007 + + 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include "torture/ui.h" + +static bool test_string_sub_simple(struct torture_context *tctx) +{ + char tmp[100]; + safe_strcpy(tmp, "foobar", sizeof(tmp)); + string_sub(tmp, "foo", "bar", sizeof(tmp)); + torture_assert_str_equal(tctx, tmp, "barbar", "invalid sub"); + return true; +} + +static bool test_string_sub_multiple(struct torture_context *tctx) +{ + char tmp[100]; + safe_strcpy(tmp, "fooblafoo", sizeof(tmp)); + string_sub(tmp, "foo", "bar", sizeof(tmp)); + torture_assert_str_equal(tctx, tmp, "barblabar", "invalid sub"); + return true; +} + +static bool test_string_sub_longer(struct torture_context *tctx) +{ + char tmp[100]; + safe_strcpy(tmp, "foobla", sizeof(tmp)); + string_sub(tmp, "foo", "blie", sizeof(tmp)); + torture_assert_str_equal(tctx, tmp, "bliebla", "invalid sub"); + return true; +} + +static bool test_string_sub_shorter(struct torture_context *tctx) +{ + char tmp[100]; + safe_strcpy(tmp, "foobla", sizeof(tmp)); + string_sub(tmp, "foo", "bl", sizeof(tmp)); + torture_assert_str_equal(tctx, tmp, "blbla", "invalid sub"); + return true; +} + +struct torture_suite *torture_local_util_str(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = torture_suite_create(mem_ctx, "STR"); + + torture_suite_add_simple_test(suite, "string_sub_simple", + test_string_sub_simple); + + torture_suite_add_simple_test(suite, "string_sub_multiple", + test_string_sub_multiple); + + torture_suite_add_simple_test(suite, "string_sub_shorter", + test_string_sub_shorter); + + torture_suite_add_simple_test(suite, "string_sub_longer", + test_string_sub_longer); + + return suite; +} diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 0f1f2d5a1c..e9f81dbd9b 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -274,7 +274,7 @@ _PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_ _PUBLIC_ void string_sub(char *s, const char *pattern, const char *insert, size_t len) { char *p; - ssize_t ls,lp,li, i; + ssize_t ls, lp, li, i; if (!insert || !pattern || !*pattern || !s) return; @@ -286,7 +286,7 @@ _PUBLIC_ void string_sub(char *s, const char *pattern, const char *insert, size_ if (len == 0) len = ls + 1; /* len is number of *bytes* */ - while (lp <= ls && (p = strstr(s,pattern))) { + while (lp <= ls && (p = strstr(s, pattern))) { if (ls + (li-lp) >= len) { DEBUG(0,("ERROR: string overflow by %d in string_sub(%.50s, %d)\n", (int)(ls + (li-lp) - len), -- cgit From 6b1c7d36f88b0c7cfdf16628d33512d4bacced88 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 24 Sep 2007 16:43:16 +0000 Subject: r25307: add string_sub_talloc. (This used to be commit 96c1a24874289fdeddcac43d23c2d1214b9b6225) --- source4/lib/util/tests/str.c | 43 +++++++++++++++++++++++++++++++++++++++++++ source4/lib/util/util.h | 4 ++++ source4/lib/util/util_str.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/tests/str.c b/source4/lib/util/tests/str.c index 4a964af0ee..a219ef0891 100644 --- a/source4/lib/util/tests/str.c +++ b/source4/lib/util/tests/str.c @@ -58,6 +58,40 @@ static bool test_string_sub_shorter(struct torture_context *tctx) return true; } +static bool test_string_sub_special_char(struct torture_context *tctx) +{ + char tmp[100]; + safe_strcpy(tmp, "foobla", sizeof(tmp)); + string_sub(tmp, "foo", "%b;l", sizeof(tmp)); + torture_assert_str_equal(tctx, tmp, "_b_lbla", "invalid sub"); + return true; +} + +static bool test_string_sub_talloc_simple(struct torture_context *tctx) +{ + char *t; + + t = string_sub_talloc(tctx, "foobla", "foo", "bl"); + + torture_assert_str_equal(tctx, t, "blbla", "invalid sub"); + + return true; +} + +static bool test_string_sub_talloc_multiple(struct torture_context *tctx) +{ + char *t; + + t = string_sub_talloc(tctx, "fooblafoo", "foo", "aapnootmies"); + + torture_assert_str_equal(tctx, t, "aapnootmiesblaaapnootmies", + "invalid sub"); + + return true; +} + + + struct torture_suite *torture_local_util_str(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, "STR"); @@ -74,5 +108,14 @@ struct torture_suite *torture_local_util_str(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "string_sub_longer", test_string_sub_longer); + torture_suite_add_simple_test(suite, "string_sub_special_chars", + test_string_sub_special_char); + + torture_suite_add_simple_test(suite, "string_sub_talloc_simple", + test_string_sub_talloc_simple); + + torture_suite_add_simple_test(suite, "string_sub_talloc_multiple", + test_string_sub_talloc_multiple); + return suite; } diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 68bf326d87..1960aa6196 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -383,6 +383,10 @@ _PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_ **/ _PUBLIC_ void string_sub(char *s,const char *pattern, const char *insert, size_t len); + +_PUBLIC_ char *string_sub_talloc(TALLOC_CTX *mem_ctx, const char *s, + const char *pattern, const char *insert); + /** Similar to string_sub() but allows for any character to be substituted. Use with caution! diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index e9f81dbd9b..9ea6403c52 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -317,6 +317,42 @@ _PUBLIC_ void string_sub(char *s, const char *pattern, const char *insert, size_ } } +/** + * Talloc'ed version of string_sub + */ +_PUBLIC_ char *string_sub_talloc(TALLOC_CTX *mem_ctx, const char *s, + const char *pattern, const char *insert) +{ + const char *p; + char *ret; + size_t len, alloc_len; + + if (insert == NULL || pattern == NULL || !*pattern || s == NULL) + return NULL; + + /* determine length needed */ + len = strlen(s); + + for (p = strstr(s, pattern); p != NULL; + p = strstr(p+strlen(pattern), pattern)) { + len += strlen(insert) - strlen(pattern); + } + + alloc_len = MAX(len, strlen(s))+1; + ret = talloc_array(mem_ctx, char, alloc_len); + if (ret == NULL) + return NULL; + strncpy(ret, s, alloc_len); + string_sub(ret, pattern, insert, alloc_len); + + ret = talloc_realloc(mem_ctx, ret, char, len+1); + if (ret == NULL) + return NULL; + + SMB_ASSERT(ret[len] == '\0'); + + return ret; +} /** Similar to string_sub() but allows for any character to be substituted. -- cgit From 14da63dbd33c21602d9ca3ccd68a9a7beea6a1d8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 1 Oct 2007 18:58:38 +0000 Subject: r25447: Fix installation of headers. Patch by Brad Hards. (This used to be commit b1aae72420362dfda7df94e8aaab8739632195dc) --- source4/lib/util/config.mk | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 702e3df5aa..a20f9d5dc6 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -3,6 +3,7 @@ #SO_VERSION = 0 #DESCRIPTION = Generic utility functions PUBLIC_HEADERS = util.h \ + attr.h \ byteorder.h \ data_blob.h \ debug.h \ -- cgit From f7c3cd1350a40efbac362f72fe2d9dcde1bce7ad Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 8 Oct 2007 10:05:13 +0000 Subject: r25566: Use -lexecinfo for backtraces on FreeBSD. Patch by Timur I. Bakeyev (This used to be commit 8d4a435601c1af42a4a6704b3181e194eb40f75a) --- source4/lib/util/config.mk | 2 +- source4/lib/util/fault.m4 | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index a20f9d5dc6..0691bd7889 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -32,7 +32,7 @@ OBJ_FILES = xfile.o \ PUBLIC_DEPENDENCIES = \ LIBTALLOC LIBCRYPTO \ SOCKET_WRAPPER EXT_NSL \ - CHARSET + CHARSET EXECINFO [SUBSYSTEM::UNIX_PRIVS] PRIVATE_PROTO_HEADER = unix_privs.h diff --git a/source4/lib/util/fault.m4 b/source4/lib/util/fault.m4 index 6d2c4f2a6a..b24e63641c 100644 --- a/source4/lib/util/fault.m4 +++ b/source4/lib/util/fault.m4 @@ -1,2 +1,5 @@ -AC_CHECK_HEADER(execinfo.h) -AC_CHECK_FUNCS(backtrace) +AC_CHECK_HEADERS(execinfo.h) +AC_SEARCH_LIBS_EXT(backtrace, [execinfo], EXECINFO_LIBS) +AC_CHECK_FUNC_EXT(backtrace, $EXECINFO_LIBS) +SMB_EXT_LIB(EXECINFO,[${EXECINFO_LIBS}]) +SMB_ENABLE(EXECINFO) -- cgit From b09047b78e981af8ade6a72d426bfcb0e742995b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 13 Oct 2007 20:24:37 +0200 Subject: r25624: Remove ipv4_addr hack. Only causes 4 extra includes of system/network.h because we stripped down includes. (This used to be commit 262c1c23a61f1f4fae13e0a61179fe98b682cecf) --- source4/lib/util/system.c | 13 +++---------- source4/lib/util/util.c | 18 +++++++++--------- source4/lib/util/util.h | 18 ++++++------------ 3 files changed, 18 insertions(+), 31 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/system.c b/source4/lib/util/system.c index 1ebc6e7e0f..9bd1800233 100644 --- a/source4/lib/util/system.c +++ b/source4/lib/util/system.c @@ -79,19 +79,12 @@ _PUBLIC_ struct hostent *sys_gethostbyname(const char *name) #endif /* REDUCE_ROOT_DNS_LOOKUPS */ } -_PUBLIC_ const char *sys_inet_ntoa(struct ipv4_addr in) -{ - struct in_addr in2; - in2.s_addr = in.addr; - return inet_ntoa(in2); -} - -_PUBLIC_ struct ipv4_addr sys_inet_makeaddr(int net, int host) +_PUBLIC_ struct in_addr sys_inet_makeaddr(int net, int host) { struct in_addr in; - struct ipv4_addr in2; + struct in_addr in2; in = inet_makeaddr(net, host); - in2.addr = in.s_addr; + in2.s_addr = in.s_addr; return in2; } diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index 624315f99e..2a2813f9af 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -285,11 +285,11 @@ _PUBLIC_ uint32_t interpret_addr(const char *str) /** A convenient addition to interpret_addr(). **/ -_PUBLIC_ struct ipv4_addr interpret_addr2(const char *str) +_PUBLIC_ struct in_addr interpret_addr2(const char *str) { - struct ipv4_addr ret; + struct in_addr ret; uint32_t a = interpret_addr(str); - ret.addr = a; + ret.s_addr = a; return ret; } @@ -297,22 +297,22 @@ _PUBLIC_ struct ipv4_addr interpret_addr2(const char *str) Check if an IP is the 0.0.0.0. **/ -_PUBLIC_ bool is_zero_ip(struct ipv4_addr ip) +_PUBLIC_ bool is_zero_ip(struct in_addr ip) { - return ip.addr == 0; + return ip.s_addr == 0; } /** Are two IPs on the same subnet? **/ -_PUBLIC_ bool same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask) +_PUBLIC_ bool same_net(struct in_addr ip1, struct in_addr ip2, struct in_addr mask) { uint32_t net1,net2,nmask; - nmask = ntohl(mask.addr); - net1 = ntohl(ip1.addr); - net2 = ntohl(ip2.addr); + nmask = ntohl(mask.s_addr); + net1 = ntohl(ip1.s_addr); + net2 = ntohl(ip2.s_addr); return((net1 & nmask) == (net2 & nmask)); } diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 1960aa6196..71880c1c1a 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -254,13 +254,7 @@ void CatchChildLeaveStatus(void); /* The following definitions come from lib/util/system.c */ -/* - we use struct ipv4_addr to avoid having to include all the - system networking headers everywhere -*/ -struct ipv4_addr { - uint32_t addr; -}; +struct in_addr; /************************************************************************** A wrapper for gethostbyname() that tries avoids looking up hostnames @@ -268,8 +262,8 @@ in the root domain, which can cause dial-on-demand links to come up for no apparent reason. ****************************************************************************/ _PUBLIC_ struct hostent *sys_gethostbyname(const char *name); -_PUBLIC_ const char *sys_inet_ntoa(struct ipv4_addr in); -_PUBLIC_ struct ipv4_addr sys_inet_makeaddr(int net, int host); +_PUBLIC_ const char *sys_inet_ntoa(struct in_addr in); +_PUBLIC_ struct in_addr sys_inet_makeaddr(int net, int host); /* The following definitions come from lib/util/genrand.c */ @@ -676,17 +670,17 @@ _PUBLIC_ uint32_t interpret_addr(const char *str); /** A convenient addition to interpret_addr(). **/ -_PUBLIC_ struct ipv4_addr interpret_addr2(const char *str); +_PUBLIC_ struct in_addr interpret_addr2(const char *str); /** Check if an IP is the 0.0.0.0. **/ -_PUBLIC_ bool is_zero_ip(struct ipv4_addr ip); +_PUBLIC_ bool is_zero_ip(struct in_addr ip); /** Are two IPs on the same subnet? **/ -_PUBLIC_ bool same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask); +_PUBLIC_ bool same_net(struct in_addr ip1,struct in_addr ip2,struct in_addr mask); /** Check if a process exists. Does this work on all unixes? -- cgit From f26222df4db2055d267789655a7113a49c178071 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 14 Oct 2007 12:52:32 +0200 Subject: r25626: Move some debug-specific prototypes to debug.h. (This used to be commit 84a202754004ec618aa2663a4614d80eb2c7ce60) --- source4/lib/util/debug.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++ source4/lib/util/fault.c | 3 ++- source4/lib/util/util.h | 55 ------------------------------------------------ 3 files changed, 56 insertions(+), 56 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/debug.h b/source4/lib/util/debug.h index 4fa2e9f598..25b28b65e9 100644 --- a/source4/lib/util/debug.h +++ b/source4/lib/util/debug.h @@ -68,3 +68,57 @@ extern int DEBUGLEVEL; /** Possible destinations for the debug log */ enum debug_logtype {DEBUG_STDOUT = 0, DEBUG_FILE = 1, DEBUG_STDERR = 2}; + +/** + the backend for debug messages. Note that the DEBUG() macro has already + ensured that the log level has been met before this is called +*/ +_PUBLIC_ void do_debug_header(int level, const char *location, const char *func); + +/** + reopen the log file (usually called because the log file name might have changed) +*/ +_PUBLIC_ void reopen_logs(void); + +/** + * this global variable determines what messages are printed + */ +_PUBLIC_ void debug_schedule_reopen_logs(void); + +/** + control the name of the logfile and whether logging will be to stdout, stderr + or a file +*/ +_PUBLIC_ void setup_logging(const char *prog_name, enum debug_logtype new_logtype); + +/** + return a string constant containing n tabs + no more than 10 tabs are returned +*/ +_PUBLIC_ const char *do_debug_tab(int n); + +/** + log suspicious usage - print comments and backtrace +*/ +_PUBLIC_ void log_suspicious_usage(const char *from, const char *info); + +/** + print suspicious usage - print comments and backtrace +*/ +_PUBLIC_ void print_suspicious_usage(const char* from, const char* info); +_PUBLIC_ uint32_t get_task_id(void); +_PUBLIC_ void log_task_id(void); + +/** + register a set of debug handlers. +*/ +_PUBLIC_ void register_debug_handlers(const char *name, struct debug_ops *ops); + +/** + the backend for debug messages. Note that the DEBUG() macro has already + ensured that the log level has been met before this is called + + @note You should never have to call this function directly. Call the DEBUG() + macro instead. +*/ +_PUBLIC_ void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2); diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index e9cd040ee6..cd347a5ef9 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -208,7 +208,8 @@ _PUBLIC_ void fault_setup(const char *pname) register a fault handler. Should only be called once in the execution of smbd. */ -_PUBLIC_ bool register_fault_handler(const char *name, void (*fault_handler)(int sig)) +_PUBLIC_ bool register_fault_handler(const char *name, + void (*fault_handler)(int sig)) { if (fault_handlers.name != NULL) { /* it's already registered! */ diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 71880c1c1a..ca11bdfef9 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -146,61 +146,6 @@ extern const char *panic_action; #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2))) #endif - -/** - * this global variable determines what messages are printed - */ -_PUBLIC_ void debug_schedule_reopen_logs(void); - -/** - the backend for debug messages. Note that the DEBUG() macro has already - ensured that the log level has been met before this is called -*/ -_PUBLIC_ void do_debug_header(int level, const char *location, const char *func); - -/** - the backend for debug messages. Note that the DEBUG() macro has already - ensured that the log level has been met before this is called - - @note You should never have to call this function directly. Call the DEBUG() - macro instead. -*/ -_PUBLIC_ void do_debug(const char *format, ...) PRINTF_ATTRIBUTE(1,2); - -/** - reopen the log file (usually called because the log file name might have changed) -*/ -_PUBLIC_ void reopen_logs(void); - -/** - control the name of the logfile and whether logging will be to stdout, stderr - or a file -*/ -_PUBLIC_ void setup_logging(const char *prog_name, enum debug_logtype new_logtype); - -/** - return a string constant containing n tabs - no more than 10 tabs are returned -*/ -_PUBLIC_ const char *do_debug_tab(int n); - -/** - log suspicious usage - print comments and backtrace -*/ -_PUBLIC_ void log_suspicious_usage(const char *from, const char *info); - -/** - print suspicious usage - print comments and backtrace -*/ -_PUBLIC_ void print_suspicious_usage(const char* from, const char* info); -_PUBLIC_ uint32_t get_task_id(void); -_PUBLIC_ void log_task_id(void); - -/** - register a set of debug handlers. -*/ -_PUBLIC_ void register_debug_handlers(const char *name, struct debug_ops *ops); - /* The following definitions come from lib/util/fault.c */ -- cgit From ef13073676be9ec073f9cec3dd9fbce90e1d1228 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 14 Oct 2007 13:00:12 +0200 Subject: r25627: Remove unused global. (This used to be commit b0b4668333b53991b04cae8905836c766e50aa10) --- source4/lib/util/dprintf.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 91665e7bdd..be716241e3 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -19,8 +19,10 @@ /* - this module provides functions for printing internal strings in the "display charset" - This charset may be quite different from the chosen unix charset + this module provides functions for printing internal strings in the + "display charset". + + This charset may be quite different from the chosen unix charset. Eventually these functions will need to take care of column count constraints @@ -99,25 +101,14 @@ _PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) return ret; } -static FILE *outfile; - _PUBLIC_ int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) { int ret; va_list ap; - if (!outfile) outfile = stdout; - va_start(ap, format); - ret = d_vfprintf(outfile, format, ap); + ret = d_vfprintf(stdout, format, ap); va_end(ap); return ret; } - -/* interactive programs need a way of tell d_*() to write to stderr instead - of stdout */ -_PUBLIC_ void display_set_stderr(void) -{ - outfile = stderr; -} -- cgit From a449b30ca4ad029243b585c386f11b689f7dfeda Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 14 Oct 2007 13:28:01 +0200 Subject: r25628: Fix formatting, missing include. (This used to be commit aafd3ea03f52b08b6697f3778728659c790d03b4) --- source4/lib/util/util.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index ca11bdfef9..42dde70a44 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -23,6 +23,9 @@ #include "charset/charset.h" +/* for TALLOC_CTX */ +#include + /** * @file * @brief Helpful macros @@ -207,7 +210,6 @@ in the root domain, which can cause dial-on-demand links to come up for no apparent reason. ****************************************************************************/ _PUBLIC_ struct hostent *sys_gethostbyname(const char *name); -_PUBLIC_ const char *sys_inet_ntoa(struct in_addr in); _PUBLIC_ struct in_addr sys_inet_makeaddr(int net, int host); /* The following definitions come from lib/util/genrand.c */ -- cgit From 6554433fc227baab93398576db703c91db1541f2 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 16 Oct 2007 01:27:15 +0200 Subject: r25660: Add a new interface 'generate_secret_buffer()', to be used when we require top-quality entropy. We don't want to waste system enropy generating challenges (which simply need to be unpredictable, not secret) or when generating UUIDs. Rework generate_random_buffer() to use /dev/urandom less often, only to seed the existing RC4 based PRNG. (With an exception to ensure we don't waste this setup cost for very small entropy requests). Perhaps we should be using heimdal's code for this instead? This should drasticly reduce our entropy use, particularly in the build farm (automated Samba build on hosts without much other source of entropy). Andrew Bartlett (This used to be commit 6a5630d37191542022f02fae519227b7829ef620) --- source4/lib/util/genrand.c | 68 ++++++++++++++++++++++++++++++++++------------ source4/lib/util/util.h | 8 ++++++ 2 files changed, 58 insertions(+), 18 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/genrand.c b/source4/lib/util/genrand.c index 4d976cecf8..31c0fce633 100644 --- a/source4/lib/util/genrand.c +++ b/source4/lib/util/genrand.c @@ -33,6 +33,10 @@ static unsigned char hash[258]; static uint32_t counter; static bool done_reseed = false; +static unsigned int bytes_since_reseed = 0; + +static int urand_fd = -1; + static void (*reseed_callback)(int *newseed); /** @@ -51,6 +55,7 @@ _PUBLIC_ void set_rand_reseed_callback(void (*fn)(int *)) _PUBLIC_ void set_need_random_reseed(void) { done_reseed = false; + bytes_since_reseed = 0; } static void get_rand_reseed_data(int *reseed_data) @@ -163,12 +168,16 @@ static int do_reseed(bool use_fd, int fd) int reseed_data = 0; if (use_fd) { - if (fd != -1) - return fd; - - fd = open( "/dev/urandom", O_RDONLY,0); - if(fd >= 0) + if (fd == -1) { + fd = open( "/dev/urandom", O_RDONLY,0); + } + if (fd != -1 + && (read(fd, seed_inbuf, sizeof(seed_inbuf)) == sizeof(seed_inbuf))) { + DEBUG(0, ("do_reseed: need %d\n", sizeof(seed_inbuf))); + call_backtrace(); + seed_random_stream(seed_inbuf, sizeof(seed_inbuf)); return fd; + } } /* Add in some secret file contents */ @@ -205,28 +214,33 @@ static int do_reseed(bool use_fd, int fd) /** Interface to the (hopefully) good crypto random number generator. + Will use our internal PRNG if more than 40 bytes of random generation + has been requested, otherwise tries to read from /dev/random **/ _PUBLIC_ void generate_random_buffer(uint8_t *out, int len) { - static int urand_fd = -1; unsigned char md4_buf[64]; unsigned char tmp_buf[16]; unsigned char *p; if(!done_reseed) { - urand_fd = do_reseed(true, urand_fd); - done_reseed = true; - } - - if (urand_fd != -1 && len > 0) { - - if (read(urand_fd, out, len) == len) - return; /* len bytes of random data read from urandom. */ + bytes_since_reseed += len; + + /* Magic constant to try and avoid reading 40 bytes + * and setting up the PRNG if the app only ever wants + * a few bytes */ + if (bytes_since_reseed < 40) { + if (urand_fd == -1) { + urand_fd = open( "/dev/urandom", O_RDONLY,0); + } + DEBUG(0, ("generate_random_buffer: need %d\n", len)); + call_backtrace(); + if(urand_fd != -1 && (read(urand_fd, out, len) == len)) { + return; + } + } - /* Read of urand error, drop back to non urand method. */ - close(urand_fd); - urand_fd = -1; - do_reseed(false, -1); + urand_fd = do_reseed(true, urand_fd); done_reseed = true; } @@ -249,6 +263,24 @@ _PUBLIC_ void generate_random_buffer(uint8_t *out, int len) } } +/** + Interface to the (hopefully) good crypto random number generator. + Will always use /dev/urandom if available. +**/ +_PUBLIC_ void generate_secret_buffer(uint8_t *out, int len) +{ + if (urand_fd == -1) { + urand_fd = open( "/dev/urandom", O_RDONLY,0); + } + DEBUG(0, ("generate_random_buffer: need %d\n", len)); + call_backtrace(); + if(urand_fd != -1 && (read(urand_fd, out, len) == len)) { + return; + } + + generate_random_buffer(out, len); +} + /** generate a single random uint32_t **/ diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 42dde70a44..fc9cb1e57a 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -226,9 +226,17 @@ _PUBLIC_ void set_need_random_reseed(void); /** Interface to the (hopefully) good crypto random number generator. + Will use our internal PRNG if more than 40 bytes of random generation + has been requested, otherwise tries to read from /dev/random **/ _PUBLIC_ void generate_random_buffer(uint8_t *out, int len); +/** + Interface to the (hopefully) good crypto random number generator. + Will always use /dev/urandom if available. +**/ +_PUBLIC_ void generate_secret_buffer(uint8_t *out, int len); + /** generate a single random uint32_t **/ -- cgit From e19d281cb74054baf017f710ecb83d461e4a0971 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 16 Oct 2007 05:26:15 +0200 Subject: r25661: We don't actually need to know with DEBUG(0, ... every time we ask for some random bytes. Andrew Bartlett (This used to be commit 606c82f6254b8dc6fb32740a7bb55a1989081fe7) --- source4/lib/util/genrand.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/genrand.c b/source4/lib/util/genrand.c index 31c0fce633..5751db23d6 100644 --- a/source4/lib/util/genrand.c +++ b/source4/lib/util/genrand.c @@ -173,8 +173,6 @@ static int do_reseed(bool use_fd, int fd) } if (fd != -1 && (read(fd, seed_inbuf, sizeof(seed_inbuf)) == sizeof(seed_inbuf))) { - DEBUG(0, ("do_reseed: need %d\n", sizeof(seed_inbuf))); - call_backtrace(); seed_random_stream(seed_inbuf, sizeof(seed_inbuf)); return fd; } @@ -233,8 +231,6 @@ _PUBLIC_ void generate_random_buffer(uint8_t *out, int len) if (urand_fd == -1) { urand_fd = open( "/dev/urandom", O_RDONLY,0); } - DEBUG(0, ("generate_random_buffer: need %d\n", len)); - call_backtrace(); if(urand_fd != -1 && (read(urand_fd, out, len) == len)) { return; } @@ -272,8 +268,6 @@ _PUBLIC_ void generate_secret_buffer(uint8_t *out, int len) if (urand_fd == -1) { urand_fd = open( "/dev/urandom", O_RDONLY,0); } - DEBUG(0, ("generate_random_buffer: need %d\n", len)); - call_backtrace(); if(urand_fd != -1 && (read(urand_fd, out, len) == len)) { return; } -- cgit From c4b9283bbb69e7754555ce7dc21c769ca205dd08 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 2 Nov 2007 11:33:53 +0100 Subject: r25799: Add dump_data_skip_zeros() which omits 16 zero bytes in a row (if not at the beginning or the end of a blob). Usefull when inspecting protocols that exchange huge mostly empty blobs. Guenther (This used to be commit c96047d022555678dabe08c0de94f0913bb4d047) --- source4/lib/util/util.c | 72 ++++++++++++++++++++++++++++++++++++++++++------- source4/lib/util/util.h | 8 ++++++ 2 files changed, 71 insertions(+), 9 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index 2a2813f9af..ac9ae779a0 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -393,24 +393,55 @@ static void print_asc(int level, const uint8_t *buf,int len) * * The data is only written if the log level is at least level. */ -_PUBLIC_ void dump_data(int level, const uint8_t *buf,int len) +static void _dump_data(int level, const uint8_t *buf, int len, + bool omit_zero_bytes) { int i=0; + const uint8_t empty[16]; + bool skipped = false; + if (len<=0) return; if (!DEBUGLVL(level)) return; - - DEBUGADD(level,("[%03X] ",i)); + + memset(&empty, '\0', 16); + for (i=0;i 0) && + (len > i+16) && + (memcmp(&buf[i], &empty, 16) == 0)) + { + i +=16; + continue; + } + + if (i i+16) && + (memcmp(&buf[i], &empty, 16) == 0)) { + if (!skipped) { + DEBUGADD(level,("skipping zero buffer bytes\n")); + skipped = true; + } + } } } + if (i%16) { int n; n = 16 - (i%16); @@ -420,11 +451,34 @@ _PUBLIC_ void dump_data(int level, const uint8_t *buf,int len) 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")); - } + if (n>0) print_asc(level,&buf[i-n],n); + DEBUGADD(level,("\n")); + } + } +/** + * Write dump of binary data to the log file. + * + * The data is only written if the log level is at least level. + */ +_PUBLIC_ void dump_data(int level, const uint8_t *buf, int len) +{ + return _dump_data(level, buf, len, false); +} + +/** + * Write dump of binary data to the log file. + * + * The data is only written if the log level is at least level. + * 16 zero bytes in a row are ommited + */ +_PUBLIC_ void dump_data_skip_zeros(int level, const uint8_t *buf, int len) +{ + return _dump_data(level, buf, len, true); +} + + /** malloc that aborts with smb_panic on fail or zero size. **/ diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index fc9cb1e57a..f3adbb3333 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -655,6 +655,14 @@ _PUBLIC_ bool fcntl_lock(int fd, int op, off_t offset, off_t count, int type); */ _PUBLIC_ void dump_data(int level, const uint8_t *buf,int len); +/** + * Write dump of binary data to the log file. + * + * The data is only written if the log level is at least level. + * 16 zero bytes in a row are ommited + */ +_PUBLIC_ void dump_data_skip_zeros(int level, const uint8_t *buf, int len); + /** malloc that aborts with smb_panic on fail or zero size. **/ -- cgit From ffc3ff734ee46c1c5837545114bbbc57ffcf6c9b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Nov 2007 12:50:24 +0100 Subject: r25802: fix the build on solaris, void functions doesn't return values metze (This used to be commit 7d6c3e31de448c59dbb6933917c4f434c90cedf6) --- source4/lib/util/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index ac9ae779a0..7b6bfeeb7b 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -464,7 +464,7 @@ static void _dump_data(int level, const uint8_t *buf, int len, */ _PUBLIC_ void dump_data(int level, const uint8_t *buf, int len) { - return _dump_data(level, buf, len, false); + _dump_data(level, buf, len, false); } /** @@ -475,7 +475,7 @@ _PUBLIC_ void dump_data(int level, const uint8_t *buf, int len) */ _PUBLIC_ void dump_data_skip_zeros(int level, const uint8_t *buf, int len) { - return _dump_data(level, buf, len, true); + _dump_data(level, buf, len, true); } -- cgit From 149190ff2108ba203f5cddd4414e2d02e469747a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 5 Nov 2007 10:10:17 +0100 Subject: r25830: fix compiler warning metze (This used to be commit 26bfdff48779447a2f4b552c5af32abf2b8c4c45) --- source4/lib/util/debug.c | 2 +- source4/lib/util/debug.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index 67663cb6ce..070cdee7d5 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -102,7 +102,7 @@ _PUBLIC_ void do_debug_header(int level, const char *location, const char *func) @note You should never have to call this function directly. Call the DEBUG() macro instead. */ -_PUBLIC_ void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) +_PUBLIC_ void do_debug(const char *format, ...) { va_list ap; char *s = NULL; diff --git a/source4/lib/util/debug.h b/source4/lib/util/debug.h index 25b28b65e9..1895ed53ad 100644 --- a/source4/lib/util/debug.h +++ b/source4/lib/util/debug.h @@ -121,4 +121,4 @@ _PUBLIC_ void register_debug_handlers(const char *name, struct debug_ops *ops); @note You should never have to call this function directly. Call the DEBUG() macro instead. */ -_PUBLIC_ void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2); +_PUBLIC_ void do_debug(const char *format, ...) PRINTF_ATTRIBUTE(1,2); -- cgit From ca0b72a1fdb7bd965065e833df34662afef0423e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 16 Nov 2007 20:12:00 +0100 Subject: r26003: Split up DB_WRAP, as first step in an attempt to sanitize dependencies. (This used to be commit 56dfcb4f2f8e74c9d8b2fe3a0df043781188a555) --- source4/lib/util/config.mk | 10 ++-- source4/lib/util/util_ldb.c | 131 ++++++++++++++++++++++++++++++++++++++++++++ source4/lib/util/util_ldb.h | 55 +++++++++++++++++++ 3 files changed, 192 insertions(+), 4 deletions(-) create mode 100644 source4/lib/util/util_ldb.c create mode 100644 source4/lib/util/util_ldb.h (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 0691bd7889..01ad14aa95 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -49,12 +49,14 @@ PUBLIC_DEPENDENCIES = XATTR # End SUBSYSTEM WRAP_XATTR ################################################ -################################################ -# Start SUBSYSTEM UTIL_TDB [SUBSYSTEM::UTIL_TDB] PUBLIC_PROTO_HEADER = util_tdb.h OBJ_FILES = \ util_tdb.o PUBLIC_DEPENDENCIES = LIBTDB -# End SUBSYSTEM UTIL_TDB -################################################ + +[SUBSYSTEM::UTIL_LDB] +PUBLIC_PROTO_HEADER = util_ldb.h +OBJ_FILES = \ + util_ldb.o +PUBLIC_DEPENDENCIES = LIBLDB diff --git a/source4/lib/util/util_ldb.c b/source4/lib/util/util_ldb.c new file mode 100644 index 0000000000..ba8443c236 --- /dev/null +++ b/source4/lib/util/util_ldb.c @@ -0,0 +1,131 @@ +/* + Unix SMB/CIFS implementation. + + common share info functions + + Copyright (C) Andrew Tridgell 2004 + Copyright (C) Tim Potter 2004 + + 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include "lib/ldb/include/ldb.h" +#include "lib/ldb/include/ldb_errors.h" + +/* + search the sam for the specified attributes - va_list variant +*/ +int gendb_search_v(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + struct ldb_message ***msgs, + const char * const *attrs, + const char *format, + va_list ap) _PRINTF_ATTRIBUTE(6,0) +{ + enum ldb_scope scope = LDB_SCOPE_SUBTREE; + struct ldb_result *res; + char *expr = NULL; + int ret; + + if (format) { + expr = talloc_vasprintf(mem_ctx, format, ap); + if (expr == NULL) { + return -1; + } + } else { + scope = LDB_SCOPE_BASE; + } + + res = NULL; + + ret = ldb_search(ldb, basedn, scope, expr, attrs, &res); + + if (ret == LDB_SUCCESS) { + talloc_steal(mem_ctx, res->msgs); + + DEBUG(6,("gendb_search_v: %s %s -> %d\n", + basedn?ldb_dn_get_linearized(basedn):"NULL", + expr?expr:"NULL", res->count)); + + ret = res->count; + *msgs = res->msgs; + talloc_free(res); + } else if (scope == LDB_SCOPE_BASE && ret == LDB_ERR_NO_SUCH_OBJECT) { + ret = 0; + *msgs = NULL; + } else { + DEBUG(4,("gendb_search_v: search failed: %s", ldb_errstring(ldb))); + ret = -1; + } + + talloc_free(expr); + + return ret; +} + +/* + search the LDB for the specified attributes - varargs variant +*/ +int gendb_search(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + struct ldb_message ***res, + const char * const *attrs, + const char *format, ...) _PRINTF_ATTRIBUTE(6,7) +{ + va_list ap; + int count; + + va_start(ap, format); + count = gendb_search_v(ldb, mem_ctx, basedn, res, attrs, format, ap); + va_end(ap); + + return count; +} + +/* + search the LDB for a specified record (by DN) +*/ + +int gendb_search_dn(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *dn, + struct ldb_message ***res, + const char * const *attrs) +{ + return gendb_search(ldb, mem_ctx, dn, res, attrs, NULL); +} + +/* + setup some initial ldif in a ldb +*/ +int gendb_add_ldif(struct ldb_context *ldb, const char *ldif_string) +{ + struct ldb_ldif *ldif; + int ret; + ldif = ldb_ldif_read_string(ldb, &ldif_string); + if (ldif == NULL) return -1; + ret = ldb_add(ldb, ldif->msg); + talloc_free(ldif); + return ret; +} + +char *wrap_casefold(void *context, void *mem_ctx, const char *s) +{ + return strupper_talloc(mem_ctx, s); +} + + diff --git a/source4/lib/util/util_ldb.h b/source4/lib/util/util_ldb.h new file mode 100644 index 0000000000..f4f56d6b18 --- /dev/null +++ b/source4/lib/util/util_ldb.h @@ -0,0 +1,55 @@ +#ifndef __LIB_UTIL_UTIL_LDB_H__ +#define __LIB_UTIL_UTIL_LDB_H__ + +#undef _PRINTF_ATTRIBUTE +#define _PRINTF_ATTRIBUTE(a1, a2) PRINTF_ATTRIBUTE(a1, a2) +/* This file was automatically generated by mkproto.pl. DO NOT EDIT */ + +#ifndef _PUBLIC_ +#define _PUBLIC_ +#endif + +#ifndef _PURE_ +#define _PURE_ +#endif + +#ifndef _NORETURN_ +#define _NORETURN_ +#endif + +#ifndef _DEPRECATED_ +#define _DEPRECATED_ +#endif + +#ifndef _WARN_UNUSED_RESULT_ +#define _WARN_UNUSED_RESULT_ +#endif + + +/* The following definitions come from lib/util/util_ldb.c */ + +int gendb_search_v(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + struct ldb_message ***msgs, + const char * const *attrs, + const char *format, + va_list ap) _PRINTF_ATTRIBUTE(6,0); +int gendb_search(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + struct ldb_message ***res, + const char * const *attrs, + const char *format, ...) _PRINTF_ATTRIBUTE(6,7); +int gendb_search_dn(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *dn, + struct ldb_message ***res, + const char * const *attrs); +int gendb_add_ldif(struct ldb_context *ldb, const char *ldif_string); +char *wrap_casefold(void *context, void *mem_ctx, const char *s); +#undef _PRINTF_ATTRIBUTE +#define _PRINTF_ATTRIBUTE(a1, a2) + +#endif /* __LIB_UTIL_UTIL_LDB_H__ */ + -- cgit From 2f8dc4f48f1802baa3405e7803563f6840e0d1b3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 3 Dec 2007 21:25:06 +0100 Subject: r26266: Remove more global_loadparm uses. (This used to be commit 99113075c4a96679bcec4f4d6bba4acb3dee4245) --- source4/lib/util/util_ldb.h | 55 --------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 source4/lib/util/util_ldb.h (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_ldb.h b/source4/lib/util/util_ldb.h deleted file mode 100644 index f4f56d6b18..0000000000 --- a/source4/lib/util/util_ldb.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef __LIB_UTIL_UTIL_LDB_H__ -#define __LIB_UTIL_UTIL_LDB_H__ - -#undef _PRINTF_ATTRIBUTE -#define _PRINTF_ATTRIBUTE(a1, a2) PRINTF_ATTRIBUTE(a1, a2) -/* This file was automatically generated by mkproto.pl. DO NOT EDIT */ - -#ifndef _PUBLIC_ -#define _PUBLIC_ -#endif - -#ifndef _PURE_ -#define _PURE_ -#endif - -#ifndef _NORETURN_ -#define _NORETURN_ -#endif - -#ifndef _DEPRECATED_ -#define _DEPRECATED_ -#endif - -#ifndef _WARN_UNUSED_RESULT_ -#define _WARN_UNUSED_RESULT_ -#endif - - -/* The following definitions come from lib/util/util_ldb.c */ - -int gendb_search_v(struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *basedn, - struct ldb_message ***msgs, - const char * const *attrs, - const char *format, - va_list ap) _PRINTF_ATTRIBUTE(6,0); -int gendb_search(struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *basedn, - struct ldb_message ***res, - const char * const *attrs, - const char *format, ...) _PRINTF_ATTRIBUTE(6,7); -int gendb_search_dn(struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *dn, - struct ldb_message ***res, - const char * const *attrs); -int gendb_add_ldif(struct ldb_context *ldb, const char *ldif_string); -char *wrap_casefold(void *context, void *mem_ctx, const char *s); -#undef _PRINTF_ATTRIBUTE -#define _PRINTF_ATTRIBUTE(a1, a2) - -#endif /* __LIB_UTIL_UTIL_LDB_H__ */ - -- cgit From 39ee38d9c1aabf4db065b433d067d0da053d7d61 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 6 Dec 2007 17:52:23 +0100 Subject: r26316: Use contexts for conversion functions. (This used to be commit f6420d933b5b011d428974f3a2a57edf19e6f482) --- source4/lib/util/dprintf.c | 2 +- source4/lib/util/ms_fnmatch.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index be716241e3..5b3fe4b1ea 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -55,7 +55,7 @@ again: SAFE_FREE(p); return -1; } - clen = convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); + clen = convert_string(global_smb_iconv_convenience, CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); if (clen == -1) { /* the string can't be converted - do the best we can, filling in non-printing chars with '?' */ diff --git a/source4/lib/util/ms_fnmatch.c b/source4/lib/util/ms_fnmatch.c index 73fb0e0966..e1bf6f94c5 100644 --- a/source4/lib/util/ms_fnmatch.c +++ b/source4/lib/util/ms_fnmatch.c @@ -64,7 +64,7 @@ static int ms_fnmatch_core(const char *p, const char *n, int i; size_t size, size_n; - while ((c = next_codepoint(p, &size))) { + while ((c = next_codepoint(global_smb_iconv_convenience, p, &size))) { p += size; switch (c) { @@ -74,7 +74,7 @@ static int ms_fnmatch_core(const char *p, const char *n, return null_match(p); } for (i=0; n[i]; i += size_n) { - next_codepoint(n+i, &size_n); + next_codepoint(global_smb_iconv_convenience, n+i, &size_n); if (ms_fnmatch_core(p, n+i, max_n+1, ldot) == 0) { return 0; } @@ -93,7 +93,7 @@ static int ms_fnmatch_core(const char *p, const char *n, return -1; } for (i=0; n[i]; i += size_n) { - next_codepoint(n+i, &size_n); + next_codepoint(global_smb_iconv_convenience, n+i, &size_n); if (ms_fnmatch_core(p, n+i, max_n+1, ldot) == 0) return 0; if (n+i == ldot) { if (ms_fnmatch_core(p, n+i+size_n, max_n+1, ldot) == 0) return 0; @@ -109,7 +109,7 @@ static int ms_fnmatch_core(const char *p, const char *n, if (! *n) { return -1; } - next_codepoint(n, &size_n); + next_codepoint(global_smb_iconv_convenience, n, &size_n); n += size_n; break; @@ -123,7 +123,7 @@ static int ms_fnmatch_core(const char *p, const char *n, break; } if (! *n) return null_match(p); - next_codepoint(n, &size_n); + next_codepoint(global_smb_iconv_convenience, n, &size_n); n += size_n; break; @@ -133,12 +133,12 @@ static int ms_fnmatch_core(const char *p, const char *n, return 0; } if (*n != '.') return -1; - next_codepoint(n, &size_n); + next_codepoint(global_smb_iconv_convenience, n, &size_n); n += size_n; break; default: - c2 = next_codepoint(n, &size_n); + c2 = next_codepoint(global_smb_iconv_convenience, n, &size_n); if (c != c2 && codepoint_cmpi(c, c2) != 0) { return -1; } -- cgit From 99930fe4e9c4665b06a41f4acc4c9127a2214681 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 11 Dec 2007 00:22:05 +0100 Subject: r26386: We need to test in more than just 'interactive' mode... Fix segfault found when running smbd without options. Andrew Bartlett (This used to be commit 880dfeadae41be5f0140ac07afb8680fc11f6ebf) --- source4/lib/util/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index 070cdee7d5..5c1abf5039 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -137,7 +137,7 @@ _PUBLIC_ void reopen_logs(void) break; case DEBUG_FILE: - if ((*logfile) == '/') { + if (logfile && (*logfile) == '/') { fname = strdup(logfile); } else { asprintf(&fname, "%s/%s.log", dyn_LOGFILEBASE, state.prog_name); -- cgit From 80b62dae14ce067fa9f13145d4ad8a8fef8b17a3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 12 Dec 2007 14:09:15 +0100 Subject: r26417: Make str_list_copy(mem_ctx, NULL) return NULL rather than an empty list. (This used to be commit cf8636c8b77c745812376d0ea6f0fb6246a2e4fb) --- source4/lib/util/tests/strlist.c | 25 +++++++++++++++++++++++++ source4/lib/util/util_strlist.c | 10 ++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/tests/strlist.c b/source4/lib/util/tests/strlist.c index 437d9d741a..3ecb982e24 100644 --- a/source4/lib/util/tests/strlist.c +++ b/source4/lib/util/tests/strlist.c @@ -64,6 +64,29 @@ static bool test_lists_shell(struct torture_context *tctx, return true; } +static bool test_list_copy(struct torture_context *tctx) +{ + const char **result; + const char *list[] = { "foo", "bar", NULL }; + const char *empty_list[] = { NULL }; + const char **null_list = NULL; + + result = str_list_copy(tctx, list); + torture_assert_int_equal(tctx, str_list_length(result), 2, "list length"); + torture_assert_str_equal(tctx, result[0], "foo", "element 0"); + torture_assert_str_equal(tctx, result[1], "bar", "element 1"); + torture_assert_str_equal(tctx, result[2], NULL, "element 2"); + + result = str_list_copy(tctx, empty_list); + torture_assert_int_equal(tctx, str_list_length(result), 0, "list length"); + torture_assert_str_equal(tctx, result[0], NULL, "element 0"); + + result = str_list_copy(tctx, null_list); + torture_assert(tctx, result == NULL, "result NULL"); + + return true; +} + struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, "STRLIST"); @@ -75,5 +98,7 @@ struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx) &test_lists_shell_strings[i]); } + torture_suite_add_simple_test(suite, "list_copy", test_list_copy); + return suite; } diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index 1f1cc17d00..30de4b962d 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -199,8 +199,14 @@ _PUBLIC_ size_t str_list_length(const char **list) _PUBLIC_ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) { int i; - const char **ret = talloc_array(mem_ctx, const char *, str_list_length(list)+1); - if (ret == NULL) return NULL; + const char **ret; + + if (list == NULL) + return NULL; + + ret = talloc_array(mem_ctx, const char *, str_list_length(list)+1); + if (ret == NULL) + return NULL; for (i=0;list && list[i];i++) { ret[i] = talloc_strdup(ret, list[i]); -- cgit From d891c0c74a03d797aed1c5ac0329fd9d1d78da63 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 22:46:09 +0100 Subject: r26429: Avoid use of global_smb_iconv_convenience. (This used to be commit d37136b7abfbba75ef2e5ab855eb3382b9648b8c) --- source4/lib/util/dprintf.c | 3 ++- source4/lib/util/ms_fnmatch.c | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 5b3fe4b1ea..ae2b7bb4d5 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -32,6 +32,7 @@ #include "includes.h" #include "system/locale.h" +#include "param/param.h" _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) { @@ -55,7 +56,7 @@ again: SAFE_FREE(p); return -1; } - clen = convert_string(global_smb_iconv_convenience, CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); + clen = convert_string(lp_iconv_convenience(global_loadparm), CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); if (clen == -1) { /* the string can't be converted - do the best we can, filling in non-printing chars with '?' */ diff --git a/source4/lib/util/ms_fnmatch.c b/source4/lib/util/ms_fnmatch.c index e1bf6f94c5..1fb57b07a4 100644 --- a/source4/lib/util/ms_fnmatch.c +++ b/source4/lib/util/ms_fnmatch.c @@ -29,6 +29,7 @@ */ #include "includes.h" +#include "param/param.h" static int null_match(const char *p) { @@ -64,7 +65,7 @@ static int ms_fnmatch_core(const char *p, const char *n, int i; size_t size, size_n; - while ((c = next_codepoint(global_smb_iconv_convenience, p, &size))) { + while ((c = next_codepoint(lp_iconv_convenience(global_loadparm), p, &size))) { p += size; switch (c) { @@ -74,7 +75,7 @@ static int ms_fnmatch_core(const char *p, const char *n, return null_match(p); } for (i=0; n[i]; i += size_n) { - next_codepoint(global_smb_iconv_convenience, n+i, &size_n); + next_codepoint(lp_iconv_convenience(global_loadparm), n+i, &size_n); if (ms_fnmatch_core(p, n+i, max_n+1, ldot) == 0) { return 0; } @@ -93,7 +94,7 @@ static int ms_fnmatch_core(const char *p, const char *n, return -1; } for (i=0; n[i]; i += size_n) { - next_codepoint(global_smb_iconv_convenience, n+i, &size_n); + next_codepoint(lp_iconv_convenience(global_loadparm), n+i, &size_n); if (ms_fnmatch_core(p, n+i, max_n+1, ldot) == 0) return 0; if (n+i == ldot) { if (ms_fnmatch_core(p, n+i+size_n, max_n+1, ldot) == 0) return 0; @@ -109,7 +110,7 @@ static int ms_fnmatch_core(const char *p, const char *n, if (! *n) { return -1; } - next_codepoint(global_smb_iconv_convenience, n, &size_n); + next_codepoint(lp_iconv_convenience(global_loadparm), n, &size_n); n += size_n; break; @@ -123,7 +124,7 @@ static int ms_fnmatch_core(const char *p, const char *n, break; } if (! *n) return null_match(p); - next_codepoint(global_smb_iconv_convenience, n, &size_n); + next_codepoint(lp_iconv_convenience(global_loadparm), n, &size_n); n += size_n; break; @@ -133,12 +134,12 @@ static int ms_fnmatch_core(const char *p, const char *n, return 0; } if (*n != '.') return -1; - next_codepoint(global_smb_iconv_convenience, n, &size_n); + next_codepoint(lp_iconv_convenience(global_loadparm), n, &size_n); n += size_n; break; default: - c2 = next_codepoint(global_smb_iconv_convenience, n, &size_n); + c2 = next_codepoint(lp_iconv_convenience(global_loadparm), n, &size_n); if (c != c2 && codepoint_cmpi(c, c2) != 0) { return -1; } -- cgit From 2bf0cdd01cf399bf28125f9e2a0d419f4e94996c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 22:46:33 +0100 Subject: r26434: Remove display charset from iconv convenience context. (This used to be commit a76625994abf9906d54ae11f9c171f89063cf508) --- source4/lib/util/dprintf.c | 38 +++++++++++++++++--------------------- source4/lib/util/util.h | 1 + 2 files changed, 18 insertions(+), 21 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index ae2b7bb4d5..308d81b105 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -2,6 +2,7 @@ Unix SMB/CIFS implementation. display print functions Copyright (C) Andrew Tridgell 2001 + Copyright (C) Jelmer Vernooij 2007 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 @@ -34,12 +35,24 @@ #include "system/locale.h" #include "param/param.h" +static smb_iconv_t display_cd = (smb_iconv_t)-1; + +void d_set_iconv(smb_iconv_t cd) +{ + display_cd = cd; +} + _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) { char *p, *p2; - int ret, maxlen, clen; + int ret, clen; va_list ap2; + /* If there's nothing to convert, take a shortcut */ + if (display_cd == (smb_iconv_t)-1) { + return vfprintf(f, format, ap); + } + /* do any message translations */ va_copy(ap2, ap); ret = vasprintf(&p, format, ap2); @@ -47,16 +60,7 @@ _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBU if (ret <= 0) return ret; - /* now we have the string in unix format, convert it to the display - charset, but beware of it growing */ - maxlen = ret*2; -again: - p2 = (char *)malloc(maxlen); - if (!p2) { - SAFE_FREE(p); - return -1; - } - clen = convert_string(lp_iconv_convenience(global_loadparm), CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); + clen = convert_string_talloc_descriptor(NULL, display_cd, p, ret, (void **)&p2); if (clen == -1) { /* the string can't be converted - do the best we can, filling in non-printing chars with '?' */ @@ -69,22 +73,13 @@ again: } } SAFE_FREE(p); - SAFE_FREE(p2); return ret; } - - if (clen >= maxlen) { - /* it didn't fit - try a larger buffer */ - maxlen *= 2; - SAFE_FREE(p2); - goto again; - } - /* good, its converted OK */ SAFE_FREE(p); ret = fwrite(p2, 1, clen, f); - SAFE_FREE(p2); + talloc_free(p2); return ret; } @@ -113,3 +108,4 @@ _PUBLIC_ int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) return ret; } + diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index f3adbb3333..9e106052f2 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -262,6 +262,7 @@ _PUBLIC_ char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len); /* The following definitions come from lib/util/dprintf.c */ +_PUBLIC_ void d_set_iconv(smb_iconv_t); _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0); _PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) PRINTF_ATTRIBUTE(2,3); _PUBLIC_ int d_printf(const char *format, ...) PRINTF_ATTRIBUTE(1,2); -- cgit From 8959ce0ea672a59cada4b39071443cf8cad3ad2d Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Fri, 14 Dec 2007 14:47:07 +0100 Subject: r26457: Janitorial: Don't use pstring in tdb_unpack (This used to be commit 447bc42180cf0be71a35e40f6d93d91879397a48) --- source4/lib/util/util_tdb.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_tdb.c b/source4/lib/util/util_tdb.c index d7bddbde01..77ad4eb617 100644 --- a/source4/lib/util/util_tdb.c +++ b/source4/lib/util/util_tdb.c @@ -445,7 +445,7 @@ int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...) int len; int *i; void **p; - char *s, **b; + char *s, **b, **ps; char c; char *buf0 = buf; const char *fmt0 = fmt; @@ -453,7 +453,7 @@ int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...) tdb_log_func log_fn = tdb_log_fn(tdb); va_start(ap, fmt); - + while (*fmt) { switch ((c=*fmt++)) { case 'b': @@ -485,11 +485,10 @@ int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...) *p = (void *)IVAL(buf, 0); break; case 'P': - s = va_arg(ap,char *); - len = strlen(buf) + 1; - if (bufsize < len || len > sizeof(pstring)) - goto no_space; - memcpy(s, buf, len); + /* Return a malloc'ed string. */ + ps = va_arg(ap,char ** ); + len = strlen((const char *)buf) + 1; + *ps = strdup((const char *)buf); break; case 'f': s = va_arg(ap,char *); @@ -518,7 +517,7 @@ int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...) memcpy(*b, buf+4, *i); break; default: - log_fn(tdb, 0, "Unknown tdb_unpack format %c in %s\n", + log_fn(tdb, 0, "Unknown tdb_unpack format %c in %s\n", c, fmt); len = 0; @@ -531,7 +530,7 @@ int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...) va_end(ap); - log_fn(tdb, 18, "tdb_unpack(%s, %d) -> %d\n", + log_fn(tdb, 18, "tdb_unpack(%s, %d) -> %d\n", fmt0, bufsize0, (int)PTR_DIFF(buf, buf0)); return PTR_DIFF(buf, buf0); -- cgit From ac4237e9971bd50ef194f2166365ff91af4dbfaa Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Mon, 17 Dec 2007 18:31:16 +0100 Subject: r26511: Janitorial: Fix a warning for the 'printf' attribute on gendb_search_v While at it, also add a PRINTF_ATTRIBUTE for talloc_vasprintf. (This used to be commit 5b3a8c8ae195e6a98357a407a0699493f54a8b79) --- source4/lib/util/util_ldb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_ldb.c b/source4/lib/util/util_ldb.c index ba8443c236..a8719af190 100644 --- a/source4/lib/util/util_ldb.c +++ b/source4/lib/util/util_ldb.c @@ -23,16 +23,16 @@ #include "includes.h" #include "lib/ldb/include/ldb.h" #include "lib/ldb/include/ldb_errors.h" - +#include "lib/util/util_ldb.h" /* search the sam for the specified attributes - va_list variant */ -int gendb_search_v(struct ldb_context *ldb, +int gendb_search_v(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_dn *basedn, struct ldb_message ***msgs, const char * const *attrs, - const char *format, + const char *format, va_list ap) _PRINTF_ATTRIBUTE(6,0) { enum ldb_scope scope = LDB_SCOPE_SUBTREE; -- cgit From 3c744ddd2c33a9a06013f357261b8ea86804e8e8 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Mon, 24 Dec 2007 13:04:56 -0600 Subject: r26588: Janitorial: Rename torture_*_add_*test to torture_*_add_*test_const. Also rename the corresponding wrap_ functions. (This used to be commit e59c2eaf681f076d175b9779d1c27b5f74a57c96) --- source4/lib/util/tests/strlist.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/tests/strlist.c b/source4/lib/util/tests/strlist.c index 3ecb982e24..9af26f9e71 100644 --- a/source4/lib/util/tests/strlist.c +++ b/source4/lib/util/tests/strlist.c @@ -93,9 +93,8 @@ struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx) int i; for (i = 0; test_lists_shell_strings[i]; i++) { - torture_suite_add_simple_tcase(suite, - "lists_shell", test_lists_shell, - &test_lists_shell_strings[i]); + torture_suite_add_simple_tcase_const(suite, "lists_shell", + test_lists_shell, &test_lists_shell_strings[i]); } torture_suite_add_simple_test(suite, "list_copy", test_list_copy); -- cgit From 939edd0eb7c3952859afb802c8e542449a2c4031 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 15 Jan 2008 01:04:38 +0100 Subject: util: Move asn1 to lib/util to trim down the number of subsystems. (This used to be commit 44e1cfd2d0ef62e4ee541cec00581a7151d951b3) --- source4/lib/util/asn1.c | 770 +++++++++++++++++++++++++++++++++++++++++++++ source4/lib/util/asn1.h | 54 ++++ source4/lib/util/config.mk | 5 + 3 files changed, 829 insertions(+) create mode 100644 source4/lib/util/asn1.c create mode 100644 source4/lib/util/asn1.h (limited to 'source4/lib/util') diff --git a/source4/lib/util/asn1.c b/source4/lib/util/asn1.c new file mode 100644 index 0000000000..4756c0640d --- /dev/null +++ b/source4/lib/util/asn1.c @@ -0,0 +1,770 @@ +/* + Unix SMB/CIFS implementation. + simple ASN1 routines + Copyright (C) Andrew Tridgell 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include "lib/util/asn1.h" + +/* allocate an asn1 structure */ +struct asn1_data *asn1_init(TALLOC_CTX *mem_ctx) +{ + struct asn1_data *ret = talloc_zero(mem_ctx, struct asn1_data); + if (ret == NULL) { + DEBUG(0,("asn1_init failed! out of memory\n")); + } + return ret; +} + +/* free an asn1 structure */ +void asn1_free(struct asn1_data *data) +{ + talloc_free(data); +} + +/* write to the ASN1 buffer, advancing the buffer pointer */ +bool asn1_write(struct asn1_data *data, const void *p, int len) +{ + if (data->has_error) return false; + if (data->length < data->ofs+len) { + uint8_t *newp; + newp = talloc_realloc(data, data->data, uint8_t, data->ofs+len); + if (!newp) { + asn1_free(data); + data->has_error = true; + return false; + } + data->data = newp; + data->length = data->ofs+len; + } + memcpy(data->data + data->ofs, p, len); + data->ofs += len; + return true; +} + +/* useful fn for writing a uint8_t */ +bool asn1_write_uint8(struct asn1_data *data, uint8_t v) +{ + return asn1_write(data, &v, 1); +} + +/* push a tag onto the asn1 data buffer. Used for nested structures */ +bool asn1_push_tag(struct asn1_data *data, uint8_t tag) +{ + struct nesting *nesting; + + asn1_write_uint8(data, tag); + nesting = talloc(data, struct nesting); + if (!nesting) { + data->has_error = true; + return false; + } + + nesting->start = data->ofs; + nesting->next = data->nesting; + data->nesting = nesting; + return asn1_write_uint8(data, 0xff); +} + +/* pop a tag */ +bool asn1_pop_tag(struct asn1_data *data) +{ + struct nesting *nesting; + size_t len; + + nesting = data->nesting; + + if (!nesting) { + data->has_error = true; + return false; + } + len = data->ofs - (nesting->start+1); + /* yes, this is ugly. We don't know in advance how many bytes the length + of a tag will take, so we assumed 1 byte. If we were wrong then we + need to correct our mistake */ + if (len > 0xFFFFFF) { + data->data[nesting->start] = 0x84; + if (!asn1_write_uint8(data, 0)) return false; + if (!asn1_write_uint8(data, 0)) return false; + if (!asn1_write_uint8(data, 0)) return false; + if (!asn1_write_uint8(data, 0)) return false; + memmove(data->data+nesting->start+5, data->data+nesting->start+1, len); + data->data[nesting->start+1] = (len>>24) & 0xFF; + data->data[nesting->start+2] = (len>>16) & 0xFF; + data->data[nesting->start+3] = (len>>8) & 0xFF; + data->data[nesting->start+4] = len&0xff; + } else if (len > 0xFFFF) { + data->data[nesting->start] = 0x83; + if (!asn1_write_uint8(data, 0)) return false; + if (!asn1_write_uint8(data, 0)) return false; + if (!asn1_write_uint8(data, 0)) return false; + memmove(data->data+nesting->start+4, data->data+nesting->start+1, len); + data->data[nesting->start+1] = (len>>16) & 0xFF; + data->data[nesting->start+2] = (len>>8) & 0xFF; + data->data[nesting->start+3] = len&0xff; + } else if (len > 255) { + data->data[nesting->start] = 0x82; + if (!asn1_write_uint8(data, 0)) return false; + if (!asn1_write_uint8(data, 0)) return false; + memmove(data->data+nesting->start+3, data->data+nesting->start+1, len); + data->data[nesting->start+1] = len>>8; + data->data[nesting->start+2] = len&0xff; + } else if (len > 127) { + data->data[nesting->start] = 0x81; + if (!asn1_write_uint8(data, 0)) return false; + memmove(data->data+nesting->start+2, data->data+nesting->start+1, len); + data->data[nesting->start+1] = len; + } else { + data->data[nesting->start] = len; + } + + data->nesting = nesting->next; + talloc_free(nesting); + return true; +} + +/* "i" is the one's complement representation, as is the normal result of an + * implicit signed->unsigned conversion */ + +static bool push_int_bigendian(struct asn1_data *data, unsigned int i, bool negative) +{ + uint8_t lowest = i & 0xFF; + + i = i >> 8; + if (i != 0) + if (!push_int_bigendian(data, i, negative)) + return false; + + if (data->nesting->start+1 == data->ofs) { + + /* We did not write anything yet, looking at the highest + * valued byte */ + + if (negative) { + /* Don't write leading 0xff's */ + if (lowest == 0xFF) + return true; + + if ((lowest & 0x80) == 0) { + /* The only exception for a leading 0xff is if + * the highest bit is 0, which would indicate + * a positive value */ + if (!asn1_write_uint8(data, 0xff)) + return false; + } + } else { + if (lowest & 0x80) { + /* The highest bit of a positive integer is 1, + * this would indicate a negative number. Push + * a 0 to indicate a positive one */ + if (!asn1_write_uint8(data, 0)) + return false; + } + } + } + + return asn1_write_uint8(data, lowest); +} + +/* write an Integer without the tag framing. Needed for example for the LDAP + * Abandon Operation */ + +bool asn1_write_implicit_Integer(struct asn1_data *data, int i) +{ + if (i == -1) { + /* -1 is special as it consists of all-0xff bytes. In + push_int_bigendian this is the only case that is not + properly handled, as all 0xff bytes would be handled as + leading ones to be ignored. */ + return asn1_write_uint8(data, 0xff); + } else { + return push_int_bigendian(data, i, i<0); + } +} + + +/* write an integer */ +bool asn1_write_Integer(struct asn1_data *data, int i) +{ + if (!asn1_push_tag(data, ASN1_INTEGER)) return false; + if (!asn1_write_implicit_Integer(data, i)) return false; + return asn1_pop_tag(data); +} + +bool ber_write_OID_String(DATA_BLOB *blob, const char *OID) +{ + uint_t v, v2; + const char *p = (const char *)OID; + char *newp; + int i; + + v = strtoul(p, &newp, 10); + if (newp[0] != '.') return false; + p = newp + 1; + + v2 = strtoul(p, &newp, 10); + if (newp[0] != '.') return false; + p = newp + 1; + + /*the ber representation can't use more space then the string one */ + *blob = data_blob(NULL, strlen(OID)); + if (!blob->data) return false; + + blob->data[0] = 40*v + v2; + + i = 1; + while (*p) { + v = strtoul(p, &newp, 10); + if (newp[0] == '.') { + p = newp + 1; + } else if (newp[0] == '\0') { + p = newp; + } else { + data_blob_free(blob); + return false; + } + if (v >= (1<<28)) blob->data[i++] = (0x80 | ((v>>28)&0x7f)); + if (v >= (1<<21)) blob->data[i++] = (0x80 | ((v>>21)&0x7f)); + if (v >= (1<<14)) blob->data[i++] = (0x80 | ((v>>14)&0x7f)); + if (v >= (1<<7)) blob->data[i++] = (0x80 | ((v>>7)&0x7f)); + blob->data[i++] = (v&0x7f); + } + + blob->length = i; + + return true; +} + +/* write an object ID to a ASN1 buffer */ +bool asn1_write_OID(struct asn1_data *data, const char *OID) +{ + DATA_BLOB blob; + + if (!asn1_push_tag(data, ASN1_OID)) return false; + + if (!ber_write_OID_String(&blob, OID)) { + data->has_error = true; + return false; + } + + if (!asn1_write(data, blob.data, blob.length)) { + data->has_error = true; + return false; + } + data_blob_free(&blob); + return asn1_pop_tag(data); +} + +/* write an octet string */ +bool asn1_write_OctetString(struct asn1_data *data, const void *p, size_t length) +{ + asn1_push_tag(data, ASN1_OCTET_STRING); + asn1_write(data, p, length); + asn1_pop_tag(data); + return !data->has_error; +} + +/* write a LDAP string */ +bool asn1_write_LDAPString(struct asn1_data *data, const char *s) +{ + asn1_write(data, s, strlen(s)); + return !data->has_error; +} + +/* write a LDAP string from a DATA_BLOB */ +bool asn1_write_DATA_BLOB_LDAPString(struct asn1_data *data, const DATA_BLOB *s) +{ + asn1_write(data, s->data, s->length); + return !data->has_error; +} + +/* write a general string */ +bool asn1_write_GeneralString(struct asn1_data *data, const char *s) +{ + asn1_push_tag(data, ASN1_GENERAL_STRING); + asn1_write_LDAPString(data, s); + asn1_pop_tag(data); + return !data->has_error; +} + +bool asn1_write_ContextSimple(struct asn1_data *data, uint8_t num, DATA_BLOB *blob) +{ + asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(num)); + asn1_write(data, blob->data, blob->length); + asn1_pop_tag(data); + return !data->has_error; +} + +/* write a BOOLEAN */ +bool asn1_write_BOOLEAN(struct asn1_data *data, bool v) +{ + asn1_push_tag(data, ASN1_BOOLEAN); + asn1_write_uint8(data, v ? 0xFF : 0); + asn1_pop_tag(data); + return !data->has_error; +} + +bool asn1_read_BOOLEAN(struct asn1_data *data, bool *v) +{ + uint8_t tmp = 0; + asn1_start_tag(data, ASN1_BOOLEAN); + asn1_read_uint8(data, &tmp); + if (tmp == 0xFF) { + *v = true; + } else { + *v = false; + } + asn1_end_tag(data); + return !data->has_error; +} + +/* check a BOOLEAN */ +bool asn1_check_BOOLEAN(struct asn1_data *data, bool v) +{ + uint8_t b = 0; + + asn1_read_uint8(data, &b); + if (b != ASN1_BOOLEAN) { + data->has_error = true; + return false; + } + asn1_read_uint8(data, &b); + if (b != v) { + data->has_error = true; + return false; + } + return !data->has_error; +} + + +/* load a struct asn1_data structure with a lump of data, ready to be parsed */ +bool asn1_load(struct asn1_data *data, DATA_BLOB blob) +{ + ZERO_STRUCTP(data); + data->data = talloc_memdup(data, blob.data, blob.length); + if (!data->data) { + data->has_error = true; + return false; + } + data->length = blob.length; + return true; +} + +/* Peek into an ASN1 buffer, not advancing the pointer */ +bool asn1_peek(struct asn1_data *data, void *p, int len) +{ + if (data->has_error) + return false; + + if (len < 0 || data->ofs + len < data->ofs || data->ofs + len < len) + return false; + + if (data->ofs + len > data->length) { + /* we need to mark the buffer as consumed, so the caller knows + this was an out of data error, and not a decode error */ + data->ofs = data->length; + return false; + } + + memcpy(p, data->data + data->ofs, len); + return true; +} + +/* read from a ASN1 buffer, advancing the buffer pointer */ +bool asn1_read(struct asn1_data *data, void *p, int len) +{ + if (!asn1_peek(data, p, len)) { + data->has_error = true; + return false; + } + + data->ofs += len; + return true; +} + +/* read a uint8_t from a ASN1 buffer */ +bool asn1_read_uint8(struct asn1_data *data, uint8_t *v) +{ + return asn1_read(data, v, 1); +} + +bool asn1_peek_uint8(struct asn1_data *data, uint8_t *v) +{ + return asn1_peek(data, v, 1); +} + +bool asn1_peek_tag(struct asn1_data *data, uint8_t tag) +{ + uint8_t b; + + if (asn1_tag_remaining(data) <= 0) { + return false; + } + + if (!asn1_peek_uint8(data, &b)) + return false; + + return (b == tag); +} + +/* start reading a nested asn1 structure */ +bool asn1_start_tag(struct asn1_data *data, uint8_t tag) +{ + uint8_t b; + struct nesting *nesting; + + if (!asn1_read_uint8(data, &b)) + return false; + + if (b != tag) { + data->has_error = true; + return false; + } + nesting = talloc(data, struct nesting); + if (!nesting) { + data->has_error = true; + return false; + } + + if (!asn1_read_uint8(data, &b)) { + return false; + } + + if (b & 0x80) { + int n = b & 0x7f; + if (!asn1_read_uint8(data, &b)) + return false; + nesting->taglen = b; + while (n > 1) { + if (!asn1_read_uint8(data, &b)) + return false; + nesting->taglen = (nesting->taglen << 8) | b; + n--; + } + } else { + nesting->taglen = b; + } + nesting->start = data->ofs; + nesting->next = data->nesting; + data->nesting = nesting; + if (asn1_tag_remaining(data) == -1) { + return false; + } + return !data->has_error; +} + +/* stop reading a tag */ +bool asn1_end_tag(struct asn1_data *data) +{ + struct nesting *nesting; + + /* make sure we read it all */ + if (asn1_tag_remaining(data) != 0) { + data->has_error = true; + return false; + } + + nesting = data->nesting; + + if (!nesting) { + data->has_error = true; + return false; + } + + data->nesting = nesting->next; + talloc_free(nesting); + return true; +} + +/* work out how many bytes are left in this nested tag */ +int asn1_tag_remaining(struct asn1_data *data) +{ + int remaining; + if (data->has_error) { + return -1; + } + + if (!data->nesting) { + data->has_error = true; + return -1; + } + remaining = data->nesting->taglen - (data->ofs - data->nesting->start); + if (remaining > (data->length - data->ofs)) { + data->has_error = true; + return -1; + } + return remaining; +} + +/* read an object ID from a data blob */ +bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID) +{ + int i; + uint8_t *b; + uint_t v; + char *tmp_oid = NULL; + + if (blob.length < 2) return false; + + b = blob.data; + + tmp_oid = talloc_asprintf(mem_ctx, "%u", b[0]/40); + if (!tmp_oid) goto nomem; + tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u", b[0]%40); + if (!tmp_oid) goto nomem; + + for(i = 1, v = 0; i < blob.length; i++) { + v = (v<<7) | (b[i]&0x7f); + if ( ! (b[i] & 0x80)) { + tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u", v); + v = 0; + } + if (!tmp_oid) goto nomem; + } + + if (v != 0) { + talloc_free(tmp_oid); + return false; + } + + *OID = tmp_oid; + return true; + +nomem: + return false; +} + +/* read an object ID from a ASN1 buffer */ +bool asn1_read_OID(struct asn1_data *data, TALLOC_CTX *mem_ctx, const char **OID) +{ + DATA_BLOB blob; + int len; + + if (!asn1_start_tag(data, ASN1_OID)) return false; + + len = asn1_tag_remaining(data); + if (len < 0) { + data->has_error = true; + return false; + } + + blob = data_blob(NULL, len); + if (!blob.data) { + data->has_error = true; + return false; + } + + asn1_read(data, blob.data, len); + asn1_end_tag(data); + if (data->has_error) { + data_blob_free(&blob); + return false; + } + + if (!ber_read_OID_String(mem_ctx, blob, OID)) { + data->has_error = true; + data_blob_free(&blob); + return false; + } + + data_blob_free(&blob); + return true; +} + +/* check that the next object ID is correct */ +bool asn1_check_OID(struct asn1_data *data, const char *OID) +{ + const char *id; + + if (!asn1_read_OID(data, data, &id)) return false; + + if (strcmp(id, OID) != 0) { + talloc_free(discard_const(id)); + data->has_error = true; + return false; + } + talloc_free(discard_const(id)); + return true; +} + +/* read a LDAPString from a ASN1 buffer */ +bool asn1_read_LDAPString(struct asn1_data *data, TALLOC_CTX *mem_ctx, char **s) +{ + int len; + len = asn1_tag_remaining(data); + if (len < 0) { + data->has_error = true; + return false; + } + *s = talloc_array(mem_ctx, char, len+1); + if (! *s) { + data->has_error = true; + return false; + } + asn1_read(data, *s, len); + (*s)[len] = 0; + return !data->has_error; +} + + +/* read a GeneralString from a ASN1 buffer */ +bool asn1_read_GeneralString(struct asn1_data *data, TALLOC_CTX *mem_ctx, char **s) +{ + if (!asn1_start_tag(data, ASN1_GENERAL_STRING)) return false; + if (!asn1_read_LDAPString(data, mem_ctx, s)) return false; + return asn1_end_tag(data); +} + + +/* read a octet string blob */ +bool asn1_read_OctetString(struct asn1_data *data, TALLOC_CTX *mem_ctx, DATA_BLOB *blob) +{ + int len; + ZERO_STRUCTP(blob); + if (!asn1_start_tag(data, ASN1_OCTET_STRING)) return false; + len = asn1_tag_remaining(data); + if (len < 0) { + data->has_error = true; + return false; + } + *blob = data_blob_talloc(mem_ctx, NULL, len+1); + if (!blob->data) { + data->has_error = true; + return false; + } + asn1_read(data, blob->data, len); + asn1_end_tag(data); + blob->length--; + blob->data[len] = 0; + + if (data->has_error) { + data_blob_free(blob); + *blob = data_blob(NULL, 0); + return false; + } + return true; +} + +bool asn1_read_ContextSimple(struct asn1_data *data, uint8_t num, DATA_BLOB *blob) +{ + int len; + ZERO_STRUCTP(blob); + if (!asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(num))) return false; + len = asn1_tag_remaining(data); + if (len < 0) { + data->has_error = true; + return false; + } + *blob = data_blob(NULL, len); + if ((len != 0) && (!blob->data)) { + data->has_error = true; + return false; + } + asn1_read(data, blob->data, len); + asn1_end_tag(data); + return !data->has_error; +} + +/* read an integer without tag*/ +bool asn1_read_implicit_Integer(struct asn1_data *data, int *i) +{ + uint8_t b; + *i = 0; + + while (!data->has_error && asn1_tag_remaining(data)>0) { + if (!asn1_read_uint8(data, &b)) return false; + *i = (*i << 8) + b; + } + return !data->has_error; + +} + +/* read an integer */ +bool asn1_read_Integer(struct asn1_data *data, int *i) +{ + *i = 0; + + if (!asn1_start_tag(data, ASN1_INTEGER)) return false; + if (!asn1_read_implicit_Integer(data, i)) return false; + return asn1_end_tag(data); +} + +/* read an integer */ +bool asn1_read_enumerated(struct asn1_data *data, int *v) +{ + *v = 0; + + if (!asn1_start_tag(data, ASN1_ENUMERATED)) return false; + while (!data->has_error && asn1_tag_remaining(data)>0) { + uint8_t b; + asn1_read_uint8(data, &b); + *v = (*v << 8) + b; + } + return asn1_end_tag(data); +} + +/* check a enumerated value is correct */ +bool asn1_check_enumerated(struct asn1_data *data, int v) +{ + uint8_t b; + if (!asn1_start_tag(data, ASN1_ENUMERATED)) return false; + asn1_read_uint8(data, &b); + asn1_end_tag(data); + + if (v != b) + data->has_error = false; + + return !data->has_error; +} + +/* write an enumerated value to the stream */ +bool asn1_write_enumerated(struct asn1_data *data, uint8_t v) +{ + if (!asn1_push_tag(data, ASN1_ENUMERATED)) return false; + asn1_write_uint8(data, v); + asn1_pop_tag(data); + return !data->has_error; +} + +/* + check if a ASN.1 blob is a full tag +*/ +NTSTATUS asn1_full_tag(DATA_BLOB blob, uint8_t tag, size_t *packet_size) +{ + struct asn1_data *asn1 = asn1_init(NULL); + int size; + + NT_STATUS_HAVE_NO_MEMORY(asn1); + + asn1->data = blob.data; + asn1->length = blob.length; + asn1_start_tag(asn1, tag); + if (asn1->has_error) { + talloc_free(asn1); + return STATUS_MORE_ENTRIES; + } + size = asn1_tag_remaining(asn1) + asn1->ofs; + + talloc_free(asn1); + + if (size > blob.length) { + return STATUS_MORE_ENTRIES; + } + + *packet_size = size; + return NT_STATUS_OK; +} diff --git a/source4/lib/util/asn1.h b/source4/lib/util/asn1.h new file mode 100644 index 0000000000..34aa1e2cb9 --- /dev/null +++ b/source4/lib/util/asn1.h @@ -0,0 +1,54 @@ +/* + Unix SMB/CIFS implementation. + simple ASN1 code + Copyright (C) Andrew Tridgell 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef _ASN_1_H +#define _ASN_1_H + +struct nesting { + off_t start; + size_t taglen; /* for parsing */ + struct nesting *next; +}; + +struct asn1_data { + uint8_t *data; + size_t length; + off_t ofs; + struct nesting *nesting; + bool has_error; +}; + +#define ASN1_APPLICATION(x) ((x)+0x60) +#define ASN1_APPLICATION_SIMPLE(x) ((x)+0x40) +#define ASN1_SEQUENCE(x) ((x)+0x30) +#define ASN1_CONTEXT(x) ((x)+0xa0) +#define ASN1_CONTEXT_SIMPLE(x) ((x)+0x80) +#define ASN1_GENERAL_STRING 0x1b +#define ASN1_OCTET_STRING 0x4 +#define ASN1_OID 0x6 +#define ASN1_BOOLEAN 0x1 +#define ASN1_INTEGER 0x2 +#define ASN1_ENUMERATED 0xa +#define ASN1_SET 0x31 + +#define ASN1_MAX_OIDS 20 + +#include "lib/util/asn1_proto.h" + +#endif /* _ASN_1_H */ diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 01ad14aa95..53a55bf7af 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -34,6 +34,11 @@ PUBLIC_DEPENDENCIES = \ SOCKET_WRAPPER EXT_NSL \ CHARSET EXECINFO +[SUBSYSTEM::ASN1_UTIL] +PUBLIC_PROTO_HEADER = asn1_proto.h +PUBLIC_HEADERS = asn1.h +OBJ_FILES = asn1.o + [SUBSYSTEM::UNIX_PRIVS] PRIVATE_PROTO_HEADER = unix_privs.h OBJ_FILES = unix_privs.o -- cgit From a2595477869d5fee2f916bc857ca028e3b2fc677 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 22 Jan 2008 18:49:51 +0100 Subject: build: Remove support for DESCRIPTION setting that is now unused. (This used to be commit 91d7ba5202e6c375456a42c2c6861f63c7fcfc20) --- source4/lib/util/config.mk | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 53a55bf7af..f3e6cd7acf 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -1,7 +1,6 @@ [SUBSYSTEM::LIBSAMBA-UTIL] #VERSION = 0.0.1 #SO_VERSION = 0 -#DESCRIPTION = Generic utility functions PUBLIC_HEADERS = util.h \ attr.h \ byteorder.h \ -- cgit From 77a2870186d3b10ea15ba5e001e7a703f0a5ccaf Mon Sep 17 00:00:00 2001 From: Amin Azez Date: Fri, 1 Feb 2008 16:19:36 +0000 Subject: Samba4 poor mans debug_ctx() DEBUG(), DEBUGADD() and friends can now use debug_ctx() in the formatting expressions again, e.g. DEBUG(5,("Guid failed to match: %s\n", GUID_string(debug_ctx(), r->guid))); Sadly it's done with macros (again) but when we need to save the 8 or 16 bytes of object code per DEBUG() expression we can do it the Samba 3 way with added thread-safety for Samba 4. That could save up to 200K, allowing 12 bytes for each occurrance of DEBUG... Signed-off-by: Amin Azez (This used to be commit 9781967542b00c279563d435aec72dac1e8c7e9a) --- source4/lib/util/debug.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/debug.h b/source4/lib/util/debug.h index 1895ed53ad..605628174a 100644 --- a/source4/lib/util/debug.h +++ b/source4/lib/util/debug.h @@ -41,13 +41,17 @@ struct debug_ops { extern int DEBUGLEVEL; +#define debug_ctx() (_debug_ctx?_debug_ctx:(_debug_ctx=talloc_new(NULL))) + #define DEBUGLVL(level) ((level) <= DEBUGLEVEL) #define _DEBUG(level, body, header) do { \ if (DEBUGLVL(level)) { \ + void* _debug_ctx=NULL; \ if (header) { \ do_debug_header(level, __location__, __FUNCTION__); \ } \ do_debug body; \ + talloc_free(_debug_ctx); \ } \ } while (0) /** -- cgit From 3525f77e56966d688a11e3f4520e9cd799fd4f23 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 9 Feb 2008 14:24:24 +0100 Subject: Move nt_time_equal() to libutil. (This used to be commit 9705263a6c58d4ade556d17db2009dbb85291b22) --- source4/lib/util/time.c | 8 ++++++++ source4/lib/util/time.h | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/time.c b/source4/lib/util/time.c index fc51498009..a181885806 100644 --- a/source4/lib/util/time.c +++ b/source4/lib/util/time.c @@ -612,3 +612,11 @@ _PUBLIC_ int get_time_zone(time_t t) return 0; return tm_diff(&tm_utc,tm); } + +/** + check if 2 NTTIMEs are equal. +*/ +bool nt_time_equal(NTTIME *t1, NTTIME *t2) +{ + return *t1 == *t2; +} diff --git a/source4/lib/util/time.h b/source4/lib/util/time.h index 557c5d4eab..1ab976ca78 100644 --- a/source4/lib/util/time.h +++ b/source4/lib/util/time.h @@ -224,6 +224,9 @@ _PUBLIC_ void nttime_to_timeval(struct timeval *tv, NTTIME t); */ _PUBLIC_ int get_time_zone(time_t t); - +/** + check if 2 NTTIMEs are equal. +*/ +bool nt_time_equal(NTTIME *t1, NTTIME *t2); #endif /* _SAMBA_TIME_H_ */ -- cgit From e0a5fb8a9be9f3002d6f73c272793a75fa71d313 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 11 Feb 2008 12:39:47 +0100 Subject: Fix typo. (This used to be commit 54e7d10fe0eb4837b00b9b049fbd59a56ee85bea) --- source4/lib/util/fault.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index cd347a5ef9..cb51cbd859 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -178,7 +178,7 @@ _NORETURN_ static void sig_fault(int sig) /* we have a fault handler, call it. It may not return. */ fault_handlers.fault_handler(sig); } - /* If it returns or doean't exist, use regular reporter */ + /* If it returns or doesn't exist, use regular reporter */ fault_report(sig); } -- cgit From f22598a95c5a42c6453f11e5e95c720e8b61c4fc Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Wed, 13 Feb 2008 23:35:43 +0100 Subject: util_ldb: Add a missing \n to debug string, fix trailing whitespaces. (This used to be commit b0991cc09b36171c18d2407c9f3153b6f7e8299b) --- source4/lib/util/util_ldb.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_ldb.c b/source4/lib/util/util_ldb.c index a8719af190..f1b42effd8 100644 --- a/source4/lib/util/util_ldb.c +++ b/source4/lib/util/util_ldb.c @@ -1,21 +1,21 @@ -/* +/* Unix SMB/CIFS implementation. common share info functions Copyright (C) Andrew Tridgell 2004 Copyright (C) Tim Potter 2004 - + 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 the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -56,7 +56,7 @@ int gendb_search_v(struct ldb_context *ldb, if (ret == LDB_SUCCESS) { talloc_steal(mem_ctx, res->msgs); - DEBUG(6,("gendb_search_v: %s %s -> %d\n", + DEBUG(6,("gendb_search_v: %s %s -> %d\n", basedn?ldb_dn_get_linearized(basedn):"NULL", expr?expr:"NULL", res->count)); @@ -67,7 +67,8 @@ int gendb_search_v(struct ldb_context *ldb, ret = 0; *msgs = NULL; } else { - DEBUG(4,("gendb_search_v: search failed: %s", ldb_errstring(ldb))); + DEBUG(4,("gendb_search_v: search failed: %s\n", + ldb_errstring(ldb))); ret = -1; } @@ -80,7 +81,7 @@ int gendb_search_v(struct ldb_context *ldb, search the LDB for the specified attributes - varargs variant */ int gendb_search(struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, struct ldb_dn *basedn, struct ldb_message ***res, const char * const *attrs, @@ -101,7 +102,7 @@ int gendb_search(struct ldb_context *ldb, */ int gendb_search_dn(struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, struct ldb_dn *dn, struct ldb_message ***res, const char * const *attrs) -- cgit From 39a817d310964f8e9a63cfb096b3ad24fa03bd5e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 20 Feb 2008 04:33:43 +0100 Subject: Fix use of some modules (needed _PUBLIC_). (This used to be commit ce332130ea77159832da23bab760fa26921719e2) --- source4/lib/util/attr.h | 2 -- source4/lib/util/util.h | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/attr.h b/source4/lib/util/attr.h index 8f6c4f5d8a..f64b272a67 100644 --- a/source4/lib/util/attr.h +++ b/source4/lib/util/attr.h @@ -29,13 +29,11 @@ /** Feel free to add definitions for other compilers here. */ #endif -#ifndef _PUBLIC_ #ifdef HAVE_VISIBILITY_ATTR # define _PUBLIC_ __attribute__((visibility("default"))) #else # define _PUBLIC_ #endif -#endif #ifndef _DEPRECATED_ #if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 9e106052f2..550b60c625 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -21,6 +21,8 @@ #ifndef _SAMBA_UTIL_H_ #define _SAMBA_UTIL_H_ +#include "util/attr.h" + #include "charset/charset.h" /* for TALLOC_CTX */ @@ -36,7 +38,6 @@ struct smbsrv_tcon; extern const char *logfile; extern const char *panic_action; -#include "util/attr.h" #include "util/time.h" #include "util/data_blob.h" #include "util/xfile.h" -- cgit From ede79ae482b16c3cea65d3019bc1a68f07354e89 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 21 Feb 2008 15:38:35 +0100 Subject: Remove more uses of global_loadparm. (This used to be commit 58a5b1de2b093fe642eb11d76d12db0edf60c25c) --- source4/lib/util/ms_fnmatch.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/ms_fnmatch.c b/source4/lib/util/ms_fnmatch.c index 1fb57b07a4..5e04ec1f4b 100644 --- a/source4/lib/util/ms_fnmatch.c +++ b/source4/lib/util/ms_fnmatch.c @@ -64,8 +64,9 @@ static int ms_fnmatch_core(const char *p, const char *n, codepoint_t c, c2; int i; size_t size, size_n; + struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm); - while ((c = next_codepoint(lp_iconv_convenience(global_loadparm), p, &size))) { + while ((c = next_codepoint(iconv_convenience, p, &size))) { p += size; switch (c) { @@ -75,7 +76,7 @@ static int ms_fnmatch_core(const char *p, const char *n, return null_match(p); } for (i=0; n[i]; i += size_n) { - next_codepoint(lp_iconv_convenience(global_loadparm), n+i, &size_n); + next_codepoint(iconv_convenience, n+i, &size_n); if (ms_fnmatch_core(p, n+i, max_n+1, ldot) == 0) { return 0; } @@ -94,7 +95,7 @@ static int ms_fnmatch_core(const char *p, const char *n, return -1; } for (i=0; n[i]; i += size_n) { - next_codepoint(lp_iconv_convenience(global_loadparm), n+i, &size_n); + next_codepoint(iconv_convenience, n+i, &size_n); if (ms_fnmatch_core(p, n+i, max_n+1, ldot) == 0) return 0; if (n+i == ldot) { if (ms_fnmatch_core(p, n+i+size_n, max_n+1, ldot) == 0) return 0; @@ -110,7 +111,7 @@ static int ms_fnmatch_core(const char *p, const char *n, if (! *n) { return -1; } - next_codepoint(lp_iconv_convenience(global_loadparm), n, &size_n); + next_codepoint(iconv_convenience, n, &size_n); n += size_n; break; @@ -124,7 +125,7 @@ static int ms_fnmatch_core(const char *p, const char *n, break; } if (! *n) return null_match(p); - next_codepoint(lp_iconv_convenience(global_loadparm), n, &size_n); + next_codepoint(iconv_convenience, n, &size_n); n += size_n; break; @@ -134,12 +135,12 @@ static int ms_fnmatch_core(const char *p, const char *n, return 0; } if (*n != '.') return -1; - next_codepoint(lp_iconv_convenience(global_loadparm), n, &size_n); + next_codepoint(iconv_convenience, n, &size_n); n += size_n; break; default: - c2 = next_codepoint(lp_iconv_convenience(global_loadparm), n, &size_n); + c2 = next_codepoint(iconv_convenience, n, &size_n); if (c != c2 && codepoint_cmpi(c, c2) != 0) { return -1; } -- cgit From 1ada7108408f567f61cfbf2b625730ba898452db Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 29 Feb 2008 14:23:38 +0100 Subject: Move public header accumulation out of the perl code. Never install generated prototype files. It's easier to break the API when using them and they're not easily readable for 3rd party users. Conflicts: source/auth/config.mk source/auth/credentials/config.mk source/auth/gensec/config.mk source/build/smb_build/config_mk.pm source/build/smb_build/main.pl source/build/smb_build/makefile.pm source/dsdb/config.mk source/lib/charset/config.mk source/lib/tdr/config.mk source/lib/util/config.mk source/libcli/config.mk source/libcli/ldap/config.mk source/librpc/config.mk source/param/config.mk source/rpc_server/config.mk source/torture/config.mk (This used to be commit 6c659689ed4081f1d7a6253c538c7f01784197ba) --- source4/lib/util/config.mk | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index f3e6cd7acf..e0573400a5 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -1,15 +1,6 @@ [SUBSYSTEM::LIBSAMBA-UTIL] #VERSION = 0.0.1 #SO_VERSION = 0 -PUBLIC_HEADERS = util.h \ - attr.h \ - byteorder.h \ - data_blob.h \ - debug.h \ - mutex.h \ - safe_string.h \ - time.h \ - xfile.h OBJ_FILES = xfile.o \ debug.o \ fault.o \ @@ -33,11 +24,22 @@ PUBLIC_DEPENDENCIES = \ SOCKET_WRAPPER EXT_NSL \ CHARSET EXECINFO +PUBLIC_HEADERS += $(addprefix lib/util/, util.h \ + attr.h \ + byteorder.h \ + data_blob.h \ + debug.h \ + mutex.h \ + safe_string.h \ + time.h \ + xfile.h) + [SUBSYSTEM::ASN1_UTIL] -PUBLIC_PROTO_HEADER = asn1_proto.h -PUBLIC_HEADERS = asn1.h +PRIVATE_PROTO_HEADER = asn1_proto.h OBJ_FILES = asn1.o +PUBLIC_HEADERS += lib/util/asn1.h + [SUBSYSTEM::UNIX_PRIVS] PRIVATE_PROTO_HEADER = unix_privs.h OBJ_FILES = unix_privs.o -- cgit From 489f66cd422453c00afd14121fb61a41a6785249 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 29 Feb 2008 14:36:51 +0100 Subject: Change remaining prototype headers to be private. (This used to be commit 2f7ff409e89c9682e681ddcf54439db9e3b6ccb4) --- source4/lib/util/config.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index e0573400a5..16a0357df8 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -47,7 +47,7 @@ OBJ_FILES = unix_privs.o ################################################ # Start SUBSYSTEM WRAP_XATTR [SUBSYSTEM::WRAP_XATTR] -PUBLIC_PROTO_HEADER = wrap_xattr.h +PRIVATE_PROTO_HEADER = wrap_xattr.h OBJ_FILES = \ wrap_xattr.o PUBLIC_DEPENDENCIES = XATTR @@ -56,13 +56,13 @@ PUBLIC_DEPENDENCIES = XATTR ################################################ [SUBSYSTEM::UTIL_TDB] -PUBLIC_PROTO_HEADER = util_tdb.h +PRIVATE_PROTO_HEADER = util_tdb.h OBJ_FILES = \ util_tdb.o PUBLIC_DEPENDENCIES = LIBTDB [SUBSYSTEM::UTIL_LDB] -PUBLIC_PROTO_HEADER = util_ldb.h +PRIVATE_PROTO_HEADER = util_ldb.h OBJ_FILES = \ util_ldb.o PUBLIC_DEPENDENCIES = LIBLDB -- cgit From 52669d84722c175555e17a222077f845d9aa958f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 18 Mar 2008 18:03:18 +0100 Subject: lib/util: use LIBREPLACE_NETWORK as EXT_NSL doesn't exist anymore metze (This used to be commit b7dad8674a3aaa27bc1103a83be75434d413239b) --- source4/lib/util/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 16a0357df8..22e6617f7c 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -21,7 +21,7 @@ OBJ_FILES = xfile.o \ become_daemon.o PUBLIC_DEPENDENCIES = \ LIBTALLOC LIBCRYPTO \ - SOCKET_WRAPPER EXT_NSL \ + SOCKET_WRAPPER LIBREPLACE_NETWORK \ CHARSET EXECINFO PUBLIC_HEADERS += $(addprefix lib/util/, util.h \ -- cgit From 14a54761d98e2c4345e3e667d02279d2765617c1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 1 Apr 2008 14:51:06 +0200 Subject: Move ini-like file parser to the utility library. (This used to be commit 2dc2bb800dab3f7dbdba01f5ca5076edd1a2b0f3) --- source4/lib/util/config.mk | 3 ++- source4/lib/util/util.h | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 22e6617f7c..c6afad1e3f 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -18,7 +18,8 @@ OBJ_FILES = xfile.o \ ms_fnmatch.o \ mutex.o \ idtree.o \ - become_daemon.o + become_daemon.o \ + params.o PUBLIC_DEPENDENCIES = \ LIBTALLOC LIBCRYPTO \ SOCKET_WRAPPER LIBREPLACE_NETWORK \ diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 550b60c625..26700587ef 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -795,4 +795,12 @@ _PUBLIC_ int idr_remove(struct idr_context *idp, int id); **/ _PUBLIC_ void become_daemon(bool fork); +/** + * Load a ini-style file. + */ +bool pm_process( const char *fileName, + bool (*sfunc)(const char *, void *), + bool (*pfunc)(const char *, const char *, void *), + void *userdata); + #endif /* _SAMBA_UTIL_H_ */ -- cgit From 7fd96c5b04177a412d9ef12b2f4620b587fe8ed6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 1 Apr 2008 15:17:18 +0200 Subject: Add userdata argument to reseed callback function. (This used to be commit d4272bc6bcfcd71fa93edb25bb33d6458e8b33cd) --- source4/lib/util/genrand.c | 8 +++++--- source4/lib/util/tests/genrand.c | 4 ++-- source4/lib/util/util.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/genrand.c b/source4/lib/util/genrand.c index 5751db23d6..7df4ec4e20 100644 --- a/source4/lib/util/genrand.c +++ b/source4/lib/util/genrand.c @@ -37,15 +37,17 @@ static unsigned int bytes_since_reseed = 0; static int urand_fd = -1; -static void (*reseed_callback)(int *newseed); +static void (*reseed_callback)(void *userdata, int *newseed); +static void *reseed_callback_userdata = NULL; /** Copy any user given reseed data. **/ -_PUBLIC_ void set_rand_reseed_callback(void (*fn)(int *)) +_PUBLIC_ void set_rand_reseed_callback(void (*fn)(void *, int *), void *userdata) { reseed_callback = fn; + reseed_callback_userdata = userdata; set_need_random_reseed(); } @@ -61,7 +63,7 @@ _PUBLIC_ void set_need_random_reseed(void) static void get_rand_reseed_data(int *reseed_data) { if (reseed_callback) { - reseed_callback(reseed_data); + reseed_callback(reseed_callback_userdata, reseed_data); } else { *reseed_data = 0; } diff --git a/source4/lib/util/tests/genrand.c b/source4/lib/util/tests/genrand.c index 205a66352f..5fe229c089 100644 --- a/source4/lib/util/tests/genrand.c +++ b/source4/lib/util/tests/genrand.c @@ -22,14 +22,14 @@ #include "includes.h" #include "torture/torture.h" -static void dummy_reseed(int *d) +static void dummy_reseed(void *userdata, int *d) { *d = 42; } static bool test_reseed_callback(struct torture_context *tctx) { - set_rand_reseed_callback(dummy_reseed); + set_rand_reseed_callback(dummy_reseed, NULL); return true; } diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 26700587ef..60c8437634 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -218,7 +218,7 @@ _PUBLIC_ struct in_addr sys_inet_makeaddr(int net, int host); /** Copy any user given reseed data. **/ -_PUBLIC_ void set_rand_reseed_callback(void (*fn)(int *)); +_PUBLIC_ void set_rand_reseed_callback(void (*fn)(void *, int *), void *); /** * Tell the random number generator it needs to reseed. -- cgit From bebb7b890c754b05cbb5f4cf83da5b10478ff368 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 1 Apr 2008 16:18:31 +0200 Subject: Add warning to public headers. (This used to be commit 7bfe359c73aac96f8e983e8d5e9621235cf79a3a) --- source4/lib/util/data_blob.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/data_blob.h b/source4/lib/util/data_blob.h index 1442438dd7..e9dca67772 100644 --- a/source4/lib/util/data_blob.h +++ b/source4/lib/util/data_blob.h @@ -16,6 +16,10 @@ along with this program. If not, see . */ +/* This is a public header file that is installed as part of Samba. + * If you remove any functions or change their signature, update + * the so version number. */ + #ifndef _SAMBA_DATABLOB_H_ #define _SAMBA_DATABLOB_H_ -- cgit From afe3e8172ddaa5e4aa811faceecda4f943d6e2ef Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Apr 2008 04:53:27 +0200 Subject: Install public header files again and include required prototypes. (This used to be commit 47ffbbf67435904754469544390b67d34c958343) --- source4/lib/util/config.mk | 3 +-- source4/lib/util/dprintf.c | 6 +++--- source4/lib/util/util_file.c | 4 ++-- source4/lib/util/util_ldb.c | 4 ++-- source4/lib/util/util_ldb.h | 26 ++++++++++++++++++++++++++ source4/lib/util/wrap_xattr.h | 12 ++++++++++++ 6 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 source4/lib/util/util_ldb.h create mode 100644 source4/lib/util/wrap_xattr.h (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index c6afad1e3f..483e835e00 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -33,6 +33,7 @@ PUBLIC_HEADERS += $(addprefix lib/util/, util.h \ mutex.h \ safe_string.h \ time.h \ + util_ldb.h \ xfile.h) [SUBSYSTEM::ASN1_UTIL] @@ -48,7 +49,6 @@ OBJ_FILES = unix_privs.o ################################################ # Start SUBSYSTEM WRAP_XATTR [SUBSYSTEM::WRAP_XATTR] -PRIVATE_PROTO_HEADER = wrap_xattr.h OBJ_FILES = \ wrap_xattr.o PUBLIC_DEPENDENCIES = XATTR @@ -63,7 +63,6 @@ OBJ_FILES = \ PUBLIC_DEPENDENCIES = LIBTDB [SUBSYSTEM::UTIL_LDB] -PRIVATE_PROTO_HEADER = util_ldb.h OBJ_FILES = \ util_ldb.o PUBLIC_DEPENDENCIES = LIBLDB diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 308d81b105..e4f02758eb 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -42,7 +42,7 @@ void d_set_iconv(smb_iconv_t cd) display_cd = cd; } -_PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) +_PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) { char *p, *p2; int ret, clen; @@ -85,7 +85,7 @@ _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBU } -_PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) +_PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) { int ret; va_list ap; @@ -97,7 +97,7 @@ _PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) return ret; } -_PUBLIC_ int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) +_PUBLIC_ int d_printf(const char *format, ...) { int ret; va_list ap; diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index 836e188ac1..c3e22196c0 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -356,7 +356,7 @@ _PUBLIC_ bool file_save(const char *fname, const void *packet, size_t length) return true; } -_PUBLIC_ int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) +_PUBLIC_ int vfdprintf(int fd, const char *format, va_list ap) { char *p; int len, ret; @@ -371,7 +371,7 @@ _PUBLIC_ int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE return ret; } -_PUBLIC_ int fdprintf(int fd, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) +_PUBLIC_ int fdprintf(int fd, const char *format, ...) { va_list ap; int ret; diff --git a/source4/lib/util/util_ldb.c b/source4/lib/util/util_ldb.c index f1b42effd8..38f53c2c66 100644 --- a/source4/lib/util/util_ldb.c +++ b/source4/lib/util/util_ldb.c @@ -33,7 +33,7 @@ int gendb_search_v(struct ldb_context *ldb, struct ldb_message ***msgs, const char * const *attrs, const char *format, - va_list ap) _PRINTF_ATTRIBUTE(6,0) + va_list ap) { enum ldb_scope scope = LDB_SCOPE_SUBTREE; struct ldb_result *res; @@ -85,7 +85,7 @@ int gendb_search(struct ldb_context *ldb, struct ldb_dn *basedn, struct ldb_message ***res, const char * const *attrs, - const char *format, ...) _PRINTF_ATTRIBUTE(6,7) + const char *format, ...) { va_list ap; int count; diff --git a/source4/lib/util/util_ldb.h b/source4/lib/util/util_ldb.h new file mode 100644 index 0000000000..864ce7e8c6 --- /dev/null +++ b/source4/lib/util/util_ldb.h @@ -0,0 +1,26 @@ +#ifndef __LIB_UTIL_UTIL_LDB_H__ +#define __LIB_UTIL_UTIL_LDB_H__ + +int gendb_search_v(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + struct ldb_message ***msgs, + const char * const *attrs, + const char *format, + va_list ap) _PRINTF_ATTRIBUTE(6,0); +int gendb_search(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + struct ldb_message ***res, + const char * const *attrs, + const char *format, ...) _PRINTF_ATTRIBUTE(6,7); +int gendb_search_dn(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *dn, + struct ldb_message ***res, + const char * const *attrs); +int gendb_add_ldif(struct ldb_context *ldb, const char *ldif_string); +char *wrap_casefold(void *context, void *mem_ctx, const char *s); + +#endif /* __LIB_UTIL_UTIL_LDB_H__ */ + diff --git a/source4/lib/util/wrap_xattr.h b/source4/lib/util/wrap_xattr.h new file mode 100644 index 0000000000..64b28d250c --- /dev/null +++ b/source4/lib/util/wrap_xattr.h @@ -0,0 +1,12 @@ +#ifndef __LIB_UTIL_WRAP_XATTR_H__ +#define __LIB_UTIL_WRAP_XATTR_H__ + +ssize_t wrap_fgetxattr(int fd, const char *name, void *value, size_t size); +ssize_t wrap_getxattr(const char *path, const char *name, void *value, size_t size); +int wrap_fsetxattr(int fd, const char *name, void *value, size_t size, int flags); +int wrap_setxattr(const char *path, const char *name, void *value, size_t size, int flags); +int wrap_fremovexattr(int fd, const char *name); +int wrap_removexattr(const char *path, const char *name); + +#endif /* __LIB_UTIL_WRAP_XATTR_H__ */ + -- cgit From 236fc02913adafd80921d4e30aa6ee1e414bef44 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Apr 2008 13:41:10 +0200 Subject: Reduce the number of installed headers. (This used to be commit 2243e24024f09ff9c9c7d0eb735c3b39c9d84424) --- source4/lib/util/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 483e835e00..0bf0692193 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -40,7 +40,7 @@ PUBLIC_HEADERS += $(addprefix lib/util/, util.h \ PRIVATE_PROTO_HEADER = asn1_proto.h OBJ_FILES = asn1.o -PUBLIC_HEADERS += lib/util/asn1.h +# PUBLIC_HEADERS += lib/util/asn1.h [SUBSYSTEM::UNIX_PRIVS] PRIVATE_PROTO_HEADER = unix_privs.h -- cgit From 4e5e7a7c688d8a065994cb16fb1da7581bab081a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Apr 2008 16:47:17 +0200 Subject: Reintroduce header previously autogenerated but ignored by git. Also fixed extra include in regpatch. (This used to be commit 0e371cf169e9a607fcbb3e65437ab9413935dd52) --- source4/lib/util/util_ldb.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_ldb.h b/source4/lib/util/util_ldb.h index 864ce7e8c6..030ba7ebee 100644 --- a/source4/lib/util/util_ldb.h +++ b/source4/lib/util/util_ldb.h @@ -1,19 +1,21 @@ #ifndef __LIB_UTIL_UTIL_LDB_H__ #define __LIB_UTIL_UTIL_LDB_H__ +/* The following definitions come from lib/util/util_ldb.c */ + int gendb_search_v(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_dn *basedn, struct ldb_message ***msgs, const char * const *attrs, const char *format, - va_list ap) _PRINTF_ATTRIBUTE(6,0); + va_list ap) PRINTF_ATTRIBUTE(6,0); int gendb_search(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_dn *basedn, struct ldb_message ***res, const char * const *attrs, - const char *format, ...) _PRINTF_ATTRIBUTE(6,7); + const char *format, ...) PRINTF_ATTRIBUTE(6,7); int gendb_search_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_dn *dn, @@ -23,4 +25,3 @@ int gendb_add_ldif(struct ldb_context *ldb, const char *ldif_string); char *wrap_casefold(void *context, void *mem_ctx, const char *s); #endif /* __LIB_UTIL_UTIL_LDB_H__ */ - -- cgit From 753824e9cfcbba51a2157eb75cc9ff9b287028fa Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Apr 2008 19:05:31 +0200 Subject: Re-add params file to git. (This used to be commit fc50e78e2631e8253571bc236302e2859e4d1559) --- source4/lib/util/params.c | 587 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 587 insertions(+) create mode 100644 source4/lib/util/params.c (limited to 'source4/lib/util') diff --git a/source4/lib/util/params.c b/source4/lib/util/params.c new file mode 100644 index 0000000000..3a9e2b9505 --- /dev/null +++ b/source4/lib/util/params.c @@ -0,0 +1,587 @@ +/* -------------------------------------------------------------------------- ** + * Microsoft Network Services for Unix, AKA., Andrew Tridgell's SAMBA. + * + * This module Copyright (C) 1990-1998 Karl Auer + * + * Rewritten almost completely by Christopher R. Hertel + * at the University of Minnesota, September, 1997. + * This module Copyright (C) 1997-1998 by the University of Minnesota + * -------------------------------------------------------------------------- ** + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + * -------------------------------------------------------------------------- ** + * + * Module name: params + * + * -------------------------------------------------------------------------- ** + * + * This module performs lexical analysis and initial parsing of a + * Windows-like parameter file. It recognizes and handles four token + * types: section-name, parameter-name, parameter-value, and + * end-of-file. Comments and line continuation are handled + * internally. + * + * The entry point to the module is function pm_process(). This + * function opens the source file, calls the Parse() function to parse + * the input, and then closes the file when either the EOF is reached + * or a fatal error is encountered. + * + * A sample parameter file might look like this: + * + * [section one] + * parameter one = value string + * parameter two = another value + * [section two] + * new parameter = some value or t'other + * + * The parameter file is divided into sections by section headers: + * section names enclosed in square brackets (eg. [section one]). + * Each section contains parameter lines, each of which consist of a + * parameter name and value delimited by an equal sign. Roughly, the + * syntax is: + * + * :== {
} EOF + * + *
:==
{ } + * + *
:== '[' NAME ']' + * + * :== NAME '=' VALUE '\n' + * + * Blank lines and comment lines are ignored. Comment lines are lines + * beginning with either a semicolon (';') or a pound sign ('#'). + * + * All whitespace in section names and parameter names is compressed + * to single spaces. Leading and trailing whitespace is stipped from + * both names and values. + * + * Only the first equals sign in a parameter line is significant. + * Parameter values may contain equals signs, square brackets and + * semicolons. Internal whitespace is retained in parameter values, + * with the exception of the '\r' character, which is stripped for + * historic reasons. Parameter names may not start with a left square + * bracket, an equal sign, a pound sign, or a semicolon, because these + * are used to identify other tokens. + * + * -------------------------------------------------------------------------- ** + */ + +#include "includes.h" +#include "system/locale.h" + +/* -------------------------------------------------------------------------- ** + * Constants... + */ + +#define BUFR_INC 1024 + + +/* we can't use FILE* due to the 256 fd limit - use this cheap hack + instead */ +typedef struct { + char *buf; + char *p; + size_t size; + char *bufr; + int bSize; +} myFILE; + +static int mygetc(myFILE *f) +{ + if (f->p >= f->buf+f->size) return EOF; + /* be sure to return chars >127 as positive values */ + return (int)( *(f->p++) & 0x00FF ); +} + +static void myfile_close(myFILE *f) +{ + talloc_free(f); +} + +/* -------------------------------------------------------------------------- ** + * Functions... + */ + +static int EatWhitespace( myFILE *InFile ) + /* ------------------------------------------------------------------------ ** + * Scan past whitespace (see ctype(3C)) and return the first non-whitespace + * character, or newline, or EOF. + * + * Input: InFile - Input source. + * + * Output: The next non-whitespace character in the input stream. + * + * Notes: Because the config files use a line-oriented grammar, we + * explicitly exclude the newline character from the list of + * whitespace characters. + * - Note that both EOF (-1) and the nul character ('\0') are + * considered end-of-file markers. + * + * ------------------------------------------------------------------------ ** + */ + { + int c; + + for( c = mygetc( InFile ); isspace( c ) && ('\n' != c); c = mygetc( InFile ) ) + ; + return( c ); + } /* EatWhitespace */ + +static int EatComment( myFILE *InFile ) + /* ------------------------------------------------------------------------ ** + * Scan to the end of a comment. + * + * Input: InFile - Input source. + * + * Output: The character that marks the end of the comment. Normally, + * this will be a newline, but it *might* be an EOF. + * + * Notes: Because the config files use a line-oriented grammar, we + * explicitly exclude the newline character from the list of + * whitespace characters. + * - Note that both EOF (-1) and the nul character ('\0') are + * considered end-of-file markers. + * + * ------------------------------------------------------------------------ ** + */ + { + int c; + + for( c = mygetc( InFile ); ('\n'!=c) && (EOF!=c) && (c>0); c = mygetc( InFile ) ) + ; + return( c ); + } /* EatComment */ + +/***************************************************************************** + * Scan backards within a string to discover if the last non-whitespace + * character is a line-continuation character ('\\'). + * + * Input: line - A pointer to a buffer containing the string to be + * scanned. + * pos - This is taken to be the offset of the end of the + * string. This position is *not* scanned. + * + * Output: The offset of the '\\' character if it was found, or -1 to + * indicate that it was not. + * + *****************************************************************************/ + +static int Continuation(char *line, int pos ) +{ + pos--; + while( (pos >= 0) && isspace((int)line[pos])) + pos--; + + return (((pos >= 0) && ('\\' == line[pos])) ? pos : -1 ); +} + + +static bool Section( myFILE *InFile, bool (*sfunc)(const char *, void *), void *userdata ) + /* ------------------------------------------------------------------------ ** + * Scan a section name, and pass the name to function sfunc(). + * + * Input: InFile - Input source. + * sfunc - Pointer to the function to be called if the section + * name is successfully read. + * + * Output: true if the section name was read and true was returned from + * . false if failed or if a lexical error was + * encountered. + * + * ------------------------------------------------------------------------ ** + */ + { + int c; + int i; + int end; + const char *func = "params.c:Section() -"; + + i = 0; /* is the offset of the next free byte in bufr[] and */ + end = 0; /* is the current "end of string" offset. In most */ + /* cases these will be the same, but if the last */ + /* character written to bufr[] is a space, then */ + /* will be one less than . */ + + c = EatWhitespace( InFile ); /* We've already got the '['. Scan */ + /* past initial white space. */ + + while( (EOF != c) && (c > 0) ) + { + + /* Check that the buffer is big enough for the next character. */ + if( i > (InFile->bSize - 2) ) + { + char *tb; + + tb = talloc_realloc(InFile, InFile->bufr, char, InFile->bSize + BUFR_INC); + if( NULL == tb ) + { + DEBUG(0, ("%s Memory re-allocation failure.", func) ); + return( false ); + } + InFile->bufr = tb; + InFile->bSize += BUFR_INC; + } + + /* Handle a single character. */ + switch( c ) + { + case ']': /* Found the closing bracket. */ + InFile->bufr[end] = '\0'; + if( 0 == end ) /* Don't allow an empty name. */ + { + DEBUG(0, ("%s Empty section name in configuration file.\n", func )); + return( false ); + } + if( !sfunc(InFile->bufr,userdata) ) /* Got a valid name. Deal with it. */ + return( false ); + (void)EatComment( InFile ); /* Finish off the line. */ + return( true ); + + case '\n': /* Got newline before closing ']'. */ + i = Continuation( InFile->bufr, i ); /* Check for line continuation. */ + if( i < 0 ) + { + InFile->bufr[end] = '\0'; + DEBUG(0, ("%s Badly formed line in configuration file: %s\n", + func, InFile->bufr )); + return( false ); + } + end = ( (i > 0) && (' ' == InFile->bufr[i - 1]) ) ? (i - 1) : (i); + c = mygetc( InFile ); /* Continue with next line. */ + break; + + default: /* All else are a valid name chars. */ + if( isspace( c ) ) /* One space per whitespace region. */ + { + InFile->bufr[end] = ' '; + i = end + 1; + c = EatWhitespace( InFile ); + } + else /* All others copy verbatim. */ + { + InFile->bufr[i++] = c; + end = i; + c = mygetc( InFile ); + } + } + } + + /* We arrive here if we've met the EOF before the closing bracket. */ + DEBUG(0, ("%s Unexpected EOF in the configuration file\n", func)); + return( false ); + } /* Section */ + +static bool Parameter( myFILE *InFile, bool (*pfunc)(const char *, const char *, void *), int c, void *userdata ) + /* ------------------------------------------------------------------------ ** + * Scan a parameter name and value, and pass these two fields to pfunc(). + * + * Input: InFile - The input source. + * pfunc - A pointer to the function that will be called to + * process the parameter, once it has been scanned. + * c - The first character of the parameter name, which + * would have been read by Parse(). Unlike a comment + * line or a section header, there is no lead-in + * character that can be discarded. + * + * Output: true if the parameter name and value were scanned and processed + * successfully, else false. + * + * Notes: This function is in two parts. The first loop scans the + * parameter name. Internal whitespace is compressed, and an + * equal sign (=) terminates the token. Leading and trailing + * whitespace is discarded. The second loop scans the parameter + * value. When both have been successfully identified, they are + * passed to pfunc() for processing. + * + * ------------------------------------------------------------------------ ** + */ + { + int i = 0; /* Position within bufr. */ + int end = 0; /* bufr[end] is current end-of-string. */ + int vstart = 0; /* Starting position of the parameter value. */ + const char *func = "params.c:Parameter() -"; + + /* Read the parameter name. */ + while( 0 == vstart ) /* Loop until we've found the start of the value. */ + { + + if( i > (InFile->bSize - 2) ) /* Ensure there's space for next char. */ + { + char *tb; + + tb = talloc_realloc(InFile, InFile->bufr, char, InFile->bSize + BUFR_INC ); + if( NULL == tb ) + { + DEBUG(0, ("%s Memory re-allocation failure.", func) ); + return( false ); + } + InFile->bufr = tb; + InFile->bSize += BUFR_INC; + } + + switch( c ) + { + case '=': /* Equal sign marks end of param name. */ + if( 0 == end ) /* Don't allow an empty name. */ + { + DEBUG(0, ("%s Invalid parameter name in config. file.\n", func )); + return( false ); + } + InFile->bufr[end++] = '\0'; /* Mark end of string & advance. */ + i = end; /* New string starts here. */ + vstart = end; /* New string is parameter value. */ + InFile->bufr[i] = '\0'; /* New string is nul, for now. */ + break; + + case '\n': /* Find continuation char, else error. */ + i = Continuation( InFile->bufr, i ); + if( i < 0 ) + { + InFile->bufr[end] = '\0'; + DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n", + func, InFile->bufr )); + return( true ); + } + end = ( (i > 0) && (' ' == InFile->bufr[i - 1]) ) ? (i - 1) : (i); + c = mygetc( InFile ); /* Read past eoln. */ + break; + + case '\0': /* Shouldn't have EOF within param name. */ + case EOF: + InFile->bufr[i] = '\0'; + DEBUG(1,("%s Unexpected end-of-file at: %s\n", func, InFile->bufr )); + return( true ); + + default: + if( isspace( c ) ) /* One ' ' per whitespace region. */ + { + InFile->bufr[end] = ' '; + i = end + 1; + c = EatWhitespace( InFile ); + } + else /* All others verbatim. */ + { + InFile->bufr[i++] = c; + end = i; + c = mygetc( InFile ); + } + } + } + + /* Now parse the value. */ + c = EatWhitespace( InFile ); /* Again, trim leading whitespace. */ + while( (EOF !=c) && (c > 0) ) + { + + if( i > (InFile->bSize - 2) ) /* Make sure there's enough room. */ + { + char *tb; + + tb = talloc_realloc(InFile, InFile->bufr, char, InFile->bSize + BUFR_INC ); + if( NULL == tb ) + { + DEBUG(0, ("%s Memory re-allocation failure.", func) ); + return( false ); + } + InFile->bufr = tb; + InFile->bSize += BUFR_INC; + } + + switch( c ) + { + case '\r': /* Explicitly remove '\r' because the older */ + c = mygetc( InFile ); /* version called fgets_slash() which also */ + break; /* removes them. */ + + case '\n': /* Marks end of value unless there's a '\'. */ + i = Continuation( InFile->bufr, i ); + if( i < 0 ) + c = 0; + else + { + for( end = i; (end >= 0) && isspace((int)InFile->bufr[end]); end-- ) + ; + c = mygetc( InFile ); + } + break; + + default: /* All others verbatim. Note that spaces do */ + InFile->bufr[i++] = c; /* not advance . This allows trimming */ + if( !isspace( c ) ) /* of whitespace at the end of the line. */ + end = i; + c = mygetc( InFile ); + break; + } + } + InFile->bufr[end] = '\0'; /* End of value. */ + + return( pfunc( InFile->bufr, &InFile->bufr[vstart], userdata ) ); /* Pass name & value to pfunc(). */ + } /* Parameter */ + +static bool Parse( myFILE *InFile, + bool (*sfunc)(const char *, void *), + bool (*pfunc)(const char *, const char *, void *), + void *userdata ) + /* ------------------------------------------------------------------------ ** + * Scan & parse the input. + * + * Input: InFile - Input source. + * sfunc - Function to be called when a section name is scanned. + * See Section(). + * pfunc - Function to be called when a parameter is scanned. + * See Parameter(). + * + * Output: true if the file was successfully scanned, else false. + * + * Notes: The input can be viewed in terms of 'lines'. There are four + * types of lines: + * Blank - May contain whitespace, otherwise empty. + * Comment - First non-whitespace character is a ';' or '#'. + * The remainder of the line is ignored. + * Section - First non-whitespace character is a '['. + * Parameter - The default case. + * + * ------------------------------------------------------------------------ ** + */ + { + int c; + + c = EatWhitespace( InFile ); + while( (EOF != c) && (c > 0) ) + { + switch( c ) + { + case '\n': /* Blank line. */ + c = EatWhitespace( InFile ); + break; + + case ';': /* Comment line. */ + case '#': + c = EatComment( InFile ); + break; + + case '[': /* Section Header. */ + if( !Section( InFile, sfunc, userdata ) ) + return( false ); + c = EatWhitespace( InFile ); + break; + + case '\\': /* Bogus backslash. */ + c = EatWhitespace( InFile ); + break; + + default: /* Parameter line. */ + if( !Parameter( InFile, pfunc, c, userdata ) ) + return( false ); + c = EatWhitespace( InFile ); + break; + } + } + return( true ); + } /* Parse */ + +static myFILE *OpenConfFile( const char *FileName ) + /* ------------------------------------------------------------------------ ** + * Open a configuration file. + * + * Input: FileName - The pathname of the config file to be opened. + * + * Output: A pointer of type (char **) to the lines of the file + * + * ------------------------------------------------------------------------ ** + */ + { + const char *func = "params.c:OpenConfFile() -"; + myFILE *ret; + + ret = talloc(talloc_autofree_context(), myFILE); + if (!ret) return NULL; + + ret->buf = file_load(FileName, &ret->size, ret); + if( NULL == ret->buf ) + { + DEBUG( 1, + ("%s Unable to open configuration file \"%s\":\n\t%s\n", + func, FileName, strerror(errno)) ); + talloc_free(ret); + return NULL; + } + + ret->p = ret->buf; + ret->bufr = NULL; + ret->bSize = 0; + return( ret ); + } /* OpenConfFile */ + +bool pm_process( const char *FileName, + bool (*sfunc)(const char *, void *), + bool (*pfunc)(const char *, const char *, void *), + void *userdata) + /* ------------------------------------------------------------------------ ** + * Process the named parameter file. + * + * Input: FileName - The pathname of the parameter file to be opened. + * sfunc - A pointer to a function that will be called when + * a section name is discovered. + * pfunc - A pointer to a function that will be called when + * a parameter name and value are discovered. + * + * Output: TRUE if the file was successfully parsed, else FALSE. + * + * ------------------------------------------------------------------------ ** + */ + { + int result; + myFILE *InFile; + const char *func = "params.c:pm_process() -"; + + InFile = OpenConfFile( FileName ); /* Open the config file. */ + if( NULL == InFile ) + return( false ); + + DEBUG( 3, ("%s Processing configuration file \"%s\"\n", func, FileName) ); + + if( NULL != InFile->bufr ) /* If we already have a buffer */ + result = Parse( InFile, sfunc, pfunc, userdata ); /* (recursive call), then just */ + /* use it. */ + + else /* If we don't have a buffer */ + { /* allocate one, then parse, */ + InFile->bSize = BUFR_INC; /* then free. */ + InFile->bufr = talloc_array(InFile, char, InFile->bSize ); + if( NULL == InFile->bufr ) + { + DEBUG(0,("%s memory allocation failure.\n", func)); + myfile_close(InFile); + return( false ); + } + result = Parse( InFile, sfunc, pfunc, userdata ); + InFile->bufr = NULL; + InFile->bSize = 0; + } + + myfile_close(InFile); + + if( !result ) /* Generic failure. */ + { + DEBUG(0,("%s Failed. Error returned from params.c:parse().\n", func)); + return( false ); + } + + return( true ); /* Generic success. */ + } /* pm_process */ + +/* -------------------------------------------------------------------------- */ -- cgit From 2d12b275f38fe2785c9ae389cc987269a232b5a8 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Fri, 21 Mar 2008 22:27:02 +0100 Subject: util: Add talloc_get_type_abort() call. (This used to be commit 38413ed4b6957e5f72e78a04f479c6a5d8b69ef5) --- source4/lib/util/util.c | 15 +++++++++++++++ source4/lib/util/util.h | 7 +++++++ 2 files changed, 22 insertions(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index 7b6bfeeb7b..b5bb75358e 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -582,3 +582,18 @@ _PUBLIC_ void *realloc_array(void *ptr, size_t el_size, unsigned count) return realloc(ptr, el_size * count); } +_PUBLIC_ 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; +} + diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 60c8437634..3bf6b98d2f 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -803,4 +803,11 @@ bool pm_process( const char *fileName, bool (*pfunc)(const char *, const char *, void *), void *userdata); +/** + * Add-on to talloc_get_type + */ +_PUBLIC_ void *talloc_check_name_abort(const void *ptr, const char *name); +#define talloc_get_type_abort(ptr, type) \ + (type *)talloc_check_name_abort(ptr, #type) + #endif /* _SAMBA_UTIL_H_ */ -- cgit From 148d3b170ae00d4001fa011450c7238052d32ae2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Apr 2008 22:00:36 +0200 Subject: Use torture_assert_mem_equal() in a couple more places. (This used to be commit e2c3fab9d1bf0482c15a115e7d373562ffe50b29) --- source4/lib/util/tests/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/tests/file.c b/source4/lib/util/tests/file.c index fe87293671..3377e833dc 100644 --- a/source4/lib/util/tests/file.c +++ b/source4/lib/util/tests/file.c @@ -45,9 +45,9 @@ static bool test_file_load_save(struct torture_context *tctx) data = file_load(TEST_FILENAME, &len, mem_ctx); torture_assert(tctx, data, "loading file"); - torture_assert(tctx, len == strlen(TEST_DATA), "Length"); + torture_assert_int_equal(tctx, len, strlen(TEST_DATA), "Length"); - torture_assert(tctx, memcmp(data, TEST_DATA, len) == 0, "Contents"); + torture_assert_mem_equal(tctx, data, TEST_DATA, len, "Contents"); unlink(TEST_FILENAME); return true; -- cgit From e9017ba418202b4b191c5a9ad4a96857558ce606 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Apr 2008 17:22:58 +0200 Subject: Use _OBJ_FILES variables in a couple more places. (This used to be commit 92856d5054106894b65cd1a1b5119c0facfc4cff) --- source4/lib/util/config.mk | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 0bf0692193..fff489d62c 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -1,7 +1,13 @@ [SUBSYSTEM::LIBSAMBA-UTIL] #VERSION = 0.0.1 #SO_VERSION = 0 -OBJ_FILES = xfile.o \ +PUBLIC_DEPENDENCIES = \ + LIBTALLOC LIBCRYPTO \ + SOCKET_WRAPPER LIBREPLACE_NETWORK \ + CHARSET EXECINFO + +LIBSAMBA-UTIL_OBJ_FILES = $(addprefix lib/util/, \ + xfile.o \ debug.o \ fault.o \ signal.o \ @@ -19,11 +25,7 @@ OBJ_FILES = xfile.o \ mutex.o \ idtree.o \ become_daemon.o \ - params.o -PUBLIC_DEPENDENCIES = \ - LIBTALLOC LIBCRYPTO \ - SOCKET_WRAPPER LIBREPLACE_NETWORK \ - CHARSET EXECINFO + params.o) PUBLIC_HEADERS += $(addprefix lib/util/, util.h \ attr.h \ @@ -38,31 +40,31 @@ PUBLIC_HEADERS += $(addprefix lib/util/, util.h \ [SUBSYSTEM::ASN1_UTIL] PRIVATE_PROTO_HEADER = asn1_proto.h -OBJ_FILES = asn1.o -# PUBLIC_HEADERS += lib/util/asn1.h +ASN1_UTIL_OBJ_FILES = lib/util/asn1.o [SUBSYSTEM::UNIX_PRIVS] PRIVATE_PROTO_HEADER = unix_privs.h -OBJ_FILES = unix_privs.o + +UNIX_PRIVS_OBJ_FILES = lib/util/unix_privs.o ################################################ # Start SUBSYSTEM WRAP_XATTR [SUBSYSTEM::WRAP_XATTR] -OBJ_FILES = \ - wrap_xattr.o PUBLIC_DEPENDENCIES = XATTR # # End SUBSYSTEM WRAP_XATTR ################################################ +WRAP_XATTR_OBJ_FILES = lib/util/wrap_xattr.o + [SUBSYSTEM::UTIL_TDB] PRIVATE_PROTO_HEADER = util_tdb.h -OBJ_FILES = \ - util_tdb.o PUBLIC_DEPENDENCIES = LIBTDB +UTIL_TDB_OBJ_FILES = lib/util/util_tdb.o + [SUBSYSTEM::UTIL_LDB] -OBJ_FILES = \ - util_ldb.o PUBLIC_DEPENDENCIES = LIBLDB + +UTIL_LDB_OBJ_FILES = lib/util/util_ldb.o -- cgit From 08baea013b73607df0c86f24506912c7e6af6f7e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 15 Apr 2008 02:25:16 +0200 Subject: Move SOVERSION, VERSION and PC_FILE out of smb_build but use make variables directly instead. (This used to be commit 9d0ae012b0b463278cd054d06788aa998acc2da2) --- source4/lib/util/config.mk | 2 -- 1 file changed, 2 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index fff489d62c..5a4b831ed5 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -1,6 +1,4 @@ [SUBSYSTEM::LIBSAMBA-UTIL] -#VERSION = 0.0.1 -#SO_VERSION = 0 PUBLIC_DEPENDENCIES = \ LIBTALLOC LIBCRYPTO \ SOCKET_WRAPPER LIBREPLACE_NETWORK \ -- cgit From 107ab090e23dfc517bc74bb553315cd3528e1f7d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 17 Apr 2008 14:47:07 +0200 Subject: use uintptr_t instead of intptr_t where appropriate (This used to be commit d62f2bcc85c13605c133db250e0a86d2d6ccc481) --- source4/lib/util/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 3bf6b98d2f..ffe83c14b2 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -64,7 +64,7 @@ extern const char *panic_action; makes the return type safe. */ #ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) +#define discard_const(ptr) ((void *)((uintptr_t)(ptr))) #endif /** Type-safe version of discard_const */ -- cgit From 1e973565b6c0cb738b25a2d9439d5acb441701f4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 27 Apr 2008 14:02:46 +0100 Subject: Move subunit infrastructure code into lib/torture. (This used to be commit 5b44d8121de7735d69e6238a1442aff034a8ebd3) --- source4/lib/util/tests/str.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/tests/str.c b/source4/lib/util/tests/str.c index a219ef0891..3bd6a02fdc 100644 --- a/source4/lib/util/tests/str.c +++ b/source4/lib/util/tests/str.c @@ -20,7 +20,7 @@ */ #include "includes.h" -#include "torture/ui.h" +#include "torture/torture.h" static bool test_string_sub_simple(struct torture_context *tctx) { -- cgit From 333c169529a3f64a28fcaff1056069867fd56a90 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 18 May 2008 20:30:46 +0200 Subject: Use variables for source directory in remaining subsystems. (This used to be commit 6b6b2196a8a8d9e741f5c399185ded7a16938da0) --- source4/lib/util/config.mk | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 5a4b831ed5..2c8d7e5f4d 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -4,7 +4,7 @@ PUBLIC_DEPENDENCIES = \ SOCKET_WRAPPER LIBREPLACE_NETWORK \ CHARSET EXECINFO -LIBSAMBA-UTIL_OBJ_FILES = $(addprefix lib/util/, \ +LIBSAMBA-UTIL_OBJ_FILES = $(addprefix $(libutilsrcdir)/, \ xfile.o \ debug.o \ fault.o \ @@ -25,7 +25,7 @@ LIBSAMBA-UTIL_OBJ_FILES = $(addprefix lib/util/, \ become_daemon.o \ params.o) -PUBLIC_HEADERS += $(addprefix lib/util/, util.h \ +PUBLIC_HEADERS += $(addprefix $(libutilsrcdir)/, util.h \ attr.h \ byteorder.h \ data_blob.h \ @@ -39,12 +39,12 @@ PUBLIC_HEADERS += $(addprefix lib/util/, util.h \ [SUBSYSTEM::ASN1_UTIL] PRIVATE_PROTO_HEADER = asn1_proto.h -ASN1_UTIL_OBJ_FILES = lib/util/asn1.o +ASN1_UTIL_OBJ_FILES = $(libutilsrcdir)/asn1.o [SUBSYSTEM::UNIX_PRIVS] PRIVATE_PROTO_HEADER = unix_privs.h -UNIX_PRIVS_OBJ_FILES = lib/util/unix_privs.o +UNIX_PRIVS_OBJ_FILES = $(libutilsrcdir)/unix_privs.o ################################################ # Start SUBSYSTEM WRAP_XATTR @@ -54,15 +54,15 @@ PUBLIC_DEPENDENCIES = XATTR # End SUBSYSTEM WRAP_XATTR ################################################ -WRAP_XATTR_OBJ_FILES = lib/util/wrap_xattr.o +WRAP_XATTR_OBJ_FILES = $(libutilsrcdir)/wrap_xattr.o [SUBSYSTEM::UTIL_TDB] PRIVATE_PROTO_HEADER = util_tdb.h PUBLIC_DEPENDENCIES = LIBTDB -UTIL_TDB_OBJ_FILES = lib/util/util_tdb.o +UTIL_TDB_OBJ_FILES = $(libutilsrcdir)/util_tdb.o [SUBSYSTEM::UTIL_LDB] PUBLIC_DEPENDENCIES = LIBLDB -UTIL_LDB_OBJ_FILES = lib/util/util_ldb.o +UTIL_LDB_OBJ_FILES = $(libutilsrcdir)/util_ldb.o -- cgit From 4c8756f147f8b9a2806fd76e4cb06bb99d391516 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 18 May 2008 22:30:08 +0200 Subject: Create prototype headers from Makefile directory, without smb_build in the middle. (This used to be commit f4a77b96f9c17d853348b70794026e5b9e384942) --- source4/lib/util/config.mk | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 2c8d7e5f4d..e365082178 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -37,15 +37,17 @@ PUBLIC_HEADERS += $(addprefix $(libutilsrcdir)/, util.h \ xfile.h) [SUBSYSTEM::ASN1_UTIL] -PRIVATE_PROTO_HEADER = asn1_proto.h ASN1_UTIL_OBJ_FILES = $(libutilsrcdir)/asn1.o +$(call proto_header_template,$(libutilsrcdir)/asn1_proto.h,$(ASN1_UTIL_OBJ_FILES:.o=.c)) + [SUBSYSTEM::UNIX_PRIVS] -PRIVATE_PROTO_HEADER = unix_privs.h UNIX_PRIVS_OBJ_FILES = $(libutilsrcdir)/unix_privs.o +$(call proto_header_template,$(libutilsrcdir)/unix_privs.h,$(UNIX_PRIVS_OBJ_FILES:.o=.c)) + ################################################ # Start SUBSYSTEM WRAP_XATTR [SUBSYSTEM::WRAP_XATTR] @@ -57,11 +59,12 @@ PUBLIC_DEPENDENCIES = XATTR WRAP_XATTR_OBJ_FILES = $(libutilsrcdir)/wrap_xattr.o [SUBSYSTEM::UTIL_TDB] -PRIVATE_PROTO_HEADER = util_tdb.h PUBLIC_DEPENDENCIES = LIBTDB UTIL_TDB_OBJ_FILES = $(libutilsrcdir)/util_tdb.o +$(call proto_header_template,$(libutilsrcdir)/util_tdb.h,$(UTIL_TDB_OBJ_FILES)) + [SUBSYSTEM::UTIL_LDB] PUBLIC_DEPENDENCIES = LIBLDB -- cgit From 4c70cda986c86fe536327321d04c29eca81b6409 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 18 May 2008 23:02:47 +0200 Subject: Fix a couple (well, little more than that..) of typos. (This used to be commit a6b52119940a900fb0de3864b8bca94e2965cc24) --- source4/lib/util/config.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index e365082178..e9b8b38614 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -40,13 +40,13 @@ PUBLIC_HEADERS += $(addprefix $(libutilsrcdir)/, util.h \ ASN1_UTIL_OBJ_FILES = $(libutilsrcdir)/asn1.o -$(call proto_header_template,$(libutilsrcdir)/asn1_proto.h,$(ASN1_UTIL_OBJ_FILES:.o=.c)) +$(eval $(call proto_header_template,$(libutilsrcdir)/asn1_proto.h,$(ASN1_UTIL_OBJ_FILES:.o=.c))) [SUBSYSTEM::UNIX_PRIVS] UNIX_PRIVS_OBJ_FILES = $(libutilsrcdir)/unix_privs.o -$(call proto_header_template,$(libutilsrcdir)/unix_privs.h,$(UNIX_PRIVS_OBJ_FILES:.o=.c)) +$(eval $(call proto_header_template,$(libutilsrcdir)/unix_privs.h,$(UNIX_PRIVS_OBJ_FILES:.o=.c))) ################################################ # Start SUBSYSTEM WRAP_XATTR @@ -63,7 +63,7 @@ PUBLIC_DEPENDENCIES = LIBTDB UTIL_TDB_OBJ_FILES = $(libutilsrcdir)/util_tdb.o -$(call proto_header_template,$(libutilsrcdir)/util_tdb.h,$(UTIL_TDB_OBJ_FILES)) +$(eval $(call proto_header_template,$(libutilsrcdir)/util_tdb.h,$(UTIL_TDB_OBJ_FILES))) [SUBSYSTEM::UTIL_LDB] PUBLIC_DEPENDENCIES = LIBLDB -- cgit From 60ae8f06574c74261643f469e6be2a945fd90880 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 18 May 2008 23:40:23 +0200 Subject: Fix a bunch of dependencies. (This used to be commit a63f458462d207d215a6e4ef8e480b0c8daedf6a) --- source4/lib/util/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index e9b8b38614..925713a53c 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -63,7 +63,7 @@ PUBLIC_DEPENDENCIES = LIBTDB UTIL_TDB_OBJ_FILES = $(libutilsrcdir)/util_tdb.o -$(eval $(call proto_header_template,$(libutilsrcdir)/util_tdb.h,$(UTIL_TDB_OBJ_FILES))) +$(eval $(call proto_header_template,$(libutilsrcdir)/util_tdb.h,$(UTIL_TDB_OBJ_FILES:.o=.c))) [SUBSYSTEM::UTIL_LDB] PUBLIC_DEPENDENCIES = LIBLDB -- cgit From 9a975a868e949e61cb011422363cd07b4ec0ce43 Mon Sep 17 00:00:00 2001 From: James Peach Date: Tue, 20 May 2008 10:54:45 -0700 Subject: smbtorture: Add RAW-BENCH-TCON benchmark. Add a simple test to benchmark the rate at which a server can accept new tree connections. You can tune the length of time to run the benchmark for and the number of parallel connections to make. (This used to be commit ea3f4b93057e85c4ea516cc77dd0f293016d520c) --- source4/lib/util/time.c | 2 +- source4/lib/util/time.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/time.c b/source4/lib/util/time.c index a181885806..978d73cc0a 100644 --- a/source4/lib/util/time.c +++ b/source4/lib/util/time.c @@ -376,7 +376,7 @@ _PUBLIC_ NTTIME pull_nttime(uint8_t *base, uint16_t offset) /** return (tv1 - tv2) in microseconds */ -_PUBLIC_ int64_t usec_time_diff(struct timeval *tv1, struct timeval *tv2) +_PUBLIC_ int64_t usec_time_diff(const struct timeval *tv1, const struct timeval *tv2) { int64_t sec_diff = tv1->tv_sec - tv2->tv_sec; return (sec_diff * 1000000) + (int64_t)(tv1->tv_usec - tv2->tv_usec); diff --git a/source4/lib/util/time.h b/source4/lib/util/time.h index 1ab976ca78..e4008c5782 100644 --- a/source4/lib/util/time.h +++ b/source4/lib/util/time.h @@ -127,7 +127,7 @@ _PUBLIC_ NTTIME nttime_from_string(const char *s); /** return (tv1 - tv2) in microseconds */ -_PUBLIC_ int64_t usec_time_diff(struct timeval *tv1, struct timeval *tv2); +_PUBLIC_ int64_t usec_time_diff(const struct timeval *tv1, const struct timeval *tv2); /** return a zero timeval -- cgit From 936b973acbc756cc3b6cb0d9df85ebc28ba76ae7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 14:36:28 +0200 Subject: Use new dynconfig.h location. (This used to be commit c3f556915f09d078253e4c5539910a1cf420eeca) --- source4/lib/util/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index 5c1abf5039..00dcbfc8bd 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -21,7 +21,7 @@ #include "includes.h" #include "system/filesys.h" #include "system/time.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" /** * @file -- cgit From 929adc9efa5cf985f0585214d30d18521aa1a821 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 14 Jun 2008 11:24:17 -0400 Subject: Make up the right dependencies now that ldb depends on libevents (This used to be commit 3b8eec7ca334528cad3cdcd5e3fc5ee555d8d0e0) --- source4/lib/util/util_ldb.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_ldb.c b/source4/lib/util/util_ldb.c index 38f53c2c66..0a7433696e 100644 --- a/source4/lib/util/util_ldb.c +++ b/source4/lib/util/util_ldb.c @@ -21,6 +21,7 @@ */ #include "includes.h" +#include "lib/events/events.h" #include "lib/ldb/include/ldb.h" #include "lib/ldb/include/ldb_errors.h" #include "lib/util/util_ldb.h" -- cgit From bcc6a3786c30a76ac80529cc60f4958dfed9abc6 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 27 Jun 2008 08:23:26 +0200 Subject: tdb_unpack: Eliminate "cast to pointer from integer of different size" warning on 64bit. The 'p' type is just a flag to mark the presence of a pointer, not a real pointer itself. The code is now the same as in Samba3's tdb_unpack. Michael (This used to be commit a516bc9a2d4ce86244d0e2fbfacf6fda5e12e987) --- source4/lib/util/util_tdb.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_tdb.c b/source4/lib/util/util_tdb.c index 77ad4eb617..e4219dfd69 100644 --- a/source4/lib/util/util_tdb.c +++ b/source4/lib/util/util_tdb.c @@ -482,7 +482,13 @@ int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...) p = va_arg(ap, void **); if (bufsize < len) goto no_space; - *p = (void *)IVAL(buf, 0); + + /* + * This isn't a real pointer - only a token (1 or 0) + * to mark the fact a pointer is present. + */ + + *p = (void *)(IVAL(buf, 0) ? (void *)1 : NULL); break; case 'P': /* Return a malloc'ed string. */ -- cgit From a05c9ab9391c80da747e2ee8cd52e92c23f5c72d Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Fri, 25 Jul 2008 17:43:21 +1000 Subject: Define HAVE_ASM_BYTEORDER at all times (This used to be commit 396ea14732d667960091f4a2570341059914ecb6) --- source4/lib/util/byteorder.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/byteorder.h b/source4/lib/util/byteorder.h index 857bd1d50b..894beccabf 100644 --- a/source4/lib/util/byteorder.h +++ b/source4/lib/util/byteorder.h @@ -126,6 +126,8 @@ static __inline__ void st_le32(uint32_t *addr, const uint32_t val) __asm__ ("stwbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr)); } #define HAVE_ASM_BYTEORDER 1 +#else +#define HAVE_ASM_BYTEORDER 0 #endif @@ -172,7 +174,7 @@ static __inline__ void st_le32(uint32_t *addr, const uint32_t val) #define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16_t)(val))) #define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32_t)(val))) -#else /* CAREFUL_ALIGNMENT */ +#else /* not CAREFUL_ALIGNMENT */ /* this handles things for architectures like the 386 that can handle alignment errors */ @@ -197,7 +199,7 @@ static __inline__ void st_le32(uint32_t *addr, const uint32_t val) #define SSVALS(buf,pos,val) SVALS_NC(buf,pos)=((int16_t)(val)) #define SIVALS(buf,pos,val) IVALS_NC(buf,pos)=((int32_t)(val)) -#endif /* CAREFUL_ALIGNMENT */ +#endif /* not CAREFUL_ALIGNMENT */ /* now the reverse routines - these are used in nmb packets (mostly) */ #define SREV(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF)) -- cgit From 4ad97a1d0593b3401a352407009a99ead23f21f2 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 21 Aug 2008 19:24:58 +1000 Subject: Don't walk past the end of ldb values. This is a partial fix towards bugs due to us walking past the end of what we think are strings in ldb. There is much more work to do in this area. Andrew Bartlett (This used to be commit 5805a9a8f35fd90fa4f718f73534817fa3bbdfd2) --- source4/lib/util/data_blob.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/data_blob.c b/source4/lib/util/data_blob.c index b258e47bba..57b34b7ae7 100644 --- a/source4/lib/util/data_blob.c +++ b/source4/lib/util/data_blob.c @@ -176,7 +176,7 @@ _PUBLIC_ DATA_BLOB data_blob_string_const(const char *str) { DATA_BLOB blob; blob.data = discard_const_p(uint8_t, str); - blob.length = strlen(str); + blob.length = str ? strlen(str) : 0; return blob; } -- cgit From cc43037f19056ed24d7fffa54456d597c63ad105 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 22 Aug 2008 17:36:56 +1000 Subject: fixed a problem with length limited ldap values The core ldb code for string matching assumed NULL terminated strings, whereas the anr module used data_blob_const() to effectively truncate a ldb_val by changing its length. The ldb code is supposed to be based around length limited blobs, not NULL terminated strings, so the correct fix was to change the string comparison functions to be length limited (This used to be commit 26c6aa5a80ffaf06fc33f30a6533f8f16ef538bc) --- source4/lib/util/util_ldb.c | 4 ++-- source4/lib/util/util_ldb.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/util_ldb.c b/source4/lib/util/util_ldb.c index 0a7433696e..fab729c036 100644 --- a/source4/lib/util/util_ldb.c +++ b/source4/lib/util/util_ldb.c @@ -125,9 +125,9 @@ int gendb_add_ldif(struct ldb_context *ldb, const char *ldif_string) return ret; } -char *wrap_casefold(void *context, void *mem_ctx, const char *s) +char *wrap_casefold(void *context, void *mem_ctx, const char *s, size_t n) { - return strupper_talloc(mem_ctx, s); + return strupper_talloc_n(mem_ctx, s, n); } diff --git a/source4/lib/util/util_ldb.h b/source4/lib/util/util_ldb.h index 030ba7ebee..43f98ae1a9 100644 --- a/source4/lib/util/util_ldb.h +++ b/source4/lib/util/util_ldb.h @@ -22,6 +22,6 @@ int gendb_search_dn(struct ldb_context *ldb, struct ldb_message ***res, const char * const *attrs); int gendb_add_ldif(struct ldb_context *ldb, const char *ldif_string); -char *wrap_casefold(void *context, void *mem_ctx, const char *s); +char *wrap_casefold(void *context, void *mem_ctx, const char *s, size_t n); #endif /* __LIB_UTIL_UTIL_LDB_H__ */ -- cgit