Back to index

courier  0.68.2
Classes | Defines | Typedefs | Functions | Variables
maildiraclt.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  maildir_aclt_node
struct  maildir_aclt_list

Defines

#define maildir_aclt_ascstr(t)   (*(t) ? (const char *)*(t):"")
#define ACL_LOOKUP   "l"
#define ACL_READ   "r"
#define ACL_SEEN   "s"
#define ACL_WRITE   "w"
#define ACL_INSERT   "i"
#define ACL_POST   "p"
#define ACL_CREATE   "c"
#define ACL_DELETEFOLDER   "x"
#define ACL_DELETEMSGS   "t"
#define ACL_EXPUNGE   "e"
#define ACL_ADMINISTER   "a"
#define ACL_ALL
#define ACL_DELETE_SPECIAL   "d"
#define ACLFILE   "courierimapacl"
#define ACLHIERDIR   "courierimaphieracl"
#define MAILDIR_ACL_ANYONE(s)

Typedefs

typedef char * maildir_aclt

Functions

int maildir_aclt_init (maildir_aclt *aclt, const char *initvalue_cstr, const maildir_aclt *initvalue_cpy)
void maildir_aclt_destroy (maildir_aclt *aclt)
int maildir_aclt_add (maildir_aclt *aclt, const char *add_strs, const maildir_aclt *add_aclt)
int maildir_aclt_del (maildir_aclt *aclt, const char *del_strs, const maildir_aclt *del_aclt)
void maildir_aclt_list_init (maildir_aclt_list *aclt_list)
void maildir_aclt_list_destroy (maildir_aclt_list *aclt_list)
int maildir_aclt_list_add (maildir_aclt_list *aclt_list, const char *identifier, const char *aclt_str, maildir_aclt *aclt_cpy)
int maildir_aclt_list_del (maildir_aclt_list *aclt_list, const char *identifier)
int maildir_aclt_list_enum (maildir_aclt_list *aclt_list, int(*cb_func)(const char *identifier, const maildir_aclt *acl, void *cb_arg), void *cb_arg)
const maildir_acltmaildir_aclt_list_find (maildir_aclt_list *aclt_list, const char *identifier)
int maildir_acl_read (maildir_aclt_list *aclt_list, const char *maildir, const char *path)
int maildir_acl_write (maildir_aclt_list *aclt_list, const char *maildir, const char *path, const char *owner, const char **err_failedrights)
int maildir_acl_reset (const char *maildir)
int maildir_acl_delete (const char *maildir, const char *path)
int maildir_acl_compute (maildir_aclt *aclt, maildir_aclt_list *aclt_list, int(*cb_func)(const char *identifier, void *void_arg), void *void_arg)
int maildir_acl_compute_array (maildir_aclt *aclt, maildir_aclt_list *aclt_list, const char *const *identifiers)
int maildir_acl_computerights (maildir_aclt *rights, maildir_aclt_list *acl_list, const char *me, const char *folder_owner)
int maildir_acl_canlistrights (const char *myrights)

Variables

int maildir_acl_disabled

Class Documentation

struct maildir_aclt_node

Definition at line 60 of file maildiraclt.h.

Collaboration diagram for maildir_aclt_node:
Class Members
maildir_aclt acl
char * identifier
struct maildir_aclt_node * next
struct maildir_aclt_node * prev
struct maildir_aclt_list

Definition at line 67 of file maildiraclt.h.

Collaboration diagram for maildir_aclt_list:
Class Members
struct maildir_aclt_node * head
struct maildir_aclt_node * tail

Define Documentation

#define ACL_ADMINISTER   "a"

Definition at line 123 of file maildiraclt.h.

#define ACL_ALL
Value:
ACL_ADMINISTER \
       ACL_CREATE \
       ACL_EXPUNGE \
       ACL_INSERT \
       ACL_LOOKUP \
       ACL_READ \
       ACL_SEEN \
       ACL_DELETEMSGS \
       ACL_WRITE \
       ACL_DELETEFOLDER

Definition at line 125 of file maildiraclt.h.

#define ACL_CREATE   "c"

Definition at line 119 of file maildiraclt.h.

#define ACL_DELETE_SPECIAL   "d"

Definition at line 137 of file maildiraclt.h.

#define ACL_DELETEFOLDER   "x"

Definition at line 120 of file maildiraclt.h.

#define ACL_DELETEMSGS   "t"

Definition at line 121 of file maildiraclt.h.

#define ACL_EXPUNGE   "e"

Definition at line 122 of file maildiraclt.h.

