lsa_enum_trust_dom functionality

Rafal Szczesniak mimir at diament.ists.pwr.wroc.pl
Tue Apr 16 05:53:03 GMT 2002


On Sun, 14 Apr 2002, Andrew Bartlett wrote:

> I would expect the current code comes pretty close already actually.
> 
> I'll be interested to see what you actually need to change.

OK. This is another fix to enumerationn code. Major changes:
 - fix for returned error codes during enumeration
 - comments
 - renamed STATUS_MORE_ENTRIES to NT_STATUS_MORE_ENTRIES
 - fixes to cli_lsa_enum_trust_dom. Now it respects error codes correctly
 - changes in rpcclient. "enumtrust" command is now parametrized to be
   able to check returned error codes

And here comes the issue. Function cli_lsa_enum_trust_domi is stateless by
its nature. It returns enum_context returned by rpc server as well as
status code and it's up to caller of the function to call it again with
proper args to continue or finish the enumeration. It may be annoying to
write such code in each place we use client side of enumeration, so I
propose to write a "higher level" function which could take care of doing
it properly so that we don't have to worry about details of this
process. Such function could be cli_lsa_enum_trust_domain or
cli_enum_trust_dom_2 or whatever. Doesn't really matter.

What do you think ?



cheers,
+------------------------------------------------------------+
|Rafal 'Mimir' Szczesniak <mimir at diament.ists.pwr.wroc.pl>   |
|*BSD, GNU/Linux and Samba                                  /
|__________________________________________________________/
-------------- next part --------------
Index: include/nterr.h
===================================================================
RCS file: /cvsroot/samba/source/include/nterr.h,v
retrieving revision 1.22
diff -u -r1.22 nterr.h
--- include/nterr.h	14 Apr 2002 10:50:32 -0000	1.22
+++ include/nterr.h	16 Apr 2002 12:35:30 -0000
@@ -29,7 +29,7 @@
 #define STATUS_BUFFER_OVERFLOW            NT_STATUS(0x80000005)
 #define NT_STATUS_NO_MORE_ENTRIES         NT_STATUS(0x8000001a)
 
-#define STATUS_MORE_ENTRIES               NT_STATUS(0x0105)
+#define NT_STATUS_MORE_ENTRIES            NT_STATUS(0x0105)
 #define STATUS_SOME_UNMAPPED              NT_STATUS(0x0107)
 #define ERROR_INVALID_PARAMETER		  NT_STATUS(0x0057)
 #define ERROR_INSUFFICIENT_BUFFER	  NT_STATUS(0x007a)
Index: include/rpc_samr.h
===================================================================
RCS file: /cvsroot/samba/source/include/rpc_samr.h,v
retrieving revision 1.74
diff -u -r1.74 rpc_samr.h
--- include/rpc_samr.h	30 Jan 2002 06:08:15 -0000	1.74
+++ include/rpc_samr.h	16 Apr 2002 12:35:30 -0000
@@ -953,7 +953,7 @@
 	uint32 start_idx;       /* start enumeration index */
 	uint32 max_entries;     /* maximum number of entries to return */
 	uint32 max_size;        /* recommended data size; if exceeded server
-				   should return STATUS_MORE_ENTRIES */
+				   should return NT_STATUS_MORE_ENTRIES */
 
 } SAMR_Q_QUERY_DISPINFO;
 
Index: libsmb/cli_lsarpc.c
===================================================================
RCS file: /cvsroot/samba/source/libsmb/cli_lsarpc.c,v
retrieving revision 1.43
diff -u -r1.43 cli_lsarpc.c
--- libsmb/cli_lsarpc.c	14 Apr 2002 11:21:25 -0000	1.43
+++ libsmb/cli_lsarpc.c	16 Apr 2002 12:35:30 -0000
@@ -5,7 +5,8 @@
    Copyright (C) Andrew Tridgell              1992-1997,2000,
    Copyright (C) Luke Kenneth Casson Leighton 1996-1997,2000,
    Copyright (C) Paul Ashton                       1997,2000,
