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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 #include <smbsrv/libsmb.h>
31 #include <smbsrv/smb_xdr.h>
32 #include <smbsrv/smb_door.h>
36 * Generic XDR encoder.
38 * Returns a malloc'd, encoded buffer upon success.
39 * Otherwise, returns NULL.
42 smb_common_encode(void *data
, xdrproc_t proc
, size_t *rsize
)
48 if (proc
== NULL
|| data
== NULL
|| rsize
== NULL
) {
49 syslog(LOG_ERR
, "smb_common_encode: invalid parameter");
53 len
= xdr_sizeof(proc
, data
);
55 if ((buf
= malloc(len
)) == NULL
) {
56 syslog(LOG_ERR
, "smb_common_encode: %m");
61 xdrmem_create(&xdrs
, buf
, len
, XDR_ENCODE
);
64 if (!proc(&xdrs
, data
)) {
65 syslog(LOG_DEBUG
, "smb_common_encode: encode error");
76 * Generic XDR decoder. Ensure that data is non-null and bzero'd.
79 smb_common_decode(char *buf
, size_t len
, xdrproc_t proc
, void *data
)
87 xdrmem_create(&xdrs
, buf
, len
, XDR_DECODE
);
88 if (!proc(&xdrs
, data
))
96 smb_string_encode(char *s
, size_t *rsize
)
103 if ((obj
.buf
= s
) == NULL
) {
104 syslog(LOG_DEBUG
, "smb_string_encode: invalid param");
105 goto smb_string_encode_failed
;
108 len
= xdr_sizeof(smb_string_xdr
, &obj
);
109 if ((buf
= calloc(len
, 1)) == NULL
) {
110 syslog(LOG_DEBUG
, "smb_string_encode: %m");
111 goto smb_string_encode_failed
;
114 xdrmem_create(&xdrs
, buf
, len
, XDR_ENCODE
);
116 if (!smb_string_xdr(&xdrs
, &obj
)) {
117 syslog(LOG_DEBUG
, "smb_string_encode: encode failed");
120 goto smb_string_encode_failed
;
128 smb_string_encode_failed
:
135 smb_string_decode(smb_string_t
*obj
, char *buf
, size_t buflen
)
140 xdrmem_create(&xdrs
, (const caddr_t
)buf
, buflen
, XDR_DECODE
);
142 bzero(obj
, sizeof (smb_string_t
));
143 if (!smb_string_xdr(&xdrs
, obj
))
151 * Encode an lsa_account_t into a buffer.
154 lsa_account_encode(lsa_account_t
*acct
, uint8_t *buf
, uint32_t buflen
)
159 xdrmem_create(&xdrs
, (const caddr_t
)buf
, buflen
, XDR_ENCODE
);
161 if (!lsa_account_xdr(&xdrs
, acct
))
169 * Decode an XDR buffer into an lsa_account_t.
172 lsa_account_decode(lsa_account_t
*acct
, uint8_t *buf
, uint32_t buflen
)
177 xdrmem_create(&xdrs
, (const caddr_t
)buf
, buflen
, XDR_DECODE
);
179 bzero(acct
, sizeof (lsa_account_t
));
180 if (!lsa_account_xdr(&xdrs
, acct
))
188 lsa_account_xdr(XDR
*xdrs
, lsa_account_t
*objp
)
190 if (!xdr_uint16_t(xdrs
, &objp
->a_sidtype
))
192 if (!xdr_uint32_t(xdrs
, &objp
->a_status
))
194 if (!xdr_vector(xdrs
, (char *)objp
->a_domain
, MAXNAMELEN
,
195 sizeof (char), (xdrproc_t
)xdr_char
))
197 if (!xdr_vector(xdrs
, (char *)objp
->a_name
, MAXNAMELEN
,
198 sizeof (char), (xdrproc_t
)xdr_char
))
200 if (!xdr_vector(xdrs
, (char *)objp
->a_sid
, SMB_SID_STRSZ
,
201 sizeof (char), (xdrproc_t
)xdr_char
))