Esempio n. 1
0
static void		update_env(t_env **env, char *dir)
{
	char	buf[2048];
	char	*new_dir;
	char	*tmp;

	set_option(env);
	ft_strdel(&(*env)->oldpwd);
	(*env)->oldpwd = (*env)->pwd;
	new_dir = ft_strdup(getcwd(buf, 2048));
	if ((*env)->optp == 0 && ft_strstr(new_dir, dir))
		(*env)->pwd = ft_strdup(ft_strstr(new_dir, dir));
	else
		(*env)->pwd = ft_strdup(new_dir);
	ft_strdel(&new_dir);
	if (!(update_var(env, "PWD", (*env)->pwd)))
	{
		tmp = ft_strjoin("setenv PWD ", (*env)->pwd);
		apply_setenv(tmp);
		ft_strdel(&tmp);
	}
	if (!(update_var(env, "OLDPWD", (*env)->oldpwd)))
	{
		tmp = ft_strjoin("setenv OLDPWD ", (*env)->oldpwd);
		apply_setenv(tmp);
		ft_strdel(&tmp);
	}
}
Esempio n. 2
0
void add_package(package_t* package)
{
   variable_t* evar;
   variable_t* vvar;
   list_node* enode;
   list_node* vnode;
   list_node* rnode;
   group_t* group;
   char* name;
   int got_one;
   char* text;
   
   if (package->requires)
   {
      DEBUG(stderr, "(pre-using required packages list)\n");

      for (rnode=list_tail(package->requires) ; rnode ; rnode=previous(rnode))
      {
         name = (char*) get_value(rnode);

         if (group = get_group(name))
            use_group(group);
         else
            use_package(name);
      }
   }

   for (vnode = head(package->variables) ; vnode ; vnode = next(vnode))
   {
      vvar = get_value(vnode);
      got_one = 0;
      for (enode = head(the_environment) ; enode ; enode = next(enode))
      {
         evar = get_value(enode);
         if (!strcmp(vvar->name, evar->name))
         {
            remove_node(the_environment, enode, 0);
            add_to_tail(the_environment, update_var(evar, vvar));
            got_one = 1;
            break;
         }
      }
      if (!got_one)
      {
         enode = get_into_env(vvar);
         evar = get_value(enode);
         set_value(enode, update_var(evar, vvar));
      }
   }
   
   for (vnode = head(package->scripts) ; vnode ; vnode = next(vnode))
   {
      text = ((script_t*) get_value(vnode))->text;
      add_to_tail(the_scripts, (void*) text);
   }   
}
Esempio n. 3
0
File: stack.c Progetto: k6s/yaod
void							update_vars(struct user_regs_struct *regs,
											long stack_frame,
											long old_stack_frame, WINDOW **wins,
											unsigned *hl)
{
	size_t						idx = 0;
	size_t						var_len;

	while (regs->rbp - idx + 8 > regs->rsp)
	{
		var_len = 0;
		while (regs->rbp - idx + 8 > regs->rsp
			   && *(char *)(stack_frame + idx)
			   == *(char *)(old_stack_frame + idx))
			++idx;
		while (regs->rbp - idx - var_len + 8 > regs->rsp
			   && *(char *)(stack_frame + idx + var_len)
			   != *(char *)(old_stack_frame + idx + var_len))
			++var_len;
		if (var_len)
		{
			update_var(wins[WIN_STACK], (char *)stack_frame + idx, idx, var_len,
					   hl, COLOR_PAIR(2));
			idx += var_len;
		}
	}
}
Esempio n. 4
0
int		my_set(t_cmd *cmd, t_shell *shell)
{
	t_cmd	*tmp;
	t_env	*exist;

	tmp = cmd->next->next;
	while (tmp != cmd)
	{
		if (verif_var(tmp))
		{
			if ((exist = already_exist_var(tmp, shell->var))
				&& update_var(tmp, exist) == -1)
				return (-1);
			else if (!exist)
				if (create_var(tmp, shell->var) == -1)
					return (-1);
		}
		else
		{
			ft_putstr_fd("Var should begin with a letter\n", 2);
			return (0);
		}
		tmp = tmp->next;
	}
	if (cmd->next->next == cmd)
		aff_var(shell->var);
	return (1);
}
Esempio n. 5
0
/* Same as session_env_putenv but with name and value given as distict
   values.  */
