[SCM] Samba Shared Repository - branch master updated
Stefan Metzmacher
metze at samba.org
Sat Oct 23 01:36:01 MDT 2010
The branch, master has been updated
via c320c1a lib/util: Add tevent WERROR wrappers
via 79c6572 tsocket: let tstream_inet_tcp_connect_recv() optionally return the used local address
via d2c6536 tsocket: ask the kernel for the specific local address after a tcp connect
via 96601ca lib/replace: use snprintf() in test code to avoid warnings in the IBM-Checker
via d65896c lib/replace: fix rep_strtoull() prototype
from 272feb7 Revert "Wrap security_token_has_privilege() with a check for lp_enable_privileges(). Needed"
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit c320c1ab989cf809da6effb4a47e8355c94357f5
Author: Kai Blin <kai at samba.org>
Date: Fri Oct 22 16:40:38 2010 +0200
lib/util: Add tevent WERROR wrappers
Signed-off-by: Stefan Metzmacher <metze at samba.org>
Autobuild-User: Stefan Metzmacher <metze at samba.org>
Autobuild-Date: Sat Oct 23 07:35:28 UTC 2010 on sn-devel-104
commit 79c6572256a01279d9e4f0b436d334f4fd739866
Author: Stefan Metzmacher <metze at samba.org>
Date: Thu Oct 21 23:31:41 2010 +0200
tsocket: let tstream_inet_tcp_connect_recv() optionally return the used local address
tstream_inet_tcp_connect_send() usually only gets no local port number
and it may use the wildcard address '0.0.0.0' or '::'.
tstream_inet_tcp_connect_recv() provides the used local address and port
which are used on the wire.
metze
commit d2c653629cdc3df8549c6faabfcdbe3045cd013c
Author: Stefan Metzmacher <metze at samba.org>
Date: Thu Oct 21 23:26:14 2010 +0200
tsocket: ask the kernel for the specific local address after a tcp connect
metze
commit 96601cab1cb0bd47051cd9fb30f0464c0734cb8a
Author: Stefan Metzmacher <metze at samba.org>
Date: Fri Oct 22 14:41:47 2010 +0200
lib/replace: use snprintf() in test code to avoid warnings in the IBM-Checker
metze
commit d65896cc3c5e67508e295e6d64193210e958971c
Author: Stefan Metzmacher <metze at samba.org>
Date: Fri Oct 22 08:44:29 2010 +0200
lib/replace: fix rep_strtoull() prototype
metze
-----------------------------------------------------------------------
Summary of changes:
lib/replace/replace.c | 2 +-
lib/replace/replace.h | 4 +-
lib/replace/test/os2_delete.c | 4 +-
lib/tsocket/tsocket.h | 13 ++++--
lib/tsocket/tsocket_bsd.c | 58 +++++++++++++++++++++-
lib/util/{tevent_ntstatus.c => tevent_werror.c} | 44 +++++++++--------
lib/util/{tevent_ntstatus.h => tevent_werror.h} | 30 ++++++------
lib/util/wscript_build | 4 +-
source3/Makefile.in | 1 +
source3/wscript_build | 1 +
source4/libcli/wrepl/winsrepl.c | 2 +-
11 files changed, 112 insertions(+), 51 deletions(-)
copy lib/util/{tevent_ntstatus.c => tevent_werror.c} (59%)
copy lib/util/{tevent_ntstatus.h => tevent_werror.h} (55%)
Changeset truncated at 500 lines:
diff --git a/lib/replace/replace.c b/lib/replace/replace.c
index 5ecda92..d9a96ff 100644
--- a/lib/replace/replace.c
+++ b/lib/replace/replace.c
@@ -558,7 +558,7 @@ unsigned long long int rep_strtoull(const char *str, char **endptr, int base)
#else
#ifdef HAVE_BSD_STRTOLL
#ifdef HAVE_STRTOUQ
-long long int rep_strtoull(const char *str, char **endptr, int base)
+unsigned long long int rep_strtoull(const char *str, char **endptr, int base)
{
unsigned long long int nb = strtouq(str, endptr, base);
/* In linux EINVAL is only returned if base is not ok */
diff --git a/lib/replace/replace.h b/lib/replace/replace.h
index 8f820a9..15ec80a 100644
--- a/lib/replace/replace.h
+++ b/lib/replace/replace.h
@@ -299,8 +299,8 @@ long long int rep_strtoll(const char *str, char **endptr, int base);
#define strtoull rep_strtoull
unsigned long long int rep_strtoull(const char *str, char **endptr, int base);
#else
-#ifdef HAVE_BSD_STRTOLL
-long long int rep_strtoull(const char *str, char **endptr, int base);
+#ifdef HAVE_BSD_STRTOLL /* yes, it's not HAVE_BSD_STRTOULL */
+unsigned long long int rep_strtoull(const char *str, char **endptr, int base);
#define strtoull rep_strtoull
#endif
#endif
diff --git a/lib/replace/test/os2_delete.c b/lib/replace/test/os2_delete.c
index 8b52837..9d760bf 100644
--- a/lib/replace/test/os2_delete.c
+++ b/lib/replace/test/os2_delete.c
@@ -46,7 +46,7 @@ static void create_files(void)
for (i=0;i<NUM_FILES;i++) {
char fname[40];
int fd;
- sprintf(fname, TESTDIR "/test%u.txt", i);
+ snprintf(fname, sizeof(fname), TESTDIR "/test%u.txt", i);
fd = open(fname, O_CREAT|O_RDWR, 0600);
if (fd < 0) {
FAILED("open");
@@ -79,7 +79,7 @@ static int os2_delete(DIR *d)
/* delete the first few */
for (j=0; j<MIN(i, DELETE_SIZE); j++) {
char fname[40];
- sprintf(fname, TESTDIR "/%s", names[j]);
+ snprintf(fname, sizeof(fname), TESTDIR "/%s", names[j]);
unlink(fname) == 0 || FAILED("unlink");
}
diff --git a/lib/tsocket/tsocket.h b/lib/tsocket/tsocket.h
index 3dd9666..3aca536 100644
--- a/lib/tsocket/tsocket.h
+++ b/lib/tsocket/tsocket.h
@@ -724,23 +724,28 @@ struct tevent_req *tstream_inet_tcp_connect_send(TALLOC_CTX *mem_ctx,
*
* @param[in] mem_ctx The talloc memory context to use.
*
- * @param[in] stream A tstream_context pointer to setup the tcp communication
+ * @param[out] stream A tstream_context pointer to setup the tcp communication
* on. This function will allocate the memory.
*
+ * @param[out] local The real 'inet' tsocket_address of the local endpoint.
+ * This parameter is optional and can be NULL.
+ *
* @return 0 on success, -1 on error with perrno set.
*/
int tstream_inet_tcp_connect_recv(struct tevent_req *req,
int *perrno,
TALLOC_CTX *mem_ctx,
- struct tstream_context **stream);
+ struct tstream_context **stream,
+ struct tsocket_address **local)
#else
int _tstream_inet_tcp_connect_recv(struct tevent_req *req,
int *perrno,
TALLOC_CTX *mem_ctx,
struct tstream_context **stream,
+ struct tsocket_address **local,
const char *location);
-#define tstream_inet_tcp_connect_recv(req, perrno, mem_ctx, stream) \
- _tstream_inet_tcp_connect_recv(req, perrno, mem_ctx, stream, \
+#define tstream_inet_tcp_connect_recv(req, perrno, mem_ctx, stream, local) \
+ _tstream_inet_tcp_connect_recv(req, perrno, mem_ctx, stream, local, \
__location__)
#endif
diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c
index bc7cfe3..019bf42 100644
--- a/lib/tsocket/tsocket_bsd.c
+++ b/lib/tsocket/tsocket_bsd.c
@@ -1973,6 +1973,7 @@ struct tstream_bsd_connect_state {
int fd;
struct tevent_fd *fde;
struct tstream_conext *stream;
+ struct tsocket_address *local;
};
static int tstream_bsd_connect_destructor(struct tstream_bsd_connect_state *state)
@@ -1991,7 +1992,7 @@ static void tstream_bsd_connect_fde_handler(struct tevent_context *ev,
uint16_t flags,
void *private_data);
-static struct tevent_req * tstream_bsd_connect_send(TALLOC_CTX *mem_ctx,
+static struct tevent_req *tstream_bsd_connect_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
int sys_errno,
const struct tsocket_address *local,
@@ -2002,6 +2003,7 @@ static struct tevent_req * tstream_bsd_connect_send(TALLOC_CTX *mem_ctx,
struct tsocket_address_bsd *lbsda =
talloc_get_type_abort(local->private_data,
struct tsocket_address_bsd);
+ struct tsocket_address_bsd *lrbsda = NULL;
struct tsocket_address_bsd *rbsda =
talloc_get_type_abort(remote->private_data,
struct tsocket_address_bsd);
@@ -2081,6 +2083,20 @@ static struct tevent_req * tstream_bsd_connect_send(TALLOC_CTX *mem_ctx,
}
}
+ if (is_inet) {
+ state->local = tsocket_address_create(state,
+ &tsocket_address_bsd_ops,
+ &lrbsda,
+ struct tsocket_address_bsd,
+ __location__ "bsd_connect");
+ if (tevent_req_nomem(state->local, req)) {
+ goto post;
+ }
+
+ ZERO_STRUCTP(lrbsda);
+ lrbsda->sa_socklen = sizeof(lrbsda->u.ss);
+ }
+
state->fd = socket(sa_fam, SOCK_STREAM, 0);
if (state->fd == -1) {
tevent_req_error(req, errno);
@@ -2140,6 +2156,17 @@ static struct tevent_req * tstream_bsd_connect_send(TALLOC_CTX *mem_ctx,
goto post;
}
+ if (!state->local) {
+ tevent_req_done(req);
+ goto post;
+ }
+
+ ret = getsockname(state->fd, &lrbsda->u.sa, &lrbsda->sa_socklen);
+ if (ret == -1) {
+ tevent_req_error(req, errno);
+ goto post;
+ }
+
tevent_req_done(req);
goto post;
@@ -2169,6 +2196,7 @@ static void tstream_bsd_connect_fde_handler(struct tevent_context *ev,
struct tevent_req);
struct tstream_bsd_connect_state *state = tevent_req_data(req,
struct tstream_bsd_connect_state);
+ struct tsocket_address_bsd *lrbsda = NULL;
int ret;
int error=0;
socklen_t len = sizeof(error);
@@ -2191,6 +2219,20 @@ static void tstream_bsd_connect_fde_handler(struct tevent_context *ev,
return;
}
+ if (!state->local) {
+ tevent_req_done(req);
+ return;
+ }
+
+ lrbsda = talloc_get_type_abort(state->local->private_data,
+ struct tsocket_address_bsd);
+
+ ret = getsockname(state->fd, &lrbsda->u.sa, &lrbsda->sa_socklen);
+ if (ret == -1) {
+ tevent_req_error(req, errno);
+ return;
+ }
+
tevent_req_done(req);
}
@@ -2198,6 +2240,7 @@ static int tstream_bsd_connect_recv(struct tevent_req *req,
int *perrno,
TALLOC_CTX *mem_ctx,
struct tstream_context **stream,
+ struct tsocket_address **local,
const char *location)
{
struct tstream_bsd_connect_state *state = tevent_req_data(req,
@@ -2216,6 +2259,10 @@ static int tstream_bsd_connect_recv(struct tevent_req *req,
}
TALLOC_FREE(state->fde);
state->fd = -1;
+
+ if (local) {
+ *local = talloc_move(mem_ctx, &state->local);
+ }
}
done:
@@ -2255,9 +2302,12 @@ int _tstream_inet_tcp_connect_recv(struct tevent_req *req,
int *perrno,
TALLOC_CTX *mem_ctx,
struct tstream_context **stream,
+ struct tsocket_address **local,
const char *location)
{
- return tstream_bsd_connect_recv(req, perrno, mem_ctx, stream, location);
+ return tstream_bsd_connect_recv(req, perrno,
+ mem_ctx, stream, local,
+ location);
}
struct tevent_req * tstream_unix_connect_send(TALLOC_CTX *mem_ctx,
@@ -2290,7 +2340,9 @@ int _tstream_unix_connect_recv(struct tevent_req *req,
struct tstream_context **stream,
const char *location)
{
- return tstream_bsd_connect_recv(req, perrno, mem_ctx, stream, location);
+ return tstream_bsd_connect_recv(req, perrno,
+ mem_ctx, stream, NULL,
+ location);
}
int _tstream_unix_socketpair(TALLOC_CTX *mem_ctx1,
diff --git a/lib/util/tevent_ntstatus.c b/lib/util/tevent_werror.c
similarity index 59%
copy from lib/util/tevent_ntstatus.c
copy to lib/util/tevent_werror.c
index c4dd074..d8956b3 100644
--- a/lib/util/tevent_ntstatus.c
+++ b/lib/util/tevent_werror.c
@@ -1,7 +1,7 @@
/*
Unix SMB/CIFS implementation.
- Wrap unix errno around tevent_req
- Copyright (C) Volker Lendecke 2009
+ Wrap win32 errors around tevent_req
+ Copyright (C) Kai Blin 2010
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
@@ -18,17 +18,17 @@
*/
#include "../replace/replace.h"
-#include "tevent_ntstatus.h"
+#include "tevent_werror.h"
-bool _tevent_req_nterror(struct tevent_req *req,
- NTSTATUS status,
- const char *location)
+bool _tevent_req_werror(struct tevent_req *req,
+ WERROR werror,
+ const char *location)
{
- return _tevent_req_error(req, NT_STATUS_V(status),
+ return _tevent_req_error(req, W_ERROR_V(werror),
location);
}
-bool tevent_req_is_nterror(struct tevent_req *req, NTSTATUS *status)
+bool tevent_req_is_werror(struct tevent_req *req, WERROR *error)
{
enum tevent_req_state state;
uint64_t err;
@@ -38,41 +38,43 @@ bool tevent_req_is_nterror(struct tevent_req *req, NTSTATUS *status)
}
switch (state) {
case TEVENT_REQ_TIMED_OUT:
- *status = NT_STATUS_IO_TIMEOUT;
+ *error = WERR_TIMEOUT;
break;
case TEVENT_REQ_NO_MEMORY:
- *status = NT_STATUS_NO_MEMORY;
+ *error = WERR_NOMEM;
break;
case TEVENT_REQ_USER_ERROR:
- *status = NT_STATUS(err);
+ *error = W_ERROR(err);
break;
default:
- *status = NT_STATUS_INTERNAL_ERROR;
+ *error = WERR_INTERNAL_ERROR;
break;
}
return true;
}
-NTSTATUS tevent_req_simple_recv_ntstatus(struct tevent_req *req)
+WERROR tevent_req_simple_recv_werror(struct tevent_req *req)
{
- NTSTATUS status;
+ WERROR werror;
- if (tevent_req_is_nterror(req, &status)) {
- return status;
+ if (tevent_req_is_werror(req, &werror)) {
+ tevent_req_received(req);
+ return werror;
}
- return NT_STATUS_OK;
+ tevent_req_received(req);
+ return WERR_OK;
}
-void tevent_req_simple_finish_ntstatus(struct tevent_req *subreq,
- NTSTATUS subreq_status)
+void tevent_req_simple_finish_werror(struct tevent_req *subreq,
+ WERROR subreq_error)
{
struct tevent_req *req = tevent_req_callback_data(
subreq, struct tevent_req);
TALLOC_FREE(subreq);
- if (!NT_STATUS_IS_OK(subreq_status)) {
- tevent_req_nterror(req, subreq_status);
+ if (!W_ERROR_IS_OK(subreq_error)) {
+ tevent_req_werror(req, subreq_error);
return;
}
tevent_req_done(req);
diff --git a/lib/util/tevent_ntstatus.h b/lib/util/tevent_werror.h
similarity index 55%
copy from lib/util/tevent_ntstatus.h
copy to lib/util/tevent_werror.h
index 4ac9243..0e24382 100644
--- a/lib/util/tevent_ntstatus.h
+++ b/lib/util/tevent_werror.h
@@ -1,7 +1,7 @@
/*
Unix SMB/CIFS implementation.
- Wrap unix errno around tevent_req
- Copyright (C) Volker Lendecke 2009
+ Wrap win32 errors around tevent_req
+ Copyright (C) Kai Blin 2010
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
@@ -17,27 +17,27 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _TEVENT_NTSTATUS_H
-#define _TEVENT_NTSTATUS_H
+#ifndef _TEVENT_WERROR_H
+#define _TEVENT_WERROR_H
#include <stdint.h>
#include <stdbool.h>
-#include "../libcli/util/ntstatus.h"
+#include "../libcli/util/werror.h"
#include <tevent.h>
-bool _tevent_req_nterror(struct tevent_req *req,
- NTSTATUS status,
- const char *location);
-#define tevent_req_nterror(req, status) \
- _tevent_req_nterror(req, status, __location__)
-bool tevent_req_is_nterror(struct tevent_req *req, NTSTATUS *pstatus);
-NTSTATUS tevent_req_simple_recv_ntstatus(struct tevent_req *req);
+bool _tevent_req_werror(struct tevent_req *req,
+ WERROR werror,
+ const char *location);
+#define tevent_req_werror(req, werror) \
+ _tevent_req_werror(req, werror, __location__)
+bool tevent_req_is_werror(struct tevent_req *req, WERROR *error);
+WERROR tevent_req_simple_recv_werror(struct tevent_req *req);
/*
- * Helper routine to pass the subreq_ntstatus to the req embedded in
+ * Helper routine to pass the subreq_werror to the req embedded in
* tevent_req_callback_data(subreq), which will be freed.
*/
-void tevent_req_simple_finish_ntstatus(struct tevent_req *subreq,
- NTSTATUS subreq_status);
+void tevent_req_simple_finish_werror(struct tevent_req *subreq,
+ WERROR subreq_error);
#endif
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index 9162bcb..e1030c8 100644
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -41,10 +41,10 @@ bld.SAMBA_SUBSYSTEM('UTIL_TDB',
)
bld.SAMBA_SUBSYSTEM('UTIL_TEVENT',
- source='tevent_unix.c tevent_ntstatus.c',
+ source='tevent_unix.c tevent_ntstatus.c tevent_werror.c',
local_include=False,
public_deps='tevent',
- public_headers='tevent_ntstatus.h tevent_unix.h',
+ public_headers='tevent_ntstatus.h tevent_unix.h tevent_werror.h',
header_path=[ ('*', 'util') ],
)
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 5d390de..b287784 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -429,6 +429,7 @@ UTIL_OBJ = ../lib/util/rbtree.o ../lib/util/signal.o ../lib/util/time.o \
../lib/util/genrand.o ../lib/util/util_net.o \
../lib/util/become_daemon.o ../lib/util/system.o \
../lib/util/tevent_unix.o ../lib/util/tevent_ntstatus.o \
+ ../lib/util/tevent_werror.o \
../lib/util/smb_threads.o ../lib/util/util_id.o \
../lib/util/blocking.o ../lib/util/rfc1738.o \
../lib/util/select.o
diff --git a/source3/wscript_build b/source3/wscript_build
index 7516f7a..9ee2cbc 100644
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -152,6 +152,7 @@ UTIL_SRC = '''../lib/util/rbtree.c ../lib/util/signal.c ../lib/util/time.c
../lib/util/genrand.c ../lib/util/util_net.c
../lib/util/become_daemon.c ../lib/util/system.c
../lib/util/tevent_unix.c ../lib/util/tevent_ntstatus.c
+ ../lib/util/tevent_werror.c
../lib/util/smb_threads.c ../lib/util/util_id.c
../lib/util/blocking.c ../lib/util/rfc1738.c
../lib/util/select.c'''
diff --git a/source4/libcli/wrepl/winsrepl.c b/source4/libcli/wrepl/winsrepl.c
index 83da217..842a351 100644
--- a/source4/libcli/wrepl/winsrepl.c
+++ b/source4/libcli/wrepl/winsrepl.c
@@ -248,7 +248,7 @@ static void wrepl_connect_done(struct tevent_req *subreq)
int sys_errno;
ret = tstream_inet_tcp_connect_recv(subreq, &sys_errno,
- state, &state->stream);
+ state, &state->stream, NULL);
if (ret != 0) {
NTSTATUS status = map_nt_error_from_unix(sys_errno);
tevent_req_nterror(req, status);
--
Samba Shared Repository
More information about the samba-cvs
mailing list