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 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #include <sys/ddi.h> 27 #include <sys/sunddi.h> 28 #include <sys/cmn_err.h> 29 #include <smbsrv/smb_door_svc.h> 30 #include <smbsrv/smb_common_door.h> 31 #include <smbsrv/smb_vops.h> 32 #include <sys/stat.h> 33 34 35 void 36 smb_user_nonauth_logon(uint32_t audit_sid) 37 { 38 char *arg, *rsp; 39 size_t arg_size, rsp_size; 40 41 arg = smb_kdr_encode_common(SMB_DR_USER_NONAUTH_LOGON, 42 &audit_sid, xdr_uint32_t, &arg_size); 43 44 if (arg != NULL) { 45 rsp = smb_kdoor_clnt_upcall(arg, arg_size, NULL, 0, &rsp_size); 46 smb_kdoor_clnt_free(arg, arg_size, rsp, rsp_size); 47 } 48 } 49 50 void 51 smb_user_auth_logoff(uint32_t audit_sid) 52 { 53 char *arg, *rsp; 54 size_t arg_size, rsp_size; 55 56 arg = smb_kdr_encode_common(SMB_DR_USER_AUTH_LOGOFF, 57 &audit_sid, xdr_uint32_t, &arg_size); 58 59 if (arg != NULL) { 60 rsp = smb_kdoor_clnt_upcall(arg, arg_size, NULL, 0, &rsp_size); 61 smb_kdoor_clnt_free(arg, arg_size, rsp, rsp_size); 62 } 63 } 64 65 smb_token_t * 66 smb_get_token(netr_client_t *clnt_info) 67 { 68 char *arg, *rsp; 69 size_t arg_size, rsp_size; 70 smb_token_t *token = NULL; 71 72 if ((arg = smb_dr_encode_arg_get_token(clnt_info, &arg_size)) == NULL) 73 return (NULL); 74 75 rsp = smb_kdoor_clnt_upcall(arg, arg_size, NULL, 0, &rsp_size); 76 if (rsp) { 77 token = smb_dr_decode_res_token(rsp + SMB_DR_DATA_OFFSET, 78 rsp_size - SMB_DR_DATA_OFFSET); 79 } 80 81 smb_kdoor_clnt_free(arg, arg_size, rsp, rsp_size); 82 return (token); 83 84 } 85 86 /* 87 * This returns the number of snapshots for the dataset 88 * of the path provided. 89 */ 90 uint32_t 91 smb_upcall_vss_get_count(char *resource_path) 92 { 93 char *argp, *rsp; 94 size_t arg_size, rsp_size; 95 uint32_t count = 0; 96 97 arg_size = strlen(resource_path); 98 99 argp = smb_dr_encode_string(SMB_DR_VSS_GET_COUNT, resource_path, 100 &arg_size); 101 102 rsp = smb_kdoor_clnt_upcall(argp, arg_size, NULL, 0, &rsp_size); 103 104 if (rsp) { 105 if (smb_kdr_decode_common((rsp + SMB_DR_DATA_OFFSET), 106 (rsp_size - SMB_DR_DATA_OFFSET), xdr_uint32_t, &count) 107 != 0) { 108 count = 0; 109 } 110 } 111 112 smb_kdoor_clnt_free(argp, arg_size, rsp, rsp_size); 113 return (count); 114 } 115 116 /* 117 * This take a path for the root of the dataset and 118 * gets the counts of snapshots for that dataset and the 119 * list of @GMT tokens(one for each snapshot) up to the 120 * count provided. 121 * Need to call smb_upcall_vss_get_snapshots_free after 122 * to free up the data 123 */ 124 void 125 smb_upcall_vss_get_snapshots(char *resource_path, uint32_t count, 126 smb_dr_return_gmttokens_t *gmttokens) 127 { 128 char *argp, *rbufp; 129 size_t rbuf_size; 130 size_t arg_size; 131 smb_dr_get_gmttokens_t request; 132 133 request.gg_count = count; 134 request.gg_path = resource_path; 135 bzero(gmttokens, sizeof (smb_dr_return_gmttokens_t)); 136 137 argp = smb_kdr_encode_common(SMB_DR_VSS_GET_SNAPSHOTS, &request, 138 xdr_smb_dr_get_gmttokens_t, &arg_size); 139 140 rbufp = smb_kdoor_clnt_upcall(argp, arg_size, NULL, 0, &rbuf_size); 141 142 if (rbufp != NULL) { 143 (void) smb_kdr_decode_common((rbufp + SMB_DR_DATA_OFFSET), 144 (rbuf_size - SMB_DR_DATA_OFFSET), 145 xdr_smb_dr_return_gmttokens_t, gmttokens); 146 } 147 148 smb_kdoor_clnt_free(argp, arg_size, rbufp, rbuf_size); 149 } 150 151 void 152 smb_upcall_vss_get_snapshots_free(smb_dr_return_gmttokens_t *reply) 153 { 154 xdr_free(xdr_smb_dr_return_gmttokens_t, (char *)reply); 155 } 156 157 158 /* 159 * Returns the snapshot name for the @GMT token provided 160 * for the dataset of the path. 161 * If the snapshot can not be found, a string with a NULL 162 * is returned. 163 */ 164 void 165 smb_upcall_vss_map_gmttoken(char *path, char *gmttoken, 166 char *snapname) 167 { 168 char *argp, *rbufp; 169 size_t arg_size, rbuf_size; 170 smb_dr_string_t res; 171 smb_dr_map_gmttoken_t request; 172 173 bzero(&res, sizeof (smb_dr_string_t)); 174 175 request.mg_path = path; 176 request.mg_gmttoken = gmttoken; 177 178 argp = smb_kdr_encode_common(SMB_DR_VSS_MAP_GMTTOKEN, &request, 179 xdr_smb_dr_map_gmttoken_t, &arg_size); 180 181 if (argp == NULL) { 182 return; 183 } 184 185 rbufp = smb_kdoor_clnt_upcall(argp, arg_size, NULL, 0, &rbuf_size); 186 187 if (rbufp != NULL) { 188 res.buf = snapname; 189 190 /* a snapname set to '\0' means that there was no match */ 191 (void) smb_kdr_decode_common((rbufp + SMB_DR_DATA_OFFSET), 192 (rbuf_size - SMB_DR_DATA_OFFSET), xdr_smb_dr_string_t, 193 &res); 194 } 195 196 smb_kdoor_clnt_free(argp, arg_size, rbufp, rbuf_size); 197 } 198