svn commit: samba r5201 - in trunk/source/nsswitch: .

vlendec at samba.org vlendec at samba.org
Thu Feb 3 14:28:55 GMT 2005


Author: vlendec
Date: 2005-02-03 14:28:54 +0000 (Thu, 03 Feb 2005)
New Revision: 5201

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

Log:
Add a GETDCNAME request -- be able to issue that async.

Volker

Modified:
   trunk/source/nsswitch/wbinfo.c
   trunk/source/nsswitch/winbindd.c
   trunk/source/nsswitch/winbindd_dual.c
   trunk/source/nsswitch/winbindd_misc.c
   trunk/source/nsswitch/winbindd_nss.h
   trunk/source/nsswitch/winbindd_util.c


Changeset:
Modified: trunk/source/nsswitch/wbinfo.c
===================================================================
--- trunk/source/nsswitch/wbinfo.c	2005-02-03 13:13:01 UTC (rev 5200)
+++ trunk/source/nsswitch/wbinfo.c	2005-02-03 14:28:54 UTC (rev 5201)
@@ -316,6 +316,32 @@
 	return True;
 }
 
+/* Get a foreign DC's name */
+static BOOL wbinfo_getdcname(const char *domain_name)
+{
+	struct winbindd_request request;
+	struct winbindd_response response;
+
+	ZERO_STRUCT(request);
+	ZERO_STRUCT(response);
+
+	fstrcpy(request.domain_name, domain_name);
+
+	/* Send request */
+
+	if (winbindd_request(WINBINDD_GETDCNAME, &request, &response) !=
+	    NSS_STATUS_SUCCESS) {
+		d_printf("Could not get dc name for %s\n", domain_name);
+		return False;
+	}
+
+	/* Display response */
+
+	d_printf("%s\n", response.data.dc_name);
+
+	return True;
+}
+
 /* Check trust account password */
 
 static BOOL wbinfo_check_secret(void)
@@ -1058,6 +1084,7 @@
 	OPT_GET_AUTH_USER,
 	OPT_DOMAIN_NAME,
 	OPT_SEQUENCE,
+	OPT_GETDCNAME,
 	OPT_USERSIDS
 };
 
