smb_subr.h revision 225736
1183234Ssimon/*-
2183234Ssimon * Copyright (c) 2000-2001 Boris Popov
3183234Ssimon * All rights reserved.
4183234Ssimon *
5183234Ssimon * Redistribution and use in source and binary forms, with or without
6183234Ssimon * modification, are permitted provided that the following conditions
7183234Ssimon * are met:
8183234Ssimon * 1. Redistributions of source code must retain the above copyright
9183234Ssimon *    notice, this list of conditions and the following disclaimer.
10183234Ssimon * 2. Redistributions in binary form must reproduce the above copyright
11183234Ssimon *    notice, this list of conditions and the following disclaimer in the
12183234Ssimon *    documentation and/or other materials provided with the distribution.
13183234Ssimon *
14183234Ssimon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15183234Ssimon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16183234Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17183234Ssimon * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18183234Ssimon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19183234Ssimon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20183234Ssimon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21183234Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22183234Ssimon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23183234Ssimon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24183234Ssimon * SUCH DAMAGE.
25183234Ssimon *
26183234Ssimon * $FreeBSD: stable/9/sys/netsmb/smb_subr.h 217174 2011-01-08 23:06:54Z csjp $
27183234Ssimon */
28183234Ssimon#ifndef _NETSMB_SMB_SUBR_H_
29183234Ssimon#define _NETSMB_SMB_SUBR_H_
30183234Ssimon
31183234Ssimon#ifndef _KERNEL
32183234Ssimon#error "This file shouldn't be included from userland programs"
33183234Ssimon#endif
34183234Ssimon
35183234Ssimon#ifdef MALLOC_DECLARE
36183234SsimonMALLOC_DECLARE(M_SMBTEMP);
37183234Ssimon#endif
38183234Ssimon
39183234Ssimon#define SMBERROR(format, args...) printf("%s: "format, __func__ ,## args)
40183234Ssimon#define SMBPANIC(format, args...) printf("%s: "format, __func__ ,## args)
41183234Ssimon
42183234Ssimon#ifdef SMB_SOCKET_DEBUG
43183234Ssimon#define SMBSDEBUG(format, args...) printf("%s: "format, __func__ ,## args)
44183234Ssimon#else
45183234Ssimon#define SMBSDEBUG(format, args...)
46183234Ssimon#endif
47183234Ssimon
48183234Ssimon#ifdef SMB_IOD_DEBUG
49183234Ssimon#define SMBIODEBUG(format, args...) printf("%s: "format, __func__ ,## args)
50183234Ssimon#else
51183234Ssimon#define SMBIODEBUG(format, args...)
52183234Ssimon#endif
53183234Ssimon
54183234Ssimon#ifdef SMB_SOCKETDATA_DEBUG
55183234Ssimonvoid m_dumpm(struct mbuf *m);
56183234Ssimon#else
57183234Ssimon#define m_dumpm(m)
58183234Ssimon#endif
59183234Ssimon
60183234Ssimon#define	SMB_SIGMASK(set) 						\
61183234Ssimon	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
62183234Ssimon	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
63183234Ssimon	 SIGISMEMBER(set, SIGQUIT))
64183234Ssimon
65183234Ssimon#define	smb_suser(cred)	priv_check_cred(cred, PRIV_NETSMB, 0)
66183234Ssimon
67183234Ssimon/*
68183234Ssimon * Compatibility wrappers for simple locks
69183234Ssimon */
70183234Ssimon
71183234Ssimon#include <sys/lock.h>
72183234Ssimon#include <sys/mutex.h>
73183234Ssimon
74183234Ssimon#define	smb_slock			mtx
75183234Ssimon#define	smb_sl_init(mtx, desc)		mtx_init(mtx, desc, NULL, MTX_DEF)
76183234Ssimon#define	smb_sl_destroy(mtx)		mtx_destroy(mtx)
77183234Ssimon#define	smb_sl_lock(mtx)		mtx_lock(mtx)
78183234Ssimon#define	smb_sl_unlock(mtx)		mtx_unlock(mtx)
79183234Ssimon
80183234Ssimon
81183234Ssimon#define SMB_STRFREE(p)	do { if (p) smb_strfree(p); } while(0)
82183234Ssimon
83183234Ssimontypedef u_int16_t	smb_unichar;
84183234Ssimontypedef	smb_unichar	*smb_uniptr;
85183234Ssimon
86183234Ssimon/*
87183234Ssimon * Crediantials of user/process being processing in the connection procedures
88183234Ssimon */
89183234Ssimonstruct smb_cred {
90183234Ssimon	struct thread *	scr_td;
91183234Ssimon	struct ucred *	scr_cred;
92183234Ssimon};
93183234Ssimon
94183234Ssimonextern smb_unichar smb_unieol;
95183234Ssimon
96183234Ssimonstruct mbchain;
97183234Ssimonstruct smb_vc;
98183234Ssimonstruct smb_rq;
99183234Ssimon
100183234Ssimonvoid smb_makescred(struct smb_cred *scred, struct thread *td, struct ucred *cred);
101183234Ssimonint  smb_td_intr(struct thread *);
102183234Ssimonchar *smb_strdup(const char *s);
103183234Ssimonvoid *smb_memdup(const void *umem, int len);
104183234Ssimonchar *smb_strdupin(char *s, size_t maxlen);
105183234Ssimonvoid *smb_memdupin(void *umem, size_t len);
106183234Ssimonvoid smb_strtouni(u_int16_t *dst, const char *src);
107183234Ssimonvoid smb_strfree(char *s);
108183234Ssimonvoid smb_memfree(void *s);
109183234Ssimonvoid *smb_zmalloc(size_t size, struct malloc_type *type, int flags);
110183234Ssimon
111183234Ssimonint  smb_calcmackey(struct smb_vc *vcp);
112183234Ssimonint  smb_encrypt(const u_char *apwd, u_char *C8, u_char *RN);
113183234Ssimonint  smb_ntencrypt(const u_char *apwd, u_char *C8, u_char *RN);
114183234Ssimonint  smb_maperror(int eclass, int eno);
115183234Ssimonint  smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp,
116183234Ssimon	const char *src, size_t len, int caseopt);
117183234Ssimonint  smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp,
118183234Ssimon	const char *src, int caseopt);
119183234Ssimonint  smb_put_string(struct smb_rq *rqp, const char *src);
120183234Ssimonint  smb_put_asunistring(struct smb_rq *rqp, const char *src);
121183234Ssimonint  smb_rq_sign(struct smb_rq *rqp);
122183234Ssimonint  smb_rq_verify(struct smb_rq *rqp);
123183234Ssimon
124183234Ssimon#endif /* !_NETSMB_SMB_SUBR_H_ */
125183234Ssimon