#define ACL_INSERT   "i"

Definition at line 117 of file maildiraclt.h.

#define ACL_LOOKUP   "l"

Definition at line 113 of file maildiraclt.h.

#define ACL_POST   "p"

Definition at line 118 of file maildiraclt.h.

#define ACL_READ   "r"

Definition at line 114 of file maildiraclt.h.

#define ACL_SEEN   "s"

Definition at line 115 of file maildiraclt.h.

#define ACL_WRITE   "w"

Definition at line 116 of file maildiraclt.h.

#define ACLFILE   "courierimapacl"

Definition at line 139 of file maildiraclt.h.

#define ACLHIERDIR   "courierimaphieracl"

Definition at line 140 of file maildiraclt.h.

#define MAILDIR_ACL_ANYONE (   s)
Value:
(strcmp( (s), "anonymous") == 0 || \
        strcmp( (s), "anyone") == 0)

Definition at line 143 of file maildiraclt.h.

#define maildir_aclt_ascstr (   t)    (*(t) ? (const char *)*(t):"")

Definition at line 55 of file maildiraclt.h.


Typedef Documentation

typedef char* maildir_aclt

Definition at line 26 of file maildiraclt.h.


Function Documentation

int maildir_acl_canlistrights ( const char *  myrights)

Definition at line 1165 of file maildiraclt.c.

{
       return (strchr(myrights, ACL_LOOKUP[0]) ||
              strchr(myrights, ACL_READ[0]) ||
              strchr(myrights, ACL_INSERT[0]) ||
              strchr(myrights, ACL_CREATE[0]) ||
              strchr(myrights, ACL_DELETEFOLDER[0]) ||
              strchr(myrights, ACL_EXPUNGE[0]) ||
              strchr(myrights, ACL_ADMINISTER[0]));
}

Here is the caller graph for this function:

int maildir_acl_compute ( maildir_aclt aclt,
maildir_aclt_list aclt_list,
int(*)(const char *identifier, void *void_arg)  cb_func,
void *  void_arg 
)
int maildir_acl_compute_array ( maildir_aclt aclt,
maildir_aclt_list aclt_list,
const char *const *  identifiers 
)

Definition at line 1144 of file maildiraclt.c.

