uint64_t sst_getoff(struct sst *sst, struct slice *sk) { int lsn; uint64_t off = 0UL; struct meta_node *meta_info; meta_info = meta_get(sst->meta, sk->data); if(!meta_info) return 0UL; memcpy(sst->name, meta_info->index_name, FILE_NAME_SIZE); /* If get one record from on-disk sst file, * this file must not be operated by bg-merge thread */ lsn = meta_info->lsn; if (sst->mutexer.lsn == lsn) { pthread_mutex_lock(&sst->mutexer.mutex); off = _read_offset(sst, sk); pthread_mutex_unlock(&sst->mutexer.mutex); } else { off = _read_offset(sst, sk); } return off; }
void _flush_list(struct silopit *silopit, struct skipnode *x,struct skipnode *hdr,int flush_count) { int pos = 0; int count = flush_count; struct skipnode *cur = x; struct skipnode *first = hdr; struct jikukan *merge = NULL; struct meta_node *meta_info = NULL; while(cur != first) { meta_info = meta_get(silopit->meta, cur->key); if(!meta_info){ if(merge) { struct skipnode *h = merge->hdr->forward[0]; _flush_merge_list(silopit, h, merge->count, NULL); jikukan_free(merge); merge = NULL; } _flush_new_list(silopit, x, count - pos); return; } else { int cmp = strcmp(silopit->name, meta_info->index_name); if(cmp == 0) { if (!merge) merge = _read_mmap(silopit,count); jikukan_insert_node(merge, cur); } else { if (merge) { struct skipnode *h = merge->hdr->forward[0]; _flush_merge_list(silopit, h, merge->count, meta_info); jikukan_free(merge); merge = NULL; } memset(silopit->name, 0, FILE_NAME_SIZE); memcpy(silopit->name, meta_info->index_name, FILE_NAME_SIZE); merge = _read_mmap(silopit, count); jikukan_insert_node(merge, cur); } } pos++; cur = cur->forward[0]; } if (merge) { struct skipnode *h = merge->hdr->forward[0]; _flush_merge_list(silopit, h, merge->count, meta_info); jikukan_free(merge); } }
uint64_t silopit_getoff(struct silopit *silopit, struct slice *sk) { int lsn; uint64_t off = 0UL; struct meta_node *meta_info; meta_info = meta_get(silopit->meta, sk->data); if(!meta_info) return 0UL; memcpy(silopit->name, meta_info->index_name, FILE_NAME_SIZE); lsn = meta_info->lsn; if (silopit->mutexer.lsn == lsn) { pthread_mutex_lock(&silopit->mutexer.mutex); off = _read_offset(silopit, sk); pthread_mutex_unlock(&silopit->mutexer.mutex); } else { off = _read_offset(silopit, sk); } return off; }
/** * @brief Accept and verify a password for POP3 authentication. * @note This command is only allowed for sessions which have not yet been authenticated, but which have already supplied a username. * If the username/password combo was validated, the account information is retrieved and checked to see if it is locked. * After successful authentication, this function will prohibit insecure connections for any user configured to use SSL only, * and enforce the existence of only one POP3 session at a time. * Finally, the database Log table for this user's POP3 access is updated, and all the user's messages are retrieved. * @param con the POP3 client connection issuing the command. * @return This function returns no value. */ void pop_pass(connection_t *con) { int_t state; credential_t *cred; stringer_t *password, *username; if (con->pop.session_state != 0) { pop_invalid(con); return; } // The user must come before the PASS command. if (st_empty(con->pop.username)) { con_write_bl(con, "-ERR You must supply a username first.\r\n", 40); return; } // If they didn't pass in a valid password. if (!(password = pop_pass_parse(con))) { con_write_bl(con, "-ERR Invalid PASS command.\r\n", 28); return; } // Hash the password. // First we need to get the regular username from the fully qualified one. if (!(username = credential_username(con->pop.username))) { con_write_bl(con, "-ERR Internal server error. Please try again later.\r\n", 53); st_wipe(password); st_free(password); } st_free(con->pop.username); con->pop.username = username; if (!(cred = credential_alloc_auth(con->pop.username, password))) { con_write_bl(con, "-ERR Internal server error. Please try again later.\r\n", 53); st_wipe(password); st_free(password); return; } st_wipe(password); st_free(password); // Pull the user info out. state = meta_get(con->pop.username, cred->auth.domain, cred->auth.password, cred->auth.key, META_PROT_POP, META_GET_MESSAGES, &(con->pop.user)); // Securely delete this information, as these are the keys to the castle. credential_free(cred); // Not found, or invalid password. if (state == 0) { con_write_bl(con, "-ERR The username and password combination is invalid.\r\n", 56); return; } // Internal error. else if (state < 0 || !con->pop.user) { con_write_bl(con, "-ERR [SYS/TEMP] Internal server error. Please try again later.\r\n", 64); return; } // Locks else if (con->pop.user->lock_status != 0) { // What type of lock is it. if (con->pop.user->lock_status == 1) { con_write_bl(con, "-ERR [SYS/PERM] This account has been administratively locked.\r\n", 64); } else if (con->pop.user->lock_status == 2) { con_write_bl(con, "-ERR [SYS/PERM] This account has been locked for inactivity.\r\n", 62); } else if (con->pop.user->lock_status == 3) { con_write_bl(con, "-ERR [SYS/PERM] This account has been locked on suspicion of abuse.\r\n", 69); } else if (con->pop.user->lock_status == 4) { con_write_bl(con, "-ERR [SYS/PERM] This account has been locked at the request of the user.\r\n", 74); } else { con_write_bl(con, "-ERR [SYS/PERM] This account has been locked.\r\n", 47); } con->pop.user = NULL; meta_remove(con->pop.username, META_PROT_POP); return; } // SSL check. else if ((con->pop.user->flags & META_USER_SSL) == META_USER_SSL && con_secure(con) != 1) { con->pop.user = NULL; meta_remove(con->pop.username, META_PROT_POP); con_write_bl(con, "-ERR [SYS/PERM] This user account is configured to require that all POP sessions be connected over SSL.\r\n", 105); return; } // Single session check. else if (con->pop.user->refs.pop != 1) { con->pop.user = NULL; meta_remove(con->pop.username, META_PROT_POP); con_write_bl(con, "-ERR [IN-USE] This account is being used by another session. Please try again in a few minutes.\r\n", 97); return; } // Debug logging. log_pedantic("User %.*s logged in from %s via POP. {poprefs = %lu, imaprefs = %lu, messages = %lu}", st_length_int(con->pop.username), st_char_get(con->pop.username), st_char_get(con_addr_presentation(con, MANAGEDBUF(256))), con->pop.user->refs.pop, con->pop.user->refs.imap, con->pop.user->messages ? inx_count(con->pop.user->messages) : 0); // Update the log and unlock the session. meta_data_update_log(con->pop.user, META_PROT_POP); meta_user_wlock(con->pop.user); meta_messages_login_update(con->pop.user, META_LOCKED); meta_user_unlock(con->pop.user); // Update session state. con->pop.session_state = 1; // Tell the client everything worked. con_write_bl(con, "+OK Password accepted.\r\n", 24); return; }
void _flush_list(struct sst *sst, struct skipnode *x, struct skipnode *hdr, int flush_count) { int pos = 0; int count = flush_count; struct skipnode *cur = x; struct skipnode *first = hdr; struct skiplist *merge = NULL; struct meta_node *meta_info = NULL; while(cur != first) { meta_info = meta_get(sst->meta, cur->key); /* If m is NULL, cur->key more larger than meta's largest area * need to create new index-file */ if(!meta_info) { /* If merge is NULL, it has no merge */ if(merge) { struct skipnode *h = merge->hdr->forward[0]; _flush_merge_list(sst, h, merge->count, NULL); skiplist_free(merge); merge = NULL; } /* Flush the last nodes to disk */ _flush_new_list(sst, x, count - pos); return ; } else { /* If m is not NULL, means found the index of the cur * We need: * 1) compare the sst->name with meta index name * a)If 0: add the cur to merge, and continue * b)others: * b1)Flush the merge list to disk * b2)Open the meta's mmap, and load all blocks to new merge, add cur to merge */ int cmp = strcmp(sst->name, meta_info->index_name); if(cmp == 0) { if(!merge) merge = _read_mmap(sst, count); skiplist_insert_node(merge, cur); } else { if(merge) { struct skipnode *h = merge->hdr->forward[0]; _flush_merge_list(sst, h, merge->count, meta_info); skiplist_free(merge); merge = NULL; } memset(sst->name, 0, FILE_NAME_SIZE); memcpy(sst->name, meta_info->index_name, FILE_NAME_SIZE); merge = _read_mmap(sst, count); /* Add to merge list */ skiplist_insert_node(merge, cur); } } pos++; cur = cur->forward[0]; } if(merge) { struct skipnode *h = merge->hdr->forward[0]; _flush_merge_list(sst, h, merge->count, meta_info); skiplist_free(merge); } }
int main() { TestDerived1 d1; TestDerived2 d2; const char* s; unsigned int i; float f; META_INIT(TestBase); META_INIT(TestDerived1); META_INIT(TestDerived2); const meta* meta = meta_find("TestDerived2"); assert(meta != NULL); const meta_attribute* attr = meta_find_attribute(meta, "x"); assert(attr != NULL); d2.x = 2.5f; d2.y = -17.3f; meta_get(attr, &d2, &f); assert(f == d2.x); d2._base.last_input = NULL; d2._base.counter = 0; const meta_event* event = meta_find_event(meta, "jumped"); assert(event != NULL); f = 10.0f; meta_call(event, &d2, &f); event = meta_find_event(meta, "input"); assert(event != NULL); meta_call(event, &d2, "key"); meta_call(event, &d2, "key"); meta_call(event, &d2, "key"); assert(0 == strcmp(d2._base.last_input, "key")); assert(3 == d2._base.counter); meta = meta_find("TestBase"); assert(meta != NULL); meta_call(event, &d2, "key"); assert(4 == d2._base.counter); attr = meta_find_attribute(meta, "counter"); assert(attr != NULL); meta_get(attr, &d2, &i); assert(4 == i); attr = meta_find_attribute(meta, "last_input"); assert(attr != NULL); meta_get(attr, &d2, &s); assert(0 == strcmp("key", d2._base.last_input)); meta = meta_find("TestDerived1"); d1.health = 100; d1.damage = 17; event = meta_find_event(meta, "damaged"); assert(event != NULL); meta_call(event, &d1, &d1.damage); meta_call(event, &d1, &d1.damage); meta_call(event, &d1, &d1.damage); attr = meta_find_attribute(meta, "health"); assert(attr != NULL); meta_get(attr, &d1, &i); assert(49 == i); return 0; }