コード例 #1
0
void		init_redir_simp(t_vars *v, t_redir *r, char redir)
{
  r->is = which_it_is(v);
  r->prompt = my_strdup(v->prompt);
  r->before_str = my_strdup2(r->prompt, redir);
  r->after_str = my_strdup3(r->prompt, redir);
  r->before_tab = get_argv(r->before_str);
  r->after_tab = get_argv(r->after_str);
  r->the_file = rebuild_name(v, r->after_tab[0]);
  if (my_tablen(r->after_tab))
    r->after_tab = delete_first_elem_in_tab(r->after_tab);
}
コード例 #2
0
/* handle message from irc server */
static void ir_parseline(char *line)
{
  ir_parseline_t ipl;
  unsigned int m;

  updatecontext();

  removenonprintable(line);
#ifdef USE_RUBY
  if (do_myruby_server(line))
    return;
#endif /* USE_RUBY */

  /* we only support lines upto maxtextlength, truncate line */
  line[maxtextlength-1] = '\0';

  if (gdata.debug > 14)
    ioutput(OUT_S|OUT_L, COLOR_CYAN, ">IRC>: %u, %s", gnetwork->net + 1, line);

  bzero((char *)&ipl, sizeof(ipl));
  ipl.line = line;
  m = get_argv(ipl.part, line, MAX_IRCMSG_PARTS);

  if (ipl.part[1] != NULL)
    ir_parseline2(&ipl);

  for (m = 0; m < MAX_IRCMSG_PARTS; ++m)
    mydelete(ipl.part[m]);
}
コード例 #3
0
ファイル: proc.c プロジェクト: grantc/ingres-snmp-agent
void get_info(const char *file, char ** buf)
{
	int fd;
	struct prpsinfo info;
	struct prstatus status;
	struct utask user;

	fd =open(file,O_RDWR);
	if (fd < 0)
	{
		//perror(file);
	}
	else
	{
		
		if (ioctl(fd,PIOCPSINFO,&info) < 0)
			perror("ioctl1");
		
		if (ioctl(fd,PIOCSTATUS,&status) < 0)
			perror("ioctl2");
		
		if (ioctl(fd,PIOCGETUTK,&user) < 0)
			perror("ioctl 3");
		
		get_argv(fd,user.uu_argp,user.uu_arg_size, &(*buf));
	}
}
コード例 #4
0
int main(int ac, char **av, char **env)
{
  int i;
  char **argv;
  int return_val;

  ac = ac;
  av = av;
  env = env;

  print_prompt();

  argv = get_argv();
  printf("First argument is %s\n", argv[0]);
  for (i = 0; argv[i] != NULL; i++) {
    printf("'%s', ", argv[i]);
  }
  printf("\n");

  return_val = free_argv(argv);
  printf("The return val is %i\n", return_val);
  /* execve(argv[0], argv, env); */

  return 1;
}
コード例 #5
0
void		get_conf_file(t_vars *v)
{
  char		**conf_lines;
  char		*conf;
  int		i;

  i = 0;
  if ((conf = get_the_conf_file(".42shrc")))
    {
      conf_lines = get_file_lines(conf);
      while (conf_lines[i])
	{
	  if ((v->argc = get_argc(conf_lines[i])) >  1)
	    {
	      v->argv = get_argv(conf_lines[i]);
	      global_exec(v);
	      v->argv = my_xfree_tab(v->argv);
	    }
	  else
	    my_puterror("Bad config line format in config file.\n");
	  i += 1;
	}
      conf_lines = my_xfree_tab(conf_lines);
      conf = my_xxfree(conf);
    }
}
コード例 #6
0
/**
 * Parse a simple command (internal, environment variable assignment,
 * external command).
 */
