diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-08-25 13:29:33 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-08-25 13:29:33 +0000 |
commit | e4b5d37def5023905e98bc0b6c6f81c2d56ba362 (patch) | |
tree | 76dbdd53079e4f05529c002284467820c8d5d0ef /src/verify.c | |
parent | 1107c4341552ecb568b43292fc219a73e0d49a0f (diff) | |
download | wydawca-e4b5d37def5023905e98bc0b6c6f81c2d56ba362.tar.gz wydawca-e4b5d37def5023905e98bc0b6c6f81c2d56ba362.tar.bz2 |
* configure.ac: Require mailutils for wydawca
* bootstrap: Require inttostr and strftime
* wydawca/mail.h: New file
* wydawca/mail.c: New file
* wydawca/Makefile.am: Add mail.c and mail.h
* wydawca/wydawca.c: Include mail.h
(stat_mask_p, make_stat_expansion): New functions
(logstats): Call mail_stats
(main): Call initialize mailer subsystem
* wydawca/sql.c, wydawca/sql.h: Keep usage reference count. Do not
deinitialize unless it falls to 0. Do not initialize if it is > 0.
* wydawca/verify.c (expand_param): Rewrite to allow long keywords
All callers updated.
* wydawca/wydawca.h (struct access_method): Keep reference count
(struct directory_pair): verify_method and gpg_key_method are
pointers to structs.
(struct kw_expansion): kw is char*
(count_collected_triplets): New function
(method_new): New function
* wydawca/config.c: reimplement verify-user and gpg-key
New keywords mailer, admin-address, from-address, mail-admin-stat
and admin-stat-message
* wydawca/process.c: Close methods only when their reference count
is 0.
* wydawca/method.c: Likewise.
(method_new): New function
* wydawca/wydawca.rc: Update
* wydawca/diskio.c: Minor changes
* wydawca/triplet.c (count_collected_triplets): New function
* jabberd/main.c: Minor change
git-svn-id: file:///svnroot/wydawca/trunk@295 6bb4bd81-ecc2-4fd4-a2d4-9571d19c0d33
Diffstat (limited to 'src/verify.c')
-rw-r--r-- | src/verify.c | 60 |
1 files changed, 48 insertions, 12 deletions
diff --git a/src/verify.c b/src/verify.c index e63d524..2ccdfaa 100644 --- a/src/verify.c +++ b/src/verify.c @@ -39,16 +39,26 @@ trim (char *str) } static const char * -find_expansion (int c, const struct kw_expansion *exp, size_t nexp) +find_expansion_char (int c, const struct kw_expansion *exp, size_t nexp) { for (; nexp; nexp--, exp++) - if (exp->kw == c) + if (exp->kw[1] == 0 && exp->kw[0] == c) return exp->value; return NULL; } -/* Expand PARAM by replacing %X with the values as per expansion map EXP - (of NEXP elements). +static const char * +find_expansion_word (char *kw, size_t len, + const struct kw_expansion *exp, size_t nexp) +{ + for (; nexp; nexp--, exp++) + if (strlen (exp->kw) == len && memcmp (exp->kw, kw, len) == 0) + return exp->value; + return NULL; +} + +/* Expand PARAM by replacing %u with the quoted value of USER, %p with that + of PROJECT and %% with a single %. Return the malloc'ed result. FIXME: Should we quote PARAM itself? */ char * @@ -71,7 +81,18 @@ expand_param (const char *param, const struct kw_expansion *exp, size_t nexp) len++; p += 2; } - else if ((s = find_expansion (p[1], exp, nexp)) != NULL) + else if (p[1] == '{') + { + char *e = strchr (p + 2, '}'); + if (e && (s = find_expansion_word (p + 2, e - p - 2, exp, nexp))) + { + len += strlen (s); + p = e + 1; + } + else + len++, p++; + } + else if ((s = find_expansion_char (p[1], exp, nexp)) != NULL) { len += strlen (s); p += 2; @@ -102,8 +123,23 @@ expand_param (const char *param, const struct kw_expansion *exp, size_t nexp) *q++ = *p++; break; + case '{': + { + char *e = strchr (p + 1, '}'); + if (e + && (s = find_expansion_word (p + 1, e - p - 1, exp, nexp))) + { + strcpy (q, s); + q += strlen (s); + p = e + 1; + } + else + len++, p++; + } + break; + default: - if ((s = find_expansion (*p, exp, nexp)) != NULL) + if ((s = find_expansion_char (*p, exp, nexp)) != NULL) { strcpy (q, s); q += strlen (s); @@ -168,7 +204,7 @@ escape_kwexp (struct access_method *method, struct kw_expansion *exp, quote_string (method, exp[i].value, &exp[i].value); } -static void +void free_kwexp (struct kw_expansion *exp, size_t nexp) { size_t i; @@ -185,7 +221,7 @@ int check_access_rights (struct file_triplet *trp, struct directory_pair *dpair, const char *user) { - struct access_method *method = &dpair->verify_method; + struct access_method *method = dpair->verify_method; char *project; const char *directory; char *p; @@ -215,9 +251,9 @@ check_access_rights (struct file_triplet *trp, struct directory_pair *dpair, logmsg (LOG_DEBUG, "verifying access rights for user %s to project %s", user, project); - kwexp[0].kw = 'u'; + kwexp[0].kw = "u"; kwexp[0].value = (char*) user; - kwexp[1].kw = 'p'; + kwexp[1].kw = "p"; kwexp[1].value = project; escape_kwexp (method, kwexp, 2); @@ -255,7 +291,7 @@ 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; + struct access_method *method = dpair->gpg_key_method; const char *pubkey; int rc; struct kw_expansion kwexp[1]; @@ -273,7 +309,7 @@ verify_directive_file (struct file_triplet *trp, struct directory_pair *dpair) trp->gid = pw->pw_gid; user_name = pw->pw_name; - kwexp[0].kw = 'u'; + kwexp[0].kw = "u"; kwexp[0].value = user_name; escape_kwexp (method, kwexp, 1); command = expand_param (method->param[1], kwexp, 1); |