gpg_error_t
session_env_setenv (session_env_t se, const char *name, const char *value)
{
  if (!name || !*name)
    return gpg_error (GPG_ERR_INV_VALUE);
  if (!value)
    return delete_var (se, name);
  else
    return update_var (se, name, strlen (name), value, 0);
}
Esempio n. 6
0
File: stack.c Progetto: k6s/yaod
void										un_hl(WINDOW *win, unsigned *hl,
												  char *data)
{
	size_t								i;

	i = 0;
	while (i < MAX_STACK_FRAME && *(hl + i * 2 + 1))
	{
		update_var(win, *(hl + i * 2) + data, *(hl + i * 2), *(hl + i * 2 + 1),
				   NULL, COLOR_PAIR(1));
		++i;
	}
}
Esempio n. 7
0
static void		update_env(t_params *p, char *new_dir)
{
	char	*tmp;

	p->oldpwd = p->pwd;
	if (ft_strstr(new_dir, "/nfs/"))
		p->pwd = ft_strdup(ft_strstr(new_dir, "/nfs/"));
	else
		p->pwd = ft_strdup(new_dir);
	if (!(update_var(p, "PWD=", p->pwd)))
	{
		tmp = ft_strjoin("setenv PWD ", p->pwd);
		ft_add_env(tmp, p);
		ft_strdel(&tmp);
	}
	if (!(update_var(p, "OLDPWD=", p->oldpwd)))
	{
		tmp = ft_strjoin("setenv OLDPWD ", p->oldpwd);
		ft_add_env(tmp, p);
		ft_strdel(&tmp);
	}
}
Esempio n. 8
0
/* Set or update an environment variable of the session environment.
   String is similar to the putval(3) function but it is reentrant and
   takes a copy.  In particular it exhibits this behaviour:

          <NAME>            Delete envvar NAME
          <KEY>=            Set envvar NAME to the empty string
          <KEY>=<VALUE>     Set envvar NAME to VALUE

   On success 0 is returned; on error an gpg-error code.  */
gpg_error_t
session_env_putenv (session_env_t se, const char *string)
{
  const char *s;

  if (!string || !*string)
    return gpg_error (GPG_ERR_INV_VALUE);
  s = strchr (string, '=');
  if (s == string)
    return gpg_error (GPG_ERR_INV_VALUE);
  if (!s)
    return delete_var (se, string);
  else
    return update_var (se, string, s - string, NULL, 0);
}
Esempio n. 9
0
/* Return the value of the environment variable NAME from the SE
   object.  The returned value is valid as long as SE is valid and as
   long it has not been removed or updated by a call to
   session_env_putenv.  If the variable does not exist, the function
   tries to return the value trough a call to getenv; if that returns
   a value, this value is recorded and and used.  If no value could be
   found, returns NULL.  The caller must not change the returned
   value. */
