[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Tue Dec 28 05:47:01 MST 2010


The branch, master has been updated
       via  5717114 s3: Make node_status_query return NTSTATUS
       via  e1ab3c3 s3: Remove an ancient typedef
       via  b0ff97d s3: Fix some typos
       via  c4b18bd async_send->sendto, async_recv->recvfrom
      from  c604388 s3:winbindd: remove useless ';'

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 571711431885e8e556822c14b3d117025860bf81
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Dec 28 12:53:12 2010 +0100

    s3: Make node_status_query return NTSTATUS
    
    Also make the result talloc'ed
    
    Autobuild-User: Volker Lendecke <vlendec at samba.org>
    Autobuild-Date: Tue Dec 28 13:46:59 CET 2010 on sn-devel-104

commit e1ab3c3470a7f1159d52ed0c1eacf4a5a7b6bc2b
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Dec 28 11:55:47 2010 +0100

    s3: Remove an ancient typedef

commit b0ff97d8d37957fc34861214b6cbab513072bef1
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Dec 28 11:48:43 2010 +0100

    s3: Fix some typos

commit c4b18bd860bc18529249a8c54c7db6aba2347591
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Dec 26 16:03:58 2010 +0100

    async_send->sendto, async_recv->recvfrom

-----------------------------------------------------------------------

Summary of changes:
 lib/async_req/async_sock.c       |   74 +++++++++++++++++++++----------------
 lib/async_req/async_sock.h       |   21 ++++++-----
 nsswitch/wins.c                  |    6 ++--
 source3/include/proto.h          |   12 ++++---
 source3/include/smb.h            |    4 +-
 source3/libsmb/namequery.c       |   60 ++++++++++++++++++------------
 source3/utils/nmblookup.c        |   16 +++++----
 source3/winbindd/winbindd_wins.c |   26 ++++++++-----
 8 files changed, 126 insertions(+), 93 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/async_req/async_sock.c b/lib/async_req/async_sock.c
index 18adb42..9b2a625 100644
--- a/lib/async_req/async_sock.c
+++ b/lib/async_req/async_sock.c
@@ -36,28 +36,30 @@
 #define TALLOC_FREE(ctx) do { talloc_free(ctx); ctx=NULL; } while(0)
 #endif
 
-struct async_send_state {
+struct sendto_state {
 	int fd;
 	const void *buf;
 	size_t len;
 	int flags;
+	const struct sockaddr *addr;
+	socklen_t addr_len;
 	ssize_t sent;
 };
 
-static void async_send_handler(struct tevent_context *ev,
+static void sendto_handler(struct tevent_context *ev,
 			       struct tevent_fd *fde,
 			       uint16_t flags, void *private_data);
 
-struct tevent_req *async_send_send(TALLOC_CTX *mem_ctx,
-				   struct tevent_context *ev,
-				   int fd, const void *buf, size_t len,
-				   int flags)
+struct tevent_req *sendto_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
+			       int fd, const void *buf, size_t len, int flags,
+			       const struct sockaddr *addr,
+			       socklen_t addr_len)
 {
 	struct tevent_req *result;
-	struct async_send_state *state;
+	struct sendto_state *state;
 	struct tevent_fd *fde;
 
-	result = tevent_req_create(mem_ctx, &state, struct async_send_state);
+	result = tevent_req_create(mem_ctx, &state, struct sendto_state);
 	if (result == NULL) {
 		return result;
 	}
@@ -65,8 +67,10 @@ struct tevent_req *async_send_send(TALLOC_CTX *mem_ctx,
 	state->buf = buf;
 	state->len = len;
 	state->flags = flags;
+	state->addr = addr;
+	state->addr_len = addr_len;
 
-	fde = tevent_add_fd(ev, state, fd, TEVENT_FD_WRITE, async_send_handler,
+	fde = tevent_add_fd(ev, state, fd, TEVENT_FD_WRITE, sendto_handler,
 			    result);
 	if (fde == NULL) {
 		TALLOC_FREE(result);
@@ -75,16 +79,17 @@ struct tevent_req *async_send_send(TALLOC_CTX *mem_ctx,
 	return result;
 }
 
-static void async_send_handler(struct tevent_context *ev,
+static void sendto_handler(struct tevent_context *ev,
 			       struct tevent_fd *fde,
 			       uint16_t flags, void *private_data)
 {
 	struct tevent_req *req = talloc_get_type_abort(
 		private_data, struct tevent_req);
-	struct async_send_state *state =
-		tevent_req_data(req, struct async_send_state);
+	struct sendto_state *state =
+		tevent_req_data(req, struct sendto_state);
 
-	state->sent = send(state->fd, state->buf, state->len, state->flags);
+	state->sent = sendto(state->fd, state->buf, state->len, state->flags,
+			     state->addr, state->addr_len);
 	if ((state->sent == -1) && (errno == EINTR)) {
 		/* retry */
 		return;
@@ -96,10 +101,10 @@ static void async_send_handler(struct tevent_context *ev,
 	tevent_req_done(req);
 }
 
-ssize_t async_send_recv(struct tevent_req *req, int *perrno)
+ssize_t sendto_recv(struct tevent_req *req, int *perrno)
 {
-	struct async_send_state *state =
-		tevent_req_data(req, struct async_send_state);
+	struct sendto_state *state =
+		tevent_req_data(req, struct sendto_state);
 
 	if (tevent_req_is_unix_error(req, perrno)) {
 		return -1;
@@ -107,27 +112,30 @@ ssize_t async_send_recv(struct tevent_req *req, int *perrno)
 	return state->sent;
 }
 
-struct async_recv_state {
+struct recvfrom_state {
 	int fd;
 	void *buf;
 	size_t len;
 	int flags;
+	struct sockaddr *addr;
+	socklen_t *addr_len;
 	ssize_t received;
 };
 
-static void async_recv_handler(struct tevent_context *ev,
+static void recvfrom_handler(struct tevent_context *ev,
 			       struct tevent_fd *fde,
 			       uint16_t flags, void *private_data);
 
-struct tevent_req *async_recv_send(TALLOC_CTX *mem_ctx,
-				   struct tevent_context *ev,
-				   int fd, void *buf, size_t len, int flags)
+struct tevent_req *recvfrom_send(TALLOC_CTX *mem_ctx,
+				 struct tevent_context *ev,
+				 int fd, void *buf, size_t len, int flags,
+				 struct sockaddr *addr, socklen_t *addr_len)
 {
 	struct tevent_req *result;
-	struct async_recv_state *state;
+	struct recvfrom_state *state;
 	struct tevent_fd *fde;
 
-	result = tevent_req_create(mem_ctx, &state, struct async_recv_state);
+	result = tevent_req_create(mem_ctx, &state, struct recvfrom_state);
 	if (result == NULL) {
 		return result;
 	}
@@ -135,8 +143,10 @@ struct tevent_req *async_recv_send(TALLOC_CTX *mem_ctx,
 	state->buf = buf;
 	state->len = len;
 	state->flags = flags;
+	state->addr = addr;
+	state->addr_len = addr_len;
 
-	fde = tevent_add_fd(ev, state, fd, TEVENT_FD_READ, async_recv_handler,
+	fde = tevent_add_fd(ev, state, fd, TEVENT_FD_READ, recvfrom_handler,
 			    result);
 	if (fde == NULL) {
 		TALLOC_FREE(result);
@@ -145,17 +155,17 @@ struct tevent_req *async_recv_send(TALLOC_CTX *mem_ctx,
 	return result;
 }
 
-static void async_recv_handler(struct tevent_context *ev,
+static void recvfrom_handler(struct tevent_context *ev,
 			       struct tevent_fd *fde,
 			       uint16_t flags, void *private_data)
 {
 	struct tevent_req *req = talloc_get_type_abort(
 		private_data, struct tevent_req);
-	struct async_recv_state *state =
-		tevent_req_data(req, struct async_recv_state);
+	struct recvfrom_state *state =
+		tevent_req_data(req, struct recvfrom_state);
 
-	state->received = recv(state->fd, state->buf, state->len,
-			       state->flags);
+	state->received = recvfrom(state->fd, state->buf, state->len,
+				   state->flags, state->addr, state->addr_len);
 	if ((state->received == -1) && (errno == EINTR)) {
 		/* retry */
 		return;
@@ -171,10 +181,10 @@ static void async_recv_handler(struct tevent_context *ev,
 	tevent_req_done(req);
 }
 
-ssize_t async_recv_recv(struct tevent_req *req, int *perrno)
+ssize_t recvfrom_recv(struct tevent_req *req, int *perrno)
 {
-	struct async_recv_state *state =
-		tevent_req_data(req, struct async_recv_state);
+	struct recvfrom_state *state =
+		tevent_req_data(req, struct recvfrom_state);
 
 	if (tevent_req_is_unix_error(req, perrno)) {
 		return -1;
diff --git a/lib/async_req/async_sock.h b/lib/async_req/async_sock.h
index e7ddff8..d87b2c1 100644
--- a/lib/async_req/async_sock.h
+++ b/lib/async_req/async_sock.h
@@ -27,16 +27,17 @@
 #include <talloc.h>
 #include <tevent.h>
 
-struct tevent_req *async_send_send(TALLOC_CTX *mem_ctx,
-				   struct tevent_context *ev,
-				   int fd, const void *buf, size_t len,
-				   int flags);
-ssize_t async_send_recv(struct tevent_req *req, int *perrno);
-
-struct tevent_req *async_recv_send(TALLOC_CTX *mem_ctx,
-				   struct tevent_context *ev,
-				   int fd, void *buf, size_t len, int flags);
-ssize_t async_recv_recv(struct tevent_req *req, int *perrno);
+struct tevent_req *sendto_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
+			       int fd, const void *buf, size_t len, int flags,
+			       const struct sockaddr *addr,
+			       socklen_t addr_len);
+ssize_t sendto_recv(struct tevent_req *req, int *perrno);
+
+struct tevent_req *recvfrom_send(TALLOC_CTX *mem_ctx,
+				 struct tevent_context *ev,
+				 int fd, void *buf, size_t len, int flags,
+				 struct sockaddr *addr, socklen_t *addr_len);
+ssize_t recvfrom_recv(struct tevent_req *req, int *perrno);
 
 struct tevent_req *async_connect_send(TALLOC_CTX *mem_ctx,
 				      struct tevent_context *ev,
diff --git a/nsswitch/wins.c b/nsswitch/wins.c
index aa02f32..731efcb 100644
--- a/nsswitch/wins.c
+++ b/nsswitch/wins.c
@@ -162,12 +162,12 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count)
 
 #ifdef HAVE_NS_API_H
 
-static NODE_STATUS_STRUCT *lookup_byaddr_backend(char *addr, int *count)
+static struct node_status *lookup_byaddr_backend(char *addr, int *count)
 {
 	int fd;
 	struct sockaddr_storage ss;
 	struct nmb_name nname;
-	NODE_STATUS_STRUCT *status;
+	struct node_status *status;
 
 	if (!initialised) {
 		nss_wins_init();
@@ -202,7 +202,7 @@ int lookup(nsd_file_t *rq)
 	char *key;
 	char *addr;
 	struct in_addr *ip_list;
-	NODE_STATUS_STRUCT *status;
+	struct node_status *status;
 	int i, count, len, size;
 	char response[1024];
 	bool found = False;
diff --git a/source3/include/proto.h b/source3/include/proto.h
index f9bf72f..8278ffb 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -2699,11 +2699,13 @@ bool saf_store( const char *domain, const char *servername );
 bool saf_join_store( const char *domain, const char *servername );
 bool saf_delete( const char *domain );
 char *saf_fetch( const char *domain );
-NODE_STATUS_STRUCT *node_status_query(int fd,
-					struct nmb_name *name,
-					const struct sockaddr_storage *to_ss,
-					int *num_names,
-					struct node_status_extra *extra);
+NTSTATUS node_status_query(int fd,
+			   struct nmb_name *name,
+			   const struct sockaddr_storage *to_ss,
+			   TALLOC_CTX *mem_ctx,
+			   struct node_status **names,
+			   int *num_names,
+			   struct node_status_extra *extra);
 bool name_status_find(const char *q_name,
 			int q_type,
 			int type,
diff --git a/source3/include/smb.h b/source3/include/smb.h
index 8d12fb9..1957504 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -1687,11 +1687,11 @@ struct nmb_name {
 };
 
 /* A netbios node status array element. */
-typedef struct node_status_ {
+struct node_status {
 	nstring name;
 	unsigned char type;
 	unsigned char flags;
-} NODE_STATUS_STRUCT;
+};
 
 /* The extra info from a NetBIOS node status query */
 struct node_status_extra {
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index fd12f75..a283038 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -212,11 +212,11 @@ static int generate_trn_id(void)
  Parse a node status response into an array of structures.
 ****************************************************************************/
 
-static NODE_STATUS_STRUCT *parse_node_status(char *p,
+static struct node_status *parse_node_status(TALLOC_CTX *mem_ctx, char *p,
 				int *num_names,
 				struct node_status_extra *extra)
 {
-	NODE_STATUS_STRUCT *ret;
+	struct node_status *ret;
 	int i;
 
 	*num_names = CVAL(p,0);
@@ -224,7 +224,7 @@ static NODE_STATUS_STRUCT *parse_node_status(char *p,
 	if (*num_names == 0)
 		return NULL;
 
-	ret = SMB_MALLOC_ARRAY(NODE_STATUS_STRUCT,*num_names);
+	ret = TALLOC_ARRAY(mem_ctx, struct node_status,*num_names);
 	if (!ret)
 		return NULL;
 
@@ -278,11 +278,13 @@ static bool send_packet_request(struct packet_struct *p)
  structures holding the returned names or NULL if the query failed.
 **************************************************************************/
 
-NODE_STATUS_STRUCT *node_status_query(int fd,
-					struct nmb_name *name,
-					const struct sockaddr_storage *to_ss,
-					int *num_names,
-					struct node_status_extra *extra)
+NTSTATUS node_status_query(int fd,
+			   struct nmb_name *name,
+			   const struct sockaddr_storage *to_ss,
+			   TALLOC_CTX *mem_ctx,
+			   struct node_status **names,
+			   int *num_names,
+			   struct node_status_extra *extra)
 {
 	bool found=False;
 	int retries = 2;
@@ -291,13 +293,13 @@ NODE_STATUS_STRUCT *node_status_query(int fd,
 	struct packet_struct p;
 	struct packet_struct *p2;
 	struct nmb_packet *nmb = &p.packet.nmb;
-	NODE_STATUS_STRUCT *ret;
+	struct node_status *ret;
 
 	ZERO_STRUCT(p);
 
 	if (to_ss->ss_family != AF_INET) {
 		/* Can't do node status to IPv6 */
-		return NULL;
+		return NT_STATUS_INVALID_ADDRESS;
 	}
 	nmb->header.name_trn_id = generate_trn_id();
 	nmb->header.opcode = 0;
@@ -326,7 +328,7 @@ NODE_STATUS_STRUCT *node_status_query(int fd,
 	clock_gettime_mono(&tp);
 
 	if (!send_packet_request(&p))
-		return NULL;
+		return NT_STATUS_NOT_FOUND;
 
 	retries--;
 
@@ -337,7 +339,7 @@ NODE_STATUS_STRUCT *node_status_query(int fd,
 			if (!retries)
 				break;
 			if (!found && !send_packet_request(&p))
-				return NULL;
+				return NT_STATUS_NOT_FOUND;
 			clock_gettime_mono(&tp);
 			retries--;
 		}
@@ -358,14 +360,20 @@ NODE_STATUS_STRUCT *node_status_query(int fd,
 				continue;
 			}
 
-			ret = parse_node_status(&nmb2->answers->rdata[0],
-					num_names, extra);
+			ret = parse_node_status(
+				mem_ctx, &nmb2->answers->rdata[0], num_names,
+				extra);
 			free_packet(p2);
-			return ret;
+
+			if (ret == NULL) {
+				return NT_STATUS_NO_MEMORY;
+			}
+			*names = ret;
+			return NT_STATUS_OK;
 		}
 	}
 
-	return NULL;
+	return NT_STATUS_IO_TIMEOUT;
 }
 
 /****************************************************************************
@@ -381,11 +389,12 @@ bool name_status_find(const char *q_name,
 {
 	char addr[INET6_ADDRSTRLEN];
 	struct sockaddr_storage ss;
-	NODE_STATUS_STRUCT *status = NULL;
+	struct node_status *addrs = NULL;
 	struct nmb_name nname;
 	int count, i;
 	int sock;
 	bool result = false;
+	NTSTATUS status;
 
 	if (lp_disable_netbios()) {
 		DEBUG(5,("name_status_find(%s#%02x): netbios is disabled\n",
@@ -420,20 +429,22 @@ bool name_status_find(const char *q_name,
 
 	/* W2K PDC's seem not to respond to '*'#0. JRA */
 	make_nmb_name(&nname, q_name, q_type);
-	status = node_status_query(sock, &nname, to_ss, &count, NULL);
+	status = node_status_query(sock, &nname, to_ss, talloc_tos(),
+				   &addrs, &count, NULL);
 	close(sock);
-	if (!status)
+	if (!NT_STATUS_IS_OK(status)) {
 		goto done;
+	}
 
 	for (i=0;i<count;i++) {
                 /* Find first one of the requested type that's not a GROUP. */
-		if (status[i].type == type && ! (status[i].flags & 0x80))
+		if (addrs[i].type == type && ! (addrs[i].flags & 0x80))
 			break;
 	}
 	if (i == count)
 		goto done;
 
-	pull_ascii_nstring(name, sizeof(fstring), status[i].name);
+	pull_ascii_nstring(name, sizeof(fstring), addrs[i].name);
 
 	/* Store the result in the cache. */
 	/* but don't store an entry for 0x1c names here.  Here we have
@@ -446,7 +457,7 @@ bool name_status_find(const char *q_name,
 	result = true;
 
  done:
-	SAFE_FREE(status);
+	TALLOC_FREE(addrs);
 
 	DEBUG(10, ("name_status_find: name %sfound", result ? "" : "not "));
 
@@ -1090,11 +1101,12 @@ NTSTATUS resolve_wins(const char *name,
 			close(sock);
 
 			if (timed_out) {
-				/* Timed out wating for WINS server to respond.
+				/* Timed out waiting for WINS server to
+				 * respond.
 				 * Mark it dead. */
 				wins_srv_died(wins_ip, src_ip);
 			} else {
-				/* The name definately isn't in this
+				/* The name definitely isn't in this
 				   group of WINS servers.
 				   goto the next group  */
 				break;
diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c
index b63b0a3..5bbd06c 100644
--- a/source3/utils/nmblookup.c
+++ b/source3/utils/nmblookup.c
@@ -113,33 +113,35 @@ static void do_node_status(int fd,
 {
 	struct nmb_name nname;
 	int count, i, j;
-	NODE_STATUS_STRUCT *status;
+	struct node_status *addrs;
 	struct node_status_extra extra;
 	fstring cleanname;
 	char addr[INET6_ADDRSTRLEN];
+	NTSTATUS status;
 
 	print_sockaddr(addr, sizeof(addr), pss);
 	d_printf("Looking up status of %s\n",addr);
 	make_nmb_name(&nname, name, type);
-	status = node_status_query(fd, &nname, pss, &count, &extra);
-	if (status) {
+	status = node_status_query(fd, &nname, pss, talloc_tos(),
+				   &addrs, &count, &extra);
+	if (NT_STATUS_IS_OK(status)) {
 		for (i=0;i<count;i++) {
-			pull_ascii_fstring(cleanname, status[i].name);
+			pull_ascii_fstring(cleanname, addrs[i].name);
 			for (j=0;cleanname[j];j++) {
 				if (!isprint((int)cleanname[j])) {
 					cleanname[j] = '.';
 				}
 			}
 			d_printf("\t%-15s <%02x> - %s\n",
-			       cleanname,status[i].type,
-			       node_status_flags(status[i].flags));
+			       cleanname,addrs[i].type,
+			       node_status_flags(addrs[i].flags));
 		}
 		d_printf("\n\tMAC Address = %02X-%02X-%02X-%02X-%02X-%02X\n",
 				extra.mac_addr[0], extra.mac_addr[1],
 				extra.mac_addr[2], extra.mac_addr[3],
 				extra.mac_addr[4], extra.mac_addr[5]);
 		d_printf("\n");
-		SAFE_FREE(status);
+		TALLOC_FREE(addrs);
 	} else {
 		d_printf("No reply from %s\n\n",addr);
 	}
diff --git a/source3/winbindd/winbindd_wins.c b/source3/winbindd/winbindd_wins.c
index f5727cc..484b393 100644
--- a/source3/winbindd/winbindd_wins.c
+++ b/source3/winbindd/winbindd_wins.c


-- 
Samba Shared Repository


More information about the samba-cvs mailing list