smb_subr.h revision 139823
132145Spst/*- 232145Spst * Copyright (c) 2000-2001, Boris Popov 332145Spst * All rights reserved. 432145Spst * 532145Spst * Redistribution and use in source and binary forms, with or without 632145Spst * modification, are permitted provided that the following conditions 732145Spst * are met: 832145Spst * 1. Redistributions of source code must retain the above copyright 932145Spst * notice, this list of conditions and the following disclaimer. 1032145Spst * 2. Redistributions in binary form must reproduce the above copyright 1132145Spst * notice, this list of conditions and the following disclaimer in the 1232145Spst * documentation and/or other materials provided with the distribution. 1332145Spst * 3. All advertising materials mentioning features or use of this software 1432145Spst * must display the following acknowledgement: 1532145Spst * This product includes software developed by Boris Popov. 1632145Spst * 4. Neither the name of the author nor the names of any co-contributors 1732145Spst * may be used to endorse or promote products derived from this software 1832145Spst * without specific prior written permission. 1932145Spst * 2066644Skris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2166644Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2232145Spst * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2332145Spst * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2432145Spst * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25146778Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26162021Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2732145Spst * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2832145Spst * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29146778Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30146778Ssam * SUCH DAMAGE. 3132145Spst * 3232145Spst * $FreeBSD: head/sys/netsmb/smb_subr.h 139823 2005-01-07 01:45:51Z imp $ 33146778Ssam */ 3432145Spst#ifndef _NETSMB_SMB_SUBR_H_ 35146778Ssam#define _NETSMB_SMB_SUBR_H_ 36146778Ssam 3732145Spst#ifndef _KERNEL 3832145Spst#error "This file shouldn't be included from userland programs" 39146778Ssam#endif 40146778Ssam 4132145Spst#ifdef MALLOC_DECLARE 42146778SsamMALLOC_DECLARE(M_SMBTEMP); 43146778Ssam#endif 44146778Ssam 4532145Spst#define SMBERROR(format, args...) printf("%s: "format, __func__ ,## args) 46146778Ssam#define SMBPANIC(format, args...) printf("%s: "format, __func__ ,## args) 4732145Spst 48146778Ssam#ifdef SMB_SOCKET_DEBUG 49146778Ssam#define SMBSDEBUG(format, args...) printf("%s: "format, __func__ ,## args) 50146778Ssam#else 51146778Ssam#define SMBSDEBUG(format, args...) 52146778Ssam#endif 53146778Ssam 54146778Ssam#ifdef SMB_IOD_DEBUG 55146778Ssam#define SMBIODEBUG(format, args...) printf("%s: "format, __func__ ,## args) 56146778Ssam#else 57146778Ssam#define SMBIODEBUG(format, args...) 58146778Ssam#endif 59146778Ssam 60146778Ssam#ifdef SMB_SOCKETDATA_DEBUG 61146778Ssamvoid m_dumpm(struct mbuf *m); 62146778Ssam#else 63146778Ssam#define m_dumpm(m) 64146778Ssam#endif 65146778Ssam 66146778Ssam#define SMB_SIGMASK(set) \ 67146778Ssam (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \ 6832145Spst SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \ 69146778Ssam SIGISMEMBER(set, SIGQUIT)) 7032145Spst 71146778Ssam#define smb_suser(cred) suser_cred(cred, 0) 72146778Ssam 73146778Ssam/* 74146778Ssam * Compatibility wrappers for simple locks 75146778Ssam */ 7632145Spst 77146778Ssam#include <sys/lock.h> 78146778Ssam#include <sys/mutex.h> 79146778Ssam 80146778Ssam#define smb_slock mtx 81146778Ssam#define smb_sl_init(mtx, desc) mtx_init(mtx, desc, NULL, MTX_DEF) 82146778Ssam#define smb_sl_destroy(mtx) mtx_destroy(mtx) 83146778Ssam#define smb_sl_lock(mtx) mtx_lock(mtx) 84146778Ssam#define smb_sl_unlock(mtx) mtx_unlock(mtx) 8532145Spst 8632145Spst 87162021Ssam#define SMB_STRFREE(p) do { if (p) smb_strfree(p); } while(0) 88162021Ssam 89162021Ssamtypedef u_int16_t smb_unichar; 90162021Ssamtypedef smb_unichar *smb_uniptr; 91162021Ssam 92162021Ssam/* 93162021Ssam * Crediantials of user/process being processing in the connection procedures 94146778Ssam */ 95162021Ssamstruct smb_cred { 96162021Ssam struct thread * scr_td; 97162021Ssam struct ucred * scr_cred; 98162021Ssam}; 99162021Ssam 100162021Ssamextern smb_unichar smb_unieol; 101162021Ssam 102146778Ssamstruct mbchain; 103146778Ssamstruct smb_vc; 104146778Ssamstruct smb_rq; 105146778Ssam 106146778Ssamvoid smb_makescred(struct smb_cred *scred, struct thread *td, struct ucred *cred); 10732145Spstint smb_td_intr(struct thread *); 108146778Ssamchar *smb_strdup(const char *s); 109146778Ssamvoid *smb_memdup(const void *umem, int len); 11032145Spstchar *smb_strdupin(char *s, int maxlen); 111146778Ssamvoid *smb_memdupin(void *umem, int len); 112146778Ssamvoid smb_strtouni(u_int16_t *dst, const char *src); 11332145Spstvoid smb_strfree(char *s); 114146778Ssamvoid smb_memfree(void *s); 115146778Ssamvoid *smb_zmalloc(unsigned long size, struct malloc_type *type, int flags); 11632145Spst 117146778Ssamint smb_calcmackey(struct smb_vc *vcp); 118146778Ssamint smb_encrypt(const u_char *apwd, u_char *C8, u_char *RN); 11932145Spstint smb_ntencrypt(const u_char *apwd, u_char *C8, u_char *RN); 120146778Ssamint smb_maperror(int eclass, int eno); 121146778Ssamint smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp, 122146778Ssam const char *src, int len, int caseopt); 123146778Ssamint smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp, 124146778Ssam const char *src, int caseopt); 125146778Ssamint smb_put_string(struct smb_rq *rqp, const char *src); 126146778Ssamint smb_put_asunistring(struct smb_rq *rqp, const char *src); 12732145Spstint smb_rq_sign(struct smb_rq *rqp); 128146778Ssamint smb_rq_verify(struct smb_rq *rqp); 129146778Ssam 130146778Ssam#endif /* !_NETSMB_SMB_SUBR_H_ */ 131146778Ssam