filter_t* createGaussianFilterN(uint size)
{
	filter_t* filter = (filter_t*)malloc(sizeof(filter_t));
	if (!filter) return NULL;
	filter->mask = (int**)calloc(size, sizeof(int*));
	if (!filter->mask) return NULL;

	uint i, j;

	float** coeffs = (float**)generateNormalizedGaussianNKernel(size);

	float weightSum = 0;
	for (j = 0; j < size; j++)
	for (i = 0; i < size; i++)
		weightSum += coeffs[j][i];

	for (j = 0; j < size; j++) {
		filter->mask[j] = (int*)calloc(size, sizeof(int*));
		if (!filter->mask[j]) return NULL;
		for (i = 0; i < size; i++)
			filter->mask[j][i] = (int)coeffs[j][i];
	}

	for (j = 0; j < size; j++)
		secure_free(coeffs[j]);
	secure_free(coeffs);

	filter->div = 0;
	filter->size = size;
	filter->needNormalization = true;
	filter->reBoundOnly = false;
	filter->method = flt_m_Convolution;

	return filter;
}
void freeFilter(filter_t* flt)
{
	if (flt && flt->mask) {
		uint i;
		for (i = 0; i < flt->size; i++)
			secure_free(flt->mask[i]);
		secure_free(flt->mask);
	}
	secure_free(flt);
}
Exemple #3
0
dc_pass *__get_pass_keyfiles(
		HWND h_pass,
		BOOL use_keyfiles,
		int  key_list
	)
{
	dc_pass *pass;
	wchar_t *s_pass;
	size_t   plen;
	int      rlt;

	if ( (pass = secure_alloc(sizeof(dc_pass))) == NULL )
	{
		return NULL;
	}
	if ( (s_pass = secure_alloc((MAX_PASSWORD + 1) * sizeof(wchar_t))) == NULL) 
	{
		return NULL;
	}
	GetWindowText( h_pass, s_pass, MAX_PASSWORD + 1 );
	if ( wcslen(s_pass) > 0 )
	{
		plen       = wcslen(s_pass) * sizeof(wchar_t);
		pass->size = d32( min( plen, MAX_PASSWORD * sizeof(wchar_t) ) );

		mincpy( &pass->pass, s_pass, pass->size );
		secure_free( s_pass );
	}
	if ( use_keyfiles )
	{
		_list_key_files *key_file;

		if ( key_file = _first_keyfile(key_list) )
		{
			do {
				rlt = dc_add_keyfiles( pass, key_file->path );
				if ( rlt != ST_OK )
				{
					__error_s( GetParent(h_pass), L"Keyfiles not loaded", rlt );

					secure_free( pass );
					pass = NULL;

					break;
				}
				key_file = _next_keyfile( key_file, key_list );

			} while ( key_file != NULL );
		} 
	}

	return pass;
}
Exemple #4
0
int dc_start_format(wchar_t *device, dc_pass *password, crypt_info *crypt)
{
	dc_ioctl *dctl;
	u32       bytes;
	int       resl;
	int       succs;

	do
	{
		if ( (dctl = secure_alloc(sizeof(dc_ioctl))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		wcscpy(dctl->device, device);
		autocpy(&dctl->passw1, password, sizeof(dc_pass));

		dctl->crypt = crypt[0];

		succs = DeviceIoControl(
			TlsGetValue(h_tls_idx), DC_FORMAT_START,
			dctl, sizeof(dc_ioctl), dctl, sizeof(dc_ioctl), &bytes, NULL);

		if (succs == 0) {
			resl = ST_ERROR; break;
		}

		resl = dctl->status;
	} while (0);

	if (dctl != NULL) {
		secure_free(dctl);
	}

	return resl;
}
DWORD 
WINAPI 
_thread_enc_iso_proc(
		LPVOID lparam
	)
{
	_dnode *node;
	dc_open_device( );

	if ( (node = pv(lparam)) != NULL )
	{
		node->dlg.rlt = ST_OK;

		node->dlg.rlt = dc_encrypt_cd(
			node->dlg.iso.s_iso_src, node->dlg.iso.s_iso_dst, node->dlg.iso.pass, node->dlg.iso.cipher_id, dc_cd_callback, lparam
			);
		{
			secure_free( node->dlg.iso.pass );
			SendMessage( GetParent(GetParent(node->dlg.h_page)), WM_CLOSE_DIALOG, 0, 0 );
		}

	}
	//EnterCriticalSection(&crit_sect);
	//LeaveCriticalSection(&crit_sect);

	dc_close_device( );
	return 1L;
}
Exemple #6
0
void * secure_realloc(
    SecureAllocator allocator,
    void * ptr,
    size_t new_size)
{
    /* TODO: THIS IS A NAIVE IMPLEMENTATION, which always allocates new
       memory, and copies the memory, then frees the old memory. */

    /* Allocate new memory. */
    void * new_ptr = secure_malloc(allocator, new_size);
    /* If memory allocation failed, abort. */
    if (new_ptr == NULL) {
        return NULL;
    }

    /* Passing NULL as ptr is legal, realloc acts as malloc then. */
    if (ptr) {
        /* Get the size of the ptr memory. */
        size_t size = ((MEMP *) ((uint32_t) ptr - sizeof(MEMP)))->len;
        /* Copy the memory to the new location, min(new_size, size). */
        memcpy(new_ptr, ptr, new_size < size ? new_size : size);
        /* Free the previous memory. */
        secure_free(allocator, ptr);
    }
    return new_ptr;
}
Exemple #7
0
static char *
wallet_encrypt_string(struct wallet    *wallet,
                      const char       *plaintext,
                      struct crypt_key *ckey)
{
   struct secure_area *sec;
   char cipherStr[1024];
   uint8 *cipher;
   char *hmac;
   char *res;
   size_t clen;
   size_t len;
   bool s;

   ASSERT(plaintext);

   len = strlen(plaintext) + 1;
   sec = secure_alloc(len);
   memcpy(sec->buf, plaintext, len);

   s = crypt_encrypt(ckey, sec, &cipher, &clen);
   ASSERT(s);

   str_snprintf_bytes(cipherStr, sizeof cipherStr, NULL, cipher, clen);
   hmac = wallet_hmac_string(cipher, clen, wallet->pass);
   res = safe_asprintf("%s-%s", cipherStr, hmac);
   free(hmac);

   free(cipher);
   secure_free(sec);

   return res;
}
Exemple #8
0
int dc_restore_header(wchar_t *device, dc_pass *password, void *in)
{
	dc_backup_ctl *back;
	u32            bytes;
	int            succs;
	int            resl;

	do
	{
		if ( (back = secure_alloc(sizeof(dc_backup_ctl))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		wcscpy(back->device, device);
		autocpy(&back->pass, password, sizeof(dc_pass));
		autocpy(back->backup, in, DC_AREA_SIZE);

		succs = DeviceIoControl(
			TlsGetValue(h_tls_idx), DC_RESTORE_HEADER,
			back, sizeof(dc_backup_ctl), back, sizeof(dc_backup_ctl), &bytes, NULL);

		if (succs == 0) {
			resl = ST_ERROR; break;
		}
		
		resl = back->status;
	} while (0);

	if (back != NULL) {
		secure_free(back);
	}

	return resl;
}
Exemple #9
0
int dc_add_password(dc_pass *password)
{
	dc_ioctl *dctl;
	u32       bytes;
	int       resl;
	int       succs;

	do
	{
		if ( (dctl = secure_alloc(sizeof(dc_ioctl))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		autocpy(&dctl->passw1, password, sizeof(dc_pass));

		succs = DeviceIoControl(
			TlsGetValue(h_tls_idx), DC_CTL_ADD_PASS,
			dctl, sizeof(dc_ioctl), dctl, sizeof(dc_ioctl), &bytes, NULL
			);

		if (succs == 0) {
			resl = ST_ERROR;
		} else {
			resl = dctl->status;
		}
	} while (0);

	if (dctl != NULL) {
		secure_free(dctl);
	}
	return resl;
}
Exemple #10
0
void processor_cleanup(EC_KEY *key, secure_t *ciphered, char *hex_pub, char 
*hex_priv, unsigned char *text, unsigned char *copy, unsigned char *original) {

        if (key) {
                ecies_key_free(key);
        }

        if (ciphered) {
                secure_free(ciphered);
        }

        if (hex_pub) {
                OPENSSL_free(hex_pub);
        }

        if (hex_priv) {
                OPENSSL_free(hex_priv);
        }

        if (text) {
                free(text);
        }

        if (copy) {
                free(copy);
        }

        if (original) {
                free(original);
        }

        return;
}
Exemple #11
0
void
wallet_close(struct wallet *wallet)
{
   if (wallet == NULL) {
      return;
   }
   bloom_free(wallet->filter);
   wallet->filter = NULL;
   txdb_close(wallet->txdb);
   hashtable_clear_with_callback(wallet->hash_keys, wallet_free_key_cb);
   hashtable_destroy(wallet->hash_keys);
   free(wallet->filename);
   secure_free(wallet->ckey_store);
   memset(wallet, 0, sizeof *wallet);
   free(wallet);
}
Exemple #12
0
void
ipmiconsole_ctx_cleanup (ipmiconsole_ctx_t c)
{
  assert (c);
  assert (c->magic == IPMICONSOLE_CTX_MAGIC);

  /* don't call ctx_set_errnum after the mutex_destroy */
  ipmiconsole_ctx_set_errnum (c, IPMICONSOLE_ERR_CTX_INVALID);
  pthread_mutex_destroy (&(c->errnum_mutex));
  c->magic = ~IPMICONSOLE_CTX_MAGIC;
  c->api_magic = ~IPMICONSOLE_CTX_API_MAGIC;
  if (c->config.engine_flags & IPMICONSOLE_ENGINE_LOCK_MEMORY)
    secure_free (c, sizeof (struct ipmiconsole_ctx));
  else
    free (c);
}
Exemple #13
0
void _keyfiles_wipe(
		int key_list
	)
{
	_list_key_files *node, *next;
	if ( next = _first_keyfile(key_list) )
	{
		do 
		{
			node = next;
			next = _next_keyfile( node, key_list );

			_remove_entry_list( &node->next );
			secure_free( node );

		} while ( next != NULL );
	} 
}
Exemple #14
0
void
weechat_end (void (*gui_end_cb)(int clean_exit))
{
    gui_layout_store_on_exit ();        /* store layout                     */
    plugin_end ();                      /* end plugin interface(s)          */
    if (CONFIG_BOOLEAN(config_look_save_config_on_exit))
        (void) config_weechat_write (); /* save WeeChat config file         */
    (void) secure_write ();             /* save secured data                */

    if (gui_end_cb)
        (*gui_end_cb) (1);              /* shut down WeeChat GUI            */

    proxy_free_all ();                  /* free all proxies                 */
    config_weechat_free ();             /* free WeeChat options             */
    secure_free ();                     /* free secured data options        */
    config_file_free_all ();            /* free all configuration files     */
    gui_key_end ();                     /* remove all keys                  */
    unhook_all ();                      /* remove all hooks                 */
    hdata_end ();                       /* end hdata                        */
    secure_end ();                      /* end secured data                 */
    string_end ();                      /* end string                       */
    weechat_shutdown (-1, 0);           /* end other things                 */
}
Exemple #15
0
int dc_mount_all(dc_pass *password, int *mounted, int flags)
{
	dc_ioctl *dctl;
	u32       bytes;
	int       resl;
	int       succs;

	do
	{
		if ( (dctl = secure_alloc(sizeof(dc_ioctl))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		if (password != NULL) {
			autocpy(&dctl->passw1, password, sizeof(dc_pass));			
		}

		dctl->flags = flags;

		succs = DeviceIoControl(
			TlsGetValue(h_tls_idx), DC_CTL_MOUNT_ALL,
			dctl, sizeof(dc_ioctl), dctl, sizeof(dc_ioctl), &bytes, NULL);

		if (succs == 0) {
			resl = ST_ERROR; break;
		}

		resl = dctl->status; 
		mounted[0] = dctl->n_mount;
	} while (0);

	if (dctl != NULL) {
		secure_free(dctl);
	}

	return resl;
}
Exemple #16
0
int dc_change_password(
	  wchar_t *device, dc_pass *old_pass, dc_pass *new_pass
	  )
{
	dc_ioctl *dctl;
	u32       bytes;
	int       resl;
	int       succs;

	do
	{
		if ( (dctl = secure_alloc(sizeof(dc_ioctl))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		wcscpy(dctl->device, device);
		autocpy(&dctl->passw1, old_pass, sizeof(dc_pass));
		autocpy(&dctl->passw2, new_pass, sizeof(dc_pass));

		succs = DeviceIoControl(
			TlsGetValue(h_tls_idx), DC_CTL_CHANGE_PASS,
			dctl, sizeof(dc_ioctl), dctl, sizeof(dc_ioctl), &bytes, NULL);

		if (succs == 0) {
			resl = ST_ERROR; break;
		}

		resl = dctl->status;
	} while (0);

	if (dctl != NULL) {
		secure_free(dctl);
	}

	return resl;
}
Exemple #17
0
int dc_mount_volume(wchar_t *device, dc_pass *password, int flags)
{
	dc_ioctl *dctl;
	u32       bytes;
	int       resl;
	int       succs;

	do
	{
		if ( (dctl = secure_alloc(sizeof(dc_ioctl))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		wcscpy(dctl->device, device); dctl->flags = flags;

		if (password != NULL) {
			autocpy(&dctl->passw1, password, sizeof(dc_pass));
		}

		succs = DeviceIoControl(
			TlsGetValue(h_tls_idx), DC_CTL_MOUNT,
			dctl, sizeof(dc_ioctl), dctl, sizeof(dc_ioctl), &bytes, NULL);

		if (succs == 0) {
			resl = ST_ERROR; break;
		}

		resl = dctl->status;
	} while (0);

	if (dctl != NULL) {
		secure_free(dctl);
	}

	return resl;
}
Exemple #18
0
static
int dc_add_single_kf(dc_pass *pass, wchar_t *path)
{
	kf_ctx *k_ctx;
	HANDLE  h_file;
	int     resl, i;
	int     succs;
	u32     bytes;

	h_file = NULL; k_ctx = NULL;
	do
	{
		if ( (k_ctx = secure_alloc(sizeof(kf_ctx))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		h_file = CreateFile(
			path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);

		if (h_file == INVALID_HANDLE_VALUE) {
			h_file = NULL; resl = ST_ACCESS_DENIED; break;
		}

		/* initialize sha512 for hashing keyfile */
		sha512_init(&k_ctx->sha);

		do
		{
			succs = ReadFile(h_file, k_ctx->kf_block, KF_BLOCK_SIZE, &bytes, NULL);

			if ( (succs == 0) || (bytes == 0) ) {
				break;
			}
			sha512_hash(&k_ctx->sha, k_ctx->kf_block, bytes);
		} while (1);		
	
		/* done hasing */
		sha512_done(&k_ctx->sha, k_ctx->hash);

		/* zero unused password buffer bytes */
		zeromem(
			p8(pass->pass) + pass->size, (MAX_PASSWORD*2) - pass->size);

		/* mix the keyfile hash and password */
		for (i = 0; i < (SHA512_DIGEST_SIZE / sizeof(u32)); i++) {
			p32(pass->pass)[i] += p32(k_ctx->hash)[i];
		}
		pass->size = max(pass->size, SHA512_DIGEST_SIZE); 
		resl = ST_OK;		
	} while (0);

	if (h_file != NULL) {
		CloseHandle(h_file);
	}

	if (k_ctx != NULL) {
		secure_free(k_ctx);
	}

	return resl;
}
void _run_wizard_action(
		HWND        hwnd,
		_wz_sheets *sheets,
		_dnode     *node
												
	)
{
	BOOL set_loader = (BOOL)
		SendMessage(
			GetDlgItem(sheets[WPAGE_ENC_BOOT].hwnd, IDC_COMBO_BOOT_INST), CB_GETCURSEL, 0, 0
			);

	wchar_t *fs_name = 
		fs_names[SendMessage(
			GetDlgItem(sheets[WPAGE_ENC_FRMT].hwnd, IDC_COMBO_FS_LIST), CB_GETCURSEL, 0, 0
			)];

	int  kb_layout = _get_combo_val( GetDlgItem(sheets[WPAGE_ENC_PASS].hwnd, IDC_COMBO_KBLAYOUT), kb_layouts );
	BOOL q_format  = _get_check( sheets[WPAGE_ENC_FRMT].hwnd, IDC_CHECK_QUICK_FORMAT );

	int is_small = (
		IsWindowEnabled( GetDlgItem( sheets[WPAGE_ENC_CONF].hwnd, IDC_COMBO_ALGORT ) ) ? FALSE : TRUE
	);

	crypt_info  crypt;
	dc_pass    *pass = NULL;

	crypt.cipher_id  = _get_combo_val( GetDlgItem(sheets[WPAGE_ENC_CONF].hwnd, IDC_COMBO_ALGORT), cipher_names );
	crypt.wp_mode    = _get_combo_val( GetDlgItem(sheets[WPAGE_ENC_CONF].hwnd, IDC_COMBO_PASSES), wipe_modes );
 
	node->dlg.rlt = ST_ERROR;

	switch ( node->dlg.act_type )
	{
	///////////////////////////////////////////////////////////////
	case ACT_REENCRYPT :
	///////////////////////////////////////////////////////////////
	/////// REENCRYPT VOLUME //////////////////////////////////////
	{
		wchar_t mnt_point[MAX_PATH] = { 0 };
		wchar_t vol[MAX_PATH];

		dlgpass dlg_info = { node, NULL, NULL, mnt_point };

		ShowWindow(hwnd, FALSE);
		if ( _dlg_get_pass(__dlg, &dlg_info) == ST_OK )
		{
			node->mnt.info.status.crypt.wp_mode = crypt.wp_mode;
			node->dlg.rlt = dc_start_re_encrypt( node->mnt.info.device, dlg_info.pass, &crypt );

			secure_free( dlg_info.pass );
			if ( mnt_point[0] != 0 )
			{
				_snwprintf( vol, sizeof_w(vol), L"%s\\", node->mnt.info.w32_device );
				_set_trailing_slash( mnt_point );

				if ( SetVolumeMountPoint(mnt_point, vol) == 0 )
				{
					__error_s( __dlg, L"Error when adding mount point", node->dlg.rlt );
				}
			}
		} else {
			node->dlg.rlt = ST_CANCEL;
		}
	}
	break;
	///////////////////////////////////////////////////////////////
	case ACT_ENCRYPT_CD :
	///////////////////////////////////////////////////////////////
	/////// ENCRYPT CD ////////////////////////////////////////////
	{
		_init_speed_stat( &node->dlg.iso.speed );
		pass = _get_pass_keyfiles( sheets[WPAGE_ENC_PASS].hwnd, IDE_PASS, IDC_USE_KEYFILES, KEYLIST_CURRENT );		

		if ( pass )
		{
			DWORD resume;
			{
				wchar_t s_src_path[MAX_PATH] = { 0 };
				wchar_t s_dst_path[MAX_PATH] = { 0 };

				GetWindowText( GetDlgItem(sheets[WPAGE_ENC_ISO].hwnd, IDE_ISO_SRC_PATH), s_src_path, sizeof_w(s_src_path) );
				GetWindowText( GetDlgItem(sheets[WPAGE_ENC_ISO].hwnd, IDE_ISO_DST_PATH), s_dst_path, sizeof_w(s_dst_path) );

				wcscpy( node->dlg.iso.s_iso_src, s_src_path );
				wcscpy( node->dlg.iso.s_iso_dst, s_dst_path );

				node->dlg.iso.cipher_id = crypt.cipher_id;
				node->dlg.iso.pass      = pass;
			}

			node->dlg.iso.h_thread = 
				CreateThread(
					NULL, 0, _thread_enc_iso_proc, pv(node), CREATE_SUSPENDED, NULL
					);

			SetThreadPriority( node->dlg.iso.h_thread, THREAD_PRIORITY_LOWEST );
			resume = ResumeThread( node->dlg.iso.h_thread );

			if ( !node->dlg.iso.h_thread || resume == (DWORD) -1 )
			{
				__error_s( hwnd, L"Error create thread", -1 );
				secure_free(pass);
			}
		}		
	}
	break;
	///////////////////////////////////////////////////////////////
	default :
	///////////////////////////////////////////////////////////////
	{
		node->mnt.info.status.crypt.wp_mode = crypt.wp_mode;
		node->dlg.rlt = ST_OK;

		if ( sheets[WPAGE_ENC_BOOT].show )
		{
			if ( set_loader )
			{
				node->dlg.rlt = _set_boot_loader( hwnd, -1, is_small );
			}
		}
		if ( ( node->dlg.rlt == ST_OK ) && 
			 ( IsWindowEnabled( GetDlgItem( sheets[WPAGE_ENC_PASS].hwnd, IDC_LAYOUTS_LIST ) ) ) 
		   )
		{
			node->dlg.rlt = _update_layout( node, kb_layout, NULL );
		}
		if ( node->dlg.rlt == ST_OK )
		{
			switch ( node->dlg.act_type )
			{
		///////////////////////////////////////////////////////////////
			case ACT_ENCRYPT :
		///////////////////////////////////////////////////////////////
		/////// ENCRYPT VOLUME ////////////////////////////////////////
			{
				pass = _get_pass_keyfiles( sheets[WPAGE_ENC_PASS].hwnd, IDE_PASS, IDC_USE_KEYFILES, KEYLIST_CURRENT );

				if ( pass != NULL )
				{
					node->dlg.rlt = dc_start_encrypt( node->mnt.info.device, pass, &crypt );
					secure_free(pass);
				}
			}
			break;
		///////////////////////////////////////////////////////////////
			case ACT_FORMAT :
		///////////////////////////////////////////////////////////////
		/////// FORMAT VOLUME /////////////////////////////////////////
			{
				pass = _get_pass_keyfiles( sheets[WPAGE_ENC_PASS].hwnd, IDE_PASS, IDC_USE_KEYFILES, KEYLIST_CURRENT );
				if ( pass )
				{
					node->dlg.rlt = dc_start_format( node->mnt.info.device, pass, &crypt );
					secure_free(pass);
				}
			}
			break;
			}
		}
	}
	}
	node->dlg.q_format = q_format;
	node->dlg.fs_name  = fs_name;

	if ( !node->dlg.iso.h_thread )
	{
		EndDialog( hwnd, 0 );
	}
}
Exemple #20
0
int
main (int argc, char *argv[])
{
    weechat_first_start_time = time (NULL); /* initialize start time        */
    gettimeofday (&weechat_current_start_timeval, NULL);

    setlocale (LC_ALL, "");             /* initialize gettext               */
#ifdef ENABLE_NLS
    bindtextdomain (PACKAGE, LOCALEDIR);
    bind_textdomain_codeset (PACKAGE, "UTF-8");
    textdomain (PACKAGE);
#endif

#ifdef HAVE_LANGINFO_CODESET
    weechat_local_charset = strdup (nl_langinfo (CODESET));
#else
    weechat_local_charset = strdup ("");
#endif
    utf8_init ();

    util_catch_signal (SIGINT, SIG_IGN);  /* ignore SIGINT signal           */
    util_catch_signal (SIGQUIT, SIG_IGN); /* ignore SIGQUIT signal          */
    util_catch_signal (SIGPIPE, SIG_IGN); /* ignore SIGPIPE signal          */
    util_catch_signal (SIGSEGV,
                       &debug_sigsegv); /* crash dump for SIGSEGV signal    */
    hdata_init ();                      /* initialize hdata                 */
    hook_init ();                       /* initialize hooks                 */
    debug_init ();                      /* hook signals for debug           */
    gui_main_pre_init (&argc, &argv);   /* pre-initialize interface         */
    command_init ();                    /* initialize WeeChat commands      */
    completion_init ();                 /* add core completion hooks        */
    gui_key_init ();                    /* init keys                        */
    network_init_gcrypt ();             /* init gcrypt                      */
    if (!secure_init ())                /* init secured data options (sec.*)*/
        weechat_shutdown (EXIT_FAILURE, 0);
    if (!config_weechat_init ())        /* init WeeChat options (weechat.*) */
        weechat_shutdown (EXIT_FAILURE, 0);
    weechat_parse_args (argc, argv);    /* parse command line args          */
    weechat_create_home_dir ();         /* create WeeChat home directory    */
    log_init ();                        /* init log file                    */
    plugin_api_init ();                 /* create some hooks (info,hdata,..)*/
    secure_read ();                     /* read secured data options        */
    config_weechat_read ();             /* read WeeChat options             */
    network_init_gnutls ();             /* init GnuTLS                      */
    gui_main_init ();                   /* init WeeChat interface           */
    if (weechat_upgrading)
    {
        upgrade_weechat_load ();        /* upgrade with session file        */
        weechat_upgrade_count++;        /* increase /upgrade count          */
    }
    weechat_welcome_message ();         /* display WeeChat welcome message  */
    gui_chat_print_lines_waiting_buffer (NULL); /* display lines waiting    */
    command_startup (0);                /* command executed before plugins  */
    plugin_init (weechat_auto_load_plugins, /* init plugin interface(s)     */
                 argc, argv);
    command_startup (1);                /* commands executed after plugins  */
    if (!weechat_upgrading)
        gui_layout_window_apply (gui_layout_current, -1);
    if (weechat_upgrading)
        upgrade_weechat_end ();         /* remove .upgrade files + signal   */

    gui_main_loop ();                   /* WeeChat main loop                */

    gui_layout_store_on_exit ();        /* store layout                     */
    plugin_end ();                      /* end plugin interface(s)          */
    if (CONFIG_BOOLEAN(config_look_save_config_on_exit))
        (void) config_weechat_write (); /* save WeeChat config file         */
    (void) secure_write ();             /* save secured data                */
    gui_main_end (1);                   /* shut down WeeChat GUI            */
    proxy_free_all ();                  /* free all proxies                 */
    config_weechat_free ();             /* free WeeChat options             */
    secure_free ();                     /* free secured data options        */
    config_file_free_all ();            /* free all configuration files     */
    gui_key_end ();                     /* remove all keys                  */
    unhook_all ();                      /* remove all hooks                 */
    hdata_end ();                       /* end hdata                        */
    secure_end ();                      /* end secured data                 */
    string_end ();                      /* end string                       */
    weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?)       */

    return EXIT_SUCCESS;                /* make C compiler happy            */
}
Exemple #21
0
INT_PTR CALLBACK
_password_change_dlg_proc(
		HWND	hwnd,
		UINT	message,
		WPARAM	wparam,
		LPARAM	lparam
	)
{
	WORD code = HIWORD(wparam);
	WORD id   = LOWORD(wparam);

	wchar_t display[MAX_PATH] = { 0 };
	static  dlgpass *info;
	int     k;

	int check_init[ ] = {
		IDC_CHECK_SHOW_CURRENT, IDC_USE_KEYFILES_CURRENT,
		IDC_CHECK_SHOW_NEW, IDC_USE_KEYFILES_NEW,
		-1
	};

	_ctl_init static_head[ ] = {
		{ L"# Current Password", IDC_HEAD_PASS_CURRENT, 0 },
		{ L"# New Password",     IDC_HEAD_PASS_NEW,     0 },
		{ L"# Password Rating",  IDC_HEAD_RATING,       0 },
		{ STR_NULL, -1, -1 }
	};

	switch (message) 
	{
		case WM_CTLCOLOREDIT : return _ctl_color(wparam, _cl(COLOR_BTNFACE, LGHT_CLR));
			break;

		case WM_CTLCOLORSTATIC : 
		{
			HDC dc = (HDC)wparam;
			COLORREF bgcolor, fn = 0;

			SetBkMode(dc, TRANSPARENT);

			k = 0;
			while (pass_gr_ctls[k].id != -1) 
			{
				if (pass_gr_ctls[k].hwnd == (HWND)lparam)
					fn = pass_gr_ctls[k].color;

				if (pass_pe_ctls[k].hwnd == (HWND)lparam)
					fn = pass_pe_ctls[k].color;

				k++;
			}
			SetTextColor(dc, fn);

			bgcolor = GetSysColor(COLOR_BTNFACE);
			SetDCBrushColor(dc, bgcolor);
			
			return (INT_PTR)GetStockObject(DC_BRUSH);
		
		}
		break;
		case WM_INITDIALOG : 
		{
			info = (dlgpass *)lparam;

			SendMessage(GetDlgItem(hwnd, IDE_PASS_NEW_CONFIRM), EM_LIMITTEXT, MAX_PASSWORD, 0);
			SendMessage(GetDlgItem(hwnd, IDE_PASS_CURRENT),     EM_LIMITTEXT, MAX_PASSWORD, 0);
			SendMessage(GetDlgItem(hwnd, IDE_PASS_NEW),         EM_LIMITTEXT, MAX_PASSWORD, 0);			

			SendMessage(hwnd, WM_COMMAND, 
				MAKELONG(IDE_PASS_NEW, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_NEW));

			if (info->node) {
				_snwprintf(display, sizeof_w(display), L"[%s] - %s", 
					info->node->mnt.info.status.mnt_point, info->node->mnt.info.device);

			} else {
				wcscpy(display, L"Change password");

			}
			SetWindowText(hwnd, display);
		
			SendMessage(
				GetDlgItem(hwnd, IDP_BREAKABLE),
				PBM_SETBARCOLOR, 0, _cl(COLOR_BTNSHADOW, DARK_CLR-20)
			);

			SendMessage(
				GetDlgItem(hwnd, IDP_BREAKABLE),
				PBM_SETRANGE, 0, MAKELPARAM(0, 193)
			);

			k = 0;
			while (static_head[k].id != -1) {

				SetWindowText(GetDlgItem(hwnd, static_head[k].id), static_head[k].display);
				SendMessage(GetDlgItem(hwnd, static_head[k].id), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0);
				k++;
			}

			k = 0;
			while (check_init[k] != -1) {

				_sub_class(GetDlgItem(hwnd, check_init[k]), SUB_STATIC_PROC, HWND_NULL);
				_set_check(hwnd, check_init[k], FALSE);
				k++;
			}	
			SetForegroundWindow(hwnd);
			return 1L;

		}
		break;
		case WM_USER_CLICK : 
		{
			if ( (HWND)wparam == GetDlgItem(hwnd, IDC_CHECK_SHOW_CURRENT) )
			{
				SendMessage(GetDlgItem(hwnd, IDE_PASS_CURRENT), 
					EM_SETPASSWORDCHAR, _get_check(hwnd, IDC_CHECK_SHOW_CURRENT) ? 0 : '*', 0
					);

				InvalidateRect(GetDlgItem(hwnd, IDE_PASS_CURRENT), NULL, TRUE);
				return 1L;

			}
			if ( (HWND)wparam == GetDlgItem(hwnd, IDC_CHECK_SHOW_NEW) )
			{
				int mask = _get_check(hwnd, IDC_CHECK_SHOW_NEW) ? 0 : '*';

				SendMessage(GetDlgItem(hwnd, IDE_PASS_NEW), EM_SETPASSWORDCHAR,	mask, 0);
				SendMessage(GetDlgItem(hwnd, IDE_PASS_NEW_CONFIRM), EM_SETPASSWORDCHAR,	mask, 0);

				InvalidateRect(GetDlgItem(hwnd, IDE_PASS_NEW), NULL, TRUE);
				InvalidateRect(GetDlgItem(hwnd, IDE_PASS_NEW_CONFIRM), NULL, TRUE);
				return 1L;

			}
			if ( (HWND)wparam == GetDlgItem(hwnd, IDC_USE_KEYFILES_CURRENT) ) 
			{
				SendMessage(
					hwnd, WM_COMMAND, MAKELONG(IDE_PASS_CURRENT, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_CURRENT)
					);
				EnableWindow(
					GetDlgItem(hwnd, IDB_USE_KEYFILES_CURRENT), _get_check(hwnd, IDC_USE_KEYFILES_CURRENT)
					);
				return 1L;
			}
			if ( (HWND)wparam == GetDlgItem(hwnd, IDC_USE_KEYFILES_NEW) ) 
			{
				SendMessage(
					hwnd, WM_COMMAND, MAKELONG(IDE_PASS_NEW, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_NEW)
					);
				EnableWindow(
					GetDlgItem(hwnd, IDB_USE_KEYFILES_NEW), _get_check(hwnd, IDC_USE_KEYFILES_NEW
					));
				return 1L;
			}
		}
		break;
		case WM_COMMAND :

			if ( id == IDB_USE_KEYFILES_CURRENT )
			{
				_dlg_keyfiles( hwnd, KEYLIST_CURRENT );

				SendMessage(
					hwnd, WM_COMMAND, MAKELONG(IDE_PASS_CURRENT, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_CURRENT)
					);
			}
			if ( id == IDB_USE_KEYFILES_NEW )
			{
				_dlg_keyfiles( hwnd, KEYLIST_CHANGE_PASS );

				SendMessage(
					hwnd, WM_COMMAND, MAKELONG(IDE_PASS_NEW, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_NEW)
					);
			}

			if ( code == EN_CHANGE ) 
			{
				BOOL correct_current, correct_new;
				int  id_stat_current, id_stat_new;

				dc_pass *pass;
				dc_pass *verify;

				ldr_config conf;

				int kb_layout = -1;
				int keylist;

				if ( info->node && _is_boot_device(&info->node->mnt.info) )
				{
					if (dc_get_mbr_config( -1, NULL, &conf ) == ST_OK)
					{
						kb_layout = conf.kbd_layout;
					}
				}
				if ( id == IDE_PASS_NEW )
				{
					int entropy;
					dc_pass *pass;

					pass = _get_pass(hwnd, IDE_PASS_NEW);

					_draw_pass_rating(hwnd, pass, kb_layout, &entropy);
					secure_free(pass);

					SendMessage(
						GetDlgItem(hwnd, IDP_BREAKABLE),
						PBM_SETPOS,
						(WPARAM)entropy, 0
						);
				}
				
				pass    = _get_pass(hwnd, IDE_PASS_CURRENT);
				keylist = _get_check(hwnd, IDC_USE_KEYFILES_CURRENT) ? KEYLIST_CURRENT : KEYLIST_NONE;

				correct_current = 
					_input_verify(pass, NULL, keylist, -1, &id_stat_current
				);

				secure_free(pass);

				pass    = _get_pass(hwnd, IDE_PASS_NEW);
				verify  = _get_pass(hwnd, IDE_PASS_NEW_CONFIRM);
				keylist = _get_check(hwnd, IDC_USE_KEYFILES_NEW) ? KEYLIST_CHANGE_PASS : KEYLIST_NONE;

				correct_new =
					_input_verify(pass, verify, keylist, kb_layout, &id_stat_new
					);

				secure_free(pass);
				secure_free(verify);				

				SetWindowText(GetDlgItem(hwnd, IDC_PASS_STATUS_CURRENT), _get_text_name(id_stat_current, pass_status));
				SetWindowText(GetDlgItem(hwnd, IDC_PASS_STATUS_NEW), _get_text_name(id_stat_new, pass_status));

				EnableWindow(GetDlgItem(hwnd, IDOK), correct_current && correct_new);

				return 1L;
		
			}
			if ( (id == IDCANCEL) || (id == IDOK) )
			{
				if ( id == IDOK )
				{
					info->pass     = _get_pass_keyfiles(hwnd, IDE_PASS_CURRENT, IDC_USE_KEYFILES_CURRENT, KEYLIST_CURRENT);
					info->new_pass = _get_pass_keyfiles(hwnd, IDE_PASS_NEW,     IDC_USE_KEYFILES_NEW,     KEYLIST_CHANGE_PASS);

					if ( IsWindowEnabled(GetDlgItem(hwnd, IDC_COMBO_MNPOINT)) && 
						 info->mnt_point
						 )
					{
						GetWindowText(
							GetDlgItem(hwnd, IDC_COMBO_MNPOINT), 
							(wchar_t *)info->mnt_point, 
							MAX_PATH
							);
					}
				}
				EndDialog (hwnd, id);
				return 1L;
	
			}
		break;
		case WM_DESTROY: 
		{
			_wipe_pass_control(hwnd, IDE_PASS_NEW_CONFIRM);
			_wipe_pass_control(hwnd, IDE_PASS_CURRENT);
			_wipe_pass_control(hwnd, IDE_PASS_NEW);		

			_keyfiles_wipe(KEYLIST_CURRENT);
			_keyfiles_wipe(KEYLIST_CHANGE_PASS);

			return 0L;
		}
		break;
		default:
		{
			int rlt = _draw_proc(message, lparam);
			if (rlt != -1) return rlt;
		}
	}
	return 0L;

}
Exemple #22
0
INT_PTR CALLBACK
_password_dlg_proc(
		HWND	hwnd,
		UINT	message,
		WPARAM	wparam,
		LPARAM	lparam
	)
{
	WORD code	= HIWORD(wparam);
	WORD id		= LOWORD(wparam);

	wchar_t display[MAX_PATH] = { 0 };
	static dlgpass *info;

	static RECT rc_left  = { 0, 0, 0, 0 };
	static RECT rc_right = { 0, 0, 0, 0 };

	static cut;
	switch ( message )
	{
		case WM_DRAWITEM : 
		{
			DRAWITEMSTRUCT *draw = pv(lparam);

			static RECT left;
			static RECT right;

			switch ( draw->CtlID )
			{
				case IDC_FRAME_LEFT: 
				{
					if ( !rc_left.right )
					{
						_relative_rect( draw->hwndItem, &rc_left );
						rc_left.bottom -= cut;
					}
					MoveWindow(
						draw->hwndItem, rc_left.left, rc_left.top, rc_left.right, rc_left.bottom, TRUE
						);
				}
				break;
				case IDC_FRAME_RIGHT:
				{					
					if ( !rc_right.right )
					{
						_relative_rect( draw->hwndItem, &rc_right );
						rc_right.bottom -= cut;
					}
					MoveWindow(
						draw->hwndItem, rc_right.left, rc_right.top, rc_right.right, rc_right.bottom, TRUE
						);
				}
				break;
			}
			_draw_static( draw );
			return 1L;		
		}
		break;
		case WM_CTLCOLOREDIT : 
		{
			return (
				_ctl_color( wparam, _cl(COLOR_BTNFACE, LGHT_CLR) )
			);
		}
		break;
		case WM_INITDIALOG : 
		{
			int ctl_resize[ ] = {
				IDC_FRAME_LEFT,
				IDC_FRAME_RIGHT,
				-1
			};

			info = (dlgpass *)lparam;			
			_init_mount_points( GetDlgItem(hwnd, IDC_COMBO_MNPOINT) );

			SendMessage( GetDlgItem(hwnd, IDC_COMBO_MNPOINT), CB_SETCURSEL, 1, 0 );
			SendMessage( GetDlgItem(hwnd, IDE_PASS), EM_LIMITTEXT, MAX_PASSWORD, 0 );

			if ( info->node )
			{
				_snwprintf(
					display, sizeof_w(display), L"[%s] - %s", 
					info->node->mnt.info.status.mnt_point, info->node->mnt.info.device
					);
			} else
			{
				wcscpy(display, L"Enter password");
			}

			SetWindowText( hwnd, display );

			SetWindowText( GetDlgItem(hwnd, IDC_HEAD_PASS), L"# Current Password" );
			SendMessage( GetDlgItem(hwnd, IDC_HEAD_PASS), WM_SETFONT, (WPARAM)__font_bold, 0 );

			SetWindowText( GetDlgItem(hwnd, IDC_HEAD_MOUNT_OPTIONS), L"# Mount Options" );
			SendMessage( GetDlgItem(hwnd, IDC_HEAD_MOUNT_OPTIONS), WM_SETFONT, (WPARAM)__font_bold, 0 );

			_sub_class( GetDlgItem(hwnd, IDC_CHECK_SHOW), SUB_STATIC_PROC, HWND_NULL );
			_set_check( hwnd, IDC_CHECK_SHOW, FALSE );

			_sub_class( GetDlgItem(hwnd, IDC_USE_KEYFILES), SUB_STATIC_PROC, HWND_NULL );
			_set_check( hwnd, IDC_USE_KEYFILES, FALSE );

			{
				HWND mnt_combo = GetDlgItem( hwnd, IDC_COMBO_MNPOINT );
				HWND mnt_check = GetDlgItem( hwnd, IDC_CHECK_MNT_SET );
				HWND mnt_label = GetDlgItem( hwnd, IDC_MNT_POINT );

				BOOL enable;
				RECT rc_main;

				GetWindowRect(hwnd, &rc_main);
				enable = info->node && ( info->node->mnt.info.status.mnt_point[0] == L'\\' );

				EnableWindow( mnt_combo, enable );
				EnableWindow( mnt_check, enable );
				EnableWindow( mnt_label, enable );

				_sub_class( GetDlgItem(hwnd, IDC_CHECK_MNT_SET), SUB_STATIC_PROC, HWND_NULL );
				_set_check( hwnd, IDC_CHECK_MNT_SET, enable );

			}
			SendMessage(
				hwnd, WM_COMMAND, MAKELONG(IDE_PASS, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS)
				);

			SetForegroundWindow(hwnd);
			return 1L;

		}
		break;
		case WM_USER_CLICK : 
		{
			if ( (HWND)wparam == GetDlgItem(hwnd, IDC_CHECK_MNT_SET) )
			{
				EnableWindow(
					GetDlgItem(hwnd, IDC_COMBO_MNPOINT), _get_check(hwnd, IDC_CHECK_MNT_SET)
					);
				EnableWindow(
					GetDlgItem(hwnd, IDC_MNT_POINT), _get_check(hwnd, IDC_CHECK_MNT_SET)
					);
				return 1L;
			}

			if ( (HWND)wparam == GetDlgItem(hwnd, IDC_CHECK_SHOW) )
			{
				int mask = _get_check(hwnd, IDC_CHECK_SHOW) ? 0 : '*';

				SendMessage(GetDlgItem(hwnd, IDE_PASS), EM_SETPASSWORDCHAR, mask, 0 );
				InvalidateRect(GetDlgItem(hwnd, IDE_PASS), NULL, TRUE);

				return 1L;
			}

			if ( (HWND)wparam == GetDlgItem(hwnd, IDC_USE_KEYFILES) ) 
			{
				SendMessage(
					hwnd, WM_COMMAND, 
					MAKELONG(IDE_PASS, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS)
					);

				EnableWindow(GetDlgItem(hwnd, IDB_USE_KEYFILES), _get_check(hwnd, IDC_USE_KEYFILES));
				return 1L;
			}
		}
		break;
		case WM_COMMAND :

			if ( id == IDB_USE_KEYFILES )
			{
				_dlg_keyfiles(hwnd, KEYLIST_CURRENT);

				SendMessage(
					hwnd, WM_COMMAND, MAKELONG(IDE_PASS, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS)
					);
			}

			if ( code == CBN_SELCHANGE && id == IDC_COMBO_MNPOINT )
			{
				if ( SendMessage((HWND)lparam, CB_GETCURSEL, 0, 0) == 0 )
				{
					HWND h_combo = GetDlgItem(hwnd, IDC_COMBO_MNPOINT);

					int sel_item = 1;
					wchar_t path[MAX_PATH];

					if ( _folder_choice(hwnd, path, L"Choice folder for mount point") )
					{
						sel_item = (int)SendMessage(h_combo, CB_GETCOUNT, 0, 0);
						SendMessage(h_combo, CB_ADDSTRING, 0, (LPARAM)path);						
					}
					SendMessage(h_combo, CB_SETCURSEL, sel_item, 0);

				}
			}
			if (code == EN_CHANGE)
			{
				BOOL correct;
				int idx_status;

				dc_pass *pass = _get_pass(hwnd, IDE_PASS);
				int keylist = _get_check(hwnd, IDC_USE_KEYFILES) ? KEYLIST_CURRENT : KEYLIST_NONE;

				correct = 
					_input_verify(pass, NULL, keylist, -1, &idx_status
				);

				secure_free(pass);

				SetWindowText(GetDlgItem(hwnd, IDC_PASS_STATUS), _get_text_name(idx_status, pass_status));
				EnableWindow(GetDlgItem(hwnd, IDOK), correct);

				return 1L;
		
			}
			if ((id == IDCANCEL) || (id == IDOK)) 
			{
				if (id == IDOK)
				{
					info->pass = _get_pass_keyfiles(hwnd, IDE_PASS, IDC_USE_KEYFILES, KEYLIST_CURRENT);

					if (IsWindowEnabled(GetDlgItem(hwnd, IDC_COMBO_MNPOINT)) && 
							info->mnt_point) 
					{
						GetWindowText(
								GetDlgItem(hwnd, IDC_COMBO_MNPOINT), 
								(wchar_t *)info->mnt_point, 
								MAX_PATH
						);
					}
				}
				EndDialog (hwnd, id);
				return 1L;
	
			}
		break;
		case WM_DESTROY: 
		{
			_wipe_pass_control(hwnd, IDE_PASS);
			_keyfiles_wipe(KEYLIST_CURRENT);

			memset(&rc_right, 0, sizeof(rc_right));
			memset(&rc_left, 0, sizeof(rc_left));

			cut = 0;
			return 0L;

		}
		break;
		case WM_MEASUREITEM: 
		{
			MEASUREITEMSTRUCT *item = pv(lparam);

			if (item->CtlType != ODT_LISTVIEW)
				item->itemHeight -= 3;
 
		}
		break; 
	}
	return 0L;

}
Exemple #23
0
static bool
wallet_alloc_key(struct wallet *wallet,
                 const char    *priv,
                 const char    *pub,
                 const char    *desc,
                 time_t         birth,
                 bool           spendable)
{
   struct wallet_key *wkey;
   struct key *key;
   uint160 pub_key;
   size_t len;
   uint8 *buf;
   bool s;

   ASSERT(priv);

   key = NULL;
   buf = NULL;
   len = 0;
   memset(&pub_key, 0, sizeof pub_key);

   if (btc->wallet_state == WALLET_ENCRYPTED_LOCKED) {
      if (wallet->pass) {
         struct secure_area *sec_b58;
         uint8 *encPrivKey;
         size_t encLen;

         if (!wallet_verify_hmac(wallet, priv, &encPrivKey, &encLen)) {
            return 0;
         }

         s = crypt_decrypt(wallet->ckey, encPrivKey, encLen, &sec_b58);
         free(encPrivKey);
         ASSERT(s);
         /*
          * 'buf' is a sensitive buffer here. It should be backed by
          * a struct secure_area.
          */
         s = b58_privkey_to_bytes((char *)sec_b58->buf, &buf, &len);
         secure_free(sec_b58);
         ASSERT(s);
      } else {
         uint8 *pkey;
         size_t plen;

         str_to_bytes(pub, &pkey, &plen);
         hash160_calc(pkey, plen, &pub_key);
         free(pkey);
      }
   } else {
      s = b58_privkey_to_bytes(priv, &buf, &len);
      ASSERT(s);
   }

   if (buf) {
      key = key_alloc();
      key_set_privkey(key, buf, len);
      memset(buf, 0, len);
      free(buf);
      key_get_pubkey_hash160(key, &pub_key);
   }
   ASSERT(!uint160_iszero(&pub_key));

   wkey = safe_calloc(1, sizeof *wkey);
   wkey->cfg_idx   = hashtable_getnumentries(wallet->hash_keys);
   wkey->btc_addr  = b58_pubkey_from_uint160(&pub_key);
   wkey->desc      = desc ? safe_strdup(desc) : NULL;
   wkey->pub_key   = pub_key;
   wkey->birth     = birth;
   wkey->key       = key;
   wkey->spendable = spendable;

   if (spendable == 0) {
      Log(LGPFX" funds on %s are not spendable.\n", wkey->btc_addr);
   }

   s = hashtable_insert(wallet->hash_keys, &pub_key, sizeof pub_key, wkey);
   ASSERT(s);

   return 1;
}