Exemplo n.º 1
0
t_token	*glob_gest_tok_list(t_token *t, t_global *glob, int flag, char *str)
{
  t_token	*tmp;
  t_token	*tmp2;
  t_token	*tmp3;

  (flag == 0) ? (tmp = creat_list_token(t->content, glob, 0)) :
    (tmp = analyse_cmd(t->content));
  if (str)
    (check_alias(tmp, str));
  if (t && tmp)
    {
      tmp2 = t->next;
      (t->content) ? free(t->content) : (NULL);
      t->content = my_strdup(tmp->content);
      t->id = tmp->id;
      t->spec = tmp->spec;
      (tmp->content) ? (free(tmp->content)) : (tmp->content = NULL);
      (tmp->next) ? (t->next = tmp->next) : (t->next = t->next);
      tmp3 = tmp;
      tmp = tmp->next;
      tmp3 ? (free(tmp3)) : (tmp3 = tmp3);
      while (tmp && tmp->next)
	tmp = tmp->next;
      (tmp) ? tmp->next = tmp2 : (tmp = t);
    }
  return (t);
}
Exemplo n.º 2
0
int EVP_AEAD_CTX_seal(const EVP_AEAD_CTX *ctx, uint8_t *out, size_t *out_len,
                      size_t max_out_len, const uint8_t *nonce,
                      size_t nonce_len, const uint8_t *in, size_t in_len,
                      const uint8_t *ad, size_t ad_len) {
  size_t possible_out_len = in_len + ctx->aead->overhead;

  if (possible_out_len < in_len /* overflow */) {
    OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE);
    goto error;
  }

  if (!check_alias(in, in_len, out)) {
    OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_OUTPUT_ALIASES_INPUT);
    goto error;
  }

  if (ctx->aead->seal(ctx, out, out_len, max_out_len, nonce, nonce_len, in,
                      in_len, ad, ad_len)) {
    return 1;
  }

