smb_dev.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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_DEV_H_
  31. #define _NETSMB_DEV_H_
  32. #ifndef _KERNEL
  33. #include <sys/types.h>
  34. #endif
  35. #include <sys/ioccom.h>
  36. #include <netsmb/smb.h>
  37. #define NSMB_NAME "nsmb"
  38. #define NSMB_VERMAJ 1
  39. #define NSMB_VERMIN 3006
  40. #define NSMB_VERSION (NSMB_VERMAJ * 100000 + NSMB_VERMIN)
  41. #define NSMBFL_OPEN 0x0001
  42. #define SMBVOPT_CREATE 0x0001 /* create object if necessary */
  43. #define SMBVOPT_PRIVATE 0x0002 /* connection should be private */
  44. #define SMBVOPT_SINGLESHARE 0x0004 /* keep only one share at this VC */
  45. #define SMBVOPT_PERMANENT 0x0010 /* object will keep last reference */
  46. #define SMBSOPT_CREATE 0x0001 /* create object if necessary */
  47. #define SMBSOPT_PERMANENT 0x0010 /* object will keep last reference */
  48. /*
  49. * SMBIOC_LOOKUP flags
  50. */
  51. #define SMBLK_CREATE 0x0001
  52. struct smbioc_ossn {
  53. int ioc_opt;
  54. uint32_t ioc_svlen; /* size of ioc_server address */
  55. struct sockaddr*ioc_server;
  56. uint32_t ioc_lolen; /* size of ioc_local address */
  57. struct sockaddr*ioc_local;
  58. char ioc_srvname[SMB_MAXSRVNAMELEN + 1];
  59. int ioc_timeout;
  60. int ioc_retrycount; /* number of retries before giveup */
  61. char ioc_localcs[16];/* local charset */
  62. char ioc_servercs[16];/* server charset */
  63. char ioc_user[SMB_MAXUSERNAMELEN + 1];
  64. char ioc_workgroup[SMB_MAXUSERNAMELEN + 1];
  65. char ioc_password[SMB_MAXPASSWORDLEN + 1];
  66. uid_t ioc_owner; /* proposed owner */
  67. gid_t ioc_group; /* proposed group */
  68. mode_t ioc_mode; /* desired access mode */
  69. mode_t ioc_rights; /* SMBM_* */
  70. };
  71. struct smbioc_oshare {
  72. int ioc_opt;
  73. int ioc_stype; /* share type */
  74. char ioc_share[SMB_MAXSHARENAMELEN + 1];
  75. char ioc_password[SMB_MAXPASSWORDLEN + 1];
  76. uid_t ioc_owner; /* proposed owner of share */
  77. gid_t ioc_group; /* proposed group of share */
  78. mode_t ioc_mode; /* desired access mode to share */
  79. mode_t ioc_rights; /* SMBM_* */
  80. };
  81. struct smbioc_rq {
  82. u_char ioc_cmd;
  83. u_char ioc_twc;
  84. void * ioc_twords;
  85. u_short ioc_tbc;
  86. void * ioc_tbytes;
  87. int ioc_rpbufsz;
  88. char * ioc_rpbuf;
  89. u_char ioc_rwc;
  90. u_short ioc_rbc;
  91. u_int8_t ioc_errclass;
  92. u_int16_t ioc_serror;
  93. u_int32_t ioc_error;
  94. };
  95. struct smbioc_t2rq {
  96. u_int16_t ioc_setup[3];
  97. int ioc_setupcnt;
  98. char * ioc_name;
  99. u_short ioc_tparamcnt;
  100. void * ioc_tparam;
  101. u_short ioc_tdatacnt;
  102. void * ioc_tdata;
  103. u_short ioc_rparamcnt;
  104. void * ioc_rparam;
  105. u_short ioc_rdatacnt;
  106. void * ioc_rdata;
  107. };
  108. struct smbioc_flags {
  109. int ioc_level; /* 0 - session, 1 - share */
  110. int ioc_mask;
  111. int ioc_flags;
  112. };
  113. struct smbioc_lookup {
  114. int ioc_level;
  115. int ioc_flags;
  116. struct smbioc_ossn ioc_ssn;
  117. struct smbioc_oshare ioc_sh;
  118. };
  119. struct smbioc_rw {
  120. smbfh ioc_fh;
  121. char * ioc_base;
  122. off_t ioc_offset;
  123. int ioc_cnt;
  124. };
  125. /*
  126. * Device IOCTLs
  127. */
  128. #define SMBIOC_OPENSESSION _IOW('n', 100, struct smbioc_ossn)
  129. #define SMBIOC_OPENSHARE _IOW('n', 101, struct smbioc_oshare)
  130. #define SMBIOC_REQUEST _IOWR('n', 102, struct smbioc_rq)
  131. #define SMBIOC_T2RQ _IOWR('n', 103, struct smbioc_t2rq)
  132. #define SMBIOC_SETFLAGS _IOW('n', 104, struct smbioc_flags)
  133. #define SMBIOC_LOOKUP _IOW('n', 106, struct smbioc_lookup)
  134. #define SMBIOC_READ _IOWR('n', 107, struct smbioc_rw)
  135. #define SMBIOC_WRITE _IOWR('n', 108, struct smbioc_rw)
  136. #ifdef _KERNEL
  137. #define SMBST_CONNECTED 1
  138. STAILQ_HEAD(smbrqh, smb_rq);
  139. struct smb_dev {
  140. struct cdev * dev;
  141. int sd_opened;
  142. int sd_level;
  143. struct smb_vc * sd_vc; /* reference to VC */
  144. struct smb_share *sd_share; /* reference to share if any */
  145. int sd_poll;
  146. int sd_seq;
  147. int sd_flags;
  148. int refcount;
  149. int usecount;
  150. };
  151. extern struct sx smb_lock;
  152. #define SMB_LOCK() sx_xlock(&smb_lock)
  153. #define SMB_UNLOCK() sx_unlock(&smb_lock)
  154. #define SMB_LOCKASSERT() sx_assert(&smb_lock, SA_XLOCKED)
  155. struct smb_cred;
  156. void sdp_dtor(void *arg);
  157. void sdp_trydestroy(struct smb_dev *dev);
  158. /*
  159. * Compound user interface
  160. */
  161. int smb_usr_lookup(struct smbioc_lookup *dp, struct smb_cred *scred,
  162. struct smb_vc **vcpp, struct smb_share **sspp);
  163. int smb_usr_opensession(struct smbioc_ossn *data,
  164. struct smb_cred *scred, struct smb_vc **vcpp);
  165. int smb_usr_openshare(struct smb_vc *vcp, struct smbioc_oshare *data,
  166. struct smb_cred *scred, struct smb_share **sspp);
  167. int smb_usr_simplerequest(struct smb_share *ssp, struct smbioc_rq *data,
  168. struct smb_cred *scred);
  169. int smb_usr_t2request(struct smb_share *ssp, struct smbioc_t2rq *data,
  170. struct smb_cred *scred);
  171. int smb_dev2share(int fd, int mode, struct smb_cred *scred,
  172. struct smb_share **sspp, struct smb_dev **ssdp);
  173. #endif /* _KERNEL */
  174. #endif /* _NETSMB_DEV_H_ */