Skip to content

Commit

Permalink
mbname_t stage 2 - replace mboxname_hiersep_to{in|ex}ternal
Browse files Browse the repository at this point in the history
This cleans up a bunch of more places
  • Loading branch information
brong committed Sep 10, 2015
1 parent e95c7de commit 69bfaea
Show file tree
Hide file tree
Showing 34 changed files with 685 additions and 1,142 deletions.
31 changes: 25 additions & 6 deletions imap/append.c
Expand Up @@ -957,7 +957,10 @@ EXPORTED int append_fromstage(struct appendstate *as, struct body **body,
/* Handle flags the user wants to set in the message */
if (flags) {
r = append_apply_flags(as, mboxevent, &record, flags);
if (r) goto out;
if (r) {
syslog(LOG_ERR, "Annotation callout failed to apply flags %s", error_message(r));
goto out;
}
}

/* Write out index file entry */
Expand All @@ -974,14 +977,20 @@ EXPORTED int append_fromstage(struct appendstate *as, struct body **body,
as->userid, as->auth_state);
r = annotate_state_store(astate, user_annots);
}
if (r) goto out;
if (r) {
syslog(LOG_ERR, "Annotation callout failed to apply user annots %s", error_message(r));
goto out;
}
if (system_annots) {
/* pretend to be admin to avoid ACL checks */
annotate_state_set_auth(astate, /*isadmin*/1,
as->userid, as->auth_state);
r = annotate_state_store(astate, system_annots);
}
if (r) goto out;
if (r) {
syslog(LOG_ERR, "Annotation callout failed to apply system annots %s", error_message(r));
goto out;
}
}

