--- imapfilter/account.c 2004/02/11 00:03:46 1.8 +++ imapfilter/account.c 2004/02/13 23:44:50 1.11 @@ -3,7 +3,7 @@ #include #include #include -#include /* IEEE Std 1003.1-2001 non-conformance. */ +#include /* For POSIX.1-2001 non-conformant systems. */ #include #include "config.h" @@ -12,21 +12,21 @@ #include "struct.h" -extern opts_t opts; +extern options_t opts; extern unsigned int flags; account_t *accounts = NULL; /* First node of accounts linked list. */ mboxgrp_t *mboxgrps = NULL; /* First node of mailbox-groups tree. */ -account_t *cur_acct = NULL; /* Current account. */ +account_t *curacct = NULL; /* Current account. */ -void init_account(account_t * node); +void init_account(account_t * a); -void init_mboxgrp(mboxgrp_t * node); -void process_mboxgrp(mboxgrp_t * node, char *mboxs); +void init_mboxgrp(mboxgrp_t * g); +void process_mboxgrp(mboxgrp_t * g, char *mboxs); -void init_mbox(mbox_t * node); +void init_mbox(mbox_t * m); mbox_t *set_mbox(char *name); int string_decode(char *str); @@ -36,15 +36,18 @@ * Set new account's variables to safe values. */ void -init_account(account_t * node) +init_account(account_t * a) { - node->next = NULL; - node->key[0] = node->server[0] = '\0'; - node->username[0] = node->password[0] = '\0'; - node->passwdattr = PASSWORD_NONE; - node->port = 143; - node->ssl = SSL_DISABLED; - node->mboxes = NULL; + + a->next = NULL; + a->key[0] = '\0'; + a->server[0] = '\0'; + a->user[0] = '\0'; + a->pass[0] = '\0'; + a->pass_attr = PASS_ATTR_NONE; + a->port = 143; + a->ssl = SSL_DISABLED; + a->mboxes = NULL; } @@ -57,70 +60,70 @@ { int n; char p[6]; - account_t *node; + account_t *a; - node = (account_t *) xmalloc(sizeof(account_t)); - node->password = (char *)smalloc(PASSWORD_LEN); + a = (account_t *) xmalloc(sizeof(account_t)); + a->pass = (char *)smalloc(PASS_LEN); - init_account(node); + init_account(a); - strncat(node->key, line + m[1].rm_so, - min(m[1].rm_eo - m[1].rm_so, KEY_LEN - 1)); + strncat(a->key, line + m[1].rm_so, min(m[1].rm_eo - m[1].rm_so, + KEY_LEN - 1)); - debug("ACCOUNT: '%s'\n", node->key); + debug("account: '%s'\n", a->key); - if (m[3].rm_so != -1) { - strncat(node->username, line + m[3].rm_so, - min(m[3].rm_eo - m[3].rm_so, USERNAME_LEN - 1)); - } else { - strncat(node->username, line + m[5].rm_so, - min(m[5].rm_eo - m[5].rm_so, USERNAME_LEN - 1)); - } - if (strchr(node->username, '%')) - if (string_decode(node->username)) - return ERROR_CONFIG_PARSE; + if (m[3].rm_so != -1) + strncat(a->user, line + m[3].rm_so, + min(m[3].rm_eo - m[3].rm_so, USER_LEN - 1)); + else + strncat(a->user, line + m[5].rm_so, + min(m[5].rm_eo - m[5].rm_so, USER_LEN - 1)); - debug("USERNAME: '%s'\n", node->username); + if (strchr(a->user, '%')) + if (string_decode(a->user)) + return ERROR_PARSER; + + debug("username: '%s'\n", a->user); if (m[4].rm_so != -1) { - strncat(node->password, line + m[4].rm_so, - min(m[4].rm_eo - m[4].rm_so, PASSWORD_LEN - 1)); - if (strchr(node->password, '%')) - if (string_decode(node->password)) - return ERROR_CONFIG_PARSE; - node->passwdattr = PASSWORD_PLAIN; + strncat(a->pass, line + m[4].rm_so, + min(m[4].rm_eo - m[4].rm_so, PASS_LEN - 1)); + if (strchr(a->pass, '%')) + if (string_decode(a->pass)) + return ERROR_PARSER; + a->pass_attr = PASS_ATTR_PLAIN; if (opts.debug == 1) - debug("PASSWORD: *\n"); + debug("password: *\n"); else - debug("PASSWORD: '%s'\n", node->password); + debug("password: '%s'\n", a->pass); } else - flags |= FLAG_BLANK_PASSWORD; + flags |= FLAG_BLANKPASS; - strncat(node->server, line + m[6].rm_so, + strncat(a->server, line + m[6].rm_so, min(m[6].rm_eo - m[6].rm_so, SERVER_LEN - 1)); - debug("SERVER: '%s'\n", node->server); + debug("server: '%s'\n", a->server); if (m[7].rm_so != -1) { n = min(m[7].rm_eo - m[7].rm_so - 1, 5); xstrncpy(p, line + m[7].rm_so + 1, n); p[n] = '\0'; - node->port = strtoul(p, NULL, 10); - debug("PORT: %d\n", node->port); + a->port = strtoul(p, NULL, 10); + debug("port: %d\n", a->port); } if (m[8].rm_so != -1) { if (m[7].rm_so == -1) - node->port = 993; + a->port = 993; if (strcasestr(line + m[8].rm_so, "SSL2")) - node->ssl = SSL_SSL_V2; + a->ssl = SSL_SSL_V2; else if (strcasestr(line + m[8].rm_so, "SSL3")) - node->ssl = SSL_SSL_V3; + a->ssl = SSL_SSL_V3; else - node->ssl = SSL_TLS_V1; + a->ssl = SSL_TLS_V1; } - APPEND_LINKED_LIST(accounts, node, account); - cur_acct = node; + APPEND_LINKED_LIST(accounts, a, account); + curacct = a; return 0; } @@ -136,10 +139,11 @@ account_t *a; for (a = accounts; a != NULL; a = a->next) - if (a->passwdattr == PASSWORD_NONE && - !strcmp(a->server, serv) && !strcmp(a->username, user)) { - a->passwdattr = PASSWORD_ENCRYPTED; - return a->password; + if (a->pass_attr == PASS_ATTR_NONE && + !strcmp(a->server, serv) && + !strcmp(a->user, user)) { + a->pass_attr = PASS_ATTR_CRYPT; + return a->pass; } return NULL; } @@ -150,11 +154,12 @@ * Set new mailbox-group's variables to safe values. */ void -init_mboxgrp(mboxgrp_t * node) +init_mboxgrp(mboxgrp_t * g) { - node->left = node->right = NULL; - node->key[0] = '\0'; - node->mboxes[0] = NULL; + + g->left = g->right = NULL; + g->key[0] = '\0'; + g->mboxes[0] = NULL; } @@ -165,29 +170,29 @@ int set_mboxgrp(char *line, regmatch_t * m) { - mboxgrp_t *node; + mboxgrp_t *g; char mboxs[LINE_MAX]; mboxs[0] = '\0'; if (accounts == NULL) - return ERROR_CONFIG_PARSE; + return ERROR_PARSER; - node = (mboxgrp_t *) xmalloc(sizeof(mboxgrp_t)); + g = (mboxgrp_t *) xmalloc(sizeof(mboxgrp_t)); - init_mboxgrp(node); + init_mboxgrp(g); - strncat(node->key, line + m[1].rm_so, - min(m[1].rm_eo - m[1].rm_so, KEY_LEN - 1)); + strncat(g->key, line + m[1].rm_so, min(m[1].rm_eo - m[1].rm_so, + KEY_LEN - 1)); - debug("FOLDER: '%s'\n", node->key); + debug("folder: '%s'\n", g->key); - strncat(mboxs, line + m[2].rm_so, - min(m[2].rm_eo - m[2].rm_so, LINE_MAX - 1)); + strncat(mboxs, line + m[2].rm_so, min(m[2].rm_eo - m[2].rm_so, + LINE_MAX - 1)); - process_mboxgrp(node, mboxs); + process_mboxgrp(g, mboxs); - INSERT_TREE(mboxgrps, node, mboxgrp); + INSERT_TREE(mboxgrps, g, mboxgrp); return 0; } @@ -198,7 +203,7 @@ * the mailbox-group. */ void -process_mboxgrp(mboxgrp_t * node, char *mboxs) +process_mboxgrp(mboxgrp_t * g, char *mboxs) { unsigned int i; char *tok; @@ -207,8 +212,8 @@ tok = strtok_r(mboxs, ",", &mboxs); while (i < MBOXGRP_MBOXES_MAX - 1 && tok != NULL) { - node->mboxes[i] = (mbox_t *) set_mbox(tok); - node->mboxes[++i] = NULL; + g->mboxes[i] = (mbox_t *) set_mbox(tok); + g->mboxes[++i] = NULL; tok = strtok_r(NULL, ",", &mboxs); } @@ -219,11 +224,12 @@ * Set new mailbox's variables to safe values. */ void -init_mbox(mbox_t * node) +init_mbox(mbox_t * m) { - node->next = NULL; - node->name[0] = '\0'; - node->filters[0] = NULL; + + m->next = NULL; + m->name[0] = '\0'; + m->filters[0] = NULL; } @@ -233,31 +239,31 @@ mbox_t * set_mbox(char *name) { - char s[MBOX_NAME_LEN]; - mbox_t *node, *m; + char s[MBOX_LEN]; + mbox_t *m, *am; *s = '\0'; if (*name == '"' && *(name + strlen(name) - 1) == '"') - strncat(s, name + 1, min(strlen(name) - 2, MBOX_NAME_LEN - 1)); + strncat(s, name + 1, min(strlen(name) - 2, MBOX_LEN - 1)); else - strncat(s, name, min(strlen(name), MBOX_NAME_LEN - 1)); + strncat(s, name, min(strlen(name), MBOX_LEN - 1)); - for (m = cur_acct->mboxes; m != NULL; m = m->next) - if (!strcmp(m->name, s)) - return m; + for (am = curacct->mboxes; am != NULL; am = am->next) + if (!strcmp(am->name, s)) + return am; - node = (mbox_t *) xmalloc(sizeof(mbox_t)); + m = (mbox_t *) xmalloc(sizeof(mbox_t)); - init_mbox(node); + init_mbox(m); - strncat(node->name, s, MBOX_NAME_LEN - 1); + strncat(m->name, s, MBOX_LEN - 1); - debug("MBOX: '%s'\n", node->name); + debug("mbox: '%s'\n", m->name); - APPEND_LINKED_LIST(cur_acct->mboxes, node, mbox); + APPEND_LINKED_LIST(curacct->mboxes, m, mbox); - return node; + return m; } @@ -278,14 +284,14 @@ if (*c == '%') { if (!isxdigit((unsigned char)(*(c + 1))) || !isxdigit((unsigned char)(*(c + 2)))) - return ERROR_CONFIG_PARSE; + return ERROR_PARSER; xstrncpy(hex, ++c, 2); hex[2] = '\0'; if (!isprint((unsigned char)(*str = (char)strtoul(hex, NULL, 16)))) - return ERROR_CONFIG_PARSE; + return ERROR_PARSER; str++; c += 2; @@ -305,7 +311,7 @@ char * apply_namespace(char *mbox, char *prefix, char delim) { - static char m[MBOX_NAME_LEN]; + static char m[MBOX_LEN]; char *c; if ((prefix[0] == '\0' && delim == '\0') || @@ -314,14 +320,14 @@ return mbox; m[0] = '\0'; - strncat(m, prefix, MBOX_NAME_LEN - 1); - strncat(m, mbox, MBOX_NAME_LEN - strlen(m) - 1); + strncat(m, prefix, NAMESPACE_PREFIX_LEN - 1); + strncat(m, mbox, MBOX_LEN - strlen(m) - 1); c = m; while ((c = strchr(c, '/'))) *(c++) = delim; - debug("MAILBOX: '%s'\n", m); + debug("mailbox: '%s'\n", m); return m; }