diff options
author | Volker Lendecke <vlendec@samba.org> | 2006-10-09 07:17:37 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:15:20 -0500 |
commit | cfed7a5a71aab48b1d5b758df318b991a95592a5 (patch) | |
tree | 5ebaab4d9b2dd20067b8194b9102bf54c4cb255d | |
parent | d63a3e05a23ffb016578c3daa8b48d6fc32e1e8c (diff) | |
download | samba-cfed7a5a71aab48b1d5b758df318b991a95592a5.tar.gz samba-cfed7a5a71aab48b1d5b758df318b991a95592a5.tar.bz2 samba-cfed7a5a71aab48b1d5b758df318b991a95592a5.zip |
r19184: W2k3 returns its name for the GetServerInfo RAP call. Do the same.
Implement 'net rap server name'.
Volker
(This used to be commit 919385ed2a2a07e848bc0baaac9ed3d1964d4386)
-rw-r--r-- | source3/libsmb/clirap2.c | 56 | ||||
-rw-r--r-- | source3/smbd/lanman.c | 2 | ||||
-rw-r--r-- | source3/utils/net_rap.c | 30 |
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; |