Line | Count | Source (jump to first uncovered line) |
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 | | |
25 | | #ifndef DROPBEAR_DBUTIL_H_ |
26 | | |
27 | | #define DROPBEAR_DBUTIL_H_ |
28 | | |
29 | | #include "includes.h" |
30 | | #include "buffer.h" |
31 | | #include "queue.h" |
32 | | #include "dbhelpers.h" |
33 | | #include "dbmalloc.h" |
34 | | |
35 | | #ifndef DISABLE_SYSLOG |
36 | | void startsyslog(const char *ident); |
37 | | #endif |
38 | | |
39 | | extern void (*_dropbear_exit)(int exitcode, const char* format, va_list param) ATTRIB_NORETURN; |
40 | | extern void (*_dropbear_log)(int priority, const char* format, va_list param); |
41 | | |
42 | | void dropbear_exit(const char* format, ...) ATTRIB_PRINTF(1,2) ATTRIB_NORETURN; |
43 | | |
44 | | void dropbear_close(const char* format, ...) ATTRIB_PRINTF(1,2) ; |
45 | | void dropbear_log(int priority, const char* format, ...) ATTRIB_PRINTF(2,3) ; |
46 | | |
47 | | void fail_assert(const char* expr, const char* file, int line) ATTRIB_NORETURN; |
48 | | |
49 | | #if DEBUG_TRACE |
50 | | void dropbear_trace1(const char* format, ...) ATTRIB_PRINTF(1,2); |
51 | | void dropbear_trace2(const char* format, ...) ATTRIB_PRINTF(1,2); |
52 | | void dropbear_trace3(const char* format, ...) ATTRIB_PRINTF(1,2); |
53 | | void dropbear_trace4(const char* format, ...) ATTRIB_PRINTF(1,2); |
54 | | void dropbear_trace5(const char* format, ...) ATTRIB_PRINTF(1,2); |
55 | | void printhex(const char * label, const unsigned char * buf, int len); |
56 | | void printmpint(const char *label, const mp_int *mp); |
57 | | void debug_start_net(void); |
58 | | extern int debug_trace; |
59 | | #endif |
60 | | |
61 | | char * stripcontrol(const char * text); |
62 | | |
63 | | int spawn_command(void(*exec_fn)(const void *user_data), const void *exec_data, |
64 | | int *writefd, int *readfd, int *errfd, pid_t *pid); |
65 | | void run_shell_command(const char* cmd, unsigned int maxfd, char* usershell); |
66 | | #if ENABLE_CONNECT_UNIX |
67 | | int connect_unix(const char* addr); |
68 | | #endif |
69 | | int buf_readfile(buffer* buf, const char* filename); |
70 | | int buf_getline(buffer * line, FILE * authfile); |
71 | | |
72 | | void m_close(int fd); |
73 | | void setnonblocking(int fd); |
74 | | void disallow_core(void); |
75 | | int m_str_to_uint(const char* str, unsigned int *val); |
76 | | /* The same as snprintf() but exits rather than returning negative */ |
77 | | int m_snprintf(char *str, size_t size, const char *format, ...); |
78 | | |
79 | | /* Used to force mp_ints to be initialised */ |
80 | 0 | #define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL} |
81 | | |
82 | | /* Dropbear assertion */ |
83 | 9.08k | #define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0) |
84 | | |
85 | | /* Returns 0 if a and b have the same contents */ |
86 | | int constant_time_memcmp(const void* a, const void *b, size_t n); |
87 | | |
88 | | /* Returns a time in seconds that doesn't go backwards - does not correspond to |
89 | | a real-world clock */ |
90 | | time_t monotonic_now(void); |
91 | | /* Higher resolution clock_gettime(CLOCK_MONOTONIC) wrapper */ |
92 | | void gettime_wrapper(struct timespec *now); |
93 | | |
94 | | char * expand_homedir_path(const char *inpath); |
95 | | |
96 | | void fsync_parent_dir(const char* fn); |
97 | | |
98 | | int fd_read_pending(int fd); |
99 | | |
100 | | #if DROPBEAR_MSAN |
101 | | /* FD_ZERO seems to leave some memory uninitialized. clear it to avoid false positives */ |
102 | | #define DROPBEAR_FD_ZERO(fds) do { memset((fds), 0x0, sizeof(fd_set)); FD_ZERO(fds); } while(0) |
103 | | #else |
104 | 171k | #define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds) |
105 | | #endif |
106 | | |
107 | | /* dropbearmulti entry points */ |
108 | | int dropbear_main(int argc, char ** argv, const char * multipath); |
109 | | int cli_main(int argc, char ** argv); |
110 | | int dropbearkey_main(int argc, char ** argv); |
111 | | int dropbearconvert_main(int argc, char ** argv); |
112 | | int scp_main(int argc, char ** argv); |
113 | | |
114 | | |
115 | | #endif /* DROPBEAR_DBUTIL_H_ */ |