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