Exemplo n.º 1
0
krb5_error_code krb5int_hmacmd5_checksum(const struct krb5_cksumtypes *ctp,
                                         krb5_key key, krb5_keyusage usage,
                                         const krb5_crypto_iov *data,
                                         size_t num_data,
                                         krb5_data *output)
{
    krb5_keyusage ms_usage;
    krb5_error_code ret;
    krb5_keyblock ks, *keyblock;
    krb5_crypto_iov *hash_iov = NULL, iov;
    krb5_data ds = empty_data(), hashval = empty_data();
    char t[4];

    if (key == NULL || key->keyblock.length > ctp->hash->blocksize)
        return KRB5_BAD_ENCTYPE;
    if (ctp->ctype == CKSUMTYPE_HMAC_MD5_ARCFOUR) {
        /* Compute HMAC(key, "signaturekey\0") to get the signing key ks. */
        ret = alloc_data(&ds, ctp->hash->hashsize);
        if (ret != 0)
            goto cleanup;

        iov.flags = KRB5_CRYPTO_TYPE_DATA;
        iov.data = make_data("signaturekey", 13);
        ret = krb5int_hmac(ctp->hash, key, &iov, 1, &ds);
        if (ret)
            goto cleanup;
        ks.length = key->keyblock.length;
        ks.contents = (krb5_octet *) ds.data;
        keyblock = &ks;
    } else  /* For md5-hmac, just use the key. */
        keyblock = &key->keyblock;

    /* Compute the MD5 value of the input. */
    ms_usage = krb5int_arcfour_translate_usage(usage);
    store_32_le(ms_usage, t);
    hash_iov = k5alloc((num_data + 1) * sizeof(krb5_crypto_iov), &ret);
    if (hash_iov == NULL)
        goto cleanup;
    hash_iov[0].flags = KRB5_CRYPTO_TYPE_DATA;
    hash_iov[0].data = make_data(t, 4);
    memcpy(hash_iov + 1, data, num_data * sizeof(krb5_crypto_iov));
    ret = alloc_data(&hashval, ctp->hash->hashsize);
    if (ret != 0)
        goto cleanup;
    ret = ctp->hash->hash(hash_iov, num_data + 1, &hashval);
    if (ret != 0)
        goto cleanup;

    /* Compute HMAC(ks, md5value). */
    iov.flags = KRB5_CRYPTO_TYPE_DATA;
    iov.data = hashval;
    ret = krb5int_hmac_keyblock(ctp->hash, keyblock, &iov, 1, output);

cleanup:
    zapfree(ds.data, ds.length);
    zapfree(hashval.data, hashval.length);
    free(hash_iov);
    return ret;
}
Exemplo n.º 2
0
Arquivo: rd_cred.c Projeto: krb5/krb5
/*
 * Decrypt and decode the enc_part of a krb5_cred using the receiving subkey or
 * the session key of authcon.  If neither key is present, ctext->ciphertext is
 * assumed to be unencrypted plain text (RFC 6448).
 */
