From: Timo Sirainen Date: Mon, 26 May 2008 23:09:47 +0000 (+0300) Subject: Avoid using shadow variables. Unfortunately -Wshadow also complains about X-Git-Tag: 1.1.rc6~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b8d232d88018c5cafd2f3be5a181d318137a45f2;p=thirdparty%2Fdovecot%2Fcore.git Avoid using shadow variables. Unfortunately -Wshadow also complains about index variable conflicting with index(), which is used in way too many places to change. --HG-- branch : HEAD --- diff --git a/src/auth/auth-master-listener.c b/src/auth/auth-master-listener.c index 6bf313168b..0d6b82c947 100644 --- a/src/auth/auth-master-listener.c +++ b/src/auth/auth-master-listener.c @@ -40,16 +40,16 @@ struct auth_master_listener *auth_master_listener_create(struct auth *auth) } static void -auth_master_listener_socket_free(struct auth_master_listener_socket *socket) +auth_master_listener_socket_free(struct auth_master_listener_socket *s) { - if (socket->path != NULL) { - (void)unlink(socket->path); - i_free(socket->path); + if (s->path != NULL) { + (void)unlink(s->path); + i_free(s->path); } - io_remove(&socket->io); - net_disconnect(socket->fd); - i_free(socket); + io_remove(&s->io); + net_disconnect(s->fd); + i_free(s); } void auth_master_listener_destroy(struct auth_master_listener *listener) diff --git a/src/auth/db-passwd-file.c b/src/auth/db-passwd-file.c index ccf8a2543a..f9d6015451 100644 --- a/src/auth/db-passwd-file.c +++ b/src/auth/db-passwd-file.c @@ -385,15 +385,12 @@ db_passwd_file_lookup(struct db_passwd_file *db, struct auth_request *request) struct passwd_file *pw; struct passwd_user *pu; const struct var_expand_table *table; - string_t *username; + string_t *username, *dest; const char *path; if (!db->vars) pw = db->default_file; else { - const struct var_expand_table *table; - string_t *dest; - table = auth_request_get_var_expand_table(request, path_fix); dest = t_str_new(256); var_expand(dest, db->path, table); diff --git a/src/auth/userdb-nss.c b/src/auth/userdb-nss.c index 3b750a74ab..acc2f4976b 100644 --- a/src/auth/userdb-nss.c +++ b/src/auth/userdb-nss.c @@ -130,13 +130,13 @@ userdb_nss_preinit(struct auth_userdb *auth_userdb, const char *args) static void userdb_nss_deinit(struct userdb_module *_module) { struct nss_userdb_module *module = (struct nss_userdb_module *)_module; - void (*endpwent)(void); + void (*mod_endpwent)(void); + const char *symbol; - endpwent = module_get_symbol(&module->nss_module, - t_strdup_printf("_nss_%s_endpwent", - module->nss_module.name)); - if (endpwent != NULL) - endpwent(); + symbol = t_strdup_printf("_nss_%s_endpwent", module->nss_module.name); + mod_endpwent = module_get_symbol(&module->nss_module, symbol); + if (mod_endpwent != NULL) + mod_endpwent(); } struct userdb_module_interface userdb_nss = { diff --git a/src/deliver/auth-client.c b/src/deliver/auth-client.c index 8a82344a85..90bb612d2d 100644 --- a/src/deliver/auth-client.c +++ b/src/deliver/auth-client.c @@ -95,7 +95,7 @@ static void auth_parse_input(struct auth_connection *conn, const char *args) const char *const *tmp, *extra_groups; uid_t uid = 0; gid_t gid = 0; - const char *chroot = getenv("MAIL_CHROOT"); + const char *chroot_dir = getenv("MAIL_CHROOT"); const char *home_dir = NULL; bool debug = getenv("DEBUG") != NULL; unsigned int len; @@ -121,7 +121,7 @@ static void auth_parse_input(struct auth_connection *conn, const char *args) return_value = EX_TEMPFAIL; } } else if (strncmp(*tmp, "chroot=", 7) == 0) { - chroot = *tmp + 7; + chroot_dir = *tmp + 7; } else { char *field = i_strdup(*tmp); @@ -162,15 +162,15 @@ static void auth_parse_input(struct auth_connection *conn, const char *args) if (conn->euid == 0 || getegid() != gid) env_put(t_strconcat("RESTRICT_SETGID=", dec2str(gid), NULL)); - if (chroot != NULL) { - len = strlen(chroot); - if (len > 2 && strcmp(chroot + len - 2, "/.") == 0 && + if (chroot_dir != NULL) { + len = strlen(chroot_dir); + if (len > 2 && strcmp(chroot_dir + len - 2, "/.") == 0 && home_dir != NULL && - strncmp(home_dir, chroot, len - 2) == 0) { + strncmp(home_dir, chroot_dir, len - 2) == 0) { /* strip chroot dir from home dir */ home_dir += len - 2; } - env_put(t_strconcat("RESTRICT_CHROOT=", chroot, NULL)); + env_put(t_strconcat("RESTRICT_CHROOT=", chroot_dir, NULL)); } if (home_dir != NULL) env_put(t_strconcat("HOME=", home_dir, NULL)); diff --git a/src/deliver/deliver.c b/src/deliver/deliver.c index 7052305eb6..289ef837d3 100644 --- a/src/deliver/deliver.c +++ b/src/deliver/deliver.c @@ -711,7 +711,7 @@ int main(int argc, char *argv[]) const char *config_path = DEFAULT_CONFIG_FILE; const char *mailbox = "INBOX"; const char *auth_socket; - const char *home, *destaddr, *user, *value, *error; + const char *home, *destaddr, *user, *value, *errstr; ARRAY_TYPE(string) extra_fields; struct mail_namespace *ns, *raw_ns; struct mail_storage *storage; @@ -938,8 +938,8 @@ int main(int argc, char *argv[]) raw_ns = mail_namespaces_init_empty(namespace_pool); raw_ns->flags |= NAMESPACE_FLAG_INTERNAL; if (mail_storage_create(raw_ns, "raw", "/tmp", user, - 0, FILE_LOCK_METHOD_FCNTL, &error) < 0) - i_fatal("Couldn't create internal raw storage: %s", error); + 0, FILE_LOCK_METHOD_FCNTL, &errstr) < 0) + i_fatal("Couldn't create internal raw storage: %s", errstr); input = create_raw_stream(0, &mtime); box = mailbox_open(raw_ns->storage, "Dovecot Delivery Mail", input, MAILBOX_OPEN_NO_INDEX_FILES); @@ -991,7 +991,6 @@ int main(int argc, char *argv[]) if (ret < 0 ) { const char *error_string; enum mail_error error; - int ret; if (storage == NULL) { /* This shouldn't happen */ diff --git a/src/deliver/duplicate.c b/src/deliver/duplicate.c index 34d9cca044..846d46d55c 100644 --- a/src/deliver/duplicate.c +++ b/src/deliver/duplicate.c @@ -245,7 +245,7 @@ int duplicate_check(const void *id, size_t id_size, const char *user) } void duplicate_mark(const void *id, size_t id_size, - const char *user, time_t time) + const char *user, time_t timestamp) { struct duplicate *d; void *new_id; @@ -260,7 +260,7 @@ void duplicate_mark(const void *id, size_t id_size, d->id = new_id; d->id_size = id_size; d->user = p_strdup(duplicate_file->pool, user); - d->time = time; + d->time = timestamp; duplicate_file->changed = TRUE; hash_insert(duplicate_file->hash, d, d); diff --git a/src/deliver/duplicate.h b/src/deliver/duplicate.h index ed3ac5fa78..c31402c71c 100644 --- a/src/deliver/duplicate.h +++ b/src/deliver/duplicate.h @@ -5,7 +5,7 @@ int duplicate_check(const void *id, size_t id_size, const char *user); void duplicate_mark(const void *id, size_t id_size, - const char *user, time_t time); + const char *user, time_t timestamp); void duplicate_flush(void); diff --git a/src/imap/imap-fetch-body.c b/src/imap/imap-fetch-body.c index 7f77138cbc..9a102a02cc 100644 --- a/src/imap/imap-fetch-body.c +++ b/src/imap/imap-fetch-body.c @@ -41,7 +41,7 @@ struct partial_cache { struct message_size pos; }; -static struct partial_cache partial = { 0, 0, 0, 0, { 0, 0, 0 } }; +static struct partial_cache last_partial = { 0, 0, 0, 0, { 0, 0, 0 } }; static bool seek_partial(unsigned int select_counter, unsigned int uid, struct partial_cache *partial, struct istream *stream, @@ -224,10 +224,10 @@ static int fetch_stream_send(struct imap_fetch_context *ctx) ctx->cur_offset += ret; if (ctx->update_partial) { - partial.cr_skipped = ctx->skip_cr != 0; - partial.pos.physical_size = - ctx->cur_input->v_offset - partial.physical_start; - partial.pos.virtual_size += ret; + last_partial.cr_skipped = ctx->skip_cr != 0; + last_partial.pos.physical_size = + ctx->cur_input->v_offset - last_partial.physical_start; + last_partial.pos.virtual_size += ret; } return ctx->cur_offset == ctx->cur_size; @@ -312,7 +312,7 @@ static int fetch_data(struct imap_fetch_context *ctx, } else { ctx->skip_cr = seek_partial(ctx->select_counter, ctx->cur_mail->uid, - &partial, ctx->cur_input, body->skip); + &last_partial, ctx->cur_input, body->skip); } return fetch_stream(ctx, size); diff --git a/src/imap/imap-thread.c b/src/imap/imap-thread.c index f3ab6c9171..ce2bc51b7e 100644 --- a/src/imap/imap-thread.c +++ b/src/imap/imap-thread.c @@ -939,8 +939,7 @@ static void mail_thread_finish(struct thread_context *ctx) /* (2) save root nodes and drop the msgids */ iter = hash_iterate_init(ctx->msgid_hash); while (hash_iterate(iter, &key, &value)) { - struct node *node = value; - + node = value; if (node->parent == NULL) add_root(ctx, node); } diff --git a/src/lib-imap/imap-date.c b/src/lib-imap/imap-date.c index 268960f63e..2ff7289640 100644 --- a/src/lib-imap/imap-date.c +++ b/src/lib-imap/imap-date.c @@ -105,7 +105,7 @@ static bool imap_mktime(struct tm *tm, time_t *time_r) return FALSE; } -bool imap_parse_date(const char *str, time_t *time) +bool imap_parse_date(const char *str, time_t *timestamp_r) { struct tm tm; @@ -114,11 +114,12 @@ bool imap_parse_date(const char *str, time_t *time) return FALSE; tm.tm_isdst = -1; - (void)imap_mktime(&tm, time); + (void)imap_mktime(&tm, timestamp_r); return TRUE; } -bool imap_parse_datetime(const char *str, time_t *time, int *timezone_offset) +bool imap_parse_datetime(const char *str, time_t *timestamp_r, + int *timezone_offset_r) { struct tm tm; @@ -149,22 +150,22 @@ bool imap_parse_datetime(const char *str, time_t *time, int *timezone_offset) str += 3; /* timezone */ - *timezone_offset = parse_timezone(str); + *timezone_offset_r = parse_timezone(str); tm.tm_isdst = -1; - if (imap_mktime(&tm, time)) - *time -= *timezone_offset * 60; + if (imap_mktime(&tm, timestamp_r)) + *timestamp_r -= *timezone_offset_r * 60; return TRUE; } -const char *imap_to_datetime(time_t time) +const char *imap_to_datetime(time_t timestamp) { char *buf; struct tm *tm; int timezone_offset, year; - tm = localtime(&time); - timezone_offset = utc_offset(tm, time); + tm = localtime(×tamp); + timezone_offset = utc_offset(tm, timestamp); /* @UNSAFE: but faster than t_strdup_printf() call.. */ buf = t_malloc(27); diff --git a/src/lib-imap/imap-date.h b/src/lib-imap/imap-date.h index 6e6ea036de..475bb3814d 100644 --- a/src/lib-imap/imap-date.h +++ b/src/lib-imap/imap-date.h @@ -8,10 +8,11 @@ If date is too low or too high to fit to time_t, it's set to lowest/highest allowed value. This allows you to use the value directly for comparing timestamps. */ -bool imap_parse_date(const char *str, time_t *time); -bool imap_parse_datetime(const char *str, time_t *time, int *timezone_offset); +bool imap_parse_date(const char *str, time_t *timestamp_r); +bool imap_parse_datetime(const char *str, time_t *timestamp_r, + int *timezone_offset_r); /* Returns given UTC time in local timezone. */ -const char *imap_to_datetime(time_t time); +const char *imap_to_datetime(time_t timestamp); #endif diff --git a/src/lib-index/mail-cache-compress.c b/src/lib-index/mail-cache-compress.c index 6b3624ee68..ece39327fc 100644 --- a/src/lib-index/mail-cache-compress.c +++ b/src/lib-index/mail-cache-compress.c @@ -199,28 +199,28 @@ mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans, used_fields_count = i; } else { for (i = used_fields_count = 0; i < orig_fields_count; i++) { - struct mail_cache_field_private *field = + struct mail_cache_field_private *priv = &cache->fields[i]; enum mail_cache_decision_type dec = - field->field.decision; + priv->field.decision; /* if the decision isn't forced and this field hasn't been accessed for a while, drop it */ if ((dec & MAIL_CACHE_DECISION_FORCED) == 0 && - (time_t)field->last_used < max_drop_time && - !field->adding) { + (time_t)priv->last_used < max_drop_time && + !priv->adding) { dec = MAIL_CACHE_DECISION_NO; - field->field.decision = dec; + priv->field.decision = dec; } /* drop all fields we don't want */ if ((dec & ~MAIL_CACHE_DECISION_FORCED) == - MAIL_CACHE_DECISION_NO && !field->adding) { - field->used = FALSE; - field->last_used = 0; + MAIL_CACHE_DECISION_NO && !priv->adding) { + priv->used = FALSE; + priv->last_used = 0; } - ctx.field_file_map[i] = !field->used ? + ctx.field_file_map[i] = !priv->used ? (uint32_t)-1 : used_fields_count++; } } diff --git a/src/lib-index/mail-index-map.c b/src/lib-index/mail-index-map.c index 4d7bbed265..ec10eb0351 100644 --- a/src/lib-index/mail-index-map.c +++ b/src/lib-index/mail-index-map.c @@ -331,11 +331,11 @@ int mail_index_map_parse_keywords(struct mail_index_map *map) for (i = 0; i < array_count(&map->keyword_idx_map); i++) { const char *keyword = name + kw_rec[i].name_offset; const unsigned int *old_idx; - unsigned int idx; + unsigned int kw_idx; old_idx = array_idx(&map->keyword_idx_map, i); - if (!mail_index_keyword_lookup(index, keyword, &idx) || - idx != *old_idx) { + if (!mail_index_keyword_lookup(index, keyword, &kw_idx) || + kw_idx != *old_idx) { mail_index_set_error(index, "Corrupted index file %s: " "Keywords changed unexpectedly", index->filepath); @@ -347,7 +347,7 @@ int mail_index_map_parse_keywords(struct mail_index_map *map) i = array_count(&map->keyword_idx_map); for (; i < kw_hdr->keywords_count; i++) { const char *keyword = name + kw_rec[i].name_offset; - unsigned int idx; + unsigned int kw_idx; if (*keyword == '\0') { mail_index_set_error(index, "Corrupted index file %s: " @@ -355,8 +355,8 @@ int mail_index_map_parse_keywords(struct mail_index_map *map) index->filepath); return -1; } - mail_index_keyword_lookup_or_create(index, keyword, &idx); - array_append(&map->keyword_idx_map, &idx, 1); + mail_index_keyword_lookup_or_create(index, keyword, &kw_idx); + array_append(&map->keyword_idx_map, &kw_idx, 1); } return 0; } diff --git a/src/lib-mail/mbox-from.c b/src/lib-mail/mbox-from.c index b7f39c22ae..8c0d874f2c 100644 --- a/src/lib-mail/mbox-from.c +++ b/src/lib-mail/mbox-from.c @@ -54,7 +54,7 @@ int mbox_from_parse(const unsigned char *msg, size_t size, { const unsigned char *msg_start, *sender_end, *msg_end; struct tm tm; - int esc, alt_stamp, timezone = 0, seen_timezone = FALSE; + int esc, alt_stamp, timezone_secs = 0, seen_timezone = FALSE; time_t t; *time_r = (time_t)-1; @@ -198,9 +198,9 @@ int mbox_from_parse(const unsigned char *msg, size_t size, i_isdigit(msg[3]) && i_isdigit(msg[4]) && msg[5] == ' ') { /* numeric timezone, use it */ seen_timezone = TRUE; - timezone = (msg[1]-'0') * 10*60*60 + (msg[2]-'0') * 60*60 + + timezone_secs = (msg[1]-'0') * 10*60*60 + (msg[2]-'0') * 60*60 + (msg[3]-'0') * 10 + (msg[4]-'0'); - if (msg[0] == '-') timezone = -timezone; + if (msg[0] == '-') timezone_secs = -timezone_secs; msg += 6; } @@ -217,9 +217,9 @@ int mbox_from_parse(const unsigned char *msg, size_t size, i_isdigit(msg[2]) && i_isdigit(msg[3]) && i_isdigit(msg[4]) && i_isdigit(msg[5])) { seen_timezone = TRUE; - timezone = (msg[2]-'0') * 10*60*60 + (msg[3]-'0') * 60*60 + + timezone_secs = (msg[2]-'0') * 10*60*60 + (msg[3]-'0') * 60*60 + (msg[4]-'0') * 10 + (msg[5]-'0'); - if (msg[1] == '-') timezone = -timezone; + if (msg[1] == '-') timezone_secs = -timezone_secs; } if (seen_timezone) { @@ -227,7 +227,7 @@ int mbox_from_parse(const unsigned char *msg, size_t size, if (t == (time_t)-1) return -1; - t -= timezone; + t -= timezone_secs; *time_r = t; } else { /* assume local timezone */ @@ -238,7 +238,7 @@ int mbox_from_parse(const unsigned char *msg, size_t size, return 0; } -const char *mbox_from_create(const char *sender, time_t time) +const char *mbox_from_create(const char *sender, time_t timestamp) { string_t *str; struct tm *tm; @@ -251,7 +251,7 @@ const char *mbox_from_create(const char *sender, time_t time) /* we could use simply asctime(), but i18n etc. may break it. Example: "Thu Nov 29 22:33:52 2001" */ - tm = localtime(&time); + tm = localtime(×tamp); /* week day */ str_append(str, weekdays[tm->tm_wday]); diff --git a/src/lib-mail/mbox-from.h b/src/lib-mail/mbox-from.h index 71d1f924a4..e4557bb302 100644 --- a/src/lib-mail/mbox-from.h +++ b/src/lib-mail/mbox-from.h @@ -7,6 +7,6 @@ int mbox_from_parse(const unsigned char *msg, size_t size, time_t *time_r, char **sender_r); /* Return a mbox-compatible From_-line using given sender and time. The returned string begins with "From ". */ -const char *mbox_from_create(const char *sender, time_t time); +const char *mbox_from_create(const char *sender, time_t timestamp); #endif diff --git a/src/lib-mail/message-date.c b/src/lib-mail/message-date.c index 7e0dd34dcb..cb0227ae31 100644 --- a/src/lib-mail/message-date.c +++ b/src/lib-mail/message-date.c @@ -105,8 +105,9 @@ static int next_token(struct message_date_parser_context *ctx, return ret < 0 ? -1 : *value_len > 0; } -static bool message_date_parser_tokens(struct message_date_parser_context *ctx, - time_t *time, int *timezone_offset) +static bool +message_date_parser_tokens(struct message_date_parser_context *ctx, + time_t *timestamp_r, int *timezone_offset_r) { struct tm tm; const unsigned char *value; @@ -212,24 +213,24 @@ static bool message_date_parser_tokens(struct message_date_parser_context *ctx, return FALSE; if (ret == 0) { /* missing timezone */ - *timezone_offset = 0; + *timezone_offset_r = 0; } else { /* timezone */ - *timezone_offset = parse_timezone(value, len); + *timezone_offset_r = parse_timezone(value, len); } tm.tm_isdst = -1; - *time = utc_mktime(&tm); - if (*time == (time_t)-1) + *timestamp_r = utc_mktime(&tm); + if (*timestamp_r == (time_t)-1) return FALSE; - *time -= *timezone_offset * 60; + *timestamp_r -= *timezone_offset_r * 60; return TRUE; } bool message_date_parse(const unsigned char *data, size_t size, - time_t *time, int *timezone_offset) + time_t *timestamp_r, int *timezone_offset_r) { bool success; @@ -238,21 +239,21 @@ bool message_date_parse(const unsigned char *data, size_t size, rfc822_parser_init(&ctx.parser, data, size, NULL); ctx.str = t_str_new(128); - success = message_date_parser_tokens(&ctx, time, - timezone_offset); + success = message_date_parser_tokens(&ctx, timestamp_r, + timezone_offset_r); } T_END; return success; } -const char *message_date_create(time_t time) +const char *message_date_create(time_t timestamp) { struct tm *tm; int offset; bool negative; - tm = localtime(&time); - offset = utc_offset(tm, time); + tm = localtime(×tamp); + offset = utc_offset(tm, timestamp); if (offset >= 0) negative = FALSE; else { diff --git a/src/lib-mail/message-date.h b/src/lib-mail/message-date.h index 6fe98a15ba..fb1364b186 100644 --- a/src/lib-mail/message-date.h +++ b/src/lib-mail/message-date.h @@ -4,9 +4,9 @@ /* Parses RFC2822 date/time string. timezone_offset is filled with the timezone's difference to UTC in minutes. */ bool message_date_parse(const unsigned char *data, size_t size, - time_t *time, int *timezone_offset); + time_t *timestamp_r, int *timezone_offset_r); /* Create RFC2822 date/time string from given time in local timezone. */ -const char *message_date_create(time_t time); +const char *message_date_create(time_t timestamp); #endif diff --git a/src/lib-storage/index/dbox/dbox-index.c b/src/lib-storage/index/dbox/dbox-index.c index cc68c29b37..8812e88267 100644 --- a/src/lib-storage/index/dbox/dbox-index.c +++ b/src/lib-storage/index/dbox/dbox-index.c @@ -155,11 +155,11 @@ static void dbox_index_header_init(struct dbox_index *index, struct dbox_index_file_header *hdr) { if (index->uid_validity == 0) { - const struct mail_index_header *hdr; + const struct mail_index_header *idx_hdr; - hdr = mail_index_get_header(index->mbox->ibox.view); - index->uid_validity = hdr->uid_validity != 0 ? - hdr->uid_validity : (uint32_t)ioloop_time; + idx_hdr = mail_index_get_header(index->mbox->ibox.view); + index->uid_validity = idx_hdr->uid_validity != 0 ? + idx_hdr->uid_validity : (uint32_t)ioloop_time; } memset(hdr, ' ', sizeof(*hdr)); diff --git a/src/lib-storage/index/index-sync.c b/src/lib-storage/index/index-sync.c index 83c12dd0f4..6326ed797e 100644 --- a/src/lib-storage/index/index-sync.c +++ b/src/lib-storage/index/index-sync.c @@ -118,12 +118,12 @@ static void index_mailbox_expunge_recent(struct index_mailbox *ibox, static void index_view_sync_recs_get(struct index_mailbox_sync_context *ctx) { - struct mail_index_view_sync_rec sync; + struct mail_index_view_sync_rec sync_rec; uint32_t seq1, seq2; i_array_init(&ctx->flag_updates, 128); - while (mail_index_view_sync_next(ctx->sync_ctx, &sync)) { - switch (sync.type) { + while (mail_index_view_sync_next(ctx->sync_ctx, &sync_rec)) { + switch (sync_rec.type) { case MAIL_INDEX_SYNC_TYPE_APPEND: /* not interested */ break; @@ -135,7 +135,8 @@ static void index_view_sync_recs_get(struct index_mailbox_sync_context *ctx) case MAIL_INDEX_SYNC_TYPE_KEYWORD_REMOVE: case MAIL_INDEX_SYNC_TYPE_KEYWORD_RESET: if (mail_index_lookup_seq_range(ctx->ibox->view, - sync.uid1, sync.uid2, + sync_rec.uid1, + sync_rec.uid2, &seq1, &seq2)) { seq_range_array_add_range(&ctx->flag_updates, seq1, seq2); diff --git a/src/lib-storage/index/mbox/mbox-sync.c b/src/lib-storage/index/mbox/mbox-sync.c index 6605f027b4..fc632b0573 100644 --- a/src/lib-storage/index/mbox/mbox-sync.c +++ b/src/lib-storage/index/mbox/mbox-sync.c @@ -1656,7 +1656,6 @@ again: before index syncing is started to avoid deadlocks, so we don't have much choice either (well, easy ones anyway). */ int lock_type = mbox->mbox_readonly ? F_RDLCK : F_WRLCK; - int ret; if ((ret = mbox_lock(mbox, lock_type, &lock_id)) <= 0) { if (ret == 0 || lock_type == F_RDLCK) diff --git a/src/lib-storage/list/mailbox-list-fs-iter.c b/src/lib-storage/list/mailbox-list-fs-iter.c index 926be9e6d2..159ee08803 100644 --- a/src/lib-storage/list/mailbox-list-fs-iter.c +++ b/src/lib-storage/list/mailbox-list-fs-iter.c @@ -574,9 +574,9 @@ fs_list_dir_next(struct fs_list_iterate_context *ctx) if (dir->dirp != NULL) { if (dir->next_entry != NULL) { - const struct list_dir_entry *ret = dir->next_entry; + const struct list_dir_entry *entry = dir->next_entry; dir->next_entry = NULL; - return ret; + return entry; } d = readdir(dir->dirp); if (d == NULL) diff --git a/src/lib/module-dir.c b/src/lib/module-dir.c index d8ef603c82..ab912ae4a4 100644 --- a/src/lib/module-dir.c +++ b/src/lib/module-dir.c @@ -250,9 +250,9 @@ module_dir_load_real(const char *dir, const char *module_names, module_pos = &modules; for (i = 0; i < count; i++) T_BEGIN { - const char *name = names_p[i]; const char *path, *stripped_name; + name = names_p[i]; stripped_name = module_file_get_name(name); if (!module_want_load(module_names_arr, stripped_name)) module = NULL; diff --git a/src/lib/restrict-access.c b/src/lib/restrict-access.c index 5391d28b78..a05af97828 100644 --- a/src/lib/restrict-access.c +++ b/src/lib/restrict-access.c @@ -12,8 +12,9 @@ #include #include -static gid_t primary_gid = (gid_t)-1, privileged_gid = (gid_t)-1; -static bool using_priv_gid = FALSE; +static gid_t process_primary_gid = (gid_t)-1; +static gid_t process_privileged_gid = (gid_t)-1; +static bool process_using_priv_gid = FALSE; void restrict_access_set_env(const char *user, uid_t uid, gid_t gid, gid_t privileged_gid, @@ -160,7 +161,7 @@ static void fix_groups_list(const char *extra_groups, /* if we're using a privileged GID, we can temporarily drop our effective GID. we still want to be able to use its privileges, so add it to supplementary groups. */ - add_primary_gid = privileged_gid != (gid_t)-1; + add_primary_gid = process_privileged_gid != (gid_t)-1; tmp = extra_groups == NULL ? &empty : t_strsplit_spaces(extra_groups, ", "); @@ -171,7 +172,7 @@ static void fix_groups_list(const char *extra_groups, have_root_group); /* see if the list already contains the primary GID */ for (i = 0; i < gid_count; i++) { - if (gid_list[i] == primary_gid) { + if (gid_list[i] == process_primary_gid) { add_primary_gid = FALSE; break; } @@ -184,7 +185,7 @@ static void fix_groups_list(const char *extra_groups, /* Some OSes don't like an empty groups list, so use the primary GID as the only one. */ gid_list = t_new(gid_t, 2); - gid_list[0] = primary_gid; + gid_list[0] = process_primary_gid; gid_count = 1; add_primary_gid = FALSE; } @@ -195,11 +196,11 @@ static void fix_groups_list(const char *extra_groups, memcpy(gid_list2, gid_list, gid_count * sizeof(gid_t)); for (; *tmp != NULL; tmp++) { gid = get_group_id(*tmp); - if (gid != primary_gid) + if (gid != process_primary_gid) gid_list2[gid_count++] = gid; } if (add_primary_gid) - gid_list2[gid_count++] = primary_gid; + gid_list2[gid_count++] = process_primary_gid; gid_list = gid_list2; } @@ -224,28 +225,30 @@ void restrict_access_by_env(bool disallow_root) /* set the primary/privileged group */ env = getenv("RESTRICT_SETGID"); - primary_gid = env == NULL || *env == '\0' ? (gid_t)-1 : + process_primary_gid = env == NULL || *env == '\0' ? (gid_t)-1 : (gid_t)strtoul(env, NULL, 10); env = getenv("RESTRICT_SETGID_PRIV"); - privileged_gid = env == NULL || *env == '\0' ? (gid_t)-1 : + process_privileged_gid = env == NULL || *env == '\0' ? (gid_t)-1 : (gid_t)strtoul(env, NULL, 10); - have_root_group = primary_gid == 0; - if (primary_gid != (gid_t)-1 || privileged_gid != (gid_t)-1) { - if (primary_gid == (gid_t)-1) - primary_gid = getegid(); - restrict_init_groups(primary_gid, privileged_gid); + have_root_group = process_primary_gid == 0; + if (process_primary_gid != (gid_t)-1 || + process_privileged_gid != (gid_t)-1) { + if (process_primary_gid == (gid_t)-1) + process_primary_gid = getegid(); + restrict_init_groups(process_primary_gid, + process_privileged_gid); } else { - if (primary_gid == (gid_t)-1) - primary_gid = getegid(); + if (process_primary_gid == (gid_t)-1) + process_primary_gid = getegid(); } /* set system user's groups */ env = getenv("RESTRICT_USER"); if (env != NULL && *env != '\0' && is_root) { - if (initgroups(env, primary_gid) < 0) { + if (initgroups(env, process_primary_gid) < 0) { i_fatal("initgroups(%s, %s) failed: %m", - env, dec2str(primary_gid)); + env, dec2str(process_primary_gid)); } preserve_groups = TRUE; } @@ -303,18 +306,18 @@ void restrict_access_by_env(bool disallow_root) env = getenv("RESTRICT_GID_FIRST"); if (env != NULL && atoi(env) != 0) allow_root_gid = FALSE; - else if (primary_gid == 0 || privileged_gid == 0) + else if (process_primary_gid == 0 || process_privileged_gid == 0) allow_root_gid = TRUE; else allow_root_gid = FALSE; if (!allow_root_gid && uid != 0) { if (getgid() == 0 || getegid() == 0 || setgid(0) == 0) { - if (primary_gid == 0) + if (process_primary_gid == 0) i_fatal("GID 0 isn't permitted"); i_fatal("We couldn't drop root group privileges " "(wanted=%s, gid=%s, egid=%s)", - dec2str(primary_gid), + dec2str(process_primary_gid), dec2str(getgid()), dec2str(getegid())); } } @@ -323,7 +326,7 @@ void restrict_access_by_env(bool disallow_root) env_put("RESTRICT_USER="); env_put("RESTRICT_CHROOT="); env_put("RESTRICT_SETUID="); - if (privileged_gid == (gid_t)-1) { + if (process_privileged_gid == (gid_t)-1) { /* if we're dropping privileges before executing and a privileged group is set, the groups must be fixed after exec */ @@ -337,29 +340,29 @@ void restrict_access_by_env(bool disallow_root) int restrict_access_use_priv_gid(void) { - i_assert(!using_priv_gid); + i_assert(!process_using_priv_gid); - if (privileged_gid == (gid_t)-1) + if (process_privileged_gid == (gid_t)-1) return 0; - if (setegid(privileged_gid) < 0) { + if (setegid(process_privileged_gid) < 0) { i_error("setegid(privileged) failed: %m"); return -1; } - using_priv_gid = TRUE; + process_using_priv_gid = TRUE; return 0; } void restrict_access_drop_priv_gid(void) { - if (!using_priv_gid) + if (!process_using_priv_gid) return; - if (setegid(primary_gid) < 0) + if (setegid(process_primary_gid) < 0) i_fatal("setegid(primary) failed: %m"); - using_priv_gid = FALSE; + process_using_priv_gid = FALSE; } bool restrict_access_have_priv_gid(void) { - return privileged_gid != (gid_t)-1; + return process_privileged_gid != (gid_t)-1; } diff --git a/src/master/dict-process.c b/src/master/dict-process.c index eb7fcf7e54..3fec00cd8a 100644 --- a/src/master/dict-process.c +++ b/src/master/dict-process.c @@ -25,7 +25,7 @@ struct dict_process { struct io *io; }; -static struct dict_process *process; +static struct dict_process *dict_process; static void dict_process_unlisten(struct dict_process *process); @@ -181,7 +181,9 @@ dict_process_destroyed(struct child_process *process, void dict_process_init(void) { - process = i_new(struct dict_process, 1); + struct dict_process *process; + + process = dict_process = i_new(struct dict_process, 1); process->process.type = PROCESS_TYPE_DICT; process->fd = -1; process->path = i_strconcat(settings_root->defaults->base_dir, @@ -194,6 +196,8 @@ void dict_process_init(void) void dict_process_deinit(void) { + struct dict_process *process = dict_process; + dict_process_unlisten(process); if (process->log != NULL) log_unref(process->log); @@ -203,6 +207,8 @@ void dict_process_deinit(void) void dict_process_kill(void) { + struct dict_process *process = dict_process; + if (process->log != NULL) { log_unref(process->log); process->log = NULL; diff --git a/src/master/listener.c b/src/master/listener.c index 33c1053921..38dc5ca356 100644 --- a/src/master/listener.c +++ b/src/master/listener.c @@ -130,7 +130,7 @@ static void check_conflicts(const struct ip_addr *ip, unsigned int port, } static void -listener_init(const char *set_name, const char *listen, +listener_init(const char *set_name, const char *listen_list, unsigned int default_port, ARRAY_TYPE(listener) *listens_arr) { const char *const *tmp; @@ -148,7 +148,7 @@ listener_init(const char *set_name, const char *listen, l.fd = -1; l.wanted = TRUE; - for (tmp = t_strsplit_spaces(listen, ", "); *tmp != NULL; tmp++) { + for (tmp = t_strsplit_spaces(listen_list, ", "); *tmp != NULL; tmp++) { l.port = default_port; resolve_ip(set_name, *tmp, &l.ip, &l.port); @@ -204,7 +204,7 @@ static void listen_parse_and_close_unneeded(struct settings *set) { const char *const *proto; unsigned int default_port; - bool listen = FALSE, ssl_listen = FALSE; + bool nonssl_listen = FALSE, ssl_listen = FALSE; if (set == NULL) return; @@ -214,14 +214,14 @@ static void listen_parse_and_close_unneeded(struct settings *set) for (; *proto != NULL; proto++) { if (strcasecmp(*proto, "imap") == 0) { if (set->protocol == MAIL_PROTOCOL_IMAP) - listen = TRUE; + nonssl_listen = TRUE; } else if (strcasecmp(*proto, "imaps") == 0) { if (set->protocol == MAIL_PROTOCOL_IMAP && !set->ssl_disable) ssl_listen = TRUE; } else if (strcasecmp(*proto, "pop3") == 0) { if (set->protocol == MAIL_PROTOCOL_POP3) - listen = TRUE; + nonssl_listen = TRUE; } else if (strcasecmp(*proto, "pop3s") == 0) { if (set->protocol == MAIL_PROTOCOL_POP3 && !set->ssl_disable) @@ -229,7 +229,7 @@ static void listen_parse_and_close_unneeded(struct settings *set) } } - if (!listen) + if (!nonssl_listen) listener_close_fds(&set->listens); else { default_port = set->protocol == MAIL_PROTOCOL_IMAP ? 143 : 110; diff --git a/src/master/mail-process.c b/src/master/mail-process.c index c82a05bd08..c9b4878401 100644 --- a/src/master/mail-process.c +++ b/src/master/mail-process.c @@ -519,7 +519,7 @@ static void nfs_warn_if_found(const char *mail, const char *full_home_dir) enum master_login_status create_mail_process(enum process_type process_type, struct settings *set, - int socket, const struct ip_addr *local_ip, + int socket_fd, const struct ip_addr *local_ip, const struct ip_addr *remote_ip, const char *user, const char *const *args, bool dump_capability) @@ -536,7 +536,7 @@ create_mail_process(enum process_type process_type, struct settings *set, gid_t gid; ARRAY_DEFINE(extra_args, const char *); unsigned int i, len, count, left, process_count, throttle; - int ret, log_fd, nice, chdir_errno; + int ret, log_fd, nice_value, chdir_errno; bool home_given, nfs_check; i_assert(process_type == PROCESS_TYPE_IMAP || @@ -558,7 +558,7 @@ create_mail_process(enum process_type process_type, struct settings *set, t_array_init(&extra_args, 16); mail = home_dir = chroot_dir = system_user = ""; - uid = (uid_t)-1; gid = (gid_t)-1; nice = 0; + uid = (uid_t)-1; gid = (gid_t)-1; nice_value = 0; home_given = FALSE; for (; *args != NULL; args++) { if (strncmp(*args, "home=", 5) == 0) { @@ -569,7 +569,7 @@ create_mail_process(enum process_type process_type, struct settings *set, else if (strncmp(*args, "chroot=", 7) == 0) chroot_dir = *args + 7; else if (strncmp(*args, "nice=", 5) == 0) - nice = atoi(*args + 5); + nice_value = atoi(*args + 5); else if (strncmp(*args, "system_user=", 12) == 0) system_user = *args + 12; else if (strncmp(*args, "uid=", 4) == 0) { @@ -705,9 +705,9 @@ create_mail_process(enum process_type process_type, struct settings *set, } #ifdef HAVE_SETPRIORITY - if (nice != 0) { - if (setpriority(PRIO_PROCESS, 0, nice) < 0) - i_error("setpriority(%d) failed: %m", nice); + if (nice_value != 0) { + if (setpriority(PRIO_PROCESS, 0, nice_value) < 0) + i_error("setpriority(%d) failed: %m", nice_value); } #endif @@ -720,9 +720,9 @@ create_mail_process(enum process_type process_type, struct settings *set, child_process_init_env(); /* move the client socket into stdin and stdout fds, log to stderr */ - if (dup2(dump_capability ? null_fd : socket, 0) < 0) + if (dup2(dump_capability ? null_fd : socket_fd, 0) < 0) i_fatal("dup2(stdin) failed: %m"); - if (dup2(socket, 1) < 0) + if (dup2(socket_fd, 1) < 0) i_fatal("dup2(stdout) failed: %m"); if (dup2(log_fd, 2) < 0) i_fatal("dup2(stderr) failed: %m"); diff --git a/src/master/mail-process.h b/src/master/mail-process.h index 91b0e9197c..98c187e21a 100644 --- a/src/master/mail-process.h +++ b/src/master/mail-process.h @@ -10,7 +10,7 @@ void mail_process_exec(const char *protocol, const char **args) ATTR_NORETURN; enum master_login_status create_mail_process(enum process_type process_type, struct settings *set, - int socket, const struct ip_addr *local_ip, + int socket_fd, const struct ip_addr *local_ip, const struct ip_addr *remote_ip, const char *user, const char *const *args, bool dump_capability); diff --git a/src/master/master-settings.c b/src/master/master-settings.c index c3211781b2..a4a47d422c 100644 --- a/src/master/master-settings.c +++ b/src/master/master-settings.c @@ -1650,7 +1650,7 @@ static void auth_settings_dump(struct auth_settings *auth, bool nondefaults) { const struct auth_passdb_settings *passdb; const struct auth_userdb_settings *userdb; - const struct auth_socket_settings *socket; + const struct auth_socket_settings *socket_set; const void *sets[2], *sets2[2]; const void *empty_defaults; @@ -1682,23 +1682,23 @@ static void auth_settings_dump(struct auth_settings *auth, bool nondefaults) nondefaults, 4); } - socket = auth->sockets; - for (; socket != NULL; socket = socket->next) { + socket_set = auth->sockets; + for (; socket_set != NULL; socket_set = socket_set->next) { printf(" socket:\n"); - sets2[1] = socket; + sets2[1] = socket_set; settings_dump(auth_socket_setting_defs, sets2, NULL, 2, nondefaults, 4); - if (socket->client.used) { + if (socket_set->client.used) { printf(" client:\n"); - sets2[1] = &socket->client; + sets2[1] = &socket_set->client; settings_dump(socket_setting_defs, sets2, NULL, 2, nondefaults, 6); } - if (socket->master.used) { + if (socket_set->master.used) { printf(" master:\n"); - sets2[1] = &socket->master; + sets2[1] = &socket_set->master; settings_dump(socket_setting_defs, sets2, NULL, 2, nondefaults, 6); } diff --git a/src/plugins/fts-squat/squat-trie.c b/src/plugins/fts-squat/squat-trie.c index 802dc7d46a..f283fa9ee8 100644 --- a/src/plugins/fts-squat/squat-trie.c +++ b/src/plugins/fts-squat/squat-trie.c @@ -643,17 +643,17 @@ node_split_string(struct squat_trie_build_context *ctx, struct squat_node *node) { struct squat_node *child; unsigned char *str; - unsigned int uid, idx, str_len = node->leaf_string_length; + unsigned int uid, idx, leafstr_len = node->leaf_string_length; - i_assert(str_len > 0); + i_assert(leafstr_len > 0); /* make a copy of the leaf string and convert to normal node by removing it. */ - str = t_malloc(str_len); + str = t_malloc(leafstr_len); if (!NODE_IS_DYNAMIC_LEAF(node)) - memcpy(str, node->children.static_leaf_string, str_len); + memcpy(str, node->children.static_leaf_string, leafstr_len); else { - memcpy(str, node->children.leaf_string, str_len); + memcpy(str, node->children.leaf_string, leafstr_len); i_free(node->children.leaf_string); } node->leaf_string_length = 0; @@ -671,16 +671,17 @@ node_split_string(struct squat_trie_build_context *ctx, struct squat_node *node) } i_assert(!child->have_sequential && child->children.data == NULL); - if (str_len > 1) { + if (leafstr_len > 1) { /* make the child a leaf string */ - str_len--; - child->leaf_string_length = str_len; + leafstr_len--; + child->leaf_string_length = leafstr_len; if (!NODE_IS_DYNAMIC_LEAF(child)) { memcpy(child->children.static_leaf_string, - str + 1, str_len); + str + 1, leafstr_len); } else { - child->children.leaf_string = i_malloc(str_len); - memcpy(child->children.leaf_string, str + 1, str_len); + child->children.leaf_string = i_malloc(leafstr_len); + memcpy(child->children.leaf_string, + str + 1, leafstr_len); } } } @@ -691,10 +692,10 @@ node_leaf_string_add_or_split(struct squat_trie_build_context *ctx, const unsigned char *data, unsigned int data_len) { const unsigned char *str = NODE_LEAF_STRING(node); - const unsigned int str_len = node->leaf_string_length; + const unsigned int leafstr_len = node->leaf_string_length; unsigned int i; - if (data_len != str_len) { + if (data_len != leafstr_len) { /* different lengths, can't match */ T_BEGIN { node_split_string(ctx, node); @@ -1757,15 +1758,15 @@ squat_trie_lookup_data(struct squat_trie *trie, const unsigned char *data, return -1; } if (node->leaf_string_length != 0) { - unsigned int str_len = node->leaf_string_length; + unsigned int len = node->leaf_string_length; const unsigned char *str; - if (str_len > sizeof(node->children.static_leaf_string)) + if (len > sizeof(node->children.static_leaf_string)) str = node->children.leaf_string; else str = node->children.static_leaf_string; - if (size > str_len || memcmp(data, str, size) != 0) + if (size > len || memcmp(data, str, size) != 0) return 0; /* match */ diff --git a/src/plugins/quota/quota-fs.c b/src/plugins/quota/quota-fs.c index b35f30079c..5944a20aab 100644 --- a/src/plugins/quota/quota-fs.c +++ b/src/plugins/quota/quota-fs.c @@ -203,7 +203,7 @@ static void fs_quota_mount_init(struct fs_quota_root *root, /* if there are more unused quota roots, copy this mount to them */ roots = array_get(&root->root.quota->roots, &count); for (i = 0; i < count; i++) { - struct fs_quota_root *root = (struct fs_quota_root *)roots[i]; + root = (struct fs_quota_root *)roots[i]; if (QUOTA_ROOT_MATCH(root, mount) && root->mount == NULL) { mount->refcount++; root->mount = mount; diff --git a/src/util/idxview.c b/src/util/idxview.c index 9804447240..0144f7cdcb 100644 --- a/src/util/idxview.c +++ b/src/util/idxview.c @@ -21,12 +21,12 @@ struct dbox_index_header { uint32_t last_dirty_flush_stamp; }; -static const char *unixdate2str(time_t time) +static const char *unixdate2str(time_t timestamp) { static char buf[64]; struct tm *tm; - tm = localtime(&time); + tm = localtime(×tamp); strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", tm); return buf; } diff --git a/src/util/rawlog.c b/src/util/rawlog.c index f8219a4401..2060bd2bab 100644 --- a/src/util/rawlog.c +++ b/src/util/rawlog.c @@ -274,15 +274,15 @@ rawlog_proxy_create(int client_in_fd, int client_out_fd, int server_fd, static void rawlog_open(enum rawlog_flags flags) { - const char *chroot, *home, *path; + const char *chroot_dir, *home, *path; struct stat st; int sfd[2]; pid_t pid; - chroot = getenv("RESTRICT_CHROOT"); + chroot_dir = getenv("RESTRICT_CHROOT"); home = getenv("HOME"); - if (chroot != NULL) - home = t_strconcat(chroot, home, NULL); + if (chroot_dir != NULL) + home = t_strconcat(chroot_dir, home, NULL); else if (home == NULL) home = "."; @@ -296,9 +296,9 @@ static void rawlog_open(enum rawlog_flags flags) if (!S_ISDIR(st.st_mode)) return; - if (chroot != NULL) { + if (chroot_dir != NULL) { /* we'll chroot soon. skip over the chroot in the path. */ - path += strlen(chroot); + path += strlen(chroot_dir); } if (socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0)