1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 * Copyright 2013 Nexenta Systems, Inc. All rights reserved. 27 */ 28 29 /* 30 * A few excerpts from lib/smbsrv/libmlsvc 31 * See longer comment in srvsvc1.ndl 32 */ 33 34 #include <sys/errno.h> 35 #include <stdio.h> 36 #include <time.h> 37 #include <strings.h> 38 #include <time.h> 39 40 #include <libmlrpc/libmlrpc.h> 41 #include "srvsvc1_clnt.h" 42 43 static ndr_service_t srvsvc_service = { 44 "SRVSVC", /* name */ 45 "Server services", /* desc */ 46 "\\srvsvc", /* endpoint */ 47 "\\PIPE\\ntsvcs", /* sec_addr_port */ 48 "4b324fc8-1670-01d3-1278-5a47bf6ee188", 3, /* abstract */ 49 NDR_TRANSFER_SYNTAX_UUID, 2, /* transfer */ 50 0, /* no bind_instance_size */ 51 0, /* no bind_req() */ 52 0, /* no unbind_and_close() */ 53 0, /* use generic_call_stub() */ 54 &TYPEINFO(srvsvc_interface), /* interface_ti */ 55 NULL /* stub_table */ 56 }; 57 58 /* 59 * srvsvc_initialize 60 * 61 * This function registers the SRVSVC RPC interface with the RPC runtime 62 * library. It must be called in order to use either the client side 63 * or the server side functions. 64 */ 65 void 66 srvsvc1_initialize(void) 67 { 68 static int init_done; 69 if (init_done) 70 return; 71 init_done = 1; 72 (void) ndr_svc_register(&srvsvc_service); 73 } 74 75 /* 76 * Client-side stub for NetServerGetInfo 77 */ 78 int 79 srvsvc_net_server_getinfo(mlrpc_handle_t *handle, char *server, 80 int level, union mslm_NetServerGetInfo_ru *resp) 81 { 82 struct mslm_NetServerGetInfo arg; 83 int len, opnum, rc; 84 85 opnum = SRVSVC_OPNUM_NetServerGetInfo; 86 bzero(&arg, sizeof (arg)); 87 88 len = strlen(server) + 4; 89 arg.servername = ndr_rpc_malloc(handle, len); 90 if (arg.servername == NULL) 91 return (ENOMEM); 92 93 (void) snprintf((char *)arg.servername, len, "\\\\%s", server); 94 arg.level = level; 95 96 rc = ndr_rpc_call(handle, opnum, &arg); 97 if ((rc != 0) || (arg.status != 0)) 98 return (EIO); 99 100 *resp = arg.result.ru; 101 return (0); 102 } 103 104 /* 105 * Client-side stub for NetShareEnum 106 */ 107 int 108 srvsvc_net_share_enum(mlrpc_handle_t *handle, char *server, 109 int level, union mslm_NetShareEnum_ru *resp) 110 { 111 /* Any enum result type is OK for nres. */ 112 struct mslm_NetShareInfo_0_result nres; 113 struct mslm_NetShareEnum arg; 114 int len, opnum, rc; 115 116 opnum = SRVSVC_OPNUM_NetShareEnum; 117 bzero(&nres, sizeof (nres)); 118 bzero(&arg, sizeof (arg)); 119 120 len = strlen(server) + 4; 121 arg.servername = ndr_rpc_malloc(handle, len); 122 if (arg.servername == NULL) 123 return (ENOMEM); 124 125 (void) snprintf((char *)arg.servername, len, "\\\\%s", server); 126 arg.level = level; 127 arg.result.level = level; 128 arg.result.ru.bufptr0 = &nres; 129 arg.prefmaxlen = 0xFFFFFFFF; 130 arg.resume_handle = NULL; 131 132 rc = ndr_rpc_call(handle, opnum, &arg); 133 if ((rc != 0) || (arg.status != 0)) 134 return (EIO); 135 136 *resp = arg.result.ru; 137 return (0); 138 } 139