CYPHERTITE(3)

NAME
cyphertite - cyphertite library

SYNOPSIS

  CRYPTO
#include <ct_crypto.h>
int
ct_create_secrets(const char *passphrase, const char *filename, uint8_t *myaeskey, uint8_t *myivkey);
int
ct_unlock_secrets(const char *passphrase, const char *filename, uint8_t *outaeskey, size_t outaeskeylen, uint8_t *outivkey, size_t outivkeylen);
ct_crypto.h functions used internally only:
int
ct_crypto_crypt(const EVP_CIPHER *type, uint8_t *key, size_t keylen, uint8_t *iv, size_t ivlen, uint8_t *src, size_t srclen, uint8_t *dst, size_t dstlen, int enc);
int
ct_encrypt(uint8_t *key, size_t keylen, uint8_t *iv, size_t ivlen, uint8_t *src, size_t srclen, uint8_t *dst, size_t dstlen);
int
ct_decrypt(uint8_t *key, size_t keylen, uint8_t *iv, size_t ivlen, uint8_t *src, size_t srclen, uint8_t *dst, size_t dstlen);
int
ct_create_iv(uint8_t *key, size_t keylen, uint8_t *src, size_t srclen, uint8_t *iv, size_t ivlen);
int
ct_create_iv_ctfile(uint32_t chunkno, uint8_t *iv, size_t ivlen);
int
ct_crypto_blocksz(void);

  CTFILE
#include <ct_ctfile.h>
int
ctfile_parse(struct ctfile_parse_state *ctx);
int
ctfile_parse_seek(struct ctfile_parse_state *ctx);
void
ctfile_parse_close(struct ctfile_parse_state *ctx);
off_t
ctfile_parse_tell(struct ctfile_parse_state *ctx);
struct dnode *
ctfile_parse_finddir(struct ctfile_parse_state *ctx, int num);
struct dnode *
ctfile_parse_insertdir(struct ctfile_parse_state *ctx, struct dnode *dnode);
struct ctfile_write_state *
ctfile_write_init(const char *ctfile, const char *ctfile_basedir, int type, const char *basis, int lvl, char *cmd, char **filelist, int encrypted, int max_block_size);
ct_ctfile.h functions used internally only:
int
ctfile_parse_init_at(struct ctfile_parse_state *ctx, const char *file, const char *ctfile_basedir, off_t offset);
int
ctfile_parse_init_f(struct ctfile_parse_state *ctx, FILE *f, const char *ctfile_basedir);
int
ctfile_write_special(struct ctfile_write_state *ctx, struct fnode *fnode);
int
ctfile_write_file_start(struct ctfile_write_state *ctx, struct fnode *fnode);
int
ctfile_write_file_sha(struct ctfile_write_state *ctx, uint8_t *sha, uint8_t *csha, uint8_t *iv);
int
ctfile_write_file_pad(struct ctfile_write_state *ctx, struct fnode *fn);
int
ctfile_write_file_end(struct ctfile_write_state *ctx, struct fnode *fnode);
int
ctfile_write_close(struct ctfile_write_state *ctx);
char *
ctfile_get_previous(const char *path);

  DB
#include <ct_db.h>
void
ctdb_shutdown(struct ctdb_state *state);
ct_db.h functions used internally only:
struct ctdb_state *
ctdb_setup(const char *path, int crypt_enabled);
int
ctdb_insert_sha(struct ctdb_state *state, uint8_t *sha_k, uint8_t *sha_v, uint8_t *iv);
int
ctdb_lookup_sha(struct ctdb_state *state, uint8_t *sha_k, uint8_t *sha_v, uint8_t *iv);
int
ctdb_get_genid(struct ctdb_state *state);
void
ctdb_reopendb(struct ctdb_state *state, int genid);

  INTERNAL
#include <ct_internal.h>
int
ct_basis_setup(const char *basisbackup, char **filelist, int max_incrementals, time_t *prev_backup);
ct_internal.h functions used internally only:
void
ct_handle_xml_reply(struct ct_global_state *state, struct ct_trans *trans, struct ct_header *hdr, void *vbody);
void
ct_xml_file_open(struct ct_global_state *state, struct ct_trans *trans, const char *file, int mode, uint32_t chunkno);
int
ct_xml_file_open_polled( struct ct_global_state *state, const char *file, int mode, uint32_t chunkno);
void
ct_xml_file_close(struct ct_global_state *state);
void
ct_complete_metadata(struct ct_global_state *state, struct ct_trans *trans);

  LIB