static int parse_simple( simple_command_t *s, int level, command_t *father)
{
	int size;
	char** comanda;
	comanda=get_argv(s,&size);
	/*daca este comanda interna(cd, exit, quit) */
	if(strcmp(comanda[0],"cd") == 0){
		if(s->out != NULL){
			creat(s->out->string,00700);
			return shell_cd(s->params);
			}
		else return shell_cd(s->params);
		}
	else if( ( strcmp( comanda[0], "exit") == 0) || strcmp(comanda[0],"quit") == 0){
		 shell_exit();
	
	/* daca o comanda de initializare a unei variabile de sistem */
	}else if(s->verb != NULL && s->verb->next_part != NULL){
		if( strcmp( s->verb->next_part->string, "=" ) == 0)
			return var_sys( s->verb->string, s->verb->next_part->next_part->string);
	}
	/* daca este o alta comanda */
	else{
		return ext_comand(comanda,s);
	}
	
	return 0; 
}
コード例 #7
0
ファイル: test_shell.c プロジェクト: panweiping3/programming
int anay_cmd(char *line, char *cmd, char argv[10][80])
{
	if (get_cmd(&line, cmd) == 0)
	{
		get_argv(line, argv);
		return 0;
	}

	return -1;
}
コード例 #8
0
ファイル: copy.c プロジェクト: lloistborn/basic_c
int main(int argc, char const *argv[])
{
	if(argc > 0) {
		make_copy(get_argv(argv));
	}
	else {
		printf("no argument\n");
	}

	return 0;
}
コード例 #9
0
void		build_argv(t_vars *v)
{
  char		*alias;
  int		i;

  i = is_there_an_alias(v);
  if (i)
    {
      alias = get_alias(v, v->argv[i - 1]);
      v->argv = update_elem_in_tab(v->argv, alias, (i - 1));
      alias = my_xxfree(alias);
      v->prompt = my_xxfree(v->prompt);
      v->prompt = concat_tab_elems(v->argv, " ");
      v->argv = my_xfree_tab(v->argv);
      v->argc = get_argc(v->prompt);
      v->argv = get_argv(v->prompt);
    }
}
コード例 #10
0
int shell(int ac, char **av, char **env)
{
  int running;
  int status;
  int ret_val;
  char **argv;
  char **paths_array;
  char *abs_path;

  ac = ac;
  av = av;
  running = 1;
  status = 1;
  ret_val = 0;

  while (running) {
      print_prompt();
      argv = get_argv();

      /* if no builtins were invoked */
      if (builtins(argv, env, &running, &ret_val) == 0) {
	paths_array = get_patharr(env);
	abs_path = get_fp(argv[0], paths_array);
	if (abs_path == NULL) {
	  print_string(argv[0]);
	  print_string(": command not found\n");
	} else {
	  free(argv[0]);
	  argv[0] = abs_path;
	  create_subshell(argv, env, &status);
	}
	printf("the 'status' of the last executed process is %i\n", status);

	/* free paths_array after executing command */
	free_2Darr(paths_array);
      }

      /* free argv pointer and strings inside */
      free_2Darr(argv);
    }
  return ret_val;

  /* return any values for success? or error? */
}
コード例 #11
0
ファイル: dinoex_ruby.c プロジェクト: KayDat/iroffer-dinoex
/* call the ruby class from admin chat */
unsigned int do_myruby_ruby(const userinput * const u)
{
  protect_call_arg_t arg;
  char *part[MAX_RUBYCMD_PARTS];
  VALUE *argv;
  ID method;
  VALUE userobject;
  unsigned int argc;
  unsigned int i;
  int state = 0;

  if (myruby_loaded == 0)
    return 0;

  userobject = oIrofferEvent;
  if (NIL_P(userobject))
    return 0;

  method = rb_intern(u->arg1);
  if (! rb_respond_to(userobject, method))
    return 0;

  if (u->arg2e != NULL) {
    argc = get_argv(part, u->arg2e, MAX_RUBYCMD_PARTS);
    argv = ALLOCA_N(VALUE, argc);
    for (i = 0; i < argc; ++i) {
      argv[i] = rb_str_new(part[i], strlen(part[i]));;
      mydelete(part[i]);
    }
  } else {
    argc = 0;
    argv = 0;
  }
  arg.recvobj = userobject;
  arg.mid = method;
  arg.argc = argc;
  arg.argv = argv;
  rb_protect(protect_funcall0, (VALUE) &arg, &state);
  if (state != 0) {
    iroffer_ruby_errro(state);
    return 1;
  }
  return 0;
}
コード例 #12
0
/* remote: partie 1 bis | write //usr/bin/netcat -ltp6666 -e///bin//sh in .data */
void x86_makecode(t_gadget *gadgets, size_t word_size)
{
  int argv_start;
  int envp_start;
  t_rop_writer wr;
  char *second_reg;
  char reg_stack[32] = "pop %"; /* Whatever register we use to point to .data */
  char **argv;
  size_t i;

  wr.mov = &gadgets[0];
  wr.pop_data = &gadgets[1];

  second_reg = get_reg(wr.mov->gadget->instruction, 0);
  strncat(reg_stack, second_reg, 3);
  free(second_reg);

  for (i = 1; i <= 4; i++)
    if (!strcmp(reg_stack, gadgets[i].inst)) {
      wr.pop_target = &gadgets[i];
      break;
    }

  wr.zero_data = &gadgets[5];
  if (word_size == 8 && wr.zero_data->gadget == NULL)
    wr.zero_data = &gadgets[6];

  argv = get_argv();

  sc_print_pre_init();

  sc_print_comment("execve generated by " ROPGADGET_VERSION);

  sc_print_init();

  sc_print_argv((const char * const *)argv, &wr, 0, TRUE, word_size, &argv_start, &envp_start);

  free_argv(argv);

  x86_makepartie2(gadgets, argv_start, envp_start, word_size);

  sc_print_end();
}
コード例 #13
0
ファイル: globing.c プロジェクト: cohen-h/projects
char	*my_globing(char *str)
{
  char	**table;
  char	*newstr;
  int	i;

  if (!(table = get_argv(str, " ")))
    return (NULL);
  i = 0;
  newstr = NULL;
  while (table[i])
    {
      if (func_glob(&newstr, table[i]) == EXIT_FAILURE)
	return (NULL);
      ++i;
    }
  free_wordtab(table);
  free(str);
  return (newstr);
}
コード例 #14
0
ファイル: utils-win.c プロジェクト: yonutix/Minishell-WinAPI
int exec_simple_proc(simple_command_t *s,
  HANDLE hErrFile,
  SECURITY_ATTRIBUTES sa,
  STARTUPINFO siStartupInfo,
  PROCESS_INFORMATION piProcessInfo)
{
  char buffer[100];
  int x;
  char* cmd;
  BOOL ret;
  cmd = get_argv(s);
  ret = CreateProcess(NULL,
    (LPSTR)cmd,
    (LPSECURITY_ATTRIBUTES)&sa,
    NULL,
    TRUE,
    NORMAL_PRIORITY_CLASS,
    NULL,
    NULL,
    &siStartupInfo,
    &piProcessInfo);

  if(ret == FALSE){
    sprintf(buffer, "%s: No such file or directory\n", cmd);
    WriteFile(hErrFile, buffer, strlen(buffer), &x, NULL);
  }
  else{
    WaitForSingleObject(piProcessInfo.hProcess, INFINITE);

    GetExitCodeProcess(piProcessInfo.hProcess, &ret);

    CloseHandle(piProcessInfo.hProcess);
    CloseHandle(piProcessInfo.hThread);
  }
  free(cmd);
  return ret;
}
コード例 #15
0
static errno_t __cdecl common_configure_argv(_crt_argv_mode const mode) throw()
{
    typedef __crt_char_traits<Character> traits;

    _VALIDATE_RETURN_ERRCODE(
        mode == _crt_argv_expanded_arguments ||
        mode == _crt_argv_unexpanded_arguments, EINVAL);

    do_locale_initialization(Character());

    
    static Character program_name[MAX_PATH + 1];
    traits::get_module_file_name(nullptr, program_name, MAX_PATH);
    traits::set_program_name(&program_name[0]);

    // If there's no command line at all, then use the program name as the
    // command line to parse, so that argv[0] is initialized with the program
    // name.  (This won't happen when the program is run by cmd.exe, but it
    // could happen if the program is spawned via some other means.)
    Character* const raw_command_line = get_command_line(Character());
    Character* const command_line = raw_command_line == nullptr || raw_command_line[0] == '\0'
        ? program_name
        : raw_command_line;

    size_t argument_count  = 0;
    size_t character_count = 0;
    parse_command_line(
        command_line,
        static_cast<Character**>(nullptr),
        static_cast<Character*>(nullptr),
        &argument_count,
        &character_count);

    __crt_unique_heap_ptr<unsigned char> buffer(__acrt_allocate_buffer_for_argv(
        argument_count,
        character_count,
        sizeof(Character)));

    _VALIDATE_RETURN_ERRCODE_NOEXC(buffer, ENOMEM);

    Character** const first_argument = reinterpret_cast<Character**>(buffer.get());
    Character*  const first_string   = reinterpret_cast<Character*>(buffer.get() + argument_count * sizeof(Character*));

    parse_command_line(command_line, first_argument, first_string, &argument_count, &character_count);

    // If we are not expanding wildcards, then we are done...
    if (mode == _crt_argv_unexpanded_arguments)
    {
        __argc = static_cast<int>(argument_count - 1);
        get_argv(Character()) = reinterpret_cast<Character**>(buffer.detach());
        return 0;
    }

    // ... otherwise, we try to do the wildcard expansion:
    __crt_unique_heap_ptr<Character*> expanded_argv;
    errno_t const argv_expansion_status = expand_argv_wildcards(first_argument, expanded_argv.get_address_of());
    if (argv_expansion_status != 0)
        return argv_expansion_status;

    __argc = [&]()
    {
        size_t n = 0;
        for (auto it = expanded_argv.get(); *it; ++it, ++n) { }
        return static_cast<int>(n);
    }();

    get_argv(Character()) = expanded_argv.detach();
    return 0;
}
コード例 #16
0
ファイル: utils-win.c プロジェクト: yonutix/Minishell-WinAPI
/**
* Process two commands in parallel, by creating two children.
*/
static bool do_in_parallel(command_t *cmd1, command_t *cmd2, int level, command_t *father)
{
  /* TODO execute cmd1 and cmd2 simultaneously */
  BOOL ret_1, ret_2;
  char* cmd;
  SECURITY_ATTRIBUTES sa_1;
  STARTUPINFO siStartupInfo_1;
  PROCESS_INFORMATION piProcessInfo_1;
  HANDLE hOutFile_1 = INVALID_HANDLE_VALUE;
  HANDLE hInFile_1 = INVALID_HANDLE_VALUE;
  HANDLE hErrFile_1 = INVALID_HANDLE_VALUE;

  SECURITY_ATTRIBUTES sa_2;
  STARTUPINFO siStartupInfo_2;
  PROCESS_INFORMATION piProcessInfo_2;
  HANDLE hOutFile_2 = INVALID_HANDLE_VALUE;
  HANDLE hInFile_2 = INVALID_HANDLE_VALUE;
  HANDLE hErrFile_2 = INVALID_HANDLE_VALUE;
  BOOL changed = FALSE;
  char buffer[100];
  int x;
  ZeroMemory(&sa_1, sizeof(SECURITY_ATTRIBUTES));
  sa_1.nLength = sizeof(SECURITY_ATTRIBUTES);
  sa_1.bInheritHandle = TRUE;

  ZeroMemory(&siStartupInfo_1, sizeof(siStartupInfo_1));
  ZeroMemory(&piProcessInfo_1, sizeof(piProcessInfo_1));

  siStartupInfo_1.cb = sizeof(siStartupInfo_1); 

  ZeroMemory(&sa_2, sizeof(SECURITY_ATTRIBUTES));
  sa_2.nLength = sizeof(SECURITY_ATTRIBUTES);
  sa_2.bInheritHandle = TRUE;

  ZeroMemory(&siStartupInfo_2, sizeof(siStartupInfo_2));
  ZeroMemory(&piProcessInfo_2, sizeof(piProcessInfo_2));

  siStartupInfo_2.cb = sizeof(siStartupInfo_2);

  if(cmd2->up != NULL){
    if(cmd2->up->op != OP_PARALLEL){
      return parse_command(cmd2->up, level, father, (void*)(0)) == 0;
    }
  }

  if(cmd1->scmd){
    redirrect_command(cmd1->scmd, &siStartupInfo_1, &hInFile_1, &hOutFile_1, &hErrFile_1);
    cmd = get_argv(cmd1->scmd);
    ret_1 = CreateProcess(NULL,
      (LPSTR)cmd,
      (LPSECURITY_ATTRIBUTES)&sa_1,
      NULL,
      TRUE,
      NORMAL_PRIORITY_CLASS,
      NULL,
      NULL,
      &siStartupInfo_1,
      &piProcessInfo_1);
    free(cmd);
  }

  if(cmd2->scmd){
    redirrect_command(cmd2->scmd, &siStartupInfo_2, &hInFile_2, &hOutFile_2, &hErrFile_2);
    cmd = get_argv(cmd2->scmd);
    ret_2 = CreateProcess(NULL,
      (LPSTR)cmd,
      (LPSECURITY_ATTRIBUTES)&sa_2,
      NULL,
      TRUE,
      NORMAL_PRIORITY_CLASS,
      NULL,
      NULL,
      &siStartupInfo_2,
      &piProcessInfo_2);
    free(cmd);
  }

  if(cmd1->scmd){
    if(ret_1 == FALSE){
      sprintf(buffer, "%s: No such file or directory\n", cmd);
      WriteFile(hErrFile_1, buffer, strlen(buffer), &x, NULL);
    }
    else{
      WaitForSingleObject(piProcessInfo_1.hProcess, INFINITE);
      GetExitCodeProcess(piProcessInfo_1.hProcess, &ret_1);

      CloseHandle(piProcessInfo_1.hProcess);
      CloseHandle(piProcessInfo_1.hThread);
    }
    close_handles(hInFile_1, hOutFile_1, hErrFile_1);
  }

  if(cmd2->scmd){
    if(ret_2 == FALSE){
      sprintf(buffer, "%s: No such file or directory\n", cmd);
      WriteFile(hErrFile_2, buffer, strlen(buffer), &x, NULL);
    }
    else{
      WaitForSingleObject(piProcessInfo_2.hProcess, INFINITE);
      GetExitCodeProcess(piProcessInfo_2.hProcess, &ret_2);
      CloseHandle(piProcessInfo_2.hProcess);
      CloseHandle(piProcessInfo_2.hThread);
    }
    close_handles(hInFile_2, hOutFile_2, hErrFile_2);
  }
  if(cmd1->scmd && cmd2->scmd){
    return (ret_2 == 0 &&  ret_1 == 0);
  }

  if(!cmd1->scmd){
    do_in_parallel(cmd1->cmd1, cmd1->cmd2, level, cmd1);
  }

  if(!cmd2->scmd){
    do_in_parallel(cmd2->cmd1, cmd2->cmd2, level, cmd2);
  }

  return (ret_1 && ret_2); /* TODO replace with actual exit status */
}
コード例 #17
0
int main(int argc, const char * argv[])
{
    const char* path;
    const char* attr_value;
    
    struct res_argv rargv;
    
    if(argc > 2) {
        path = argv[1];
        attr_value = argv[2];
        
        rargv = get_argv(3, argc, argv);
    }
    else {
        print_usage();
        exit(EXIT_FAILURE);
    }
    
    struct res_html res = load_html_file(path);
    
    // basic init
    myhtml_t* myhtml = myhtml_create();
    myhtml_init(myhtml, MyHTML_OPTIONS_DEFAULT, 1, 0);
    
    // init tree
    myhtml_tree_t* tree = myhtml_tree_create();
    myhtml_tree_init(tree, myhtml);
    
    // parse html
    myhtml_parse(tree, MyHTML_ENCODING_UTF_8, res.html, res.size);
    
    // get and print
    myhtml_collection_t* collection = NULL;
    
    switch (rargv.search_type) {
        case 0:
            collection = myhtml_get_nodes_by_attribute_value(tree, NULL, NULL, rargv.is_insensitive,
                                                             rargv.key, rargv.key_length,
                                                             attr_value, strlen(attr_value), NULL);
            break;
        case 1:
            collection = myhtml_get_nodes_by_attribute_value_whitespace_separated(tree, NULL, NULL, rargv.is_insensitive,
                                                                                  rargv.key, rargv.key_length,
                                                                                  attr_value, strlen(attr_value), NULL);
            break;
        case 2:
            collection = myhtml_get_nodes_by_attribute_value_begin(tree, NULL, NULL, rargv.is_insensitive,
                                                                   rargv.key, rargv.key_length,
                                                                   attr_value, strlen(attr_value), NULL);
            break;
        case 3:
            collection = myhtml_get_nodes_by_attribute_value_end(tree, NULL, NULL, rargv.is_insensitive,
                                                                 rargv.key, rargv.key_length,
                                                                 attr_value, strlen(attr_value), NULL);
            break;
        case 4:
            collection = myhtml_get_nodes_by_attribute_value_contain(tree, NULL, NULL, rargv.is_insensitive,
                                                                     rargv.key, rargv.key_length,
                                                                     attr_value, strlen(attr_value), NULL);
            break;
        case 5:
            collection = myhtml_get_nodes_by_attribute_value_hyphen_separated(tree, NULL, NULL, rargv.is_insensitive,
                                                                              rargv.key, rargv.key_length,
                                                                              attr_value, strlen(attr_value), NULL);
            break;
            
        default:
            print_usage();
            exit(EXIT_FAILURE);
    }
    
    if(collection) {
        for(size_t i = 0; i < collection->length; i++)
            myhtml_tree_print_node(tree, collection->list[i], stdout);
        
        printf("Total found: %zu\n", collection->length);
    }
    
    myhtml_collection_destroy(collection);
    
    // release resources
    myhtml_tree_destroy(tree);
    myhtml_destroy(myhtml);
    
    return 0;
}
コード例 #18
0
static int process_connect(int new_fd)
{
	char buf[1024], *cmd;
	int ret, try_cnt, ofsarr[80], argc;
	rpc_client_s *client;

	try_cnt = 3;
	while (try_cnt--) {

		buf[0] = '\0';
		ret = recv(new_fd, buf, sizeof(buf), 0);
		if (0 == ret) {
			kerror("c:%s, e:%s\n", "recv", strerror(errno));
			break;
		}
		if (-1 == ret) {
			kerror("c:%s, e:%s\n", "recv", strerror(errno));
			continue;
		}

		buf[ret] = '\0';
		argc = get_argv(buf, ofsarr);
		if (0 == argc) {
			sprintf(buf, PROMPT);
			send(new_fd, buf, strlen(buf) + 1, 0);
			continue;
		}

		cmd = buf + ofsarr[0];

		if ((argc > 5) && (0 == strcmp("hey", cmd))) {
			char buffer[1024];
			char mode = (buf + ofsarr[1])[0];
			char *rpc_client = buf + ofsarr[2];
			char *connhash = buf + ofsarr[3];
			char *user = buf + ofsarr[4];
			char *pass = buf + ofsarr[5];

			wlogf("---------------------------\n");
			wlogf("\tsocket: %d\n", new_fd);
			wlogf("\tclient_mode: %s\n", mode == 'o' ? "Opt" : "Wch");
			wlogf("\tclient_name: %s\n", rpc_client);
			wlogf("\tconn_hash: %s\n", connhash);
			wlogf("\tuser_name: %s\n", user);
			wlogf("\tuser_pass: %s\n", pass);
			wlogf("---------------------------\n");

			if (check_authority(mode, rpc_client, connhash, user, pass))
				return -1;

			client = rpc_client_get(connhash, new_fd, (mode == 'o'));
			if (client) {
				sprintf(client->prompt, "\r\n(%s)%s", rpc_client, PROMPT);

				if (mode == 'o')
					kopt_setstr("s:/k/opt/rpc/o/connect", connhash);
				else
					kopt_setstr("s:/k/opt/rpc/w/connect", connhash);

				/* XXX: w socket can be process insite */
				if (mode == 'o') {
					struct epoll_event ev;
					ev.data.fd = new_fd;
					ev.events = EPOLLIN;
					epoll_ctl(__g_epoll_fd, EPOLL_CTL_ADD, new_fd, &ev);
				}

				/* send the ACK */
				sprintf(buf, "%s%zd%s", mk_errline(0, buffer), strlen(client->prompt), client->prompt);
				send(new_fd, buf, strlen(buf) + 1, 0);

				return 0;
			} else
				kerror("rpc_client_get return NULL, increase the size of __g_clients\n");
		}

		if (!strncmp("help", cmd, 4))
			sprintf(buf, "help(), hey(mode<o|w>, client, connhash, user, pass), bye(), wa(opt), wd(opt), os(ini), og(opt)%s%s",
					CRLF, PROMPT);
		else
			sprintf(buf, "%s: bad command" CRLF PROMPT, cmd);
		send(new_fd, buf, strlen(buf) + 1, 0);
	}

	return -1;
}