예제 #1
0
파일: bigint.c 프로젝트: duckhead/amanda
SV *
amglue_newSVu64(guint64 v)
{
    char numstr[25];
    g_snprintf(numstr, sizeof(numstr), "%ju", (uintmax_t)v);
    numstr[sizeof(numstr)-1] = '\0';
    return str2bigint(numstr);
}
예제 #2
0
/**
 * \retval DB_NOT_EXISTS if the recovery table does not exist
 */
int ListMgr_RecovStatus( lmgr_t * p_mgr, lmgr_recov_stat_t * p_stats )
{
    int  rc, i;
    result_handle_t result;
    char * status[3];

    /* test if a RECOVERY table already exist, and contains entries */
    rc = db_exec_sql_quiet( &p_mgr->conn, "SELECT recov_status,COUNT(*),SUM(size) FROM "RECOV_TABLE
                            " GROUP BY recov_status", &result );
    if (rc)
        return rc;

    /* table exists, fill status tab */
    p_stats->total = 0;
    for (i = 0; i < RS_COUNT; i++ )
    {
        p_stats->status_count[i] = 0;
        p_stats->status_size[i] = 0;
    }

    while ( (rc = db_next_record( &p_mgr->conn, &result, status, 3 ))
            != DB_END_OF_LIST )
    {
        long long cnt;
        uint64_t sz;
        if (rc)
            return rc;

        cnt = str2bigint( status[1] );
        if ( cnt == -1LL)
            return DB_INVALID_ARG;

        sz = str2size(  status[2] );
        if ( sz == -1LL)
            return DB_INVALID_ARG;

        p_stats->total += cnt;

        if ( status[0] != NULL )
        {
            int idx = str2int( status[0] );
            if ((idx >= RS_COUNT) || (idx == -1) )
                return DB_REQUEST_FAILED;
            p_stats->status_count[idx] = cnt;
            p_stats->status_size[idx] = sz;
        }
    }

    db_result_free( &p_mgr->conn, &result );
    return 0;
}
예제 #3
0
/**
 * \retval DB_NOT_EXISTS if the recovery table does not exist
 */