error:
  /* In the event of an error, clear the output buffer so that a caller
   * that doesn't check the return value doesn't send raw data. */
  memset(out, 0, max_out_len);
  *out_len = 0;
  return 0;
}
Exemplo n.º 3
0
t_token	*glob_gest_tok_list(t_token *t, t_global *glob, int flag, char *str)
{
  t_token	*tmp;
  t_token	*tmp2;

  if (flag == 0)
    tmp = creat_list_token(t->content, glob);
  else
    tmp = analyse_cmd(t->content);
  if (str)
    check_alias(tmp, str);
  if (t && tmp)
    {
      tmp2 = t->next;
      t->content = tmp->content;
      t->id = tmp->id;
      t->spec = tmp->spec;
      if (tmp->next)
	t->next = tmp->next;
      tmp = tmp->next;
      while (tmp && tmp->next)
	tmp = tmp->next;
      if (tmp)
	tmp->next = tmp2;
    }
  return (t);
}
Exemplo n.º 4
0
int
EVP_AEAD_CTX_seal(const EVP_AEAD_CTX *ctx, unsigned char *out, size_t *out_len,
    size_t max_out_len, const unsigned char *nonce, size_t nonce_len,
    const unsigned char *in, size_t in_len, const unsigned char *ad,
    size_t ad_len)
{
	size_t possible_out_len = in_len + ctx->aead->overhead;

	/* Overflow. */
	if (possible_out_len < in_len) {
		EVPerr(EVP_F_AEAD_CTX_SEAL, EVP_R_TOO_LARGE);
		goto error;
	}

	if (!check_alias(in, in_len, out)) {
		EVPerr(EVP_F_AEAD_CTX_SEAL, EVP_R_OUTPUT_ALIASES_INPUT);
		goto error;
	}

	if (ctx->aead->seal(ctx, out, out_len, max_out_len, nonce, nonce_len,
	    in, in_len, ad, ad_len)) {
		return 1;
	}

error:
	/* In the event of an error, clear the output buffer so that a caller
	 * that doesn't check the return value doesn't send raw data. */
	memset(out, 0, max_out_len);
	*out_len = 0;
	return 0;
}
Exemplo n.º 5
0
char		my_execve(char **command, t_list *env, char *path)
{
  char		**tabenv;
  int		status;
  pid_t		pid;
  int		i;
  char		*error;

  pid = fork();
  tabenv = NULL;
  error = NULL;
  if (pid == -1)
    my_puterror("Impossible, error with pid");
  else if (pid == 0)
    {
      i = 0;
      tabenv = conv_list(env);
      error = recursive_execve(my_str_to_wordtab(path, ':'),
			       check_alias(command), tabenv, i);
      execve_error(error, command, tabenv);
    }
  else
    if (wait(&status) == -1)
      my_puterror("Impossible to use wait\n");
  if (WTERMSIG(status) == 11)
    my_putstr("Segmentation fault (core dumped)\n");
  return (0);
}
Exemplo n.º 6
0
void execute(char *cmd)
{
	/* Arguments:
			*cmd --- the program to run
		
		Purpose:
			this function takes a string and forks off
			a new process with the global args array
			
			this will first check to see if aliases exist for 
			the command. check_alias will deal with 
			changing arg[0] if an alias exists, so always
			call execvp with arg[0] (instead of cmd arg) in
			case check_alias changes the cmd
			
			it will then check to see if the cmd is a built in
			command. if it is, then this doesnt fork any process
	*/
	int i;
	check_alias(cmd);
	i = check_builtin(args[0]);
	if(!i) { return;} //cmd was a built in (like "cd")
	if(fork() == 0) {		
		//now in child process
		check_redir(); //check for redirections
		i = execvp(args[0], args); //using execvp to avoid PATH crap		
		if(i < 0) {
			printf("-fash: %s: command not found\n", cmd); //error, we'll just say not found
			exit(1);
		}
	}
	else { handleSig = 1; wait(NULL); }
	handleSig = 0;
}
Exemplo n.º 7
0
void pipe_execute(char *cmd, int readWrite)
{
		/* Arguments:
			*cmd --- the program to run
			*fds   --- array of two file descriptors for pipe
			readWrite --- 0 = read, 1 = write, 2 = both
		
		Purpose:
			this function takes a string and forks off
			a new process with the global args array
			
			this will first check to see if aliases exist for 
			the command. check_alias will deal with 
			changing arg[0] if an alias exists, so always
			call execvp with arg[0] (instead of cmd arg) in
			case check_alias changes the cmd
			
			it will then check to see if the cmd is a built in
			command. if it is, then this doesnt fork any process
	*/
	int i;
	check_alias(cmd);
	i = check_builtin(args[0]);
	if(!i) { return;} //cmd was a built in (like "cd")
	if(fork() == 0) {
		//in child
		check_redir();
		int newfd, readfd, writefd;
		if(readWrite == 2){ //this is a middle command, no closing, dup both stdin and stdout			
			readfd = open("pipe", O_RDONLY);	
			writefd = open("pipe_middle", O_WRONLY | O_CREAT, S_IRWXU | S_IRGRP | S_IROTH);	
			close(0);
			dup(readfd);
			close(1);
			dup(writefd);		
		}else if (readWrite == 1){ //first command, purely writing	
			newfd = open("pipe", O_WRONLY | O_CREAT, S_IRWXU | S_IRGRP | S_IROTH);	
			dup2(newfd,1);
			close(newfd);
		}else{ //last command, purely reading
			newfd = open("pipe", O_RDONLY);			
			close(0);		
			dup(newfd);
			close(newfd);
		}
		i = execvp(args[0], args);	
			
		if(i < 0) {
			printf("-fash: %s: command not found\n", cmd); //error, we'll just say not found
			exit(1);
		}
		if(readWrite == 0){ close(0);close(newfd);}
		else if(readWrite ==1){close(1);close(newfd);}
		else{ close(0);close(1);close(readfd);close(writefd);system("mv pipe_middle pipe");}
	} else {wait(NULL);}	//wait for everyone
}
Exemplo n.º 8
0
Arquivo: alias.c Projeto: SylTi/school
char	*remplace_alias(char *cmd, char **alias)
{
  char	**wordtab;
  int	a;
  
  if ((a = check_alias(cmd, alias)) != -1)
    {
      wordtab = my_wordtab_sep(alias[a], '"');
      return (wordtab[1]);
    }
  else
    return (cmd);
}
	void s3_list_cb(gpointer ignored, gpointer bean)
	{
		(void) ignored;
		if(max > 0) {
			if(DESCR(bean) == &descr_struct_ALIASES) {
				check_alias(bean);
				max--;
				if(0 == max)
					next_marker = g_strdup(ALIASES_get_alias(bean)->str);
			} else {
				_get_cb(obc, bean);
			}
			return;
		}
		if(DESCR(bean) == &descr_struct_ALIASES) {
			truncated = TRUE;
		}
		_bean_clean(bean);
	}
