xref: /illumos-gate/usr/src/uts/common/fs/smbclnt/netsmb/smb_subr.h (revision b1d7ec75953cd517f5b7c3d9cb427ff8ec5d7d07)
1 /*
2  * Copyright (c) 2000-2001, Boris Popov
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *    This product includes software developed by Boris Popov.
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * $Id: smb_subr.h,v 1.13 2004/09/14 22:59:08 lindak Exp $
33  */
34 
35 /*
36  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
37  */
38 
39 #ifndef _NETSMB_SMB_SUBR_H_
40 #define	_NETSMB_SMB_SUBR_H_
41 
42 #include <sys/cmn_err.h>
43 #include <sys/lock.h>
44 #include <sys/note.h>
45 
46 /* Helper function for SMBERROR */
47 /*PRINTFLIKE3*/
48 extern void smb_errmsg(int, const char *, const char *, ...)
49 	__KPRINTFLIKE(3);
50 void m_dumpm(mblk_t *m);
51 
52 /*
53  * Let's use C99 standard variadic macros!
54  * Also the C99 __func__ (function name) feature.
55  */
56 #define	SMBERROR(...) \
57 	smb_errmsg(CE_NOTE, __func__, __VA_ARGS__)
58 #define	SMBPANIC(...) \
59 	smb_errmsg(CE_PANIC, __func__, __VA_ARGS__)
60 #define	SMBSDEBUG(...) \
61 	smb_errmsg(CE_CONT, __func__, __VA_ARGS__)
62 #define	SMBIODEBUG(...) \
63 	smb_errmsg(CE_CONT, __func__, __VA_ARGS__)
64 #define	NBDEBUG(...) \
65 	smb_errmsg(CE_CONT, __func__, __VA_ARGS__)
66 
67 #if defined(DEBUG) || defined(lint)
68 
69 #define	DEBUG_ENTER(str) debug_enter(str)
70 
71 #else /* DEBUG or lint */
72 
73 #define	DEBUG_ENTER(str) ((void)0)
74 
75 #endif /* DEBUG or lint */
76 
77 typedef uint16_t	smb_unichar;
78 typedef	smb_unichar	*smb_uniptr;
79 
80 extern smb_unichar smb_unieol;
81 
82 struct mbchain;
83 struct smb_rq;
84 struct smb_vc;
85 
86 /*
87  * Tunable timeout values.  See: smb_smb.c
88  */
89 extern int smb_timo_notice;
90 extern int smb_timo_default;
91 extern int smb_timo_open;
92 extern int smb_timo_read;
93 extern int smb_timo_write;
94 extern int smb_timo_append;
95 
96 #define	EMOREDATA (0x7fff)
97 
98 void smb_credinit(struct smb_cred *scred, cred_t *cr);
99 void smb_credrele(struct smb_cred *scred);
100 
101 void smb_oldlm_hash(const char *apwd, uchar_t *hash);
102 void smb_ntlmv1hash(const char *apwd, uchar_t *hash);
103 void smb_ntlmv2hash(const uchar_t *v1hash, const char *user,
104 	const char *destination, uchar_t *v2hash);
105 
106 int  smb_lmresponse(const uchar_t *hash, const uchar_t *C8, uchar_t *RN);
107 int  smb_ntlmv2response(const uchar_t *hash, const uchar_t *C8,
108     const uchar_t *blob, size_t bloblen, uchar_t **RN, size_t *RNlen);
109 int  smb_maperror(int eclass, int eno);
110 int  smb_maperr32(uint32_t eno);
111 int  smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp,
112     const char *src, int len, int caseopt, int *lenp);
113 int  smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp,
114     const char *src, int caseopt);
115 int  smb_put_string(struct smb_rq *rqp, const char *src);
116 int  smb_put_asunistring(struct smb_rq *rqp, const char *src);
117 int  smb_checksmp(void);
118 
119 int smb_cmp_sockaddr(struct sockaddr *, struct sockaddr *);
120 struct sockaddr *smb_dup_sockaddr(struct sockaddr *sa);
121 void smb_free_sockaddr(struct sockaddr *sa);
122 int smb_toupper(const char *, char *, size_t);
123 
124 void smb_rq_sign(struct smb_rq *);
125 int smb_rq_verify(struct smb_rq *);
126 int smb_calcv2mackey(struct smb_vc *, const uchar_t *,
127 	const uchar_t *, size_t);
128 int smb_calcmackey(struct smb_vc *, const uchar_t *,
129 	const uchar_t *, size_t);
130 void smb_crypto_mech_init(void);
131 
132 void smb_time_init(void);
133 void smb_time_fini(void);
134 
135 void  smb_time_local2server(struct timespec *tsp, int tzoff, long *seconds);
136 void  smb_time_server2local(ulong_t seconds, int tzoff, struct timespec *tsp);
137 void  smb_time_NT2local(uint64_t nsec, struct timespec *tsp);
138 void  smb_time_local2NT(struct timespec *tsp, uint64_t *nsec);
139 void  smb_time_unix2dos(struct timespec *tsp, int tzoff, uint16_t *ddp,
140 	uint16_t *dtp, uint8_t *dhp);
141 void smb_dos2unixtime(uint_t dd, uint_t dt, uint_t dh, int tzoff,
142 	struct timespec *tsp);
143 
144 #endif /* !_NETSMB_SMB_SUBR_H_ */
145