Exemplo n.º 1
0
files_t *add_files(u8 *fname, int fsize, int *ret_files) {
    static int      filesi  = 0,
                    filesn  = 0;
    static files_t  *files  = NULL;
    files_t         *ret;

    if(ret_files) {
        *ret_files = filesi;
        files = realloc(files, sizeof(files_t) * (filesi + 1)); // not needed, but it's ok
        if(!files) STD_ERR;
        files[filesi].name   = NULL;
        //files[filesi].offset = 0;
        files[filesi].size   = 0;
        ret    = files;
        filesi = 0;
        filesn = 0;
        files  = NULL;
        return(ret);
    }

    if(filter_in_files && (check_wildcard(fname, filter_in_files) < 0)) return(NULL);

    if(filesi >= filesn) {
        filesn += 1024;
        files = realloc(files, sizeof(files_t) * filesn);
        if(!files) STD_ERR;
    }
    files[filesi].name   = mystrdup(fname);
    //files[filesi].offset = 0;
    files[filesi].size   = fsize;
    filesi++;
    return(NULL);
}
Exemplo n.º 2
0
static int
check_name_match(ASN1_STRING *name, const char *hostname)
{
	char *name_utf8 = NULL;
	int ret, name_len;

	name_len = ASN1_STRING_to_UTF8((unsigned char **) &name_utf8, name);
	if (name_len < 0)
		return 0;

	tdsdump_log(TDS_DBG_INFO1, "Got name %s\n", name_utf8);
	ret = 0;
	if (strlen(name_utf8) == name_len && check_wildcard(name_utf8, hostname) == 0)
		ret = 1;
	OPENSSL_free(name_utf8);
	return ret;
}
Exemplo n.º 3
0
static void
tds_check_wildcard_test(void)
{
	assert(check_wildcard("foo", "foo") == 1);
	assert(check_wildcard("FOO", "foo") == 1);
	assert(check_wildcard("foo", "FOO") == 1);
	assert(check_wildcard("\x90oo", "\x90OO") == 0);
	assert(check_wildcard("xn--foo", "xn--foo") == 1);
	assert(check_wildcard("xn--FOO", "XN--foo") == 1);
	assert(check_wildcard("xn--a.example.org", "xn--*.example.org") == 0);
	assert(check_wildcard("a.*", "a.*") == 1);
	assert(check_wildcard("a.b", "a.*") == 0);
	assert(check_wildcard("ab", "a*") == 0);
	assert(check_wildcard("a.example.", "*.example.") == 0);
	assert(check_wildcard("a.example.com", "*.example.com") == 1);
	assert(check_wildcard("a.b.example.com", "a.*.example.com") == 0);
	assert(check_wildcard("foo.example.com", "foo*.example.com") == 1);
	assert(check_wildcard("fou.example.com", "foo*.example.com") == 0);
	assert(check_wildcard("baz.example.com", "*baz.example.com") == 1);
	assert(check_wildcard("buzz.example.com", "b*z.example.com") == 1);
	assert(check_wildcard("bz.example.com", "b*z.example.com") == 1);
	assert(check_wildcard(".example.com", "*.example.com") == 0);
	assert(check_wildcard("example.com", "*.example.com") == 0);
}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{

  int i = -1;
	int pid = -1;
  int ret_code = -1;
  int len = -1;
  char *the_cmd = NULL;    // pointer to a command
	char home_dir[81] = {'\0'};
	char *arguments[MAXARGS]= {NULL};
	char *brkt = NULL;

	//preprocess, get process home directory
	if (getcwd(home_dir, sizeof(home_dir)) == NULL)
	{
		printf("Error executing getcwd\n");
	}

  the_cmd = get_cmd(&len);
  while(!feof(stdin))
	{
    if(len > 0)
		{  // a non-empty command was entered
			cmd_count++;

			pid = fork();
      if(pid)
			{  // parent process
				//wait for child process to finish
        wait(NULL);
      }
			else
			{  // child process - execute the command
				i=0;

				//parsing command arguments
				for(arguments[i] = strtok_r(the_cmd, SEPERATION, &brkt);
						arguments[i]; 
						arguments[++i] = strtok_r(NULL, SEPERATION, &brkt));

				if(equals(arguments[0], "cd"))
				{
					if('\0' == arguments[1])
					{//arguments[1] empty, go to home directory
						ret_code = chdir(home_dir);
					}
					else
					{
						ret_code = chdir(arguments[1]);
					}
				}
				else
				{
					glob_t g = {0};
					if(check_wildcard(arguments, MAXARGS, &g))
					{
						ret_code = execvp(arguments[0], g.gl_pathv);
					}
					else
					{
        		ret_code = execvp(the_cmd, arguments);
					}
				}

        if(ret_code != 0)
				{
          printf("error executing %s.\n", the_cmd);
        	exit(TRUE);  // indicate that cmd failed
        }
			}

		}

    the_cmd = get_cmd(&len);
  }

  printf("\nEnd of processing\n");
  return 0;
}