smb_subr.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  3. *
  4. * Copyright (c) 2000-2001 Boris Popov
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  20. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. * SUCH DAMAGE.
  27. *
  28. * $FreeBSD$
  29. */
  30. #ifndef _NETSMB_SMB_SUBR_H_
  31. #define _NETSMB_SMB_SUBR_H_
  32. #ifndef _KERNEL
  33. #error "This file shouldn't be included from userland programs"
  34. #endif
  35. #ifdef MALLOC_DECLARE
  36. MALLOC_DECLARE(M_SMBTEMP);
  37. #endif
  38. #define SMBERROR(format, args...) printf("%s: "format, __func__ ,## args)
  39. #define SMBPANIC(format, args...) printf("%s: "format, __func__ ,## args)
  40. #ifdef SMB_SOCKET_DEBUG
  41. #define SMBSDEBUG(format, args...) printf("%s: "format, __func__ ,## args)
  42. #else
  43. #define SMBSDEBUG(format, args...)
  44. #endif
  45. #ifdef SMB_IOD_DEBUG
  46. #define SMBIODEBUG(format, args...) printf("%s: "format, __func__ ,## args)
  47. #else
  48. #define SMBIODEBUG(format, args...)
  49. #endif
  50. #ifdef SMB_SOCKETDATA_DEBUG
  51. void m_dumpm(struct mbuf *m);
  52. #else
  53. #define m_dumpm(m)
  54. #endif
  55. #define SMB_SIGMASK(set) \
  56. (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \
  57. SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \
  58. SIGISMEMBER(set, SIGQUIT))
  59. #define smb_suser(cred) priv_check_cred(cred, PRIV_NETSMB)
  60. /*
  61. * Compatibility wrappers for simple locks
  62. */
  63. #include <sys/lock.h>
  64. #include <sys/mutex.h>
  65. #define smb_slock mtx
  66. #define smb_sl_init(mtx, desc) mtx_init(mtx, desc, NULL, MTX_DEF)
  67. #define smb_sl_destroy(mtx) mtx_destroy(mtx)
  68. #define smb_sl_lock(mtx) mtx_lock(mtx)
  69. #define smb_sl_unlock(mtx) mtx_unlock(mtx)
  70. #define SMB_STRFREE(p) do { if (p) smb_strfree(p); } while(0)
  71. typedef u_int16_t smb_unichar;
  72. typedef smb_unichar *smb_uniptr;
  73. /*
  74. * Crediantials of user/process being processing in the connection procedures
  75. */
  76. struct smb_cred {
  77. struct thread * scr_td;
  78. struct ucred * scr_cred;
  79. };
  80. extern smb_unichar smb_unieol;
  81. struct mbchain;
  82. struct smb_vc;
  83. struct smb_rq;
  84. void smb_makescred(struct smb_cred *scred, struct thread *td, struct ucred *cred);
  85. int smb_td_intr(struct thread *);
  86. char *smb_strdup(const char *s);
  87. void *smb_memdup(const void *umem, int len);
  88. char *smb_strdupin(char *s, size_t maxlen);
  89. void *smb_memdupin(void *umem, size_t len);
  90. void smb_strtouni(u_int16_t *dst, const char *src);
  91. void smb_strfree(char *s);
  92. void smb_memfree(void *s);
  93. void *smb_zmalloc(size_t size, struct malloc_type *type, int flags);
  94. int smb_calcmackey(struct smb_vc *vcp);
  95. int smb_encrypt(const u_char *apwd, u_char *C8, u_char *RN);
  96. int smb_ntencrypt(const u_char *apwd, u_char *C8, u_char *RN);
  97. int smb_maperror(int eclass, int eno);
  98. int smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp,
  99. const char *src, size_t len, int caseopt);
  100. int smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp,
  101. const char *src, int caseopt);
  102. int smb_put_string(struct smb_rq *rqp, const char *src);
  103. int smb_put_asunistring(struct smb_rq *rqp, const char *src);
  104. int smb_rq_sign(struct smb_rq *rqp);
  105. int smb_rq_verify(struct smb_rq *rqp);
  106. #endif /* !_NETSMB_SMB_SUBR_H_ */