3328 smbutil view does't work with Win2008 and later
[unleashed.git] / usr / src / cmd / fs.d / smbclnt / smbutil / shares_rpc.c
blob221d6f077baafb557108546f4e3356ab175a09b1
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
17 * Share enumeration using Remote Procedure Call (RPC)
20 #include <sys/types.h>
22 #include <errno.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #include <libmlrpc/libmlrpc.h>
28 #include <netsmb/smbfs_api.h>
29 #include "srvsvc1_clnt.h"
30 #include "common.h"
32 int
33 share_enum_rpc(struct smb_ctx *ctx, char *server)
35 mlrpc_handle_t handle;
36 ndr_service_t *svc;
37 union mslm_NetShareEnum_ru res;
38 struct mslm_NetShareInfo_1 *nsi1;
39 int err, i, count;
42 * Create an RPC handle using the smb_ctx we already have.
43 * Just local allocation and initialization.
45 srvsvc1_initialize();
46 svc = ndr_svc_lookup_name("srvsvc");
47 if (svc == NULL)
48 return (ENOENT);
50 err = mlrpc_clh_create(&handle, ctx);
51 if (err)
52 return (err);
55 * Try to bind to the RPC service. If it fails,
56 * just return the error and the caller will
57 * fall back to RAP.
59 err = mlrpc_clh_bind(&handle, svc);
60 if (err)
61 goto out;
63 err = srvsvc_net_share_enum(&handle, server, 1, &res);
64 if (err)
65 goto out;
67 /* Print the header line. */
68 view_print_share(NULL, 0, NULL);
70 /* Print the share list. */
71 count = res.bufptr1->entriesread;
72 i = 0, nsi1 = res.bufptr1->entries;
73 while (i < count) {
74 /* Convert UTF-8 to local code set? */
75 view_print_share((char *)nsi1->shi1_netname,
76 nsi1->shi1_type, (char *)nsi1->shi1_comment);
77 i++, nsi1++;
80 out:
81 (void) mlrpc_clh_free(&handle);
82 return (err);