#include <cyphertite.h>
struct ct_config *
ct_load_config(char **configfile);
void
ct_unload_config(char *configfile, struct ct_config *config);
char *
ct_system_config(void);
char *
ct_user_config(void);
char *
ct_user_config_old(void);
void
ct_write_config(struct ct_config *config, FILE *f, int save_password, int save_crypto_passphrase);
void
ct_default_config(struct ct_config *config);
void
ct_download_decode_and_save_certs(struct ct_config *config);
struct ct_global_state *
ct_setup_state(struct ct_config *config);
void
ct_set_file_state(struct ct_global_state *state, int newstate);
void
ct_queue_transfer(struct ct_global_state *state, struct ct_trans *trans);
struct ct_assl_io_ctx *
ct_ssl_connect(struct ct_global_state *state, int nonfatal);
void
ct_ssl_cleanup(struct ct_assl_io_ctx *ctx, struct bw_limit_ctx *blc);
int
ct_assl_negotiate_poll(struct ct_global_state *state);
struct ct_global_state *
ct_init(struct ct_config *conf, int need_secrets, void (*info_cb)(evutil_socket_t, short, void *));
void
ct_init_eventloop(struct ct_global_state *state, void (*info_cb)(evutil_socket_t, short, void *));
void
ct_cleanup(struct ct_global_state *state);
void
ct_cleanup_eventloop(struct ct_global_state *state);
struct ct_event_state *
ct_event_init(struct ct_global_state *state, void (*cb)(evutil_socket_t, short, void *), void (*info_cb)(evutil_socket_t, short, void *));
int
ct_event_dispatch(struct ct_event_state *ev_ct);
int
ct_event_loopbreak(struct ct_event_state *ev_ct);
void
ct_event_cleanup(struct ct_event_state *ev_ct);
void
ct_wakeup_file(struct ct_event_state *ev_ct);
void
ct_wakeup_sha(struct ct_event_state *ev_ct);
void
ct_wakeup_compress(struct ct_event_state *ev_ct);
void
ct_wakeup_csha(struct ct_event_state *ev_ct);
void
ct_wakeup_encrypt(struct ct_event_state *ev_ct);
void
ct_wakeup_write(struct ct_event_state *ev_ct);
void
ct_wakeup_complete(struct ct_event_state *ev_ct);
void
ct_setup_wakeup_file(struct ct_event_state *ev_ct, void *vctx, ct_func_cb *func_cb);
void
ct_setup_wakeup_sha(struct ct_event_state *ev_ct, void *vctx, ct_func_cb *func_cb);
void
ct_setup_wakeup_compress(struct ct_event_state *ev_ct, void *vctx, ct_func_cb *func_cb);
void
ct_setup_wakeup_csha(struct ct_event_state *ev_ct, void *vctx, ct_func_cb *func_cb);
void
ct_setup_wakeup_encrypt(struct ct_event_state *ev_ct, void *vctx, ct_func_cb *func_cb);
void
ct_setup_wakeup_write(struct ct_event_state *ev_ct, void *vctx, ct_func_cb *func_cb);
void
ct_setup_wakeup_complete(struct ct_event_state *ev_ct, void *vctx, ct_func_cb *func_cb);
void
ct_set_reconnect_timeout(struct ct_event_state *ev_ct, int delay);
struct ct_trans *
ct_trans_alloc(struct ct_global_state *state);
struct ct_trans *
ct_trans_realloc_local(struct ct_global_state *state, struct ct_trans *trans);
void
ct_trans_free(struct ct_global_state *state, struct ct_trans *trans);
char *
ct_dirname(const char *orig_path);
char *
ct_basename(const char *orig_path);
int
ct_absolute_path(const char *path);
int
ctfile_verify_name(char *ctfile);
void
ctfile_trim_cache(const char *cachedir, long long max_size);
void
ct_prompt_for_login_password(struct ct_config *conf);
void
ct_normalize_username(char *username);
char *
ct_normalize_path(char *path);
void
ct_normalize_filelist(char **filelist);
struct ct_op *
ct_add_operation(struct ct_global_state *state, ct_op_cb *start, ct_op_cb *complete, void *args);
struct ct_op *
ct_add_operation_after(struct ct_global_state *state, struct ct_op *after, ct_op_cb *start, ct_op_cb *complete, void *args);
int
ct_do_operation(struct ct_config *conf, ct_op_cb *start, ct_op_cb *complete, void *args, int need_secrets);
void
ctfile_list_complete(struct ctfile_list *files, int matchmode, char **flist, char **excludelist, struct ctfile_list_tree *results);
int
ct_file_on_server(struct ct_global_state *state, char *filename);
void
ct_cull_kick(struct ct_global_state *state);
int
ct_have_remote_secrets_file(struct ct_config *conf);
void
ctfile_find_for_operation(struct ct_global_state *state, char *tag, ctfile_find_callback *nextop, void *nextop_args, int download_chain, int empty_ok);
void
ct_extract_setup(struct ct_extract_head *extract_head, struct ctfile_parse_state *ctx, const char *file, const char *ctfile_basedir, int *is_allfiles);
void
ct_extract_open_next(struct ct_extract_head *extract_head, struct ctfile_parse_state *ctx);
int
ct_file_extract_open(struct ct_extract_state *ces, struct fnode *fnode);
void
ct_file_extract_write(struct ct_extract_state *ces, struct fnode *, uint8_t *buf, size_t size);
void
ct_file_extract_close(struct ct_extract_state *ces, struct fnode *fnode);
void
ct_file_extract_special(struct ct_extract_state *ces, struct fnode *fnode);
int
ct_get_answer(char *prompt, char *a1, char *a2, char *default_val, char *answer, size_t answer_len, int secret);
int
ct_prompt_password(char *prompt, char *answer, size_t answer_len, char *answer2, size_t answer2_len, int confirm);
char *
ct_getloginbyuid(uid_t uid);
cyphertite.h functions used internally only:
int
ct_get_file_state(struct ct_global_state *state);
void
ct_queue_first(struct ct_global_state *state, struct ct_trans *trans);
struct bw_limit_ctx *
ct_ssl_init_bw_lim(struct event_base *base, struct ct_assl_io_ctx *ctx, int io_bw_limit);
void
ct_ssl_cleanup_bw_lim(struct bw_limit_ctx *blc);
void
ct_reconnect(evutil_socket_t, short event, void *varg);
int
ct_reconnect_internal(struct ct_global_state *state);
void
ct_compute_sha(void *vctx);
void
ct_compute_compress(void *vctx);
void
ct_compute_encrypt(void *vctx);
void
ct_compute_csha(void *vctx);
void
ct_process_completions(void *vctx);
void
ct_process_write(void *vctx);
struct event_base *
ct_event_get_base(struct ct_event_state *ev_ct);
void
ct_event_shutdown "struct ct_event_state *ev_st"
void
ct_wakeup_decrypt(struct ct_event_state *ev_ct);
void
ct_wakeup_uncompress(struct ct_event_state *ev_ct);
void
ct_wakeup_filewrite(struct ct_event_state *ev_ct);
void
ct_shutdown(struct ct_global_state *state);
void
ct_trans_cleanup(struct ct_global_state *state);
char *
ctfile_cook_name(const char *path);
int
ctfile_in_cache(const char *ctfile, const char *cachedir);
char *
ctfile_get_cachename(const char *ctfile, const char *cachedir);
void
ct_nextop(void *vctx);
int
ct_op_complete(struct ct_global_state *state);
int
ct_cull_add_shafile(const char *file, const char *cachedir);
void
ct_cull_sha_insert(const uint8_t *sha);
void
ct_extract_cleanup_queue(struct ct_extract_head *extract_head);
struct ct_extract_state *
ct_file_extract_init(const char *tdir, int attr, int follow_symlinks, int allfiles, void *log_state, ct_log_chown_failed_fn *log_chown_failed);
struct dnode *
ct_file_extract_get_rootdir(struct ct_extract_state *ces);
struct dnode *
ct_file_extract_insert_dir(struct ct_extract_state *ces, struct dnode *dnode);
struct dnode *
ct_file_extract_lookup_dir(struct ct_extract_state *ces, const char *path);
void
ct_file_extract_cleanup(struct ct_extract_state *ces);
struct ct_archive_state *
ct_archive_init(const char *tdir);
struct dnode *
ct_archive_get_rootdir(struct ct_archive_state *cas);
struct dnode *
ct_archive_lookup_dir(struct ct_archive_state *cas, const char *name);
struct dnode *
ct_archive_insert_dir(struct ct_archive_state *cas, struct dnode *);
void
ct_archive_cleanup(struct ct_archive_state *cas);

  MATCH
