Exemplo n.º 1
0
static const response* add(const char* l)
{
  struct rule* r;
  
  if (*l != 'k' && *l != 'd' && *l != 'z' && *l != 'p' && *l != 'n') return 0;
  r = alloc_rule();
  r->code = *l++;

  if ((l = parse_pattern(l, ':', &r->sender)) != 0 && *l == ':')
    if ((l = parse_pattern(l+1, ':', &r->recipient)) != 0 && *l == ':')
      if ((l = parse_str(l+1, ':', &r->response)) != 0 && *l == ':')
	if ((l = parse_uint(l+1, ':', &r->databytes)) != 0)
	  if (*l == ':'
	      && (l = parse_str(l+1, ':', &r->relayclient)) != 0
	      && *l == ':')
	    parse_env(l+1, &r->environment);

  if (l == 0) return &resp_syntax;
  append_rule(r);

  /* Pre-load text files and pre-open CDB files */
  if (!try_load(&r->sender)) return &resp_erropenref;
  if (!try_load(&r->recipient)) return &resp_erropenref;
  return 0;
}
Exemplo n.º 2
0
/*!
 * \brief Force the reading or the GISRC or MAPSET/VAR files
 * and overwrite/append the specified variables
 * 
 */ 
static void force_read_env(int loc)
{
    FILE *fd;
    if ((fd = open_env("r", loc))) {
        parse_env(fd, loc);
        fclose(fd);
    }
}
Exemplo n.º 3
0
static int saveenv_to_ptn(struct fastboot_ptentry *ptn, char *err_string)
{
	int ret = 1;
	int save = 0;
	int debug = 0;

	/* err_string is only 32 bytes
	   Initialize with a generic error message. */
	sprintf(err_string, "%s", "Unknown Error");

	/* Parse the input twice.
	   Only save to the enviroment if the entire input if correct */
	save = 0;
	if (0 == parse_env(ptn, err_string, save, debug)) {
		save = 1;
		ret = parse_env(ptn, err_string, save, debug);
	}
	return ret;
}
Exemplo n.º 4
0
int main() {
    const char* host;
    uint16_t port, num_threads;
    bool skip_validation;
    parse_env(&host, &port, &num_threads, &skip_validation);

    evbase_t* evbase = event_base_new();
    evhtp_t* htp = evhtp_new(evbase, NULL);
    evhtp_set_cb(htp, "/add", add_cb, NULL);
    evhtp_use_threads_wexit(htp, init_thread, exit_thread, num_threads, NULL);
    evhtp_bind_socket(htp, host, port, 1024);

    printf("READY\n");

    event_base_loop(evbase, 0);
}
Exemplo n.º 5
0
Arquivo: jail.c Projeto: guoyu07/jff
static int check_perm(const char* pathname, const char* envname,
                      char*** patterns)
{
    if (NULL == *patterns) {
        *patterns = parse_env(envname);
        if (NULL == *patterns) {
            errno = ENOMEM;
            return -1;
        }
    }

    if (empty_patterns == *patterns || check_patterns(pathname, *patterns)) {
        errno = EACCES;
        return -1;
    }

    return 0;
}
Exemplo n.º 6
0
static int read_env(int loc)
{

    FILE *fd;

    if (loc == G_VAR_GISRC && st->varmode == G_GISRC_MODE_MEMORY)
	return 0;		/* don't use file for GISRC */

    if (G_is_initialized(&st->init[loc]))
	return 1;

    if ((fd = open_env("r", loc))) {
        parse_env(fd, loc);
        fclose(fd);
    }

    G_initialize_done(&st->init[loc]);
    return 0;
}
Exemplo n.º 7
0
int process_env(char *envp[])
{
    int count = 0;
    int socket;
    struct Nagios_Env *base = NULL;
    struct Nagios_Env *ptr = NULL;
    while (1) {
        if (socket_status == CLOSE) {
            socket = open_sock(serverip);
        }
        if (envp[count] == NULL) {
            break;
        }
        parse_env(envp[count], &base);
        count++;
    }
    print_list(socket, base);
    return (0);
}
Exemplo n.º 8
0
static int		sh_cmd(t_cmd *cmd)
{
	int		ret;

	ret = 2;
	if (!ft_strcmp(cmd->cmd, "echo"))
		ret = echo_dol(cmd);
	cmd->ret = 0;
	if (ret && !(ret = ft_strcmp(cmd->cmd, "setenv")))
		parse_setenv(cmd);
	else if (ret && !(ret = ft_strcmp(cmd->cmd, "unsetenv")))
		parse_unsetenv(cmd);
	else if (ret && !(ret = ft_strcmp(cmd->cmd, "env")))
		parse_env(cmd);
	else if (ret && !(ret = ft_strcmp(cmd->cmd, "pwd")))
		sh_pwd(cmd);
	else if (ret && !(ret = ft_strcmp(cmd->cmd, "cd")))
		parse_cd(cmd);
	return (ret);
}
Exemplo n.º 9
0
//查询所有的slave节点的ip,从配置文件获取,不跟master要
void Client::get_all_meta(vector<string> &ips){
        parse_env("SLAVE_IP",ips,":");
}
Exemplo n.º 10
0
int main(int argc, char *argv[], char *envp[])
{
	test_init(argc, argv);

	if (argc == 1) {
		/*
		 * first process
		 */
		pid_t children_pids[NUM_CHILDREN];
		int ret, i;
		int status;
		/*
		 * We catch children's segfaults via waitpid's status,
		 * but this is to catch the parent itself segfaulting.
		 * This can happen, for instance, if an old (bad)
		 * segment file is left lying around in the hugetlbfs
		 * mountpoint
		 */
		struct sigaction sa_seg = {
			.sa_sigaction = sigsegv_handler,
			.sa_flags = SA_SIGINFO,
		};

		parse_env();

		ret = sigaction(SIGSEGV, &sa_seg, NULL);
		if (ret < 0)
			FAIL("Installing SIGSEGV handler failed: %s",
							strerror(errno));

		shmid = shmget(SHM_KEY, NUM_CHILDREN * NUM_TESTS *
					sizeof(ino_t), IPC_CREAT | IPC_EXCL |
					0666);
		if (shmid < 0)
			FAIL("Parent's shmget failed: %s", strerror(errno));

		shm = shmat(shmid, NULL, 0);
		if (shm == (void *)-1)
			FAIL("Parent's shmat failed: %s", strerror(errno));

		for (i = 0; i < NUM_CHILDREN; i++)
			children_pids[i] = spawn_child(argv[0], i);

		for (i = 0; i < NUM_CHILDREN; i++) {
			ret = waitpid(children_pids[i], &status, 0);
			if (ret < 0) {
				shmctl(shmid, IPC_RMID, NULL);
				shmdt(shm);
				FAIL("waitpid failed: %s", strerror(errno));
			}

			if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
				shmctl(shmid, IPC_RMID, NULL);
				shmdt(shm);
				FAIL("Child %d exited with non-zero status: %d",
							i + 1, WEXITSTATUS(status));
			}

			if (WIFSIGNALED(status)) {
				shmctl(shmid, IPC_RMID, NULL);
				shmdt(shm);
				FAIL("Child %d killed by signal: %s", i + 1,
							strsignal(WTERMSIG(status)));
			}
		}

		verify_inodes();

		shmctl(shmid, IPC_RMID, NULL);
		shmdt(shm);
		PASS();
	} else {
Exemplo n.º 11
0
Arquivo: registry.c Projeto: ebox/ebox
pshkConfigStruct pshk_read_registry(void)
{
    HKEY hk;
    CHAR szBuf[PSHK_REG_VALUE_MAX_LEN+1];
	DWORD szBufSize = PSHK_REG_VALUE_MAX_LEN;
	pshkConfigStruct ret = {0};
	DWORD readRetVal;

	memset(szBuf, 0, sizeof(szBuf));

	if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, PSHK_REG_KEY,
		0, KEY_QUERY_VALUE, &hk) != ERROR_SUCCESS )
	{
        return ret;
	}

	/* Get the log level */
	readRetVal
		= RegQueryValueEx( hk,"loglevel", NULL, NULL, (LPBYTE)szBuf, &szBufSize);
	if( readRetVal != ERROR_SUCCESS )
		return ret;
	ret.logLevel = strtol(szBuf, NULL, 10);
	memset(szBuf, 0, sizeof(szBuf));
	szBufSize = PSHK_REG_VALUE_MAX_LEN;

	/* Get the priority */
	readRetVal
		= RegQueryValueEx( hk,"priority", NULL, NULL, (LPBYTE)szBuf, &szBufSize);
	if( readRetVal != ERROR_SUCCESS )
		return ret;
	ret.priority = strtol(szBuf, NULL, 10);
	memset(szBuf, 0, sizeof(szBuf));
	szBufSize = PSHK_REG_VALUE_MAX_LEN;

	/* Get the pre-change program wait time */
	readRetVal
		= RegQueryValueEx( hk,"preChangeProgWait", NULL, NULL, (LPBYTE)szBuf, &szBufSize);
	if( readRetVal != ERROR_SUCCESS )
		return ret;
	ret.preChangeProgWait = strtol(szBuf, NULL, 10);
	memset(szBuf, 0, sizeof(szBuf));
	szBufSize = PSHK_REG_VALUE_MAX_LEN;

	/* Get the post-change program wait time */
	readRetVal
		= RegQueryValueEx( hk,"postChangeProgWait", NULL, NULL, (LPBYTE)szBuf, &szBufSize);
	if( readRetVal != ERROR_SUCCESS )
		return ret;
	ret.postChangeProgWait = strtol(szBuf, NULL, 10);
	memset(szBuf, 0, sizeof(szBuf));
	szBufSize = PSHK_REG_VALUE_MAX_LEN;

	/* Get the working directory */
	readRetVal = RegQueryValueEx(hk, "workingdir", NULL, NULL, (LPBYTE)szBuf, &szBufSize);
	if( readRetVal != ERROR_SUCCESS )
		return ret;
	ret.workingDir = escape_slashes(szBuf);
	memset(szBuf, 0, sizeof(szBuf));
	szBufSize = PSHK_REG_VALUE_MAX_LEN;

	/* Get the log file */
	readRetVal = RegQueryValueEx(hk, "logfile", NULL, NULL, (LPBYTE)szBuf, &szBufSize);
	if( readRetVal != ERROR_SUCCESS )
		return ret;
	ret.logFile = escape_slashes(szBuf);
	memset(szBuf, 0, sizeof(szBuf));
	szBufSize = PSHK_REG_VALUE_MAX_LEN;

	/* Get the max log file size*/
	readRetVal = RegQueryValueEx(hk, "maxlogsize", NULL, NULL, (LPBYTE)szBuf, &szBufSize);
	if( readRetVal != ERROR_SUCCESS )
		return ret;
	ret.maxLogSize = strtol(szBuf, NULL, 10);
	memset(szBuf, 0, sizeof(szBuf));
	szBufSize = PSHK_REG_VALUE_MAX_LEN;

	/* Pre password change program file */
	readRetVal = RegQueryValueEx(hk, "preChangeProg", NULL, NULL, (LPBYTE)szBuf, &szBufSize);
	if( readRetVal != ERROR_SUCCESS )
		return ret;
	ret.preChangeProg = escape_slashes(szBuf);
	memset(szBuf, 0, sizeof(szBuf));
	szBufSize = PSHK_REG_VALUE_MAX_LEN;

	/* Pre password change program args */
	readRetVal = RegQueryValueEx(hk, "preChangeProgArgs", NULL, NULL, (LPBYTE)szBuf, &szBufSize);
	if( readRetVal != ERROR_SUCCESS )
		return ret;
	ret.preChangeProgArgs = escape_slashes(szBuf);
	memset(szBuf, 0, sizeof(szBuf));
	szBufSize = PSHK_REG_VALUE_MAX_LEN;

	/* Post password change program file */
	readRetVal = RegQueryValueEx(hk, "postChangeProg", NULL, NULL, (LPBYTE)szBuf, &szBufSize);
	if( readRetVal != ERROR_SUCCESS )
		return ret;
	ret.postChangeProg = escape_slashes(szBuf);
	memset(szBuf, 0, sizeof(szBuf));
	szBufSize = PSHK_REG_VALUE_MAX_LEN;

	/* Post password change program args */
	readRetVal = RegQueryValueEx(hk, "postChangeProgArgs", NULL, NULL, (LPBYTE)szBuf, &szBufSize);
	if( readRetVal != ERROR_SUCCESS )
		return ret;
	ret.postChangeProgArgs = escape_slashes(szBuf);
	memset(szBuf, 0, sizeof(szBuf));
	szBufSize = PSHK_REG_VALUE_MAX_LEN;

	/* Environment string */
	readRetVal = RegQueryValueEx(hk, "environment", NULL, NULL, (LPBYTE)szBuf, &szBufSize);
	if( readRetVal != ERROR_SUCCESS )
		return ret;
	ret.environmentStr = strdup(szBuf);
	ret.environment = parse_env(szBuf);
	memset(szBuf, 0, sizeof(szBuf));
	szBufSize = PSHK_REG_VALUE_MAX_LEN;

	/* Get wether to urlencode the password string */
	readRetVal = RegQueryValueEx(hk, "urlencode", NULL, NULL, (LPBYTE)szBuf, &szBufSize);
	if( readRetVal != ERROR_SUCCESS )
		return ret;
	if(!_stricmp(szBuf, "true") || \
		!_stricmp(szBuf, "yes") || \
		!_stricmp(szBuf, "on")			)
		ret.urlencode = TRUE;
	memset(szBuf, 0, sizeof(szBuf));
	szBufSize = PSHK_REG_VALUE_MAX_LEN;

	/* Get wether to output to logfile */
	readRetVal = RegQueryValueEx(hk, "output2log", NULL, NULL, (LPBYTE)szBuf, &szBufSize);
	if( readRetVal != ERROR_SUCCESS )
		return ret;
	if(!_stricmp(szBuf, "true") || \
		!_stricmp(szBuf, "yes") || \
		!_stricmp(szBuf, "on")			)
		ret.inheritParentHandles = TRUE;

    RegCloseKey(hk);

	ret.valid = 1;
	return ret;
}
Exemplo n.º 12
0
int start_command(JNIEnv *env, jclass clazz __attribute__((unused)), jstring jhandler, jstring jcmd, jobjectArray jenv) {
  const char *utf;
  handler *h;
  int id;
  struct cmd_start_info *start_info;
  message *m;
  child_node *c;
  
  id = -1;
  m=NULL;
  c=NULL;
  utf=NULL;
  
  if(!authenticated()) {
    LOGE("%s: not authenticated", __func__);
    return -1;
  }
  
  if(!jhandler) {
    LOGE("%s: handler cannot be null", __func__);
    return -1;
  }
  
  utf = (*env)->GetStringUTFChars(env, jhandler, NULL);
  
  if(!utf) {
    LOGE("%s: cannot get handler name", __func__);
    goto jni_error;
  }
  
  h = get_handler_by_name(utf);
  
  if(!h) {
    LOGE("%s: handler \"%s\" not found", __func__, utf);
    goto exit;
  }
  
  (*env)->ReleaseStringUTFChars(env, jhandler, utf);
  utf=NULL;
  
  m = create_message(get_sequence(&ctrl_seq, &ctrl_seq_lock),
                      sizeof(struct cmd_start_info), CTRL_ID);
  
  if(!m) {
    LOGE("%s: cannot create messages", __func__);
    goto exit;
  }
  
  start_info = (struct cmd_start_info *) m->data;
  start_info->cmd_action = CMD_START;
  start_info->hid = h->id;
  
  if(jcmd && parse_cmd(env, h, jcmd, m)) {
    LOGE("%s: cannot parse command", __func__);
    goto exit;
  }
  
  if(jenv && parse_env(env, jenv, m)) {
    LOGE("%s: cannot parse environment", __func__);
    goto exit;
  }
  
  // create child
  
  c = create_child(m->head.seq);
  
  if(!c) {
    LOGE("%s: cannot craete child", __func__);
    goto exit;
  }
  
  c->handler = h;
  
  // add child to list
  
  pthread_mutex_lock(&(children.control.mutex));
  list_add(&(children.list), (node *) c);
  pthread_mutex_unlock(&(children.control.mutex));
  
  // send message to cSploitd
  
  pthread_mutex_lock(&write_lock);
  // OPTIMIZATION: use id to store return value for later check
  id = send_message(sockfd, m);
  pthread_mutex_unlock(&write_lock);
  
  if(id) {
    LOGE("%s: cannot send messages", __func__);
    // mark it as failed
    c->id = CTRL_ID;
    c->seq = 0;
  }
  
  id=-1;
  
  // wait for CMD_STARTED or CMD_FAIL
  
  pthread_mutex_lock(&(children.control.mutex));
  
  while(c->seq && children.control.active)
    pthread_cond_wait(&(children.control.cond), &(children.control.mutex));
  
  if(c->id == CTRL_ID || c->seq) { // command failed
    list_del(&(children.list), (node *) c);
  } else {
    id = c->id;
  }
  
  c->pending = 0;
  
  pthread_mutex_unlock(&(children.control.mutex));
  
  pthread_cond_broadcast(&(children.control.cond));
  
  if(id != -1) {
    LOGI("%s: child #%d started", __func__, id);
  } else if(c->seq) {
    LOGW("%s: pending child cancelled", __func__);
  } else {
    LOGW("%s: cannot start command", __func__);
  }
  
  goto exit;
  
  jni_error:
  if((*env)->ExceptionCheck(env)) {
    (*env)->ExceptionDescribe(env);
    (*env)->ExceptionClear(env);
  }
  
  exit:
  
  if(m)
    free_message(m);
  
  if(utf)
    (*env)->ReleaseStringUTFChars(env, jhandler, utf);
  
  return id;
}