xref: /illumos-gate/usr/src/uts/common/fs/smbclnt/netsmb/smb_subr.h (revision 07a48826732249fcd3aa8dd53c8389595e9f1fbc)
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 2009 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 typedef uint16_t	smb_unichar;
79 typedef	smb_unichar	*smb_uniptr;
80 
81 extern smb_unichar smb_unieol;
82 
83 struct mbchain;
84 struct smb_rq;
85 struct smb_vc;
86 
87 /*
88  * Tunable timeout values.  See: smb_smb.c
89  */
90 extern int smb_timo_notice;
91 extern int smb_timo_default;
92 extern int smb_timo_open;
93 extern int smb_timo_read;
94 extern int smb_timo_write;
95 extern int smb_timo_append;
96 
97 #define	EMOREDATA (0x7fff)
98 
99 void smb_credinit(struct smb_cred *scred, cred_t *cr);
100 void smb_credrele(struct smb_cred *scred);
101 
102 void smb_oldlm_hash(const char *apwd, uchar_t *hash);
103 void smb_ntlmv1hash(const char *apwd, uchar_t *hash);
104 void smb_ntlmv2hash(const uchar_t *v1hash, const char *user,
105 	const char *destination, uchar_t *v2hash);
106 
107 int  smb_lmresponse(const uchar_t *hash, const uchar_t *C8, uchar_t *RN);
108 int  smb_ntlmv2response(const uchar_t *hash, const uchar_t *C8,
109     const uchar_t *blob, size_t bloblen, uchar_t **RN, size_t *RNlen);
110 int  smb_maperror(int eclass, int eno);
111 uint32_t  smb_maperr32(uint32_t eno);
112 int  smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp,
113     const char *src, int len, int caseopt, int *lenp);
114 int  smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp,
115     const char *src, int caseopt);
116 int  smb_put_string(struct smb_rq *rqp, const char *src);
117 int  smb_put_asunistring(struct smb_rq *rqp, const char *src);
118 int  smb_checksmp(void);
119 
120 int smb_cmp_sockaddr(struct sockaddr *, struct sockaddr *);
121 struct sockaddr *smb_dup_sockaddr(struct sockaddr *sa);
122 void smb_free_sockaddr(struct sockaddr *sa);
123 int smb_toupper(const char *, char *, size_t);
124 
125 int smb_rq_sign(struct smb_rq *);
126 int smb_rq_verify(struct smb_rq *);
127 int smb_calcv2mackey(struct smb_vc *, const uchar_t *,
128 	const uchar_t *, size_t);
129 int smb_calcmackey(struct smb_vc *, const uchar_t *,
130 	const uchar_t *, size_t);
131 void smb_crypto_mech_init(void);
132 
133 #endif /* !_NETSMB_SMB_SUBR_H_ */
134