#include <ct_match.h>
struct ct_match *
ct_match_compile(int mode, char **flist);
struct ct_match *
ct_match_fromfile(const char *file, int matchmode);
char **
ct_matchlist_fromfile(const char *file, int *nentries);
void
ct_matchlist_free(char **flist);
int
ct_match(struct ct_match *match, char *candidate);
void
ct_match_unwind(struct ct_match *match);
ct_match.h functions used internally only:
void
ct_match_insert_rb(struct ct_match *match, char *string);
int
ct_match_rb_is_empty(struct ct_match *match);

  PROTO
#include <ct_proto.h>
void *
ct_body_alloc_xml(size_t sz);
ct_proto.h functions used internally only:
int
ct_create_neg(struct ct_header *hdr, void **vbody, int max_trans, int max_block_size);
int
ct_parse_neg_reply(struct ct_header *hdr, void *body, int *max_trans, int *max_block_size);
int
ct_create_login(struct ct_header *hdr, void **vbody, const char *username, const char *passphrase);
int
ct_parse_login_reply(struct ct_header *hdr, void *body);
int
ct_create_xml_negotiate(struct ct_header *hdr, void **vbody, int32_t dbgenid);
int
ct_parse_xml_negotiate_reply(struct ct_header *hdr, void *body, struct ctdb_state *ctdb);
int
ct_create_exists(struct ct_header *hdr, void **vbody, uint8_t *sha, size_t shasz);
int
ct_parse_exists_reply(struct ct_header *hdr, void *body, int *exists);
int
ct_create_write(struct ct_header *hdr, void **vbody, uint8_t *data, size_t datasize);
int
ct_create_ctfile_write(struct ct_header *hdr, void **vbody, int *nbody, uint8_t *data, size_t datasize, uint32_t chunkno);
int
ct_parse_write_reply(struct ct_header *hdr, void *vbody);
int
ct_create_read(struct ct_header *hdr, void **vbody, uint8_t *sha, size_t shasz);
int
ct_parse_read_reply(struct ct_header *hdr, void *vbody);
int
ct_parse_read_ctfile_chunk_info(struct ct_header *hdr, void *vbody, uint32_t expected_chunkno);
int
ct_create_xml_open(struct ct_header *hdr, void **vbody, const char *file, int mode, uint32_t chunkno);
int
ct_parse_xml_open_reply(struct ct_header *hdr, void *vbody, char **filename);
int
ct_create_xml_close(struct ct_header *hdr, void **vbody);
int
ct_parse_xml_close_reply(struct ct_header *hdr, void *vbody);
int
ct_create_xml_list(struct ct_header *hdr, void **vbody);
int
ct_parse_xml_list_reply(struct ct_header *hdr, void *vbody, struct ctfile_list *head);
int
ct_create_xml_delete(struct ct_header *hdr, void **vbody, const char *name);
int
ct_parse_xml_delete_reply(struct ct_header *hdr, void *vbody, char **filename);
int
ct_create_xml_cull_setup(struct ct_header *hdr, void **vbody, uint64_t cull_uuid, int mode);
int
ct_parse_xml_cull_setup_reply(struct ct_header *hdr, void *vbody);
int
ct_create_xml_cull_shas(struct ct_header *hdr, void **vbody, uint64_t cull_uuid, struct ct_sha_lookup *head, int sha_per_packet, int *no_shas);
int
ct_parse_xml_cull_shas_reply(struct ct_header *hdr, void *vbody);
int
ct_create_xml_cull_complete(struct ct_header *hdr, void **vbody, uint64_t cull_uuid, int mode);
int
ct_parse_xml_cull_complete_reply(struct ct_header *hdr, void *vbody);
void
ct_cleanup_packet(struct ct_header *hdr, void *vbody);

