Beispiel #1
0
void
hash_add_entry(struct hash* p_hash, void* p_key, void* p_value)
{
  struct hash_node** p_bucket;
  struct hash_node* p_new_node;
  if (hash_lookup_entry(p_hash, p_key))
  {
    bug("duplicate hash key");
  }
  p_bucket = hash_get_bucket(p_hash, p_key);
  p_new_node = vsf_sysutil_malloc(sizeof(*p_new_node));
  p_new_node->p_prev = 0;
  p_new_node->p_next = 0;
  p_new_node->p_key = vsf_sysutil_malloc(p_hash->key_size);
  vsf_sysutil_memcpy(p_new_node->p_key, p_key, p_hash->key_size);
  p_new_node->p_value = vsf_sysutil_malloc(p_hash->value_size);
  vsf_sysutil_memcpy(p_new_node->p_value, p_value, p_hash->value_size);

  if (!*p_bucket)
  {
    *p_bucket = p_new_node;    
  }
  else
  {
    p_new_node->p_next = *p_bucket;
    (*p_bucket)->p_prev = p_new_node;
    *p_bucket = p_new_node;
  }
}
Beispiel #2
0
struct hash*
hash_alloc(unsigned int buckets, unsigned int key_size,
           unsigned int value_size, hashfunc_t hash_func)
{
  unsigned int size;
  struct hash* p_hash = vsf_sysutil_malloc(sizeof(*p_hash));
  p_hash->buckets = buckets;
  p_hash->key_size = key_size;
  p_hash->value_size = value_size;
  p_hash->hash_func = hash_func;
  size = sizeof(struct hash_node*) * buckets;
  p_hash->p_nodes = vsf_sysutil_malloc(size);
  vsf_sysutil_memclr(p_hash->p_nodes, size);
  return p_hash;
}
Beispiel #3
0
static int
pam_conv_func(int nmsg, const struct pam_message** p_msg,
              struct pam_response** p_reply, void* p_addata)
{
  int i;
  struct pam_response* p_resps = 0;
  (void) p_addata;
  if (nmsg < 0)
  {
    bug("dodgy nmsg in pam_conv_func");
  }
  p_resps = vsf_sysutil_malloc(sizeof(struct pam_response) * nmsg);
  for (i=0; i<nmsg; i++)
  {
    switch (p_msg[i]->msg_style)
    {
      case PAM_PROMPT_ECHO_OFF:
        p_resps[i].resp_retcode = PAM_SUCCESS;
        p_resps[i].resp = (char*) str_strdup(&s_pword_str);
        break;
      case PAM_TEXT_INFO:
      case PAM_ERROR_MSG:
        p_resps[i].resp_retcode = PAM_SUCCESS;
        p_resps[i].resp = 0;
        break;
      case PAM_PROMPT_ECHO_ON:
      default:
        vsf_sysutil_free(p_resps);
        return PAM_CONV_ERR;
        break;
    }
  }
  *p_reply = p_resps;
  return PAM_SUCCESS;
}
Beispiel #4
0
void
str_list_add(struct mystr_list* p_list, const struct mystr* p_str,
             const struct mystr* p_sort_key_str)
{
  struct mystr_list_node* p_node;
  /* Expand the node allocation if we have to */
  if (p_list->list_len == p_list->alloc_len)
  {
    if (p_list->alloc_len == 0)
    {
      p_list->alloc_len = 32;
      p_list->p_nodes = vsf_sysutil_malloc(p_list->alloc_len *
                                           sizeof(struct mystr_list_node));
    }
    else
    {
      p_list->alloc_len *= 2;
      p_list->p_nodes = vsf_sysutil_realloc(p_list->p_nodes,
                                            p_list->alloc_len *
                                            sizeof(struct mystr_list_node));
    }
  }
  p_node = &p_list->p_nodes[p_list->list_len];
  p_node->str = s_null_str;
  p_node->sort_key_str = s_null_str;
  str_copy(&p_node->str, p_str);
  if (p_sort_key_str)
  {
    str_copy(&p_node->sort_key_str, p_sort_key_str);
  }
  p_list->list_len++;
}
Beispiel #5
0
void
private_str_alloc_memchunk(struct mystr* p_str, const char* p_src,
                           unsigned int len)
{
  /* Make sure this will fit in the buffer */
  unsigned int buf_needed = len + 1;
  if (buf_needed > p_str->alloc_bytes)
  {
    str_free(p_str);
    s_setbuf(p_str, vsf_sysutil_malloc(buf_needed));
    p_str->alloc_bytes = buf_needed;
  }
  vsf_sysutil_memcpy(p_str->p_buf, p_src, len);
  p_str->p_buf[len] = '\0';
  p_str->len = len;
}
Beispiel #6
0
void
vsf_banner_dir_changed(struct vsf_session* p_sess, int ftpcode)
{
  struct mystr dir_str = INIT_MYSTR;
  /* Do nothing if .message support is off */
  if (!tunable_dirmessage_enable)
  {
    return;
  }
  if (p_sess->p_visited_dir_list == 0)
  {
    struct mystr_list the_list = INIT_STRLIST;
    p_sess->p_visited_dir_list = vsf_sysutil_malloc(sizeof(struct mystr_list));
    *p_sess->p_visited_dir_list = the_list;
  }
  str_getcwd(&dir_str);
  /* Do nothing if we already visited this directory */
  if (!str_list_contains_str(p_sess->p_visited_dir_list, &dir_str))
  {
    /* Just in case, cap the max. no of visited directories we'll remember */
    if (str_list_get_length(p_sess->p_visited_dir_list) <
        VSFTP_MAX_VISIT_REMEMBER)
    {
      str_list_add(p_sess->p_visited_dir_list, &dir_str, 0);
    }
    /* If we have a .message file, squirt it out prepended by the ftpcode and
     * the continuation mark '-'
     */
    {
      struct mystr msg_file_str = INIT_MYSTR;
      if (tunable_message_file)
      {
        (void) str_fileread(&msg_file_str, tunable_message_file,
                            VSFTP_MAX_MSGFILE_SIZE);
      }
      vsf_banner_write(p_sess, &msg_file_str, ftpcode);
      str_free(&msg_file_str);
    }
  }
  str_free(&dir_str);
}
Beispiel #7
0
int LOCAL_XFORM(main, the_session)(void *session) {
	struct vsf_session_old *old_session = (struct vsf_session_old *) stackvars_get_local("main", "the_session");
	assert(old_session);
	struct vsf_session *new_session = (struct vsf_session *) session; 

/* copy control connection */
	if (old_session->p_local_addr != NULL) {
		new_session->p_local_addr = malloc(sizeof(struct sockaddr_in));
		memcpy(new_session->p_local_addr, old_session->p_local_addr, sizeof(struct sockaddr_in)); 
		free(old_session->p_local_addr);
	}

	if (old_session->p_remote_addr != NULL) {
		new_session->p_remote_addr = malloc(sizeof(struct sockaddr_in)); 
		memcpy(new_session->p_remote_addr, old_session->p_remote_addr, sizeof(struct sockaddr_in));
		free(old_session->p_remote_addr);
	}

	/* copy data connection */
	new_session->pasv_listen_fd = old_session->pasv_listen_fd;
	if (old_session->p_port_sockaddr != NULL) {
		new_session->p_port_sockaddr = malloc(sizeof(struct sockaddr_in));
		memcpy(new_session->p_port_sockaddr, old_session->p_port_sockaddr, sizeof(struct sockaddr_in));
		free(old_session->p_port_sockaddr);
	}
	new_session->data_fd = old_session->data_fd;
	new_session->data_progress = old_session->data_progress;
	new_session->bw_rate_max = old_session->bw_rate_max;
	new_session->bw_send_start_sec = old_session->bw_send_start_sec;
	new_session->bw_send_start_usec = old_session->bw_send_start_usec;

	/* copy login details */
	new_session->is_anonymous = old_session->is_anonymous;
	str_copy(&(new_session->user_str), &(old_session->user_str));
	str_copy(&(new_session->anon_pass_str), &(old_session->anon_pass_str));
	
	/* copy ftp protocol state */
	new_session->restart_pos = old_session->restart_pos;
	new_session->is_ascii = old_session->is_ascii;
	str_copy(&(new_session->rnfr_filename_str), &(old_session->rnfr_filename_str));
	new_session->abor_received = old_session->abor_received;

	/* copy ftp session state */
	struct mystr_list the_list = INIT_STRLIST;
  new_session->p_visited_dir_list = vsf_sysutil_malloc(sizeof(struct mystr_list));
  *new_session->p_visited_dir_list = the_list;

	struct mystr_list *mystr_l = old_session->p_visited_dir_list;
	if (mystr_l != NULL) {
		int num_nodes = mystr_l->list_len;
		new_session->p_visited_dir_list->list_len = 0;
		new_session->p_visited_dir_list->alloc_len = mystr_l->alloc_len; /* save some reallocs */
		new_session->p_visited_dir_list->p_nodes = (void*) 0;
		int i;	
		for (i = 0; i < num_nodes; i++) {
			str_list_add(new_session->p_visited_dir_list, &(mystr_l->p_nodes[i].str),
					&(mystr_l->p_nodes[i].sort_key_str));
		}
	}

	/* copy userids */
	new_session->anon_ftp_uid = old_session->anon_ftp_uid;
	new_session->anon_upload_chown_uid;
		/* guest_user_uid added; main should init it properly */

	/* copy cache */
	str_copy(&(new_session->banned_email_str), &(old_session->banned_email_str));
	str_copy(&(new_session->userlist_str), &(old_session->userlist_str));
	str_copy(&(new_session->banner_str), &(old_session->banner_str));
	new_session->tcp_wrapper_ok = old_session->tcp_wrapper_ok;

	/* copy logging related details */
		/* let main + logging.c handle init of xferlog_fd and log_fd */
	str_copy(&(new_session->remote_ip_str), &(old_session->remote_ip_str));
	new_session->log_type = old_session->log_type;	
	new_session->log_start_sec = old_session->log_start_sec;
	new_session->log_start_usec = old_session->log_start_usec;
	str_copy(&(new_session->log_str), &(old_session->log_str));
	new_session->transfer_size = old_session->transfer_size;

	/* copy buffers */
	str_copy(&(new_session->ftp_cmd_str), &(old_session->ftp_cmd_str));
	str_copy(&(new_session->ftp_arg_str), &(old_session->ftp_arg_str));

	/* copy parent<->child comms channel */	
	new_session->parent_fd = old_session->parent_fd;
	new_session->child_fd = old_session->child_fd;

	/* copy other details */
	new_session->num_clients = old_session->num_clients;
	new_session->num_this_ip = old_session->num_this_ip;

	return 1;
}