static void doupdate() { maildir_aclt_list l; char *owner; char buf[2]; char *p; struct maildir_info minfo; if (maildir_info_imap_find(&minfo, sqwebmail_folder, login_returnaddr()) < 0) return; if (acl_read2(&l, &minfo, &owner) < 0) { maildir_info_destroy(&minfo); return; } strcpy(buf, ACL_ADMINISTER); acl_computeRights(&l, buf, owner); if (!*buf) { if (owner) free(owner); maildir_aclt_list_destroy(&l); maildir_info_destroy(&minfo); return; } if (*cgi("delentity")) { if (maildir_aclt_list_del(&l, cgi("delentity"))) printf("%s", getarg("ACL_failed")); } if (*cgi("do.update")) { char *entity=NULL; const char *p; char new_acl[40]; p=cgi("entitytype"); if (strcmp(p, "anonymous") == 0 || strcmp(p, "owner") == 0) entity=strdup(p); else if (strcmp(p, "user") == 0) { p=cgi("entity"); if (*p) { entity=malloc(sizeof("user="******"user="******"group") == 0) { p=cgi("entity"); if (*p) { entity=malloc(sizeof("group=")+strlen(p)); if (entity) strcat(strcpy(entity, "group="), p); } } else { entity=strdup(cgi("entity")); } if (*cgi("negate") == '-' && entity) { char *p=malloc(strlen(entity)+2); if (p) strcat(strcpy(p, "-"), entity); free(entity); entity=p; } if (entity) { char *val= unicode_convert_toutf8(entity, sqwebmail_content_charset, NULL); if (val) { free(entity); entity=val; } } p=getarg("ACL_all"); new_acl[0]=0; while (*p && strlen(new_acl) < sizeof(new_acl)-2) { char b[40]; sprintf(b, "acl_%c", *p); if (*cgi(b)) { b[0]=*p; b[1]=0; strcat(new_acl, b); } ++p; } if (!entity || !*entity || maildir_aclt_list_add(&l, entity, new_acl, NULL) < 0) printf("%s", getarg("ACL_failed")); if (entity) free(entity); } p=maildir_name2dir(".", minfo.maildir); if (p) { const char *err_ident; if (maildir_acl_write(&l, minfo.homedir, strncmp(p, "./", 2) == 0 ? p+2:p, owner, &err_ident)) printf("%s", getarg("ACL_failed")); free(p); } if (owner) free(owner); maildir_aclt_list_destroy(&l); maildir_info_destroy(&minfo); }
int main(int argc, char *argv[]) { const char *cmd; const char *maildir; const char *folder; if (argc < 3) usage(); cmd=argv[1]; if (strcmp(cmd, resetcmd) && strcmp(cmd, listcmd) && strcmp(cmd, setcmd) && strcmp(cmd, deletecmd) && strcmp(cmd, computecmd)) usage(); maildir=argv[2]; if (strcmp(cmd, resetcmd) == 0) { if (maildir_acl_reset(maildir)) { perror(maildir); exit(1); } exit(0); } if (argc < 4) usage(); folder=argv[3]; if (strcmp(folder, INBOX) && strncmp(folder, INBOX ".", sizeof(INBOX ".")-1)) { errno=EINVAL; perror(folder); exit(1); } folder += sizeof(INBOX)-1; if (!*folder) folder="."; if (strcmp(cmd, listcmd) == 0) { maildir_aclt_list l; if (maildir_acl_read(&l, maildir, folder) || maildir_aclt_list_enum(&l, acl_list, NULL)) { perror(maildir); exit(1); } maildir_aclt_list_destroy(&l); exit(0); } if (strcmp(cmd, setcmd) == 0) { maildir_aclt_list l; maildir_aclt a; const char *identifier; const char *rights; const char *err_failedrights; if (argc < 6) usage(); identifier=argv[4]; rights=argv[5]; if (maildir_acl_read(&l, maildir, folder)) { perror(maildir); exit(1); } if (*rights == '+') { if (maildir_aclt_init(&a, NULL, maildir_aclt_list_find(&l, identifier )) || maildir_aclt_add(&a, rights+1, NULL)) { perror(argv[0]); exit(1); } } else if (*rights == '-') { if (maildir_aclt_init(&a, NULL, maildir_aclt_list_find(&l, identifier )) || maildir_aclt_del(&a, rights+1, NULL)) { perror(argv[0]); exit(1); } } else if (maildir_aclt_init(&a, rights, NULL)) { perror(argv[0]); exit (1); } if (maildir_aclt_list_add(&l, identifier, NULL, &a)) { perror(argv[0]); exit(1); } if (maildir_acl_write(&l, maildir, folder, "owner", &err_failedrights)) { if (err_failedrights) { fprintf(stderr, "Trying to set invalid access" " rights for %s\n", err_failedrights); } else perror(maildir); exit(1); } } if (strcmp(cmd, deletecmd) == 0) { maildir_aclt_list l; const char *identifier; const char *err_failedrights; if (argc < 5) usage(); identifier=argv[4]; if (maildir_acl_read(&l, maildir, folder)) { perror(maildir); exit(1); } if (maildir_aclt_list_del(&l, identifier)) { perror(maildir); exit(1); } if (maildir_acl_write(&l, maildir, folder, "owner", &err_failedrights)) { if (err_failedrights) { fprintf(stderr, "Trying to set invalid access" " rights for %s\n", err_failedrights); } else perror(maildir); exit(1); } } if (strcmp(cmd, computecmd) == 0) { maildir_aclt_list l; maildir_aclt a; struct computeinfo ci; ci.argc=argc; ci.argv=argv; if (argc < 5) usage(); if (maildir_acl_read(&l, maildir, folder)) { perror(maildir); exit(1); } if (maildir_acl_compute(&a, &l, isme, &ci)) { perror(maildir); exit(1); } printf("%s\n", maildir_aclt_ascstr(&a)); } return (0); }