out:
Expand Down Expand Up @@ -1157,23 +1166,33 @@ HIDDEN int append_run_annotator(struct appendstate *as,
record->system_flags &= (FLAG_SEEN | FLAGS_INTERNAL);
memset(&record->user_flags, 0, sizeof(record->user_flags));
r = append_apply_flags(as, NULL, record, flags);
if (r) goto out;
if (r) {
syslog(LOG_ERR, "Setting flags from annotator "
"callout failed (%s)",
error_message(r));
goto out;
}

r = mailbox_get_annotate_state(as->mailbox, record->uid, &astate);
if (r) goto out;
if (user_annots) {
annotate_state_set_auth(astate, as->isadmin,
as->userid, as->auth_state);
r = annotate_state_store(astate, user_annots);
if (r) goto out;
if (r) {
syslog(LOG_ERR, "Setting user annnotations from annotator "
"callout failed (%s)",
error_message(r));
goto out;
}
}
if (system_annots) {
/* pretend to be admin to avoid ACL checks */
annotate_state_set_auth(astate, /*isadmin*/1,
as->userid, as->auth_state);
r = annotate_state_store(astate, system_annots);
if (r) {
syslog(LOG_ERR, "Setting annnotations from annotator "
syslog(LOG_ERR, "Setting system annnotations from annotator "
"callout failed (%s)",
error_message(r));
goto out;
Expand Down
13 changes: 5 additions & 8 deletions imap/arbitron.c
Expand Up @@ -506,28 +506,25 @@ static void long_report_users(struct user_list *u, const char *mbox, char type)
static void make_report(const char *key, void *data, void *rock __attribute__((unused)))
{
struct arb_mailbox_data *mbox = (struct arb_mailbox_data *)data;
char *extkey;

/* Skip underread user mailboxes */
if(!strncasecmp(key, "user.", 5) && mbox->nreaders <= 1)
return;

extkey = xstrdup(key);
mboxname_hiersep_toexternal(&arb_namespace, extkey, 0);
key = extkey;
char *extname = mboxname_to_external(key, &arb_namespace, NULL);

if (long_report) {
long_report_users(mbox->readers, key, 'r');
long_report_users(mbox->subscribers, key, 's');
long_report_users(mbox->readers, extname, 'r');
long_report_users(mbox->subscribers, extname, 's');
}
else {
printf("%s %d", key, mbox->nreaders);
printf("%s %d", extname, mbox->nreaders);
if (dousers) report_users(mbox->readers);
if (dosubs) {
printf(" %d", mbox->nsubscribers);
if (dousers) report_users(mbox->subscribers);
}
printf("\n");
}
free(extkey);
free(extname);
}
7 changes: 0 additions & 7 deletions imap/autocreate.c
Expand Up @@ -727,13 +727,6 @@ int autocreate_user(struct namespace *namespace,
create = strarray_split(config_getstring(IMAPOPT_AUTOCREATE_INBOX_FOLDERS), SEP, STRARRAY_TRIM);
subscribe = strarray_split(config_getstring(IMAPOPT_AUTOCREATE_SUBSCRIBE_FOLDERS), SEP, STRARRAY_TRIM);

/* need to convert all names to internal namespace first */
for (n = 0; n < create->count; n++)
mboxname_hiersep_tointernal(namespace, create->data[n], 0);

for (n = 0; n < subscribe->count; n++)
mboxname_hiersep_tointernal(namespace, subscribe->data[n], 0);

for (n = 0; n < create->count; n++) {
const char *name = strarray_nth(create, n);
char *foldername = mboxname_user_mbox(userid, name);
Expand Down
2 changes: 1 addition & 1 deletion imap/http_admin.c
Expand Up @@ -196,7 +196,7 @@ static int meth_get(struct transaction_t *txn,
struct backend *be;

be = proxy_findserver(tgt->userid,
&http_protocol, proxy_userid,
&http_protocol, httpd_userid,
&backend_cached, NULL, NULL, httpd_in);
if (!be) return HTTP_UNAVAILABLE;

Expand Down
26 changes: 11 additions & 15 deletions imap/http_caldav.c
Expand Up @@ -616,7 +616,7 @@ static void my_caldav_init(struct buf *serverinfo)
static void my_caldav_auth(const char *userid)
{
int r;
char *mailboxname, ident[MAX_MAILBOX_NAME], rights[100];
char *mailboxname, rights[100];
struct buf acl = BUF_INITIALIZER;

if (httpd_userisadmin ||
Expand All @@ -637,9 +637,6 @@ static void my_caldav_auth(const char *userid)

/* Auto-provision calendars for 'userid' */

strlcpy(ident, userid, sizeof(ident));
mboxname_hiersep_toexternal(&httpd_namespace, ident, 0);

/* calendar-home-set */
mailboxname = caldav_mboxname(userid, NULL);
r = mboxlist_lookup(mailboxname, NULL, NULL);
Expand All @@ -652,7 +649,7 @@ static void my_caldav_auth(const char *userid)
r = http_mlookup(inboxname, &mbentry, NULL);
free(inboxname);
if (!r && mbentry->server) {
proxy_findserver(mbentry->server, &http_protocol, proxy_userid,
proxy_findserver(mbentry->server, &http_protocol, httpd_userid,
&backend_cached, NULL, NULL, httpd_in);
mboxlist_entry_free(&mbentry);
free(mailboxname);
Expand All @@ -664,7 +661,7 @@ static void my_caldav_auth(const char *userid)
/* Create locally */
buf_reset(&acl);
cyrus_acl_masktostr(ACL_ALL | DACL_READFB, rights);
buf_printf(&acl, "%s\t%s\t", ident, rights);
buf_printf(&acl, "%s\t%s\t", userid, rights);
cyrus_acl_masktostr(DACL_READFB, rights);
buf_printf(&acl, "%s\t%s\t", "anyone", rights);
r = mboxlist_createsync(mailboxname, MBTYPE_COLLECTION,
Expand All @@ -688,7 +685,7 @@ static void my_caldav_auth(const char *userid)
if (r == IMAP_MAILBOX_NONEXISTENT) {
buf_reset(&acl);
cyrus_acl_masktostr(ACL_ALL | DACL_READFB, rights);
buf_printf(&acl, "%s\t%s\t", ident, rights);
buf_printf(&acl, "%s\t%s\t", userid, rights);
cyrus_acl_masktostr(DACL_READFB, rights);
buf_printf(&acl, "%s\t%s\t", "anyone", rights);
r = mboxlist_createsync(mailboxname, MBTYPE_CALENDAR,
Expand All @@ -712,7 +709,7 @@ static void my_caldav_auth(const char *userid)
if (r == IMAP_MAILBOX_NONEXISTENT) {
buf_reset(&acl);
cyrus_acl_masktostr(ACL_ALL | DACL_SCHED, rights);
buf_printf(&acl, "%s\t%s\t", ident, rights);
buf_printf(&acl, "%s\t%s\t", userid, rights);
cyrus_acl_masktostr(DACL_SCHED, rights);
buf_printf(&acl, "%s\t%s\t", "anyone", rights);
r = mboxlist_createsync(mailboxname, MBTYPE_CALENDAR,
Expand All @@ -733,7 +730,7 @@ static void my_caldav_auth(const char *userid)
if (r == IMAP_MAILBOX_NONEXISTENT) {
buf_reset(&acl);
cyrus_acl_masktostr(ACL_ALL | DACL_SCHED, rights);
buf_printf(&acl, "%s\t%s\t", ident, rights);
buf_printf(&acl, "%s\t%s\t", userid, rights);
r = mboxlist_createsync(mailboxname, MBTYPE_CALENDAR,
NULL /* partition */,
userid, httpd_authstate,
Expand All @@ -755,7 +752,7 @@ static void my_caldav_auth(const char *userid)
if (r == IMAP_MAILBOX_NONEXISTENT) {
buf_reset(&acl);
cyrus_acl_masktostr(ACL_ALL | DACL_SCHED, rights);
buf_printf(&acl, "%s\t%s\t", ident, rights);
buf_printf(&acl, "%s\t%s\t", userid, rights);
cyrus_acl_masktostr(ACL_READ, rights);
buf_printf(&acl, "%s\t%s\t", "anyone", rights);
r = mboxlist_createsync(mailboxname, MBTYPE_COLLECTION,
Expand Down Expand Up @@ -1940,7 +1937,7 @@ static int caldav_get(struct transaction_t *txn, struct mailbox *mailbox,
struct backend *be;

be = proxy_findserver(txn->req_tgt.mbentry->server,
&http_protocol, proxy_userid,
&http_protocol, httpd_userid,
&backend_cached, NULL, NULL, httpd_in);
if (!be) return HTTP_UNAVAILABLE;

Expand Down Expand Up @@ -2464,7 +2461,6 @@ static int caldav_post_outbox(struct transaction_t *txn, int rights)
if (!caladdress_lookup(organizer, &sparam) &&
!(sparam.flags & SCHEDTYPE_REMOTE)) {
strlcpy(orgid, sparam.userid, sizeof(orgid));
mboxname_hiersep_toexternal(&httpd_namespace, orgid, 0);
}
}

Expand Down Expand Up @@ -2521,7 +2517,7 @@ static int caldav_post(struct transaction_t *txn)
struct backend *be;

be = proxy_findserver(txn->req_tgt.mbentry->server,
&http_protocol, proxy_userid,
&http_protocol, httpd_userid,
&backend_cached, NULL, NULL, httpd_in);
if (!be) ret = HTTP_UNAVAILABLE;
else ret = http_pipe_req_resp(be, txn);
Expand Down Expand Up @@ -5393,7 +5389,7 @@ static int meth_get_head_fb(struct transaction_t *txn,
struct backend *be;

be = proxy_findserver(txn->req_tgt.mbentry->server,
&http_protocol, proxy_userid,
&http_protocol, httpd_userid,
&backend_cached, NULL, NULL, httpd_in);
if (!be) return HTTP_UNAVAILABLE;

Expand Down Expand Up @@ -5475,7 +5471,7 @@ static int meth_get_head_fb(struct transaction_t *txn,
memset(&fctx, 0, sizeof(struct propfind_ctx));
fctx.req_tgt = &txn->req_tgt;
fctx.depth = 2;
fctx.userid = proxy_userid;
fctx.userid = httpd_userid;
fctx.userisadmin = httpd_userisadmin;
fctx.authstate = httpd_authstate;
fctx.reqd_privs = 0; /* handled by CALDAV:schedule-deliver on Inbox */
Expand Down
2 changes: 1 addition & 1 deletion imap/http_caldav_sched.c
Expand Up @@ -718,7 +718,7 @@ int sched_busytime_query(struct transaction_t *txn,
memset(&fctx, 0, sizeof(struct propfind_ctx));
fctx.req_tgt = &txn->req_tgt;
fctx.depth = 2;
fctx.userid = proxy_userid;
fctx.userid = httpd_userid;
fctx.userisadmin = httpd_userisadmin;
fctx.authstate = org_authstate;
fctx.reqd_privs = 0; /* handled by CALDAV:schedule-deliver on Inbox */
Expand Down
2 changes: 1 addition & 1 deletion imap/http_carddav.c
Expand Up @@ -403,7 +403,7 @@ static void my_carddav_auth(const char *userid)
r = http_mlookup(inboxname, &mbentry, NULL);
free(inboxname);
if (!r && mbentry->server) {
proxy_findserver(mbentry->server, &http_protocol, proxy_userid,
proxy_findserver(mbentry->server, &http_protocol, httpd_userid,
&backend_cached, NULL, NULL, httpd_in);
mboxlist_entry_free(&mbentry);
goto done;
Expand Down

0 comments on commit 69bfaea

Please sign in to comment.