xref: /illumos-gate/usr/src/uts/common/fs/smbclnt/netsmb/smb_subr.h (revision e0d8bef656731559f2d1d5dca0077a6a66c6f8b9)
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 2008 Sun Microsystems, Inc.  All rights reserved.
37  * Use is subject to license terms.
38  */
39 
40 #ifndef _NETSMB_SMB_SUBR_H_
41 #define	_NETSMB_SMB_SUBR_H_
42 
43 #include <sys/cmn_err.h>
44 #include <sys/lock.h>
45 #include <sys/note.h>
46 
47 /* Helper function for SMBERROR */
48 /*PRINTFLIKE3*/
49 extern void smb_errmsg(int, const char *, const char *, ...)
50 	__KPRINTFLIKE(3);
51 void m_dumpm(mblk_t *m);
52 
53 /*
54  * Let's use C99 standard variadic macros!
55  * Also the C99 __func__ (function name) feature.
56  */
57 #define	SMBERROR(...) \
58 	smb_errmsg(CE_NOTE, __func__, __VA_ARGS__)
59 #define	SMBPANIC(...) \
60 	smb_errmsg(CE_PANIC, __func__, __VA_ARGS__)
61 #define	SMBSDEBUG(...) \
62 	smb_errmsg(CE_CONT, __func__, __VA_ARGS__)
63 #define	SMBIODEBUG(...) \
64 	smb_errmsg(CE_CONT, __func__, __VA_ARGS__)
65 #define	NBDEBUG(...) \
66 	smb_errmsg(CE_CONT, __func__, __VA_ARGS__)
67 
68 #if defined(DEBUG) || defined(lint)
69 
70 #define	DEBUG_ENTER(str) debug_enter(str)
71 
72 #else /* DEBUG or lint */
73 
74 #define	DEBUG_ENTER(str) ((void)0)
75 
76 #endif /* DEBUG or lint */
77 
78 #define	SMB_SIGMASK	\
79 	(sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
80 	sigmask(SIGHUP)|sigmask(SIGQUIT))
81 
82 #define	SMB_STRFREE(p)	do { \
83 	if (p) \
84 		smb_strfree(p); \
85 	_NOTE(CONSTCOND)	\
86 } while (0)
87 
88 typedef uint16_t	smb_unichar;
89 typedef	smb_unichar	*smb_uniptr;
90 
91 extern smb_unichar smb_unieol;
92 
93 struct mbchain;
94 struct smb_rq;
95 struct smb_vc;
96 
97 /*
98  * Tunable timeout values.  See: smb_smb.c
99  */
100 extern int smb_timo_notice;
101 extern int smb_timo_default;
102 extern int smb_timo_open;
103 extern int smb_timo_read;
104 extern int smb_timo_write;
105 extern int smb_timo_append;
106 
107 #define	EMOREDATA (0x7fff)
108 
109 #ifdef APPLE
110 void smb_scred_init(struct smb_cred *scred, vfs_context_t vfsctx);
111 int  smb_sigintr(vfs_context_t);
112 #endif
113 void smb_credinit(struct smb_cred *scred, struct proc *p, cred_t *cr);
114 void smb_credrele(struct smb_cred *scred);
115 char *smb_strdup(const char *s);
116 void *smb_memdup(const void *umem, int len);
117 char *smb_strdupin(char *s, int maxlen);
118 void *smb_memdupin(void *umem, int len);
119 size_t smb_strtouni(uint16_t *dst, const char *src, size_t inlen, int flags);
120 void smb_strfree(char *s);
121 void smb_memfree(void *s);
122 void *smb_zmalloc(unsigned long size);
123 
124 void smb_oldlm_hash(const char *apwd, uchar_t *hash);
125 void smb_ntlmv1hash(const char *apwd, uchar_t *hash);
126 void smb_ntlmv2hash(const uchar_t *v1hash, const char *user,
127 	const char *destination, uchar_t *v2hash);
128 
129 int  smb_lmresponse(const uchar_t *hash, const uchar_t *C8, uchar_t *RN);
130 int  smb_ntlmv2response(const uchar_t *hash, const uchar_t *C8,
131     const uchar_t *blob, size_t bloblen, uchar_t **RN, size_t *RNlen);
132 int  smb_maperror(int eclass, int eno);
133 uint32_t  smb_maperr32(uint32_t eno);
134 int  smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp,
135     const char *src, int len, int caseopt, int *lenp);
136 int  smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp,
137     const char *src, int caseopt);
138 int  smb_put_string(struct smb_rq *rqp, const char *src);
139 int  smb_put_asunistring(struct smb_rq *rqp, const char *src);
140 int  smb_checksmp(void);
141 
142 int smb_cmp_sockaddr(struct sockaddr *, struct sockaddr *);
143 struct sockaddr *smb_dup_sockaddr(struct sockaddr *sa);
144 void smb_free_sockaddr(struct sockaddr *sa);
145 int smb_toupper(const char *, char *, size_t);
146 
147 int smb_rq_sign(struct smb_rq *);
148 int smb_rq_verify(struct smb_rq *);
149 int smb_calcv2mackey(struct smb_vc *, const uchar_t *,
150 	const uchar_t *, size_t);
151 int smb_calcmackey(struct smb_vc *, const uchar_t *,
152 	const uchar_t *, size_t);
153 void smb_crypto_mech_init(void);
154 
155 #endif /* !_NETSMB_SMB_SUBR_H_ */
156