static krb5_error_code
decrypt_encpart(krb5_context context, krb5_enc_data *ctext,
                krb5_auth_context authcon, krb5_cred_enc_part **encpart_out)
{
    krb5_error_code ret;
    krb5_data plain = empty_data();
    krb5_boolean decrypted = FALSE;

    *encpart_out = NULL;

    if (authcon->recv_subkey == NULL && authcon->key == NULL)
        return decode_krb5_enc_cred_part(&ctext->ciphertext, encpart_out);

    ret = alloc_data(&plain, ctext->ciphertext.length);
    if (ret)
        return ret;
    if (authcon->recv_subkey != NULL) {
        ret = krb5_k_decrypt(context, authcon->recv_subkey,
                             KRB5_KEYUSAGE_KRB_CRED_ENCPART, 0, ctext, &plain);
        decrypted = (ret == 0);
    }
    if (!decrypted && authcon->key != NULL) {
        ret = krb5_k_decrypt(context, authcon->key,
                             KRB5_KEYUSAGE_KRB_CRED_ENCPART, 0, ctext, &plain);
        decrypted = (ret == 0);
    }
    if (decrypted)
        ret = decode_krb5_enc_cred_part(&plain, encpart_out);
    zapfree(plain.data, plain.length);
    return ret;
}
Exemplo n.º 3
0
/* Generate a response authenticator field. */
static krb5_error_code
auth_generate_response(krb5_context ctx, const char *secret,
                       const krad_packet *response, const uchar *auth,
                       uchar *rauth)
{
    krb5_error_code retval;
    krb5_checksum hash;
    krb5_data data;

    /* Allocate the temporary buffer. */
    retval = alloc_data(&data, response->pkt.length + strlen(secret));
    if (retval != 0)
        return retval;

    /* Encoded RADIUS packet with the request's
     * authenticator and the secret at the end. */
    memcpy(data.data, response->pkt.data, response->pkt.length);
    memcpy(data.data + OFFSET_AUTH, auth, AUTH_FIELD_SIZE);
    memcpy(data.data + response->pkt.length, secret, strlen(secret));

    /* Hash it. */
    retval = krb5_c_make_checksum(ctx, CKSUMTYPE_RSA_MD5, NULL, 0, &data,
                                  &hash);
    free(data.data);
    if (retval != 0)
        return retval;

    memcpy(rauth, hash.contents, AUTH_FIELD_SIZE);
    krb5_free_checksum_contents(ctx, &hash);
    return 0;
}
Exemplo n.º 4
0
scalar* mv3d(scalar* M,scalar* V,scalar* MV) {
    scalar m11,m21,m31,m41,m12,m22,m32,m42,m13,m23,m33,m43,m14,m24,m34,m44;
    scalar v1,v2,v3,v4;
    MV=MV?MV:alloc_data(4);
    m11=M[0];
    m21=M[1];
    m31=M[2];
    m41=M[3];
    m12=M[4];
    m22=M[5];
    m32=M[6];
    m42=M[7];
    m13=M[8];
    m23=M[9];
    m33=M[10];
    m43=M[11];
    m14=M[12];
    m24=M[13];
    m34=M[14];
    m44=M[15];
    v1=V[0];
    v2=V[1];
    v3=V[2];
    v4=V[3];
    MV[0]=m11*v1+m12*v2+m13*v3+m14*v4;
    MV[1]=m21*v1+m22*v2+m23*v3+m24*v4;
    MV[2]=m31*v1+m32*v2+m33*v3+m34*v4;
    MV[3]=m41*v1+m42*v2+m43*v3+m44*v4;
    return MV;
}
Exemplo n.º 5
0
Arquivo: mk_priv.c Projeto: krb5/krb5
/*
 * Marshal a KRB-PRIV message into der_out, encrypted with key.  Store the
 * ciphertext in enc_out.  Use the timestamp and sequence number from rdata and
 * the addresses from local_addr and remote_addr (the second of which may be
 * NULL).  der_out and enc_out should be freed by the caller when finished.
 */
static krb5_error_code
create_krbpriv(krb5_context context, const krb5_data *userdata,
               krb5_key key, const krb5_replay_data *rdata,
               krb5_address *local_addr, krb5_address *remote_addr,
               krb5_data *cstate, krb5_data *der_out, krb5_enc_data *enc_out)
{
    krb5_enctype enctype = krb5_k_key_enctype(context, key);
    krb5_error_code ret;
    krb5_priv privmsg;
    krb5_priv_enc_part encpart;
    krb5_data *der_encpart = NULL, *der_krbpriv;
    size_t enclen;

    memset(&privmsg, 0, sizeof(privmsg));
    privmsg.enc_part.kvno = 0;
    privmsg.enc_part.enctype = enctype;
    encpart.user_data = *userdata;
    encpart.s_address = local_addr;
    encpart.r_address = remote_addr;
    encpart.timestamp = rdata->timestamp;
    encpart.usec = rdata->usec;
    encpart.seq_number = rdata->seq;

    /* Start by encoding the to-be-encrypted part of the message. */
    ret = encode_krb5_enc_priv_part(&encpart, &der_encpart);
    if (ret)
        return ret;

    /* put together an eblock for this encryption */
    ret = krb5_c_encrypt_length(context, enctype, der_encpart->length,
                                &enclen);
    if (ret)
        goto cleanup;

    ret = alloc_data(&privmsg.enc_part.ciphertext, enclen);
    if (ret)
        goto cleanup;

    ret = krb5_k_encrypt(context, key, KRB5_KEYUSAGE_KRB_PRIV_ENCPART,
                         (cstate->length > 0) ? cstate : NULL, der_encpart,
                         &privmsg.enc_part);
    if (ret)
        goto cleanup;

    ret = encode_krb5_priv(&privmsg, &der_krbpriv);
    if (ret)
        goto cleanup;

    *der_out = *der_krbpriv;
    free(der_krbpriv);

    *enc_out = privmsg.enc_part;
    memset(&privmsg.enc_part, 0, sizeof(privmsg.enc_part));

cleanup:
    zapfree(privmsg.enc_part.ciphertext.data,
            privmsg.enc_part.ciphertext.length);
    zapfreedata(der_encpart);
    return ret;
}
int event_loop(SOCKET acceptor)
{
    struct sockaddr_in addr;
    int addrlen = sizeof(addr);
    SOCKET socknew = accept(acceptor, (struct sockaddr*)&addr, &addrlen);
    if (socknew != INVALID_SOCKET)
    {
        socket_data_t* data = alloc_data(socknew);
        fprintf(stderr, ("socket %d accepted at %s.\n"), socknew, Now());
        if (data)
        {
            post_recv_request(data);
        }
    }
    else
    {
        if (WSAGetLastError() != WSAEWOULDBLOCK)
        {
            fprintf(stderr, ("accept() failed, %s"), LAST_ERROR_MSG);
            return 0;
        }
        else
        {
            SleepEx(50, TRUE); /* make current thread alertable */
        }
    }
    return 1;
}
Exemplo n.º 7
0
/***********************************************************************//**
 * @brief Copy class members
 *
 * @param[in] column Table column.
 *
 * Sets the content of the vector column by copying from another column.
 * If the code is compiled with the small memory option, and if the source
 * column has not yet been loaded, then we only load the column temporarily
 * for copying purposes and release it again once copying is finished.
 ***************************************************************************/