DESCRIPTION

  CRYPTO
#include ct_crypto.h int ct_create_secrets(const char *passphrase, const char *filename, uint8_t *myaeskey, uint8_t *myivkey)
int ct_unlock_secrets(const char *passphrase, const char *filename, uint8_t *outaeskey, size_t outaeskeylen, uint8_t *outivkey, size_t outivkeylen)

  CTFILE
#include ct_types.h

    /* XDR for metadata global header */
    struct ctfile_gheader {
    	int			cmg_beacon;	/* magic marker */
    #define CT_MD_BEACON		(0x43595048)
    	int			cmg_version;	/* version of the archive */
    #define CT_MD_V1		(1)
    #define CT_MD_V2		(2)
    #define CT_MD_V3		(3)
    #define CT_MD_VERSION		CT_MD_V3
    	int			cmg_chunk_size;	/* chunk size */
    	int64_t			cmg_created;	/* date created */
    	int			cmg_type;	/* normal, stdin or crypto */
    #define CT_MD_REGULAR		(0)
    #define CT_MD_STDIN		(1)
    	int			cmg_flags;	/* save digest and iv */
    #define CT_MD_NOCRYPTO		(0)
    #define CT_MD_CRYPTO		(1)
    #define CT_MD_MLB_ALLFILES	(2)
    	char			*cmg_prevlvl_filename;
    	int			cmg_cur_lvl;
    	char			*cmg_cwd;
    	int			cmg_num_paths;
    	char			**cmg_paths;
    };

    /* XDR for metadata header */
    struct ctfile_header {
    	int			cmh_beacon;	/* magic marker */
    #define CT_HDR_BEACON		(0x4d4f306f)
    #define CT_HDR_EOF		(0x454f4621)
    	int64_t			cmh_nr_shas;	/* total shas */
    	int64_t			cmh_parent_dir;	/* path file num */
    	uint32_t		cmh_uid;	/* user id */
    	uint32_t		cmh_gid;	/* group id */
    	uint32_t		cmh_mode;	/* file mode */
    	int32_t			cmh_rdev;	/* major and minor */
    	int64_t			cmh_atime;	/* last access time */
    	int64_t			cmh_mtime;	/* last modification time */
    	u_char			cmh_type;
    #define C_TY_INVALID		(0)
    #define C_TY_DIR		(1)
    #define C_TY_CHR		(2)
    #define C_TY_BLK		(3)
    #define C_TY_REG		(4)
    #define C_TY_FIFO		(5)
    #define C_TY_LINK		(6)
    #define C_TY_SOCK		(7)
    #define C_TY_MASK		(0xf)		/* extra bit for future */
    	char			*cmh_filename;	/* original filename */
    };

    /* XDR for metadata trailer */
    struct ctfile_trailer {
    	uint64_t		cmt_orig_size;	/* original size */
    	uint64_t		cmt_comp_size;	/* deduped + comp size */
    	uint8_t			cmt_sha[SHA_DIGEST_LENGTH];
    };

#include <rpc/types.h>
#include <rpc/xdr.h>

    /* parser for cyphertite ctfile archives */
    RB_HEAD(d_num_tree, dnode);
    struct ctfile_parse_state {
    	FILE			*xs_f;
    	const char		*xs_filename;
    	XDR			 xs_xdr;
    	struct ctfile_gheader	 xs_gh;
    	struct ctfile_header	 xs_hdr;
    	struct ctfile_header	 xs_lnkhdr;
    	struct ctfile_trailer	 xs_trl;
    	struct d_num_tree	 xs_dnum_head;
    	int			 xs_dnum;
    	int			 xs_state;
    	int			 xs_wasfile;
    	int			 xs_sha_cnt;
    	size_t			 xs_sha_sz;
    	uint8_t			 xs_sha[SHA_DIGEST_LENGTH];
    	uint8_t			 xs_csha[SHA_DIGEST_LENGTH];
    	uint8_t			 xs_iv[CT_IV_LEN];
    #define	XS_STATE_FILE		0
    #define	XS_STATE_SHA		1
    #define	XS_STATE_EOF		2
    #define	XS_STATE_FAIL		3
    #define	XS_RET_FILE		0
    #define	XS_RET_SHA		1
    #define	XS_RET_FILE_END		2
    #define	XS_RET_EOF		3
    #define	XS_RET_FAIL		4
    };

