dbutil.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #ifndef DISABLE_SYSLOG
  31. void startsyslog(const char *ident);
  32. #endif
  33. extern void (*_dropbear_exit)(int exitcode, const char* format, va_list param) ATTRIB_NORETURN;
  34. extern void (*_dropbear_log)(int priority, const char* format, va_list param);
  35. void dropbear_exit(const char* format, ...) ATTRIB_PRINTF(1,2) ATTRIB_NORETURN;
  36. void dropbear_close(const char* format, ...) ATTRIB_PRINTF(1,2) ;
  37. void dropbear_log(int priority, const char* format, ...) ATTRIB_PRINTF(2,3) ;
  38. void fail_assert(const char* expr, const char* file, int line) ATTRIB_NORETURN;
  39. #ifdef DEBUG_TRACE
  40. void dropbear_trace(const char* format, ...) ATTRIB_PRINTF(1,2);
  41. void dropbear_trace2(const char* format, ...) ATTRIB_PRINTF(1,2);
  42. void printhex(const char * label, const unsigned char * buf, int len);
  43. void printmpint(const char *label, mp_int *mp);
  44. void debug_start_net(void);
  45. extern int debug_trace;
  46. #endif
  47. char * stripcontrol(const char * text);
  48. int spawn_command(void(*exec_fn)(void *user_data), void *exec_data,
  49. int *writefd, int *readfd, int *errfd, pid_t *pid);
  50. void run_shell_command(const char* cmd, unsigned int maxfd, char* usershell);
  51. #ifdef ENABLE_CONNECT_UNIX
  52. int connect_unix(const char* addr);
  53. #endif
  54. int buf_readfile(buffer* buf, const char* filename);
  55. int buf_getline(buffer * line, FILE * authfile);
  56. void m_close(int fd);
  57. void * m_malloc(size_t size);
  58. void * m_strdup(const char * str);
  59. void * m_realloc(void* ptr, size_t size);
  60. #define m_free(X) do {free(X); (X) = NULL;} while (0)
  61. void setnonblocking(int fd);
  62. void disallow_core(void);
  63. int m_str_to_uint(const char* str, unsigned int *val);
  64. /* Used to force mp_ints to be initialised */
  65. #define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  66. /* Dropbear assertion */
  67. #define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  68. /* Returns 0 if a and b have the same contents */
  69. int constant_time_memcmp(const void* a, const void *b, size_t n);
  70. /* Returns a time in seconds that doesn't go backwards - does not correspond to
  71. a real-world clock */
  72. time_t monotonic_now(void);
  73. char * expand_homedir_path(const char *inpath);
  74. void fsync_parent_dir(const char* fn);
  75. #endif /* DROPBEAR_DBUTIL_H_ */