void GFitsTableFloatCol::copy_members(const GFitsTableFloatCol& column)
{
    // Fetch column data if not yet fetched. The casting circumvents the
    // const correctness
    bool not_loaded = (column.m_data == NULL);
    if (not_loaded) {
        const_cast<GFitsTableFloatCol*>(&column)->fetch_data();
    }

    // Copy attributes
    m_type = column.m_type;
    m_size = column.m_size;

    // Copy column data
    if (column.m_data != NULL && m_size > 0) {
        alloc_data();
        for (int i = 0; i < m_size; ++i) {
            m_data[i] = column.m_data[i];
        }
    }

    // Copy NULL value
    alloc_nulval(column.m_nulval);

    // Small memory option: release column if it was fetch above
#if defined(G_SMALL_MEMORY)
    if (not_loaded) {
        const_cast<GFitsTableFloatCol*>(&column)->release_data();
    }
#endif

    // Return
    return;
}
Exemplo n.º 8
0
void initSFS(int dev)
{ //Assuming only predefined sizes are used
    char buf[4096];
    int i;
    init_superblock(&sb);
    write(devfd[dev],(&sb),BLOCK);
    init_inodetable(&inodetable);
    //initialising root directory inode
    head=init_inode(getinode(dev),1,1,BLOCK,IS_DIR,6);  //4+2=>read+write
      tail=head;
      head->INODE->i_blocks[0]=alloc_data(dev);
      strcpy(dentry.dirname,".");
      dentry.i_node=head->i_node;
      head->INODE->file_size=sizeof(dentry);
      write(devfd[dev],head->INODE,sizeof(head->INODE));
    for(i=1;i<INODETABSIZE;i++)
        write(devfd[dev],&inodetable,sizeof(inodetable));
      //   printf("%d\n",p);
    bzero(buf,PAGECOMP);
    write(devfd[dev],buf,PAGECOMP);
    write(devfd[dev],&dentry,BLOCK);
    head->offset=sizeof(dentry);
    for(i=1;i<DATABLOCK;i++)
    {
        if(i==DATABLOCK-1)
            db.next=-1;
        else
            db.next=i+1;
            db.cur=i;
        write(devfd[dev],&db,BLOCK);
    }
}
Exemplo n.º 9
0
scalar* transpose(int m,int n, scalar* A,scalar* AT){
	int i;
	AT=AT?AT:alloc_data(n*m);
	i=m;
	while(i--){		set_values(n,A+i*n,1,AT+i,m);	 } /* AT[*i]=A[i*] */
	return AT;
}
Exemplo n.º 10
0
scalar* gemm(int m,int n,int k,scalar* A, scalar* B,scalar* AB){
	int i;
	AB=AB?AB:alloc_data(m*k);
	i=k;
	while(i--){ gemv(m,n,A,B+i,k,AB+i,k);	} /* AB[*i]=A*B[*i] */
	return AB;
}
Exemplo n.º 11
0
/*
 * Compute a derived key into the keyblock outkey.  This variation on
 * krb5int_derive_key does not cache the result, as it is only used
 * directly in situations which are not expected to be repeated with
 * the same inkey and constant.
 */
krb5_error_code
krb5int_derive_keyblock(const struct krb5_enc_provider *enc,
                        krb5_key inkey, krb5_keyblock *outkey,
                        const krb5_data *in_constant)
{
    krb5_error_code ret;
    krb5_data rawkey = empty_data();

    /* Allocate a buffer for the raw key bytes. */
    ret = alloc_data(&rawkey, enc->keybytes);
    if (ret)
        goto cleanup;

    /* Derive pseudo-random data for the key bytes. */
    ret = krb5int_derive_random(enc, inkey, &rawkey, in_constant);
    if (ret)
        goto cleanup;

    /* Postprocess the key. */
    ret = enc->make_key(&rawkey, outkey);

cleanup:
    zapfree(rawkey.data, enc->keybytes);
    return ret;
}
Exemplo n.º 12
0
static krb5_error_code
nonce_generate(krb5_context ctx, unsigned int length, krb5_data *nonce_out)
{
    krb5_data nonce;
    krb5_error_code retval;
    krb5_timestamp now;

    retval = krb5_timeofday(ctx, &now);
    if (retval != 0)
        return retval;

    retval = alloc_data(&nonce, sizeof(now) + length);
    if (retval != 0)
        return retval;

    retval = krb5_c_random_make_octets(ctx, &nonce);
    if (retval != 0) {
        free(nonce.data);
        return retval;
    }

    store_32_be(now, nonce.data);
    *nonce_out = nonce;
    return 0;
}
Exemplo n.º 13
0
/**
 * gwy_surface_new_part:
 * @surface: A surface.
 * @xfrom: Minimum x-coordinate value.
 * @xto: Maximum x-coordinate value.
 * @yfrom: Minimum y-coordinate value.
 * @yto: Maximum y-coordinate value.
 *
 * Creates a new surface as a part of another surface.
 *
 * The new surface consits of data with lateral coordinates within the
 * specified ranges (inclusively).  It may be empty.
 *
 * Data are physically copied, i.e. changing the new surface data does not
 * change @surface's data and vice versa.
 *
 * Returns: A new surface.
 *
 * Since: 2.45
 **/
