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.
6  *
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.
10  */
11 
12 /*
13  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
14  */
15 
16 /*
17  * Share enumeration using Remote Procedure Call (RPC)
18  */
19 
20 #include <sys/types.h>
21 
22 #include <errno.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 
27 #include <libmlrpc/libmlrpc.h>
28 #include <netsmb/smbfs_api.h>
29 #include "srvsvc1_clnt.h"
30 #include "common.h"
31 
32 int
share_enum_rpc(struct smb_ctx * ctx,char * server)33 share_enum_rpc(struct smb_ctx *ctx, char *server)
34 {
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;
40 
41 	/*
42 	 * Create an RPC handle using the smb_ctx we already have.
43 	 * Just local allocation and initialization.
44 	 */
45 	srvsvc1_initialize();
46 	svc = ndr_svc_lookup_name("srvsvc");
47 	if (svc == NULL)
48 		return (ENOENT);
49 
50 	err = mlrpc_clh_create(&handle, ctx);
51 	if (err)
52 		return (err);
53 
54 	/*
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.
58 	 */
59 	err = mlrpc_clh_bind(&handle, svc);
60 	if (err)
61 		goto out;
62 
63 	err = srvsvc_net_share_enum(&handle, server, 1, &res);
64 	if (err)
65 		goto out;
66 
67 	/* Print the header line. */
68 	view_print_share(NULL, 0, NULL);
69 
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++;
78 	}
79 
80 out:
81 	(void) mlrpc_clh_free(&handle);
82 	return (err);
83 }
84