{
       return maildir_acl_compute(aclt, aclt_list, chk_array,
                               (void *)identifiers);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_acl_computerights ( maildir_aclt rights,
maildir_aclt_list acl_list,
const char *  me,
const char *  folder_owner 
)

Definition at line 1257 of file maildiraclt.c.

{
       char **owner_array;
       size_t owner_cnt;
       char **p;
       int rc;

       owner_cnt=1;

       if (get_owner_list(count_owner_list, me, folder_owner,
                        (void *)&owner_cnt) ||
           (owner_array=calloc(owner_cnt, sizeof(char *))) == NULL)
              return -1;

       p=owner_array;

       if (get_owner_list(save_owner_list, me, folder_owner, (void *)&p))
       {
              for (owner_cnt=0; owner_array[owner_cnt]; ++owner_cnt)
                     free(owner_array[owner_cnt]);
              free(owner_array);
              return -1;
       }

       rc=maildir_acl_compute_array(rights, acl_list,
                                 (const char * const *)owner_array);

       for (owner_cnt=0; owner_array[owner_cnt]; ++owner_cnt)
              free(owner_array[owner_cnt]);
       free(owner_array);
       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_acl_delete ( const char *  maildir,
const char *  path 
)

Definition at line 580 of file maildiraclt.c.

{
       char *p, *q;

#if 0
       if (strcmp(path, SHARED) == 0)
              return 0;

       if (strncmp(path, SHARED ".", sizeof(SHARED)) == 0)
              return 0;
#endif
       if (!maildir || !*maildir)
              maildir=".";
       if (!path || !*path)
              path=".";

       if (strchr(path, '/') || *path != '.')
       {
              errno=EINVAL;
              return -1;
       }

       p=malloc(strlen(maildir)+strlen(path)+2);

       if (!p)
              return -1;

       strcat(strcat(strcpy(p, maildir), "/"), path);

       q=malloc(strlen(p)+sizeof("/" ACLFILE));
       if (!q)
       {
              free(p);
              return -1;
       }

       unlink(strcat(strcpy(q, p), "/" ACLFILE));
       free(p);
       free(q);

       if (strcmp(path, ".") == 0)
       {
              /* INBOX ACL default */

              return 0;
       }

       q=malloc(strlen(maildir)+sizeof("/" ACLHIERDIR "/") +
               strlen(path));
       if (!q)
       {
              free(p);
              return -1;
       }
       strcat(strcat(strcpy(q, maildir), "/" ACLHIERDIR "/"),
              path+1);

       unlink(q);
       free(q);
       return 0;
}

Here is the caller graph for this function:

int maildir_acl_read ( maildir_aclt_list aclt_list,
const char *  maildir,
const char *  path 
)

Definition at line 332 of file maildiraclt.c.

{
       int rc=maildir_acl_read_check(aclt_list, maildir, path);
       char *p, *q;

       if (rc)
              maildir_aclt_list_destroy(aclt_list);

       if (rc <= 0)
              return rc;

       /*
       ** If the ACL config file for this folder was not found,
       ** check for the ACL config file for its parent folder.
       */

       if ((p=strdup(path)) == NULL)
              return -1;

       strcpy(p, path);

       q=strrchr(p, '.');

       if (!q)
       {
              free(p);
              errno=EIO; /* Should not happen */
              return -1;
       }

       *q=0;

       rc=maildir_acl_read(aclt_list, maildir, p);
       if (rc == 0)
       {
              /* Make sure to save the default acl list */

              rc=maildir_acl_write(aclt_list, maildir, path, NULL, NULL);
              if (rc >= 0) /* Ok if rc=1 */
                     rc=0;
              if (rc)
                     maildir_aclt_list_destroy(aclt_list);
       }
       free(p);
       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_acl_reset ( const char *  maildir)

Definition at line 942 of file maildiraclt.c.

{
       DIR *dirp;
       struct dirent *de;
       char *p;
       struct maildir_acl_resetList *rl=NULL;
       struct maildir_acl_resetList *r;
       time_t now;
       struct stat stat_buf;

       p=malloc(strlen(maildir) + sizeof("/" ACLHIERDIR));
       if (!p)
              return -1;

       strcat(strcpy(p, maildir), "/" ACLHIERDIR);

       dirp=opendir(p);

       if (!dirp)
       {
              mkdir(p, 0755);
              dirp=opendir(p);
       }
       free(p);

       while (dirp && (de=readdir(dirp)) != NULL)
       {
              if (de->d_name[0] == '.')
                     continue;

              if ((r=malloc(sizeof(struct maildir_acl_resetList))) == NULL
                  || (r->mbox=strdup(de->d_name)) == NULL)
              {
                     if (r)
                            free(r);

                     while (rl)
                     {
                            r=rl;
                            rl=r->next;
                            free(r->mbox);
                            free(r);
                     }
                     closedir(dirp);
                     return -1;
              }

              r->next=rl;
              rl=r;
       }
       if (dirp) closedir(dirp);

       maildir_list(maildir, acl_check_cb, &rl);

       time(&now);

       while (rl)
       {
              r=rl;
              rl=r->next;

              p=malloc(strlen(maildir)+strlen(r->mbox) +
                      sizeof("/" ACLHIERDIR "/"));
              if (p)
              {
                     strcat(strcat(strcpy(p, maildir),
                                  "/" ACLHIERDIR "/"), r->mbox);

                     /* Only unlink stale entries after 1 hour (race) */

                     if (stat(p, &stat_buf) == 0 &&
                         stat_buf.st_mtime < now - 60*60)
                            unlink(p);
                     free(p);
              }
              free(r->mbox);
              free(r);
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_acl_write ( maildir_aclt_list aclt_list,
const char *  maildir,
const char *  path,
const char *  owner,
const char **  err_failedrights 
)

Definition at line 700 of file maildiraclt.c.

{
       int trycreate;
       struct maildir_tmpcreate_info tci;
       FILE *fp;
       char *p, *q;
       const char *dummy_string;
       maildir_aclt chkacls;

       if (!err_failedrights)
              err_failedrights= &dummy_string;

       if (!maildir || !*maildir)
              maildir=".";
       if (!path || !*path)
              path=".";

       if (strchr(path, '/') || *path != '.')
       {
              errno=EINVAL;
              return -1;
       }

       if (strcmp(path, ".")) /* Sanity check */
              for (dummy_string=path; *dummy_string; dummy_string++)
                     if (*dummy_string == '.' &&
                         (dummy_string[1] == '.' ||
                          dummy_string[1] == 0))
                     {
                            errno=EINVAL;
                            return -1;
                     }


       if (maildir_acl_compute_chkowner(&chkacls, aclt_list, is_owner, NULL,
                                    0))
       {
              maildir_aclt_destroy(&chkacls);
              errno=EINVAL;
              return -1;
       }

       if (check_adminrights(&chkacls))
       {
              *err_failedrights="owner";
              errno=EINVAL;
              return -1;
       }

       if (owner)
       {
              if (maildir_acl_compute_chkowner(&chkacls, aclt_list, is_owner,
                                           (void *)owner, 0))
              {
                     maildir_aclt_destroy(&chkacls);
                     errno=EINVAL;
                     return -1;
              }
              if (check_adminrights(&chkacls))
              {
                     *err_failedrights=owner;
                     errno=EINVAL;
                     return -1;
              }
       }

       if (maildir_acl_compute(&chkacls, aclt_list, is_admin, NULL))
       {
              maildir_aclt_destroy(&chkacls);
              errno=EINVAL;
              return -1;
       }
       if (check_allrights(&chkacls))
       {
              errno=EINVAL;
              return -1;
       }

       p=malloc(strlen(maildir)+strlen(path)+2);

       if (!p)
              return -1;

       strcat(strcat(strcpy(p, maildir), "/"), path);

       maildir_tmpcreate_init(&tci);

       tci.maildir=p;
       tci.uniq="acl";
       tci.doordie=1;

       fp=maildir_tmpcreate_fp(&tci);

       trycreate=0;

       if (fp)
       {
              q=malloc(strlen(p) + sizeof("/" ACLFILE));
              if (!q)
              {
                     fclose(fp);
                     unlink(tci.tmpname);
                     maildir_tmpcreate_free(&tci);
                     free(p);
                     return -1;
              }
              strcat(strcpy(q, p), "/" ACLFILE);
              free(tci.newname);
              tci.newname=q;
              free(p);
       }
       else
       {
              free(p);

              q=malloc(strlen(maildir)+sizeof("/" ACLHIERDIR "/") +
                      strlen(path));
              if (!q)
              {
                     maildir_tmpcreate_free(&tci);
                     return -1;
              }
              strcat(strcat(strcpy(q, maildir), "/" ACLHIERDIR "/"), path+1);

              tci.maildir=maildir;
              tci.uniq="acl";
              tci.doordie=1;

              fp=maildir_tmpcreate_fp(&tci);

              if (!fp)
              {
                     free(q);
                     maildir_tmpcreate_free(&tci);
                     return -1;
              }
              free(tci.newname);
              tci.newname=q;
              trycreate=1;
       }

       if (maildir_aclt_list_enum(aclt_list, save_acl, fp) < 0 ||
           ferror(fp) || fflush(fp) < 0)
       {
              fclose(fp);
              unlink(tci.tmpname);
              maildir_tmpcreate_free(&tci);
              return -1;
       }
       fclose(fp);

       if (rename(tci.tmpname, tci.newname) < 0)
       {
              /* Perhaps ACLHIERDIR needs to be created? */

              if (!trycreate)
              {
                     unlink(tci.tmpname);
                     maildir_tmpcreate_free(&tci);
                     return -1;
              }

              p=strrchr(tci.newname, '/');
              *p=0;
              mkdir(tci.newname, 0755);
              *p='/';

              if (rename(tci.tmpname, tci.newname) < 0)
              {
                     unlink(tci.tmpname);
                     maildir_tmpcreate_free(&tci);
                     return -1;
              }
       }
       maildir_tmpcreate_free(&tci);
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_aclt_add ( maildir_aclt aclt,
const char *  add_strs,
const maildir_aclt add_aclt 
)

Definition at line 113 of file maildiraclt.c.

{
       if (add_aclt)
              add_strs= *add_aclt;

       if (!add_strs || !*add_strs)
              return 0;

       if (validacl(add_strs) < 0)
              return -1;

       if (*aclt)
       {
              char *p=realloc(*aclt, strlen(*aclt)+strlen(add_strs)+1);

              if (!p)
                     return -1;
              strcat(p, add_strs);
              *aclt=p;

       }
       else if ( ((*aclt)=strdup(add_strs)) == NULL)
              return -1;

       fixup(aclt);
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_aclt_del ( maildir_aclt aclt,
const char *  del_strs,
const maildir_aclt del_aclt 
)

Definition at line 143 of file maildiraclt.c.

{
       char *a, *b;

       if (del_aclt)
              del_strs= *del_aclt;

       if (!del_strs)
              return 0;

       if (!*aclt)
              return 0;

       for (a=b=*aclt; *a; a++)
       {
              if (strchr(del_strs, *a))
                     continue;
              *b++= *a;
       }
       *b=0;

       if (**aclt == 0)
       {
              free(*aclt);
              *aclt=NULL;
       }
       return 0;
}

Here is the caller graph for this function:

Definition at line 104 of file maildiraclt.c.

{
       if (*aclt)
              free(*aclt);
}

Here is the caller graph for this function:

int maildir_aclt_init ( maildir_aclt aclt,
const char *  initvalue_cstr,
const maildir_aclt initvalue_cpy 
)

Definition at line 81 of file maildiraclt.c.

{
       if (initvalue_cpy)
              initvalue_cstr= *initvalue_cpy;

       *aclt=NULL;

       if (!initvalue_cstr || !*initvalue_cstr)
              return 0;

       if (validacl(initvalue_cstr) < 0)
              return -1;

       if ( (*aclt=strdup(initvalue_cstr)) == NULL)
              return -1;
       fixup(aclt);
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_aclt_list_add ( maildir_aclt_list aclt_list,
const char *  identifier,
const char *  aclt_str,
maildir_aclt aclt_cpy 
)

Definition at line 202 of file maildiraclt.c.

{
       struct maildir_aclt_node *p;
       const char *q;

       /* Check for valid identifiers */

       for (q=identifier; *q; q++)
              if ( (int)(unsigned char)*q <= ' ')
              {
                     errno=EINVAL;
                     return -1;
              }

       if (*identifier == 0)
       {
              errno=EINVAL;
              return -1;
       }

       if (aclt_cpy && *aclt_cpy)
              aclt_str= *aclt_cpy;

       for (p=aclt_list->head; p; p=p->next)
       {
              if (strcmp(p->identifier, identifier) == 0)
              {
                     maildir_aclt_destroy(&p->acl);
                     return maildir_aclt_init(&p->acl, aclt_str, NULL);
              }
       }

       if ((p=malloc(sizeof(*p))) == NULL ||
           (p->identifier=strdup(identifier)) == NULL)
       {
              if (p) free(p);
              return -1;
       }

       if (maildir_aclt_init(&p->acl, aclt_str, NULL) < 0)
       {
              free(p->identifier);
              free(p);
              return -1;
       }

       p->next=NULL;
       if ((p->prev=aclt_list->tail) != NULL)
              p->prev->next=p;
       else
              aclt_list->head=p;
       aclt_list->tail=p;
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_aclt_list_del ( maildir_aclt_list aclt_list,
const char *  identifier 
)

Definition at line 264 of file maildiraclt.c.

{
       struct maildir_aclt_node *p;

       for (p=aclt_list->head; p; p=p->next)
       {
              if (strcmp(p->identifier, identifier) == 0)
              {
                     if (p->prev)
                            p->prev->next=p->next;
                     else aclt_list->head=p->next;

                     if (p->next)
                            p->next->prev=p->prev;
                     else aclt_list->tail=p->prev;

                     maildir_aclt_destroy(&p->acl);
                     free(p->identifier);
                     free(p);
                     return 0;
              }
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 183 of file maildiraclt.c.

{
       struct maildir_aclt_node *p;

       for (p=aclt_list->head; p; )
       {
              struct maildir_aclt_node *q=p->next;

              free(p->identifier);
              maildir_aclt_destroy(&p->acl);
              free(p);
              p=q;
       }
       maildir_aclt_list_init(aclt_list);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_aclt_list_enum ( maildir_aclt_list aclt_list,
int(*)(const char *identifier, const maildir_aclt *acl, void *cb_arg)  cb_func,
void *  cb_arg 
)

Definition at line 294 of file maildiraclt.c.

{
       struct maildir_aclt_node *p;
       int rc;

       for (p=aclt_list->head; p; p=p->next)
       {
              rc= (*cb_func)(p->identifier, &p->acl, cb_arg);

              if (rc)
                     return rc;
       }
       return 0;
}

Here is the caller graph for this function:

const maildir_aclt* maildir_aclt_list_find ( maildir_aclt_list aclt_list,
const char *  identifier 
)

Definition at line 313 of file maildiraclt.c.

{
       struct maildir_aclt_node *p;

       for (p=aclt_list->head; p; p=p->next)
       {
              if (strcmp(p->identifier, identifier) == 0)
                     return &p->acl;
       }
       return NULL;
}

Here is the caller graph for this function:

Definition at line 177 of file maildiraclt.c.

{
       aclt_list->head=NULL;
       aclt_list->tail=NULL;
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 36 of file maildiraclt.c.