GwySurface*
gwy_surface_new_part(GwySurface *surface,
                     gdouble xfrom,
                     gdouble xto,
                     gdouble yfrom,
                     gdouble yto)
{
    GwySurface *part;
    guint n, i;

    g_return_val_if_fail(GWY_IS_SURFACE(surface), NULL);

    part = gwy_surface_new_alike(surface);
    if (!surface->n || xfrom > xto || yfrom > yto)
        return part;

    n = 0;
    for (i = 0; i < surface->n; i++) {
        gdouble x = surface->data[i].x, y = surface->data[i].y;
        if (x >= xfrom && x <= xto && y >= yfrom && y <= yto)
            n++;
    }
    part->n = n;
    alloc_data(part);

    n = 0;
    for (i = 0; i < surface->n; i++) {
        gdouble x = surface->data[i].x, y = surface->data[i].y;
        if (x >= xfrom && x <= xto && y >= yfrom && y <= yto)
            part->data[n++] = surface->data[i];
    }

    return part;
}
Exemplo n.º 14
0
/***********************************************************************//**
 * @brief Construct data from array
 *
 * @param[in] pixels Optional pointer to pixel array.
 *
 * Initialise pixel data from an optional pixel array. If the pointer is
 * NULL the image is simply initialised. This method supports all
 * constructors.
 ***************************************************************************/
