privsock.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #ifndef VSF_PRIVSOCK_H
  2. #define VSF_PRIVSOCK_H
  3. struct mystr;
  4. struct vsf_session;
  5. /* priv_sock_init()
  6. * PURPOSE
  7. * Initialize the priv_sock system, by opening the communications sockets.
  8. *
  9. * PARAMETERS
  10. * p_sess - the current session object
  11. */
  12. void priv_sock_init(struct vsf_session* p_sess);
  13. /* priv_sock_close()
  14. * PURPOSE
  15. * Closes any open file descriptors relating to the priv_sock system.
  16. *
  17. * PARAMETERS
  18. * p_sess - the current session object
  19. */
  20. void priv_sock_close(struct vsf_session* p_sess);
  21. /* priv_sock_set_parent_context()
  22. * PURPOSE
  23. * Closes the child's fd, e.g. p_sess->child_fd.
  24. *
  25. * PARAMETERS
  26. * p_sess - the current session object
  27. */
  28. void priv_sock_set_parent_context(struct vsf_session* p_sess);
  29. /* priv_sock_set_child_context()
  30. * PURPOSE
  31. * Closes the parent's fd, e.g. p_sess->parent_fd.
  32. *
  33. * PARAMETERS
  34. * p_sess - the current session object
  35. */
  36. void priv_sock_set_child_context(struct vsf_session* p_sess);
  37. /* priv_sock_send_cmd()
  38. * PURPOSE
  39. * Sends a command, typically to the privileged side of the channel.
  40. * PARAMETERS
  41. * fd - the fd on which to send the command
  42. * cmd - the command to send
  43. */
  44. void priv_sock_send_cmd(int fd, char cmd);
  45. /* priv_sock_send_str()
  46. * PURPOSE
  47. * Sends a string to the other side of the channel.
  48. * PARAMETERS
  49. * fd - the fd on which to send the string
  50. * p_str - the string to send
  51. */
  52. void priv_sock_send_str(int fd, const struct mystr* p_str);
  53. /* priv_sock_send_buf()
  54. * PURPOSE
  55. * Sends a buffer to the other side of the channel. The protocol used is the
  56. * same as priv_sock_send_str()
  57. * PARAMETERS
  58. * fd - the fd on which to send the buffer
  59. * p_buf - the buffer to send
  60. * len - length of the buffer
  61. */
  62. void priv_sock_send_buf(int fd, const char* p_buf, unsigned int len);
  63. /* priv_sock_recv_buf()
  64. * PURPOSE
  65. * Receives a buffer from the other side of the channel. The protocol used is
  66. * the same as priv_sock_recv_str()
  67. * PARAMETERS
  68. * fd - the fd on which to receive the buffer
  69. * p_buf - the buffer to write into
  70. * len - length of the buffer
  71. */
  72. void priv_sock_recv_buf(int fd, char* p_buf, unsigned int len);
  73. /* priv_sock_get_result()
  74. * PURPOSE
  75. * Receives a response, typically from the privileged side of the channel.
  76. * PARAMETERS
  77. * fd - the fd on which to receive the response
  78. * RETURNS
  79. * The response code.
  80. */
  81. char priv_sock_get_result(int fd);
  82. /* priv_sock_get_cmd()
  83. * PURPOSE
  84. * Receives a command, typically on the privileged side of the channel.
  85. * PARAMETERS
  86. * fd - the fd on which to receive the command.
  87. * RETURNS
  88. * The command that was sent.
  89. */
  90. char priv_sock_get_cmd(int fd);
  91. /* priv_sock_get_str()
  92. * PURPOSE
  93. * Receives a string from the other side of the channel.
  94. * PARAMETERS
  95. * fd - the fd on which to receive the string
  96. * p_dest - where to copy the received string
  97. */
  98. void priv_sock_get_str(int fd, struct mystr* p_dest);
  99. /* priv_sock_send_result()
  100. * PURPOSE
  101. * Sends a command result, typically to the unprivileged side of the channel.
  102. * PARAMETERS
  103. * fd - the fd on which to send the result
  104. * res - the result to send
  105. */
  106. void priv_sock_send_result(int fd, char res);
  107. /* priv_sock_send_fd()
  108. * PURPOSE
  109. * Sends a file descriptor to the other side of the channel.
  110. * PARAMETERS
  111. * fd - the fd on which to send the descriptor
  112. * send_fd - the descriptor to send
  113. */
  114. void priv_sock_send_fd(int fd, int send_fd);
  115. /* priv_sock_recv_fd()
  116. * PURPOSE
  117. * Receives a file descriptor from the other side of the channel.
  118. * PARAMETERS
  119. * fd - the fd on which to receive the descriptor
  120. * RETURNS
  121. * The received file descriptor
  122. */
  123. int priv_sock_recv_fd(int fd);
  124. /* priv_sock_send_int()
  125. * PURPOSE
  126. * Sends an integer to the other side of the channel.
  127. * PARAMETERS
  128. * fd - the fd on which to send the integer
  129. * the_int - the integer to send
  130. */
  131. void priv_sock_send_int(int fd, int the_int);
  132. /* priv_sock_get_int()
  133. * PURPOSE
  134. * Receives an integer from the other side of the channel.
  135. * PARAMETERS
  136. * fd - the fd on which to receive the integer
  137. * RETURNS
  138. * The integer that was sent.
  139. */
  140. int priv_sock_get_int(int fd);
  141. #define PRIV_SOCK_LOGIN 1
  142. #define PRIV_SOCK_CHOWN 2
  143. #define PRIV_SOCK_GET_DATA_SOCK 3
  144. #define PRIV_SOCK_GET_USER_CMD 4
  145. #define PRIV_SOCK_WRITE_USER_RESP 5
  146. #define PRIV_SOCK_DO_SSL_HANDSHAKE 6
  147. #define PRIV_SOCK_DO_SSL_CLOSE 7
  148. #define PRIV_SOCK_DO_SSL_READ 8
  149. #define PRIV_SOCK_DO_SSL_WRITE 9
  150. #define PRIV_SOCK_PASV_CLEANUP 10
  151. #define PRIV_SOCK_PASV_ACTIVE 11
  152. #define PRIV_SOCK_PASV_LISTEN 12
  153. #define PRIV_SOCK_PASV_ACCEPT 13
  154. #define PRIV_SOCK_RESULT_OK 1
  155. #define PRIV_SOCK_RESULT_BAD 2
  156. #endif /* VSF_PRIVSOCK_H */