コード例 #1
0
ファイル: chirp_ticket.c プロジェクト: nfillmore/cctools
void chirp_ticket_name(const char *root, const char *pk, char *ticket_subject, char *ticket_filename)
{
	unsigned char digest[TICKET_DIGEST_LENGTH];
	md5_context_t context;
	md5_init(&context);
	md5_update(&context, (const unsigned char *) pk, strlen(pk));
	md5_final(digest, &context);
	sprintf(ticket_subject, TICKET_SUBJECT_FORMAT, md5_string(digest));
	sprintf(ticket_filename, "%s/" TICKET_FILENAME_FORMAT, root, md5_string(digest));
}
コード例 #2
0
// Evaluate differences between time-zone.  Two time zones that differ
// by almost 24 hours are actually very close on the surface of the
// earth.  This function finds the 'shortest way around'
//
static int compare(const void *x, const void *y) {
    const URLTYPE *a=(const URLTYPE *)x;
    const URLTYPE *b=(const URLTYPE *)y;

    char longname[512];

    const int twelve_hours = 12*3600;

    int diffa = abs(tzone - (a->zone));
    int diffb = abs(tzone - (b->zone));

    if (diffa > twelve_hours) {
        diffa = 2*twelve_hours-diffa;
    }

    if (diffb > twelve_hours) {
        diffb = 2*twelve_hours-diffb;
    }

    if (diffa < diffb) {
        return -1;
    }

    if (diffa > diffb) {
        return +1;
    }

    // In order to ensure uniform distribution, we hash paths that are
    // equidistant from the host's timezone in a way that gives a
    // unique ordering for each host but which is effectively random
    // between hosts.
    //
    sprintf(longname, "%s%d", a->name, hostid);
    std::string sa = md5_string((const unsigned char *)longname, strlen((const char *)longname));
    sprintf(longname, "%s%d", b->name, hostid);
    std::string sb = md5_string((const unsigned char *)longname, strlen((const char *)longname));
    int xa = strtol(sa.substr(1, 7).c_str(), 0, 16);
    int xb = strtol(sb.substr(1, 7).c_str(), 0, 16);

    if (xa<xb) {
        return -1;
    }

    if (xa>xb) {
        return 1;
    }

    return 0;
}
コード例 #3
0
ファイル: md5.c プロジェクト: hckjsnzf/selflib
int main(int argc, char **argv)
{
	int leng;
	
	st=ft=ht=vt=0;
	md_parse_opt(argc, argv);

	if(vt == 1) {
		md_show_version();
		return 0;
	}
	if(ht == 1) {
		md_show_version();
		md_show_help();
		return 0;
	}

	if(st == 1) {
		md5_string();
	}
	if(ft == 1) {
		md5_file();
	}
	
	return 0;
}
コード例 #4
0
ファイル: ancestors.c プロジェクト: jessewt/tundra
static void
compute_node_guid(td_engine *engine, td_node *node)
{
	MD5_CTX context;
	MD5_Init(&context);
	md5_string(&context, node->action);
	md5_string(&context, node->annotation);
	md5_string(&context, node->salt);
	MD5_Final(node->guid.data, &context);

	if (td_debug_check(engine, TD_DEBUG_NODES))
	{
		char guidstr[33];
		td_digest_to_string(&node->guid, guidstr);
		printf("%s with guid %s\n", node->annotation, guidstr);
	}
}
コード例 #5
0
ファイル: file_cache.c プロジェクト: bbockelm/cctools
static void txn_name(struct file_cache *c, const char *path, char *txn)
{
	unsigned char digest[MD5_DIGEST_LENGTH];
	char shortname[DOMAIN_NAME_MAX];
	domain_name_cache_guess_short(shortname);
	md5_buffer(path, strlen(path), digest);
	sprintf(txn, "%s/txn/%s.%s.%d.XXXXXX", c->root, md5_string(digest), shortname, (int) getpid());
}
コード例 #6
0
ファイル: chirp_ticket.c プロジェクト: nfillmore/cctools
const char *chirp_ticket_digest(const char *pk)
{
	unsigned char digest[TICKET_DIGEST_LENGTH];
	md5_context_t context;
	md5_init(&context);
	md5_update(&context, (const unsigned char *) pk, strlen(pk));
	md5_final(digest, &context);
	return md5_string(digest);	/* static memory */
}
コード例 #7
0
ファイル: util.cpp プロジェクト: brianserv/dbproxy
 /*
 *  输入一个整数,获取其字符串对应的MD5码
 */
 char* GetMD5(const RoleID roleid)
 {
	 char arrA[16] = {0};
	 sprintf(arrA, "%d", roleid);
	 int32_t iInputLength = strlen(arrA);

	 char arrOut[32] = {0};
	 char *pResult = NULL;

	 pResult = md5_string((const unsigned char*)arrA, arrOut, iInputLength);
	 return pResult;
 }
