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