-   Copyright (C) Elrond                                 2000.
+   Copyright (C) Elrond                                 2000,
+   Copyright (C) Rafal Szczesniak                       2002
    
    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
@@ -537,12 +538,25 @@
 	return result;
 }
 
-/** Enumerate list of trusted domains */
+/**
+ * Enumerate list of trusted domains
+ *
+ * @param cli client state (cli_state) structure of the connection
+ * @param mem_ctx memory context
+ * @param pol opened lsa policy handle
+ * @param enum_ctx enumeration context ie. index of first returned domain entry
+ * @param pref_num_domains preferred max number of entries returned in one response
+ * @param num_domains total number of trusted domains returned by response
+ * @param domain_names returned trusted domain names
+ * @param domain_sids returned trusted domain sids
+ *
+ * @return nt status code of response
+ **/
 
 NTSTATUS cli_lsa_enum_trust_dom(struct cli_state *cli, TALLOC_CTX *mem_ctx,
                                 POLICY_HND *pol, uint32 *enum_ctx, 
-                                uint32 *num_domains, char ***domain_names, 
-                                DOM_SID **domain_sids)
+                                uint32 *pref_num_domains, uint32 *num_domains,
+				char ***domain_names, DOM_SID **domain_sids)
 {
 	prs_struct qbuf, rbuf;
 	LSA_Q_ENUM_TRUST_DOM q;
@@ -560,7 +574,7 @@
 
 	/* Marshall data and send request */
 
-        init_q_enum_trust_dom(&q, pol, *enum_ctx, 0xffffffff);
+        init_q_enum_trust_dom(&q, pol, *enum_ctx, *pref_num_domains);
 
 	if (!lsa_io_q_enum_trust_dom("", &q, &qbuf, 0) ||
 	    !rpc_api_pipe_req(cli, LSA_ENUMTRUSTDOM, &qbuf, &rbuf)) {
@@ -577,15 +591,14 @@
 
 	result = r.status;
 
-	if (!NT_STATUS_IS_OK(result) && 
-	    NT_STATUS_V(result) != NT_STATUS_V(NT_STATUS_NO_MORE_ENTRIES)) {
+	if (!NT_STATUS_IS_OK(result) &&
+	    !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
+	    !NT_STATUS_EQUAL(result, NT_STATUS_MORE_ENTRIES)) {
 
 		/* An actual error ocured */
 
 		goto done;
 	}
-
-	result = NT_STATUS_OK;
 
 	/* Return output parameters */
 
Index: libsmb/cli_samr.c
===================================================================
RCS file: /cvsroot/samba/source/libsmb/cli_samr.c,v
retrieving revision 1.28
diff -u -r1.28 cli_samr.c
--- libsmb/cli_samr.c	14 Apr 2002 09:44:14 -0000	1.28
+++ libsmb/cli_samr.c	16 Apr 2002 12:35:30 -0000
@@ -560,7 +560,7 @@
 	result = r.status;
 
 	if (!NT_STATUS_IS_OK(result) &&
-	    NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
+	    NT_STATUS_V(result) != NT_STATUS_V(NT_STATUS_MORE_ENTRIES)) {
 		goto done;
 	}
 
@@ -638,7 +638,7 @@
 	result = r.status;
 
 	if (!NT_STATUS_IS_OK(result) &&
-	    NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
+	    NT_STATUS_V(result) != NT_STATUS_V(NT_STATUS_MORE_ENTRIES)) {
 		goto done;
 	}
 
@@ -878,7 +878,7 @@
         result = r.status;
 
 	if (!NT_STATUS_IS_OK(result) &&
-	    NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
+	    NT_STATUS_V(result) != NT_STATUS_V(NT_STATUS_MORE_ENTRIES)) {
 		goto done;
 	}
 
Index: libsmb/clireadwrite.c
===================================================================
RCS file: /cvsroot/samba/source/libsmb/clireadwrite.c,v
retrieving revision 1.16
diff -u -r1.16 clireadwrite.c
--- libsmb/clireadwrite.c	20 Mar 2002 01:47:31 -0000	1.16
+++ libsmb/clireadwrite.c	16 Apr 2002 12:35:30 -0000
@@ -119,7 +119,7 @@
                                 cli_dos_error(cli, &eclass, &ecode);
 
                         if ((eclass == ERRDOS && ecode == ERRmoredata) ||
-                            NT_STATUS_V(status) == NT_STATUS_V(STATUS_MORE_ENTRIES))
+                            NT_STATUS_V(status) == NT_STATUS_V(NT_STATUS_MORE_ENTRIES))
                                 return -1;
 		}
 
Index: libsmb/errormap.c
===================================================================
RCS file: /cvsroot/samba/source/libsmb/errormap.c,v
retrieving revision 1.15
diff -u -r1.15 errormap.c
--- libsmb/errormap.c	23 Mar 2002 08:45:02 -0000	1.15
+++ libsmb/errormap.c	16 Apr 2002 12:35:30 -0000
@@ -668,7 +668,7 @@
 	{ERRDOS,	87,	NT_STATUS_INVALID_INFO_CLASS},
 	{ERRDOS,	88,	NT_STATUS_NET_WRITE_FAULT},
 	{ERRDOS,	109,	NT_STATUS_PIPE_BROKEN},
-	{ERRDOS,	111,	STATUS_MORE_ENTRIES},
+	{ERRDOS,	111,	NT_STATUS_MORE_ENTRIES},
 	{ERRDOS,	112,	NT_STATUS_DISK_FULL},
 	{ERRDOS,	121,	NT_STATUS_IO_TIMEOUT},
 	{ERRDOS,	122,	NT_STATUS_BUFFER_TOO_SMALL},
@@ -801,7 +801,7 @@
 	{ERRHRD,	87,	NT_STATUS_INVALID_INFO_CLASS},
 	{ERRHRD,	88,	NT_STATUS_NET_WRITE_FAULT},
 	{ERRHRD,	109,	NT_STATUS_PIPE_BROKEN},
-	{ERRHRD,	111,	STATUS_MORE_ENTRIES},
+	{ERRHRD,	111,	NT_STATUS_MORE_ENTRIES},
 	{ERRHRD,	112,	NT_STATUS_DISK_FULL},
 	{ERRHRD,	121,	NT_STATUS_IO_TIMEOUT},
 	{ERRHRD,	122,	NT_STATUS_BUFFER_TOO_SMALL},
@@ -824,7 +824,7 @@
 	{ERRHRD,	231,	NT_STATUS_INSTANCE_NOT_AVAILABLE},
 	{ERRHRD,	232,	NT_STATUS_PIPE_CLOSING},
 	{ERRHRD,	233,	NT_STATUS_PIPE_DISCONNECTED},
-	{ERRHRD,	234,	STATUS_MORE_ENTRIES},
+	{ERRHRD,	234,	NT_STATUS_MORE_ENTRIES},
 	{ERRHRD,	240,	NT_STATUS_VIRTUAL_CIRCUIT_CLOSED},
 	{ERRHRD,	254,	NT_STATUS(0x80000013)},
 	{ERRHRD,	255,	NT_STATUS_EA_TOO_LARGE},
Index: libsmb/nterr.c
===================================================================
RCS file: /cvsroot/samba/source/libsmb/nterr.c,v
retrieving revision 1.24
diff -u -r1.24 nterr.c
--- libsmb/nterr.c	14 Apr 2002 11:13:49 -0000	1.24
+++ libsmb/nterr.c	16 Apr 2002 12:35:31 -0000
@@ -534,6 +534,7 @@
 	{ "NT_STATUS_QUOTA_LIST_INCONSISTENT", NT_STATUS_QUOTA_LIST_INCONSISTENT },
 	{ "NT_STATUS_FILE_IS_OFFLINE", NT_STATUS_FILE_IS_OFFLINE },
         { "NT_STATUS_NO_MORE_ENTRIES", NT_STATUS_NO_MORE_ENTRIES },
+	{ "NT_STATUS_MORE_ENTRIES", NT_STATUS_MORE_ENTRIES },
 	{ "STATUS_SOME_UNMAPPED", STATUS_SOME_UNMAPPED },
 	{ NULL, NT_STATUS(0) }
 };
