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.
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.
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]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
29 * NT Token library (kernel/user)
32 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
33 #include <sys/types.h>
34 #include <sys/cmn_err.h>
42 #include <smbsrv/string.h>
43 #include <smbsrv/smb_token.h>
44 #include <smbsrv/smb_xdr.h>
47 * smb_token_query_privilege
49 * Find out if the specified privilege is enable in the given
53 smb_token_query_privilege(smb_token_t
*token
, int priv_id
)
55 smb_privset_t
*privset
;
58 if ((token
== NULL
) || (token
->tkn_privileges
== NULL
))
61 privset
= token
->tkn_privileges
;
62 for (i
= 0; privset
->priv_cnt
; i
++) {
63 if (privset
->priv
[i
].luid
.lo_part
== priv_id
) {
64 if (privset
->priv
[i
].attrs
== SE_PRIVILEGE_ENABLED
)
75 * Basic sanity check on a token.
78 smb_token_valid(smb_token_t
*token
)
83 if ((token
->tkn_user
.i_sid
== NULL
) ||
84 (token
->tkn_owner
.i_sid
== NULL
) ||
85 (token
->tkn_primary_grp
.i_sid
== NULL
) ||
86 (token
->tkn_account_name
== NULL
) ||
87 (token
->tkn_domain_name
== NULL
) ||
88 (token
->tkn_posix_grps
== NULL
))
91 if ((token
->tkn_win_grps
.i_cnt
!= 0) &&
92 (token
->tkn_win_grps
.i_ids
== NULL
))
98 #if !defined(_KERNEL) && !defined(_FAKE_KERNEL)
100 * Encode: structure -> flat buffer (buffer size)
101 * Pre-condition: obj is non-null.
104 smb_token_encode(smb_token_t
*obj
, uint32_t *len
)
110 syslog(LOG_ERR
, "smb_token_encode: invalid parameter");
114 *len
= xdr_sizeof(smb_token_xdr
, obj
);
115 buf
= (uint8_t *)malloc(*len
);
117 syslog(LOG_ERR
, "smb_token_encode: %m");
121 xdrmem_create(&xdrs
, (const caddr_t
)buf
, *len
, XDR_ENCODE
);
123 if (!smb_token_xdr(&xdrs
, obj
)) {
124 syslog(LOG_ERR
, "smb_token_encode: XDR encode error");
135 * Decode: flat buffer -> structure
138 smb_logon_decode(uint8_t *buf
, uint32_t len
)
143 xdrmem_create(&xdrs
, (const caddr_t
)buf
, len
, XDR_DECODE
);
145 if ((obj
= malloc(sizeof (smb_logon_t
))) == NULL
) {
146 syslog(LOG_ERR
, "smb_logon_decode: %m");
151 bzero(obj
, sizeof (smb_logon_t
));
152 if (!smb_logon_xdr(&xdrs
, obj
)) {
153 syslog(LOG_ERR
, "smb_logon_decode: XDR decode error");
163 smb_logon_free(smb_logon_t
*obj
)
165 xdr_free(smb_logon_xdr
, (char *)obj
);