svn commit: samba r20103 - in branches/SAMBA_4_0/source/libnet: .

mimir at samba.org mimir at samba.org
Sun Dec 10 23:43:33 GMT 2006


Author: mimir
Date: 2006-12-10 23:43:32 +0000 (Sun, 10 Dec 2006)
New Revision: 20103

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=20103

Log:
Change the returned type of prerequisite checking functions,
as metze once suggested.


rafal


Modified:
   branches/SAMBA_4_0/source/libnet/libnet_user.c
   branches/SAMBA_4_0/source/libnet/prereq_domain.c


Changeset:
Modified: branches/SAMBA_4_0/source/libnet/libnet_user.c
===================================================================
--- branches/SAMBA_4_0/source/libnet/libnet_user.c	2006-12-10 23:28:36 UTC (rev 20102)
+++ branches/SAMBA_4_0/source/libnet/libnet_user.c	2006-12-10 23:43:32 UTC (rev 20103)
@@ -63,7 +63,7 @@
 	struct composite_context *c;
 	struct create_user_state *s;
 	struct composite_context *create_req;
-	struct composite_context *prereq_ctx;
+	BOOL prereq_met = False;
 
 	/* composite context allocation and setup */
 	c = composite_create(mem_ctx, ctx->event_ctx);
@@ -80,9 +80,9 @@
 	ZERO_STRUCT(s->r.out);
 
 	/* prerequisite: make sure the domain is opened */
