dbutil.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Dropbear - a SSH2 server
  3. *
  4. * Copyright (c) 2002,2003 Matt Johnston
  5. * All rights reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE. */
  24. #ifndef DROPBEAR_DBUTIL_H_
  25. #define DROPBEAR_DBUTIL_H_
  26. #include "includes.h"
  27. #include "buffer.h"
  28. #include "queue.h"
  29. #include "dbhelpers.h"
  30. #include "dbmalloc.h"
  31. #ifndef DISABLE_SYSLOG
  32. void startsyslog(const char *ident);
  33. #endif
  34. extern void (*_dropbear_exit)(int exitcode, const char* format, va_list param) ATTRIB_NORETURN;
  35. extern void (*_dropbear_log)(int priority, const char* format, va_list param);
  36. void dropbear_exit(const char* format, ...) ATTRIB_PRINTF(1,2) ATTRIB_NORETURN;
  37. void dropbear_close(const char* format, ...) ATTRIB_PRINTF(1,2) ;
  38. void dropbear_log(int priority, const char* format, ...) ATTRIB_PRINTF(2,3) ;
  39. void fail_assert(const char* expr, const char* file, int line) ATTRIB_NORETURN;
  40. #if DEBUG_TRACE
  41. void dropbear_trace1(const char* format, ...) ATTRIB_PRINTF(1,2);
  42. void dropbear_trace2(const char* format, ...) ATTRIB_PRINTF(1,2);
  43. void dropbear_trace3(const char* format, ...) ATTRIB_PRINTF(1,2);
  44. void dropbear_trace4(const char* format, ...) ATTRIB_PRINTF(1,2);
  45. void dropbear_trace5(const char* format, ...) ATTRIB_PRINTF(1,2);
  46. void printhex(const char * label, const unsigned char * buf, int len);
  47. void printmpint(const char *label, mp_int *mp);
  48. void debug_start_net(void);
  49. extern int debug_trace;
  50. #endif
  51. char * stripcontrol(const char * text);
  52. int spawn_command(void(*exec_fn)(const void *user_data), const void *exec_data,
  53. int *writefd, int *readfd, int *errfd, pid_t *pid);
  54. void run_shell_command(const char* cmd, unsigned int maxfd, char* usershell);
  55. #if ENABLE_CONNECT_UNIX
  56. int connect_unix(const char* addr);
  57. #endif
  58. int buf_readfile(buffer* buf, const char* filename);
  59. int buf_getline(buffer * line, FILE * authfile);
  60. void m_close(int fd);
  61. void setnonblocking(int fd);
  62. void disallow_core(void);
  63. int m_str_to_uint(const char* str, unsigned int *val);
  64. /* The same as snprintf() but exits rather than returning negative */
  65. int m_snprintf(char *str, size_t size, const char *format, ...);
  66. /* Used to force mp_ints to be initialised */
  67. #define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  68. /* Dropbear assertion */
  69. #define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  70. /* Returns 0 if a and b have the same contents */
  71. int constant_time_memcmp(const void* a, const void *b, size_t n);
  72. /* Returns a time in seconds that doesn't go backwards - does not correspond to
  73. a real-world clock */
  74. time_t monotonic_now(void);
  75. /* Higher resolution clock_gettime(CLOCK_MONOTONIC) wrapper */
  76. void gettime_wrapper(struct timespec *now);
  77. char * expand_homedir_path(const char *inpath);
  78. void fsync_parent_dir(const char* fn);
  79. int fd_read_pending(int fd);
  80. #if DROPBEAR_MSAN
  81. /* FD_ZERO seems to leave some memory uninitialized. clear it to avoid false positives */
  82. #define DROPBEAR_FD_ZERO(fds) do { memset((fds), 0x0, sizeof(fd_set)); FD_ZERO(fds); } while(0)
  83. #else
  84. #define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  85. #endif
  86. /* dropbearmulti entry points */
  87. int dropbear_main(int argc, char ** argv, const char * multipath);
  88. int cli_main(int argc, char ** argv);
  89. int dropbearkey_main(int argc, char ** argv);
  90. int dropbearconvert_main(int argc, char ** argv);
  91. int scp_main(int argc, char ** argv);
  92. #endif /* DROPBEAR_DBUTIL_H_ */