summaryrefslogtreecommitdiffstats
path: root/source/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source/lib')
-rw-r--r--source/lib/access.c2
-rw-r--r--source/lib/charcnv.c19
-rw-r--r--source/lib/debug.c9
-rw-r--r--source/lib/error.c4
-rw-r--r--source/lib/interfaces.c17
-rw-r--r--source/lib/kanji.c4
-rw-r--r--source/lib/messages.c14
-rw-r--r--source/lib/replace.c2
-rw-r--r--source/lib/select.c7
-rw-r--r--source/lib/snprintf.c22
-rw-r--r--source/lib/sysacls.c2
-rw-r--r--source/lib/talloc.c17
-rw-r--r--source/lib/time.c10
-rw-r--r--source/lib/util.c8
-rw-r--r--source/lib/util_sock.c10
-rw-r--r--source/lib/util_str.c34
-rw-r--r--source/lib/util_unistr.c35
17 files changed, 149 insertions, 67 deletions
diff --git a/source/lib/access.c b/source/lib/access.c
index 73b4d57e706..8bf3ba19337 100644
--- a/source/lib/access.c
+++ b/source/lib/access.c
@@ -33,7 +33,7 @@ static int masked_match(char *tok, char *slash, char *s)
if (strlen(slash + 1) > 2) {
mask = interpret_addr(slash + 1);
} else {
- mask = (uint32)((ALLONES >> atoi(slash + 1)) ^ ALLONES);
+ mask = (uint32)((ALLONES << atoi(slash + 1)) ^ ALLONES);
}
if (net == INADDR_NONE || mask == INADDR_NONE) {
diff --git a/source/lib/charcnv.c b/source/lib/charcnv.c
index 2affa6a9e06..a4f90a5a10f 100644
--- a/source/lib/charcnv.c
+++ b/source/lib/charcnv.c
@@ -20,7 +20,8 @@
*/
#include "includes.h"
-#define CTRLZ 26
+#define CTRLZ 26
+#define SPC 32
static char cvtbuf[sizeof(pstring)];
@@ -58,8 +59,15 @@ static void setupmaps(void)
/* Do not map undefined characters to some accidental code */
for (i = 128; i < 256; i++)
{
+#if 0 /* JERRY */
+ /* Win2k & XP don't like the Ctrl-Z apparently */
+ /* patch from Toomas.Soome@microlink.ee */
unix2dos[i] = CTRLZ;
dos2unix[i] = CTRLZ;
+#else
+ unix2dos[i] = SPC;
+ dos2unix[i] = SPC;
+#endif
}
}
@@ -400,6 +408,8 @@ char *unix2dos_format_static(const char *str)
if (!mapsinited)
initmaps();
+ if (!str)
+ return NULL;
for (p = str, dp = cvtbuf;*p && (dp - cvtbuf < sizeof(cvtbuf) - 1); p++,dp++)
*dp = unix2dos[(unsigned char)*p];
*dp = 0;
@@ -413,6 +423,8 @@ char *unix2dos_format(char *str)
if (!mapsinited)
initmaps();
+ if (!str)
+ return NULL;
for (p = str; *p; p++)
*p = unix2dos[(unsigned char)*p];
return str;
@@ -430,6 +442,8 @@ char *dos2unix_format_static(const char *str)
if (!mapsinited)
initmaps();
+ if (!str)
+ return NULL;
for (p = str, dp = cvtbuf;*p && (dp - cvtbuf < sizeof(cvtbuf) - 1); p++,dp++)
*dp = dos2unix[(unsigned char)*p];
*dp = 0;
@@ -443,6 +457,9 @@ char *dos2unix_format(char *str)
if (!mapsinited)
initmaps();
+ if (!str)
+ return NULL;
+
for (p = str; *p; p++)
*p = dos2unix[(unsigned char)*p];
return str;
diff --git a/source/lib/debug.c b/source/lib/debug.c
index 3731b3656fa..347c644c2a0 100644
--- a/source/lib/debug.c
+++ b/source/lib/debug.c
@@ -232,13 +232,12 @@ BOOL debug_parse_levels(char *params_str)
/* save current debug level */
memcpy(old_debuglevel_class, DEBUGLEVEL_CLASS, sizeof(DEBUGLEVEL_CLASS));
if (debug_parse_params(params, debuglevel_class))
- debug_message(0, getpid(), (void*)debuglevel_class, sizeof(debuglevel_class));
- memcpy(parsed_debuglevel_class, DEBUGLEVEL_CLASS, sizeof(DEBUGLEVEL_CLASS));
+ memcpy(parsed_debuglevel_class, debuglevel_class, sizeof(DEBUGLEVEL_CLASS));
memcpy(DEBUGLEVEL_CLASS, old_debuglevel_class, sizeof(old_debuglevel_class));
return True;
}
if (debug_parse_params(params, debuglevel_class)) {
- debug_message(DEBUGLEVEL, getpid(), (void*)debuglevel_class, sizeof(debuglevel_class));
+ debug_message(MSG_DEBUG, getpid(), (void*)debuglevel_class, sizeof(debuglevel_class));
return True;
} else
return False;
@@ -247,14 +246,14 @@ BOOL debug_parse_levels(char *params_str)
/****************************************************************************
receive a "set debug level" message
****************************************************************************/
-void debug_message(int msg_level, pid_t src, void *buf, size_t len)
+void debug_message(int msg_type, pid_t src, void *buf, size_t len)
{
int i;
/* Set the new DEBUGLEVEL_CLASS array from the pased array */
memcpy(DEBUGLEVEL_CLASS, buf, sizeof(DEBUGLEVEL_CLASS));
- DEBUG(msg_level,("INFO: Debug class %s level = %d (pid %u from pid %u)\n",
+ DEBUG(1,("INFO: Debug class %s level = %d (pid %u from pid %u)\n",
classname_table[DBGC_ALL],
DEBUGLEVEL_CLASS[DBGC_ALL], (unsigned int)getpid(), (unsigned int)src));
diff --git a/source/lib/error.c b/source/lib/error.c
index ec7efd11f4c..5fbc9a7f4fa 100644
--- a/source/lib/error.c
+++ b/source/lib/error.c
@@ -26,8 +26,8 @@
struct unix_error_map unix_dos_nt_errmap[] = {
{ EPERM, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED },
{ EACCES, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED },
- { ENOENT, ERRDOS, ERRbadfile, NT_STATUS_NO_SUCH_FILE },
- { ENOTDIR, ERRDOS, ERRbadpath, NT_STATUS_NOT_A_DIRECTORY },
+ { ENOENT, ERRDOS, ERRbadfile, NT_STATUS_OBJECT_NAME_NOT_FOUND },
+ { ENOTDIR, ERRDOS, ERRbadpath, NT_STATUS_OBJECT_PATH_NOT_FOUND },
{ EIO, ERRHRD, ERRgeneral, NT_STATUS_IO_DEVICE_ERROR },
{ EBADF, ERRSRV, ERRsrverror, NT_STATUS_INVALID_HANDLE },
{ EINVAL, ERRSRV, ERRsrverror, NT_STATUS_INVALID_HANDLE },
diff --git a/source/lib/interfaces.c b/source/lib/interfaces.c
index e7b9efa1f0a..9e8c979aa7b 100644
--- a/source/lib/interfaces.c
+++ b/source/lib/interfaces.c
@@ -39,15 +39,8 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/ioctl.h>
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
#include <net/if.h>
-#ifndef SIOCGIFCONF
-#include <sys/sockio.h>
-#endif
-
#ifdef AUTOCONF_TEST
struct iface_struct {
char name[16];
@@ -59,6 +52,16 @@ struct iface_struct {
#include "interfaces.h"
#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
+#ifndef SIOCGIFCONF
+#ifdef HAVE_SYS_SOCKIO_H
+#include <sys/sockio.h>
+#endif
+#endif
+
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
diff --git a/source/lib/kanji.c b/source/lib/kanji.c
index 8a7494e6d77..940457d1681 100644
--- a/source/lib/kanji.c
+++ b/source/lib/kanji.c
@@ -1249,7 +1249,7 @@ static char *sj_to_hex_static(const char *from)
const unsigned char *sp;
unsigned char *dp;
- sp = from;
+ sp = (const uchar *)from;
dp = (unsigned char*) cvtbuf;
while (*sp && (((char *)dp)- cvtbuf < sizeof(cvtbuf)-7)) {
if (is_kana(*sp)) {
@@ -1321,7 +1321,7 @@ static char *sj_to_cap_static(const char *from)
const unsigned char *sp;
unsigned char *dp;
- sp = from;
+ sp = (const uchar *)from;
dp = (unsigned char*) cvtbuf;
while (*sp && (((char *)dp) - cvtbuf < sizeof(cvtbuf)-4)) {
if (*sp >= 0x80) {
diff --git a/source/lib/messages.c b/source/lib/messages.c
index 518b7d51c1e..9d2d46e4114 100644
--- a/source/lib/messages.c
+++ b/source/lib/messages.c
@@ -322,8 +322,8 @@ void message_dispatch(void)
received_signal = 0;
while (message_recv(&msg_type, &src, &buf, &len)) {
- DEBUG(10,("message_dispatch: received msg_type=%d src_pid=%d\n",
- msg_type, (int) src));
+ DEBUG(10,("message_dispatch: received msg_type=%d src_pid=%u\n",
+ msg_type, (unsigned int) src));
n_handled = 0;
for (dfn = dispatch_fns; dfn; dfn = dfn->next) {
if (dfn->msg_type == msg_type) {
@@ -334,8 +334,8 @@ void message_dispatch(void)
}
if (!n_handled) {
DEBUG(5,("message_dispatch: warning: no handlers registed for "
- "msg_type %d in pid%d\n",
- msg_type, getpid()));
+ "msg_type %d in pid%u\n",
+ msg_type, (unsigned int)getpid()));
}
SAFE_FREE(buf);
}
@@ -459,7 +459,7 @@ BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type,
/** @} **/
-static VOLATILE sig_atomic_t gotalarm;
+static SIG_ATOMIC_T gotalarm;
/***************************************************************
Signal function to tell us we timed out.
@@ -474,7 +474,7 @@ static void gotalarm_sig(void)
lock the messaging tdb based on a string - this is used as a primitive form of mutex
between smbd instances.
*/
-BOOL message_named_mutex(char *name, unsigned int timeout)
+BOOL message_named_mutex(const char *name, unsigned int timeout)
{
TDB_DATA key;
int ret;
@@ -482,7 +482,7 @@ BOOL message_named_mutex(char *name, unsigned int timeout)
if (!message_init())
return False;
- key.dptr = name;
+ key.dptr = (char *)name;
key.dsize = strlen(name)+1;
if (timeout) {
diff --git a/source/lib/replace.c b/source/lib/replace.c
index dd50ff035e0..370b6dfebf2 100644
--- a/source/lib/replace.c
+++ b/source/lib/replace.c
@@ -47,7 +47,7 @@ ftruncate for operating systems that don't have it
{
size_t len = strlen(s);
size_t ret = len;
- if (bufsize <= 0) return 0;
+ if (bufsize == 0) return 0;
if (len >= bufsize) len = bufsize-1;
memcpy(d, s, len);
d[len] = 0;
diff --git a/source/lib/select.c b/source/lib/select.c
index f70268b7ce4..efcf63becca 100644
--- a/source/lib/select.c
+++ b/source/lib/select.c
@@ -134,10 +134,12 @@ int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorf
{
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)
@@ -146,7 +148,10 @@ int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorf
writefds_buf = *writefds;
if (errorfds)
errorfds_buf = *errorfds;
- ret = sys_select(maxfd, readfds2, writefds2, errorfds2, tval);
+ if (tval)
+ tval2 = *tval;
+
+ ret = sys_select(maxfd, readfds2, writefds2, errorfds2, ptval);
} while (ret == -1 && errno == EINTR);
if (readfds)
diff --git a/source/lib/snprintf.c b/source/lib/snprintf.c
index 27336261086..ebb8bf74c77 100644
--- a/source/lib/snprintf.c
+++ b/source/lib/snprintf.c
@@ -105,8 +105,16 @@
#define SAFE_FREE(x) do { if ((x) != NULL) {free((x)); (x)=NULL;} } while(0)
#endif
+#ifndef VA_COPY
+#ifdef HAVE_VA_COPY
+#define VA_COPY(dest, src) __va_copy(dest, src)
+#else
+#define VA_COPY(dest, src) (dest) = (src)
+#endif
+#endif
+
static size_t dopr(char *buffer, size_t maxlen, const char *format,
- va_list args);
+ va_list args_in);
static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
char *value, int flags, int min, int max);
static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
@@ -149,7 +157,7 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c);
#define MAX(p,q) (((p) >= (q)) ? (p) : (q))
#endif
-static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args)
+static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args_in)
{
char ch;
LLONG value;
@@ -161,7 +169,10 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
int flags;
int cflags;
size_t currlen;
+ va_list args;
+ VA_COPY(args, args_in);
+
state = DP_S_DEFAULT;
currlen = flags = cflags = min = 0;
max = -1;
@@ -793,13 +804,16 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c)
int vasprintf(char **ptr, const char *format, va_list ap)
{
int ret;
+ va_list ap2;
- ret = vsnprintf(NULL, 0, format, ap);
+ VA_COPY(ap2, ap);
+ ret = vsnprintf(NULL, 0, format, ap2);
if (ret <= 0) return ret;
(*ptr) = (char *)malloc(ret+1);
if (!*ptr) return -1;
- ret = vsnprintf(*ptr, ret+1, format, ap);
+ VA_COPY(ap2, ap);
+ ret = vsnprintf(*ptr, ret+1, format, ap2);
return ret;
}
diff --git a/source/lib/sysacls.c b/source/lib/sysacls.c
index 9ce04e596b9..21814383697 100644
--- a/source/lib/sysacls.c
+++ b/source/lib/sysacls.c
@@ -2937,7 +2937,7 @@ int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl
memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
}
- rc = chacl(name,file_acl,file_acl->acl_len);
+ rc = chacl((char *)name,file_acl,file_acl->acl_len);
DEBUG(10,("errno is %d\n",errno));
DEBUG(10,("return code is %d\n",rc));
SAFE_FREE(file_acl);
diff --git a/source/lib/talloc.c b/source/lib/talloc.c
index 6ac784a9297..8c722e1ff78 100644
--- a/source/lib/talloc.c
+++ b/source/lib/talloc.c
@@ -307,12 +307,16 @@ char *talloc_strdup(TALLOC_CTX *t, const char *p)
{
int len;
char *ret;
+ va_list ap2;
- len = vsnprintf(NULL, 0, fmt, ap);
+ VA_COPY(ap2, ap); /* for systems were va_list is a struct */
+ len = vsnprintf(NULL, 0, fmt, ap2);
ret = talloc(t, len+1);
- if (ret)
- vsnprintf(ret, len+1, fmt, ap);
+ if (ret) {
+ VA_COPY(ap2, ap);
+ vsnprintf(ret, len+1, fmt, ap2);
+ }
return ret;
}
@@ -345,14 +349,17 @@ char *talloc_strdup(TALLOC_CTX *t, const char *p)
const char *fmt, va_list ap)
{
int len, s_len;
+ va_list ap2;
+ VA_COPY(ap2, ap);
s_len = strlen(s);
- len = vsnprintf(NULL, 0, fmt, ap);
+ len = vsnprintf(NULL, 0, fmt, ap2);
s = talloc_realloc(t, s, s_len + len+1);
if (!s) return NULL;
- vsnprintf(s+s_len, len+1, fmt, ap);
+ VA_COPY(ap2, ap);
+ vsnprintf(s+s_len, len+1, fmt, ap2);
return s;
}
diff --git a/source/lib/time.c b/source/lib/time.c
index 43c8ca67dd4..aa433a769c6 100644
--- a/source/lib/time.c
+++ b/source/lib/time.c
@@ -33,14 +33,6 @@ int extra_time_offset = 0;
#define CHAR_BIT 8
#endif
-#ifndef TIME_T_MIN
-#define TIME_T_MIN ((time_t)0 < (time_t) -1 ? (time_t) 0 \
- : ~ (time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1))
-#endif
-#ifndef TIME_T_MAX
-#define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN)
-#endif
-
/*******************************************************************
External access to time_t_min and time_t_max.
********************************************************************/
@@ -414,7 +406,7 @@ void unix_to_nt_time(NTTIME *nt, time_t t)
}
/* this converts GMT to kludge-GMT */
- t -= LocTimeDiff(t) - get_serverzone();
+ t -= TimeDiff(t) - get_serverzone();
d = (double)(t);
d += TIME_FIXUP_CONSTANT;
diff --git a/source/lib/util.c b/source/lib/util.c
index 9ff2bba5647..b017e75dca2 100644
--- a/source/lib/util.c
+++ b/source/lib/util.c
@@ -119,7 +119,7 @@ BOOL in_group(gid_t group, gid_t current_gid, int ngroups, gid_t *groups)
}
/****************************************************************************
- Like atoi but gets the value up to the separater character.
+ Like atoi but gets the value up to the separator character.
****************************************************************************/
char *Atoic(char *p, int *n, char *c)
@@ -1783,7 +1783,11 @@ char *smb_xstrdup(const char *s)
int smb_xvasprintf(char **ptr, const char *format, va_list ap)
{
int n;
- n = vasprintf(ptr, format, ap);
+ va_list ap2;
+
+ VA_COPY(ap2, ap);
+
+ n = vasprintf(ptr, format, ap2);
if (n == -1 || ! *ptr) {
smb_panic("smb_xvasprintf: out of memory");
}
diff --git a/source/lib/util_sock.c b/source/lib/util_sock.c
index 4b5abbb5724..dca80289e1f 100644
--- a/source/lib/util_sock.c
+++ b/source/lib/util_sock.c
@@ -42,7 +42,8 @@ int smb_read_error = 0;
BOOL is_a_socket(int fd)
{
- int v,l;
+ int v;
+ socklen_t l;
l = sizeof(int);
return(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&v, &l) == 0);
}
@@ -99,7 +100,8 @@ smb_socket_option socket_options[] = {
static void print_socket_options(int s)
{
- int value, vlen = 4;
+ int value;
+ socklen_t vlen = 4;
smb_socket_option *p = &socket_options[0];
for (; p->name != NULL; p++) {
@@ -931,7 +933,7 @@ static BOOL matchname(char *remotehost,struct in_addr addr)
/* Look up the host address in the address list we just got. */
for (i = 0; hp->h_addr_list[i]; i++) {
- if (memcmp(hp->h_addr_list[i], (caddr_t) & addr, sizeof(addr)) == 0)
+ if (memcmp(hp->h_addr_list[i], (void *) & addr, sizeof(addr)) == 0)
return True;
}
@@ -997,7 +999,7 @@ char *get_socket_addr(int fd)
{
struct sockaddr sa;
struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
- int length = sizeof(sa);
+ socklen_t length = sizeof(sa);
static fstring addr_buf;
fstrcpy(addr_buf,"0.0.0.0");
diff --git a/source/lib/util_str.c b/source/lib/util_str.c
index a2b01a0fc7e..f44341b8dd1 100644
--- a/source/lib/util_str.c
+++ b/source/lib/util_str.c
@@ -1332,3 +1332,37 @@ char *binary_string(char *buf, int len)
s[j] = 0;
return s;
}
+
+#ifndef HAVE_STRNLEN
+/*******************************************************************
+ Some platforms don't have strnlen
+********************************************************************/
+
+ size_t strnlen(const char *s, size_t n)
+{
+ int i;
+ for (i=0; s[i] && i<n; i++)
+ /* noop */ ;
+ return i;
+}
+#endif
+
+#ifndef HAVE_STRNDUP
+/*******************************************************************
+ Some platforms don't have strndup.
+********************************************************************/
+
+ char *strndup(const char *s, size_t n)
+{
+ char *ret;
+
+ n = strnlen(s, n);
+ ret = malloc(n+1);
+ if (!ret)
+ return NULL;
+ memcpy(ret, s, n);
+ ret[n] = 0;
+
+ return ret;
+}
+#endif
diff --git a/source/lib/util_unistr.c b/source/lib/util_unistr.c
index a2bd0cf4913..efad8df1ea8 100644
--- a/source/lib/util_unistr.c
+++ b/source/lib/util_unistr.c
@@ -310,11 +310,11 @@ void unistr_to_ascii(char *dest, const uint16 *src, int len)
}
/*******************************************************************
- Convert a (little-endian) UNISTR2 structure to an ASCII string
- Warning: this version does DOS codepage.
+ Convert a (little-endian) UNISTR2 structure to an ASCII string, either
+ DOS or UNIX codepage.
********************************************************************/
-void unistr2_to_ascii(char *dest, const UNISTR2 *str, size_t maxlen)
+static void unistr2_to_mbcp(char *dest, const UNISTR2 *str, size_t maxlen, uint16 *ucs2_to_mbcp)
{
char *p;
uint16 *src;
@@ -335,7 +335,7 @@ void unistr2_to_ascii(char *dest, const UNISTR2 *str, size_t maxlen)
for (p = dest; (p-dest < maxlen-3) && (src - str->buffer < str->uni_str_len) && *src; src++) {
uint16 ucs2_val = SVAL(src,0);
- uint16 cp_val = ucs2_to_doscp[ucs2_val];
+ uint16 cp_val = ucs2_to_mbcp[ucs2_val];
if (cp_val < 256)
*p++ = (char)cp_val;
@@ -349,18 +349,23 @@ void unistr2_to_ascii(char *dest, const UNISTR2 *str, size_t maxlen)
}
/*******************************************************************
- duplicate a UNISTR2 string into a null terminated char*
- using a talloc context
+ Convert a (little-endian) UNISTR2 structure to an ASCII string
+ Warning: this version does DOS codepage.
********************************************************************/
-char *unistr2_tdup(TALLOC_CTX *ctx, const UNISTR2 *str)
-{
- char *s;
- int maxlen = (str->uni_str_len+1)*4;
- if (!str->buffer) return NULL;
- s = (char *)talloc(ctx, maxlen); /* convervative */
- if (!s) return NULL;
- unistr2_to_ascii(s, str, maxlen);
- return s;
+
+void unistr2_to_dos(char *dest, const UNISTR2 *str, size_t maxlen)
+{
+ unistr2_to_mbcp(dest, str, maxlen, ucs2_to_doscp);
+}
+
+/*******************************************************************
+ Convert a (little-endian) UNISTR2 structure to an ASCII string
+ Warning: this version does UNIX codepage.
+********************************************************************/
+
+void unistr2_to_unix(char *dest, const UNISTR2 *str, size_t maxlen)
+{
+ unistr2_to_mbcp(dest, str, maxlen, ucs2_to_unixcp);
}
/*******************************************************************