static int expected_recov_status( lmgr_t * p_mgr, lmgr_recov_stat_t * p_stats )
{
    int  rc, i;
    result_handle_t result;
    char * status[5];

    /* test if a RECOVERY table already exist, and contains entries */
    rc = db_exec_sql_quiet( &p_mgr->conn, "SELECT status,type,COUNT(*),(size=0) as empty,SUM(size) FROM "RECOV_TABLE
                            " GROUP BY status,type,empty", &result );
    if (rc)
        return rc;

    /* @TODO manage dirs and symlinks differently */

    p_stats->total = 0;
    for (i = 0; i < RS_COUNT; i++ )
    {
        p_stats->status_count[i] = 0;
        p_stats->status_size[i] = 0;
    }

    while ( (rc = db_next_record( &p_mgr->conn, &result, status, 5 ))
            != DB_END_OF_LIST )
    {
        long long cnt;
        uint64_t sz;
        int isempty;

        if (rc)
            return rc;

        cnt = str2bigint( status[2] );
        if ( cnt == -1LL)
            return DB_INVALID_ARG;

        isempty = str2int(  status[3] );
        if ( isempty == -1)
            return DB_INVALID_ARG;

        sz = str2size(  status[4] );
        if ( sz == -1LL)
            return DB_INVALID_ARG;

        p_stats->total += cnt;

        if ( status[0] != NULL )
        {
            int st = str2int( status[0] );

            /* archived entries: file and (optionally) symlinks  */
            if (!strcasecmp(status[1], STR_TYPE_FILE))
            {
                if (isempty)
                {
                     p_stats->status_count[RS_FILE_EMPTY] += cnt;
                     p_stats->status_size[RS_FILE_EMPTY] += sz;
                }
                else
                {
                    switch (st)
                    {
                        case STATUS_NEW:
                            p_stats->status_count[RS_NOBACKUP] += cnt;
                            p_stats->status_size[RS_NOBACKUP] += sz;
                            break;
                        case STATUS_MODIFIED:
                        case STATUS_ARCHIVE_RUNNING:
                            p_stats->status_count[RS_FILE_DELTA] += cnt;
                            p_stats->status_size[RS_FILE_DELTA] += sz;
                            break;
                        case STATUS_SYNCHRO:
                        case STATUS_RELEASED:
                            p_stats->status_count[RS_FILE_OK] += cnt;
                            p_stats->status_size[RS_FILE_OK] += sz;
                            break;
                    }
                }
            }
            else if (!strcasecmp(status[1], STR_TYPE_LINK)
                     || !strcasecmp(status[1], STR_TYPE_DIR))
            {
                /* symlinks and dirs always recoverable from DB */
                p_stats->status_count[RS_NON_FILE] += cnt;
                p_stats->status_size[RS_NON_FILE] += sz;
            }
            else
            {
                /* non recoverable : special entry like fifo, blk, ... */
                p_stats->status_count[RS_NOBACKUP] += cnt;
                p_stats->status_size[RS_NOBACKUP] += sz;
            }
        }
    }

    db_result_free( &p_mgr->conn, &result );
    return 0;
}
예제 #4
0
/** retrieve directory attributes (nbr of entries, avg size of entries)*/
int listmgr_get_dirattrs( lmgr_t * p_mgr, PK_ARG_T dir_pk, attr_set_t * p_attrs )
{
    GString         *req;
    result_handle_t  result;
    char            *str_info[1];
    int              rc = 0;
    int              tmp_val;
    long long        tmp_long;

    if (ATTR_MASK_TEST(p_attrs, type) &&
        (strcmp(ATTR(p_attrs, type), STR_TYPE_DIR) != 0))
    {
        DisplayLog(LVL_FULL, LISTMGR_TAG,
                   "Type='%s' != 'dir' => unsetting dirattrs in attr mask",
                   ATTR(p_attrs, type));
        p_attrs->attr_mask = attr_mask_and_not(&p_attrs->attr_mask, &dir_attr_set);
        return 0;
    }

    req = g_string_new(NULL);

    /* get child entry count from DNAMES_TABLE */
    if (ATTR_MASK_TEST(p_attrs, dircount))
    {
        g_string_printf(req, "SELECT %s FROM "DNAMES_TABLE" WHERE parent_id="DPK,
                        dirattr2str(ATTR_INDEX_dircount), dir_pk);

        rc = db_exec_sql(&p_mgr->conn, req->str, &result);
        if (rc)
            goto free_str;

        rc = db_next_record(&p_mgr->conn, &result, str_info, 1);
        if (rc == DB_END_OF_LIST)
        {
            ATTR_MASK_UNSET(p_attrs, dircount);
            rc = DB_SUCCESS;
        }
        else if (rc == DB_SUCCESS)
        {
            if (str_info[0] == NULL)
                /* count(*) should at least return 0 */
                rc = DB_REQUEST_FAILED;
            else
            {
                tmp_val = str2int(str_info[0]);
                if (tmp_val != -1)
                {
                    ATTR_MASK_SET(p_attrs, dircount);
                    ATTR(p_attrs, dircount) = tmp_val;
                    rc = DB_SUCCESS;
                }
                else
                    /* invalid output format */
                    rc = DB_REQUEST_FAILED;
            }
        }
        db_result_free(&p_mgr->conn, &result);
        if (rc)
            goto free_str;
    }

    /* get avgsize of child entries from MAIN_TABLE */
    if (ATTR_MASK_TEST(p_attrs, avgsize))
    {
        g_string_printf(req, "SELECT %s FROM "MAIN_TABLE" m, "DNAMES_TABLE" d"
                        " WHERE m.id = d.id and type='file' and d.parent_id="DPK,
                        dirattr2str(ATTR_INDEX_avgsize), dir_pk);

        rc = db_exec_sql(&p_mgr->conn, req->str, &result);
        if (rc)
            goto free_str;

        rc = db_next_record(&p_mgr->conn, &result, str_info, 1);
        if (rc == DB_END_OF_LIST)
            ATTR_MASK_UNSET(p_attrs, avgsize);
        else if (rc == DB_SUCCESS)
        {
            if (str_info[0] == NULL)
            {
                /* NULL if no entry matches the criteria */
                ATTR_MASK_UNSET(p_attrs, avgsize);
                rc = DB_SUCCESS;
            }
            else
            {
                tmp_long = str2bigint(str_info[0]);
                if (tmp_long != -1LL)
                {
                    ATTR_MASK_SET(p_attrs, avgsize);
                    ATTR(p_attrs, avgsize) = tmp_long;
                    rc = DB_SUCCESS;
                }
                else
                    /* invalid output format */
                    rc = DB_REQUEST_FAILED;
            }
        }
        db_result_free(&p_mgr->conn, &result);
    }

free_str:
    g_string_free(req, TRUE);
    return rc;
}
예제 #5
0
파일: utils.cpp 프로젝트: tedher/aztecc
/////////////////////////////////////////////////////
// FUNCTION : get user private key
//
// Input  : char* username
// Output : bigint d -> user private key
/////////////////////////////////////////////////////
void get_passphrase(bigint& d, int blocksize, const char* username)
{
	int c,i=0;
	char passphrase[MAX2];		// max size 2047 chars
	
	cout<<"\nINPUT PASSPHRASE :";
	cout<<"\n------------------";
	cout<<"\nHello =>"<<username<<"<= please enter your passphrase (up to "<<MAX2<<" chars)";
	cout<<"\nThis is your PRIVATE KEY. Do not forget it.";
	cout<<"\n\nWhen you're done, press <ENTER>."<<endl;
	cout<<"Begin entering your passphrase ==>"<<endl;

#ifdef __unix__
	struct termios terminal;
	
	tcgetattr(0,&terminal);
	terminal.c_lflag &= ! ECHO;
	tcsetattr(0,TCSANOW,&terminal);
#endif
	
#ifdef __unix__
	c = getchar();
	if(c != '\n')
#else
	c = getch();
	if(c != '\r') 
#endif
    	ungetc(c, stdin);

	i=0;
#ifdef __unix__
	while((c=getchar()) != '\n')
#else
	while((c=getch()) != '\r')
#endif
	{
		cout<<"*"<<flush;
		passphrase[i]=c;
		i++;
		if(i>=MAX2)
		{
			cerr<<"\nAZTECC ERROR : Ooopss...passphrase too long. Aborting."<<endl;
			exit(1);
		}
	}
	passphrase[i]='\0';

#ifdef __unix__
	terminal.c_lflag |= ECHO;
	tcsetattr(0,TCSANOW,&terminal);
#endif

	// hash #1 passphrase
	unsigned char* str1=new unsigned char[16];
	str1= MD5_raw_digest(passphrase);
	
	// save to buffer
	unsigned char* buffer=new unsigned char[32];
	for(i=0;i<16;i++)
		buffer[i]=str1[i];
	
	// hash #2 passphrase
	unsigned char* str2=new unsigned char[16];
	strncpy((char*)str2,(char*)str1, strlen((char*)str1));
	strncat((char*)str2,"aaa",3);
	str2=MD5_raw_digest((char*)str2);
	
	// save to buffer
	for(i=16;i<32;i++)
		buffer[i]=str2[i-16];
	
	// convert to bigint
	bigint priv_key;
	str2bigint((char*)buffer,blocksize,priv_key);
	d=priv_key;

	//cleaning up
	delete[] str1;
	delete[] str2;
	delete[] buffer;
}