aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2007-08-22 19:09:04 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2007-08-22 19:09:04 +0000
commitc7e791e9563b7805fc7a375bc7e616b4252a9c57 (patch)
tree7e34ebcd4326df7f562f73175762a322c4ce2d5e /src
parent180ca1d87d2bf69d9dbb0acb76422e9ae15f930c (diff)
downloadwydawca-c7e791e9563b7805fc7a375bc7e616b4252a9c57.tar.gz
wydawca-c7e791e9563b7805fc7a375bc7e616b4252a9c57.tar.bz2
Update
git-svn-id: file:///svnroot/wydawca/trunk@285 6bb4bd81-ecc2-4fd4-a2d4-9571d19c0d33
Diffstat (limited to 'src')
-rw-r--r--src/directive.c23
-rw-r--r--src/diskio.c53
-rw-r--r--src/exec.c5
-rw-r--r--src/gpg.c12
-rw-r--r--src/process.c8
-rw-r--r--src/triplet.c15
6 files changed, 110 insertions, 6 deletions
diff --git a/src/directive.c b/src/directive.c
index ee52dd7..0853552 100644
--- a/src/directive.c
+++ b/src/directive.c
@@ -18,6 +18,7 @@
/* Directive file support */
+/* Parse directives from TRP->blurb. Fill TRP->directive */
int
directive_parse (struct file_triplet *trp)
{
@@ -59,6 +60,8 @@ directive_parse (struct file_triplet *trp)
return 0;
}
+/* If a directive KEY exists in the triplet TRP, return 0 and point PVAL
+ (unless it is NULL) to its value. Othervise, return 1. */
int
directive_get_value (struct file_triplet *trp, const char *key,
const char **pval)
@@ -83,6 +86,16 @@ directive_get_value (struct file_triplet *trp, const char *key,
return 1;
}
+/* Auxiliary function for sequential access to directories from TRP.
+ Arguments:
+ N - Index of the current directive,
+ TRP - Triplet,
+ PKEY, PVAL - Return addresses.
+
+ The function points PKEY and PVAL to the keyword and value of the Nth
+ directive, and returns N + 1.
+
+ If N points past all the directive, the function returns 0. */
static int
_directive_seq_get (int n, struct file_triplet *trp,
const char **pkey, const char **pval)
@@ -110,6 +123,8 @@ _directive_seq_get (int n, struct file_triplet *trp,
return ++n;
}
+/* Get the first directive from TRP. Point *PKEY to its keyword and
+ *PVAL to its value. Return 1 on success, 0 on failure. */
int
directive_first (struct file_triplet *trp,
const char **pkey, const char **pval)
@@ -118,6 +133,9 @@ directive_first (struct file_triplet *trp,
return _directive_seq_get (n, trp, pkey, pval);
}
+/* Get the first directive from TRP. Point *PKEY to its keyword and
+ *PVAL to its value. Return 1 on success, 0 on failure.
+ Return non-0 on success, 0 on failure */
int
directive_next (struct file_triplet *trp, int n,
const char **pkey, const char **pval)
@@ -125,6 +143,7 @@ directive_next (struct file_triplet *trp, int n,
return _directive_seq_get (n, trp, pkey, pval);
}
+/* Pack a directive string VAL into an unsigned number */
int
directive_pack_version (const char *val, unsigned *pversion)
{
@@ -143,6 +162,8 @@ directive_pack_version (const char *val, unsigned *pversion)
return 0;
}
+/* Return true if the directory file version of the triplet TRP
+ is within the inclusive range FROM and TO (packed) */
int
directive_version_in_range_p (struct file_triplet *trp,
unsigned from, unsigned to)
@@ -212,6 +233,7 @@ find_directive (const char *key)
return unknown_dir;
}
+/* Return 0 if the directory file format of the triplet TRP is OK. */
int
verify_directive_format (struct file_triplet *trp)
{
@@ -278,6 +300,7 @@ verify_directive_format (struct file_triplet *trp)
return 0;
}
+/* Process the directives from TRP, using directory pair DPAIR */
int
process_directives (struct file_triplet *trp, struct directory_pair *dpair)
{
diff --git a/src/diskio.c b/src/diskio.c
index 6eaffa0..cb8df71 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -24,6 +24,7 @@
# endif
#endif
+/* Return true if ARG is a sub-directory of DIR */
int
sub_dir_p (char *arg, char *dir)
{
@@ -34,6 +35,9 @@ sub_dir_p (char *arg, char *dir)
&& arg[dlen] == '/';
}
+/* Concatenate BASE directory name, a single directory separator (/) and
+ NAME. Return in PBASELEN the length of BASE, not counting eventual trailing
+ slash. */
char *
concat_dir (const char *base, const char *name, size_t *pbaselen)
{
@@ -55,6 +59,8 @@ concat_dir (const char *base, const char *name, size_t *pbaselen)
return dir;
}
+/* Create the directory DIR, eventually creating all intermediate directories
+ starting from DIR + BASELEN, with owner UID and GID. */
int
create_hierarchy (char *dir, size_t baselen, uid_t uid, gid_t gid)
{
@@ -108,6 +114,9 @@ create_hierarchy (char *dir, size_t baselen, uid_t uid, gid_t gid)
return rc;
}
+/* Create a directory BASE/NAME (with eventual intermediate directories in
+ NAME). Use UID and GID as owner ids.
+ Do nothing if dry_run_mode is set. */
char *
create_directory (const char *base, const char *name, uid_t uid, gid_t gid)
{
@@ -122,6 +131,9 @@ create_directory (const char *base, const char *name, uid_t uid, gid_t gid)
return dir;
}
+
+/* Copy FILE to DST_FILE, creating the latter with owner UID and GID.
+ Prefer sendfile(2), if available. Otherwise use plain old approach. */
int
copy_file (const char *file, const char *dst_file, uid_t uid, gid_t gid)
{
@@ -230,6 +242,9 @@ copy_file (const char *file, const char *dst_file, uid_t uid, gid_t gid)
return rc;
}
+/* Move FILE to DST_FILE. If they reside on different devices, use copy_file
+ + unlink.
+ UID and GID give DST_FILE ownership. */
int
do_move_file (const char *file, const char *dst_file, uid_t uid, gid_t gid)
{
@@ -261,6 +276,8 @@ do_move_file (const char *file, const char *dst_file, uid_t uid, gid_t gid)
return rc;
}
+/* Append the FILE to the tar ARCHIVE.
+ Do nothing if dry_run_mode is set. */
int
tar_append_file (const char *archive, const char *file)
{
@@ -293,6 +310,16 @@ tar_append_file (const char *archive, const char *file)
return 1;
}
+/* Backup a file to a directory.
+ Arguments:
+ DST_FILE - File nam to back up.
+ DST_DIR - Directory part of DST_FILE.
+ FILE - File part of DST_FILE; can contain subdirs.
+ ARCHIVE - Archive descriptor.
+ UID, GID - Ownership
+ RELDIR - Directory part of FILE
+
+ Do nothing if dry_run_mode is set. */
int
backup_file (const char *dst_file, const char *dst_dir, const char *file,
struct archive_descr *archive, uid_t uid, gid_t gid,
@@ -363,7 +390,9 @@ backup_file (const char *dst_file, const char *dst_dir, const char *file,
free (adir);
return rc;
}
-
+
+/* Select the appropriate backup type and backup a file. See backup_file
+ for the argument description. */
int
do_archive_file (const char *dst_file, const char *dst_dir, const char *file,
struct archive_descr *archive, uid_t uid, gid_t gid,
@@ -383,6 +412,11 @@ do_archive_file (const char *dst_file, const char *dst_dir, const char *file,
return 0;
}
+/* Move the part FILE_ID of the triplet TRP between the directories in
+ DPAIR. RELDIR gives relative directory (i.e. the directory part of
+ the file name) for backup purposes.
+
+ Do nothing if dry_run_mode is set. */
int
move_file (struct file_triplet *trp, struct directory_pair *dpair,
enum file_type file_id, const char *reldir)
@@ -414,6 +448,11 @@ move_file (struct file_triplet *trp, struct directory_pair *dpair,
return rc;
}
+/* Archive the part FILE_ID of the triplet TRP located in DPAIR->dest_dir.
+ Do nothing if dry_run_mode is set.
+
+ FIXME: Remove the file afterwards?
+*/
int
archive_file (struct file_triplet *trp, struct directory_pair *dpair,
const char *file_name, const char *reldir)
@@ -451,7 +490,11 @@ archive_file (struct file_triplet *trp, struct directory_pair *dpair,
free (dst_dir);
return rc;
}
-
+
+/* Create a symbolic link from WANTED_SRC to WANTED_DST in the subdirectory
+ RELDIR of DPAIR->dest_dir. Get ownership information from TRP.
+
+ Do nothing if dry_run_mode is set. */
int
symlink_file (struct file_triplet *trp, struct directory_pair *dpair,
const char *reldir,
@@ -537,6 +580,7 @@ symlink_file (struct file_triplet *trp, struct directory_pair *dpair,
return rc;
}
+/* Auxiliary function for rmsymlink_file (see below) */
static int
do_rmsymlink_file (const char *dst_file)
{
@@ -569,6 +613,11 @@ do_rmsymlink_file (const char *dst_file)
return 0;
}
+/* Remove the symbolic link DPAIR->dest_dir/RELDIR/FILE_NAME
+
+ Get ownership information from TRP.
+
+ Do nothing if dry_run_mode is set. */
int
rmsymlink_file (struct file_triplet *trp, struct directory_pair *dpair,
const char *reldir, const char *file_name)
diff --git a/src/exec.c b/src/exec.c
index 1f9e27a..7eb8883 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -21,6 +21,8 @@
#include <sys/wait.h>
#include <signal.h>
+/* Execute a program from ARGC/ARGV. Return PID in PPID.
+ Return FILE connected to the program's stdout and stderr. */
static FILE *
start_prog (int argc, const char **argv, pid_t *ppid)
{
@@ -65,6 +67,8 @@ start_prog (int argc, const char **argv, pid_t *ppid)
return fp;
}
+/* Log everything read from FP as the output from the program PROG, using
+ syslog priority PRIO. */
void
log_output (int prio, const char *prog, FILE *fp)
{
@@ -78,6 +82,7 @@ log_output (int prio, const char *prog, FILE *fp)
free (buf);
}
+/* Execute ARGC/ARGV. Return the exit code in RETCODE. */
enum exec_result
wydawca_exec (int argc, const char **argv, int *retcode)
{
diff --git a/src/gpg.c b/src/gpg.c
index ea011ff..8e67e63 100644
--- a/src/gpg.c
+++ b/src/gpg.c
@@ -14,6 +14,8 @@
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>. */
+/* GPG interface functions */
+
#include "wydawca.h"
#include "save-cwd.h"
#include <gpgme.h>
@@ -34,6 +36,8 @@ static char *homedir;
static int rmdir_r (const char *name);
+/* Auxiliary function: change to directory NAME and recursively remove
+ everything under it. */
static int
recursive_rmdir (const char *name)
{
@@ -80,6 +84,8 @@ recursive_rmdir (const char *name)
return rc;
}
+/* Recursively remove the contents of the directory NAME and the directory
+ itself. Do not change CWD. */
static int
rmdir_r (const char *name)
{
@@ -110,6 +116,7 @@ rmdir_r (const char *name)
return rc;
}
+/* Remove temporary GPG home directory */
static void
remove_homedir ()
{
@@ -119,6 +126,7 @@ remove_homedir ()
logmsg (LOG_CRIT, "Failed to remove GPG directory %s", homedir);
}
+/* Create a temporary GPG home directory */
int
wydawca_gpg_homedir ()
{
@@ -139,6 +147,7 @@ wydawca_gpg_homedir ()
return 0;
}
+/* Verify the directive file from TRP using public key PUBKEY */
/* FIXME: dpair currently unused */
int
verify_directive_signature (struct file_triplet *trp,
@@ -185,6 +194,9 @@ verify_directive_signature (struct file_triplet *trp,
return rc;
}
+/* Verify the detached signature of TRP.
+ NOTE: It is assumed that the public key is already registered (by
+ a previous call to verify_directive_signature). */
int
verify_detached_signature (struct file_triplet *trp,
struct directory_pair *dpair)
diff --git a/src/process.c b/src/process.c
index 575874a..5452cd9 100644
--- a/src/process.c
+++ b/src/process.c
@@ -33,6 +33,8 @@ register_directory_pair (struct directory_pair *dpair)
dlist = dl;
}
+/* Return true if NAME is a directory. If stat fails, return the error
+ code in EC */
int
test_dir (const char *name, int *ec)
{
@@ -47,6 +49,7 @@ test_dir (const char *name, int *ec)
return S_ISDIR (st.st_mode) == 0;
}
+/* Return a textual representation of a file TYPE */
const char *
file_type_str (enum file_type type)
{
@@ -66,6 +69,8 @@ file_type_str (enum file_type type)
#define SUF_SIG ".sig"
#define SUF_DIR ".directive.asc"
+/* Parse file NAME: determine its type and root name and store this
+ information in FINFO */
void
parse_file_name (const char *name, struct file_info *finfo)
{
@@ -97,6 +102,8 @@ parse_file_name (const char *name, struct file_info *finfo)
abort (); /* should not happen */
}
+/* Scan upload directory from the DPAIR and register all files found
+ there, forming triplets when possible */
void
scan_directory_pair (struct directory_pair *dpair)
{
@@ -169,6 +176,7 @@ scan_directory_pair (struct directory_pair *dpair)
method_done (&dpair->gpg_key_method);
}
+/* Scan all configured update directories */
void
scan_directories ()
{
diff --git a/src/triplet.c b/src/triplet.c
index d0c1dc4..3ecee29 100644
--- a/src/triplet.c
+++ b/src/triplet.c
@@ -35,6 +35,7 @@ hash_triplet_compare (void const *data1, void const *data2)
return t1->name && t2->name && strcmp (t1->name, t2->name) == 0;
}
+/* Reclaim memory storage associated with a table entry */
void
hash_triplet_free (void *data)
{
@@ -54,6 +55,7 @@ hash_triplet_free (void *data)
free (tp);
}
+/* Register a file in the triplet table */
void
register_file (struct file_info *finfo)
{
@@ -80,19 +82,21 @@ register_file (struct file_info *finfo)
#define SP(s) ((s) ? (s) : "NONE")
+/* Return true if any part of the triplet TRP was modified more than
+ TTL seconds ago */
static bool
-triplet_expired_p (struct file_triplet *trp, time_t file_sweep_time)
+triplet_expired_p (struct file_triplet *trp, time_t ttl)
{
int i;
time_t now = time (NULL);
- if (file_sweep_time == 0)
+ if (ttl == 0)
return false;
for (i = 0; i < FILE_TYPE_COUNT; i++)
{
if (trp->file[i].name
- && (now - trp->file[i].mtime) > file_sweep_time)
+ && (now - trp->file[i].mtime) > ttl)
{
if (debug_level)
logmsg (LOG_DEBUG, "File %s expired", trp->file[i].name);
@@ -102,6 +106,7 @@ triplet_expired_p (struct file_triplet *trp, time_t file_sweep_time)
return false;
}
+/* Return true if TRP is a complete and valid triplet */
static bool
valid_triplet_p (struct file_triplet *trp)
{
@@ -120,6 +125,7 @@ valid_triplet_p (struct file_triplet *trp)
return false;
}
+/* Unlink all parts of the triplet TRP */
static void
remove_triplet (struct file_triplet *trp)
{
@@ -137,7 +143,7 @@ remove_triplet (struct file_triplet *trp)
}
}
-
+/* Process a single triplet from the table */
static bool
triplet_processor (void *data, void *proc_data)
{
@@ -167,6 +173,7 @@ triplet_processor (void *data, void *proc_data)
return true;
}
+/* Process all triplets from the table according to the directory pair DPAIR */
void
enumerate_triplets (struct directory_pair *dpair)
{

Return to:

Send suggestions and report system problems to the System administrator.