summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/libsmb/clirap2.c56
-rw-r--r--source3/smbd/lanman.c2
-rw-r--r--source3/utils/net_rap.c30
3 files changed, 86 insertions, 2 deletions
diff --git a/source3/libsmb/clirap2.c b/source3/libsmb/clirap2.c
index 3c23310f66..d6a44f4ea2 100644
--- a/source3/libsmb/clirap2.c
+++ b/source3/libsmb/clirap2.c
@@ -1414,6 +1414,62 @@ BOOL cli_get_server_type(struct cli_state *cli, uint32 *pstype)
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;
+}
/*************************************************************************
*
diff --git a/source3/smbd/lanman.c b/source3/smbd/lanman.c
index 637d5b4120..8a16c2c044 100644
--- a/source3/smbd/lanman.c
+++ b/source3/smbd/lanman.c
@@ -2677,7 +2677,7 @@ static BOOL api_RNetServerGetInfo(connection_struct *conn,uint16 vuid, char *par
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;
diff --git a/source3/utils/net_rap.c b/source3/utils/net_rap.c
index ef5df43535..9084122d68 100644
--- a/source3/utils/net_rap.c
+++ b/source3/utils/net_rap.c
@@ -407,12 +407,40 @@ int net_rap_server_usage(int argc, const char **argv)
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;