int ctfile_parse(struct ctfile_parse_state *ctx)
int ctfile_parse_seek(struct ctfile_parse_state *ctx)
void ctfile_parse_close(struct ctfile_parse_state *ctx)
off_t ctfile_parse_tell(struct ctfile_parse_state *ctx)
struct dnode * ctfile_parse_finddir(struct ctfile_parse_state *ctx, int num)
struct dnode * ctfile_parse_insertdir(struct ctfile_parse_state *ctx, struct dnode *dnode)
struct ctfile_write_state * ctfile_write_init(const char *ctfile, const char *ctfile_basedir, int type, const char *basis, int lvl, char *cmd, char **filelist, int encrypted, int max_block_size)

  DB

    /* localdb interface */

void ctdb_shutdown(struct ctdb_state *state)

  INTERNAL
#include <ct_socket.h> int ct_basis_setup(const char *basisbackup, char **filelist, int max_incrementals, time_t *prev_backup)

  LIB
#include <ct_types.h>
#include <ct_socket.h>

    struct ct_config {
    	char	*ct_host;
    	char	*ct_hostport;
    	char	*ct_username;
    	char	*ct_password;
    	char	*ct_localdb;
    	char	*ct_ca_cert;
    	char	*ct_cert;
    	char	*ct_key;
    	char	*ct_crypto_secrets;
    	char	*ct_crypto_passphrase;
    	char	*ct_polltype;
    	char	*ct_ctfile_cachedir;
    	int	ct_max_trans;
    	int	ct_compress;
    	int	ct_auto_incremental;
    	int	ct_max_incrementals;
    	int	ct_ctfile_keep_days;
    #define CT_MDMODE_LOCAL		(0)
    #define CT_MDMODE_REMOTE	(1)
    	int	ct_ctfile_mode;
    	long long	ct_ctfile_max_cachesize;
    	int	ct_secrets_upload;
    	int	ct_io_bw_limit;
    };

struct ct_config * ct_load_config(char **configfile)
void ct_unload_config(char *configfile, struct ct_config *config)
char * ct_system_config(void)
char * ct_user_config(void)
char * ct_user_config_old(void)
void ct_write_config(struct ct_config *config, FILE *f, int save_password, int save_crypto_passphrase)
void ct_default_config(struct ct_config *config)
void ct_download_decode_and_save_certs(struct ct_config *config)

    /* Statistics */
    struct ct_statistics {
    	struct timeval		st_time_start;
    	struct timeval		st_time_scan_end;
    	uint64_t		st_files_scanned;
    	uint64_t		st_bytes_tot;
    	uint64_t		st_chunks_tot;
    	uint64_t		st_bytes_read;
    	uint64_t		st_bytes_written;
    	uint64_t		st_bytes_compressed;
    	uint64_t		st_bytes_uncompressed;
    	uint64_t		st_bytes_crypted;
    	uint64_t		st_bytes_exists;
    	uint64_t		st_bytes_sent;
    	uint64_t		st_chunks_completed;
    	uint64_t		st_bytes_sha;
    	uint64_t		st_bytes_crypt;
    	uint64_t		st_bytes_csha;
    	uint64_t		st_files_completed;
    } ;

    RB_HEAD(ct_iotrans_lookup, ct_trans);
    RB_PROTOTYPE(ct_iotrans_lookup, ct_trans, tr_trans_id, ct_cmp_iotrans);
    RB_HEAD(ct_trans_lookup, ct_trans);
    RB_PROTOTYPE(ct_trans_lookup, ct_trans, tr_trans_id, ct_cmp_trans);
    struct ct_global_state {
    	struct ct_assl_io_ctx		*ct_assl_ctx; /* Connection state */
    	struct ct_config		*ct_config;
    	struct ct_extract_state		*extract_state;
    	struct ct_archive_state		*archive_state;
    	struct ct_statistics		*ct_stats;
    	TAILQ_HEAD(,ct_trans)		ct_trans_free_head;
    	int				ct_trans_id; /* next transaction id */
    	uint64_t			ct_packet_id; /* next complete id */
    	int				ct_tr_tag; /* next packet tag */
    	int				ct_max_block_size; /* negotiated */
    	int				ct_alloc_block_size; /* trans data sz */
    	int				ct_max_trans;
    	int				ct_trans_alloc;
    	int				ct_trans_free;
    	int				ct_num_local_transactions;
    	int				ct_sha_state;
    	int				ct_csha_state;
    	int				ct_file_state;
    	int				ct_comp_state;
    	int				ct_crypt_state;
    	TAILQ_HEAD(, ct_trans)		ct_sha_queue;
    	int				ct_sha_qlen;
    	CT_LOCK_STORE(ct_sha_lock);
    	TAILQ_HEAD(, ct_trans)		ct_comp_queue;
    	int				ct_comp_qlen;
    	CT_LOCK_STORE(ct_comp_lock);
    	TAILQ_HEAD(, ct_trans)		ct_crypt_queue;
    	int				ct_crypt_qlen;
    	CT_LOCK_STORE(ct_crypt_lock);
    	TAILQ_HEAD(, ct_trans)		ct_csha_queue;
    	int				ct_csha_qlen;
    	CT_LOCK_STORE(ct_csha_lock);
    	TAILQ_HEAD(, ct_trans)		ct_write_queue;
    	int				ct_write_qlen;
    	CT_LOCK_STORE(ct_write_lock);
    	TAILQ_HEAD(, ct_trans)		ct_queued;
    	int				ct_queued_qlen;
    	CT_LOCK_STORE(ct_queued_lock);
    	struct ct_iotrans_lookup	ct_inflight;
    	int				ct_inflight_rblen;
    	struct ct_trans_lookup		ct_complete;
    	int				ct_complete_rblen;
    	CT_LOCK_STORE(ct_complete_lock);
    	TAILQ_HEAD(ct_ops, ct_op)	ct_operations;
    	struct ctdb_state		*ct_db_state;
    	/* Reconnect state */
    	int				ct_disconnected;
    	int				ct_reconnect_pending;
    #define CT_RECONNECT_DEFAULT_TIMEOUT	30
    	int				ct_reconnect_timeout;
    	/* ctfile list state */
    	struct ctfile_list		ctfile_list_files;
    	/* Crypto state */
    	unsigned char			ct_iv[CT_IV_LEN];
    	unsigned char			ct_crypto_key[CT_KEY_LEN];
    	int				ct_verbose;
    	struct ct_compress_ctx		*ct_compress_state;
    	struct ct_event_state		*event_state;
    	struct bw_limit_ctx		*bw_limit;
    };