コード例 #8
0
ファイル: caching.cpp プロジェクト: bolaria/HPCC-Platform
bool CPermissionsCache::lookup(ISecUser& sec_user)
{
    if(!isCacheEnabled())
        return false;

    const char* username = sec_user.getName();
    if(!username || !*username)
        return false;

    string key(username);
    ReadLockBlock readLock(m_userCacheRWLock );

    MapUserCache::iterator it = m_userCache.find(key);
    if (it == m_userCache.end())
        return false;
    CachedUser* user = (CachedUser*)(it->second);

    time_t now;
    time(&now);
    if(user->getTimestamp() < (now - m_cacheTimeout))
    {
        m_userCache.erase(username);
        delete user;
        return false;
    }

    const char* cachedpw = user->queryUser()->credentials().getPassword();
    StringBuffer pw(sec_user.credentials().getPassword());
    
    if(cachedpw && pw.length() > 0)
    {
        StringBuffer md5pbuf;
        md5_string(pw, md5pbuf);
        if(strcmp(cachedpw, md5pbuf.str()) == 0)
        {
#ifdef _DEBUG
            DBGLOG("CACHE: CPermissionsCache Found validated user %s", username);
#endif
            // Copy cached user to the sec_user structure, but still keep the original clear text password.
            user->queryUser()->copyTo(sec_user);
            sec_user.credentials().setPassword(pw.str());
            return true;
        }
        else
        {
            m_userCache.erase(username);
            delete user;
            return false;
        }
    }

    return false;
}
コード例 #9
0
/// Answer an authorization request sent by the server.
/// The answer is the response to the nonce sent as challenge by the server.
/// It is the md5sum from the concatenation of the nonce and the
/// GUI-RPC password.
///
/// \param[in] passwd The GUI-RPC password.
/// \return Zero if the authorization was acknowledged by the server,
///         nonzero if the server rejected the request or if any other error
///         occurred.
int RPC_CLIENT::authorize(const char* passwd) {
    RPC rpc(this);
    int retval = rpc.do_rpc("<auth1/>\n");
    if (retval) {
        return retval;
    }

    XML_PARSER xp(&rpc.fin);
    char nonce[256];
    bool found = false;
    char chr_buf[256];
    bool is_tag;
    while (!xp.get(chr_buf, sizeof(chr_buf), is_tag)) {
        if (!is_tag) {
            continue;
        }
        if (xp.parse_str(chr_buf, "nonce", nonce, sizeof(nonce))) {
            found = true;
            break;
        }
    }
    
    if (!found) {
        //fprintf(stderr, "Nonce not found\n");
        return ERR_AUTHENTICATOR;
    }

    free(rpc.mbuf);
    
    std::ostringstream input;
    input << nonce << passwd;
    std::string nonce_hash = md5_string(input.str());
    std::ostringstream buf;
    buf << "<auth2>\n<nonce_hash>" << nonce_hash << "</nonce_hash>\n</auth2>\n";
    retval = rpc.do_rpc(buf.str().c_str());
    if (retval) {
        return retval;
    }

    while (!xp.get(chr_buf, sizeof(chr_buf), is_tag)) {
        if (!is_tag) {
            continue;
        }
        bool authorized;
        if (xp.parse_bool(chr_buf, "authorized", authorized)) {
            if (authorized) {
                return 0;
            }
        }
    }
    return ERR_AUTHENTICATOR;
}
コード例 #10
0
ファイル: chirp_tool.c プロジェクト: ailurus1991/cctools
static INT64_T do_md5(int argc, char **argv)
{
	unsigned char digest[16];
	char full_path[CHIRP_LINE_MAX];
	int result;

	complete_remote_path(argv[1], full_path);

	result = chirp_reli_md5(current_host, full_path, digest, stoptime);
	if(result > 0)
		printf("%s %s\n", md5_string(digest), full_path);
	return result;
}
コード例 #11
0
ファイル: file_cache.c プロジェクト: bbockelm/cctools
static int wait_for_running_txn(struct file_cache *c, const char *path)
{
	char txn[PATH_MAX];
	char dirname[PATH_MAX];
	unsigned char digest[MD5_DIGEST_LENGTH];
	DIR *dir;
	struct dirent *d;
	const char *checksum;

	md5_buffer(path, strlen(path), digest);
	checksum = md5_string(digest);

	txn[0] = 0;

	sprintf(dirname, "%s/txn", c->root);

	dir = opendir(dirname);
	if(!dir)
		return 0;

	while((d = readdir(dir))) {
		if(!strncmp(d->d_name, checksum, 32)) {
			sprintf(txn, "%s/txn/%s", c->root, d->d_name);
			break;
		}
	}

	closedir(dir);

	if(!txn[0])
		return 0;

	while(1) {
		struct stat64 info;

		debug(D_CACHE, "wait %s", txn);
		if(stat64(txn, &info) < 0)
			return 1;

		time_t current = time(0);

		if((current - info.st_mtime) < 60) {
			sleep(1);
			continue;
		} else {
			debug(D_CACHE, "override %s", txn);
			return 0;
		}
	}

}
コード例 #12
0
ファイル: cs_statefile.cpp プロジェクト: Wizardofoddz/boinc
// this is called whenever new results are added,
// namely at startup and after a scheduler RPC.
// Sort results based on (arrival time, name),
// then set result.index to their position in this order.
// This determines the order in which results are run.
//
void CLIENT_STATE::sort_results() {
    unsigned int i;
    for (i=0; i<results.size(); i++) {
        RESULT* rp = results[i];
        rp->name_md5 = md5_string(string(rp->name));
    }
    std::sort(
        results.begin(),
        results.end(),
        arrived_first
    );
    for (i=0; i<results.size(); i++) {
        RESULT* rp = results[i];
        rp->index = i;
    }
}
コード例 #13
0
ファイル: caching.cpp プロジェクト: AsherBond/HPCC-Platform
bool CPermissionsCache::lookup(ISecUser& sec_user)
{
    if(!isCacheEnabled())
        return false;

    const char* username = sec_user.getName();
    if(!username || !*username)
        return false;

    synchronized block(m_userCacheMonitor); 

    CachedUser* user = m_userCache[username];
    if(user == NULL)
        return false;       
    time_t now;
    time(&now);
    if(user->getTimestamp() < (now - m_cacheTimeout))
    {
        m_userCache.erase(username);
        delete user;
        return false;
    }

    const char* cachedpw = user->queryUser()->credentials().getPassword();
    StringBuffer pw(sec_user.credentials().getPassword());
    
    if(cachedpw && pw.length() > 0)
    {
        StringBuffer md5pbuf;
        md5_string(pw, md5pbuf);
        if(strcmp(cachedpw, md5pbuf.str()) == 0)
        {
            // Copy cached user to the sec_user structure, but still keep the original clear text password.
            user->queryUser()->copyTo(sec_user);
            sec_user.credentials().setPassword(pw.str());
            return true;
        }
        else
        {
            m_userCache.erase(username);
            delete user;
            return false;
        }
    }

    return false;
}
コード例 #14
0
ファイル: main.cpp プロジェクト: JustinZhou/acl
int main()
{
	const char* s = "中国人民银行!";
	const char* key = "zsxxsz";
	char  buf1[33], buf2[33];

	acl::md5::md5_string(s, strlen(s), key, strlen(key),
		buf1, sizeof(buf1));
	printf("first md5: %s\r\n", buf1);

	md5_string(s, key, strlen(key), buf2, sizeof(buf2));
	printf("second md5: %s\r\n", buf2);

	assert(strcmp(buf1, buf2) == 0);

#ifdef WIN32
	getchar();
#endif
	return 0;
}
コード例 #15
0
ファイル: parrot_md5.c プロジェクト: Baguage/cctools
int main( int argc, char *argv[] )
{
	int i;
	unsigned char digest[16];

	if(argc<2) {
		printf("use: parrot_md5 <file> ...\n");
		return 1;
	}

	for(i=1;i<argc;i++) {
		if(parrot_md5(argv[i],digest)>=0 || md5_file(argv[i],digest)) {
			printf("%s %s\n",md5_string(digest),argv[i]);
		} else {
			fprintf(stderr,"parrot_md5: %s: %s\n",argv[i],strerror(errno));
		}
	}

	return 0;
}
コード例 #16
0
ファイル: ircbot.c プロジェクト: ectrospeedy/NEctroverse
void event_privmsg (irc_session_t * irc_session, const char * event, const char * origin, const char ** params, unsigned int count) {
	char nickbuf[128], md5sum[MD5_HASHSUM_SIZE];
	SessionPtr session;

//dump_event (irc_session, event, origin, params, count);
params[1] = irc_color_strip_from_mirc( params[1] );
addlog ("'%s' said to me (%s): %s", origin ? origin : "someone", params[0], params[1] );

if ( !origin )
	return;

irc_target_get_nick( origin, nickbuf, sizeof(nickbuf) );
md5_string( origin, md5sum );
session = get_session( SESSION_IRC, md5sum );

if( !( session->dbuser ) ) {
	irc_cmd_notice( sysconfig.irc_session, nickbuf, "You must be loged in to use any features." );
} else {
	irc_cmd_notice( sysconfig.irc_session, nickbuf, "Now just how did you manage that..." );
}

return;
}
コード例 #17
0
ファイル: md5.c プロジェクト: fluyy/fluyy_code
int main(int argc,char **argv){

	int opt;

	while((opt=getopt(argc,argv,":vf:h"))!=-1){
		switch (opt){

			case 'v':
				show_version();
				break;

			case 'f':
				md5_file(optarg);
				break;

			case ':':
				printf("need a filename\n");
				break;

			case 'h':
			case '?':
				printf("unknow option\n");
				show_help();
				break;
			default:
				printf("a a %s\n",optarg);
		}
	}

	while(optind<argc){
		md5_string(argv[optind]);
		optind++;
	}

	return 0;
}
コード例 #18
0
ファイル: StripCS.c プロジェクト: sjlombardo/strip-palm
/********************************************************************************
 * Description: this is the function responsible for checking the 
 * input password value of the authentication form. 
 * ******************************************************************************/ 