Index: nsswitch/winbindd_rpc.c
===================================================================
RCS file: /cvsroot/samba/source/nsswitch/winbindd_rpc.c,v
retrieving revision 1.26
diff -u -r1.26 winbindd_rpc.c
--- nsswitch/winbindd_rpc.c	14 Apr 2002 11:21:25 -0000	1.26
+++ nsswitch/winbindd_rpc.c	16 Apr 2002 12:35:31 -0000
@@ -78,7 +78,7 @@
 						 &count, 0xFFFF, &ctr);
 
 		if (!NT_STATUS_IS_OK(result) && 
-		    !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) break;
+		    !NT_STATUS_EQUAL(result, NT_STATUS_MORE_ENTRIES)) break;
 
 		(*num_entries) += count;
 
@@ -106,7 +106,7 @@
 		}
 
 		talloc_destroy(ctx2);
-	} while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
+	} while (NT_STATUS_EQUAL(result, NT_STATUS_MORE_ENTRIES));
 
  done:
 
@@ -153,7 +153,7 @@
 						  &info2, &count);
 
 		if (!NT_STATUS_IS_OK(status) && 
-		    !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
+		    !NT_STATUS_EQUAL(status, NT_STATUS_MORE_ENTRIES)) {
 			talloc_destroy(mem_ctx2);
 			break;
 		}