Exemplo n.º 10
0
int main(int argc, char *argv[])
{
    void *fdt;

    test_init(argc, argv);
    fdt = load_blob_arg(argc, argv);

    check_alias(fdt, "/subnode@1", "s1");
    check_alias(fdt, "/subnode@1/subsubnode", "ss1");
    check_alias(fdt, "/subnode@1/subsubnode", "s1/subsubnode");
    check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "sss1");
    check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "ss1/subsubsubnode");
    check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "s1/subsubnode/subsubsubnode");

    PASS();
}
Exemplo n.º 11
0
int EVP_AEAD_CTX_open(const EVP_AEAD_CTX *ctx, uint8_t *out, size_t *out_len,
                      size_t max_out_len, const uint8_t *nonce,
                      size_t nonce_len, const uint8_t *in, size_t in_len,
                      const uint8_t *ad, size_t ad_len) {
  if (!check_alias(in, in_len, out)) {
    OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_OUTPUT_ALIASES_INPUT);
    goto error;
  }

  if (ctx->aead->open(ctx, out, out_len, max_out_len, nonce, nonce_len, in,
                      in_len, ad, ad_len)) {
    return 1;
  }

error:
  /* In the event of an error, clear the output buffer so that a caller
   * that doesn't check the return value doesn't try and process bad
   * data. */
  memset(out, 0, max_out_len);
  *out_len = 0;
  return 0;
}
Exemplo n.º 12
0
int parse_and_execute (char *line)
{
	char *cmd = NULL;
	char * args [MAX_TOKENS];
	cmdnode_t *cmd_node = NULL;
	int error_code = -1;

	if (!(cmd = check_alias (line))) {
		cmd = line;
	}

	if (!(cmd_node = search_command (cmd, &args, &error_code))) {
		write_string (cli_error[error_code]);
		return -1;
	}

	if (!(get_curr_priv_level () & cmd_node->priv_mode)) {
		write_string (cli_error[ERR_INVALID_COMMAND]);
		return 0;
	}
	execute_cmd (cmd_node, args);

	return 0;
}
Exemplo n.º 13
0
void exe_alias(char **args, int argc, struct alias_List * list)
{	
	char buf[256+1];
	

	if(argc==1){
		//show the alias list.
		// printf("%s\n", "show alias");
		show_alias(list);
		return;
	}

	else if(argc==2){
		if(strcmp(args[1],"-a")==0){
			// add here if have time!
			// remove all the node in alias list
			alias_List_remove_all(list);
			return;
		

		}else{
			// printf("%s\n", "add or check alias");
			if(strlen(args[1])>256){
				fprintf(stderr, "%s\n", "alias: too long");
				return;
			}
			strncpy(buf,args[1],strlen(args[1])+1);
			buf[strlen(args[1])]='\0';

			char *left;
			char *right;
			parseAlias(buf,&left,&right);


			if(!right){
				//add new
				show_alias_one(list,left);


			}else{
				// printf("%s\n", "add");
				//add the alias to the list
				if(check_alias(list,left)){
					update_alias(list,left,right);
				}else{
					char *left_value = calloc(strlen(left)+1,sizeof(char));
					strncpy(left_value,left,strlen(left)+1);
					char *right_value = calloc(strlen(right)+1,sizeof(char));
					strncpy(right_value,right,strlen(right)+1);
					alias_List_push(list,left_value,right_value);

				}
				
			}

		}
		
	}
	

	else {
		fprintf(stderr, "%s\n", "format error");
	}

}
Exemplo n.º 14
0
Arquivo: alias.c Projeto: wfp5p/elm
static int get_aliasname(char *aliasname, char *buffer, int *duplicate)
{

/*
 *	Have the user enter an aliasname, check to see if it
 *	is legal, then check for duplicates.  If a duplicate
 *	is found offer to replace existing alias.
 *
 *	Return values:
 *
 *	-1	Either the aliasname was zero length, had bad
 *		characters and was a duplicate which the user
 *		chose not to replace.
 *
 *	0	A new alias was entered successfully.
 *
 *	1	The entered alias was an existing USER alias
 *		that the user has chosen to replace.  In this
 *		case the alias to replace is passed back in
 *		in the variable 'duplicate'.
 */

	int loc;

	do {
	    if (enter_string(aliasname, SLEN,
				LINES-2, strlen(buffer), ESTR_REPLACE) < 0
			|| aliasname[0] == '\0')
	        return(-1);
	} while (check_alias(aliasname) == -1);

	clear_error();			/* Just in case */
/*
 *	Check to see if there is already a USER alias by this name.
 */
	if ((loc = find_alias(aliasname, USER)) >= 0) {
	    dprint(3, (debugfile,
	         "Attempt to add a duplicate alias [%s] in get_aliasname\n",
	         aliases[loc]->alias));
	    if (aliases[loc]->type & GROUP )
	        PutLine(LINES-2,0, catgets(elm_msg_cat,
	                AliasesSet, AliasesAlreadyGroup,
	                "Already a group with name %s."), aliases[loc]->alias);
	    else
	        PutLine(LINES-2,0, catgets(elm_msg_cat,
	                AliasesSet, AliasesAlreadyAlias,
	                "Already an alias for %s."), aliases[loc]->alias);
	    CleartoEOLN();
	 /*
	  * If they don't want to replace the alias by that name
	  * then just return.
	  */
	    if (!enter_yn(catgets(elm_msg_cat, AliasesSet,
			AliasesReplaceExisting,
			"Replace existing alias?"), FALSE, LINES-3, FALSE))
	        return(-1);
	    *duplicate = loc;
	    return(1);
	}
/*
 *	If they have elected to replace an existing alias then
 *	we assume that they would also elect to superceed a
 *	system alias by that name (since they have already
 *	done so).  So we don't even bother to check or ask.
 *
 *	Of course we do check if there was no USER alias match.
 */
	if ((loc = find_alias(aliasname, SYSTEM)) >= 0) {
	    dprint(3, (debugfile,
	      "Attempt to add a duplicate system alias [%s] in get_aliasname\n",
	      aliases[loc]->address));

	    if( ! superceed_system(loc))
	        return(-1);
	}
	return(0);

}
Exemplo n.º 15
0
static EncaCharsetRaw*
read_raw_charset_data(FILE *stream,
                      int *rsize)
{
  char *line;
  EncaCharsetRaw *r, *raw;
  int rs;
  char *gl;

  line = (char*)malloc(LEN);
  r = raw = (EncaCharsetRaw*)malloc(sizeof(EncaCharsetRaw));
  *r = RawNULL;
  rs = 1;
  while (1) {
    gl = fgets(line, LEN, stream);
    if (r->enca && r->rfc1345 && r->cstocs && r->human && r->iconv && r->mime
        && r->flags && r->nsurface && r->aliases) {
      if (r->enca[0] == '\0') {
        fprintf(stderr, "Enca's charset name #%d empty\n", (int)(r - raw + 1));
        exit(1);
      }
      if (r->rfc1345[0] == '\0') {
        fprintf(stderr, "RFC-1345 charset name #%d empty\n", (int)(r - raw + 1));
        exit(1);
      }
      if (r->iconv[0] == '\0') r->iconv = NULL;
      if (r->cstocs[0] == '\0') r->cstocs = NULL;
      if (r->mime[0] == '\0') r->mime = NULL;
      if (r->nsurface[0] == '\0') r->nsurface = strdup("0");
      r->aliases = check_alias(r->aliases, &r->naliases, r->enca);
      r->aliases = check_alias(r->aliases, &r->naliases, r->iconv);
      r->aliases = check_alias(r->aliases, &r->naliases, r->rfc1345);
      r->aliases = check_alias(r->aliases, &r->naliases, r->mime);
      r->aliases = check_alias(r->aliases, &r->naliases, r->cstocs);
      if (!gl) break;
      rs++;
      {
        int d = r - raw;
        raw = (EncaCharsetRaw*)realloc(raw, rs*sizeof(EncaCharsetRaw));
        r = raw + d + 1;
      }
      *r = RawNULL;
    }
    line[LEN-1] = '\0';
    fixspaces(line);
    if (line[0] == '\0' || line[0] == '#') continue;
    if (add_item(line, "enca:", &r->enca)) continue;
    if (add_item(line, "rfc:", &r->rfc1345)) continue;
    if (add_item(line, "iconv:", &r->iconv)) continue;
    if (add_item(line, "mime:", &r->mime)) continue;
    if (add_item(line, "cstocs:", &r->cstocs)) continue;
    if (add_item(line, "human:", &r->human)) continue;
    if (add_item(line, "flags:", &r->flags)) continue;
    if (add_item(line, "nsurface:", &r->nsurface)) continue;
    if (strncmp(line, "aliases:", 8) == 0 && !r->aliases) {
      int i;
      char *next, *l = fixspaces(line+8);
      r->naliases = 1;
      while ((l = strchr(l, ' ')) != NULL) {
        r->naliases++;
        l++;
      }
      r->aliases = (char**)malloc((r->naliases)*sizeof(char*));
      l = line+8;
      for (i = 0; i < r->naliases; i++) {
        next = strchr(l, ' ');
        if (next) *next = '\0';
        r->aliases[i] = strdup(l);
        l = next+1;
      }
      continue;
    }
    fprintf(stderr, "Unexpected `%s'\n", line);
    exit(1);
  }

  *rsize = rs;
  return raw;
}
Exemplo n.º 16
0
/***************************************************************************
  Function: modify_alias
  Description: read old alias and check, write new alias to alias.conf & push to cloud server
  Input: cgi_result, the return value of cgiFormString
            old_alias_str, null terminated, not check yet
            new_alias_str, null terminated, already check
  Output: 
  Return: 0 OK, other Error
  Others:  none
***************************************************************************/
int modify_alias(cgiFormResultType cgi_result, const char * old_alias_str, const char * new_alias_str)
{
    int fd_alias;
	char gateway_alias[FEATURE_GDGL_ACCOUNT_MAX_LEN + 1];
	int res;
	int len, tries = 5;
	int mqid;
	struct client_admin_msgbuf mesg;

    fd_alias = open(FEATURE_GDGL_ALIAS_PATH, O_RDWR, 0777);
	if (fd_alias < 0) {
		return clientAdminAliasFileOpenErr;
	}
	res = write_lock(fd_alias, 0, SEEK_SET, 0);
	if (res == -1) {
		close(fd_alias);
		return clientAdminAliasFileLockErr;
	}
	// Read old alias
	res = read(fd_alias, gateway_alias, FEATURE_GDGL_ACCOUNT_MAX_LEN);
	if (res < 0) {
		close(fd_alias);
		return clientAdminAliasFileReadErr;
	}
	gateway_alias[res] = '\0';
	//add yanly150625
	if((gateway_alias[res-1] == 0x0a)||(gateway_alias[res-1] == 0x0d)) {  //如果最后一个字符等于换行符号或者回车键,就换成结束符
		gateway_alias[res-1] = '\0';
	}
    // Check old alias
	res = check_alias(cgi_result, old_alias_str, gateway_alias);
	if (res != 0) {
		close(fd_alias);
		return res;
	}
	// Check if old == new
	if (strcmp(old_alias_str, new_alias_str) == 0) {
		close(fd_alias);
		return clientAdminTwoAliasEqualErr;
	}

	// Push to cloud
	//if push failed, return push error
	if ( (res = push_to_cloud(modifyAliasType, "modifyalias", old_alias_str, new_alias_str)) < 0 ) {
		close(fd_alias);
		return clientAdminPushToCloudErr;
	}
	else if (res > 0) {
		close(fd_alias);
		return res;
	}

	// Write new alias
	len = strlen(new_alias_str);
	while (tries > 0) {
		// seek to beginning of file
		res = lseek(fd_alias, 0, SEEK_SET);
		if (res < 0) {
		    close(fd_alias);
		    return clientAdminAliasFileSeekErr;
	    }
		// truncate the file to 0 byte
	    res = ftruncate(fd_alias, 0);
	    if (res < 0) {
		    close(fd_alias);
		    return clientAdminAliasFileTruncErr;
	    }
	    res = writen(fd_alias, new_alias_str, len);
	    if (res != len) {
			tries--;
	    }
		else {
			break;
		}
	}
	if (tries == 0) {
	    close(fd_alias);
		return clientAdminAliasFileWriteErr;
	}

	close(fd_alias); //also unlock

	// Send IPC msg
	mqid = msgget(CLIENTADMIN_MQ_KEY, 0);
	if (mqid == -1) {
		CA_DEBUG("msgget error %d:%s\n", mqid, strerror(errno));
	}
	else {
		len = construct_msg(clientAdmintMsgAlias, new_alias_str, &mesg);
		if (len > 0) {
			res = msgsnd(mqid, &mesg, len, 0);
			if (res == -1) {
				CA_DEBUG("msgsnd error %s\n", strerror(errno));
			}
		}
	}
	return 0;
}