void GFitsImageDouble::construct_data(const double* pixels)
{
    // If there are pixels then allocate array
    if (m_num_pixels > 0) {

        // Allocate data
        alloc_data();

        // If no pixel array has been specified then simply initialise data
        if (pixels == NULL) {
            init_data();
        }

        // ... otherwise copy pixels
        else {
            for (int i = 0; i < m_num_pixels; ++i) {
                m_pixels[i] = pixels[i];
            }
        }

    } // endif: there are pixels in image

    // Return
    return;
}
Exemplo n.º 15
0
void do_mkdir()
{
    struct inode cur_dir,new_dir;
    char dirname[256];
    struct dir_ent ent;
    scanf("%s",dirname);
    if(strcmp(dirname,".")==0 || strcmp(dirname,"..")==0)
    {
        printf("Error directory name.\n");        
        return ;
    }
    get_inode(pwd,&cur_dir);  
        /*分配一个inode给新的目录*/
    new_dir.i_num=alloc_inode();
    new_dir.i_start_sect=alloc_data();        /*分配一个数据扇区*/
    new_dir.i_nr_sects=1;
    
    new_dir.i_pnum=pwd;
    new_dir.i_mode=2;
    new_dir.i_size=0;

        //给新目录增加默认目录项
    ent.i_num=pwd;    strcpy(ent.name,"..");
    add_entry(&new_dir,&ent);
    ent.i_num=new_dir.i_num;  strcpy(ent.name,".");
    add_entry(&new_dir,&ent);  
 
    ent.i_num=new_dir.i_num;    strcpy(ent.name,dirname);     
    add_entry(&cur_dir,&ent);
    //写入inode数组中
    write_inode(pwd,&cur_dir);
    write_inode(new_dir.i_num,&new_dir); 
}
Exemplo n.º 16
0
void redraw(HWND hwnd, HDC dc)
{
    DWORD t1, t2;
    char s[2000];

    unsigned ASX = align(SX);

    if (!image_valid) {
        alloc_data();
        t1 = GetTickCount ();
        calculate_multi();
        t2 = GetTickCount();
        sprintf (s, "Mandelbrot Set %s; Image: %d x %d; (%f, %f, d=%g) time: %d ms; %d cores; %5.1f FPS%s", method_names [func_index], ASX, SY,
            X0, Y0, scale,
            (t2 - t1),
            processor_count,
            1000.0 / (t2 - t1),
            full_mode ? "; ALL MODES" : "");
        SetWindowText(hwnd, s);
        image_valid = TRUE;
    }
    bi.h.biWidth = ASX;
    bi.h.biHeight = -(LONG)SY;
    SetDIBitsToDevice(dc, 0, 0, ASX, SY, 0, 0, 0, SY, data, (BITMAPINFO*)&bi, DIB_RGB_COLORS);
}
Exemplo n.º 17
0
scalar* make_rotate(scalar* mat,scalar x,scalar y, scalar z, scalar ang) {
    scalar n,s,c;
    n=sqrt(x*x+y*y+z*z);
    s=sin(ang);
    c=cos(ang);
    x=x/n;
    y=y/n;
    z=z/n;
    mat=mat?mat:alloc_data(16);
    mat[0]=x*x*(1-c)+c;
    mat[4]=x*y*(1-c)-z*s;
    mat[8]=x*z*(1-c)+y*s;
    mat[12]=0;
    mat[1]=x*y*(1-c)+z*s;
    mat[5]=y*y*(1-c)+c;
    mat[9]=y*z*(1-c)-x*s;
    mat[13]=0;
    mat[2]=x*z*(1-c)-y*s;
    mat[6]=y*z*(1-c)+x*s;
    mat[10]=z*z*(1-c)+c;
    mat[14]=0;
    mat[3]=0;
    mat[7]=0	;
    mat[11]=0;
    mat[15]=1;
    return mat;
}
Exemplo n.º 18
0
static krb5_error_code
decrypt_encdata(krb5_context context, krb5_keyblock *armor_key,
                krb5_pa_otp_req *req, krb5_data *out)
{
    krb5_error_code retval;
    krb5_data plaintext;

    if (req == NULL)
        return EINVAL;

    retval = alloc_data(&plaintext, req->enc_data.ciphertext.length);
    if (retval)
        return retval;

    retval = krb5_c_decrypt(context, armor_key, KRB5_KEYUSAGE_PA_OTP_REQUEST,
                            NULL, &req->enc_data, &plaintext);
    if (retval != 0) {
        com_err("otp", retval, "Unable to decrypt encData in PA-OTP-REQUEST");
        free(plaintext.data);
        return retval;
    }

    *out = plaintext;
    return 0;
}
Exemplo n.º 19
0
Arquivo: init.c Projeto: Thog/wolf3d
t_env					*init_data(char *file)
{
	int					fd;
	int					error;
	t_env				*env;

	error = 0;
	fd = open(file, O_RDONLY);
	if (alloc_data(&env))
		error = ft_error_retint("Cannot allocate memory for env struct!\n", 1);
	if (fd == -1)
		error = ft_error_retint("File not found\n", 1);
	if (!error)
	{
		if (!(error = parse_header(env, fd)))
			ft_printf("xSize: %u, ySize: %u, blockSize: %u\n", env->map_x + 1,
					env->map_y + 1, env->block_size);
		env->player->dir_x = DIR_X;
		env->player->dir_y = DIR_Y;
		env->player->speed_move = SPEED_MOVE;
		env->player->speed_rotate = SPEED_ROTATE;
		env->camera->plane_x = CAM_X;
		env->camera->plane_y = CAM_Y;
		error = error ? error : parse_map(env, fd);
	}
	close(fd);
	return (error ? NULL : env);
}
Exemplo n.º 20
0
/*
 * Convert a krb5_principal into the default salt for that principal.
 */
static krb5_error_code
principal2salt_internal(krb5_context context, krb5_const_principal pr,
                        krb5_data *ret, int use_realm)
{
    unsigned int size = 0, offset=0;
    krb5_int32 i;

    *ret = empty_data();
    if (pr == NULL)
        return 0;

    if (use_realm)
        size += pr->realm.length;

    for (i = 0; i < pr->length; i++)
        size += pr->data[i].length;

    if (alloc_data(ret, size))
        return ENOMEM;

    if (use_realm) {
        offset = pr->realm.length;
        if (offset > 0)
            memcpy(ret->data, pr->realm.data, offset);
    }

    for (i = 0; i < pr->length; i++) {
        if (pr->data[i].length > 0)
            memcpy(&ret->data[offset], pr->data[i].data, pr->data[i].length);
        offset += pr->data[i].length;
    }
    return 0;
}
Exemplo n.º 21
0
/***********************************************************************//**
 * @brief Copy class members
 *
 * @param[in] column Column.
 *
 * Sets the content of the vector column by copying from another column.
 * If the code is compiled with the small memory option, and if the source
 * column has not yet been loaded, then we only load the column temporarily
 * for copying purposes and release it again once copying is finished.
 ***************************************************************************/
void GFitsTableLongLongCol::copy_members(const GFitsTableLongLongCol& column)
{
    // Fetch data if necessary
    bool not_loaded = (!column.is_loaded());
    if (not_loaded) {
        column.fetch_data();
    }

    // Copy attributes
    m_type     = column.m_type;
    m_size     = column.m_size;
    m_varlen   = column.m_varlen;
    m_rowstart = column.m_rowstart;

    // Copy column data
    if (column.m_data != NULL && m_size > 0) {
        alloc_data();
        for (int i = 0; i < m_size; ++i) {
            m_data[i] = column.m_data[i];
        }
    }

    // Copy NULL value
    alloc_nulval(column.m_nulval);

    // Small memory option: release column if it was fetch above
    #if defined(G_SMALL_MEMORY)
    if (not_loaded) {
        const_cast<GFitsTableLongLongCol*>(&column)->release_data();
    }
    #endif

    // Return
    return;
}
Exemplo n.º 22
0
 naming::id_type alloc_data_nonvirt(int item, int maxitems, int row,
     std::vector<naming::id_type> const& interp_src_data,
     double time,
     parameter const& par)
 {
     return alloc_data(item, maxitems, row, interp_src_data,time,par);
 }