@@ -169,7 +169,7 @@
 		memcpy(&(*info)[*num_entries], info2, count*sizeof(*info2));
 		(*num_entries) += count;
 		talloc_destroy(mem_ctx2);
-	} while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
+	} while (NT_STATUS_EQUAL(status, NT_STATUS_MORE_ENTRIES));
 
 	cli_samr_close(hnd->cli, mem_ctx, &dom_pol);
 
@@ -558,6 +558,7 @@
 	CLI_POLICY_HND *hnd;
 	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
 	uint32 enum_ctx = 0;
+	uint32 pref_num_domains = 5;
 
 	*num_domains = 0;
 
@@ -565,8 +566,8 @@
 		goto done;
 
 	result = cli_lsa_enum_trust_dom(hnd->cli, mem_ctx,
-					&hnd->pol, &enum_ctx, num_domains, 
-					names, dom_sids);
+					&hnd->pol, &enum_ctx, &pref_num_domains,
+					num_domains, names, dom_sids);
 done:
 	return result;
 }
Index: passdb/secrets.c
===================================================================
RCS file: /cvsroot/samba/source/passdb/secrets.c,v
retrieving revision 1.33
diff -u -r1.33 secrets.c
--- passdb/secrets.c	14 Apr 2002 09:44:14 -0000	1.33
+++ passdb/secrets.c	16 Apr 2002 12:35:31 -0000
@@ -2,6 +2,7 @@
    Unix SMB/CIFS implementation.
    Copyright (C) Andrew Tridgell 1992-2001
    Copyright (C) Andrew Bartlett      2002
+   Copyright (C) Rafal Szczesniak     2002
    
    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
@@ -383,25 +384,31 @@
  * The linked list is allocated on the supplied talloc context, caller gets to destory
  * when done.
  *
- * @param start_idx starting index, eg. we can start fetching
- *	  at third or sixth trusted domain entry
- * @param num_domains number of domain entries to fetch at one call
+ * @param ctx Allocation context
+ * @param enum_ctx Starting index, eg. we can start fetching at third
+ *        or sixth trusted domain entry. Zero is the first index.
+ *        Value it is set to is the enum context for the next enumeration.
+ * @param num_domains Number of domain entries to fetch at one call
+ * @param domains Pointer to array of trusted domain structs to be filled up
  *
- * @return list of trusted domains structs (unicode name, sid and password)
+ * @return nt status code of rpc response
  **/ 
 
-NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int start_idx, int max_num_domains, int *num_domains, TRUSTDOM ***domains)
+NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, int max_num_domains, int *num_domains, TRUSTDOM ***domains)
 {
 	TDB_LIST_NODE *keys, *k;
 	TRUSTDOM *dom = NULL;
 	char *pattern;
+	int start_idx;
 	uint32 idx = 0;
 	size_t size;
 	struct trusted_dom_pass *pass;
+	NTSTATUS status;
 
 	secrets_init();
 
 	*num_domains = 0;
+	start_idx = *enum_ctx;
 
 	/* generate searching pattern */
 	if (!(pattern = talloc_asprintf(ctx, "%s/*", SECRETS_DOMTRUST_ACCT_PASS))) {
@@ -410,13 +417,19 @@
 	}
 
 	DEBUG(5, ("secrets_get_trusted_domains: looking for %d domains, starting at index %d\n", 
-		  max_num_domains, start_idx));
+		  max_num_domains, *enum_ctx));
 
 	*domains = talloc_zero(ctx, sizeof(**domains)*max_num_domains);
 
 	/* fetching trusted domains' data and collecting them in a list */
 	keys = tdb_search_keys(tdb, pattern);
 
+	/* 
+	 * if there's no keys returned ie. no trusted domain,
+	 * return "no more entries" code
+	 */
+	status = NT_STATUS_NO_MORE_ENTRIES;
+
 	/* searching for keys in sectrets db -- way to go ... */
 	for (k = keys; k; k = k->next) {
 		char *secrets_key;
@@ -447,17 +460,26 @@
 				return NT_STATUS_NO_MEMORY;
 			}
 			
-				/* copy domain sid */
+			/* copy domain sid */
 			SMB_ASSERT(sizeof(dom->sid) == sizeof(pass->domain_sid));
 			memcpy(&(dom->sid), &(pass->domain_sid), sizeof(dom->sid));
 			
-				/* copy unicode domain name */
+			/* copy unicode domain name */
 			dom->name = talloc_strdup_w(ctx, pass->uni_name);
 			
-			(*domains)[*num_domains] = dom;
+			(*domains)[idx - start_idx] = dom;
 
+			*enum_ctx = idx + 1;
 			(*num_domains)++;
-			
+		
+			/* set proper status code to return */
+			if (k->next) {
+				/* there are yet some entries to enumerate */
+				status = NT_STATUS_MORE_ENTRIES;
+			} else {
+				/* this is the last entry in the whole enumeration */
+				status = NT_STATUS_OK;
+			}
 		}
 		
 		idx++;
@@ -466,12 +488,11 @@
 		SAFE_FREE(pass);
 	}
 	
-	DEBUG(5, ("secrets_get_trusted_domains: got %d of %d domains\n", 
-		  *num_domains, max_num_domains));
+	DEBUG(5, ("secrets_get_trusted_domains: got %d domains\n", *num_domains));
 
 	/* free the results of searching the keys */
 	tdb_search_list_free(keys);
 
-	return NT_STATUS_OK;
+	return status;
 }
 
