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 and included
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.
37 ATTR *new_attr(JCR *jcr);
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 b_strerror(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,
90 BSOCK * bnet_connect (JCR *jcr, int retry_interval,
91 utime_t max_retry_time, utime_t heart_beat,
92 const char *name, char *host, char *service,
93 int port, int verbose);
94 void bnet_close (BSOCK *bsock);
95 BSOCK * init_bsock (JCR *jcr, int sockfd, const char *who, const char *ip,
96 int port, struct sockaddr *client_addr);
102 int bnet_get_peer (BSOCK *bs, char *buf, socklen_t buflen);
103 BSOCK * dup_bsock (BSOCK *bsock);
104 void term_bsock (BSOCK *bsock);
105 const char *bnet_strerror (BSOCK *bsock);
106 const char *bnet_sig_to_ascii (BSOCK *bsock);
107 int bnet_wait_data (BSOCK *bsock, int sec);
108 int bnet_wait_data_intr (BSOCK *bsock, int sec);
109 bool is_bnet_stop (BSOCK *bsock);
110 int is_bnet_error (BSOCK *bsock);
111 void bnet_suppress_error_messages(BSOCK *bsock, bool flag);
112 dlist *bnet_host2ipaddrs(const char *host, int family, const char **errstr);
113 int bnet_set_blocking (BSOCK *sock);
114 int bnet_set_nonblocking (BSOCK *sock);
115 void bnet_restore_blocking (BSOCK *sock, int flags);
118 int bget_msg(BSOCK *sock);
121 BPIPE * open_bpipe(char *prog, int wait, const char *mode);
122 int close_wpipe(BPIPE *bpipe);
123 int close_bpipe(BPIPE *bpipe);
126 bool cram_md5_respond(BSOCK *bs, const char *password, int *tls_remote_need, int *compatible);
127 bool cram_md5_challenge(BSOCK *bs, const char *password, int tls_local_need, int compatible);
128 void hmac_md5(uint8_t* text, int text_len, uint8_t* key, int key_len, uint8_t *hmac);
132 uint32_t bcrc32(uint8_t *buf, int len);
135 int init_crypto (void);
136 int cleanup_crypto (void);
137 DIGEST * crypto_digest_new (JCR *jcr, crypto_digest_t type);
138 bool crypto_digest_update (DIGEST *digest, const uint8_t *data, uint32_t length);
139 bool crypto_digest_finalize (DIGEST *digest, uint8_t *dest, uint32_t *length);
140 void crypto_digest_free (DIGEST *digest);
141 SIGNATURE * crypto_sign_new (JCR *jcr);
142 crypto_error_t crypto_sign_get_digest (SIGNATURE *sig, X509_KEYPAIR *keypair,
143 crypto_digest_t &algorithm, DIGEST **digest);
144 crypto_error_t crypto_sign_verify (SIGNATURE *sig, X509_KEYPAIR *keypair, DIGEST *digest);
145 int crypto_sign_add_signer (SIGNATURE *sig, DIGEST *digest, X509_KEYPAIR *keypair);
146 int crypto_sign_encode (SIGNATURE *sig, uint8_t *dest, uint32_t *length);
147 SIGNATURE * crypto_sign_decode (JCR *jcr, const uint8_t *sigData, uint32_t length);
148 void crypto_sign_free (SIGNATURE *sig);
149 CRYPTO_SESSION * crypto_session_new (crypto_cipher_t cipher, alist *pubkeys);
150 void crypto_session_free (CRYPTO_SESSION *cs);
151 bool crypto_session_encode (CRYPTO_SESSION *cs, uint8_t *dest, uint32_t *length);
152 crypto_error_t crypto_session_decode (const uint8_t *data, uint32_t length, alist *keypairs, CRYPTO_SESSION **session);
153 CRYPTO_SESSION * crypto_session_decode (const uint8_t *data, uint32_t length);
154 CIPHER_CONTEXT * crypto_cipher_new (CRYPTO_SESSION *cs, bool encrypt, uint32_t *blocksize);
155 bool crypto_cipher_update (CIPHER_CONTEXT *cipher_ctx, const uint8_t *data, uint32_t length, const uint8_t *dest, uint32_t *written);
156 bool crypto_cipher_finalize (CIPHER_CONTEXT *cipher_ctx, uint8_t *dest, uint32_t *written);
157 void crypto_cipher_free (CIPHER_CONTEXT *cipher_ctx);
158 X509_KEYPAIR * crypto_keypair_new (void);
159 X509_KEYPAIR * crypto_keypair_dup (X509_KEYPAIR *keypair);
160 int crypto_keypair_load_cert (X509_KEYPAIR *keypair, const char *file);
161 bool crypto_keypair_has_key (const char *file);
162 int crypto_keypair_load_key (X509_KEYPAIR *keypair, const char *file, CRYPTO_PEM_PASSWD_CB *pem_callback, const void *pem_userdata);
163 void crypto_keypair_free (X509_KEYPAIR *keypair);
164 int crypto_default_pem_callback (char *buf, int size, const void *userdata);
165 const char * crypto_digest_name (DIGEST *digest);
166 crypto_digest_t crypto_digest_stream_type (int stream);
167 const char * crypto_strerror (crypto_error_t error);
170 void daemon_start ();
173 uint64_t str_to_uint64(char *str);
174 int64_t str_to_int64(char *str);
175 #define str_to_int32(str) ((int32_t)str_to_int64(str))
176 char * edit_uint64_with_commas (uint64_t val, char *buf);
177 char * edit_uint64_with_suffix (uint64_t val, char *buf);
178 char * add_commas (char *val, char *buf);
179 char * edit_uint64 (uint64_t val, char *buf);
180 char * edit_int64 (int64_t val, char *buf);
181 bool duration_to_utime (char *str, utime_t *value);
182 bool size_to_uint64(char *str, int str_len, uint64_t *rtn_value);
183 char *edit_utime (utime_t val, char *buf, int buf_len);
184 bool is_a_number (const char *num);
185 bool is_an_integer (const char *n);
186 bool is_name_valid (char *name, POOLMEM **msg);
188 /* jcr.c (most definitions are in src/jcr.h) */
189 void init_last_jobs_list();
190 void term_last_jobs_list();
191 void lock_last_jobs_list();
192 void unlock_last_jobs_list();
193 bool read_last_jobs_list(int fd, uint64_t addr);
194 uint64_t write_last_jobs_list(int fd, uint64_t addr);
195 void write_state_file(char *dir, const char *progname, int port);
196 void job_end_push(JCR *jcr, void job_end_cb(JCR *jcr,void *), void *ctx);
199 JCR *jcr_walk_start();
200 JCR *jcr_walk_next(JCR *prev_jcr);
201 void jcr_walk_end(JCR *jcr);
202 uint32_t get_jobid_from_tid(pthread_t tid);
203 uint32_t get_jobid_from_tid();
204 JCR *get_jcr_from_tid(pthread_t tid);
205 JCR *get_jcr_from_tid();
209 LEX * lex_close_file (LEX *lf);
210 LEX * lex_open_file (LEX *lf, const char *fname, LEX_ERROR_HANDLER *scan_error);
211 int lex_get_char (LEX *lf);
212 void lex_unget_char (LEX *lf);
213 const char * lex_tok_to_str (int token);
214 int lex_get_token (LEX *lf, int expect);
215 void lex_set_default_error_handler (LEX *lf);
216 int lex_set_error_handler_error_type (LEX *lf, int err_type);
219 void my_name_is (int argc, char *argv[], const char *name);
220 void init_msg (JCR *jcr, MSGS *msg);
221 void term_msg (void);
222 void close_msg (JCR *jcr);
223 void add_msg_dest (MSGS *msg, int dest, int type, char *where, char *dest_code);
224 void rem_msg_dest (MSGS *msg, int dest, int type, char *where);
225 void Jmsg (JCR *jcr, int type, time_t mtime, const char *fmt, ...);
226 void dispatch_message (JCR *jcr, int type, time_t mtime, char *buf);
227 void init_console_msg (const char *wd);
228 void free_msgs_res (MSGS *msgs);
229 void dequeue_messages (JCR *jcr);
230 void set_trace (int trace_flag);
231 void set_db_type (const char *name);
232 void register_message_callback(void msg_callback(int type, char *msg));
235 void bnet_thread_server(dlist *addr, int max_clients, workq_t *client_wq,
236 void *handle_client_request(void *bsock));
237 void bnet_stop_thread_server(pthread_t tid);
238 void bnet_server (int port, void handle_client_request(BSOCK *bsock));
239 int net_connect (int port);
240 BSOCK * bnet_bind (int port);
241 BSOCK * bnet_accept (BSOCK *bsock, char *who);
244 typedef int (EVENT_HANDLER)(JCR *jcr, const char *event);
245 void init_python_interpreter(const char *progname, const char *scripts,
247 void term_python_interpreter();
248 //extern EVENT_HANDLER *generate_daemon_event;
249 int generate_daemon_event(JCR *jcr, const char *event);
251 void unlock_python();
254 void init_signals (void terminate(int sig));
255 void init_stack_dump (void);
258 void strip_leading_space (char *str);
259 void strip_trailing_junk (char *str);
260 void strip_trailing_newline (char *str);
262 void strip_trailing_slashes (char *dir);
263 bool skip_spaces (char **msg);
264 bool skip_nonspaces (char **msg);
265 int fstrsch (const char *a, const char *b);
266 char *next_arg(char **s);
267 int parse_args(POOLMEM *cmd, POOLMEM **args, int *argc,
268 char **argk, char **argv, int max_args);
269 int parse_args_only(POOLMEM *cmd, POOLMEM **args, int *argc,
270 char **argk, char **argv, int max_args);
271 void split_path_and_filename(const char *fname, POOLMEM **path,
272 int *pnl, POOLMEM **file, int *fnl);
273 int bsscanf(const char *buf, const char *fmt, ...);
277 TLS_CONTEXT *new_tls_context (const char *ca_certfile,
278 const char *ca_certdir,
279 const char *certfile,
281 CRYPTO_PEM_PASSWD_CB *pem_callback,
282 const void *pem_userdata,
285 void free_tls_context (TLS_CONTEXT *ctx);
287 bool tls_postconnect_verify_host (TLS_CONNECTION *tls,
289 bool tls_postconnect_verify_cn (TLS_CONNECTION *tls,
291 TLS_CONNECTION *new_tls_connection (TLS_CONTEXT *ctx, int fd);
292 bool tls_bsock_accept (BSOCK *bsock);
293 int tls_bsock_writen (BSOCK *bsock, char *ptr, int32_t nbytes);
294 int tls_bsock_readn (BSOCK *bsock, char *ptr, int32_t nbytes);
295 #endif /* HAVE_TLS */
296 bool tls_bsock_connect (BSOCK *bsock);
297 void tls_bsock_shutdown (BSOCK *bsock);
298 void free_tls_connection (TLS_CONNECTION *tls);
299 bool get_tls_require (TLS_CONTEXT *ctx);
300 bool get_tls_enable (TLS_CONTEXT *ctx);
305 typedef char *(*job_code_callback_t)(JCR *, const char *);
307 bool is_buf_zero (char *buf, int len);
308 void lcase (char *str);
309 void bash_spaces (char *str);
310 void bash_spaces (POOL_MEM &pm);
311 void unbash_spaces (char *str);
312 void unbash_spaces (POOL_MEM &pm);
313 char * encode_time (time_t time, char *buf);
314 char * encode_mode (mode_t mode, char *buf);
315 int do_shell_expansion (char *name, int name_len);
316 void jobstatus_to_ascii (int JobStatus, char *msg, int maxlen);
317 int run_program (char *prog, int wait, POOLMEM *results);
318 int run_program_full_output (char *prog, int wait, POOLMEM *results);
319 const char * job_type_to_str (int type);
320 const char * job_status_to_str (int stat);
321 const char * job_level_to_str (int level);
322 void make_session_key (char *key, char *seed, int mode);
323 POOLMEM * edit_job_codes (JCR *jcr, char *omsg, char *imsg, const char *to, job_code_callback_t job_code_callback = NULL);
324 void set_working_directory (char *wd);
325 const char * last_path_separator (const char *str);
329 int start_watchdog(void);
330 int stop_watchdog(void);
331 watchdog_t *new_watchdog(void);
332 bool register_watchdog(watchdog_t *wd);
333 bool unregister_watchdog(watchdog_t *wd);
336 btimer_t *start_child_timer(pid_t pid, uint32_t wait);
337 void stop_child_timer(btimer_t *wid);
338 btimer_t *start_thread_timer(pthread_t tid, uint32_t wait);
339 void stop_thread_timer(btimer_t *wid);
340 btimer_t *start_bsock_timer(BSOCK *bs, uint32_t wait);
341 void stop_bsock_timer(btimer_t *wid);