1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Show information about the remote server, as offered by
* NetServerGetInfo with SERVER_INFO_101
*/
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libintl.h>
#include <libmlrpc/libmlrpc.h>
#include <netsmb/smb_lib.h>
#include "srvsvc1_clnt.h"
#include "common.h"
static int get_info(smb_ctx_t *);
void
info_usage(void)
{
printf(gettext("usage: smbutil info [connection options] //"
"[workgroup;][user[:password]@]server\n"));
exit(1);
}
int
cmd_info(int argc, char *argv[])
{
struct smb_ctx *ctx;
int error, err2, opt;
if (argc < 2)
info_usage();
error = smb_ctx_alloc(&ctx);
if (error)
return (error);
error = smb_ctx_scan_argv(ctx, argc, argv,
SMBL_SERVER, SMBL_SERVER, USE_WILDCARD);
if (error)
goto out;
error = smb_ctx_readrc(ctx);
if (error)
goto out;
while ((opt = getopt(argc, argv, STDPARAM_OPT)) != EOF) {
if (opt == '?')
info_usage();
error = smb_ctx_opt(ctx, opt, optarg);
if (error)
goto out;
}
smb_ctx_setshare(ctx, "IPC$", USE_IPC);
/*
* Resolve the server address,
* setup derived defaults.
*/
error = smb_ctx_resolve(ctx);
if (error)
goto out;
/*
* Have server, share, etc. from above:
* smb_ctx_scan_argv, option settings.
* Get the session and tree.
*/
again:
error = smb_ctx_get_ssn(ctx);
if (error == EAUTH) {
err2 = smb_get_authentication(ctx);
if (err2 == 0)
goto again;
}
if (error) {
smb_error(gettext("//%s: login failed"),
error, ctx->ct_fullserver);
goto out;
}
error = smb_ctx_get_tree(ctx);
if (error) {
smb_error(gettext("//%s/%s: tree connect failed"),
error, ctx->ct_fullserver, ctx->ct_origshare);
goto out;
}
/*
* Have IPC$ tcon. Get the server info.
*/
error = get_info(ctx);
if (error)
smb_error("cannot get server info.", error);
out:
smb_ctx_free(ctx);
return (error);
}
int
get_info(smb_ctx_t *ctx)
{
char pf_unk[32];
mlrpc_handle_t handle;
ndr_service_t *svc;
union mslm_NetServerGetInfo_ru res;
struct mslm_SERVER_INFO_101 *sv101;
char *platform_name;
int err;
/*
* Create an RPC handle using the smb_ctx we already have.
* Just local allocation and initialization.
*/
srvsvc1_initialize();
svc = ndr_svc_lookup_name("srvsvc");
if (svc == NULL)
return (ENOENT);
err = mlrpc_clh_create(&handle, ctx);
if (err)
return (err);
/*
* Try to bind to the RPC service. If it fails,
* just return the error and the caller will
* fall back to RAP.
*/
err = mlrpc_clh_bind(&handle, svc);
if (err)
goto out;
err = srvsvc_net_server_getinfo(&handle,
ctx->ct_fullserver, 101, &res);
if (err)
goto out;
sv101 = res.info101;
switch (sv101->sv101_platform_id) {
case SV_PLATFORM_ID_DOS:
platform_name = "DOS";
break;
case SV_PLATFORM_ID_OS2:
platform_name = "OS2";
break;
case SV_PLATFORM_ID_NT:
platform_name = "NT";
break;
case SV_PLATFORM_ID_OSF:
platform_name = "OSF";
break;
case SV_PLATFORM_ID_VMS:
platform_name = "VMS";
break;
default:
platform_name = pf_unk;
snprintf(pf_unk, sizeof (pf_unk), "(%d)",
sv101->sv101_platform_id);
break;
}
printf("server info:\n");
printf(" platform_id %s\n", platform_name);
printf(" vers.major %d\n", sv101->sv101_version_major);
printf(" vers.minor %d\n", sv101->sv101_version_minor);
if (smb_verbose)
printf(" type_flags 0x%x\n", sv101->sv101_type);
printf(" name \"%s\"\n", sv101->sv101_name);
printf(" comment \"%s\"\n", sv101->sv101_comment);
out:
(void) mlrpc_clh_free(&handle);
return (err);
}
|