Index: rpc_parse/parse_lsa.c
===================================================================
RCS file: /cvsroot/samba/source/rpc_parse/parse_lsa.c,v
retrieving revision 1.76
diff -u -r1.76 parse_lsa.c
--- rpc_parse/parse_lsa.c	14 Apr 2002 09:44:14 -0000	1.76
+++ rpc_parse/parse_lsa.c	16 Apr 2002 12:35:31 -0000
@@ -525,21 +525,19 @@
 ********************************************************************/
 
 void init_r_enum_trust_dom(TALLOC_CTX *ctx, LSA_R_ENUM_TRUST_DOM *r_e, uint32 enum_context,
-			   uint32 requested_num_domains, uint32 num_domains, TRUSTDOM **td)
+			   uint32 req_num_domains, uint32 num_domains, TRUSTDOM **td)
 {
 	int i;
 
         DEBUG(5, ("init_r_enum_trust_dom\n"));
 	
         r_e->enum_context = enum_context;
-	r_e->num_domains = 0;
+	r_e->num_domains = num_domains;
 	r_e->ptr_enum_domains = 0;
-	r_e->num_domains2 = 0;
-
-	if (num_domains == 0) {
-		r_e->status = NT_STATUS_NO_MORE_ENTRIES;
-
-	} else {
+	r_e->num_domains2 = num_domains;
+	
+	if (num_domains != 0) {
+	
 		/* 
 		 * allocating empty arrays of unicode headers, strings
 		 * and sids of enumerated trusted domains
@@ -558,10 +556,7 @@
 			r_e->status = NT_STATUS_NO_MEMORY;
 			return;
 		}
-		
-		r_e->num_domains = num_domains;
-		r_e->num_domains2 = num_domains;
-		
+				
 		for (i = 0; i < num_domains; i++) {
 			
 			/* don't know what actually is this for */
@@ -573,12 +568,6 @@
 			init_unistr2_w(ctx, &r_e->uni_domain_name[i], (td[i])->name);
 			
 		};
-
-		if (num_domains < requested_num_domains) {
-			r_e->status = NT_STATUS_NO_MORE_ENTRIES;
-		} else {
-			r_e->status = NT_STATUS_OK;
-		}
 	}
 
 }
Index: rpc_server/srv_lsa_nt.c
===================================================================
RCS file: /cvsroot/samba/source/rpc_server/srv_lsa_nt.c,v
retrieving revision 1.53
diff -u -r1.53 srv_lsa_nt.c
--- rpc_server/srv_lsa_nt.c	14 Apr 2002 09:44:15 -0000	1.53
+++ rpc_server/srv_lsa_nt.c	16 Apr 2002 12:35:31 -0000
@@ -3,8 +3,9 @@
  *  RPC Pipe client / server routines
  *  Copyright (C) Andrew Tridgell              1992-1997,
  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
- *  Copyright (C) Paul Ashton                       1997.
- *  Copyright (C) Jeremy Allison                    2001.
+ *  Copyright (C) Paul Ashton                       1997,
+ *  Copyright (C) Jeremy Allison                    2001,
+ *  Copyright (C) Rafal Szczesniak                  2002.
  *
  *  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
@@ -423,8 +424,12 @@
 {
 	struct lsa_info *info;
 	uint32 enum_context = q_u->enum_context;
-	/* it's set to 10 as a "our" preferred length */
-	uint32 max_num_domains = q_u->preferred_len < 10 ? q_u->preferred_len : 10;
+
+	/*
+	 * preferred length is set to 5 as a "our" preferred length
+	 * nt sets this parameter to 2
+	 */
+	uint32 max_num_domains = q_u->preferred_len < 5 ? q_u->preferred_len : 10;
 	TRUSTDOM **trust_doms;
 	uint32 num_domains;
 	NTSTATUS nt_status;
@@ -436,9 +441,14 @@
 	if (!(info->access & POLICY_VIEW_LOCAL_INFORMATION))
 		return NT_STATUS_ACCESS_DENIED;
 
-	nt_status = secrets_get_trusted_domains(p->mem_ctx, enum_context, max_num_domains, &num_domains, &trust_doms);
-	if (!NT_STATUS_IS_OK(nt_status)) {
+	nt_status = secrets_get_trusted_domains(p->mem_ctx, &enum_context, max_num_domains, &num_domains, &trust_doms);
+
+	if (!NT_STATUS_IS_OK(nt_status) &&
+	    !NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_ENTRIES) &&
+	    !NT_STATUS_EQUAL(nt_status, NT_STATUS_NO_MORE_ENTRIES)) {
 		return nt_status;
+	} else {
+		r_u->status = nt_status;
 	}
 
 	/* set up the lsa_enum_trust_dom response */
Index: rpc_server/srv_samr_nt.c
===================================================================
RCS file: /cvsroot/samba/source/rpc_server/srv_samr_nt.c,v
retrieving revision 1.87
diff -u -r1.87 srv_samr_nt.c
--- rpc_server/srv_samr_nt.c	11 Apr 2002 23:43:40 -0000	1.87
+++ rpc_server/srv_samr_nt.c	16 Apr 2002 12:35:31 -0000
@@ -324,7 +324,7 @@
 	pdb_free_sam(&pwd);
 
 	if (not_finished)
-		return STATUS_MORE_ENTRIES;
+		return NT_STATUS_MORE_ENTRIES;
 	else
 		return NT_STATUS_OK;
 }
