xref: /freebsd/sys/netsmb/smb_subr.h (revision f05cddf9)
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  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 #ifndef _NETSMB_SMB_SUBR_H_
29 #define _NETSMB_SMB_SUBR_H_
30 
31 #ifndef _KERNEL
32 #error "This file shouldn't be included from userland programs"
33 #endif
34 
35 #ifdef MALLOC_DECLARE
36 MALLOC_DECLARE(M_SMBTEMP);
37 #endif
38 
39 #define SMBERROR(format, args...) printf("%s: "format, __func__ ,## args)
40 #define SMBPANIC(format, args...) printf("%s: "format, __func__ ,## args)
41 
42 #ifdef SMB_SOCKET_DEBUG
43 #define SMBSDEBUG(format, args...) printf("%s: "format, __func__ ,## args)
44 #else
45 #define SMBSDEBUG(format, args...)
46 #endif
47 
48 #ifdef SMB_IOD_DEBUG
49 #define SMBIODEBUG(format, args...) printf("%s: "format, __func__ ,## args)
50 #else
51 #define SMBIODEBUG(format, args...)
52 #endif
53 
54 #ifdef SMB_SOCKETDATA_DEBUG
55 void m_dumpm(struct mbuf *m);
56 #else
57 #define m_dumpm(m)
58 #endif
59 
60 #define	SMB_SIGMASK(set) 						\
61 	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
62 	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
63 	 SIGISMEMBER(set, SIGQUIT))
64 
65 #define	smb_suser(cred)	priv_check_cred(cred, PRIV_NETSMB, 0)
66 
67 /*
68  * Compatibility wrappers for simple locks
69  */
70 
71 #include <sys/lock.h>
72 #include <sys/mutex.h>
73 
74 #define	smb_slock			mtx
75 #define	smb_sl_init(mtx, desc)		mtx_init(mtx, desc, NULL, MTX_DEF)
76 #define	smb_sl_destroy(mtx)		mtx_destroy(mtx)
77 #define	smb_sl_lock(mtx)		mtx_lock(mtx)
78 #define	smb_sl_unlock(mtx)		mtx_unlock(mtx)
79 
80 
81 #define SMB_STRFREE(p)	do { if (p) smb_strfree(p); } while(0)
82 
83 typedef u_int16_t	smb_unichar;
84 typedef	smb_unichar	*smb_uniptr;
85 
86 /*
87  * Crediantials of user/process being processing in the connection procedures
88  */
89 struct smb_cred {
90 	struct thread *	scr_td;
91 	struct ucred *	scr_cred;
92 };
93 
94 extern smb_unichar smb_unieol;
95 
96 struct mbchain;
97 struct smb_vc;
98 struct smb_rq;
99 
100 void smb_makescred(struct smb_cred *scred, struct thread *td, struct ucred *cred);
101 int  smb_td_intr(struct thread *);
102 char *smb_strdup(const char *s);
103 void *smb_memdup(const void *umem, int len);
104 char *smb_strdupin(char *s, size_t maxlen);
105 void *smb_memdupin(void *umem, size_t len);
106 void smb_strtouni(u_int16_t *dst, const char *src);
107 void smb_strfree(char *s);
108 void smb_memfree(void *s);
109 void *smb_zmalloc(size_t size, struct malloc_type *type, int flags);
110 
111 int  smb_calcmackey(struct smb_vc *vcp);
112 int  smb_encrypt(const u_char *apwd, u_char *C8, u_char *RN);
113 int  smb_ntencrypt(const u_char *apwd, u_char *C8, u_char *RN);
114 int  smb_maperror(int eclass, int eno);
115 int  smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp,
116 	const char *src, size_t len, int caseopt);
117 int  smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp,
118 	const char *src, int caseopt);
119 int  smb_put_string(struct smb_rq *rqp, const char *src);
120 int  smb_put_asunistring(struct smb_rq *rqp, const char *src);
121 int  smb_rq_sign(struct smb_rq *rqp);
122 int  smb_rq_verify(struct smb_rq *rqp);
123 
124 #endif /* !_NETSMB_SMB_SUBR_H_ */
125