xref: /dflybsd-src/sys/netproto/smb/smb_subr.h (revision 3412cacb5a88ff95d06808eeed783b8499b5256e)
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  * $FreeBSD: src/sys/netsmb/smb_subr.h,v 1.1.2.1 2001/05/22 08:32:34 bp Exp $
33  * $DragonFly: src/sys/netproto/smb/smb_subr.h,v 1.7 2003/11/15 21:05:43 dillon Exp $
34  */
35 #ifndef _NETSMB_SMB_SUBR_H_
36 #define _NETSMB_SMB_SUBR_H_
37 
38 #ifndef _KERNEL
39 #error "This file shouldn't be included from userland programs"
40 #endif
41 
42 #ifdef MALLOC_DECLARE
43 MALLOC_DECLARE(M_SMBTEMP);
44 #endif
45 
46 /*
47  * For compatibility with 5.x
48  */
49 #define	PDROP	PUSRFLAG1	/* OR'd with pri to stop re-entry of interlock mutex */
50 
51 #define SMBERROR(format, args...) printf("%s: "format, __FUNCTION__ ,## args)
52 #define SMBPANIC(format, args...) printf("%s: "format, __FUNCTION__ ,## args)
53 
54 #ifdef SMB_SOCKET_DEBUG
55 #define SMBSDEBUG(format, args...) printf("%s: "format, __FUNCTION__ ,## args)
56 #else
57 #define SMBSDEBUG(format, args...)
58 #endif
59 
60 #ifdef SMB_IOD_DEBUG
61 #define SMBIODEBUG(format, args...) printf("%s: "format, __FUNCTION__ ,## args)
62 #else
63 #define SMBIODEBUG(format, args...)
64 #endif
65 
66 #ifdef SMB_SOCKETDATA_DEBUG
67 void m_dumpm(struct mbuf *m);
68 #else
69 #define m_dumpm(m)
70 #endif
71 
72 #define	SMB_SIGMASK(set) 						\
73 	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
74 	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
75 	 SIGISMEMBER(set, SIGQUIT))
76 
77 #define	smb_suser(cred)	suser_cred(cred, 0)
78 
79 #include <sys/lock.h>
80 
81 #define	lockdestroy(lock)
82 #define	smb_slock			lwkt_token
83 #define	smb_sl_init(mtx, desc)		lwkt_inittoken(mtx)
84 #define	smb_sl_destroy(mtx)
85 #define	smb_sl_lock(mtx)		lwkt_gettoken(mtx)
86 #define	smb_sl_unlock(mtx)		lwkt_reltoken(mtx)
87 
88 #define SMB_STRFREE(p)	do { if (p) smb_strfree(p); } while(0)
89 
90 /*
91  * The simple try/catch/finally interface.
92  * With GCC it is possible to allow more than one try/finally block per
93  * function, but we'll avoid it to maintain portability.
94  */
95 #define itry		{						\
96 				__label__ _finlab, _catchlab;		\
97 				int _tval;				\
98 
99 #define icatch(var)							\
100 				goto _finlab;				\
101 				(void)&&_catchlab;			\
102 				_catchlab:				\
103 				var = _tval;
104 
105 #define ifinally		(void)&&_finlab;			\
106 				_finlab:
107 #define iendtry		}
108 
109 #define inocatch							\
110 				goto _finlab;				\
111 				(void)&&_catchlab;			\
112 				_catchlab:				\
113 
114 #define ithrow(t)	do {						\
115 				if ((_tval = (int)(t)) != 0)		\
116 					goto _catchlab;			\
117 			} while (0)
118 
119 #define ierror(t,e)	do {						\
120 				if (t) {				\
121 					_tval = e;			\
122 					goto _catchlab;			\
123 				}					\
124 			} while (0)
125 
126 typedef u_int16_t	smb_unichar;
127 typedef	smb_unichar	*smb_uniptr;
128 
129 /*
130  * Crediantials of user/process being processing in the connection procedures
131  */
132 struct smb_cred {
133 	struct thread *	scr_td;
134 	struct ucred *	scr_cred;
135 };
136 
137 extern smb_unichar smb_unieol;
138 
139 struct mbchain;
140 struct proc;
141 struct thread;
142 struct lwkt_token;
143 struct smb_vc;
144 struct smb_rq;
145 
146 
147 void smb_makescred(struct smb_cred *scred, struct thread *td, struct ucred *cred);
148 int  smb_proc_intr(struct thread *td);
149 char *smb_strdup(const char *s);
150 void *smb_memdup(const void *umem, int len);
151 char *smb_strdupin(char *s, int maxlen);
152 void *smb_memdupin(void *umem, int len);
153 void smb_strtouni(u_int16_t *dst, const char *src);
154 void smb_strfree(char *s);
155 void smb_memfree(void *s);
156 void *smb_zmalloc(unsigned long size, struct malloc_type *type, int flags);
157 
158 int  smb_encrypt(const u_char *apwd, u_char *C8, u_char *RN);
159 int  smb_ntencrypt(const u_char *apwd, u_char *C8, u_char *RN);
160 int  smb_maperror(int eclass, int eno);
161 int  smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp,
162 	const char *src, int len, int caseopt);
163 int  smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp,
164 	const char *src, int caseopt);
165 int  smb_put_string(struct smb_rq *rqp, const char *src);
166 int  smb_put_asunistring(struct smb_rq *rqp, const char *src);
167 int  smb_checksmp(void);
168 
169 /*
170  * Compatibilty with 5.x functions
171  */
172 int kthread_create2(void (*func)(void *), void *arg,
173     struct proc **newpp, int flags, const char *fmt, ...);
174 int smb_sleep(void *chan, struct lwkt_token *mtx, int slpflags, const char *wmesg, int timo);
175 
176 
177 #endif /* !_NETSMB_SMB_SUBR_H_ */
178