Esempio n. 1
0
int
bullet_start()
{
    long	free;		/* # units of resource still free */

    /* Now that we can start ... */
    message("BULLET SERVER STARTUP");

    if (a_begin(A_DISKBLOCKS, (Res_addr) Superblock.s_inodetop + 1,
				    (Res_addr) Superblock.s_numblocks) < 0)
    {
	bpanic("Cannot begin resource allocator for disk blocks.\n");
    }

    /* Convert file get-port to put-port */
    priv2pub(&Superblock.s_fileport,&FilePutPort) ;

    /* Get the inode table and start inode allocator */
    /* Could have been done by setinodes() as a result of a welcome */
    if ( !Inode_table) inode_init();

    /* Work out which inodes and disk blocks are in use. */
    build_free_list();

    message("%ld inodes free, %ld inodes used",
				bs_local_inodes_free,
				- 1);
    if ((free = a_notused(A_DISKBLOCKS)) < 0) {
	bpanic("Defective diskblock free list\n");
    }
    message("%ld disk blocks free, %ld disk blocks used",
				free, Superblock.s_numblocks - free);
    return 1 ;
}
Esempio n. 2
0
/*
 * Initialize the TTY structures.
 */
void
tty_init()
{
    int i;
    TScreen *screen = &term->screen;

    dbprintf(("tty_init.."));
    if (tty_inited) {
	return;
    }
    tty_inited = 1;

    mu_init(&read_mutex);
    mu_init(&write_mutex);

    uniqport(&ttyport);
    priv2pub(&ttyport, &ttycap.cap_port);

    tios.c_iflag = ICRNL | IXON;
    tios.c_oflag = OPOST;
    tios.c_cflag = CREAD | CS8 | B9600;
    tios.c_lflag = ECHO | ECHOE | ECHOK | ICANON | ISIG;

    tios.c_cc[VEOF] = CTRL('D');
    tios.c_cc[VEOL] = _POSIX_VDISABLE;
    tios.c_cc[VERASE] = CTRL('H');
    tios.c_cc[VINTR] = CTRL('C');
    tios.c_cc[VKILL] = CTRL('U');
    tios.c_cc[VMIN] = 1;
    tios.c_cc[VQUIT] = CTRL('\\');
    tios.c_cc[VSUSP] = _POSIX_VDISABLE;
    tios.c_cc[VTIME] = 0;
    tios.c_cc[VSTART] = CTRL('Q');
    tios.c_cc[VSTOP] = CTRL('S');

    screen->tty_inq = cb_alloc(TTY_INQSIZE);
    screen->tty_outq = cb_alloc(TTY_OUTQSIZE);
    screen->max_col = def_cols;
    screen->max_row = def_rows;

    /*
     * Start tty threads. Ordinarily two should suffice, one for standard
     * input and one for standard (error) output.
     */
    for (i = 0; i < TTY_NTHREADS; i++) {
	if (!thread_newthread(ttythread, TTY_THREAD_STACKSIZE, (char*) 0, 0)) {
	    FatalError("unable to start tty thread.");
	}
    }
}
Esempio n. 3
0
void flip_ip_svr_init()
{
	capability fis_cap;
	errstat result;

#if DEBUG & 2
 { where(); printf("flip_ip_svr_init called\n"); }
#endif

	uniqport(&fis_priv_port);
	priv2pub(&fis_priv_port, &fis_pub_port);
	uniqport(&fis_random);

	NewKernelThread(flip_ip_svr, FIS_STACK);

	fis_cap.cap_port= fis_pub_port;
	result= prv_encode(&fis_cap.cap_priv, (objnum)0, FIS_RIGHTS, 
		&fis_random);
	if (result)
		panic(( "unable to initialize capability" ));

	dirappend(FIS_NAME, &fis_cap);
}
Esempio n. 4
0
void pki_evp::encryptKey(const char *password)
{
	int outl, keylen;
	EVP_PKEY *pkey1 = NULL;
	EVP_CIPHER_CTX ctx;
	const EVP_CIPHER *cipher = EVP_des_ede3_cbc();
	unsigned char iv[EVP_MAX_IV_LENGTH], *punenc, *punenc1;
	unsigned char ckey[EVP_MAX_KEY_LENGTH];
	char ownPassBuf[MAX_PASS_LENGTH];

	/* This key has its own, private password */
	if (ownPass == ptPrivate) {
		int ret;
		pass_info p(XCA_TITLE, tr("Please enter the password to protect the private key: '%1'").
			arg(getIntName()));
		ret = MainWindow::passWrite(ownPassBuf, MAX_PASS_LENGTH, 0, &p);
		if (ret < 0)
			throw errorEx("Password input aborted", class_name);
	} else if (ownPass == ptBogus) { // BOGUS password
		ownPassBuf[0] = '\0';
	} else {
		if (password) {
			/* use the password parameter if this is a common password */
			strncpy(ownPassBuf, password, MAX_PASS_LENGTH);
		} else {
			int ret = 0;
			memcpy(ownPassBuf, passwd, MAX_PASS_LENGTH);
			pass_info p(XCA_TITLE, tr("Please enter the database password for encrypting the key"));
			while (md5passwd(ownPassBuf) != passHash &&
				sha512passwd(ownPassBuf, passHash) != passHash )
			{
				ret = MainWindow::passRead(ownPassBuf, MAX_PASS_LENGTH, 0,&p);
				if (ret < 0)
					throw errorEx("Password input aborted", class_name);
			}
		}
	}

	/* Prepare Encryption */
	memset(iv, 0, EVP_MAX_IV_LENGTH);
	RAND_pseudo_bytes(iv,8);      /* Generate a salt */
	EVP_BytesToKey(cipher, EVP_sha1(), iv, (unsigned char *)ownPassBuf,
			strlen(ownPassBuf), 1, ckey, NULL);
	EVP_CIPHER_CTX_init (&ctx);
	pki_openssl_error();

	/* reserve space for unencrypted and encrypted key */
	keylen = i2d_PrivateKey(key, NULL);
	encKey.resize(keylen + EVP_MAX_KEY_LENGTH + 8);
	punenc1 = punenc = (unsigned char *)OPENSSL_malloc(keylen);
	check_oom(punenc);
	keylen = i2d_PrivateKey(key, &punenc1);
	pki_openssl_error();

	memcpy(encKey.data(), iv, 8); /* store the iv */
	/*
	 * Now DER version of privkey is in punenc
	 * and privkey is still in key
	 */

	/* do the encryption */
	/* store key right after the iv */
	EVP_EncryptInit(&ctx, cipher, ckey, iv);
	unsigned char *penc = (unsigned char *)encKey.data() +8;
	EVP_EncryptUpdate(&ctx, penc, &outl, punenc, keylen);
	int encKey_len = outl;
	EVP_EncryptFinal(&ctx, penc + encKey_len, &outl);
	encKey.resize(encKey_len + outl +8);
	/* Cleanup */
	EVP_CIPHER_CTX_cleanup(&ctx);
	/* wipe out the memory */
	memset(punenc, 0, keylen);
	OPENSSL_free(punenc);
	pki_openssl_error();

	pkey1 = priv2pub(key);
	check_oom(pkey1);
	EVP_PKEY_free(key);
	key = pkey1;
	pki_openssl_error();

	//CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF);

	//printf("Encrypt: encKey_len=%d\n", encKey_len);
	return;
}