static void 
checkPassword (void) 
{
	MemPtr pass1, scratch = NULL;
	char *input;

	UInt16 index = 0;
	MemHandle rec;
	mdKey in;
	ListType *list;
	
		// compact text and get a pointer.
		FldCompactText (GetObjectFromActiveForm (PasswordField));
	input = FldGetTextPtr (GetObjectFromActiveForm (PasswordField));
	list = GetObjectFromActiveForm (selPopupList);
	
		// if SysPass is defined, free it. this happens when Strip locks
		// itself after the timeout.
		if (SysPass)
		MemPtrFree (SysPass);
	
		// if its the first time the user has used the program we need 
		// to set some things up. 
		if (input && StrLen (input))
		
	{
		
			// read the password from the database, decrypt with the input text.
			if ((rec = DmQueryRecord (PasswordDB, index)))
			
		{
			pass1 = MemHandleLock (rec);
			if ((scratch = MemPtrNew (24)))
				
			{
				UInt16 chk = LstGetSelection (list);
				
					//printf("%d\n", LstGetSelection(list)); 
					switch (chk)
					
				{
					case 0:
						UnpackPassword_old (pass1, scratch, input, 1);
						break;
					case 1:
						UnpackPassword_old (pass1, scratch, input, 2);
						break;
					case 2:
						UnpackPassword_old (pass1, scratch, input, 0);
						break;
				}
			}
			MemHandleUnlock (rec);
		}
		
			// the message digest of the password they provided should be exactly the
			// same as the message digest that was just decrypted out of the password
			// database. Do a MemCmp to make sure they are the same.
		md5_string (input, in);

		if ((!MemCmp (in, scratch, 16)) && input)
			
		{
			
				// if so, copy the password onto the system-password
		if ((SysPass = MemPtrNew (StrLen (input) + 1)))
				StrCopy (SysPass, input);
		if (scratch)
				MemPtrFree (scratch);
		md_string(SysPass, NewSysPass);
		cryptSwitch (LstGetSelection (list));
		}
		
		else
			
		{
			
				// FAILURE!!!!!!
				// free the memory and tell the user they entered the wrong password.
				FieldType *fld = GetObjectFromActiveForm (PasswordField);
			FrmCustomAlert (GenericError,
							  "The password you entered is incorrect", NULL,
							  NULL);
				FldSetSelection (fld, 0, FldGetTextLength (fld));
			LstDrawList (list);
			if (scratch)
				
			{
				MemPtrFree (scratch);
				SysPass = NULL;
			}
		}
	}
	
		// null string is always wrong!!!
		else
		
	{
		FrmCustomAlert (GenericError, "You forgot to enter a password!!",
						 NULL, NULL);
		LstDrawList (list);
	}
}
コード例 #19
0
ファイル: ircbot.c プロジェクト: ectrospeedy/NEctroverse
void event_channel (irc_session_t * irc_session, const char * event, const char * origin, const char ** params, unsigned int count) {
	char buffer[512];
	char nickbuf[128];
	char md5sum[MD5_HASHSUM_SIZE];
	ConfigArrayPtr setting;
	SessionPtr session;

if ( count != 2 )
	return;

params[1] = irc_color_strip_from_mirc( params[1] );
addlog ("'%s' said in channel %s: %s", origin ? origin : "someone", params[0], params[1] );

if ( !origin )
	return;

irc_target_get_nick( origin, nickbuf, sizeof(nickbuf) );

md5_string( origin, md5sum );
session = get_session( SESSION_IRC, md5sum );


if ( !strcmp (params[1], "help") ) {
	if( ( session->dbuser ) && ( session->dbuser->level >= LEVEL_MODERATOR ) )
		snprintf(buffer, sizeof(buffer), "%s", irc_color_convert_to_mirc( "[B]Usage[/B] - quit, help, dcc send, topic, mode, whois, nick" ) );
	else
		snprintf(buffer, sizeof(buffer), "%s", irc_color_convert_to_mirc( "[B]Usage[/B] - help, dcc send, login" ) );
	irc_cmd_notice( irc_session, params[0], buffer );
}

if ( !strcmp (params[1], "ctcp") ) {
	irc_cmd_ctcp_request (irc_session, nickbuf, "PING 223");
	irc_cmd_ctcp_request (irc_session, nickbuf, "FINGER");
	irc_cmd_ctcp_request (irc_session, nickbuf, "VERSION");
	irc_cmd_ctcp_request (irc_session, nickbuf, "TIME");
}

if ( !strcmp (params[1], "dcc chat") ) {
		irc_dcc_t dccid;
	
	irc_dcc_chat (irc_session, 0, nickbuf, dcc_recv_callback, &dccid);
	addlog ("DCC chat ID: %d", dccid);
}

if ( !strcmp (params[1], "dcc send") ) {
		irc_dcc_t dccid;
	setting = GetSetting( "HTTP Images" );
	snprintf(buffer, sizeof(buffer), "%s/cookie.gif", setting->string_value );
	irc_dcc_sendfile (irc_session, 0, nickbuf, buffer, dcc_file_send_callback, &dccid);
	addlog ("DCC send ID: %d", dccid);
}


if( ( session->dbuser ) && ( session->dbuser->level >= LEVEL_MODERATOR ) ) {

if ( !strcmp (params[1], "quit") ) {
		irc_cmd_quit (irc_session, "of course, Master!");
}

if ( !strcmp (params[1], "topic") ) {
	irc_cmd_topic (irc_session, params[0], 0);
} else if ( strstr (params[1], "topic ") == params[1] ) {
	irc_cmd_topic (irc_session, params[0], params[1] + 6);
}

if ( strstr (params[1], "mode ") == params[1] )
	irc_cmd_channel_mode (irc_session, params[0], params[1] + 5);

if ( strstr (params[1], "nick ") == params[1] )
	irc_cmd_nick (irc_session, params[1] + 5);

if ( strstr (params[1], "whois ") == params[1] )
	irc_cmd_whois (irc_session, params[1] + 5);

}

return;
}
コード例 #20
0
ファイル: Oauth.c プロジェクト: bomma/io
void oauth_signandappend_oauth_header(const char *reqMethod, struct url_props *url, const char *consumerKey, const char *consumerSecret, const char *authToken, const char *authTokenSecret, const time_t now, const char *postContent, const size_t postContentLen, const char *oauthCallback, const char *oauthVerifier, const char *oauthScope, struct string *out)
{
	struct signctx senv;
	char _tb[256];
	const size_t _tbLen = sprintf(_tb, "%u", (unsigned)now);
	struct timeval tv;
	struct md5_context md5Ctx;

	signctx_init(&senv);
	init_signature_seed(&senv, reqMethod, url);

	if (postContentLen)
		append_signature_params(&senv, postContent, postContent + postContentLen);


	string_append(out, "Authorization: OAuth ", 21);

	append_signature_param(&senv, "oauth_consumer_key", 18, consumerKey, strlen(consumerKey));
	string_appendfmt(out, "oauth_consumer_key=\"%s\"", consumerKey);

	append_signature_param(&senv, "oauth_signature_method", 22, "HMAC-SHA1", 9);
	string_append(out, ",oauth_signature_method=\"HMAC-SHA1\"", 35);


        string_appendfmt(out,",oauth_timestamp=\"%u\"", (uint32_t)now);
        append_signature_param(&senv, "oauth_timestamp", 15, _tb, _tbLen);
                
        gettimeofday(&tv, NULL);
                        
        uint8_t digest[16];
        char digestAlpha[33];

	md5_init(&md5Ctx);
        md5_update(&md5Ctx, (uint8_t *)&tv.tv_sec, sizeof(tv.tv_sec));
        md5_update(&md5Ctx, (uint8_t *)&tv.tv_usec, sizeof(tv.tv_usec));
        md5_update(&md5Ctx, (uint8_t *)consumerKey, strlen(consumerKey));
        md5_update(&md5Ctx, (uint8_t *)"io.language", 11);
	md5_finalize(&md5Ctx, digest);
                
        md5_string((char *)digest, digestAlpha);
        const size_t digestAlphaLen = strlen(digestAlpha);      // 32
                
	string_appendfmt(out, ",oauth_nonce=\"%.*s\"",  digestAlphaLen, digestAlpha);
        append_signature_param(&senv, "oauth_nonce", 11, digestAlpha, digestAlphaLen);

        string_appendfmt(out, ",oauth_version=\"1.0\"", 20);
        append_signature_param(&senv, "oauth_version", 13, "1.0", 3);
                
        if (authToken && *authToken != '\0')
        {
                string_appendfmt(out, ",oauth_token=\"%s\"", authToken);
                append_signature_param(&senv, "oauth_token", 11, authToken, strlen(authToken));
        }       

        if (oauthCallback && *oauthCallback != '\0')
        {
                string_appendfmt(out, ",oauth_callback=\"%s\"", oauthCallback);
                append_signature_param(&senv, "oauth_callback", 14, oauthCallback, strlen(oauthCallback));
        }
                
        if (oauthVerifier && *oauthVerifier != '\0')
        {
                string_appendfmt(out, ",oauth_verifier=\"%s\"", oauthVerifier);
                append_signature_param(&senv, "oauth_verifier", 14, oauthVerifier, strlen(oauthVerifier));
        }

        if (oauthScope && *oauthScope != '\0')
        {
                string_appendfmt(out, ",scope=\"%s\"", oauthScope);
                append_signature_param(&senv, "scope", 5, oauthScope, strlen(oauthScope));
        }
	
        build_signature(&senv, "HMAC-SHA1", consumerSecret, authTokenSecret ? authTokenSecret : "");

        string_append(out, ",oauth_signature=\"", 18);
	string_append_urlencoded_rfc3986(out, string_data(&senv.signatureParamsBuf), string_len(&senv.signatureParamsBuf));
	string_append(out, "\"\r\n", 3);

	signctx_dealloc(&senv);
}
コード例 #21
0
ファイル: leaff.C プロジェクト: ondovb/canu
void
processArray(int argc, char **argv) {

  int arg = 1;
  while (arg < argc) {

    if       ((strcmp(argv[arg], "-f") == 0) ||
              (strcmp(argv[arg], "-F") == 0)) {
      delete fasta;
      fasta = new seqCache(argv[++arg]);

    } else if (strcmp(argv[arg], "-i") == 0) {

      failIfNoSource();

      ++arg;
      if ((argv[arg] == 0L) || (argv[arg][0] == '-'))
        fprintf(stderr, "ERROR: next arg to -i should be 'name', I got '%s'\n",
                (argv[arg] == 0L) ? "(nullpointer)" : argv[arg]), exit(1);

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++)
        fprintf(stdout, "G\tseq\t%s:"F_U32"\t"F_U32"\t%s\n",
                argv[arg], s, fasta->getSequenceLength(s), ">unimplemented");

    } else if (strcmp(argv[arg], "-d") == 0) {
      failIfNoSource();
      printf(F_U32"\n", fasta->getNumberOfSequences());

    } else if (strcmp(argv[arg], "-L") == 0) {
      uint32 small = strtouint32(argv[++arg]);
      uint32 large = strtouint32(argv[++arg]);

      failIfNoSource();

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++)
        if ((small <= fasta->getSequenceLength(s)) && (fasta->getSequenceLength(s) < large))
          printSequence(s);

    } else if (strcmp(argv[arg], "-N") == 0) {
      double small = atof(argv[++arg]);
      double large = atof(argv[++arg]);

      failIfNoSource();

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++) {
        seqInCore *S   = fasta->getSequenceInCore(s);
        uint32     Ns  = 0;
        uint32     len = S->sequenceLength();
        char      *seq = S->sequence();

        for (uint32 i=begPos; i<len && i<endPos; i++)
          if ((seq[i] == 'n') || (seq[i] == 'N'))
            Ns++;

        double Np = 100.0 * Ns / len;

        if ((small <= Np) && (Np < large))
          printSequence(S);

        delete S;
      }

    } else if (strcmp(argv[arg], "-W") == 0) {
      failIfNoSource();

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++)
        printSequence(s);

    } else if (strcmp(argv[arg], "-G") == 0) {
      uint32 n = strtouint32(argv[++arg]);
      uint32 s = strtouint32(argv[++arg]);
      uint32 l = strtouint32(argv[++arg]);

      char      bases[4] = {'A', 'C', 'G', 'T'};
      char     *def      = new char [1024];
      char     *seq      = new char [l + 1];

      if (s == 0)
        s = 1;
      if (s > l)
        fprintf(stderr, "leaff: usage: -G num-seqs min-length max-length\n"), exit(1);

      for (uint32 i=0; i<n; i++) {
        uint32 j = s + ((l-s == 0) ? 0 : (MT.mtRandom32() % (l-s)));
        uint32 p = 0;

        while (p < j)
          seq[p++] = bases[MT.mtRandom32() & 0x3];
        seq[p] = 0;

        sprintf(def, "random%06"F_U32P, i);

        printSequence(def, seq, 0, j);
      }

      delete [] seq;
      delete [] def;

    } else if (strcmp(argv[arg], "-s") == 0) {
      failIfNoSource();
      failIfNotRandomAccess();  //  Easy to fix, just read the first N sequences
      printSequence(argv[++arg]);

    } else if (strcmp(argv[arg], "-S") == 0) {
      failIfNoSource();
      failIfNotRandomAccess();  //  Easy to fix, just read the first N sequences

      uint32 lowID  = fasta->getSequenceIID(argv[++arg]);
      uint32 highID = fasta->getSequenceIID(argv[++arg]);

      if (lowID > highID) {
        uint32 t = lowID;
        lowID    = highID;
        highID   = t;
      }

      for (uint32 s=lowID; (s <= highID) && (s <= fasta->getNumberOfSequences()); s++)
        printSequence(s);

    } else if (strcmp(argv[arg], "-r") == 0) {
      uint32 num = strtouint32(argv[++arg]);

      failIfNoSource();
      failIfNotRandomAccess();  //  Impossible to fix, or load whole thing into memory

      if (num >= fasta->getNumberOfSequences())
        num = fasta->getNumberOfSequences();

      uint32  *seqs = new uint32 [fasta->getNumberOfSequences()];

      for (uint32 i=0; i<fasta->getNumberOfSequences(); i++)
        seqs[i] = i;

      for (uint32 i=0; i<fasta->getNumberOfSequences(); i++) {
        uint32 j = MT.mtRandom32() % (fasta->getNumberOfSequences() - i) + i;
        uint32 t = seqs[j];
        seqs[j] = seqs[i];
        seqs[i] = t;
      }

      for (uint32 i=0; i<num; i++)
        printSequence(seqs[i]);

      delete [] seqs;

    } else if (strcmp(argv[arg], "-q") == 0) {
      failIfNoSource();
      failIfNotRandomAccess();  //  Impossible to fix, or load whole thing into memory
      printIDsFromFile(argv[++arg]);

    } else if (strcmp(argv[arg], "-6") == 0) {
      withLineBreaks = 60;
      if ((argv[arg+1] != 0L) && (argv[arg+1][0] != '-'))
        withLineBreaks = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-w") == 0) {
      toUppercase = !toUppercase;
      for (int z=0; z<256; z++)
        translate[z] = (toUppercase) ? alphabet.toUpper(z) : (char)z;

    } else if (strcmp(argv[arg], "-R") == 0) {
      doReverse = !doReverse;

    } else if (strcmp(argv[arg], "-C") == 0) {
      doComplement = !doComplement;

    } else if (strcmp(argv[arg], "-H") == 0) {
      withDefLine    = !withDefLine;
      specialDefLine = 0L;

    } else if (strcmp(argv[arg], "-h") == 0) {
      withDefLine    = true;
      specialDefLine = argv[++arg];

    } else if (strcmp(argv[arg], "-e") == 0) {
      begPos = strtouint32(argv[++arg]);
      endPos = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-ends") == 0) {
      endExtract = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-A") == 0) {
      processFile(argv[++arg]);



    } else if (strcmp(argv[arg], "--findduplicates") == 0) {
      findDuplicates(argv[++arg]);
      exit(0);

    } else if (strcmp(argv[arg], "--mapduplicates") == 0) {
      mapDuplicates(argv[arg+1], argv[arg+2]);
      exit(0);

    } else if (strcmp(argv[arg], "--md5") == 0) {
      md5_s     md5;
      char      sum[33];

      fasta = new seqCache(argv[++arg]);

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++) {
        seqInCore *S = fasta->getSequenceInCore(s);
        fprintf(stdout, "%s %s\n",
                md5_toascii(md5_string(&md5, S->sequence(), S->sequenceLength()), sum),
                S->header());
        delete S;
      }
      delete fasta;
      exit(0);

    } else if ((strcmp(argv[arg], "--partition") == 0) ||
               (strcmp(argv[arg], "--partitionmap") == 0)) {

      char *prefix = 0L;
      if (strcmp(argv[arg], "--partition") == 0)
        prefix = argv[++arg];

      //  does the next arg end with gbp, mbp, kbp or bp?  If so,
      //  partition by length, else partition into buckets.
      //
      int     al = strlen(argv[arg+1]);
      uint64  ps = strtouint64(argv[arg+1]);

      char a3 = (al<3) ? '0' : alphabet.toLower(argv[arg+1][al-3]);
      char a2 = (al<2) ? '0' : alphabet.toLower(argv[arg+1][al-2]);
      char a1 = (al<1) ? '0' : alphabet.toLower(argv[arg+1][al-1]);

      //  partition!

      if (!isdigit(a1) || !isdigit(a2) || !isdigit(a3)) {
        if        ((a3 == 'g') && (a2 == 'b') && (a1 == 'p')) {
          ps *= 1000000000;
        } else if ((a3 == 'm') && (a2 == 'b') && (a1 == 'p')) {
          ps *= 1000000;
        } else if ((a3 == 'k') && (a2 == 'b') && (a1 == 'p')) {
          ps *= 1000;
        } else if (isdigit(a3) && (a2 == 'b') && (a1 == 'p')) {
          ps *= 1;
        } else {
          fprintf(stderr, "Unknown partition size option '%s'\n", argv[arg+1]), exit(1);
        }

        if (ps == 0)
          fprintf(stderr, "Unknown or zero partition size '%s'\n", argv[arg+1]), exit(1);
        partitionBySize(prefix, ps, argv[arg+2]);
      } else {
        if (ps == 0)
          fprintf(stderr, "Unknown or zero partition size '%s'\n", argv[arg+1]), exit(1);
        partitionByBucket(prefix, ps, argv[arg+2]);
      }
      exit(0);

    } else if (strcmp(argv[arg], "--segment") == 0) {
      partitionBySegment(argv[arg+1], strtouint32(argv[arg+2]), argv[arg+3]);
      exit(0);

    } else if (strcmp(argv[arg], "--gccontent") == 0) {
      computeGCcontent(argv[++arg]);
      exit(0);

    } else if (strcmp(argv[arg], "--dumpblocks") == 0) {
      dumpBlocks(argv[++arg]);
      exit(0);

    } else if (strcmp(argv[arg], "--stats") == 0) {
      stats(argv[arg+1], (argv[arg+2] != 0L) ? strtouint64(argv[arg+2]) : 0);
      exit(0);

    } else if (strcmp(argv[arg], "--errors") == 0) {
      int    L = strtouint32(argv[++arg]);     //  Desired length
      int    l = 0;                            //  min of desired length, length of sequence
      int    N = strtouint32(argv[++arg]);     //  number of copies per sequence
      int    C = strtouint32(argv[++arg]);     //  number of mutations per copy
      double P = atof(argv[++arg]);            //  probability of mutation
      uint32 i = 0;

      fasta = new seqCache(argv[++arg]);

      seqInCore *S = fasta->getSequenceInCore(i++);
      while (S) {
        char   *seq = S->sequence();
        char   *hdr = S->header();
        int     len = S->sequenceLength();

        l = len;
        if ((L > 0) && (L < len))
          l = L;

        simseq(seq, hdr, len, N, l, C, P);

        delete S;
        S = fasta->getSequenceInCore(i++);
      }
      delete fasta;
      exit(0);

    } else if (strcmp(argv[arg], "--seqstore") == 0) {
      constructSeqStore(argv[++arg], fasta);
      exit(0);

    } else if (strcmp(argv[arg], "-help") == 0) {
      if      ((argv[arg+1]) && (strcmp(argv[arg+1], "analysis") == 0))
        helpAnalysis(argv[0]);
      else if ((argv[arg+1]) && (strcmp(argv[arg+1], "examples") == 0))
        helpExamples(argv[0]);
      else
        helpStandard(argv[0]);
      exit(0);

    } else {
      helpStandard(argv[0]);
      fprintf(stderr, "Unknown option '%s'\n", argv[arg]);
      exit(1);
    }

    arg++;
  }

  delete fasta;
  fasta = 0L;
}
コード例 #22
0
ファイル: file_cache.c プロジェクト: bbockelm/cctools
static void cached_name(struct file_cache *c, const char *path, char *lpath)
{
	unsigned char digest[MD5_DIGEST_LENGTH];
	md5_buffer(path, strlen(path), digest);
	sprintf(lpath, "%s/%02x/%s", c->root, digest[0], md5_string(digest));
}
コード例 #23
0
ファイル: jmd5.cpp プロジェクト: hszander/HPCC-Platform
void md5_string(StringBuffer& inpstring, StringBuffer& outstring)
{
    md5_string(inpstring, inpstring.length(), outstring);
}
コード例 #24
0
ファイル: jmd5.cpp プロジェクト: hszander/HPCC-Platform
void md5_string2(const char* inpstring, StringBuffer& outstring)
{
    md5_string(inpstring,(size32_t)strlen(inpstring),outstring);
}
コード例 #25
0
ファイル: main.cpp プロジェクト: DayBreakZhang/acl
int main()
{
	const char* s = "中国人民银行!";
	const char* key = "zsxxsz";
	char  buf1[33], buf2[33];

	acl::md5::md5_string(s, strlen(s), key, strlen(key),
		buf1, sizeof(buf1));
	printf("first md5: %s\r\n", buf1);

	md5_string(s, key, strlen(key), buf2, sizeof(buf2));
	printf("second md5: %s\r\n", buf2);

	assert(strcmp(buf1, buf2) == 0);

	/////////////////////////////////////////////////////////////////////

	acl::md5 md5;

	s = "ABCDEFGHIGKLMNOPQRSTUVWXYZ";
	md5.update(s, strlen(s));
	md5.finish();
	acl::safe_snprintf(buf1, sizeof(buf1), "%s", md5.get_string());

	md5.reset();

	char ch;
	size_t len = strlen(s);
	for (size_t i = 0; i < len; i++)
	{
		ch = s[i];
		md5.update(&ch, 1);
	}
	md5.finish();
	acl::safe_snprintf(buf2, sizeof(buf2), "%s", md5.get_string());

	if (strcmp(buf1, buf2) == 0)
		printf("OK: %s\r\n", buf1);
	else
		printf("error, buf1: %s, buf2: %s\r\n", buf1, buf2);

	/////////////////////////////////////////////////////////////////////

	md5.reset();
	len = 1024000;
	char* buf = (char*) malloc(len);

	for (size_t i = 0; i < len; i++)
	{
		ch = i % 255;
		buf[i] = ch;
		md5.update(&ch, 1);
	}
	md5.finish();
	acl::safe_snprintf(buf1, sizeof(buf1), "%s", md5.get_string());

	md5.reset();
	md5.update(buf, len);
	md5.finish();
	acl::safe_snprintf(buf2, sizeof(buf2), "%s", md5.get_string());

	if (strcmp(buf1, buf2) == 0)
		printf("OK2: %s\r\n", buf1);
	else
		printf("error, buf1: %s, buf2: %s\r\n", buf1, buf2);
#ifdef WIN32
	getchar();
#endif
	return 0;
}
コード例 #26
0
ファイル: sched_util.cpp プロジェクト: Murph9000/boinc-v2
static void filename_hash(const char* filename, int fanout, char* dir) {
    std::string s = md5_string((const unsigned char*)filename, strlen(filename));
    int x = strtol(s.substr(1, 7).c_str(), 0, 16);
    sprintf(dir, "%x", x % fanout);
}
コード例 #27
0
ファイル: test-readBuffer.C プロジェクト: bryopsis/trinity
int
main(int argc, char **argv) {
  int         error = 0;
  readBuffer *B = 0L;

  size_t      L = 0;
  size_t      H = 0;
  size_t      R = 0;

  //  If we are given a file, use that, otherwise, use ourself.
  //
  filename = argv[argc-1];

  L = sizeOfFile(filename);
  H = L/2;
  R = L - H;

  fprintf(stderr, "L=%d H=%d R=%d\n", L, H, R);

  //  Suck in the whole file, compute the correct md5 checksum on it
  //
  char *c = new char [L];

  FILE *F = fopen(filename, "r");
  fread(c, sizeof(char), L, F);
  fclose(F);
  full = md5_string(0L, c,   L);
  part = md5_string(0L, c+H, R);

  delete [] c;


  B = new readBuffer(filename, 999);
  error += doTest(B, full, "#1 (read)");
  B->seek(0);
  error += doTest(B, full, "#2 (seek)");
  B->seek(H);
  error += doTest(B, part, "#2 (seek half)");
  delete B;

  B = new readBuffer(filename, 0);
  error += doTest(B, full, "#3 (mmap)");
  B->seek(0);
  error += doTest(B, full, "#2 (mmap seek)");
  B->seek(H);
  error += doTest(B, part, "#2 (mmap seek half)");
  delete B;

  B = new readBuffer(filename, 0);
  error += doTestRead(B, full, 10000, "#4 (read buffer=mmap readsize=10000)");
  delete B;

  B = new readBuffer(filename, 100);
  error += doTestRead(B, full, 10000, "#4 (read buffer=100 readsize=10000)");
  delete B;

  B = new readBuffer(filename, 2000);
  error += doTestRead(B, full, 1000, "#4 (read buffer=2000 readsize=1000)");
  delete B;

  B = new readBuffer(filename, L);
  error += doTestRead(B, full, L+1000, "#5 (read buffer=filesize readsize=filesize+1000)");
  delete B;

  return(error);
}
コード例 #28
0
ファイル: binwalk.c プロジェクト: Franc1/firmware-mod-kit
/* Search a file for magic signatures */
int process_file(char *bin_file, struct binconf *config, struct magic_signature **signatures, int num_sigs, struct magic_filter **filters, int filter_count)
{
	char *md5 = NULL, *current_time = NULL, *ptr = NULL;
	const void *buffer = NULL, *type = NULL;
	size_t fsize = 0;
	int i = 0, j = 0, retval = EXIT_FAILURE;

	/* Read in the target file */
	buffer = file_read(bin_file, &fsize);
	if(!buffer || fsize == 0)
	{
		fprintf(stderr,"ERROR: Failed to read file '%s'.\n", bin_file);
		goto end;
	}

	/* If no scan length was specified, scan the entire file */
	if(!config->length || config->length > fsize)
	{
		config->length = fsize;
	}

	/* Sanity check on the length + offset values */
	if((config->length + config->offset) > fsize)
	{
		config->length -= (config->length + config->offset) - fsize;
	}

	if(config->verbose)
	{
		md5 = md5_string((void *) buffer,fsize);
		current_time = timestamp();
		print("\n");
		print("Scan Time:    %s\n", current_time);
		print("Magic File:   %s\n", config->magic);
		if(config->smart)
		{
			print("Signatures:   %d\n", num_sigs);
		}
		else
		{
			print("Signatures:   *\n");
		}
		print("Target File:  %s\n", bin_file);
		print("MD5 Checksum: %s\n", md5);
		if(current_time) free(current_time);
		if(md5) free(md5);
	}

	print("\nDECIMAL   \tHEX       \tDESCRIPTION\n");
	print("-------------------------------------------------------------------------------------------------------\n");

	/* Loop through the file contents starting at the given offset.
	 * Honor the given byte alignment (i.e., if align == 4, only look at every 4th byte).
	 * Stop looping when length bytes have been searched, or when the end of the file is reached.
	 */
	for(i=config->offset; ((i-config->offset)<config->length && i<(fsize-config->align)); i+=config->align)
	{
		for(j=0; j<num_sigs; j++)
		{
			/* Make sure we don't seek past the end of the buffer */
			if(!config->smart || (i+signatures[j]->offset < fsize))
			{
				/* Pre-screen data for magic file signatures prior to invoking libmagic. This significantly improves scan time. */
				if(!config->smart || 
				   signatures[j]->wildcard == 1 || 
				   memcmp((buffer+i+signatures[j]->offset), signatures[j]->signature, signatures[j]->size) == 0
				)
				{
					/* Since we found a signature match, ask libmagic to further examine the given offset into the file buffer */
                        		type = magic_buffer(config->cookie, buffer+i, (fsize-i));

                        		/* Ignore NULL, ".*text.*" and "data" responses */
                        		if(type != NULL && strncmp(type,DATA,DATA_SIZE) != 0 && strstr(type,TEXT) == NULL)
					{
						/* 
						 * If filters were specified and the filter check specifies that
						 * result should be excluded, then don't display it.
						 */
						if(filter_count > 0)
						{
							/* Don't display anything that has been explicitly marked in the exclude list */
							if(filter_check(filters, filter_count, (char *) type) == RESULT_EXCLUDE)
							{
								break;
							}
						}
                                	
						/* Prettify output if multiple matches were found at the same offset */	
						if((config->flags | MAGIC_CONTINUE) == config->flags)
						{
							while((ptr = strstr(type, MULTIPLE_MATCH_DELIM)))
							{
								memcpy(ptr, MULTIPLE_MATCH_NEWLINE, MULTIPLE_MATCH_SIZE);
							}
						}

						print("%-10d\t0x%-8X\t",i,i);
						print("%s\n",type);
						break;
                        		}
				}
			}
		}
	}

	print("\n");
	retval = EXIT_SUCCESS;

end:
	if(buffer) munmap((void *) buffer, fsize);
	return retval;
}