char *
session_env_getenv_or_default (session_env_t se, const char *name,
                               int *r_default)
{
  int idx;
  char *defvalue;

  if (r_default)
    *r_default = 0;
  if (!se || !name || !*name)
    return NULL;

  for (idx=0; idx < se->arrayused; idx++)
    if (se->array[idx] && !strcmp (se->array[idx]->name, name))
      {
        if (r_default && se->array[idx]->is_default)
          *r_default = 1;
        return se->array[idx]->value;
      }

  /* Get the default value with an additional fallback for GPG_TTY.  */
  defvalue = getenv (name);
  if ((!defvalue || !*defvalue) && !strcmp (name, "GPG_TTY")
      && gnupg_ttyname (0))
    {
      defvalue = gnupg_ttyname (0);
    }
  if (defvalue)
    {
      /* Record the default value for later use so that we are safe
         from later modifications of the environment.  We need to take
         a copy to better cope with the rules of putenv(3).  We ignore
         the error of the update function because we can't return an
         explicit error anyway and the following scan would then fail
         anyway. */
      update_var (se, name, strlen (name), defvalue, 1);

      for (idx=0; idx < se->arrayused; idx++)
        if (se->array[idx] && !strcmp (se->array[idx]->name, name))
          {
            if (r_default && se->array[idx]->is_default)
              *r_default = 1;
            return se->array[idx]->value;
          }
    }

  return NULL;
}
Esempio n. 10
0
File: stack.c Progetto: k6s/yaod
void							dump_new_frame(struct user_regs_struct *regs,
                                 struct user_regs_struct *old_regs,
                                 void *stack_frame, WINDOW **wins)
{
  wclear(wins[WIN_REGS]);
  dump_regs_name(wins[WIN_REGS]);
  if (old_regs)
    dump_regs(old_regs, regs, wins, 1);
  werase(wins[WIN_STACK]);
  addr_prefix(regs->rbp, 0, regs->rbp - regs->rsp + 8, wins[WIN_STACK]);
/*  dump_data((char *)stack_frame, (char *)((long)stack_frame + regs->rbp
										  - regs->rsp + 8),
            wins[WIN_STACK], 0, 0); */
  update_var(wins[WIN_STACK], stack_frame, 0, regs->rbp - regs->rsp + 8, NULL, 1);
  touchwin(wins[WIN_STACK]);
  prefresh(wins[WIN_STACK], 0, 0, WIN_BORDER_LEN, WIN_BORDER_LEN, WIN_STACK_LI, 
		   WIN_STACK_CO);
}
Esempio n. 11
0
File: stack.c Progetto: k6s/yaod
int								dump_new_vars(struct user_regs_struct *regs,
											  struct user_regs_struct *old_regs,
											  void *stack_frame, WINDOW *win,
											  unsigned *hl)
{
	size_t					idx;
	size_t					var_len;
	size_t					c_co;
	char					disa;

	if (old_regs->rsp > regs->rsp)
	{
		idx = regs->rbp - old_regs->rsp + 8;
		var_len = old_regs->rsp - regs->rsp;
		addr_prefix(regs->rbp, idx, var_len + idx, win);
		if ((var_len + idx) / 16 < WIN_OSTACK_LI)
			update_var(win, (char *)stack_frame + idx, idx, var_len, hl,
					   COLOR_PAIR(2));
		prefresh(win, 0, 0, WIN_BORDER_LEN, WIN_BORDER_LEN,
			WIN_STACK_LI, WIN_STACK_CO);
	}
	else
	{
		disa = (regs->rbp % 16 ? 1 : 0) ^ (regs->rbp - regs->rsp % 16 ? 1 : 0);
		idx = regs->rbp - regs->rsp + 8;
		c_co = idx % 16;
		c_co += c_co + c_co / 2 + c_co / 8;
		wmove(win, idx / 16, c_co + (disa ? ADDR_PLEN : 0));
		if (disa)
			wmove(win, idx / 16, 45 + idx % 16 + ADDR_PLEN);
		wclrtobot(win);
		prefresh(win, 0, 0, WIN_BORDER_LEN, WIN_BORDER_LEN,
			WIN_STACK_LI, WIN_STACK_CO);
	}
	return (0);
}
Esempio n. 12
0
File: eval.c Progetto: jfilleau/sss
state_t* eval_stmts(ast_t *p, state_t *state)
{
    ast_list_t *stmts;
    ast_list_t *ip;
    ast_t *t1, *t2;
    ast_t *s;
    value_t v;

    assert(p != NULL);
    assert(p->info.node.tag == SEQ);
    ip = p->info.node.arguments;
    while(ip != NULL)
    {
	s = ip->elem;
        value_t e1;

	switch(s->info.node.tag){
	case ASSIGN:
	    /* the lhs */
	    t1 = s->info.node.arguments->elem;
	    /* the rhs */
	    t2 = s->info.node.arguments->next->elem;
	    v = eval_exp(t2, state->tbl, state->mem);
	    switch(t1->tag){
	    case var_ast:
		state->tbl = update_var(t1->info.string, v, state->tbl);
		break;
	    case node_ast:
		assert(t1->info.node.tag == MEM);
		is_first_eval = 0;
		state->mem = store(eval_exp(t1->info.node.arguments->elem, state->tbl, state->mem).value, v, state->mem);
		eval_exp(t2, state->tbl, state->mem);	
		is_first_eval = 0;		  
		break;
	    default:
		assert(0);
	    }
	  break;
	case PRINT:
	    switch(s->info.node.arguments->elem->tag){
	    case str_ast:
		printf("%s\n", s->info.node.arguments->elem->info.string);
		fprintf(stderr, "Tainted variable: None\n");
		break;
	    default:
                e1 = eval_exp(s->info.node.arguments->elem, 
					state->tbl,
					state->mem);
                if (e1.taint) {
                  fprintf(stderr,"%s", "Tainted variable: ");
                  is_first_taint = 1;
                  arithmetic_check(s->info.node.arguments->elem, state);
                  fprintf(stderr,"\n");
                  printf("%s\n", "<secret>");
                }
                else {
                  fprintf(stderr,"%s\n","Tainted variable: None");
                  printf("%u\n", e1.value);
                }
		break;
	    }

	  break;
	case IF:
        //control-flow taint shall NOT be tracked, so no changes here

	    if(eval_exp(s->info.node.arguments->elem, state->tbl, state->mem).value){
		state = eval_stmts(s->info.node.arguments->next->elem, state);
	    } else {
		state = eval_stmts(s->info.node.arguments->next->next->elem, state);
            } 
	  break;
	case SEQ:
	    state = eval_stmts(s->info.node.arguments->next->elem, state);
	  break;
	case ASSERT:
	    if(eval_exp(s->info.node.arguments->elem, state->tbl,state->mem).value ==0){
		printf("Assert failed!\n");
	    }
	  break;
	default:
	  printf("Unknown statement type\n");
	  assert(0);
	  break;
	}
	is_first_eval = 1;
	ip = ip->next;
    }
    return state;
}
Esempio n. 13
0
state_t* eval_stmts(ast_t *p, state_t *state)
{
    ast_list_t *stmts;
    ast_list_t *ip;
    ast_t *t1, *t2;
    ast_t *s;
    value_t v;
    int just_tainted = 0;
    int i;
    assert(p != NULL);
    assert(p->info.node.tag == SEQ);
    ip = p->info.node.arguments;
    while(ip != NULL)
    {
	s = ip->elem;

	switch(s->info.node.tag){
	case ASSIGN:
            printf("\nthis is ASSIGN\n");
	    /* the lhs */
	    t1 = s->info.node.arguments->elem;
	    /* the rhs */
	    t2 = s->info.node.arguments->next->elem;
	    v = eval_exp(t2, state->tbl, state->mem);
	    switch(t1->tag){
	    case var_ast:
                printf("\n var ast horela.");
		state->tbl = update_var(t1->info.string, v, state->tbl);// check is tf == 1=>add tbl->name & reset tf= 0
                printf("\n var ast ke baad tbl name : %s",state->tbl->name); 
                if(tf==1){
                         printf("\nVal od type = %d",type);
                         printf("\nTainted. Adding this up! : %s\n",state->tbl->name);
                         add_var(state->tbl->name);
                         printf("\nAdded Taint! %s \n",state->tbl->name);
                         tf = 0;
                         just_tainted = 1;
                         tvar_index = 0;
                         type = 0;
                }
               


                if(constant_check == 1 && just_tainted == 0){
                printf("\n constant present...\n");
                printf("\nvariable name is ..%s\n",state->tbl->name);
                if(check_tain_var(state->tbl->name)){
                       printf("\n removing taint!\n\n");
                       remove_taint_var(state->tbl->name);
                       printf("\nremoved!\n");
                       constant_check = 0;
                      type = 0;
                }
            
                }
                just_tainted = 0;


		break;
	    case node_ast:
                 
                printf("\nMemo horela. ");
               
		assert(t1->info.node.tag == MEM);
		state->mem = store(eval_exp(t1->info.node.arguments->elem,
					  state->tbl, 
					  state->mem), v, state->mem);//same here. 

               
               

                if(tf == 1){
                            printf("\ntaint detected. Adding address %u up\n",state->mem->addr);
                            add_mem(state->mem->addr);
                            printf("\nMemory tainted! Addr : %u \n",state->mem->addr);
                             
                            tf = 0;
                            tmem_index = 0;
                            type = 0;
                            memo = 0;
                }
                     

                printf("\nafter nost ast..mem val is : %u",state->mem->addr);
                if(cc_mem == 2){
                printf("\n constant present...\n");
                if(check_tain_mem(state->mem->addr)){
                       printf("\n removing taint!\n\n");
                       remove_taint_mem(state->mem->addr);
                       printf("\nremoved!\n");
                       cc_mem = 0;
                }
            
                }

      



		break;
	    default:
		assert(0);
	    }
	  break;
	case PRINT:
            printf("\n this is printttt\n");
	    switch(s->info.node.arguments->elem->tag){
	    case str_ast:
                printf("\nin str-ast");
		printf("str asgn %s\n", s->info.node.arguments->elem->info.string);
                fprintf(stderr,"Tainted variable: None\n");
		break;
	    default:
                printf("\n default.\n");
                printf("\n Memory addrs now : %u \n",state->mem->addr);
                printf("\n var name now :%s\n",state->tbl->name);
                coming_from_print =1;
                
		printf("def %u\n", eval_exp(s->info.node.arguments->elem, 
					state->tbl,
	        				state->mem));  
                if (tf==0)
                 fprintf(stderr,"Tainted variable: None\n");
                    

                 
	         if(tf == 1){
                    
                    printf("\nTaint detected!! with type %d and tvar_index %d\n",type,tvar_index);
                    fprintf(stderr,"Tainted variable: ");
                    /*switch(type){
                    case 1 : printf("\nIts a variable!\n"); 
                             %s\n",tvar_arr[tvar_index]);
                             break;
                    case 2 : printf("\nIts a memory!\n");
                             fprintf(stderr,"Tainted variable: mem[%u]\n",tmem_arr[tmem_index]);
                             break;
                   case 3 : printf("\nIts kinda both.\n");
                             fprintf(stderr,"Tainted variable: %s, mem[%u]\n",tvar_arr[tvar_index],tmem_arr[tmem_index]); 
                             break;  
                    case 4 : printf("\nIts direct!\n");
                             fprintf(stderr," direct");
                             break;      
 
                    }
                    fprintf(stderr,"Tainted variable: ");*/
                                                
                    for (i=0;i<=tvar_index; i++)
                      {  if (tvar_arr[i][1] == 2)
                            {
         		   // printf("\nIts direct!\n");
        		    fprintf(stderr,"direct"); 
                        
                               
                            }

                         else if (tvar_arr[i][1] == 1)
                            {
         		   // printf("\nIts a variable!\n");
        		    fprintf(stderr,"mem[%d]",tvar_arr[i][0]); 
                            }

                          else 
                            {
         		   // printf("\nIts a variable!\n");
        		    fprintf(stderr,"%s",tvar_arr[i]); 
                            }
 
                          if (i>0 && i<tvar_index)
                          fprintf(stderr,", ");
       
                      }
                       fprintf(stderr,"\n");
                     
                 }

                 type = 0;
                 tf = 0;
                 tvar_index = 0;
                 tmem_index = 0;
                 coming_from_print = 0;
		break;
	    }

	  break;
	case IF:
            printf("\nthis is IFFF\n");
	    if(eval_exp(s->info.node.arguments->elem, state->tbl, state->mem)){
		state = eval_stmts(s->info.node.arguments->next->elem, state);
	    } else {
		state = eval_stmts(s->info.node.arguments->next->next->elem, state);
            } 
	  break;
	case SEQ:
            printf("\n this is SEQQQ\n");
	    state = eval_stmts(s->info.node.arguments->next->elem, state);
	  break;
	case ASSERT:
	    if(eval_exp(s->info.node.arguments->elem, state->tbl,state->mem) ==0){
		printf("Assert failed!\n");
	    }
	  break;
	default:
	  printf("Unknown statement type\n");
	  assert(0);
	  break;
	}
	ip = ip->next;
    }
    return state;
}