struct ct_global_state * ct_setup_state(struct ct_config *config)

    /* File status */
    #define CT_S_STARTING		(0)
    #define CT_S_RUNNING		(1)
    #define CT_S_WAITING_SERVER	(2)
    #define CT_S_WAITING_TRANS	(3)
    #define CT_S_FINISHED		(4)

void ct_set_file_state(struct ct_global_state *state, int newstate)
void ct_queue_transfer(struct ct_global_state *state, struct ct_trans *trans) struct ct_assl_io_ctx * ct_ssl_connect(struct ct_global_state *state, int nonfatal)
void ct_ssl_cleanup(struct ct_assl_io_ctx *ctx, struct bw_limit_ctx *blc) int ct_assl_negotiate_poll(struct ct_global_state *state) struct ct_global_state * ct_init(struct ct_config *conf, int need_secrets, int verbose, void (*info_cb)(evutil_socket_t, short, void *))
void ct_init_eventloop(struct ct_global_state *state)
void ct_cleanup(struct ct_global_state *state)
void ct_cleanup_eventloop(struct ct_global_state *state)

    /* CT context state */

struct ct_event_state * ct_event_init(struct ct_global_state *state, void (*cb)(evutil_socket_t, short, void *), void (*info_cb)(evutil_socket_t, short, void *))
int ct_event_dispatch(struct ct_event_state *ev_ct)
int ct_event_loopbreak(struct ct_event_state *ev_ct)
void ct_event_cleanup(struct ct_event_state *ev_ct)
void ct_wakeup_file(struct ct_event_state *ev_ct)
void ct_wakeup_sha(struct ct_event_state *ev_ct)
void ct_wakeup_compress(struct ct_event_state *ev_ct)
void ct_wakeup_csha(struct ct_event_state *ev_ct)
void ct_wakeup_encrypt(struct ct_event_state *ev_ct)
void ct_wakeup_write(struct ct_event_state *ev_ct)
void ct_wakeup_complete(struct ct_event_state *ev_ct)

    typedef void (ct_func_cb)(void *);

void ct_setup_wakeup_file(struct ct_event_state *ev_ct, void *vctx, ct_func_cb *func_cb)
void ct_setup_wakeup_sha(struct ct_event_state *ev_ct, void *vctx, ct_func_cb *func_cb)
void ct_setup_wakeup_compress(struct ct_event_state *ev_ct, void *vctx, ct_func_cb *func_cb)
void ct_setup_wakeup_csha(struct ct_event_state *ev_ct, void *vctx, ct_func_cb *func_cb)
void ct_setup_wakeup_encrypt(struct ct_event_state *ev_ct, void *vctx, ct_func_cb *func_cb)
void ct_setup_wakeup_write(struct ct_event_state *ev_ct, void *vctx, ct_func_cb *func_cb)
void ct_setup_wakeup_complete(struct ct_event_state *ev_ct, void *vctx, ct_func_cb *func_cb)
void ct_set_reconnect_timeout(struct ct_event_state *ev_ct, int delay)

    /* Transaction  */
    RB_HEAD(ct_trans_head, ct_trans);
    struct ct_trans {
    	struct ct_header	hdr;		/* must be first element */
    	TAILQ_ENTRY(ct_trans)	tr_next;
    	RB_ENTRY(ct_trans)	tr_trans_rbnode;
    	/* is this a local or data transaction */
    	int			tr_local;
    	struct fnode		*tr_fl_node;
    	struct ctfile_write_state *tr_ctfile;
    	uint64_t tr_trans_id;
    	int tr_type;
    /* DIR is another special */
    #define TR_T_SPECIAL		(1)
    #define TR_T_WRITE_CHUNK	(2)
    #define TR_T_WRITE_HEADER	(3)
    #define TR_T_READ_CHUNK		(4)
    #define TR_T_READ_TRAILER	(5)
    	int tr_state;
    #define TR_S_FREE		(0)
    #define TR_S_SPECIAL		(1)
    #define TR_S_FILE_START		(2)
    #define TR_S_READ		(3)
    #define TR_S_UNCOMPSHA_ED	(4)
    #define TR_S_COMPRESSED		(5)
    #define TR_S_COMPSHA_ED		(6)
    #define TR_S_ENCRYPTED		(7)
    #define TR_S_EXISTS		(8)
    #define TR_S_NEXISTS		(9)
    #define TR_S_WRITTEN		(10)
    #define TR_S_WMD_READY		(11)
    #define TR_S_WAITING		(12)
    #define TR_S_DONE		(13)
    #define TR_S_EX_SHA		(14)
    #define TR_S_EX_READ		(15)
    #define TR_S_EX_DECRYPTED	(16)
    #define TR_S_EX_UNCOMPRESSED	(17)
    #define TR_S_EX_FILE_START	(18)
    #define TR_S_EX_SPECIAL		(19)
    #define TR_S_EX_FILE_END	(20)
    #define TR_S_XML_OPEN		(21)
    #define TR_S_XML_OPENED		(22)
    #define TR_S_XML_CLOSE		(23)
    #define TR_S_XML_CLOSING	(24)
    #define TR_S_XML_CLOSED		(25)
    #define TR_S_XML_LIST		(26)
    #define TR_S_XML_DELETE		(27)
    #define TR_S_XML_CULL_SEND	(28)
    #define TR_S_XML_CULL_SHA_SEND	(29)
    #define TR_S_XML_CULL_COMPLETE_SEND	(30)
    #define TR_S_XML_CULL_REPLIED	(31)
    	char			tr_dataslot;
    	char			tr_eof;
    	uint8_t			tr_sha[SHA_DIGEST_LENGTH];
    	uint8_t			tr_csha[SHA_DIGEST_LENGTH];
    	uint8_t			tr_iv[CT_IV_LEN];
    	int			tr_chsize;
    	int			tr_size[3];
    	uint8_t			*tr_data[3];
    	uint32_t		tr_ctfile_chunkno;
    	const char		*tr_ctfile_name;
    };

