1139823Simp/*-
2206361Sjoel * Copyright (c) 2000-2001 Boris Popov
375374Sbp * All rights reserved.
475374Sbp *
575374Sbp * Redistribution and use in source and binary forms, with or without
675374Sbp * modification, are permitted provided that the following conditions
775374Sbp * are met:
875374Sbp * 1. Redistributions of source code must retain the above copyright
975374Sbp *    notice, this list of conditions and the following disclaimer.
1075374Sbp * 2. Redistributions in binary form must reproduce the above copyright
1175374Sbp *    notice, this list of conditions and the following disclaimer in the
1275374Sbp *    documentation and/or other materials provided with the distribution.
1375374Sbp *
1475374Sbp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1575374Sbp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1675374Sbp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1775374Sbp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1875374Sbp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1975374Sbp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2075374Sbp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2175374Sbp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2275374Sbp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2375374Sbp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2475374Sbp * SUCH DAMAGE.
2575374Sbp *
2675374Sbp * $FreeBSD$
2775374Sbp */
2875374Sbp#ifndef _NETSMB_SMB_SUBR_H_
2975374Sbp#define _NETSMB_SMB_SUBR_H_
3075374Sbp
3175374Sbp#ifndef _KERNEL
3275374Sbp#error "This file shouldn't be included from userland programs"
3375374Sbp#endif
3475374Sbp
3575374Sbp#ifdef MALLOC_DECLARE
3675374SbpMALLOC_DECLARE(M_SMBTEMP);
3775374Sbp#endif
3875374Sbp
3987599Sobrien#define SMBERROR(format, args...) printf("%s: "format, __func__ ,## args)
4087599Sobrien#define SMBPANIC(format, args...) printf("%s: "format, __func__ ,## args)
4175374Sbp
4275374Sbp#ifdef SMB_SOCKET_DEBUG
4387599Sobrien#define SMBSDEBUG(format, args...) printf("%s: "format, __func__ ,## args)
4475374Sbp#else
4575374Sbp#define SMBSDEBUG(format, args...)
4675374Sbp#endif
4775374Sbp
4875374Sbp#ifdef SMB_IOD_DEBUG
4987599Sobrien#define SMBIODEBUG(format, args...) printf("%s: "format, __func__ ,## args)
5075374Sbp#else
5175374Sbp#define SMBIODEBUG(format, args...)
5275374Sbp#endif
5375374Sbp
5475374Sbp#ifdef SMB_SOCKETDATA_DEBUG
5575374Sbpvoid m_dumpm(struct mbuf *m);
5675374Sbp#else
5775374Sbp#define m_dumpm(m)
5875374Sbp#endif
5975374Sbp
6075374Sbp#define	SMB_SIGMASK(set) 						\
6175374Sbp	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
6275374Sbp	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
6375374Sbp	 SIGISMEMBER(set, SIGQUIT))
6475374Sbp
65164033Srwatson#define	smb_suser(cred)	priv_check_cred(cred, PRIV_NETSMB, 0)
6675374Sbp
6775374Sbp/*
6875374Sbp * Compatibility wrappers for simple locks
6975374Sbp */
7075374Sbp
71102481Sbde#include <sys/lock.h>
7275374Sbp#include <sys/mutex.h>
7375374Sbp
7475374Sbp#define	smb_slock			mtx
7593818Sjhb#define	smb_sl_init(mtx, desc)		mtx_init(mtx, desc, NULL, MTX_DEF)
7675374Sbp#define	smb_sl_destroy(mtx)		mtx_destroy(mtx)
7775374Sbp#define	smb_sl_lock(mtx)		mtx_lock(mtx)
7875374Sbp#define	smb_sl_unlock(mtx)		mtx_unlock(mtx)
7975374Sbp
8075374Sbp
8175374Sbp#define SMB_STRFREE(p)	do { if (p) smb_strfree(p); } while(0)
8275374Sbp
8375374Sbptypedef u_int16_t	smb_unichar;
8475374Sbptypedef	smb_unichar	*smb_uniptr;
8575374Sbp
8675374Sbp/*
8775374Sbp * Crediantials of user/process being processing in the connection procedures
8875374Sbp */
8975374Sbpstruct smb_cred {
9087192Sbp	struct thread *	scr_td;
9175374Sbp	struct ucred *	scr_cred;
9275374Sbp};
9375374Sbp
9475374Sbpextern smb_unichar smb_unieol;
9575374Sbp
9675374Sbpstruct mbchain;
9775374Sbpstruct smb_vc;
9875374Sbpstruct smb_rq;
9975374Sbp
10087192Sbpvoid smb_makescred(struct smb_cred *scred, struct thread *td, struct ucred *cred);
101112888Sjeffint  smb_td_intr(struct thread *);
10275374Sbpchar *smb_strdup(const char *s);
10375374Sbpvoid *smb_memdup(const void *umem, int len);
104217174Scsjpchar *smb_strdupin(char *s, size_t maxlen);
105217174Scsjpvoid *smb_memdupin(void *umem, size_t len);
10675374Sbpvoid smb_strtouni(u_int16_t *dst, const char *src);
10775374Sbpvoid smb_strfree(char *s);
10875374Sbpvoid smb_memfree(void *s);
109217174Scsjpvoid *smb_zmalloc(size_t size, struct malloc_type *type, int flags);
11075374Sbp
111124087Stjrint  smb_calcmackey(struct smb_vc *vcp);
11275374Sbpint  smb_encrypt(const u_char *apwd, u_char *C8, u_char *RN);
11375374Sbpint  smb_ntencrypt(const u_char *apwd, u_char *C8, u_char *RN);
11475374Sbpint  smb_maperror(int eclass, int eno);
11575374Sbpint  smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp,
116217174Scsjp	const char *src, size_t len, int caseopt);
11775374Sbpint  smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp,
11875374Sbp	const char *src, int caseopt);
11975374Sbpint  smb_put_string(struct smb_rq *rqp, const char *src);
12075374Sbpint  smb_put_asunistring(struct smb_rq *rqp, const char *src);
121124087Stjrint  smb_rq_sign(struct smb_rq *rqp);
122124087Stjrint  smb_rq_verify(struct smb_rq *rqp);
12375374Sbp
12475374Sbp#endif /* !_NETSMB_SMB_SUBR_H_ */
125