From 00075c49245d5f96139b7c09f37a2b39aa10559f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 1 Feb 2008 14:23:56 +0100 Subject: NetBSD does not support AI_ADDRCONFIG (This used to be commit fb3f7f4046fa195baf5116598772d9016238637f) --- source3/lib/replace/system/network.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/replace/system/network.h b/source3/lib/replace/system/network.h index fe6e46817f..aff8a841da 100644 --- a/source3/lib/replace/system/network.h +++ b/source3/lib/replace/system/network.h @@ -137,8 +137,15 @@ const char *rep_inet_ntop(int af, const void *src, char *dst, socklen_t size); #endif #ifndef AI_ADDRCONFIG +/* + * logic copied from AI_NUMERICHOST + */ +#if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO) +#define AI_ADDRCONFIG 0 +#else #define AI_ADDRCONFIG 0x0020 #endif +#endif #ifndef AI_NUMERICSERV /* -- cgit From b9b75f37acec632333cea1737edc46071661b480 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 1 Feb 2008 14:23:54 -0800 Subject: Ensure that convert_string_allocate() allocates 2 extra bytes and null terminates them to ensure NDR wire-reads of string types are always null terminated. Bug found by Volker after great pain :-). Jeremy. (This used to be commit aab736e6079729b3f3ab653674834e3f1305d456) --- source3/lib/charcnv.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index eeff805459..d11620ecd7 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -524,7 +524,7 @@ size_t convert_string(charset_t from, charset_t to, size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, void *dst, bool allow_bad_conv) { - size_t i_len, o_len, destlen = MAX(srclen, 512); + size_t i_len, o_len, destlen = (srclen * 3) / 2; size_t retval; const char *inbuf = (const char *)src; char *outbuf = NULL, *ob = NULL; @@ -550,7 +550,8 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, convert: - if ((destlen*2) < destlen) { + /* +2 is for ucs2 null termination. */ + if ((destlen*2)+2 < destlen) { /* wrapped ! abort. */ if (!conv_silent) DEBUG(0, ("convert_string_allocate: destlen wrapped !\n")); @@ -561,10 +562,11 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, destlen = destlen * 2; } + /* +2 is for ucs2 null termination. */ if (ctx) { - ob = (char *)TALLOC_REALLOC(ctx, ob, destlen); + ob = (char *)TALLOC_REALLOC(ctx, ob, destlen + 2); } else { - ob = (char *)SMB_REALLOC(ob, destlen); + ob = (char *)SMB_REALLOC(ob, destlen + 2); } if (!ob) { @@ -619,10 +621,11 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, * reallocs *cost*. JRA. */ if (o_len > 1024) { + /* We're shrinking here so we know the +2 is safe from wrap. */ if (ctx) { - ob = (char *)TALLOC_REALLOC(ctx,ob,destlen); + ob = (char *)TALLOC_REALLOC(ctx,ob,destlen + 2); } else { - ob = (char *)SMB_REALLOC(ob,destlen); + ob = (char *)SMB_REALLOC(ob,destlen + 2); } } @@ -632,6 +635,11 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, } *dest = ob; + + /* Must ucs2 null terminate in the extra space we allocated. */ + ob[destlen] = '\0'; + ob[destlen+1] = '\0'; + return destlen; use_as_is: -- cgit From 680a0f0c69f2c31e0e72276444d130d3a60bef82 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 1 Feb 2008 15:37:11 +0100 Subject: Fix a typo (This used to be commit 1efdef08ae19a01b03bf6730df1fb4a9a4a8aba0) --- source3/lib/util_sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index ced1130536..f5797f175b 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -112,7 +112,7 @@ static bool interpret_string_addr_internal(struct addrinfo **ppres, &hints, ppres); if (ret) { - DEBUG(3,("interpret_string_addr_interal: getaddrinfo failed " + DEBUG(3,("interpret_string_addr_internal: getaddrinfo failed " "for name %s [%s]\n", str, gai_strerror(ret) )); -- cgit From 57ea4571402101915f2565133a374d9cd7c3ee51 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 1 Feb 2008 20:03:05 +0100 Subject: NetBSD needs LD_LIBRARY_PATH (This used to be commit d64b19e77aa499c1ee1aaf788ddf3d6fd36253e4) --- source3/lib/replace/libreplace_ld.m4 | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/replace/libreplace_ld.m4 b/source3/lib/replace/libreplace_ld.m4 index 2aec698967..f0d10c1e3e 100644 --- a/source3/lib/replace/libreplace_ld.m4 +++ b/source3/lib/replace/libreplace_ld.m4 @@ -289,6 +289,9 @@ AC_DEFUN([AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR], *linux*) LIB_PATH_VAR=LD_LIBRARY_PATH ;; + *netbsd*) + LIB_PATH_VAR=LD_LIBRARY_PATH + ;; *solaris*) LIB_PATH_VAR=LD_LIBRARY_PATH ;; -- cgit From fa5391a919cf729134d9ec0368fced9cc028d02e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 24 Jan 2008 19:06:25 +0100 Subject: Return NOTFOUND from db_tdb_delete if the record does not exist (This used to be commit 1ff924c4360952eb1d714a2f2ec3760b380c7a24) --- source3/lib/dbwrap_tdb.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/dbwrap_tdb.c b/source3/lib/dbwrap_tdb.c index 18f9495931..da55049e52 100644 --- a/source3/lib/dbwrap_tdb.c +++ b/source3/lib/dbwrap_tdb.c @@ -196,8 +196,15 @@ static NTSTATUS db_tdb_delete(struct db_record *rec) struct db_tdb_ctx *ctx = talloc_get_type_abort(rec->private_data, struct db_tdb_ctx); - return (tdb_delete(ctx->wtdb->tdb, rec->key) == 0) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; + if (tdb_delete(ctx->wtdb->tdb, rec->key) == 0) { + return NT_STATUS_OK; + } + + if (tdb_error(ctx->wtdb->tdb) == TDB_ERR_NOEXIST) { + return NT_STATUS_NOT_FOUND; + } + + return NT_STATUS_UNSUCCESSFUL; } struct db_tdb_traverse_ctx { -- cgit From 3f970f91c2af77acd531c37ee3aa1a09ca71e7ab Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 24 Jan 2008 19:17:14 +0100 Subject: Add read_socket_with_timeout_ntstatus (This used to be commit 546ca0414aa1a9389e620b8f532224a3a19256d4) --- source3/lib/util_sock.c | 71 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 23 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index f5797f175b..f61cdb151e 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -913,12 +913,10 @@ ssize_t read_udp_v4_socket(int fd, time_out = timeout in milliseconds ****************************************************************************/ -ssize_t read_socket_with_timeout(int fd, - char *buf, - size_t mincnt, - size_t maxcnt, - unsigned int time_out, - enum smb_read_errors *pre) +NTSTATUS read_socket_with_timeout_ntstatus(int fd, char *buf, + size_t mincnt, size_t maxcnt, + unsigned int time_out, + size_t *size_ret) { fd_set fds; int selrtn; @@ -929,9 +927,7 @@ ssize_t read_socket_with_timeout(int fd, /* just checking .... */ if (maxcnt <= 0) - return(0); - - set_smb_read_error(pre,SMB_READ_OK); + return NT_STATUS_OK; /* Blocking read */ if (time_out == 0) { @@ -945,8 +941,7 @@ ssize_t read_socket_with_timeout(int fd, if (readret == 0) { DEBUG(5,("read_socket_with_timeout: " "blocking read. EOF from client.\n")); - set_smb_read_error(pre,SMB_READ_EOF); - return -1; + return NT_STATUS_END_OF_FILE; } if (readret == -1) { @@ -962,12 +957,11 @@ ssize_t read_socket_with_timeout(int fd, "read error = %s.\n", strerror(errno) )); } - set_smb_read_error(pre,SMB_READ_ERROR); - return -1; + return map_nt_error_from_unix(errno); } nread += readret; } - return((ssize_t)nread); + goto done; } /* Most difficult - timeout read */ @@ -1001,16 +995,14 @@ ssize_t read_socket_with_timeout(int fd, "read. select error = %s.\n", strerror(errno) )); } - set_smb_read_error(pre,SMB_READ_ERROR); - return -1; + return map_nt_error_from_unix(errno); } /* Did we timeout ? */ if (selrtn == 0) { DEBUG(10,("read_socket_with_timeout: timeout read. " "select timed out.\n")); - set_smb_read_error(pre,SMB_READ_TIMEOUT); - return -1; + return NT_STATUS_IO_TIMEOUT; } readret = sys_read(fd, buf+nread, maxcnt-nread); @@ -1019,8 +1011,7 @@ ssize_t read_socket_with_timeout(int fd, /* we got EOF on the file descriptor */ DEBUG(5,("read_socket_with_timeout: timeout read. " "EOF from client.\n")); - set_smb_read_error(pre,SMB_READ_EOF); - return -1; + return NT_STATUS_END_OF_FILE; } if (readret == -1) { @@ -1037,15 +1028,49 @@ ssize_t read_socket_with_timeout(int fd, "read. read error = %s.\n", strerror(errno) )); } - set_smb_read_error(pre,SMB_READ_ERROR); - return -1; + return map_nt_error_from_unix(errno); } nread += readret; } + done: /* Return the number we got */ - return (ssize_t)nread; + if (size_ret) { + *size_ret = nread; + } + return NT_STATUS_OK; +} + +ssize_t read_socket_with_timeout(int fd, char *buf, + size_t mincnt, size_t maxcnt, + unsigned int time_out, + enum smb_read_errors *pre) +{ + NTSTATUS status; + size_t size_ret; + + set_smb_read_error(pre, SMB_READ_OK); + + status = read_socket_with_timeout_ntstatus(fd, buf, mincnt, maxcnt, + time_out, &size_ret); + + if (NT_STATUS_IS_OK(status)) { + return size_ret; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(pre, SMB_READ_EOF); + return -1; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(pre, SMB_READ_TIMEOUT); + return -1; + } + + set_smb_read_error(pre, SMB_READ_ERROR); + return -1; } /**************************************************************************** -- cgit From 3e5b98555b832772d6fe93a57005bc39222a5189 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 21:02:52 +0100 Subject: Convert read_smb_length_return_keepalive to read_socket_with_timeout_ntstatus (This used to be commit 59e8f22f36be5a70fdb101964570ce7c10e8ff65) --- source3/lib/util_sock.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index f61cdb151e..d32d67f2fc 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1146,10 +1146,27 @@ ssize_t read_smb_length_return_keepalive(int fd, unsigned int timeout, enum smb_read_errors *pre) { - ssize_t len=0; + size_t len=0; int msg_type; + NTSTATUS status; + + set_smb_read_error(pre, SMB_READ_OK); + + status = read_socket_with_timeout_ntstatus(fd, inbuf, 4, 4, timeout, + NULL); + + if (!NT_STATUS_IS_OK(status)) { + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(pre, SMB_READ_EOF); + return -1; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(pre, SMB_READ_TIMEOUT); + return -1; + } - if (read_socket_with_timeout(fd, inbuf, 4, 4, timeout, pre) != 4) { + set_smb_read_error(pre, SMB_READ_ERROR); return -1; } -- cgit From 0afbfa4284db8204a3696f4fea6cff96965e6074 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 21:24:48 +0100 Subject: Convert read_smb_length_return_keepalive to return NTSTATUS (This used to be commit 73a79a957a33a8761acf54598ce71e3604ecf3c5) --- source3/lib/util_sock.c | 80 +++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 36 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index d32d67f2fc..f62b20b6fc 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1141,36 +1141,21 @@ bool send_keepalive(int client) Timeout is in milliseconds. ****************************************************************************/ -ssize_t read_smb_length_return_keepalive(int fd, - char *inbuf, - unsigned int timeout, - enum smb_read_errors *pre) +NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf, + unsigned int timeout, + size_t *len) { - size_t len=0; int msg_type; NTSTATUS status; - set_smb_read_error(pre, SMB_READ_OK); - status = read_socket_with_timeout_ntstatus(fd, inbuf, 4, 4, timeout, NULL); if (!NT_STATUS_IS_OK(status)) { - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(pre, SMB_READ_EOF); - return -1; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(pre, SMB_READ_TIMEOUT); - return -1; - } - - set_smb_read_error(pre, SMB_READ_ERROR); - return -1; + return status; } - len = smb_len(inbuf); + *len = smb_len(inbuf); msg_type = CVAL(inbuf,0); if (msg_type == SMBkeepalive) { @@ -1179,7 +1164,7 @@ ssize_t read_smb_length_return_keepalive(int fd, DEBUG(10,("got smb length of %lu\n",(unsigned long)len)); - return len; + return NT_STATUS_OK; } /**************************************************************************** @@ -1191,15 +1176,31 @@ ssize_t read_smb_length_return_keepalive(int fd, ssize_t read_smb_length(int fd, char *inbuf, unsigned int timeout, enum smb_read_errors *pre) { - ssize_t len; + size_t len; uint8_t msgtype = SMBkeepalive; + set_smb_read_error(pre, SMB_READ_OK); + while (msgtype == SMBkeepalive) { - len = read_smb_length_return_keepalive(fd, inbuf, timeout, - pre); - if (len < 0) { - return len; + NTSTATUS status; + + status = read_smb_length_return_keepalive(fd, inbuf, timeout, + &len); + if (!NT_STATUS_IS_OK(status)) { + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(pre, SMB_READ_EOF); + return -1; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(pre, SMB_READ_TIMEOUT); + return -1; + } + + set_smb_read_error(pre, SMB_READ_ERROR); + return -1; } + msgtype = CVAL(inbuf, 0); } @@ -1225,21 +1226,28 @@ ssize_t receive_smb_raw(int fd, size_t maxlen, enum smb_read_errors *pre) { - ssize_t len,ret; + size_t len; + ssize_t ret; + NTSTATUS status; set_smb_read_error(pre,SMB_READ_OK); - len = read_smb_length_return_keepalive(fd,buffer,timeout,pre); - if (len < 0) { - DEBUG(10,("receive_smb_raw: length < 0!\n")); + status = read_smb_length_return_keepalive(fd,buffer,timeout,&len); - /* - * Correct fix. smb_read_error may have already been - * set. Only set it here if not already set. Global - * variables still suck :-). JRA. - */ + if (!NT_STATUS_IS_OK(status)) { + DEBUG(10, ("receive_smb_raw: %s!\n", nt_errstr(status))); + + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(pre, SMB_READ_EOF); + return -1; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(pre, SMB_READ_TIMEOUT); + return -1; + } - cond_set_smb_read_error(pre,SMB_READ_ERROR); + set_smb_read_error(pre, SMB_READ_ERROR); return -1; } -- cgit From 9f6e983d0b67b64daf27dab130348d3491bad4ac Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 21:31:40 +0100 Subject: Convert read_smb_length to return NTSTATUS (This used to be commit 5750c3a51b4ddac635a98195d1621b24f91bad3f) --- source3/lib/util_sock.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index f62b20b6fc..32dd2bd8a8 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1174,31 +1174,18 @@ NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf, Timeout is in milliseconds. ****************************************************************************/ -ssize_t read_smb_length(int fd, char *inbuf, unsigned int timeout, enum smb_read_errors *pre) +NTSTATUS read_smb_length(int fd, char *inbuf, unsigned int timeout, + size_t *len) { - size_t len; uint8_t msgtype = SMBkeepalive; - set_smb_read_error(pre, SMB_READ_OK); - while (msgtype == SMBkeepalive) { NTSTATUS status; status = read_smb_length_return_keepalive(fd, inbuf, timeout, - &len); + len); if (!NT_STATUS_IS_OK(status)) { - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(pre, SMB_READ_EOF); - return -1; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(pre, SMB_READ_TIMEOUT); - return -1; - } - - set_smb_read_error(pre, SMB_READ_ERROR); - return -1; + return status; } msgtype = CVAL(inbuf, 0); @@ -1207,7 +1194,7 @@ ssize_t read_smb_length(int fd, char *inbuf, unsigned int timeout, enum smb_read DEBUG(10,("read_smb_length: got smb length of %lu\n", (unsigned long)len)); - return len; + return NT_STATUS_OK; } /**************************************************************************** -- cgit From 5e43eeb1b6eef7ea7a88ffc51a0a0535e9bd8023 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 23:41:48 +0100 Subject: Get rid of read_socket_with_timeout (This used to be commit f9c8ac83ff42137d2101d3bb17e5dcc3c3d70a8f) --- source3/lib/util_sock.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index 32dd2bd8a8..d0d321ee39 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1042,21 +1042,20 @@ NTSTATUS read_socket_with_timeout_ntstatus(int fd, char *buf, return NT_STATUS_OK; } -ssize_t read_socket_with_timeout(int fd, char *buf, - size_t mincnt, size_t maxcnt, - unsigned int time_out, - enum smb_read_errors *pre) +/**************************************************************************** + Read data from the client, reading exactly N bytes. +****************************************************************************/ + +ssize_t read_data(int fd,char *buffer,size_t N, enum smb_read_errors *pre) { NTSTATUS status; - size_t size_ret; set_smb_read_error(pre, SMB_READ_OK); - status = read_socket_with_timeout_ntstatus(fd, buf, mincnt, maxcnt, - time_out, &size_ret); + status = read_socket_with_timeout_ntstatus(fd, buffer, N, N, 0, NULL); if (NT_STATUS_IS_OK(status)) { - return size_ret; + return N; } if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { @@ -1073,15 +1072,6 @@ ssize_t read_socket_with_timeout(int fd, char *buf, return -1; } -/**************************************************************************** - Read data from the client, reading exactly N bytes. -****************************************************************************/ - -ssize_t read_data(int fd,char *buffer,size_t N, enum smb_read_errors *pre) -{ - return read_socket_with_timeout(fd, buffer, N, N, 0, pre); -} - /**************************************************************************** Write data to a fd. ****************************************************************************/ @@ -1214,7 +1204,6 @@ ssize_t receive_smb_raw(int fd, enum smb_read_errors *pre) { size_t len; - ssize_t ret; NTSTATUS status; set_smb_read_error(pre,SMB_READ_OK); @@ -1264,11 +1253,23 @@ ssize_t receive_smb_raw(int fd, len = MIN(len,maxlen); } - ret = read_socket_with_timeout(fd, buffer+4, len, len, timeout, - pre); + set_smb_read_error(pre, SMB_READ_OK); - if (ret != len) { - cond_set_smb_read_error(pre,SMB_READ_ERROR); + status = read_socket_with_timeout_ntstatus( + fd, buffer+4, len, len, timeout, &len); + + if (!NT_STATUS_IS_OK(status)) { + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(pre, SMB_READ_EOF); + return -1; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(pre, SMB_READ_TIMEOUT); + return -1; + } + + set_smb_read_error(pre, SMB_READ_ERROR); return -1; } -- cgit From 6ddfa6ae7734ffdd26ac38478c27cc9d646ddadd Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 23:43:50 +0100 Subject: read_socket_with_timeout_ntstatus->read_socket_with_timeout (This used to be commit 90554799afa42855c3e7b87dc632e67f0952f988) --- source3/lib/util_sock.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index d0d321ee39..fcea5d8be6 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -913,10 +913,10 @@ ssize_t read_udp_v4_socket(int fd, time_out = timeout in milliseconds ****************************************************************************/ -NTSTATUS read_socket_with_timeout_ntstatus(int fd, char *buf, - size_t mincnt, size_t maxcnt, - unsigned int time_out, - size_t *size_ret) +NTSTATUS read_socket_with_timeout(int fd, char *buf, + size_t mincnt, size_t maxcnt, + unsigned int time_out, + size_t *size_ret) { fd_set fds; int selrtn; @@ -1052,7 +1052,7 @@ ssize_t read_data(int fd,char *buffer,size_t N, enum smb_read_errors *pre) set_smb_read_error(pre, SMB_READ_OK); - status = read_socket_with_timeout_ntstatus(fd, buffer, N, N, 0, NULL); + status = read_socket_with_timeout(fd, buffer, N, N, 0, NULL); if (NT_STATUS_IS_OK(status)) { return N; @@ -1138,8 +1138,7 @@ NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf, int msg_type; NTSTATUS status; - status = read_socket_with_timeout_ntstatus(fd, inbuf, 4, 4, timeout, - NULL); + status = read_socket_with_timeout(fd, inbuf, 4, 4, timeout, NULL); if (!NT_STATUS_IS_OK(status)) { return status; @@ -1255,7 +1254,7 @@ ssize_t receive_smb_raw(int fd, set_smb_read_error(pre, SMB_READ_OK); - status = read_socket_with_timeout_ntstatus( + status = read_socket_with_timeout( fd, buffer+4, len, len, timeout, &len); if (!NT_STATUS_IS_OK(status)) { -- cgit From 88c27f83d449fa20cba47cbf0a5dbaedc99859d8 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 23:54:22 +0100 Subject: Convert receive_smb_raw to NTSTATUS (This used to be commit ba771bd858602452a9e58c3aab1336f2ac8a25ef) --- source3/lib/util_sock.c | 51 +++++++------------------------------------------ 1 file changed, 7 insertions(+), 44 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index fcea5d8be6..ede2cdae71 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1196,34 +1196,17 @@ NTSTATUS read_smb_length(int fd, char *inbuf, unsigned int timeout, Doesn't check the MAC on signed packets. ****************************************************************************/ -ssize_t receive_smb_raw(int fd, - char *buffer, - unsigned int timeout, - size_t maxlen, - enum smb_read_errors *pre) +NTSTATUS receive_smb_raw(int fd, char *buffer, unsigned int timeout, + size_t maxlen, size_t *p_len) { size_t len; NTSTATUS status; - set_smb_read_error(pre,SMB_READ_OK); - status = read_smb_length_return_keepalive(fd,buffer,timeout,&len); if (!NT_STATUS_IS_OK(status)) { DEBUG(10, ("receive_smb_raw: %s!\n", nt_errstr(status))); - - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(pre, SMB_READ_EOF); - return -1; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(pre, SMB_READ_TIMEOUT); - return -1; - } - - set_smb_read_error(pre, SMB_READ_ERROR); - return -1; + return status; } /* @@ -1235,15 +1218,7 @@ ssize_t receive_smb_raw(int fd, DEBUG(0,("Invalid packet length! (%lu bytes).\n", (unsigned long)len)); if (len > BUFFER_SIZE + (SAFETY_MARGIN/2)) { - - /* - * Correct fix. smb_read_error may have already been - * set. Only set it here if not already set. Global - * variables still suck :-). JRA. - */ - - cond_set_smb_read_error(pre,SMB_READ_ERROR); - return -1; + return NT_STATUS_INVALID_PARAMETER; } } @@ -1252,24 +1227,11 @@ ssize_t receive_smb_raw(int fd, len = MIN(len,maxlen); } - set_smb_read_error(pre, SMB_READ_OK); - status = read_socket_with_timeout( fd, buffer+4, len, len, timeout, &len); if (!NT_STATUS_IS_OK(status)) { - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(pre, SMB_READ_EOF); - return -1; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(pre, SMB_READ_TIMEOUT); - return -1; - } - - set_smb_read_error(pre, SMB_READ_ERROR); - return -1; + return status; } /* not all of samba3 properly checks for packet-termination @@ -1278,7 +1240,8 @@ ssize_t receive_smb_raw(int fd, SSVAL(buffer+4,len, 0); } - return len; + *p_len = len; + return NT_STATUS_OK; } /**************************************************************************** -- cgit From b42a5d68a3ffd88fd60c64b6a75fe2d687d9c92d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Jan 2008 10:39:21 +0100 Subject: Convert read_data() to NTSTATUS (This used to be commit af40b71023f8c4a2133d996ea698c72b97624043) --- source3/lib/util_sock.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index ede2cdae71..25d539cace 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1046,30 +1046,9 @@ NTSTATUS read_socket_with_timeout(int fd, char *buf, Read data from the client, reading exactly N bytes. ****************************************************************************/ -ssize_t read_data(int fd,char *buffer,size_t N, enum smb_read_errors *pre) +NTSTATUS read_data(int fd, char *buffer, size_t N) { - NTSTATUS status; - - set_smb_read_error(pre, SMB_READ_OK); - - status = read_socket_with_timeout(fd, buffer, N, N, 0, NULL); - - if (NT_STATUS_IS_OK(status)) { - return N; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(pre, SMB_READ_EOF); - return -1; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(pre, SMB_READ_TIMEOUT); - return -1; - } - - set_smb_read_error(pre, SMB_READ_ERROR); - return -1; + return read_socket_with_timeout(fd, buffer, N, N, 0, NULL); } /**************************************************************************** -- cgit From 174100c30997e6ae70492528da998e30c1bfce60 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Mon, 4 Feb 2008 16:16:59 +0100 Subject: popt: Use SMB_CONF_PATH environment var if no other configfile is set. Now --configfile (or -s) will have precedence, if that's not given SMB_CONF_PATH is checked, otherwise the $(CONFIGDIR)/smb.conf default value is used. Thanks to Michael for his comments. (This used to be commit 92a9c6c56fa90aead3b7f4a07bf4f3973ba23555) --- source3/lib/popt_common.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 5a9d39d181..7f7d23fa00 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -71,10 +71,19 @@ static void popt_common_callback(poptContext con, } if (reason == POPT_CALLBACK_REASON_POST) { - if (!PrintSambaVersionString) return; - printf( "Version %s\n", SAMBA_VERSION_STRING); - exit(0); + if (PrintSambaVersionString) { + printf( "Version %s\n", SAMBA_VERSION_STRING); + exit(0); + } + + if (is_default_dyn_CONFIGFILE()) { + if(getenv("SMB_CONF_PATH")) { + set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH")); + } + } + + /* Further 'every Samba program must do this' hooks here. */ return; } -- cgit From 3955801298bbcf69afe01c212d5e8ac9812a5dcf Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 4 Feb 2008 18:49:19 +0100 Subject: Simplify str_list_xxx (This used to be commit d471dd4adb79d480c89436b2ed98f9ec6812aaa0) --- source3/lib/util_str.c | 158 +++++++++++++++---------------------------------- 1 file changed, 47 insertions(+), 111 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index bcb9197141..05be7ca1e4 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -1841,95 +1841,64 @@ int fstr_sprintf(fstring s, const char *fmt, ...) #define S_LIST_ABS 16 /* List Allocation Block Size */ -static char **str_list_make_internal(TALLOC_CTX *mem_ctx, - const char *string, - const char *sep) +static char **str_list_make_internal(TALLOC_CTX *mem_ctx, const char *string, + const char *sep) { - char **list, **rlist; + char **list; const char *str; char *s; int num, lsize; char *tok; - TALLOC_CTX *frame = NULL; if (!string || !*string) return NULL; - if (mem_ctx) { - s = talloc_strdup(mem_ctx, string); - } else { - s = SMB_STRDUP(string); + + list = TALLOC_ARRAY(mem_ctx, char *, S_LIST_ABS+1); + if (list == NULL) { + return NULL; } - if (!s) { + lsize = S_LIST_ABS; + + s = talloc_strdup(list, string); + if (s == NULL) { DEBUG(0,("str_list_make: Unable to allocate memory")); + TALLOC_FREE(list); return NULL; } if (!sep) sep = LIST_SEP; - num = lsize = 0; - list = NULL; - + num = 0; str = s; - frame = talloc_stackframe(); - while (next_token_talloc(frame, &str, &tok, sep)) { + + while (next_token_talloc(list, &str, &tok, sep)) { + if (num == lsize) { + char **tmp; + lsize += S_LIST_ABS; - if (mem_ctx) { - rlist = TALLOC_REALLOC_ARRAY(mem_ctx, list, - char *, lsize +1); - } else { - /* We need to keep the old list on - * error so we can free the elements - if the realloc fails. */ - rlist =SMB_REALLOC_ARRAY_KEEP_OLD_ON_ERROR(list, - char *, lsize +1); - } - if (!rlist) { + + tmp = TALLOC_REALLOC_ARRAY(mem_ctx, list, char *, + lsize + 1); + if (tmp == NULL) { DEBUG(0,("str_list_make: " "Unable to allocate memory")); - str_list_free(&list); - if (mem_ctx) { - TALLOC_FREE(s); - } else { - SAFE_FREE(s); - } - TALLOC_FREE(frame); + TALLOC_FREE(list); return NULL; - } else { - list = rlist; } - memset (&list[num], 0, - ((sizeof(char**)) * (S_LIST_ABS +1))); - } - if (mem_ctx) { - list[num] = talloc_strdup(mem_ctx, tok); - } else { - list[num] = SMB_STRDUP(tok); - } + list = tmp; - if (!list[num]) { - DEBUG(0,("str_list_make: Unable to allocate memory")); - str_list_free(&list); - if (mem_ctx) { - TALLOC_FREE(s); - } else { - SAFE_FREE(s); - } - TALLOC_FREE(frame); - return NULL; + memset (&list[num], 0, + ((sizeof(char**)) * (S_LIST_ABS +1))); } - num++; + list[num] = tok; + num += 1; } - TALLOC_FREE(frame); - - if (mem_ctx) { - TALLOC_FREE(s); - } else { - SAFE_FREE(s); - } + list[num] = NULL; + TALLOC_FREE(s); return list; } @@ -1947,43 +1916,31 @@ char **str_list_make(const char *string, const char *sep) bool str_list_copy(char ***dest, const char **src) { - char **list, **rlist; - int num, lsize; + char **list; + int i, num; *dest = NULL; if (!src) return false; - num = lsize = 0; - list = NULL; + num = 0; + while (src[num] != NULL) { + num += 1; + } - while (src[num]) { - if (num == lsize) { - lsize += S_LIST_ABS; - rlist = SMB_REALLOC_ARRAY_KEEP_OLD_ON_ERROR(list, - char *, lsize +1); - if (!rlist) { - DEBUG(0,("str_list_copy: " - "Unable to re-allocate memory")); - str_list_free(&list); - return false; - } else { - list = rlist; - } - memset (&list[num], 0, - ((sizeof(char **)) * (S_LIST_ABS +1))); - } + list = TALLOC_ARRAY(NULL, char *, num+1); + if (list == NULL) { + return false; + } - list[num] = SMB_STRDUP(src[num]); - if (!list[num]) { - DEBUG(0,("str_list_copy: Unable to allocate memory")); - str_list_free(&list); + for (i=0; i Date: Mon, 4 Feb 2008 20:57:35 +0100 Subject: Always pass a TALLOC_CTX to str_list_make and str_list_copy (This used to be commit e2c9fc4cf5f0ff725330fa44f53782db65fca37e) --- source3/lib/debug.c | 6 +++--- source3/lib/util_str.c | 13 +++---------- 2 files changed, 6 insertions(+), 13 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 51bb0d7541..9ff267b607 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -460,14 +460,14 @@ bool debug_parse_levels(const char *params_str) if (AllowDebugChange == False) return True; - params = str_list_make(params_str, NULL); + params = str_list_make(talloc_tos(), params_str, NULL); if (debug_parse_params(params)) { debug_dump_status(5); - str_list_free(¶ms); + TALLOC_FREE(params); return True; } else { - str_list_free(¶ms); + TALLOC_FREE(params); return False; } } diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 05be7ca1e4..fb3392f041 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -1902,19 +1902,12 @@ static char **str_list_make_internal(TALLOC_CTX *mem_ctx, const char *string, return list; } -char **str_list_make_talloc(TALLOC_CTX *mem_ctx, - const char *string, - const char *sep) +char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep) { return str_list_make_internal(mem_ctx, string, sep); } -char **str_list_make(const char *string, const char *sep) -{ - return str_list_make_internal(NULL, string, sep); -} - -bool str_list_copy(char ***dest, const char **src) +bool str_list_copy(TALLOC_CTX *mem_ctx, char ***dest, const char **src) { char **list; int i, num; @@ -1928,7 +1921,7 @@ bool str_list_copy(char ***dest, const char **src) num += 1; } - list = TALLOC_ARRAY(NULL, char *, num+1); + list = TALLOC_ARRAY(mem_ctx, char *, num+1); if (list == NULL) { return false; } -- cgit From b361956942618ec2f7c2efc60cb190858adbc516 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 4 Feb 2008 21:05:41 +0100 Subject: str_list_free is not needed anymore (This used to be commit feddc1447d585fd108d22a36bccc576fa81197ef) --- source3/lib/util_str.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index fb3392f041..93ecad728d 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -1841,8 +1841,7 @@ int fstr_sprintf(fstring s, const char *fmt, ...) #define S_LIST_ABS 16 /* List Allocation Block Size */ -static char **str_list_make_internal(TALLOC_CTX *mem_ctx, const char *string, - const char *sep) +char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep) { char **list; const char *str; @@ -1902,11 +1901,6 @@ static char **str_list_make_internal(TALLOC_CTX *mem_ctx, const char *string, return list; } -char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep) -{ - return str_list_make_internal(mem_ctx, string, sep); -} - bool str_list_copy(TALLOC_CTX *mem_ctx, char ***dest, const char **src) { char **list; @@ -1960,16 +1954,6 @@ bool str_list_compare(char **list1, char **list2) return true; } -void str_list_free_talloc(TALLOC_CTX *mem_ctx, char ***list) -{ - TALLOC_FREE(*list); -} - -void str_list_free(char ***list) -{ - TALLOC_FREE(*list); -} - /****************************************************************************** *****************************************************************************/ -- cgit From abe2fd76977d472b044f30b522aa9c114db089fc Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 5 Feb 2008 22:17:20 +0100 Subject: Fix a debug message (This used to be commit 24aa3518aef7e36fde03d58f36487cbf29c027c9) --- source3/lib/util_sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index 25d539cace..71d48d6053 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1130,7 +1130,7 @@ NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf, DEBUG(5,("Got keepalive packet\n")); } - DEBUG(10,("got smb length of %lu\n",(unsigned long)len)); + DEBUG(10,("got smb length of %lu\n",(unsigned long)(*len))); return NT_STATUS_OK; } -- cgit