struct ct_trans * ct_trans_alloc(struct ct_global_state *state)
struct ct_trans * ct_trans_realloc_local(struct ct_global_state *state, struct ct_trans *trans)
void ct_trans_free(struct ct_global_state *state, struct ct_trans *trans)

    /* Util path functions */

char * ct_dirname(const char *orig_path)
char * ct_basename(const char *orig_path)
int ct_absolute_path(const char *path) int ctfile_verify_name(char *ctfile) void ctfile_trim_cache(const char *cachedir, long long max_size) void ct_prompt_for_login_password(struct ct_config *conf)
void ct_normalize_username(char *username) char * ct_normalize_path(char *path) void ct_normalize_filelist(char **filelist)

    /* Operation API */
    typedef void (ct_op_cb)(struct ct_global_state *state, struct ct_op *);
    struct ct_op {
    	TAILQ_ENTRY(ct_op)	 op_link;
    	ct_op_cb		*op_start;
    	ct_op_cb		*op_complete;
    	void			*op_args;
    	void			*op_priv;	/* operation private data */
    };

struct ct_op * ct_add_operation(struct ct_global_state *state, ct_op_cb *start, ct_op_cb *complete, void *args)
struct ct_op * ct_add_operation_after(struct ct_global_state *state, struct ct_op *after, ct_op_cb *start, ct_op_cb *complete, void *args)
int ct_do_operation(struct ct_config *conf, ct_op_cb *start, ct_op_cb *complete, void *args, int need_secrets) void ctfile_list_complete(struct ctfile_list *files, int matchmode, char **flist, char **excludelist, struct ctfile_list_tree *results)

    /* return boolean whether or not the last ctfile_list contained the filename */

int ct_file_on_server(struct ct_global_state *state, char *filename) void ct_cull_kick(struct ct_global_state *state) int ct_have_remote_secrets_file(struct ct_config *conf)

    /*
     * For remote mode, adds the operations obtain the provided ctfile from the
     * server then calls the callback to add your dependent op.
     */
    typedef void	(ctfile_find_callback)(struct ct_global_state *,
    		    char *, void *);

void ctfile_find_for_operation(struct ct_global_state *state, char *tag, ctfile_find_callback *nextop, void *nextop_args, int download_chain, int empty_ok) void ct_extract_setup(struct ct_extract_head *extract_head, struct ctfile_parse_state *ctx, const char *file, const char *ctfile_basedir, int *is_allfiles)
void ct_extract_open_next(struct ct_extract_head *extract_head, struct ctfile_parse_state *ctx)
int ct_file_extract_open(struct ct_extract_state *ces, struct fnode *fnode)
void ct_file_extract_write(struct ct_extract_state *ces, struct fnode *, uint8_t *buf, size_t size)
void ct_file_extract_close(struct ct_extract_state *ces, struct fnode *fnode)
void ct_file_extract_special(struct ct_extract_state *ces, struct fnode *fnode)

    /* length of a ctfile tag's time string */
    #define			TIMEDATA_LEN	17	/* including NUL */

int ct_get_answer(char *prompt, char *a1, char *a2, char *default_val, char *answer, size_t answer_len, int secret)
int ct_prompt_password(char *prompt, char *answer, size_t answer_len, char *answer2, size_t answer2_len, int confirm)

    /* Probably doesn't belong here */

