2 * Copyright (c) 2000, Boris Popov
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * $Id: view.c,v 1.9 2004/12/13 00:25:39 lindak Exp $
36 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
39 #include <sys/types.h>
49 #include <netsmb/smb.h>
50 #include <netsmb/smb_lib.h>
51 #include <netsmb/smb_netshareenum.h>
55 int enum_shares(smb_ctx_t
*);
56 void print_shares(int, int, struct share_info
*);
61 printf(gettext("usage: smbutil view [connection options] //"
62 "[workgroup;][user[:password]@]server\n"));
67 cmd_view(int argc
, char *argv
[])
75 error
= smb_ctx_alloc(&ctx
);
79 error
= smb_ctx_scan_argv(ctx
, argc
, argv
,
80 SMBL_SERVER
, SMBL_SERVER
, USE_WILDCARD
);
84 error
= smb_ctx_readrc(ctx
);
88 while ((opt
= getopt(argc
, argv
, STDPARAM_OPT
)) != EOF
) {
91 error
= smb_ctx_opt(ctx
, opt
, optarg
);
96 smb_ctx_setshare(ctx
, "IPC$", USE_IPC
);
99 * Resolve the server address,
100 * setup derived defaults.
102 error
= smb_ctx_resolve(ctx
);
107 * Have server, share, etc. from above:
108 * smb_ctx_scan_argv, option settings.
109 * Get the session and tree.
112 error
= smb_ctx_get_ssn(ctx
);
113 if (error
== EAUTH
) {
114 err2
= smb_get_authentication(ctx
);
119 smb_error(gettext("//%s: login failed"),
120 error
, ctx
->ct_fullserver
);
124 error
= smb_ctx_get_tree(ctx
);
126 smb_error(gettext("//%s/%s: tree connect failed"),
127 error
, ctx
->ct_fullserver
, ctx
->ct_origshare
);
132 * Have IPC$ tcon, now list shares.
133 * This prints its own errors.
135 error
= enum_shares(ctx
);
143 #ifdef I18N /* not defined, put here so xgettext(1) can find strings */
144 static char *shtype
[] = {
147 gettext("device"), /* Communications device */
148 gettext("IPC"), /* Inter process communication */
152 static char *shtype
[] = {
155 "device", /* Communications device */
156 "IPC", /* IPC Inter process communication */
162 enum_shares(smb_ctx_t
*ctx
)
164 struct share_info
*share_info
;
165 int error
, entries
, total
;
168 * XXX: Later, try RPC first,
169 * then fall back to RAP...
171 error
= smb_netshareenum(ctx
, &entries
, &total
, &share_info
);
173 smb_error(gettext("//%s failed to list shares"),
174 error
, ctx
->ct_fullserver
);
177 print_shares(entries
, total
, share_info
);
182 print_shares(int entries
, int total
,
183 struct share_info
*share_info
)
185 struct share_info
*ep
;
188 printf(gettext("Share Type Comment\n"));
189 printf("-------------------------------\n");
191 for (ep
= share_info
, i
= 0; i
< entries
; i
++, ep
++) {
192 int sti
= ep
->type
& STYPE_MASK
;
193 if (sti
> STYPE_UNKNOWN
)
195 printf("%-12s %-10s %s\n", ep
->netname
,
196 gettext(shtype
[sti
]),
197 ep
->remark
? ep
->remark
: "");
201 printf(gettext("\n%d shares listed from %d available\n"),