diff options
-rw-r--r-- | src/mail.c | 28 | ||||
-rw-r--r-- | src/triplet.c | 32 | ||||
-rw-r--r-- | src/verify.c | 20 | ||||
-rw-r--r-- | src/wydawca.h | 4 | ||||
-rw-r--r-- | src/wydawca.rc | 4 |
5 files changed, 52 insertions, 36 deletions
@@ -149,11 +149,27 @@ void notify_owner (struct file_triplet *trp, enum notification_event ev) { int rc; - struct access_method *method = trp->dpair->project_owner_method; + struct access_method *method; char *text; mu_address_t rcpt = NULL; unsigned nrows, ncols, i; struct kw_expansion kwexp[4]; + + switch (ev) + { + case ev_success: + case ev_bad_directive_signature: + case ev_bad_detached_signature: + method = trp->dpair->user_data_method; + break; + + case ev_bad_ownership: + method = trp->dpair->project_owner_method; + break; + + default: + abort (); + } if (method->type == method_none) { @@ -171,7 +187,7 @@ notify_owner (struct file_triplet *trp, enum notification_event ev) return; } - make_default_kwexp (kwexp, NULL, trp->project); + make_default_kwexp (kwexp, trp->user, trp->project); escape_kwexp (method, kwexp, NITEMS (kwexp)); text = expand_param (method->param[1], kwexp, NITEMS (kwexp), NULL); @@ -187,6 +203,13 @@ notify_owner (struct file_triplet *trp, enum notification_event ev) nrows = method_num_rows (method); ncols = method_num_cols (method); + if (nrows == 0) + { + logmsg (LOG_ERR, "cannot obtain owner emails for %s", + trp->project); + return; + } + for (i = 0; i < nrows; i++) { mu_address_t addr; @@ -228,6 +251,7 @@ notify_owner (struct file_triplet *trp, enum notification_event ev) void notify (struct file_triplet *trp, enum notification_event ev) { + fill_project_name (trp); if (owner_notification_flags & STAT_MASK (ev)) notify_owner (trp, ev); /* FIXME */ diff --git a/src/triplet.c b/src/triplet.c index 46c6011..ad9dfb5 100644 --- a/src/triplet.c +++ b/src/triplet.c @@ -51,7 +51,8 @@ hash_triplet_free (void *data) free (tp->directive); free (tp->blurb); free (tp->tmp); - + free (tp->user); + if (tp->user_data) { for (i = 0; i < NITEMS (tp->user_data); i++) @@ -264,7 +265,7 @@ static char * expand_relative_dir (struct kw_expansion *exp, void *data) { struct file_triplet *trp = data; - directive_get_value (trp, "directory", &exp->value); + directive_get_value (trp, "directory", (const char**) &exp->value); exp->static_p = 1; return exp->value; } @@ -317,7 +318,6 @@ format_file_data (struct file_triplet *trp, enum file_type type, char **pret) char modes[11]; struct file_info *info = trp->file + type; char timebuf[sizeof "YYYY-MM-DD HH:MM:SS +0000"]; - struct passwd *pw; struct group *grp; char sbuf[INT_BUFSIZE_BOUND (uintmax_t)]; char *sptr; @@ -340,13 +340,9 @@ format_file_data (struct file_triplet *trp, enum file_type type, char **pret) tm = localtime (&info->sb.st_mtime); strftime (timebuf, sizeof timebuf, "%Y-%m-%d %H:%M:%S %z", tm); - /* FIXME: owner and group name should be store in TRP after verification */ - pw = getpwuid (TRIPLET_UID (trp)); - if (!pw) - user_name = "UNKNOWN"; /* should not happen */ - else - user_name = pw->pw_name; + user_name = trp->user; + /* FIXME: group name should be stored in TRP after verification */ grp = getgrgid (TRIPLET_GID (trp)); if (!grp) group_name = "UNKNOWN"; /* should not happen */ @@ -444,16 +440,8 @@ expand_triplet_directive (struct kw_expansion *exp, void *data) static char * expand_user_name (struct kw_expansion *exp, void *data) { - struct passwd *pw; struct file_triplet *trp = data; - - /* FIXME: should user name be stored in the triplet? */ - pw = getpwuid (TRIPLET_UID (trp)); - if (!pw) - return NULL; - exp->value = xstrdup (pw->pw_name); - exp->static_p = 0; - return exp->value; + return trp->user; } static void @@ -508,8 +496,8 @@ expand_user_real_name (struct kw_expansion *exp, void *data) { struct file_triplet *trp = data; fill_user_data (trp); - if (trp->user_data[0]) - return trp->user_data[0]; + if (trp->user_data && trp->user_data[1]) + return trp->user_data[1]; exp->value = "UNKNOWN"; exp->static_p = 1; return exp->value; @@ -520,8 +508,8 @@ expand_user_email (struct kw_expansion *exp, void *data) { struct file_triplet *trp = data; fill_user_data (trp); - if (trp->user_data[1]) - return trp->user_data[1]; + if (trp->user_data && trp->user_data[0]) + return trp->user_data[0]; exp->value = "UNKNOWN"; exp->static_p = 1; return exp->value; diff --git a/src/verify.c b/src/verify.c index 70678f3..88672ea 100644 --- a/src/verify.c +++ b/src/verify.c @@ -242,12 +242,15 @@ free_kwexp (struct kw_expansion *exp, size_t nexp) -static int -get_project_name (struct file_triplet *trp) +int +fill_project_name (struct file_triplet *trp) { char *project; const char *directory; char *p; + + if (trp->project) + return; if (directive_get_value (trp, "directory", &directory)) { logmsg (LOG_ERR, "%s: missing `directory' directive", @@ -299,7 +302,7 @@ check_access_rights (struct file_triplet *trp, struct directory_pair *dpair, const char *result; struct kw_expansion kwexp[4]; - if (get_project_name (trp)) + if (fill_project_name (trp)) return 1; if (debug_level) @@ -338,7 +341,6 @@ int verify_directive_file (struct file_triplet *trp, struct directory_pair *dpair) { struct passwd *pw; - char *user_name; char *command; struct access_method *method = dpair->gpg_key_method; const char *pubkey; @@ -356,9 +358,9 @@ verify_directive_file (struct file_triplet *trp, struct directory_pair *dpair) return 1; } trp->gid = pw->pw_gid; - user_name = pw->pw_name; + trp->user = xstrdup (pw->pw_name); - make_default_kwexp (kwexp, user_name, NULL); + make_default_kwexp (kwexp, trp->user, NULL); escape_kwexp (method, kwexp, NITEMS (kwexp)); command = expand_param (method->param[1], kwexp, NITEMS (kwexp), NULL); free_kwexp (kwexp, NITEMS (kwexp)); @@ -367,14 +369,14 @@ verify_directive_file (struct file_triplet *trp, struct directory_pair *dpair) free (command); if (rc) { - logmsg (LOG_ERR, "Cannot get PGP key for %s", user_name); + logmsg (LOG_ERR, "Cannot get PGP key for %s", trp->user); return 1; } pubkey = method_result (method, 0, 0); if (!pubkey || pubkey[0] == 0) { - logmsg (LOG_ERR, "No GPG key for %s", user_name); + logmsg (LOG_ERR, "No GPG key for %s", trp->user); return 1; } @@ -399,7 +401,7 @@ verify_directive_file (struct file_triplet *trp, struct directory_pair *dpair) if (verify_directive_format (trp)) return 1; - if (check_access_rights (trp, dpair, user_name)) + if (check_access_rights (trp, dpair, trp->user)) return 1; return 0; diff --git a/src/wydawca.h b/src/wydawca.h index 37de74d..0d38bd3 100644 --- a/src/wydawca.h +++ b/src/wydawca.h @@ -146,7 +146,6 @@ struct file_info struct file_triplet { char *name; /* Triplet base name */ - char *project; /* Triplet project name (if known) */ gid_t gid; /* Owner GID */ struct file_info file[FILE_TYPE_COUNT]; /* Components */ struct directory_pair *dpair; /* Owning directory pair */ @@ -155,6 +154,8 @@ struct file_triplet char *tmp; /* Temporary storage */ size_t tmpsize; /* Size of memory allocated in tmp */ /* Special data for template formatting */ + char *project; /* Triplet project name (if known) */ + char *user; /* User name (if known) */ char **user_data; }; @@ -295,6 +296,7 @@ int verify_directive_signature (struct file_triplet *trp, const char *pubkey); int verify_detached_signature (struct file_triplet *trp, struct directory_pair *dpair); +int fill_project_name (struct file_triplet *trp); /* Directive file support */ int directive_parse (struct file_triplet *trp); diff --git a/src/wydawca.rc b/src/wydawca.rc index b309ddf..3feb54f 100644 --- a/src/wydawca.rc +++ b/src/wydawca.rc @@ -85,7 +85,7 @@ suspicious. The person uploaded the following files: %{triplet:full} -This upload has been ignored and the files removed. If it was you that +This upload has been ignored and the files removed. If it was you who attempted this upload, please make sure you use the right PGP key and try again. If not, please let us know as soon as possible, so we can track down the person trying to make believe he is you. @@ -103,7 +103,7 @@ suspicious. The person uploaded the following files: %{triplet:full} -This upload has been ignored and the files removed. If it was you that +This upload has been ignored and the files removed. If it was you who attempted this upload, please make sure you use the right PGP key and try again. If not, please let us know as soon as possible, so we can track down the person trying to make believe he is you. |