2 * Prototypes for lib directory of Bacula
7 Bacula® - The Network Backup Solution
9 Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
11 The main author of Bacula is Kern Sibbald, with contributions from
12 many others, a complete list can be found in the file AUTHORS.
13 This program is Free Software; you can redistribute it and/or
14 modify it under the terms of version two of the GNU General Public
15 License as published by the Free Software Foundation plus additions
16 that are listed in the file LICENSE.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 Bacula® is a registered trademark of John Walker.
29 The licensor of Bacula is the Free Software Foundation Europe
30 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
31 Switzerland, email:ftf@fsfeurope.org.
38 void free_attr(ATTR *attr);
39 int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, ATTR *attr);
40 void build_attr_output_fnames(JCR *jcr, ATTR *attr);
41 void print_ls_output(JCR *jcr, ATTR *attr);
44 void base64_init (void);
45 int to_base64 (intmax_t value, char *where);
46 int from_base64 (intmax_t *value, char *where);
47 int bin_to_base64 (char *buf, int buflen, char *bin, int binlen,
51 char *bstrncpy (char *dest, const char *src, int maxlen);
52 char *bstrncpy (char *dest, POOL_MEM &src, int maxlen);
53 char *bstrncat (char *dest, const char *src, int maxlen);
54 char *bstrncat (char *dest, POOL_MEM &src, int maxlen);
55 bool bstrcmp (const char *s1, const char *s2);
56 int cstrlen (const char *str);
57 void *b_malloc (const char *file, int line, size_t size);
59 void *bmalloc (size_t size);
61 void bfree (void *buf);
62 void *brealloc (void *buf, size_t size);
63 void *bcalloc (size_t size1, size_t size2);
64 int bsnprintf (char *str, int32_t size, const char *format, ...);
65 int bvsnprintf (char *str, int32_t size, const char *format, va_list ap);
66 int pool_sprintf (char *pool_buf, const char *fmt, ...);
67 void create_pid_file (char *dir, const char *progname, int port);
68 int delete_pid_file (char *dir, const char *progname, int port);
69 void drop (char *uid, char *gid);
70 int bmicrosleep (time_t sec, long usec);
71 char *bfgets (char *s, int size, FILE *fd);
72 void make_unique_filename (POOLMEM **name, int Id, char *what);
74 long long int strtoll (const char *ptr, char **endptr, int base);
76 void read_state_file(char *dir, const char *progname, int port);
77 int bstrerror(int errnum, char *buf, size_t bufsiz);
78 char *escape_filename(const char *file_path);
81 int32_t bnet_recv (BSOCK *bsock);
82 bool bnet_send (BSOCK *bsock);
83 bool bnet_fsend (BSOCK *bs, const char *fmt, ...);
84 bool bnet_set_buffer_size (BSOCK *bs, uint32_t size, int rw);
85 bool bnet_sig (BSOCK *bs, int sig);
86 bool bnet_tls_server (TLS_CONTEXT *ctx, BSOCK *bsock,
88 bool bnet_tls_client (TLS_CONTEXT *ctx, BSOCK *bsock);
89 BSOCK * bnet_connect (JCR *jcr, int retry_interval,
90 int max_retry_time, const char *name, char *host, char *service,
91 int port, int verbose);
92 void bnet_close (BSOCK *bsock);
93 BSOCK * init_bsock (JCR *jcr, int sockfd, const char *who, const char *ip,
94 int port, struct sockaddr *client_addr);
100 int bnet_get_peer (BSOCK *bs, char *buf, socklen_t buflen);
101 BSOCK * dup_bsock (BSOCK *bsock);
102 void term_bsock (BSOCK *bsock);
103 const char *bnet_strerror (BSOCK *bsock);
104 const char *bnet_sig_to_ascii (BSOCK *bsock);
105 int bnet_wait_data (BSOCK *bsock, int sec);
106 int bnet_wait_data_intr (BSOCK *bsock, int sec);
107 int bnet_despool_to_bsock (BSOCK *bsock, void update(ssize_t size), ssize_t size);
108 bool is_bnet_stop (BSOCK *bsock);
109 int is_bnet_error (BSOCK *bsock);
110 void bnet_suppress_error_messages(BSOCK *bsock, bool flag);
111 dlist *bnet_host2ipaddrs(const char *host, int family, const char **errstr);
112 int bnet_set_blocking (BSOCK *sock);
113 int bnet_set_nonblocking (BSOCK *sock);
114 void bnet_restore_blocking (BSOCK *sock, int flags);
117 int bget_msg(BSOCK *sock);
120 BPIPE * open_bpipe(char *prog, int wait, const char *mode);
121 int close_wpipe(BPIPE *bpipe);
122 int close_bpipe(BPIPE *bpipe);
125 bool cram_md5_respond(BSOCK *bs, char *password, int *tls_remote_need, int *compatible);
126 bool cram_md5_challenge(BSOCK *bs, char *password, int tls_local_need, int compatible);
127 void hmac_md5(uint8_t* text, int text_len, uint8_t* key, int key_len, uint8_t *hmac);
131 uint32_t bcrc32(uint8_t *buf, int len);
134 int init_crypto (void);
135 int cleanup_crypto (void);
136 DIGEST * crypto_digest_new (crypto_digest_t type);
137 bool crypto_digest_update (DIGEST *digest, const uint8_t *data, uint32_t length);
138 bool crypto_digest_finalize (DIGEST *digest, uint8_t *dest, uint32_t *length);
139 void crypto_digest_free (DIGEST *digest);
140 SIGNATURE * crypto_sign_new (void);
141 crypto_error_t crypto_sign_get_digest (SIGNATURE *sig, X509_KEYPAIR *keypair, DIGEST **digest);
142 crypto_error_t crypto_sign_verify (SIGNATURE *sig, X509_KEYPAIR *keypair, DIGEST *digest);
143 int crypto_sign_add_signer (SIGNATURE *sig, DIGEST *digest, X509_KEYPAIR *keypair);
144 int crypto_sign_encode (SIGNATURE *sig, uint8_t *dest, uint32_t *length);
145 SIGNATURE * crypto_sign_decode (const uint8_t *sigData, uint32_t length);
146 void crypto_sign_free (SIGNATURE *sig);
147 CRYPTO_SESSION * crypto_session_new (crypto_cipher_t cipher, alist *pubkeys);
148 void crypto_session_free (CRYPTO_SESSION *cs);
149 bool crypto_session_encode (CRYPTO_SESSION *cs, uint8_t *dest, uint32_t *length);
150 crypto_error_t crypto_session_decode (const uint8_t *data, uint32_t length, alist *keypairs, CRYPTO_SESSION **session);
151 CRYPTO_SESSION * crypto_session_decode (const uint8_t *data, uint32_t length);
152 CIPHER_CONTEXT * crypto_cipher_new (CRYPTO_SESSION *cs, bool encrypt, uint32_t *blocksize);
153 bool crypto_cipher_update (CIPHER_CONTEXT *cipher_ctx, const uint8_t *data, uint32_t length, const uint8_t *dest, uint32_t *written);
154 bool crypto_cipher_finalize (CIPHER_CONTEXT *cipher_ctx, uint8_t *dest, uint32_t *written);
155 void crypto_cipher_free (CIPHER_CONTEXT *cipher_ctx);
156 X509_KEYPAIR * crypto_keypair_new (void);
157 X509_KEYPAIR * crypto_keypair_dup (X509_KEYPAIR *keypair);
158 int crypto_keypair_load_cert (X509_KEYPAIR *keypair, const char *file);
159 bool crypto_keypair_has_key (const char *file);
160 int crypto_keypair_load_key (X509_KEYPAIR *keypair, const char *file, CRYPTO_PEM_PASSWD_CB *pem_callback, const void *pem_userdata);
161 void crypto_keypair_free (X509_KEYPAIR *keypair);
162 int crypto_default_pem_callback (char *buf, int size, const void *userdata);
163 const char * crypto_digest_name (DIGEST *digest);
164 crypto_digest_t crypto_digest_stream_type (int stream);
165 const char * crypto_strerror (crypto_error_t error);
168 void daemon_start ();
171 uint64_t str_to_uint64(char *str);
172 int64_t str_to_int64(char *str);
173 #define str_to_int32(str) ((int32_t)str_to_int64(str))
174 char * edit_uint64_with_commas (uint64_t val, char *buf);
175 char * edit_uint64_with_suffix (uint64_t val, char *buf);
176 char * add_commas (char *val, char *buf);
177 char * edit_uint64 (uint64_t val, char *buf);
178 char * edit_int64 (int64_t val, char *buf);
179 bool duration_to_utime (char *str, utime_t *value);
180 bool size_to_uint64(char *str, int str_len, uint64_t *rtn_value);
181 char *edit_utime (utime_t val, char *buf, int buf_len);
182 bool is_a_number (const char *num);
183 bool is_an_integer (const char *n);
184 bool is_name_valid (char *name, POOLMEM **msg);
186 /* jcr.c (most definitions are in src/jcr.h) */
187 void init_last_jobs_list();
188 void term_last_jobs_list();
189 void lock_last_jobs_list();
190 void unlock_last_jobs_list();
191 bool read_last_jobs_list(int fd, uint64_t addr);
192 uint64_t write_last_jobs_list(int fd, uint64_t addr);
193 void write_state_file(char *dir, const char *progname, int port);
194 void job_end_push(JCR *jcr, void job_end_cb(JCR *jcr,void *), void *ctx);
197 JCR *jcr_walk_start();
198 JCR *jcr_walk_next(JCR *prev_jcr);
199 void jcr_walk_end(JCR *jcr);
203 LEX * lex_close_file (LEX *lf);
204 LEX * lex_open_file (LEX *lf, const char *fname, LEX_ERROR_HANDLER *scan_error);
205 int lex_get_char (LEX *lf);
206 void lex_unget_char (LEX *lf);
207 const char * lex_tok_to_str (int token);
208 int lex_get_token (LEX *lf, int expect);
209 void lex_set_default_error_handler (LEX *lf);
210 int lex_set_error_handler_error_type (LEX *lf, int err_type);
213 void my_name_is (int argc, char *argv[], const char *name);
214 void init_msg (JCR *jcr, MSGS *msg);
215 void term_msg (void);
216 void close_msg (JCR *jcr);
217 void add_msg_dest (MSGS *msg, int dest, int type, char *where, char *dest_code);
218 void rem_msg_dest (MSGS *msg, int dest, int type, char *where);
219 void Jmsg (JCR *jcr, int type, time_t mtime, const char *fmt, ...);
220 void dispatch_message (JCR *jcr, int type, time_t mtime, char *buf);
221 void init_console_msg (const char *wd);
222 void free_msgs_res (MSGS *msgs);
223 void dequeue_messages (JCR *jcr);
224 void set_trace (int trace_flag);
227 void bnet_thread_server(dlist *addr, int max_clients, workq_t *client_wq,
228 void *handle_client_request(void *bsock));
229 void bnet_stop_thread_server(pthread_t tid);
230 void bnet_server (int port, void handle_client_request(BSOCK *bsock));
231 int net_connect (int port);
232 BSOCK * bnet_bind (int port);
233 BSOCK * bnet_accept (BSOCK *bsock, char *who);
236 char *getuser(uid_t uid);
237 void free_getuser_cache();
238 char *getgroup (gid_t gid);
239 void free_getgroup_cache();
242 typedef int (EVENT_HANDLER)(JCR *jcr, const char *event);
243 void init_python_interpreter(const char *progname, const char *scripts,
245 void term_python_interpreter();
246 //extern EVENT_HANDLER *generate_daemon_event;
247 int generate_daemon_event(JCR *jcr, const char *event);
249 void unlock_python();
252 void init_signals (void terminate(int sig));
253 void init_stack_dump (void);
256 void strip_leading_space (char *str);
257 void strip_trailing_junk (char *str);
258 void strip_trailing_newline (char *str);
260 void strip_trailing_slashes (char *dir);
261 bool skip_spaces (char **msg);
262 bool skip_nonspaces (char **msg);
263 int fstrsch (const char *a, const char *b);
264 char *next_arg(char **s);
265 int parse_args(POOLMEM *cmd, POOLMEM **args, int *argc,
266 char **argk, char **argv, int max_args);
267 void split_path_and_filename(const char *fname, POOLMEM **path,
268 int *pnl, POOLMEM **file, int *fnl);
269 int bsscanf(const char *buf, const char *fmt, ...);
273 TLS_CONTEXT *new_tls_context (const char *ca_certfile,
274 const char *ca_certdir,
275 const char *certfile,
277 CRYPTO_PEM_PASSWD_CB *pem_callback,
278 const void *pem_userdata,
281 void free_tls_context (TLS_CONTEXT *ctx);
283 bool tls_postconnect_verify_host (TLS_CONNECTION *tls,
285 bool tls_postconnect_verify_cn (TLS_CONNECTION *tls,
287 TLS_CONNECTION *new_tls_connection (TLS_CONTEXT *ctx, int fd);
288 void free_tls_connection (TLS_CONNECTION *tls);
289 bool tls_bsock_connect (BSOCK *bsock);
290 bool tls_bsock_accept (BSOCK *bsock);
291 void tls_bsock_shutdown (BSOCK *bsock);
292 int tls_bsock_writen (BSOCK *bsock, char *ptr, int32_t nbytes);
293 int tls_bsock_readn (BSOCK *bsock, char *ptr, int32_t nbytes);
294 #endif /* HAVE_TLS */
298 int is_buf_zero (char *buf, int len);
299 void lcase (char *str);
300 void bash_spaces (char *str);
301 void bash_spaces (POOL_MEM &pm);
302 void unbash_spaces (char *str);
303 void unbash_spaces (POOL_MEM &pm);
304 char * encode_time (time_t time, char *buf);
305 char * encode_mode (mode_t mode, char *buf);
306 int do_shell_expansion (char *name, int name_len);
307 void jobstatus_to_ascii (int JobStatus, char *msg, int maxlen);
308 int run_program (char *prog, int wait, POOLMEM *results);
309 int run_program_full_output (char *prog, int wait, POOLMEM *results);
310 const char * job_type_to_str (int type);
311 const char * job_status_to_str (int stat);
312 const char * job_level_to_str (int level);
313 void make_session_key (char *key, char *seed, int mode);
314 POOLMEM * edit_job_codes (JCR *jcr, char *omsg, char *imsg, const char *to);
315 void set_working_directory (char *wd);
316 const char * last_path_separator (const char *str);
320 int start_watchdog(void);
321 int stop_watchdog(void);
322 watchdog_t *new_watchdog(void);
323 bool register_watchdog(watchdog_t *wd);
324 bool unregister_watchdog(watchdog_t *wd);
327 btimer_t *start_child_timer(pid_t pid, uint32_t wait);
328 void stop_child_timer(btimer_t *wid);
329 btimer_t *start_thread_timer(pthread_t tid, uint32_t wait);
330 void stop_thread_timer(btimer_t *wid);
331 btimer_t *start_bsock_timer(BSOCK *bs, uint32_t wait);
332 void stop_bsock_timer(btimer_t *wid);