コード例 #1
0
ファイル: handle_request.cpp プロジェクト: hanxue/Boinc
bool unacceptable_os() {
    unsigned int i;
    char buf[1024];

    for (i=0; i<config.ban_os->size(); i++) {
        regex_t& re = (*config.ban_os)[i];
        safe_strcpy(buf, g_request->host.os_name);
        safe_strcat(buf, "\t");
        safe_strcat(buf, g_request->host.os_version);
        if (!regexec(&re, buf, 0, NULL, 0)) {
            log_messages.printf(MSG_NORMAL,
                                "Unacceptable OS %s %s\n",
                                g_request->host.os_name, g_request->host.os_version
                               );
            sprintf(buf, "%s %s %s",
                    _("This project doesn't support operating system"),
                    g_request->host.os_name, g_request->host.os_version
                   );
            g_reply->insert_message(buf, "notice");
            g_reply->set_delay(DELAY_UNACCEPTABLE_OS);
            return true;
        }
    }
    return false;
}
コード例 #2
0
ファイル: tokenize.c プロジェクト: arv100kri/linkparser
/**
 * This just looks up all the words in the sentence, and builds
 * up an appropriate error message in case some are not there.
 * It has no side effect on the sentence.  Returns TRUE if all
 * went well.
 */
int sentence_in_dictionary(Sentence sent)
{
	int w, ok_so_far;
	char * s;
	Dictionary dict = sent->dict;
	char temp[1024];

	ok_so_far = TRUE;
	for (w=0; w<sent->length; w++)
	{
		s = sent->word[w].string;
		if (!boolean_dictionary_lookup(dict, s) &&
		    !(is_utf8_upper(s)   && dict->capitalized_word_defined) &&
		    !(is_utf8_upper(s) && is_s_word(s) && dict->pl_capitalized_word_defined) &&
		    !(ishyphenated(s) && dict->hyphenated_word_defined)  &&
		    !(is_number(s)	&& dict->number_word_defined) &&
		    !(is_ing_word(s)  && dict->ing_word_defined)  &&
		    !(is_s_word(s)	&& dict->s_word_defined)  &&
		    !(is_ed_word(s)   && dict->ed_word_defined)  &&
		    !(is_ly_word(s)   && dict->ly_word_defined))
		{
			if (ok_so_far) {
				safe_strcpy(temp, "The following words are not in the dictionary:", sizeof(temp));
				ok_so_far = FALSE;
			}
			safe_strcat(temp, " \"", sizeof(temp));
			safe_strcat(temp, sent->word[w].string, sizeof(temp));
			safe_strcat(temp, "\"", sizeof(temp));
		}
	}
	if (!ok_so_far) {
		lperror(NOTINDICT, "\n%s\n", temp);
	}
	return ok_so_far;
}
コード例 #3
0
ファイル: handle_request.cpp プロジェクト: hanxue/Boinc
bool unacceptable_cpu() {
    unsigned int i;
    char buf[1024];

    for (i=0; i<config.ban_cpu->size(); i++) {
        regex_t& re = (*config.ban_cpu)[i];
        safe_strcpy(buf, g_request->host.p_vendor);
        safe_strcat(buf, "\t");
        safe_strcat(buf, g_request->host.p_model);
        if (!regexec(&re, buf, 0, NULL, 0)) {
            log_messages.printf(MSG_NORMAL,
                                "Unacceptable CPU %s %s\n",
                                g_request->host.p_vendor, g_request->host.p_model
                               );
            sprintf(buf, "%s %s %s",
                    _("This project doesn't support CPU type"),
                    g_request->host.p_vendor, g_request->host.p_model
                   );
            g_reply->insert_message(buf, "notice");
            g_reply->set_delay(DELAY_UNACCEPTABLE_OS);
            return true;
        }
    }
    return false;
}
コード例 #4
0
/****************************************************************************
Append single file to tar file (or not)
***************************************************************************/
static void do_tar(file_info *finfo)
{
  pstring rname;

  if (strequal(finfo->name,"..") || strequal(finfo->name,"."))
    return;

  /* Is it on the exclude list ? */
  if (!tar_excl && clipn) {
    pstring exclaim;

    DEBUG(5, ("Excl: strlen(cur_dir) = %d\n", (int)strlen(cur_dir)));

    safe_strcpy(exclaim, cur_dir, sizeof(pstring));
    *(exclaim+strlen(exclaim)-1)='\0';

    safe_strcat(exclaim, "\\", sizeof(pstring));
    safe_strcat(exclaim, finfo->name, sizeof(exclaim));

    DEBUG(5, ("...tar_re_search: %d\n", tar_re_search));

    if ((!tar_re_search && clipfind(cliplist, clipn, exclaim)) ||
#ifdef HAVE_REGEX_H
	(tar_re_search && !regexec(preg, exclaim, 0, NULL, 0))) {
#else
        (tar_re_search && mask_match(exclaim, cliplist[0], True, False))) {
#endif
      DEBUG(3,("Skipping file %s\n", exclaim));
      return;
    }
  }
コード例 #5
0
ファイル: asc.c プロジェクト: sorlok/Eternal-Lands
/* whether you pass in a NULL pointer or your own allocated memory for
 * out_str, you need to free the memory yourself */
char *substitute_char_with_string(const char *str, char **out_str, char to_sub, const char* with_sub)
{
	int amp_count = 0;
	const char *start_ptr;
	char *end_ptr;
	int out_len = 0;
	size_t alloc_len = 0;

	for (start_ptr = str; (start_ptr = strchr(start_ptr, to_sub)) != NULL; start_ptr++)
		amp_count++;

	alloc_len = strlen(str) + amp_count*(strlen(with_sub)-1) + 1;
	*out_str = (char *)realloc(*out_str, alloc_len);
	**out_str = '\0';
	
	for (start_ptr = str; (end_ptr = strchr(start_ptr, to_sub)) != NULL; )
	{
		while (start_ptr < end_ptr)
			(*out_str)[out_len++] = *start_ptr++;
		(*out_str)[out_len] = '\0';

		safe_strcat(*out_str, with_sub, alloc_len);
		out_len = strlen(*out_str);
		start_ptr++;
	}
	safe_strcat(*out_str, start_ptr, alloc_len);
	return *out_str;
}
コード例 #6
0
int list_ignores()
{
	int i;
	char str[MAX_IGNORES*19];
	
	if(!ignored_so_far)
		{
			LOG_TO_CONSOLE(c_grey1,no_ignores_str);
			return 1;
		}
	safe_snprintf(str,sizeof(str),"%s:\n",ignores_str);
	for(i=0;i<MAX_IGNORES;i++)
		{
			if(ignore_list[i].used)
				{
					safe_strcat (str, ignore_list[i].name, sizeof(str));
					safe_strcat (str, ", ", sizeof(str));
				}
		}

	str[strlen(str)-2]=0;//get rid of the last ", " thingy

	LOG_TO_CONSOLE(c_grey1,str);
	return 1;
}
コード例 #7
0
ファイル: vfs_afsacl.c プロジェクト: AllardJ/Tomato
static BOOL unparse_afs_acl(struct afs_acl *acl, char *acl_str)
{
	/* TODO: String length checks!!!! */

	int positives = 0;
	int negatives = 0;
	fstring line;

	*acl_str = 0;

	struct afs_ace *ace = acl->acelist;

	while (ace != NULL) {
		if (ace->positive)
			positives++;
		else
			negatives++;
		ace = ace->next;
	}

	fstr_sprintf(line, "%d\n", positives);
	safe_strcat(acl_str, line, MAXSIZE);

	fstr_sprintf(line, "%d\n", negatives);
	safe_strcat(acl_str, line, MAXSIZE);

	ace = acl->acelist;

	while (ace != NULL) {
		fstr_sprintf(line, "%s\t%d\n", ace->name, ace->rights);
		safe_strcat(acl_str, line, MAXSIZE);
		ace = ace->next;
	}
	return True;
}
コード例 #8
0
static void SetupCertFilename()
{

   char default_priv_filename[] = "server.key";
   char default_pub_filename[] = "server.crt";
   char *priv_filename = getenv("SQCERT_PRIVKEY");
   char *pub_filename = getenv("SQCERT_PUBKEY");
   char *clustername  = getenv("CLUSTERNAME");
   char *homedir  = getenv("HOME");
   char *sqroot  = getenv("MY_SQROOT");
   char *certdir = getenv("SQCERT_DIR");

   // Get the Certificate directory and the filename
   // If the env variable SQCERT_DIR
   // For a Cluster - look

   if (certdir == NULL)
   {
      if (clustername != NULL)
      {
         strncpy (privkey_file, homedir, MS_MON_MAX_PROCESS_PATH);
         privkey_file[MS_MON_MAX_PROCESS_PATH-1] = 0;
      }

      else
      { // it's a workstation

      if (sqroot != NULL)
      {
         strncpy (privkey_file, sqroot, MS_MON_MAX_PROCESS_PATH);
         privkey_file[MS_MON_MAX_PROCESS_PATH-1] = 0;
      }
      else
         strcpy (privkey_file, "/tmp");
      }

      safe_strcat (privkey_file, (char *) "/sqcert/", MS_MON_MAX_PROCESS_PATH);
   }
   else
   {
      strncpy(privkey_file, certdir, MS_MON_MAX_PROCESS_PATH);
      privkey_file[MS_MON_MAX_PROCESS_PATH-1] == 0;
      strcat (privkey_file, "/");
   }

   // Done forming the directory location - copy the same to public file
   strcpy(pubkey_file, privkey_file);

   if (priv_filename != NULL)
      safe_strcat (privkey_file, priv_filename, MS_MON_MAX_PROCESS_PATH);  
   else
      safe_strcat (privkey_file, default_priv_filename, MS_MON_MAX_PROCESS_PATH);

   if (pub_filename != NULL)
      safe_strcat (pubkey_file, pub_filename, MS_MON_MAX_PROCESS_PATH);
   else
      safe_strcat (pubkey_file, default_pub_filename, MS_MON_MAX_PROCESS_PATH);

}
コード例 #9
0
/****************************************************************************
Ensure a remote path exists (make if necessary)
***************************************************************************/
static BOOL ensurepath(char *fname)
{
  /* *must* be called with buffer ready malloc'ed */
  /* ensures path exists */

  char *partpath, *ffname;
  char *p=fname, *basehack;

  DEBUG(5, ( "Ensurepath called with: %s\n", fname));

  partpath = string_create_s(strlen(fname));
  ffname = string_create_s(strlen(fname));

  if ((partpath == NULL) || (ffname == NULL)){

    DEBUG(0, ("Out of memory in ensurepath: %s\n", fname));
    return(False);

  }

  *partpath = 0;

  /* fname copied to ffname so can strtok */

  safe_strcpy(ffname, fname, strlen(fname));

  /* do a `basename' on ffname, so don't try and make file name directory */
  if ((basehack=strrchr(ffname, '\\')) == NULL)
    return True;
  else
    *basehack='\0';

  p=strtok(ffname, "\\");

  while (p)
    {
      safe_strcat(partpath, p, strlen(fname) + 1);

      if (!cli_chkpath(cli, partpath)) {
	if (!cli_mkdir(cli, partpath))
	  {
	    DEBUG(0, ("Error mkdirhiering\n"));
	    return False;
	  }
	else
	  DEBUG(3, ("mkdirhiering %s\n", partpath));

      }

      safe_strcat(partpath, "\\", strlen(fname) + 1);
      p = strtok(NULL,"/\\");
    }

    return True;
}
コード例 #10
0
ファイル: sched_types.cpp プロジェクト: freehal/boinc-freehal
int RESULT::parse_from_client(FILE* fin) {
    char buf[256];

    // should be non-zero if exit_status is not found
    exit_status = ERR_NO_EXIT_STATUS;
    memset(this, 0, sizeof(RESULT));
    while (fgets(buf, sizeof(buf), fin)) {
        if (match_tag(buf, "</result>")) {
            return 0;
        }
        if (parse_str(buf, "<name>", name, sizeof(name))) continue;
        if (parse_int(buf, "<state>", client_state)) continue;
        if (parse_double(buf, "<final_cpu_time>", cpu_time)) continue;
        if (parse_double(buf, "<final_elapsed_time>", elapsed_time)) continue;
        if (parse_int(buf, "<exit_status>", exit_status)) continue;
        if (parse_int(buf, "<app_version_num>", app_version_num)) continue;
        if (parse_double(buf, "<fpops_per_cpu_sec>", fpops_per_cpu_sec)) continue;
        if (parse_double(buf, "<fpops_cumulative>", fpops_cumulative)) continue;
        if (parse_double(buf, "<intops_per_cpu_sec>", intops_per_cpu_sec)) continue;
        if (parse_double(buf, "<intops_cumulative>", intops_cumulative)) continue;
        if (match_tag(buf, "<file_info>")) {
            safe_strcat(xml_doc_out, buf);
            while (fgets(buf, sizeof(buf), fin)) {
                safe_strcat(xml_doc_out, buf);
                if (match_tag(buf, "</file_info>")) break;
            }
            continue;
        }
        if (match_tag(buf, "<stderr_out>" )) {
            while (fgets(buf, sizeof(buf), fin)) {
                if (match_tag(buf, "</stderr_out>")) break;
                safe_strcat(stderr_out, buf);
            }
            continue;
        }
        if (match_tag(buf, "<platform>")) continue;
        if (match_tag(buf, "<version_num>")) continue;
        if (match_tag(buf, "<plan_class>")) continue;
        if (match_tag(buf, "<completed_time>")) continue;
        if (match_tag(buf, "<file_name>")) continue;
        if (match_tag(buf, "<file_ref>")) continue;
        if (match_tag(buf, "</file_ref>")) continue;
        if (match_tag(buf, "<open_name>")) continue;
        if (match_tag(buf, "<ready_to_report>")) continue;
        if (match_tag(buf, "<ready_to_report/>")) continue;
        if (match_tag(buf, "<report_deadline>")) continue;
        if (match_tag(buf, "<wu_name>")) continue;

        log_messages.printf(MSG_NORMAL,
            "RESULT::parse_from_client(): unrecognized: %s\n",
            buf
        );
    }
    return ERR_XML_PARSE;
}
コード例 #11
0
ファイル: emotes.c プロジェクト: Adamantinus/Eternal-Lands
void update_selectables(){
	int pos,i;
	hash_entry *he;

	i=0;
	pos=vscrollbar_get_pos(emotes_win, EMOTES_SCROLLBAR_ITEMS);
	memset(selectables,0,sizeof(emote_data*)*EMOTES_SHOWN);
	hash_start_iterator(emotes);
	while((he=hash_get_next(emotes))&&i<EMOTES_SHOWN){
		emote_data *emote;

		emote=((emote_data *)he->item);
		if(!cur_cat&&emote->pose>EMOTE_STANDING) {
			//emotes
			pos--;
			if(pos>=0) continue;
			selectables[i]=emote;
			i++;
		} else if(cur_cat&&emote->pose==(cur_cat-1)){
			//poses
			pos--;
			if(pos>=0) continue;
			selectables[i]=emote;
			i++;
		}
	}

	emote_str1[1]=emote_str2[0]=emote_str2[1]=0;
	if(emote_sel[cur_cat]){
		emote_dict *emd;

		emote_str1[0]=127+c_orange2;
		safe_strcat((char*)emote_str1,(char*)emote_sel[cur_cat]->desc,/*sizeof(emote_str1)*/23);
		hash_start_iterator(emote_cmds);
		while((he=hash_get_next(emote_cmds))){
			emd = (emote_dict*)he->item;
			if (emd->emote==emote_sel[cur_cat]){
				int ll;
				//draw command
				if(!emote_str2[0]) {
					emote_str2[0]=127+c_grey1;
					safe_strcat((char*)emote_str2,"Trigger:",10);
				}
				ll=strlen((char*)emote_str2);
				emote_str2[ll]=127+c_green3;
				emote_str2[ll+1]=emote_str2[ll+2]=' ';
				emote_str2[ll+3]=0;
				safe_strcat((char*)emote_str2,emd->command,/*sizeof(emote_str2)*/23);
				break; //just one command
			}
		}
	}
	
}
コード例 #12
0
ファイル: vfs_my_module.c プロジェクト: int-argc/CVFS2.0
static int vfs_my_module_create_dir(vfs_handle_struct *handle, const char *dname, const struct smb_filename *smb_fname)
{
	size_t len;
	mode_t mode;
	char *new_dir = NULL;
	char *tmp_str = NULL;
	char *token;
	char *tok_str;
	bool ret = False;
	char *saveptr;
    int i = 0;
	mode = vfs_my_module_directory_mode(handle);

	tmp_str = SMB_STRDUP(dname);
	ALLOC_CHECK(tmp_str, done);
	tok_str = tmp_str;

	len = strlen(dname)+1;
	new_dir = (char *)SMB_MALLOC(len + 1);
	ALLOC_CHECK(new_dir, done);
	*new_dir = '\0';
	if (dname[0] == '/') {
		/* Absolute path. */
		safe_strcat(new_dir,"/",len);
	}

	/* Create directory tree if neccessary */
	for(token = strtok_r(tok_str, "/", &saveptr); token;
	    token = strtok_r(NULL, "/", &saveptr)) {
		safe_strcat(new_dir, token, len);
		if (vfs_my_module_directory_exist(handle, new_dir))
			DEBUG(10, ("CREATE DIR: dir %s already exists\n", new_dir));
		else {
			DEBUG(1, ("CREATE DIR: creating new dir %s\n", new_dir));
			if (SMB_VFS_NEXT_MKDIR(handle, new_dir,mode) != 0) {
				DEBUG(1,("CREATE DIR: failed for %s with error: %s\n", new_dir, strerror(errno)));
				ret = False;
			}

		}
		safe_strcat(new_dir, "/", len);
		mode = vfs_my_module_subdir_mode(handle);
	i++;
	DEBUG(1,("CREATE DIR COUNTER: %d\n", i));
	ret = True;
	}
done:
	SAFE_FREE(tmp_str);
	SAFE_FREE(new_dir);
	return i;
}
コード例 #13
0
static BOOL check_cache( char *s, size_t maxlen, int snum )
{
	TDB_DATA data_val;
	char *ext_start = NULL;
	char *saved_ext = NULL;

	magic_char = lp_magicchar(snum);

	/* If the cache isn't initialized, give up. */
	if( !tdb_mangled_cache )
		return( False );

	data_val = tdb_fetch_bystring(tdb_mangled_cache, s);

	/* If we didn't find the name *with* the extension, try without. */
	if(data_val.dptr == NULL || data_val.dsize == 0) {
		ext_start = strrchr( s, '.' );
		if( ext_start ) {
			if((saved_ext = SMB_STRDUP(ext_start)) == NULL)
				return False;

			*ext_start = '\0';
			data_val = tdb_fetch_bystring(tdb_mangled_cache, s);
			/* 
			 * At this point s is the name without the
			 * extension. We re-add the extension if saved_ext
			 * is not null, before freeing saved_ext.
			 */
		}
	}

	/* Okay, if we haven't found it we're done. */
	if(data_val.dptr == NULL || data_val.dsize == 0) {
		if(saved_ext) {
			/* Replace the saved_ext as it was truncated. */
			(void)safe_strcat( s, saved_ext, maxlen );
			SAFE_FREE(saved_ext);
		}
		return( False );
	}

	/* If we *did* find it, we need to copy it into the string buffer. */
	(void)safe_strcpy( s, data_val.dptr, maxlen );
	if( saved_ext ) {
		/* Replace the saved_ext as it was truncated. */
		(void)safe_strcat( s, saved_ext, maxlen );
		SAFE_FREE(saved_ext);
	}
	SAFE_FREE(data_val.dptr);
	return( True );
}
コード例 #14
0
ファイル: strfuns.c プロジェクト: h3rb/Assault-3.0
void pre_parse( char * list, char * victimname, char * containername, char * things )
{
    char arg1[MSL];
    char container_name[MSL];
    char one_object[MSL];
    char holdbuf[MSL];
    char victim_name[MSL];
    char object_list[MSL];
    char * argument = list;
    container_name[0] = '\0';
    victim_name[0] = '\0';
    object_list[0] = '\0';
    for ( ; ; )
    {
        argument = one_argument( argument, arg1 );
        if ( arg1[0] == '\0' )
            break;
        if (  ( !str_cmp( "from", arg1 ) )
            || ( !str_cmp( "in", arg1 ) )  )
        {
            argument = one_argument( argument, container_name );
        }
        else if ( !str_cmp( "to", arg1 ) )
        {
            argument = one_argument( argument, victim_name );
        }
        else if ( object_list[0] != '\0' )
        {
            safe_strcat(MSL,victim_name,arg1);
        }
        else
        {
            if ( is_number( arg1 ) )
            {
                argument = one_argument( argument, one_object );
                sprintf( holdbuf, "%s %s ", arg1, one_object );
                safe_strcat( MSL, object_list, holdbuf );
            }
            else
            {
                sprintf( holdbuf, "1 %s ", arg1 );
                safe_strcat( MSL, object_list, holdbuf );
            }
        }
    }
    strcpy( victimname , victim_name );
    strcpy( things,object_list);
    strcpy( containername , container_name);
    return;
}
コード例 #15
0
ファイル: add_code.c プロジェクト: Jacopo/elf_add_code
//static char* link_obj(const char *objects[], int n_objects, const char *original_program, unsigned long requested_vaddr, bool before_entry)
static char* link_obj(const char *object, const char *original_program, unsigned long requested_vaddr, bool before_entry)
{
    char exec_filename[255] = "/tmp/add_elf_code_XXXXXX";
    V(mkdtemp(exec_filename) != NULL);
    strcat(exec_filename, "/exec_to_add");

    char cmdline[500];
    int cmdlen = snprintf(cmdline, sizeof(cmdline),
            "'%s/link_o.py' --original-program '%s' -o '%s' --start-address=0x%lx",
            MY_PATH, original_program, exec_filename, requested_vaddr);
    VS(cmdlen); V(cmdlen < ((int) sizeof(cmdline)));
//    for (int i; i < n_objects; i++) {
//        safe_strcat(cmdline, " '", sizeof(cmdline));
//        safe_strcat(cmdline, objects[i], sizeof(cmdline));
//        safe_strcat(cmdline, "'", sizeof(cmdline));
//    }
    safe_strcat(cmdline, " '", sizeof(cmdline));
    safe_strcat(cmdline, object, sizeof(cmdline));
    safe_strcat(cmdline, "'", sizeof(cmdline));

    if (before_entry) {
        safe_strcat(cmdline, " '", sizeof(cmdline));
        safe_strcat(cmdline, MY_PATH, sizeof(cmdline));
        safe_strcat(cmdline, "/", sizeof(cmdline));
        safe_strcat(cmdline, ENTRY_HELPER, sizeof(cmdline));
        safe_strcat(cmdline, "'", sizeof(cmdline));
    }
    info("Running %s\n", cmdline);
    V(system(cmdline) == 0);

    return strdup(exec_filename);
}
コード例 #16
0
ファイル: config.c プロジェクト: dopefishh/btd
void btd_config_populate(struct btd_config *config, int argc, char **argv)
{
	FILE *fp;
	char *key, *line = NULL;
	size_t len, sep;

	config->configpath = NULL;

	config->socket = NULL;

	config->filefmt = safe_strdup(".pdf");
	config->check_fields = true;
	config->multithread = true;
	config->pidfile = safe_strdup("");

	argp_parse(&argp, argc, argv, 0, 0, config);
	btd_log(2, "Arguments parsed. Loglevel set to %d\n",
		get_btd_log_level());

	if (config->configpath == NULL)
		config->configpath = btd_get_config_path();

	config->datadir = btd_get_data_path();
	key = safe_strcat(2, config->datadir, "/btd.socket");
	printf("config.socket: %p\n", (void *)config->socket);
	config->socket = btd_get_addrinfo(key);
	printf("config.socket: %p\n", (void *)config->socket);
	free(key);

	btd_log(2, "Opening config at '%s'\n", config->configpath);
	fp = safe_fopen(config->configpath, "r");

	while (getline(&line, &len, fp) != -1) {
		sep = strcspn(line, "=");
		key = strndup(line, sep);
		if (key == NULL){
			die("strndup() failed\n");
		}
		update_config(config, key, line+sep+1);
		free(line);
		free(key);
		line = NULL;
	}
	free(line);
	btd_log(2, "Done parsing\n");
	config->db = safe_strcat(2, config->datadir, "/db.sqlite");
	config->filesdir = safe_strcat(2, config->datadir, "/files/");

	safe_fclose(fp);
}
コード例 #17
0
static Uint32 do_file_exists(const char* file_name, const char* path,
	const Uint32 size, char* buffer)
{
	struct stat fstat;
	Uint32 found;

	safe_strncpy2(buffer, path, size, strlen(path));
	safe_strcat(buffer, file_name, size);
	safe_strcat(buffer, ".xz", size);

	found = stat(buffer, &fstat) == 0;

	LOG_DEBUG("Checking file '%s': %s.", buffer, found ? "found" :
		"not found");

	if (found)
	{
		return 1;
	}

	safe_strncpy2(buffer, path, size, strlen(path));
	safe_strcat(buffer, file_name, size);
	safe_strcat(buffer, ".gz", size);

	found = stat(buffer, &fstat) == 0;

	LOG_DEBUG("Checking file '%s': %s.", buffer, found ? "found" :
		"not found");

	if (found)
	{
		return 1;
	}

	safe_strncpy2(buffer, path, size, strlen(path));
	safe_strcat(buffer, file_name, size);

	found = stat(buffer, &fstat) == 0;

	LOG_DEBUG("Checking file '%s': %s.", buffer, found ? "found" :
		"not found");

	if (found)
	{
		return 1;
	}

	return 0;
}
コード例 #18
0
ファイル: setup.c プロジェクト: codercold/xen-4.4
void arch_get_xen_caps(xen_capabilities_info_t *info)
{
    /* Interface name is always xen-3.0-* for Xen-3.x. */
    int major = 3, minor = 0;
    char s[32];

    (*info)[0] = '\0';

#ifdef CONFIG_ARM_64
    snprintf(s, sizeof(s), "xen-%d.%d-aarch64 ", major, minor);
    safe_strcat(*info, s);
#endif
    snprintf(s, sizeof(s), "xen-%d.%d-armv7l ", major, minor);
    safe_strcat(*info, s);
}
コード例 #19
0
ファイル: vfs_recycle.c プロジェクト: themiron/asuswrt-merlin
/**
 * Create directory tree
 * @param conn connection
 * @param dname Directory tree to be created
 * @return Returns True for success
 **/
static BOOL recycle_create_dir(vfs_handle_struct *handle, const char *dname)
{
	size_t len;
	mode_t mode;
	char *new_dir = NULL;
	char *tmp_str = NULL;
	char *token;
	char *tok_str;
	BOOL ret = False;

	mode = recycle_directory_mode(handle);

	tmp_str = SMB_STRDUP(dname);
	ALLOC_CHECK(tmp_str, done);
	tok_str = tmp_str;

	len = strlen(dname)+1;
	new_dir = (char *)SMB_MALLOC(len + 1);
	ALLOC_CHECK(new_dir, done);
	*new_dir = '\0';
	if (dname[0] == '/') {
		/* Absolute path. */
		safe_strcat(new_dir,"/",len);
	}

	/* Create directory tree if neccessary */
	for(token = strtok(tok_str, "/"); token; token = strtok(NULL, "/")) {
		safe_strcat(new_dir, token, len);
		if (recycle_directory_exist(handle, new_dir))
			DEBUG(10, ("recycle: dir %s already exists\n", new_dir));
		else {
			DEBUG(5, ("recycle: creating new dir %s\n", new_dir));
			if (SMB_VFS_NEXT_MKDIR(handle, new_dir, mode) != 0) {
				DEBUG(1,("recycle: mkdir failed for %s with error: %s\n", new_dir, strerror(errno)));
				ret = False;
				goto done;
			}
		}
		safe_strcat(new_dir, "/", len);
		mode = recycle_subdir_mode(handle);
	}

	ret = True;
done:
	SAFE_FREE(tmp_str);
	SAFE_FREE(new_dir);
	return ret;
}
コード例 #20
0
ファイル: image_loading.c プロジェクト: sorlok/Eternal-Lands
Uint32 check_alpha_image_name(const char* file_name, const Uint32 size,
	char* str)
{
	char buffer[128];
	Uint32 len, i;

	if (file_name == 0)
	{
		LOG_ERROR("Zero file name!");

		return 0;
	}

	len = get_file_name_len(file_name);

	if (str == 0)
	{
		LOG_ERROR("Buffer is zero!");

		return 0;
	}

	if ((len + 11) >= sizeof(buffer))
	{
		LOG_ERROR("Buffer too small! %d bytes needed, but buffer is "
			"only %d bytes big!", len + 11, size);

		return 0;
	}

	for (i = 0; i < IMAGE_EXTENSIONS_MAX; i++)
	{
		safe_strncpy2(buffer, file_name, sizeof(buffer), len);
		safe_strcat(buffer, "_alpha", sizeof(buffer));
		safe_strcat(buffer, image_extensions[i], sizeof(buffer));

		if (el_file_exists(buffer) != 0)
		{
			len = strlen(buffer);

			safe_strncpy2(str, buffer, size, len);

			return 1;
		}
	}

	return 0;
}
コード例 #21
0
ファイル: new_update.c プロジェクト: MerkeX/Eternal-Lands
static Uint32 check_server_digest_files(const char* file, FILE* tmp_file,
	const char* server, const char* path, const Uint32 size, char* buffer,
	char md5[33])
{
	char *file_name = NULL;
	const size_t file_name_size = 1024;
	Uint32 i, result;

	if ((file_name = calloc(sizeof(char), file_name_size)) == NULL)
		return 0;

	for (i = 0; i < 2; i++)
	{
		safe_strncpy(file_name, file, file_name_size);
		safe_strcat(file_name, digest_extensions[i], file_name_size);

		result = check_server_digest_file(file_name, tmp_file, server,
			path, size, buffer, 32, md5);

		if (result < 2)
		{
			free(file_name);
			return result;
		}
	}

	free(file_name);
	return 2;
}
コード例 #22
0
ファイル: libset.c プロジェクト: Abul22/uni_work
/*
 * read_data()
 *
 * read data from a file to a set
 *
 */
    void
read_data(set_t *pset,char *pname)
{
    FILE *fp;
    int item;
    int sucess; /* use to check if sucess insert the item into set or not */
    /* the defalut path for the test data */
    char path[PATH_LENGTH] = "/public/courses/AlgorithmsAndAnalysis/proj2/";
    /*  put the file name with defalut path together */
    pname = safe_strcat(path,pname);
    fp = fopen(pname,"r");
    /* check if file exit or not */
    if(!fp){
        fprintf(stderr,"Can not open %s!!!\n",pname);
        exit(EXIT_FAILURE);
    }
    /* get the numbers to the end of file */
    while(fscanf(fp,"%d",&item) == 1 ){
        sucess = set_insert(pset,item);
        /* exit if have not sucess insert the number */
        if(sucess != TRUE){
            fprintf(stderr,"Can not insert the data in the set!!\n");
            exit(EXIT_FAILURE);
        }
    }
    /* close the file */
    free(pname);
    fclose(fp);
}
コード例 #23
0
ファイル: mac_saver_module.cpp プロジェクト: DanAurea/boinc
void print_to_log_file(const char *format, ...) {
#if CREATE_LOG
    va_list args;
    char buf[256];
    time_t t;
#if USE_SPECIAL_LOG_FILE
    safe_strcpy(buf, getenv("HOME"));
    safe_strcat(buf, "/Documents/test_log.txt");
    FILE *f;
    f = fopen(buf, "a");
    if (!f) return;

//  freopen(buf, "a", stdout);
//  freopen(buf, "a", stderr);
#else
    #define f stderr
#endif
    time(&t);
    safe_strcpy(buf, asctime(localtime(&t)));
    strip_cr(buf);

    fputs(buf, f);
    fputs("   ", f);

    va_start(args, format);
    vfprintf(f, format, args);
    va_end(args);
    
    fputs("\n", f);
#if USE_SPECIAL_LOG_FILE
    fflush(f);
    fclose(f);
#endif
#endif
}
コード例 #24
0
ファイル: sched_util_basic.cpp プロジェクト: FoxKyong/boinc
bool is_arg(const char* x, const char* y) {
    char buf[256];
    strcpy(buf, "--");
    safe_strcat(buf, y);
    if (!strcmp(buf, x)) return true;
    if (!strcmp(buf+1, x)) return true;
    return false;
}
コード例 #25
0
ファイル: hcache.c プロジェクト: srg-imperial/mutt
void *
mutt_hcache_fetch_raw (header_cache_t *h, const char *filename,
                       size_t(*keylen) (const char *fn))
{
#ifndef HAVE_DB4
  char path[_POSIX_PATH_MAX];
  int ksize;
#endif
#ifdef HAVE_QDBM
  char *data = NULL;
#elif HAVE_TC
  void *data;
  int sp;
#elif HAVE_GDBM
  datum key;
  datum data;
#elif HAVE_DB4
  DBT key;
  DBT data;
#endif
  
  if (!h)
    return NULL;
  
#ifdef HAVE_DB4
  if (filename[0] == '/')
    filename++;

  mutt_hcache_dbt_init(&key, (void *) filename, keylen(filename));
  mutt_hcache_dbt_empty_init(&data);
  data.flags = DB_DBT_MALLOC;
  
  h->db->get(h->db, NULL, &key, &data, 0);
  
  return data.data;
#else
  strncpy(path, h->folder, sizeof (path));
  safe_strcat(path, sizeof (path), filename);

  ksize = strlen (h->folder) + keylen (path + strlen (h->folder));  
#endif
#ifdef HAVE_QDBM
  data = vlget(h->db, path, ksize, NULL);
  
  return data;
#elif HAVE_TC
  data = tcbdbget(h->db, path, ksize, &sp);

  return data;
#elif HAVE_GDBM
  key.dptr = path;
  key.dsize = ksize;
  
  data = gdbm_fetch(h->db, key);
  
  return data.dptr;
#endif
}
コード例 #26
0
void
RDFAnnotation2_setup (void)
{
  char *filename = safe_strcat(TestDataDirectory, "annotation2.xml");

  // The following will return a pointer to a new SBMLDocument.
  d2 = readSBML(filename);
  m2 = d2->getModel();
}
コード例 #27
0
ファイル: TestUtil.c プロジェクト: sn248/Rcppsbml
END_TEST


START_TEST (test_util_safe_strcat)
{
  char *p, *q, *r, *s;


  fail_unless( !strcmp( p = safe_strcat( "foo", "bar" ), "foobar" ) );
  fail_unless( !strcmp( q = safe_strcat( "foo", ""    ), "foo"    ) );
  fail_unless( !strcmp( r = safe_strcat( ""   , "bar" ), "bar"    ) );
  fail_unless( !strcmp( s = safe_strcat( ""   , ""    ), ""       ) );

  safe_free(p);
  safe_free(q);
  safe_free(r);
  safe_free(s);
}
コード例 #28
0
void add_session_user(const char *user)
{
	fstring suser;
	struct passwd *passwd;

	if (!(passwd = Get_Pwnam(user)))
		return;

	fstrcpy(suser,passwd->pw_name);

	if(!*suser)
		return;

	if( session_userlist && in_list(suser,session_userlist,False) )
		return;

	if( !session_userlist ||
	    (strlen(suser) + strlen(session_userlist) + 2 >=
	     len_session_userlist) ) {
		char *newlist;

		if (len_session_userlist > 128 * PSTRING_LEN) {
			DEBUG(3,("add_session_user: session userlist already "
				 "too large.\n"));
			return;
		}
		newlist = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR(
			session_userlist,
			len_session_userlist + PSTRING_LEN );
		if( newlist == NULL ) {
			DEBUG(1,("Unable to resize session_userlist\n"));
			return;
		}
		if (!session_userlist) {
			*newlist = '\0';
		}
		session_userlist = newlist;
		len_session_userlist += PSTRING_LEN;
	}

	safe_strcat(session_userlist," ",len_session_userlist-1);
	safe_strcat(session_userlist,suser,len_session_userlist-1);
}
コード例 #29
0
ファイル: strfuns.c プロジェクト: h3rb/Assault-3.0
char * space_pad( const char * str, sh_int final_size )
{
    sh_int space_pad = my_strlen( str );
    static char padbuf[MSL];

    sprintf( padbuf, "%s", str );
    for ( ; space_pad != final_size ; space_pad++ )
        safe_strcat( MSL, padbuf, " " );
    return padbuf;
}
コード例 #30
0
ファイル: winbindd_wins.c プロジェクト: jophxy/samba
enum winbindd_result winbindd_wins_byname(struct winbindd_cli_state *state)
{
	struct in_addr *ip_list;
	int i, count, maxlen, size;
	fstring response;
	char * addr;

	DEBUG(3, ("[%5d]: wins_byname %s\n", state->pid,
		state->request.data.winsreq));

	*response = '\0';
	maxlen = sizeof(response) - 1;

	if ((ip_list = lookup_byname_backend(state->request.data.winsreq,&count))){
		for (i = count; i ; i--) {
		    addr = inet_ntoa(ip_list[i-1]);
		    size = strlen(addr);
		    if (size > maxlen) {
			SAFE_FREE(ip_list);
			return WINBINDD_ERROR;
		    }
		    if (i != 0) {
			/* Clear out the newline character */
			response[strlen(response)-1] = ' '; 
		    }
		    safe_strcat(response,addr,maxlen);
		    safe_strcat(response,"\t",maxlen);
		}
		size = strlen(state->request.data.winsreq) + strlen(response);
		if (size > maxlen) {
		    SAFE_FREE(ip_list);
		    return WINBINDD_ERROR;
		}   
		safe_strcat(response,state->request.data.winsreq,maxlen);
		safe_strcat(response,"\n",maxlen);
		SAFE_FREE(ip_list);
	} else
		return WINBINDD_ERROR;

	fstrcpy(state->response.data.winsresp,response);

	return WINBINDD_OK;
}