svn commit: samba r19184 - in branches/SAMBA_3_0/source: libsmb smbd utils

vlendec at samba.org vlendec at samba.org
Mon Oct 9 07:17:38 GMT 2006


Author: vlendec
Date: 2006-10-09 07:17:37 +0000 (Mon, 09 Oct 2006)
New Revision: 19184

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

Log:
W2k3 returns its name for the GetServerInfo RAP call. Do the same.

Implement 'net rap server name'.

Volker

Modified:
   branches/SAMBA_3_0/source/libsmb/clirap2.c
   branches/SAMBA_3_0/source/smbd/lanman.c
   branches/SAMBA_3_0/source/utils/net_rap.c


Changeset:
Modified: branches/SAMBA_3_0/source/libsmb/clirap2.c
===================================================================
--- branches/SAMBA_3_0/source/libsmb/clirap2.c	2006-10-09 07:15:27 UTC (rev 19183)
+++ branches/SAMBA_3_0/source/libsmb/clirap2.c	2006-10-09 07:17:37 UTC (rev 19184)
@@ -1414,7 +1414,63 @@
   return(res == 0 || res == ERRmoredata);
 }
 
+BOOL cli_get_server_name(TALLOC_CTX *mem_ctx, struct cli_state *cli,
+			 char **servername)
+{
+	char *rparam = NULL;
+	char *rdata = NULL;
+	unsigned int rdrcnt,rprcnt;
+	char *p;
+	char param[WORDSIZE                       /* api number    */
+		   +sizeof(RAP_WserverGetInfo_REQ) /* req string    */
+		   +sizeof(RAP_SERVER_INFO_L1)     /* return string */
+		   +WORDSIZE                       /* info level    */
+		   +WORDSIZE];                     /* buffer size   */
+	BOOL res = False;
+	fstring tmp;
+  
+	/* send a SMBtrans command with api NetServerGetInfo */
+	p = make_header(param, RAP_WserverGetInfo,
+			RAP_WserverGetInfo_REQ, RAP_SERVER_INFO_L1);
+	PUTWORD(p, 1); /* info level */
+	PUTWORD(p, CLI_BUFFER_SIZE);
+	
+	if (!cli_api(cli, 
+		     param, PTR_DIFF(p,param), 8, /* params, length, max */
+		     NULL, 0, CLI_BUFFER_SIZE, /* data, length, max */
+		     &rparam, &rprcnt,         /* return params, return size */
+		     &rdata, &rdrcnt           /* return data, return size */
+		    )) {
+		goto failed;
+	}
+    
+	if (GETRES(rparam) != 0) {
+		goto failed;
+	}
 
+	if (rdrcnt < 16) {
+		DEBUG(10, ("invalid data count %d, expected >= 16\n", rdrcnt));
+		goto failed;
+	}
+
+	if (pull_ascii(tmp, rdata, sizeof(tmp)-1, 16, STR_TERMINATE) == -1) {
+		DEBUG(10, ("pull_ascii failed\n"));
+		goto failed;
+	}
+
+	if (!(*servername = talloc_strdup(mem_ctx, tmp))) {
+		DEBUG(1, ("talloc_strdup failed\n"));
+		goto failed;
+	}
+
+	res = True;
+
+ failed:
+	SAFE_FREE(rparam);
+	SAFE_FREE(rdata);
+	return res;
+}
+
 /*************************************************************************
 *
 * Function Name:  cli_ns_check_server_type

Modified: branches/SAMBA_3_0/source/smbd/lanman.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/lanman.c	2006-10-09 07:15:27 UTC (rev 19183)
+++ branches/SAMBA_3_0/source/smbd/lanman.c	2006-10-09 07:17:37 UTC (rev 19184)
@@ -2677,7 +2677,7 @@
 	p = *rdata;
 	p2 = p + struct_len;
 	if (uLevel != 20) {
-		srvstr_push(NULL, p,get_local_machine_name(),16, 
+		srvstr_push(NULL, p,global_myname(),16, 
 			STR_ASCII|STR_UPPER|STR_TERMINATE);
   	}
 	p += 16;

Modified: branches/SAMBA_3_0/source/utils/net_rap.c
===================================================================
--- branches/SAMBA_3_0/source/utils/net_rap.c	2006-10-09 07:15:27 UTC (rev 19183)
+++ branches/SAMBA_3_0/source/utils/net_rap.c	2006-10-09 07:17:37 UTC (rev 19184)
@@ -407,12 +407,40 @@
 	net_common_flags_usage(argc, argv);
 	return -1;
 }
+
+static int net_rap_server_name(int argc, const char *argv[])
+{
+	struct cli_state *cli;
+	char *name;
+
+	if (!(cli = net_make_ipc_connection(0))) 
+                return -1;
+
+	if (!cli_get_server_name(NULL, cli, &name)) {
+		d_fprintf(stderr, "cli_get_server_name failed\n");
+		cli_shutdown(cli);
+		return -1;
+	}
+
+	d_printf("Server name = %s\n", name);
+
+	TALLOC_FREE(name);
+	cli_shutdown(cli);
+	return 0;
+}
 		    
 int net_rap_server(int argc, const char **argv)
 {
 	struct cli_state *cli;
 	int ret;
-	
+
+	if (argc > 0) {
+		if (!strequal(argv[0], "name")) {
+			return net_rap_server_usage(argc-1, argv+1);
+		}
+		return net_rap_server_name(argc, argv);
+	}
+
 	if (!(cli = net_make_ipc_connection(0))) 
                 return -1;
 



More information about the samba-cvs mailing list