@@ -1102,6 +1129,8 @@
 		{ "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" },
  		{ "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
 		{ "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
+		{ "getdcname", 0, POPT_ARG_STRING, &string_arg, OPT_GETDCNAME,
+		  "Get a DC name for a foreign domain", "domainname" },
 		{ "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
 		{ "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
 		{ "domain", 0, POPT_ARG_STRING, &opt_domain_name, OPT_DOMAIN_NAME, "Define to the domain to restrict operation", "domain" },
@@ -1327,6 +1356,9 @@
 		case OPT_GET_AUTH_USER:
 			wbinfo_get_auth_user();
 			break;
+		case OPT_GETDCNAME:
+			wbinfo_getdcname(string_arg);
+			break;
 		/* generic configuration options */
 		case OPT_DOMAIN_NAME:
 			break;

Modified: trunk/source/nsswitch/winbindd.c
===================================================================
--- trunk/source/nsswitch/winbindd.c	2005-02-03 13:13:01 UTC (rev 5200)
+++ trunk/source/nsswitch/winbindd.c	2005-02-03 14:28:54 UTC (rev 5201)
@@ -274,6 +274,7 @@
 	{ WINBINDD_DOMAIN_INFO, winbindd_domain_info, "DOMAIN_INFO" },
 	{ WINBINDD_NETBIOS_NAME, winbindd_netbios_name, "NETBIOS_NAME" },
 	{ WINBINDD_PRIV_PIPE_DIR, winbindd_priv_pipe_dir, "WINBINDD_PRIV_PIPE_DIR" },
+	{ WINBINDD_GETDCNAME, winbindd_getdcname_async, "GETDCNAME" },
 
 	/* WINS functions */
 

Modified: trunk/source/nsswitch/winbindd_dual.c
===================================================================
--- trunk/source/nsswitch/winbindd_dual.c	2005-02-03 13:13:01 UTC (rev 5200)
+++ trunk/source/nsswitch/winbindd_dual.c	2005-02-03 14:28:54 UTC (rev 5201)
@@ -363,6 +363,7 @@
 	  "LIST_TRUSTDOM" },
 	{ WINBINDD_INIT_CONNECTION, winbindd_init_connection,
 	  "INIT_CONNECTION" },
+	{ WINBINDD_GETDCNAME, winbindd_getdcname, "GETDCNAME" },
 
 	/* End of list */
 

Modified: trunk/source/nsswitch/winbindd_misc.c
===================================================================
--- trunk/source/nsswitch/winbindd_misc.c	2005-02-03 13:13:01 UTC (rev 5200)
+++ trunk/source/nsswitch/winbindd_misc.c	2005-02-03 14:28:54 UTC (rev 5201)
@@ -167,7 +167,79 @@
 	return WINBINDD_OK;
 }
 
+enum winbindd_result winbindd_getdcname_async(struct winbindd_cli_state *state)
+{
+	struct winbindd_domain *domain;
 
+	state->request.domain_name
+		[sizeof(state->request.domain_name)-1] = '\0';
+
+	DEBUG(3, ("[%5lu]: Get DC name for %s\n", (unsigned long)state->pid,
+		  state->request.domain_name));
+
+	domain = find_our_domain();
+	if (domain == NULL) {
+                DEBUG(1, ("Cannot find our own domain!\n"));
+		return WINBINDD_ERROR;
+	}
+
+	return async_request(state->mem_ctx, &domain->child,
+			     &state->request, &state->response,
+			     request_finished_cont, state);
+}
+
+enum winbindd_result winbindd_getdcname(struct winbindd_cli_state *state)
+{
+	struct winbindd_domain *domain;
+	fstring dcname_slash;
+	char *p;
+	struct rpc_pipe_client *cli;
+	NTSTATUS result;
+
+	state->request.domain_name
+		[sizeof(state->request.domain_name)-1] = '\0';
+
+	DEBUG(3, ("[%5lu]: Get DC name for %s\n", (unsigned long)state->pid,
+		  state->request.domain_name));
+
+	domain = find_our_domain();
+	if (domain == NULL) {
+                DEBUG(1, ("Cannot find our own domain!\n"));
+		return WINBINDD_ERROR;
+	}
+
+	{
+		/* These var's can be ignored -- we're not requesting
+		   anything in the credential chain here */
+		unsigned char *session_key;
+		DOM_CRED *creds;
+		result = cm_connect_netlogon(domain, state->mem_ctx, &cli,
+					     &session_key, &creds);
+	}
+
+	if (!NT_STATUS_IS_OK(result)) {
+		DEBUG(1, ("Can't contact our the NETLOGON pipe\n"));
+		return WINBINDD_ERROR;
+	}
+
+	result = rpccli_netlogon_getdcname(cli, state->mem_ctx, domain->dcname,
+					   state->request.domain_name,
+					   dcname_slash);
+
+	if (!NT_STATUS_IS_OK(result)) {
+		DEBUG(5, ("Error requesting DCname: %s\n", nt_errstr(result)));
+		return WINBINDD_ERROR;
+	}
+
+	p = dcname_slash;
+	if (*p == '\\') p+=1;
+	if (*p == '\\') p+=1;
+
+	fstrcpy(state->response.data.dc_name, p);
+
+	return WINBINDD_OK;
+}
+
 enum winbindd_result winbindd_show_sequence(struct winbindd_cli_state *state)
 {
 	struct winbindd_domain *domain;

Modified: trunk/source/nsswitch/winbindd_nss.h
===================================================================
--- trunk/source/nsswitch/winbindd_nss.h	2005-02-03 13:13:01 UTC (rev 5200)
+++ trunk/source/nsswitch/winbindd_nss.h	2005-02-03 14:28:54 UTC (rev 5201)
@@ -84,6 +84,7 @@
 
 	WINBINDD_DOMAIN_INFO,	/* Most of what we know from
 				   struct winbindd_domain */
+	WINBINDD_GETDCNAME,	/* Issue a GetDCName Request */
 
 	WINBINDD_SHOW_SEQUENCE, /* display sequence numbers of domains */
 
@@ -263,6 +264,7 @@
 		} info;
 		fstring domain_name;
 		fstring netbios_name;
+		fstring dc_name;
 
 		struct auth_reply {
 			uint32 nt_status;

Modified: trunk/source/nsswitch/winbindd_util.c
===================================================================
--- trunk/source/nsswitch/winbindd_util.c	2005-02-03 13:13:01 UTC (rev 5200)
+++ trunk/source/nsswitch/winbindd_util.c	2005-02-03 14:28:54 UTC (rev 5201)
@@ -395,7 +395,7 @@
 	state->request.data.init_conn.dcname
 		[sizeof(state->request.data.init_conn.dcname)-1]='\0';
 
-	domain = find_domain_from_name(state->request.domain_name);
+	domain = find_domain_from_name_noinit(state->request.domain_name);
 
 	if (domain == NULL) {
 		DEBUG(1, ("Could not find domain %s\n",
@@ -499,6 +499,25 @@
 	return NULL;
 }
 
+struct winbindd_domain *find_domain_from_name_noinit(const char *domain_name)
+{
+	struct winbindd_domain *domain;
+
+	/* Search through list */
+
+	for (domain = domain_list(); domain != NULL; domain = domain->next) {
+		if (strequal(domain_name, domain->name) ||
+		    (domain->alt_name[0] &&
+		     strequal(domain_name, domain->alt_name))) {
+			return domain;
+		}
+	}
+
+	/* Not found */
+
+	return NULL;
+}
+
 /* Given a domain sid, return the struct winbindd domain info for it */
 
 struct winbindd_domain *find_domain_from_sid(const DOM_SID *sid)



More information about the samba-cvs mailing list