Exemplo n.º 23
0
/**
 * gwy_surface_new_sized:
 * @n: Number of points.
 *
 * Creates a new surface with preallocated size.
 *
 * The surface will contain the speficied number of points with uninitialised
 * values.
 *
 * Returns: A new surface.
 *
 * Since: 2.45
 **/
GwySurface*
gwy_surface_new_sized(guint n)
{
    GwySurface *surface = g_object_newv(GWY_TYPE_SURFACE, 0, NULL);
    surface->n = n;
    alloc_data(surface);
    return surface;
}
Exemplo n.º 24
0
/***********************************************************************//**
 * @brief Load fixed-length column from FITS file
 *
 * @exception GException::fits_hdu_not_found
 *            Specified HDU not found in FITS file.
 * @exception GException::fits_error
 *            An error occured while loading column data from FITS file.
 *
 * If a FITS file is attached to the column the data are loaded into memory
 * from the FITS file. If no FITS file is attached, memory is allocated
 * to hold the column data and all cells are set to 0.
 *
 * The method makes use of the virtual methods 
 * GFitsTableCol::alloc_data,
 * GFitsTableCol::init_data,
 * GFitsTableCol::ptr_data, and
 * GFitsTableCol::ptr_nulval.
 * These methods are implemented by the derived column classes which 
 * implement a specific storage class (i.e. float, double, short, ...).
 ***************************************************************************/
