dbutil.h 3.41 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * Dropbear - a SSH2 server
 * 
 * Copyright (c) 2002,2003 Matt Johnston
 * All rights reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE. */

25
#ifndef DROPBEAR_DBUTIL_H_
26

27
#define DROPBEAR_DBUTIL_H_
28
29
30

#include "includes.h"
#include "buffer.h"
31
#include "queue.h"
32
#include "dbhelpers.h"
33
34

#ifndef DISABLE_SYSLOG
35
void startsyslog(const char *ident);
36
37
#endif

38
extern void (*_dropbear_exit)(int exitcode, const char* format, va_list param) ATTRIB_NORETURN;
39
40
extern void (*_dropbear_log)(int priority, const char* format, va_list param);

41
42
43
44
45
46
47
void dropbear_exit(const char* format, ...) ATTRIB_PRINTF(1,2) ATTRIB_NORETURN;

void dropbear_close(const char* format, ...) ATTRIB_PRINTF(1,2) ;
void dropbear_log(int priority, const char* format, ...) ATTRIB_PRINTF(2,3) ;

void fail_assert(const char* expr, const char* file, int line) ATTRIB_NORETURN;

48
#if DEBUG_TRACE
49
void dropbear_trace(const char* format, ...) ATTRIB_PRINTF(1,2);
50
void dropbear_trace2(const char* format, ...) ATTRIB_PRINTF(1,2);
51
void printhex(const char * label, const unsigned char * buf, int len);
Matt Johnston's avatar
Matt Johnston committed
52
void printmpint(const char *label, mp_int *mp);
Francois Perrad's avatar
Francois Perrad committed
53
void debug_start_net(void);
54
extern int debug_trace;
55
#endif
56

57
char * stripcontrol(const char * text);
Matt Johnston's avatar
Matt Johnston committed
58

59
60
int spawn_command(void(*exec_fn)(void *user_data), void *exec_data,
		int *writefd, int *readfd, int *errfd, pid_t *pid);
61
void run_shell_command(const char* cmd, unsigned int maxfd, char* usershell);
62
63
64
#ifdef ENABLE_CONNECT_UNIX
int connect_unix(const char* addr);
#endif
65
int buf_readfile(buffer* buf, const char* filename);
66
int buf_getline(buffer * line, FILE * authfile);
67

68
void m_close(int fd);
69
void * m_malloc(size_t size);
70
void * m_strdup(const char * str);
71
void * m_realloc(void* ptr, size_t size);
72
#define m_free(X) do {free(X); (X) = NULL;} while (0)
73
void setnonblocking(int fd);
Francois Perrad's avatar
Francois Perrad committed
74
void disallow_core(void);
75
int m_str_to_uint(const char* str, unsigned int *val);
76

Matt Johnston's avatar
Matt Johnston committed
77
78
79
/* Used to force mp_ints to be initialised */
#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}

80
81
82
/* Dropbear assertion */
#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)

83
84
85
/* Returns 0 if a and b have the same contents */
int constant_time_memcmp(const void* a, const void *b, size_t n);

86
87
/* Returns a time in seconds that doesn't go backwards - does not correspond to
a real-world clock */
Francois Perrad's avatar
Francois Perrad committed
88
time_t monotonic_now(void);
89

90
char * expand_homedir_path(const char *inpath);
91

92
93
void fsync_parent_dir(const char* fn);

94
#endif /* DROPBEAR_DBUTIL_H_ */