@@ -749,7 +749,7 @@
 	DEBUG(10,("get_group_alias_entries: returning %d entries\n", *p_num_entries));
 
 	if (num_entries >= max_entries)
-		return STATUS_MORE_ENTRIES;
+		return NT_STATUS_MORE_ENTRIES;
 	return NT_STATUS_OK;
 }
 
@@ -1041,7 +1041,7 @@
 	total_data_size=num_account*struct_size;
 
 	if (enum_context+max_entries < num_account)
-		r_u->status = STATUS_MORE_ENTRIES;
+		r_u->status = NT_STATUS_MORE_ENTRIES;
 
 	DEBUG(5, ("_samr_query_dispinfo: %d\n", __LINE__));
 
Index: rpcclient/cmd_lsarpc.c
===================================================================
RCS file: /cvsroot/samba/source/rpcclient/cmd_lsarpc.c,v
retrieving revision 1.59
diff -u -r1.59 cmd_lsarpc.c
--- rpcclient/cmd_lsarpc.c	14 Apr 2002 11:21:24 -0000	1.59
+++ rpcclient/cmd_lsarpc.c	16 Apr 2002 12:35:31 -0000
@@ -2,7 +2,8 @@
    Unix SMB/CIFS implementation.
    RPC pipe client
 
-   Copyright (C) Tim Potter 2000
+   Copyright (C) Tim Potter              2000
+   Copyright (C) Rafal Szczesniak        2002
 
    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
@@ -188,17 +189,31 @@
 	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
 	DOM_SID *domain_sids;
 	char **domain_names;
+
+	/* defaults, but may be changed using params */
 	uint32 enum_ctx = 0;
-	uint32 num_domains;
+	uint32 preferred_maxnum = 5;
+	uint32 num_domains = 0;
 	int i;
 
-	if (argc != 1) {
-		printf("Usage: %s\n", argv[0]);
+	if (argc > 3) {
+		printf("Usage: %s [preferred max number (%d)] [enum context (0)]\n",
+			argv[0], preferred_maxnum);
 		return NT_STATUS_OK;
 	}
 
+	/* enumeration context */
+	if (argc >= 2 && argv[1]) {
+		preferred_maxnum = atoi(argv[1]);
+	}	
+
+	/* preferred maximum number */
+	if (argc == 3 && argv[2]) {
+		enum_ctx = atoi(argv[2]);
+	}	
+
 	result = cli_lsa_open_policy(cli, mem_ctx, True, 
-				     SEC_RIGHTS_MAXIMUM_ALLOWED,
+				     POLICY_VIEW_LOCAL_INFORMATION,
 				     &pol);
 
 	if (!NT_STATUS_IS_OK(result))
@@ -207,14 +222,14 @@
 	/* Lookup list of trusted domains */
 
 	result = cli_lsa_enum_trust_dom(cli, mem_ctx, &pol, &enum_ctx,
-					&num_domains, &domain_names,
-					&domain_sids);
-
-	if (!NT_STATUS_IS_OK(result))
-		goto done;
-
-	/* Print results */
+						&preferred_maxnum, &num_domains,
+						&domain_names, &domain_sids);
+	if (!NT_STATUS_IS_OK(result) &&
+	    !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
+	    !NT_STATUS_EQUAL(result, NT_STATUS_MORE_ENTRIES))
+	    goto done;
 
+	/* Print results: list of names and sids returned in this response. */	 
 	for (i = 0; i < num_domains; i++) {
 		fstring sid_str;
 


More information about the samba-technical mailing list