smb_subr.h revision 164033
1139823Simp/*-
275374Sbp * 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 * 3. All advertising materials mentioning features or use of this software
1475374Sbp *    must display the following acknowledgement:
1575374Sbp *    This product includes software developed by Boris Popov.
1675374Sbp * 4. Neither the name of the author nor the names of any co-contributors
1775374Sbp *    may be used to endorse or promote products derived from this software
1875374Sbp *    without specific prior written permission.
1975374Sbp *
2075374Sbp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2175374Sbp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2275374Sbp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2375374Sbp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2475374Sbp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2575374Sbp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2675374Sbp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2775374Sbp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2875374Sbp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2975374Sbp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3075374Sbp * SUCH DAMAGE.
3175374Sbp *
3275374Sbp * $FreeBSD: head/sys/netsmb/smb_subr.h 164033 2006-11-06 13:42:10Z rwatson $
3375374Sbp */
3475374Sbp#ifndef _NETSMB_SMB_SUBR_H_
3575374Sbp#define _NETSMB_SMB_SUBR_H_
3675374Sbp
3775374Sbp#ifndef _KERNEL
3875374Sbp#error "This file shouldn't be included from userland programs"
3975374Sbp#endif
4075374Sbp
4175374Sbp#ifdef MALLOC_DECLARE
4275374SbpMALLOC_DECLARE(M_SMBTEMP);
4375374Sbp#endif
4475374Sbp
4587599Sobrien#define SMBERROR(format, args...) printf("%s: "format, __func__ ,## args)
4687599Sobrien#define SMBPANIC(format, args...) printf("%s: "format, __func__ ,## args)
4775374Sbp
4875374Sbp#ifdef SMB_SOCKET_DEBUG
4987599Sobrien#define SMBSDEBUG(format, args...) printf("%s: "format, __func__ ,## args)
5075374Sbp#else
5175374Sbp#define SMBSDEBUG(format, args...)
5275374Sbp#endif
5375374Sbp
5475374Sbp#ifdef SMB_IOD_DEBUG
5587599Sobrien#define SMBIODEBUG(format, args...) printf("%s: "format, __func__ ,## args)
5675374Sbp#else
5775374Sbp#define SMBIODEBUG(format, args...)
5875374Sbp#endif
5975374Sbp
6075374Sbp#ifdef SMB_SOCKETDATA_DEBUG
6175374Sbpvoid m_dumpm(struct mbuf *m);
6275374Sbp#else
6375374Sbp#define m_dumpm(m)
6475374Sbp#endif
6575374Sbp
6675374Sbp#define	SMB_SIGMASK(set) 						\
6775374Sbp	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
6875374Sbp	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
6975374Sbp	 SIGISMEMBER(set, SIGQUIT))
7075374Sbp
71164033Srwatson#define	smb_suser(cred)	priv_check_cred(cred, PRIV_NETSMB, 0)
7275374Sbp
7375374Sbp/*
7475374Sbp * Compatibility wrappers for simple locks
7575374Sbp */
7675374Sbp
77102481Sbde#include <sys/lock.h>
7875374Sbp#include <sys/mutex.h>
7975374Sbp
8075374Sbp#define	smb_slock			mtx
8193818Sjhb#define	smb_sl_init(mtx, desc)		mtx_init(mtx, desc, NULL, MTX_DEF)
8275374Sbp#define	smb_sl_destroy(mtx)		mtx_destroy(mtx)
8375374Sbp#define	smb_sl_lock(mtx)		mtx_lock(mtx)
8475374Sbp#define	smb_sl_unlock(mtx)		mtx_unlock(mtx)
8575374Sbp
8675374Sbp
8775374Sbp#define SMB_STRFREE(p)	do { if (p) smb_strfree(p); } while(0)
8875374Sbp
8975374Sbptypedef u_int16_t	smb_unichar;
9075374Sbptypedef	smb_unichar	*smb_uniptr;
9175374Sbp
9275374Sbp/*
9375374Sbp * Crediantials of user/process being processing in the connection procedures
9475374Sbp */
9575374Sbpstruct smb_cred {
9687192Sbp	struct thread *	scr_td;
9775374Sbp	struct ucred *	scr_cred;
9875374Sbp};
9975374Sbp
10075374Sbpextern smb_unichar smb_unieol;
10175374Sbp
10275374Sbpstruct mbchain;
10375374Sbpstruct smb_vc;
10475374Sbpstruct smb_rq;
10575374Sbp
10687192Sbpvoid smb_makescred(struct smb_cred *scred, struct thread *td, struct ucred *cred);
107112888Sjeffint  smb_td_intr(struct thread *);
10875374Sbpchar *smb_strdup(const char *s);
10975374Sbpvoid *smb_memdup(const void *umem, int len);
11075374Sbpchar *smb_strdupin(char *s, int maxlen);
11175374Sbpvoid *smb_memdupin(void *umem, int len);
11275374Sbpvoid smb_strtouni(u_int16_t *dst, const char *src);
11375374Sbpvoid smb_strfree(char *s);
11475374Sbpvoid smb_memfree(void *s);
11575374Sbpvoid *smb_zmalloc(unsigned long size, struct malloc_type *type, int flags);
11675374Sbp
117124087Stjrint  smb_calcmackey(struct smb_vc *vcp);
11875374Sbpint  smb_encrypt(const u_char *apwd, u_char *C8, u_char *RN);
11975374Sbpint  smb_ntencrypt(const u_char *apwd, u_char *C8, u_char *RN);
12075374Sbpint  smb_maperror(int eclass, int eno);
12175374Sbpint  smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp,
12275374Sbp	const char *src, int len, int caseopt);
12375374Sbpint  smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp,
12475374Sbp	const char *src, int caseopt);
12575374Sbpint  smb_put_string(struct smb_rq *rqp, const char *src);
12675374Sbpint  smb_put_asunistring(struct smb_rq *rqp, const char *src);
127124087Stjrint  smb_rq_sign(struct smb_rq *rqp);
128124087Stjrint  smb_rq_verify(struct smb_rq *rqp);
12975374Sbp
13075374Sbp#endif /* !_NETSMB_SMB_SUBR_H_ */
131