void GFitsTableCol::load_column_fixed(void)
{
    // Calculate size of memory
    m_size = m_number * m_length;

    // Load only if the column has a positive size
    if (m_size > 0) {

        // Allocate and initialise fresh memory
        alloc_data();
        init_data();

        // If a FITS file is attached then try loading column data from the
        // FITS file. This may fail in case that no data has yet been written
        // to the FITS file. In that case we just skip loading and return
        // the initalised column ... 
        if (FPTR(m_fitsfile)->Fptr != NULL) {

            // Move to the HDU
            int status = 0;
            status     = __ffmahd(FPTR(m_fitsfile),
                                  (FPTR(m_fitsfile)->HDUposition)+1,
                                  NULL, &status);
            
            // If this failed because:
            // - the primary HDU was not found (status 252)
            // - we moved past the file (status 107)
            // we assume that no data have yet been written to the file and
            // we skip the loading.
            if (status != 252 && status != 107) {
            
                // Break on any other cfitsio error
                if (status != 0) {
                    throw GException::fits_hdu_not_found(G_LOAD_COLUMN_FIXED,
                                  (FPTR(m_fitsfile)->HDUposition)+1,
                                  status);
                }

                // Load data
                status = __ffgcv(FPTR(m_fitsfile), m_type, m_colnum, 
                                 1, 1, m_size, ptr_nulval(), ptr_data(),
                                 &m_anynul, &status);
                if (status != 0) {
                    throw GException::fits_error(G_LOAD_COLUMN_FIXED, status,
                                    "for column '"+m_name+"'.");
                }
        
            } // endif: no primary HDU found

        } // endif: there was a FITS file attached

    } // endif: column has a positive size

    // Return
    return;
}
Exemplo n.º 25
0
static krb5_error_code
test_process(krb5_context context, krb5_clpreauth_moddata moddata,
             krb5_clpreauth_modreq modreq, krb5_get_init_creds_opt *opt,
             krb5_clpreauth_callbacks cb, krb5_clpreauth_rock rock,
             krb5_kdc_req *request, krb5_data *encoded_request_body,
             krb5_data *encoded_previous_request, krb5_pa_data *pa_data,
             krb5_prompter_fct prompter, void *prompter_data,
             krb5_pa_data ***out_pa_data)
{
    struct client_state *st = (struct client_state *)moddata;
    struct client_request_state *reqst = (struct client_request_state *)modreq;
    krb5_error_code ret;
    krb5_keyblock *k;
    krb5_enc_data enc;
    krb5_data plain;
    const char *indstr;

    if (pa_data->length == 0) {
        /* This is an optimistic preauth test.  Send a recognizable padata
         * value so the KDC knows not to expect a cookie. */
        if (st->fail_optimistic) {
            k5_setmsg(context, KRB5_PREAUTH_FAILED, "induced optimistic fail");
            return KRB5_PREAUTH_FAILED;
        }
        *out_pa_data = make_pa_list("optimistic", 10);
        return 0;
    } else if (reqst->second_round_trip) {
        printf("2rt: %.*s\n", pa_data->length, pa_data->contents);
        if (st->fail_2rt) {
            k5_setmsg(context, KRB5_PREAUTH_FAILED, "induced 2rt fail");
            return KRB5_PREAUTH_FAILED;
        }
    } else if (pa_data->length == 6 &&
               memcmp(pa_data->contents, "no key", 6) == 0) {
        printf("no key\n");
    } else {
        /* This fails during s4u_identify_user(), so don't assert. */
        ret = cb->get_as_key(context, rock, &k);
        if (ret)
            return ret;
        ret = alloc_data(&plain, pa_data->length);
        assert(!ret);
        enc.enctype = k->enctype;
        enc.ciphertext = make_data(pa_data->contents, pa_data->length);
        ret = krb5_c_decrypt(context, k, 1024, NULL, &enc, &plain);
        assert(!ret);
        printf("%.*s\n", plain.length, plain.data);
        free(plain.data);
    }
    reqst->second_round_trip = TRUE;

    indstr = (st->indicators != NULL) ? st->indicators : "";
    *out_pa_data = make_pa_list(indstr, strlen(indstr));
    return 0;
}
Exemplo n.º 26
0
image::image(int xres, int yres, int bpp)
:width(xres)
,height(yres)
,bpp(bpp==-1?vid_bpp:bpp)
,pitch(xres)
,cx1(0),cy1(0),cx2(xres-1),cy2(yres-1)
,shell(false)
,alpha(false)
,alphaChannel(0)
{
	alloc_data();
}
Exemplo n.º 27
0
krb5_error_code krb5int_confounder_verify(const struct krb5_cksumtypes *ctp,
                                          krb5_key key, krb5_keyusage usage,
                                          const krb5_crypto_iov *data,
                                          size_t num_data,
                                          const krb5_data *input,
                                          krb5_boolean *valid)
{
    krb5_error_code ret;
    unsigned char *plaintext = NULL;
    krb5_key xorkey = NULL;
    krb5_data computed = empty_data();
    krb5_crypto_iov *hash_iov = NULL, iov;
    size_t blocksize = ctp->enc->block_size, hashsize = ctp->hash->hashsize;

    plaintext = k5memdup(input->data, input->length, &ret);
    if (plaintext == NULL)
        return ret;

    ret = mk_xorkey(key, &xorkey);
    if (ret != 0)
        goto cleanup;

    /* Decrypt the input checksum. */
    iov.flags = KRB5_CRYPTO_TYPE_DATA;
    iov.data = make_data(plaintext, input->length);
    ret = ctp->enc->decrypt(xorkey, NULL, &iov, 1);
    if (ret != 0)
        goto cleanup;

    /* Hash the confounder, then the input data. */
    hash_iov = k5alloc((num_data + 1) * sizeof(krb5_crypto_iov), &ret);
    if (hash_iov == NULL)
        goto cleanup;
    hash_iov[0].flags = KRB5_CRYPTO_TYPE_DATA;
    hash_iov[0].data = make_data(plaintext, blocksize);
    memcpy(hash_iov + 1, data, num_data * sizeof(krb5_crypto_iov));
    ret = alloc_data(&computed, hashsize);
    if (ret != 0)
        goto cleanup;
    ret = ctp->hash->hash(hash_iov, num_data + 1, &computed);
    if (ret != 0)
        goto cleanup;

    /* Compare the decrypted hash to the computed one. */
    *valid = (memcmp(plaintext + blocksize, computed.data, hashsize) == 0);

cleanup:
    zapfree(plaintext, input->length);
    zapfree(computed.data, hashsize);
    free(hash_iov);
    krb5_k_free_key(NULL, xorkey);
    return ret;
}
Exemplo n.º 28
0
krb5_error_code
krb5int_derive_random(const struct krb5_enc_provider *enc,
                      krb5_key inkey, krb5_data *outrnd,
                      const krb5_data *in_constant)
{
    size_t blocksize, keybytes, n;
    krb5_crypto_iov iov;
    krb5_error_code ret;

    blocksize = enc->block_size;
    keybytes = enc->keybytes;

    if (blocksize == 1)
        return KRB5_BAD_ENCTYPE;
    if (inkey->keyblock.length != enc->keylength || outrnd->length != keybytes)
        return KRB5_CRYPTO_INTERNAL;

    /* Allocate encryption data buffer. */
    iov.flags = KRB5_CRYPTO_TYPE_DATA;
    ret = alloc_data(&iov.data, blocksize);
    if (ret)
        return ret;

    /* Initialize the input block. */
    if (in_constant->length == blocksize) {
        memcpy(iov.data.data, in_constant->data, blocksize);
    } else {
        krb5int_nfold(in_constant->length * 8,
                      (unsigned char *) in_constant->data,
                      blocksize * 8, (unsigned char *) iov.data.data);
    }

    /* Loop encrypting the blocks until enough key bytes are generated. */
    n = 0;
    while (n < keybytes) {
        ret = enc->encrypt(inkey, 0, &iov, 1);
        if (ret)
            goto cleanup;

        if ((keybytes - n) <= blocksize) {
            memcpy(outrnd->data + n, iov.data.data, (keybytes - n));
            break;
        }

        memcpy(outrnd->data + n, iov.data.data, blocksize);
        n += blocksize;
    }

cleanup:
    zapfree(iov.data.data, blocksize);
    return ret;
}
Exemplo n.º 29
0
static krb5_error_code
make_proxy_request(struct conn_state *state, const krb5_data *realm,
                   const krb5_data *message, char **req_out, size_t *len_out)
{
    krb5_kkdcp_message pm;
    krb5_data *encoded_pm = NULL;
    struct k5buf buf;
    const char *uri_path;
    krb5_error_code ret;

    *req_out = NULL;
    *len_out = 0;

    /*
     * Stuff the message length in at the front of the kerb_message field
     * before encoding.  The proxied messages are actually the payload we'd
     * be sending and receiving if we were using plain TCP.
     */
    memset(&pm, 0, sizeof(pm));
    ret = alloc_data(&pm.kerb_message, message->length + 4);
    if (ret != 0)
        goto cleanup;
    store_32_be(message->length, pm.kerb_message.data);
    memcpy(pm.kerb_message.data + 4, message->data, message->length);
    pm.target_domain = *realm;
    ret = encode_krb5_kkdcp_message(&pm, &encoded_pm);
    if (ret != 0)
        goto cleanup;

    /* Build the request to transmit: the headers + the proxy message. */
    k5_buf_init_dynamic(&buf);
    uri_path = (state->http.uri_path != NULL) ? state->http.uri_path : "";
    k5_buf_add_fmt(&buf, "POST /%s HTTP/1.0\r\n", uri_path);
    k5_buf_add(&buf, "Cache-Control: no-cache\r\n");
    k5_buf_add(&buf, "Pragma: no-cache\r\n");
    k5_buf_add(&buf, "User-Agent: kerberos/1.0\r\n");
    k5_buf_add(&buf, "Content-type: application/kerberos\r\n");
    k5_buf_add_fmt(&buf, "Content-Length: %d\r\n\r\n", encoded_pm->length);
    k5_buf_add_len(&buf, encoded_pm->data, encoded_pm->length);
    if (k5_buf_status(&buf) != 0) {
        ret = ENOMEM;
        goto cleanup;
    }

    *req_out = buf.data;
    *len_out = buf.len;

cleanup:
    krb5_free_data_contents(NULL, &pm.kerb_message);
    krb5_free_data(NULL, encoded_pm);
    return ret;
}
Exemplo n.º 30
0
/* 将外部文件写入到镜像中 */
void do_write()
{
    struct stat st;
    struct inode cur_dir,new_file;
    struct dir_ent ent;
    char buf[SECTOR_SIZE+10];
    int i;
    FILE *fin;
    char filename[16];
    scanf("%s",filename);
    if(stat(filename,&st)<0) {
        printf("No such file.\n");
        return ;
    }
    fin=fopen(filename,"rb");
    get_inode(pwd,&cur_dir);
    new_file.i_num=alloc_inode();
    new_file.i_pnum=pwd;
    new_file.i_size=st.st_size; 
    new_file.i_mode=1; //标示为文件
    ent.i_num=new_file.i_num;   strcpy(ent.name,filename);    
    add_entry(&cur_dir,&ent);
    
    u32 last_sector=0,cur_sector;
    u32 need=st.st_size/(SECTOR_SIZE-sizeof(u32))+1;
    new_file.i_nr_sects=need;
        //根据文件大小,逐个分配扇区来写入数据,并采用单链表方式连接各个扇区
    for(i=0;i<need;i++)
    {
        cur_sector=alloc_data();
        if(last_sector==0)  {
            new_file.i_start_sect=cur_sector;
        }else{ //上一个扇区到这个扇区的指针
            fseek(fimg,last_sector*SECTOR_SIZE+SECTOR_SIZE-sizeof(u32),SEEK_SET);
            fwrite(&cur_sector,sizeof(u32),1,fimg);
        }
        int nread=fread(buf,sizeof(char),SECTOR_SIZE-sizeof(u32),fin);
        if(nread<0)  {
            printf("Read file %s error.\n",filename );
            return ;
        }
        fseek(fimg,cur_sector*SECTOR_SIZE,SEEK_SET);
        fwrite(buf,sizeof(char),nread,fimg);
        last_sector=cur_sector;
    }
    fseek(fimg,last_sector*SECTOR_SIZE+SECTOR_SIZE-sizeof(u32),SEEK_SET);
    u32 tmp=0;
    fwrite(&tmp,sizeof(u32),1,fimg);
    write_inode(new_file.i_num,&new_file);
    write_inode(cur_dir.i_num,&cur_dir);
}