diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-08-22 13:23:03 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-08-22 13:23:03 +0000 |
commit | 180ca1d87d2bf69d9dbb0acb76422e9ae15f930c (patch) | |
tree | b14651206aaec8e03fdfdce9e04433068fa62648 /src/wydawca.h | |
parent | 708a28a2f5bd2384e4c254a47d069ec4d9ef697e (diff) | |
download | wydawca-180ca1d87d2bf69d9dbb0acb76422e9ae15f930c.tar.gz wydawca-180ca1d87d2bf69d9dbb0acb76422e9ae15f930c.tar.bz2 |
Implement all directives
git-svn-id: file:///svnroot/wydawca/trunk@284 6bb4bd81-ecc2-4fd4-a2d4-9571d19c0d33
Diffstat (limited to 'src/wydawca.h')
-rw-r--r-- | src/wydawca.h | 206 |
1 files changed, 129 insertions, 77 deletions
diff --git a/src/wydawca.h b/src/wydawca.h index ec3ec51..918f6e0 100644 --- a/src/wydawca.h +++ b/src/wydawca.h @@ -39,107 +39,158 @@ #include "backupfile.h" #include "gsc.h" +/* The range of directive versions we accept (major * 100 + minor) */ #define MIN_DIRECTIVE_VERSION 101 #define MAX_DIRECTIVE_VERSION 101 +/* Default modes for mkdir and creat commands: rely on the umask value */ #define MKDIR_PERMISSIONS 0777 #define CREAT_PERMISSIONS 0666 + enum access_method_type { - method_none, - method_sql, - method_builtin, - method_external + method_none, /* Undefined or no method */ + method_sql, /* Use SQL database */ + method_builtin, /* Use built-in facilities */ + method_external /* Invoke an external program */ }; struct access_method { - enum access_method_type type; - char *param[2]; - int init_passed; - char *result; - size_t result_size; + enum access_method_type type; /* Access method type */ + char *param[2]; /* Parameters. The semantics differs + depending on type. For SQL: + 0 - Identifier of the SQL struct + to use; + 1 - Request template */ + + int init_passed; /* Is the structure initialized */ + char *result; /* Last result string */ + size_t result_size; /* Size of result */ union { - struct sqlconn *sqlconn; + struct sqlconn *sqlconn; /* type == method_sql */ /* More to come */ } v; }; + +/* Archive types */ + enum archive_type { - archive_none, - archive_directory, - archive_tar + archive_none, /* No archivation requested */ + archive_directory, /* Archive by moving files to a separate directory + hierarchy */ + archive_tar /* Archive by appending to a tar file (tar -r) */ }; struct archive_descr { - enum archive_type type; - char *name; - enum backup_type backup_type; + enum archive_type type; /* Archivation type */ + char *name; /* Directory name if type==archive_directory, + archive file name if type==archive_tar */ + enum backup_type backup_type; /* Requested backup type if + type == archive_directory */ }; + + +/* A source/destination directory pair. This structure contains all the + data necessary for releasing files from source to destination */ struct directory_pair { - char *source_dir; - char *dest_dir; - time_t file_sweep_time; - struct access_method verify_method; - struct access_method gpg_key_method; - struct archive_descr archive; + char *source_dir; /* Source directory */ + char *dest_dir; /* Destination directory */ + time_t file_sweep_time; /* Remove invalid/unprocessed files + after this amount of time */ + struct access_method verify_method; /* Method for verification user's + access to the project */ + struct access_method gpg_key_method; /* Method for retrieving the user + public key */ + struct archive_descr archive; /* Archivation data */ }; + +/* Type of file in a triplet */ enum file_type { - file_dist, - file_signature, - file_directive, + file_dist, /* Something to be distributed */ + file_signature, /* Detached signature (.sig) */ + file_directive, /* Directive (.directive.asc) */ }; #define FILE_TYPE_COUNT (file_directive+1) +/* Part of a triplet */ struct file_info { - enum file_type type; - time_t mtime; - uid_t uid; - char *name; - unsigned root_len; + enum file_type type; /* Part type */ + time_t mtime; /* Modification time */ + uid_t uid; /* Owner UID */ + char *name; /* File name */ + unsigned root_len; /* Length of root part in name */ }; -struct file_register +/* File triplet */ +struct file_triplet { - char *name; - int flags; - gid_t gid; - struct file_info file[FILE_TYPE_COUNT]; - char **directive; - char *blurb; - char *tmp; - size_t tmpsize; + char *name; /* Triplet base name */ + gid_t gid; /* Owner GID */ + struct file_info file[FILE_TYPE_COUNT]; /* Components */ + char **directive; /* Decoded directive pairs (key: value\0) */ + char *blurb; /* Block of directives: directive[i] points here */ + char *tmp; /* Temporary storage */ + size_t tmpsize; /* Size of memory allocated in tmp */ }; -extern char *conffile; -extern int debug_level; -extern int dry_run_mode; -extern int log_to_stderr; -extern int log_facility; -extern char *syslog_tag; -extern int unlink_invalid_files; -extern time_t file_sweep_time; -extern char *tar_command_name; - -void register_directory_pair (struct directory_pair *dpair); +/* Macros to access owner UID and GID. */ +/* The directive file is always present in the triplet */ +#define TRIPLET_UID(t) ((t)->file[file_directive].uid) +/* GID is filled in after the triplet is finalized and verified */ +#define TRIPLET_GID(t) ((t)->gid) + + +/* Global variables */ +extern char *conffile; /* Configuration file name */ +extern int debug_level; /* Debugging level */ +extern int dry_run_mode; /* Dry run indicator */ +extern int log_to_stderr; /* Log to stderr instead of the syslog */ +extern int log_facility; /* Syslog facility to use if !log_to_stderr */ +extern char *syslog_tag; /* Syslog tag */ +extern time_t file_sweep_time; /* Unlink stale file after this amount of time + */ +extern char *tar_command_name; /* Name of the tar command */ + + +/* Utility functions */ +char *safe_file_name (char *file_name); +char *safe_file_name_alloc (const char *file_name); +size_t trim_length (const char *str); +size_t trim (char *str); void logmsg (int prio, char *fmt, ...) GSC_PRINTFLIKE(2,3); -void scan_directories (void); int test_dir (const char *name, int *ec); -void register_file (struct file_info *finfo); -void enumerate_triplets (struct directory_pair *); - +char *create_directory (const char *base, const char *name, + uid_t uid, gid_t gid); void parse_config (void); +void log_output (int prio, const char *prog, FILE *fp); -char *safe_file_name (char *file_name); +enum exec_result + { + exec_success, /* Command executed and returned 0 */ + exec_fail, /* Command executed and returned not 0 */ + exec_error /* Command failed to execute */ + }; + +enum exec_result wydawca_exec (int argc, const char **argv, int *retcode); + + +/* Directory scanning and registering */ +void scan_directories (void); +void register_directory_pair (struct directory_pair *dpair); +void register_file (struct file_info *finfo); +void enumerate_triplets (struct directory_pair *); +/* General-purpose method support */ int method_init (struct access_method *method); int method_done (struct access_method *method); int method_run (struct access_method *method, const char *cmd); @@ -147,39 +198,40 @@ const char *method_result (struct access_method *method); void method_copy_result (struct access_method *method, const char *res, size_t size); -int verify_triplet (struct file_register *reg, struct directory_pair *dpair); -int verify_directive_signature (struct file_register *reg, +/* Verification functions */ +int verify_triplet (struct file_triplet *trp, struct directory_pair *dpair); +int verify_directive_signature (struct file_triplet *trp, struct directory_pair *dpair, const char *pubkey); -int verify_detached_signature (struct file_register *reg, +int verify_detached_signature (struct file_triplet *trp, struct directory_pair *dpair); -size_t trim_length (const char *str); -size_t trim (char *str); - -int directive_parse (struct file_register *reg); -int directive_get_value (struct file_register *reg, const char *key, +/* Directive file support */ +int directive_parse (struct file_triplet *trp); +int directive_get_value (struct file_triplet *trp, const char *key, const char **pval); int directive_pack_version (const char *val, unsigned *pversion); -int directive_version_in_range_p (struct file_register *reg, +int directive_version_in_range_p (struct file_triplet *trp, unsigned from, unsigned to); -int verify_directive_format (struct file_register *reg); - - -int directive_first (struct file_register *reg, +int verify_directive_format (struct file_triplet *trp); +int directive_first (struct file_triplet *trp, const char **pkey, const char **pval); -int directive_next (struct file_register *reg, int n, +int directive_next (struct file_triplet *trp, int n, const char **pkey, const char **pval); -int process_directives (struct file_register *reg, +int process_directives (struct file_triplet *trp, struct directory_pair *dpair); -char *create_directory (const char *base, const char *name, - uid_t uid, gid_t gid); + +/* Actions */ -int move_file (struct file_register *reg, enum file_type file_id, - const char *dst_dir, const char *reldir, - struct archive_descr *archive); +int move_file (struct file_triplet *trp, struct directory_pair *dpair, + enum file_type file_id, const char *reldir); +int archive_file (struct file_triplet *trp, struct directory_pair *dpair, + const char *file_name, const char *reldir); +int symlink_file (struct file_triplet *trp, struct directory_pair *dpair, + const char *reldir, + const char *wanted_src, const char *wanted_dst); +int rmsymlink_file (struct file_triplet *trp, struct directory_pair *dpair, + const char *reldir, const char *file_name); -FILE *start_prog (int argc, const char **argv, pid_t *ppid); -void log_output (int prio, const char *prog, FILE *fp); |