char * ct_getloginbyuid(uid_t uid) The following functions belong to the simple api and are described in simplect(3) int ct_do_remotelist(struct ct_global_state *state, char **search, char **exclude, int matchmode, void (*printfn) (struct ct_global_state *state, struct ct_op *op)) int ct_do_remotearchive(struct ct_global_state *state, char *ctfile, char **flist, char *tdir, char **excludelist, char *includefile, int match_mode, int no_cross_mounts, int strip_slash, int follow_root_symlink, int follow_symlinks, struct ct_config *conf) int ct_do_remoteextract(struct ct_global_state *state, char *ctfile, char *tdir, char **excludelist, char **includelist, int match_mode, int strip_slash, int follow_symlinks, int preserve_attr, struct ct_config *conf) int ct_setup_flags(int flags, int cflags, int debug_mask) int ct_setup_config(char *configfile, struct ct_config **config, struct ct_global_state **state) int ct_cleanup_all(struct ct_global_state *state, char *configfile, struct ct_config *config)

  MATCH

    /* API to match straings against previously provided lists of criteria */
    #define CT_MATCH_INVALID	(0)
    #define CT_MATCH_REGEX		(1)
    #define CT_MATCH_RB		(2)
    #define CT_MATCH_GLOB		(3)

struct ct_match * ct_match_compile(int mode, char **flist)
struct ct_match * ct_match_fromfile(const char *file, int matchmode)
char ** ct_matchlist_fromfile(const char *file, int *nentries)
void ct_matchlist_free(char **flist)
int ct_match(struct ct_match *match, char *candidate)
void ct_match_unwind(struct ct_match *match)

  PROTO
#include <ctutil.h>
#include ct_types.h
#include ct_db.h void * ct_body_alloc_xml(size_t sz)

    #define MD_O_READ	0
    #define MD_O_WRITE	1
    #define MD_O_APPEND	2
    #define CT_CULL_PRECIOUS	0x1

#include <sys/tree.h>
#include <sys/queue.h>
#include <stdint.h>
#include <openssl/sha.h>
#include <ctutil.h>

    struct fnode {
    	TAILQ_ENTRY(fnode)	fn_list;
    	char			*fn_hlname;
    	struct dnode		*fn_parent_dir;
    	struct dnode		*fn_curdir_dir;
    	int			fn_hardlink;
    	dev_t			fn_dev;
    	ino_t			fn_ino;
    	uint64_t		fn_idx;
    	dev_t			fn_rdev;
    	uint32_t		fn_uid;
    	uint32_t		fn_gid;
    	int			fn_mode;
    	int64_t			fn_atime;
    	int64_t			fn_mtime;
    	int			fn_type;
    	off_t			fn_size;
    	off_t			fn_offset;
    	off_t			fn_comp_size;
    	char			*fn_name;	/* name to access */
    	char			*fn_fullname;	/* path to file */
    	char			*fn_tempname;
    	int			fn_state;
    #define CT_FILE_START		(0)
    #define CT_FILE_PROCESSING	(1)
    #define CT_FILE_FINISHED	(2)
    	SHA_CTX			fn_shactx;
    	int			fn_skip_file;
    	TAILQ_HEAD(, fnode)	fn_hardlinks;
    };

    struct dnode {
    	RB_ENTRY(dnode)		 d_rb_name;
    	RB_ENTRY(dnode)		 d_rb_num;
    	int64_t			 d_num;
    	struct dnode		*d_parent;
    	char			*d_name;
    	char			*d_sname;
    	int			 d_fd; /* valid if processing */
    	uint32_t                 d_uid;         /* user id */
    	uint32_t                 d_gid;         /* group id */
    	uint32_t                 d_mode;        /* file mode */
    	int                      d_atime;       /* last access time */
    	int                      d_mtime;       /* last modification time */
    };

    /*
     * remote listing structures.
     */
    SIMPLEQ_HEAD(ctfile_list, ctfile_list_file);
    RB_HEAD(ctfile_list_tree, ctfile_list_file);
    RB_PROTOTYPE(ctfile_list_tree, ctfile_list_file, next, ct_cmp_ctfile);

    struct ctfile_list_file {
    	union {
    		RB_ENTRY(ctfile_list_file)	nxt;
    		SIMPLEQ_ENTRY(ctfile_list_file)	lnk;
    	}					mlf_entries;
    #define mlf_next	mlf_entries.nxt
    #define mlf_link	mlf_entries.lnk
    	char					mlf_name[CT_CTFILE_MAXLEN];
    	off_t					mlf_size;
    	time_t					mlf_mtime;
    	int					mlf_keep;
    };

    /* debug log levels */
    /* 0x1 and 0x2 taken by ctutil */
    #define CT_LOG_SOCKET	(CTUTIL_LOG_SOCKET)
    #define	CT_LOG_CONFIG	(CTUTIL_LOG_CONFIG)
    #define	CT_LOG_EXUDE	(0x004)
    #define	CT_LOG_NET	(0x008)
    #define	CT_LOG_TRANS	(0x010)
    #define	CT_LOG_SHA	(0x020)
    #define	CT_LOG_CTFILE	(0x040)
    #define	CT_LOG_DB	(0x080)
    #define	CT_LOG_CRYPTO	(0x100)
    #define	CT_LOG_FILE	(0x200)
    #define	CT_LOG_XML	(0x400)
    #define	CT_LOG_VERTREE	(0x800)

SEE ALSO
simplect(3)

HISTORY
-nosplit cyphertite was written by Conformal Systems, LLC. <info@conformal.com>.