1c398230bSWarner Losh /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3fe267a55SPedro F. Giffuni * 4d122d784SJoel Dahl * Copyright (c) 2000-2001 Boris Popov 5681a5bbeSBoris Popov * All rights reserved. 6681a5bbeSBoris Popov * 7681a5bbeSBoris Popov * Redistribution and use in source and binary forms, with or without 8681a5bbeSBoris Popov * modification, are permitted provided that the following conditions 9681a5bbeSBoris Popov * are met: 10681a5bbeSBoris Popov * 1. Redistributions of source code must retain the above copyright 11681a5bbeSBoris Popov * notice, this list of conditions and the following disclaimer. 12681a5bbeSBoris Popov * 2. Redistributions in binary form must reproduce the above copyright 13681a5bbeSBoris Popov * notice, this list of conditions and the following disclaimer in the 14681a5bbeSBoris Popov * documentation and/or other materials provided with the distribution. 15681a5bbeSBoris Popov * 16681a5bbeSBoris Popov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17681a5bbeSBoris Popov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18681a5bbeSBoris Popov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19681a5bbeSBoris Popov * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20681a5bbeSBoris Popov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21681a5bbeSBoris Popov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22681a5bbeSBoris Popov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23681a5bbeSBoris Popov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24681a5bbeSBoris Popov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25681a5bbeSBoris Popov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26681a5bbeSBoris Popov * SUCH DAMAGE. 27681a5bbeSBoris Popov * 28681a5bbeSBoris Popov * $FreeBSD$ 29681a5bbeSBoris Popov */ 30681a5bbeSBoris Popov #ifndef _NETSMB_SMB_SUBR_H_ 31681a5bbeSBoris Popov #define _NETSMB_SMB_SUBR_H_ 32681a5bbeSBoris Popov 33681a5bbeSBoris Popov #ifndef _KERNEL 34681a5bbeSBoris Popov #error "This file shouldn't be included from userland programs" 35681a5bbeSBoris Popov #endif 36681a5bbeSBoris Popov 37681a5bbeSBoris Popov #ifdef MALLOC_DECLARE 38681a5bbeSBoris Popov MALLOC_DECLARE(M_SMBTEMP); 39681a5bbeSBoris Popov #endif 40681a5bbeSBoris Popov 416e551fb6SDavid E. O'Brien #define SMBERROR(format, args...) printf("%s: "format, __func__ ,## args) 426e551fb6SDavid E. O'Brien #define SMBPANIC(format, args...) printf("%s: "format, __func__ ,## args) 43681a5bbeSBoris Popov 44681a5bbeSBoris Popov #ifdef SMB_SOCKET_DEBUG 456e551fb6SDavid E. O'Brien #define SMBSDEBUG(format, args...) printf("%s: "format, __func__ ,## args) 46681a5bbeSBoris Popov #else 47681a5bbeSBoris Popov #define SMBSDEBUG(format, args...) 48681a5bbeSBoris Popov #endif 49681a5bbeSBoris Popov 50681a5bbeSBoris Popov #ifdef SMB_IOD_DEBUG 516e551fb6SDavid E. O'Brien #define SMBIODEBUG(format, args...) printf("%s: "format, __func__ ,## args) 52681a5bbeSBoris Popov #else 53681a5bbeSBoris Popov #define SMBIODEBUG(format, args...) 54681a5bbeSBoris Popov #endif 55681a5bbeSBoris Popov 56681a5bbeSBoris Popov #ifdef SMB_SOCKETDATA_DEBUG 57681a5bbeSBoris Popov void m_dumpm(struct mbuf *m); 58681a5bbeSBoris Popov #else 59681a5bbeSBoris Popov #define m_dumpm(m) 60681a5bbeSBoris Popov #endif 61681a5bbeSBoris Popov 62681a5bbeSBoris Popov #define SMB_SIGMASK(set) \ 63681a5bbeSBoris Popov (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \ 64681a5bbeSBoris Popov SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \ 65681a5bbeSBoris Popov SIGISMEMBER(set, SIGQUIT)) 66681a5bbeSBoris Popov 67cc426dd3SMateusz Guzik #define smb_suser(cred) priv_check_cred(cred, PRIV_NETSMB) 68681a5bbeSBoris Popov 69681a5bbeSBoris Popov /* 70681a5bbeSBoris Popov * Compatibility wrappers for simple locks 71681a5bbeSBoris Popov */ 72681a5bbeSBoris Popov 73ecc56e13SBruce Evans #include <sys/lock.h> 74681a5bbeSBoris Popov #include <sys/mutex.h> 75681a5bbeSBoris Popov 76681a5bbeSBoris Popov #define smb_slock mtx 776008862bSJohn Baldwin #define smb_sl_init(mtx, desc) mtx_init(mtx, desc, NULL, MTX_DEF) 78681a5bbeSBoris Popov #define smb_sl_destroy(mtx) mtx_destroy(mtx) 79681a5bbeSBoris Popov #define smb_sl_lock(mtx) mtx_lock(mtx) 80681a5bbeSBoris Popov #define smb_sl_unlock(mtx) mtx_unlock(mtx) 81681a5bbeSBoris Popov 82681a5bbeSBoris Popov #define SMB_STRFREE(p) do { if (p) smb_strfree(p); } while(0) 83681a5bbeSBoris Popov 84681a5bbeSBoris Popov typedef u_int16_t smb_unichar; 85681a5bbeSBoris Popov typedef smb_unichar *smb_uniptr; 86681a5bbeSBoris Popov 87681a5bbeSBoris Popov /* 88681a5bbeSBoris Popov * Crediantials of user/process being processing in the connection procedures 89681a5bbeSBoris Popov */ 90681a5bbeSBoris Popov struct smb_cred { 91fce6fbfaSBoris Popov struct thread * scr_td; 92681a5bbeSBoris Popov struct ucred * scr_cred; 93681a5bbeSBoris Popov }; 94681a5bbeSBoris Popov 95681a5bbeSBoris Popov extern smb_unichar smb_unieol; 96681a5bbeSBoris Popov 97681a5bbeSBoris Popov struct mbchain; 98681a5bbeSBoris Popov struct smb_vc; 99681a5bbeSBoris Popov struct smb_rq; 100681a5bbeSBoris Popov 101fce6fbfaSBoris Popov void smb_makescred(struct smb_cred *scred, struct thread *td, struct ucred *cred); 1024093529dSJeff Roberson int smb_td_intr(struct thread *); 103681a5bbeSBoris Popov char *smb_strdup(const char *s); 104681a5bbeSBoris Popov void *smb_memdup(const void *umem, int len); 105a67b22d6SChristian S.J. Peron char *smb_strdupin(char *s, size_t maxlen); 106a67b22d6SChristian S.J. Peron void *smb_memdupin(void *umem, size_t len); 107681a5bbeSBoris Popov void smb_strtouni(u_int16_t *dst, const char *src); 108681a5bbeSBoris Popov void smb_strfree(char *s); 109681a5bbeSBoris Popov void smb_memfree(void *s); 110a67b22d6SChristian S.J. Peron void *smb_zmalloc(size_t size, struct malloc_type *type, int flags); 111681a5bbeSBoris Popov 112190b2c4fSTim J. Robbins int smb_calcmackey(struct smb_vc *vcp); 113681a5bbeSBoris Popov int smb_encrypt(const u_char *apwd, u_char *C8, u_char *RN); 114681a5bbeSBoris Popov int smb_ntencrypt(const u_char *apwd, u_char *C8, u_char *RN); 115681a5bbeSBoris Popov int smb_maperror(int eclass, int eno); 116681a5bbeSBoris Popov int smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp, 117a67b22d6SChristian S.J. Peron const char *src, size_t len, int caseopt); 118681a5bbeSBoris Popov int smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp, 119681a5bbeSBoris Popov const char *src, int caseopt); 120681a5bbeSBoris Popov int smb_put_string(struct smb_rq *rqp, const char *src); 121681a5bbeSBoris Popov int smb_put_asunistring(struct smb_rq *rqp, const char *src); 122190b2c4fSTim J. Robbins int smb_rq_sign(struct smb_rq *rqp); 123190b2c4fSTim J. Robbins int smb_rq_verify(struct smb_rq *rqp); 124681a5bbeSBoris Popov 125681a5bbeSBoris Popov #endif /* !_NETSMB_SMB_SUBR_H_ */ 126