-	prereq_ctx = samr_domain_opened(ctx, s->r.in.domain_name, c, &s->domain_open,
+	prereq_met = samr_domain_opened(ctx, s->r.in.domain_name, &c, &s->domain_open,
 					continue_domain_open_create, monitor);
-	if (prereq_ctx) return prereq_ctx;
+	if (!prereq_met) return c;
 
 	/* prepare arguments for useradd call */
 	s->user_add.in.username       = r->in.user_name;
@@ -232,7 +232,7 @@
 	struct composite_context *c;
 	struct delete_user_state *s;
 	struct composite_context *delete_req;
-	struct composite_context *prereq_ctx;
+	BOOL prereq_met = False;
 
 	/* composite context allocation and setup */
 	c = composite_create(mem_ctx, ctx->event_ctx);
@@ -249,9 +249,9 @@
 	ZERO_STRUCT(s->r.out);
 	
 	/* prerequisite: make sure the domain is opened before proceeding */
-	prereq_ctx = samr_domain_opened(ctx, s->r.in.domain_name, c, &s->domain_open,
+	prereq_met = samr_domain_opened(ctx, s->r.in.domain_name, &c, &s->domain_open,
 					continue_domain_open_delete, monitor);
-	if (prereq_ctx) return prereq_ctx;
+	if (!prereq_met) return c;
 
 	/* prepare arguments for userdel call */
 	s->user_del.in.username       = r->in.user_name;
@@ -402,8 +402,8 @@
 	const uint16_t level = 21;
 	struct composite_context *c;
 	struct modify_user_state *s;
-	struct composite_context *prereq_ctx;
 	struct composite_context *userinfo_req;
+	BOOL prereq_met = False;
 
 	c = composite_create(mem_ctx, ctx->event_ctx);
 	if (c == NULL) return NULL;
@@ -416,9 +416,9 @@
 	s->ctx = ctx;
 	s->r = *r;
 
-	prereq_ctx = samr_domain_opened(ctx, s->r.in.domain_name, c, &s->domain_open,
+	prereq_met = samr_domain_opened(ctx, s->r.in.domain_name, &c, &s->domain_open,
 					continue_domain_open_modify, monitor);
-	if (prereq_ctx) return prereq_ctx;
+	if (!prereq_met) return c;
 
 	s->user_info.in.username      = r->in.user_name;
 	s->user_info.in.domain_handle = ctx->samr.handle;
@@ -626,8 +626,8 @@
 {
 	struct composite_context *c;
 	struct user_info_state *s;
-	struct composite_context *prereq_ctx;
 	struct composite_context *lookup_req;
+	BOOL prereq_met = False;
 
 	/* composite context allocation and setup */
 	c = composite_create(mem_ctx, ctx->event_ctx);
@@ -645,9 +645,9 @@
 	s->user_name = talloc_strdup(c, r->in.user_name);
 
 	/* prerequisite: make sure the domain is opened */
-	prereq_ctx = samr_domain_opened(ctx, s->domain_name, c, &s->domopen,
+	prereq_met = samr_domain_opened(ctx, s->domain_name, &c, &s->domopen,
 					continue_domain_open_info, monitor);
-	if (prereq_ctx) return prereq_ctx;
+	if (!prereq_met) return c;
 
 	/* prepare arguments for LookupName call */
 	s->lookup.in.domain_name = s->domain_name;
@@ -869,8 +869,8 @@
 {
 	struct composite_context *c;
 	struct userlist_state *s;
-	struct composite_context *prereq_ctx;
 	struct rpc_request *query_req;
+	BOOL prereq_met = False;
 
 	/* composite context allocation and setup */
 	c = composite_create(mem_ctx, ctx->event_ctx);
@@ -889,9 +889,9 @@
 	s->monitor_fn   = monitor;
 
 	/* make sure we have lsa domain handle before doing anything */
-	prereq_ctx = lsa_domain_opened(ctx, s->domain_name, c, &s->domain_open,
+	prereq_met = lsa_domain_opened(ctx, s->domain_name, &c, &s->domain_open,
 				       continue_lsa_domain_opened, monitor);
-	if (prereq_ctx) return prereq_ctx;
+	if (!prereq_met) return c;
 
 	/* prepare arguments of QueryDomainInfo call */
 	s->query_domain.in.handle = &ctx->lsa.handle;
@@ -943,8 +943,8 @@
 {
 	struct composite_context *c;
 	struct userlist_state *s;
-	struct composite_context *prereq_ctx;
 	struct rpc_request *enum_req;
+	BOOL prereq_met = False;
 	
 	c = talloc_get_type(req->async.private, struct composite_context);
 	s = talloc_get_type(c->private_data, struct userlist_state);
@@ -957,9 +957,9 @@
 	s->dominfo = s->query_domain.out.info->domain;
 
 	/* make sure we have samr domain handle before continuing */
-	prereq_ctx = samr_domain_opened(s->ctx, s->domain_name, c, &s->domain_open,
+	prereq_met = samr_domain_opened(s->ctx, s->domain_name, &c, &s->domain_open,
 					continue_samr_domain_opened, s->monitor_fn);
-	if (prereq_ctx) return;
+	if (!prereq_met) return;
 
 	/* prepare arguments od EnumDomainUsers call */
 	s->user_list.in.domain_handle = &s->ctx->samr.handle;
@@ -1027,7 +1027,7 @@
 	/* get the actual status of the rpc call result (instead of rpc layer status) */
 	c->status = s->user_list.out.result;
 
-	/* we're interested in status "ok" as well as two enum-specific statuses */
+	/* we're interested in status "ok" as well as two enum-specific status codes */
 	if (NT_STATUS_IS_OK(c->status) ||
 	    NT_STATUS_EQUAL(c->status, STATUS_MORE_ENTRIES) ||
 	    NT_STATUS_EQUAL(c->status, NT_STATUS_NO_MORE_ENTRIES)) {

Modified: branches/SAMBA_4_0/source/libnet/prereq_domain.c
===================================================================
--- branches/SAMBA_4_0/source/libnet/prereq_domain.c	2006-12-10 23:28:36 UTC (rev 20102)
+++ branches/SAMBA_4_0/source/libnet/prereq_domain.c	2006-12-10 23:43:32 UTC (rev 20103)
@@ -30,15 +30,16 @@
 #include "librpc/gen_ndr/ndr_lsa.h"
 
 
-struct composite_context* samr_domain_opened(struct libnet_context *ctx,
-					     const char *domain_name,
-					     struct composite_context *parent_ctx,
-					     struct libnet_DomainOpen *domain_open,
-					     void (*continue_fn)(struct composite_context*),
-					     void (*monitor)(struct monitor_msg*))
+BOOL samr_domain_opened(struct libnet_context *ctx, const char *domain_name,
+			struct composite_context **parent_ctx,
+			struct libnet_DomainOpen *domain_open,
+			void (*continue_fn)(struct composite_context*),
+			void (*monitor)(struct monitor_msg*))
 {
 	struct composite_context *domopen_req;
 
+	if (parent_ctx == NULL || *parent_ctx == NULL) return False;
+
 	if (domain_name == NULL) {
 		/*
 		 * Try to guess the domain name from credentials,
@@ -51,8 +52,8 @@
 			domain_open->in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
 
 		} else {
-			composite_error(parent_ctx, NT_STATUS_INVALID_PARAMETER);
-			return parent_ctx;
+			composite_error(*parent_ctx, NT_STATUS_INVALID_PARAMETER);
+			return True;
 		}
 
 	} else {
@@ -71,27 +72,28 @@
 		} else {
 			/* domain has already been opened and it's the same domain
 			   as requested */
-			return NULL;
+			return True;
 		}
 	}
 
 	/* send request to open the domain */
 	domopen_req = libnet_DomainOpen_send(ctx, domain_open, monitor);
-	if (composite_nomem(domopen_req, parent_ctx)) return parent_ctx;
+	if (composite_nomem(domopen_req, *parent_ctx)) return False;
 	
-	composite_continue(parent_ctx, domopen_req, continue_fn, parent_ctx);
-	return parent_ctx;
+	composite_continue(*parent_ctx, domopen_req, continue_fn, *parent_ctx);
+	return False;
 }
 
 
-struct composite_context* lsa_domain_opened(struct libnet_context *ctx,
-					    const char *domain_name,
-					    struct composite_context *parent_ctx,
-					    struct libnet_DomainOpen *domain_open,
-					    void (*continue_fn)(struct composite_context*),
-					    void (*monitor)(struct monitor_msg*))
+BOOL lsa_domain_opened(struct libnet_context *ctx, const char *domain_name,
+		       struct composite_context **parent_ctx,
+		       struct libnet_DomainOpen *domain_open,
+		       void (*continue_fn)(struct composite_context*),
+		       void (*monitor)(struct monitor_msg*))
 {
 	struct composite_context *domopen_req;
+	
+	if (parent_ctx == NULL || *parent_ctx == NULL) return False;
 
 	if (domain_name == NULL) {
 		/*
@@ -105,8 +107,10 @@
 			domain_open->in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
 
 		} else {
-			composite_error(parent_ctx, NT_STATUS_INVALID_PARAMETER);
-			return parent_ctx;
+			composite_error(*parent_ctx, NT_STATUS_INVALID_PARAMETER);
+			/* this ensures the calling function exits and composite function error
+			   gets noticed quickly */
+			return True;
 		}
 
 	} else {
@@ -125,14 +129,15 @@
 		} else {
 			/* domain has already been opened and it's the same domain
 			   as requested */
-			return NULL;
+			return True;
 		}
 	}
 
 	/* send request to open the domain */
 	domopen_req = libnet_DomainOpen_send(ctx, domain_open, monitor);
-	if (composite_nomem(domopen_req, parent_ctx)) return parent_ctx;
+	/* see the comment above to find out why true is returned here */
+	if (composite_nomem(domopen_req, *parent_ctx)) return True;
 	
-	composite_continue(parent_ctx, domopen_req, continue_fn, parent_ctx);
-	return parent_ctx;
+	composite_continue(*parent_ctx, domopen_req, continue_fn, *parent_ctx);
+	return False;
 }



More information about the samba-cvs mailing list