示例#1
0
subuser *checkrecv_websocket(ape_socket *co, acetables *g_ape)
{
	unsigned int op;
	clientget cget;
	websocket_state *websocket = co->parser.data;
	subuser *user = NULL;
	
	cget.client = co;
	cget.ip_get = co->ip_client;
	cget.get = websocket->data;
	cget.host = websocket->http->host;

	op = checkcmd(&cget, TRANSPORT_WEBSOCKET, &user, g_ape);

	switch (op) {
		case CONNECT_SHUTDOWN:
		case CONNECT_KEEPALIVE:
			break;
	}	
	
	return user;
}
示例#2
0
文件: sys.c 项目: agatti/radare2
R_API int r_sys_crash_handler(const char *cmd) {
#if __UNIX__
	struct sigaction sigact;
	if (!checkcmd (cmd)) {
		return false;
	}
#ifdef HAVE_BACKTRACE
	void *array[1];
	/* call this outside of the signal handler to init it safely */
	backtrace (array, 1);
#endif

	free (crash_handler_cmd);
	crash_handler_cmd = strdup (cmd);
	sigact.sa_handler = signal_handler;
	sigemptyset (&sigact.sa_mask);
	sigact.sa_flags = 0;
	sigaction (SIGINT, &sigact, (struct sigaction *)NULL);

	sigaddset (&sigact.sa_mask, SIGSEGV);
	sigaction (SIGSEGV, &sigact, (struct sigaction *)NULL);

	sigaddset (&sigact.sa_mask, SIGBUS);
	sigaction (SIGBUS, &sigact, (struct sigaction *)NULL);

	sigaddset (&sigact.sa_mask, SIGQUIT);
	sigaction (SIGQUIT, &sigact, (struct sigaction *)NULL);

	sigaddset (&sigact.sa_mask, SIGHUP);
	sigaction (SIGHUP, &sigact, (struct sigaction *)NULL);

	sigaddset (&sigact.sa_mask, SIGKILL);
	sigaction (SIGKILL, &sigact, (struct sigaction *)NULL);
	return true;
#else
	return false;
#endif
}
示例#3
0
subuser *checkrecv(char *pSock, ape_socket *client, acetables *g_ape, char *ip_client)
{

	unsigned int op;
	unsigned int isget = 0;
	
	subuser *user = NULL;
	int local = (strcmp(ip_client, CONFIG_VAL(Server, ip_local, g_ape->srv)) == 0);
	
	clientget *cget = xmalloc(sizeof(*cget));


	if (strlen(pSock) < 3 || (local && getqueryip(pSock, cget->ip_get) == 0)) {  // get query IP (from htaccess)
		free(cget);
		shutdown(client->fd, 2);
		return NULL;		
	}
	if (!local) {
		strncpy(cget->ip_get, ip_client, 16); // get real IP (from socket)
	}
	
	cget->client = client;
	
	gethost(pSock, cget->host);
	
	if (strncasecmp(pSock, "GET", 3) == 0) {
		if (!fixpacket(pSock, 0) || (cget->get = getfirstparam(pSock, (local ? '&' : '?'))) == NULL) {
			free(cget);
			
			shutdown(client->fd, 2);
			return NULL;			
		} else {
			isget = 1;
		}
	} else if (strncasecmp(pSock, "POST", 4) == 0) {
		if ((cget->get = getpost(pSock)) == NULL) {
			free(cget);
			
			shutdown(client->fd, 2);
			return NULL;			
		}
	} else {
		free(cget);

		shutdown(client->fd, 2);
		return NULL;		
	}
	
	fixpacket(cget->get, 1);

	if (isget) {
		urldecode(cget->get);
	}
	
	op = checkcmd(cget, gettransport(pSock), &user, g_ape);

	switch (op) {
		case CONNECT_SHUTDOWN:
			shutdown(client->fd, 2);			
			break;
		case CONNECT_KEEPALIVE:
			break;
	}

	free(cget);
	
	return user;

}
示例#4
0
subuser *checkrecv(ape_socket *co, acetables *g_ape)
{
	unsigned int op;
	http_state *http = co->parser.data;
	subuser *user = NULL;
	clientget cget;
	
	if (http->host == NULL) {
		shutdown(co->fd, 2);
		return NULL;
	}
	
	if (gettransport(http->uri) == TRANSPORT_WEBSOCKET) {
		char *origin = get_header_line(http->hlines, "Origin");
		websocket_state *websocket;
		if (origin == NULL) {
			shutdown(co->fd, 2);
			return NULL;
		}
		
		PACK_TCP(co->fd);
		sendbin(co->fd, CONST_STR_LEN(WEBSOCKET_HARDCODED_HEADERS), 0, g_ape);
		sendbin(co->fd, CONST_STR_LEN("WebSocket-Origin: "), 0, g_ape);
		sendbin(co->fd, origin, strlen(origin), 0, g_ape);
		sendbin(co->fd, CONST_STR_LEN("\r\nWebSocket-Location: ws://"), 0, g_ape);
		sendbin(co->fd, http->host, strlen(http->host), 0, g_ape);
		sendbin(co->fd, http->uri, strlen(http->uri), 0, g_ape);
		sendbin(co->fd, CONST_STR_LEN("\r\n\r\n"), 0, g_ape);
		FLUSH_TCP(co->fd);
		
		co->parser = parser_init_stream(co);
		websocket = co->parser.data;
		websocket->http = http; /* keep http data */
		
		return NULL;
	}

	if (http->data == NULL) {
		sendbin(co->fd, HEADER_DEFAULT, HEADER_DEFAULT_LEN, 0, g_ape);
		sendbin(co->fd, CONST_STR_LEN(CONTENT_NOTFOUND), 0, g_ape);
		
		safe_shutdown(co->fd, g_ape);
		return NULL;
	}
	
	cget.client = co;
	cget.ip_get = co->ip_client;
	cget.get = http->data;
	cget.host = http->host;
	cget.hlines = http->hlines;
	
	op = checkcmd(&cget, gettransport(http->uri), &user, g_ape);

	switch (op) {
		case CONNECT_SHUTDOWN:
			safe_shutdown(co->fd, g_ape);			
			break;
		case CONNECT_KEEPALIVE:
			break;
	}
	
	return user;
}
示例#5
0
文件: docmd.c 项目: UNGLinux/Obase
/*
 * Do the commands in cmds (initialized by yyparse).
 */
void
docmds(struct namelist *hostlist, int argc, char **argv)
{
	struct cmd *c;
	char *cp;
	int i;

	(void) signal(SIGHUP, sighandler);
	(void) signal(SIGINT, sighandler);
	(void) signal(SIGQUIT, sighandler);
	(void) signal(SIGTERM, sighandler);

	if (!nflag)
		mysetlinebuf(stdout);	/* Make output (mostly) clean */

#if	defined(USE_STATDB)
	if (!nflag && (dostatdb || juststatdb)) {
		extern long reccount;
		message(MT_INFO, "Making stat database [%s] ... \n", 
			       gettimestr());
		if (mkstatdb() < 0)
			error("Warning: Make stat database failed.");
		message(MT_INFO,
			      "Stat database created: %d files stored [%s].\n",
			       reccount, gettimestr());
		if (juststatdb)
			return;
	}
#endif	/* USE_STATDB */

	/*
	 * Print errors for any command line targets we didn't find.
	 * If any errors are found, return to main() which will then exit.
	 */
	for (i = 0; i < argc; i++) {
		int found;

		for (found = FALSE, c = cmds; c != NULL; c = c->c_next) {
			if (c->c_label && argv[i] && 
			    strcmp(c->c_label, argv[i]) == 0) {
				found = TRUE;
				break;
			}
		}
		if (!found)
			error("Label \"%s\" is not defined in the distfile.", 
			      argv[i]);
	}
	if (nerrs)
		return;

	/*
	 * Main command loop.  Loop through all the commands.
	 */
	for (c = cmds; c != NULL; c = c->c_next) {
		checkcmd(c);
		if (do_fork) {
			/*
			 * Let the children take care of their assigned host
			 */
			if (amchild) {
				if (strcmp(c->c_name, currenthost) != 0)
					continue;
			} else if (c->c_flags & CMD_ASSIGNED) {
				/* This cmd has been previously assigned */
				debugmsg(DM_MISC, "prev assigned: %s\n",
					 c->c_name);
				continue;
			}
		}

		if (hostlist) {
			/* Do specific hosts as specified on command line */
			struct namelist *nlptr;

			for (nlptr = hostlist; nlptr; nlptr = nlptr->n_next)
				/*
				 * Try an exact match and then a match
				 * without '@' (if present).
				 */
				if ((strcmp(c->c_name, nlptr->n_name) == 0) ||
				    ((cp = strchr(c->c_name, '@')) &&
				     strcmp(++cp, nlptr->n_name) == 0))
					docmd(c, argc, argv);
			continue;
		} else
			/* Do all of the command */
			docmd(c, argc, argv);
	}

	if (do_fork) {
		/*
		 * We're multi-threaded, so do appropriate shutdown
		 * actions based on whether we're the parent or a child.
		 */
		if (amchild) {
			if (!IS_ON(options, DO_QUIET))
				message(MT_VERBOSE, "updating of %s finished", 
					currenthost);
			closeconn();
			cleanup(0);
			exit(nerrs);
		}

		/*
		 * Wait for all remaining active children to finish
		 */
		while (activechildren > 0) {
			debugmsg(DM_MISC, 
				 "Waiting for %d children to finish.\n",
				 activechildren);
			waitup();
		}
	} else if (!nflag) {
		/*
		 * We're single-threaded so close down current connection
		 */
		closeconn();
		cleanup(0);
	}
}
示例#6
0
文件: readcmd.c 项目: hydrix1/tacacs
static void parsecmd(struct context *ctx, int cfn)
{
    char *t, *u;
    char lastchar = 0;		/* Anything different from <CR> will do. */
    DebugIn(DEBUG_PROC);

    t = u = ctx->cbufi->buf + ctx->cbufi->offset;

  again:

    for (; t < ctx->cbufi->buf + ctx->cbufi->length; t++)
	switch (*t) {
	case '\0':
	    if (lastchar == '\r')	/* <CR><NUL> => <CR> */
		lastchar = *u++ = *t;
	    else {
		Debug((DEBUG_PROC, " %s: Illegal character sequence \\%o\\%o\n", __func__, lastchar, *t));
		cleanup(ctx, ctx->cfn);
		DebugOut(DEBUG_PROC);
		return;
	    }
	    break;
	case '\n':
	    if (lastchar == '\r') {	/* <CR><LF> => EOL */
		struct io_context *io = ctx->io;
		cfn = ctx->cfn;
		*(u - 1) = 0;
		checkcmd(ctx, ctx->cbufi->buf);

		if (io_get_ctx(io, cfn))
		    /* need to check whether our context is still valid */
		{
		    ctx->cbufi->offset = t - ctx->cbufi->buf + 1;
		    if (ctx->cbufi->offset == ctx->cbufi->length) {
			ctx->cbufi = buffer_free(ctx->cbufi);
			io_sched_del(ctx->io, ctx, (void *) parsecmd);
			if (!ctx->cbufi && io_get_cb_i(ctx->io, ctx->cfn) == (void *) readcmd)
			    io_set_i(ctx->io, ctx->cfn);
		    } else if (io_sched_renew_proc(ctx->io, ctx, (void *) parsecmd))
			io_sched_add(ctx->io, ctx, (void *) parsecmd, 0, 0);
		}
		DebugOut(DEBUG_PROC);
		return;
	    }
	    /* fall through */
	default:
	    lastchar = *u++ = *t;
	}

    /*
     * The FTP protocol doesn't support pipelining. No way this code can
     * be reached with a well-behaving client.
     */

    /*
     * Move content of input buffer to beginning of buffer.
     */
    if (ctx->cbufi->offset != ctx->cbufi->length) {
	ctx->cbufi->length -= ctx->cbufi->offset;
	memmove(ctx->cbufi->buf, ctx->cbufi->buf + ctx->cbufi->offset, ctx->cbufi->length);
	t -= ctx->cbufi->offset, u -= ctx->cbufi->offset;
	ctx->cbufi->offset = 0;
    }

    /*
     * If we have more data, try to fill current buffer, then continue parsing.
     */
    if (ctx->cbufi->next && ctx->cbufi->length < ctx->cbufi->size) {
	size_t len = MIN(ctx->cbufi->size - ctx->cbufi->length,
			 ctx->cbufi->next->length - ctx->cbufi->offset);
	memcpy(ctx->cbufi->buf + ctx->cbufi->length, ctx->cbufi->next->buf + ctx->cbufi->offset, len);
	ctx->cbufi->length += len, ctx->cbufi->next->offset += len;
	if (ctx->cbufi->next->offset == ctx->cbufi->next->length)
	    ctx->cbufi->next = buffer_free(ctx->cbufi->next);
	goto again;
    }

    /*
     * Terminate connection if buffer filled but no <CR><LF> is found.
     * Otherwise, accept more input.
     */
    if (ctx->cbufi->length == ctx->cbufi->size) {
	logmsg("Found garbage in command buffer. Terminating session %.8lx", ctx->id);
	cleanup(ctx, ctx->cfn);
    } else
	io_set_i(ctx->io, ctx->cfn);

    DebugOut(DEBUG_PROC);
}
示例#7
0
文件: options.c 项目: wlevine/clamz
static int read_user_config(clamz_config *cfg)
{
  static const char default_config[] =
    "## Clamz configuration file\n"
    "\n"
    "## Default format for output filenames.  This may contain any of\n"
    "## the following variables:\n"
    "##\n"
    "##  ${title} ${creator} ${album} ${tracknum} ${album_artist}\n"
    "##  ${genre} ${discnum} ${suffix} ${asin} ${album_asin}\n"
    "##\n"
    "## The name format may also contain slashes, if you'd like to\n"
    "## categorize your files in subdirectories.\n"
    "NameFormat       \"${tracknum} - ${title}.${suffix}\"\n"
    "\n"
    "## The base directory in which to store downloaded music.\n"
    "## If unset, it defaults to the current directory.\n"
    "# OutputDir       \"/home/me/Music\"\n"
    "\n"
    "## Set to True to allow uppercase in filenames.\n"
    "## False to convert to lowercase.\n"
    "AllowUppercase   True\n"
    "\n"
    "## Set to True to output UTF-8 filenames, False to output ASCII only,\n"
    "## UseLocale to check the system locale setting.\n"
    "AllowUTF8        UseLocale\n"
    "\n"
    "## The set of ASCII characters which are disallowed.  (Control\n"
    "## characters and slashes are always disallowed.)\n"
    "ForbidChars      \"!\\\"$*:;<>?\\\\`|~\"\n"
    "\n";

  char *cfgname;
  FILE *cfgfile;
  char buf[1024];
  int linenum = 0;
  char *p;

  cfgname = get_config_file_name(NULL, "config", NULL);
  if (!cfgname)
    return 1;

  cfgfile = fopen(cfgname, "r");
  if (!cfgfile) {
    cfgfile = fopen(cfgname, "w+");
    if (!cfgfile) {
      print_error("Unable to open configuration file '%s'", cfgname);
      free(cfgname);
      return 1;
    }

    fputs(default_config, cfgfile);
    fseek(cfgfile, 0L, SEEK_SET);
  }

  while (fgets(buf, sizeof(buf), cfgfile)) {
    linenum++;
    if ((p = strchr(buf, '#')))
      *p = 0;

    p = buf;
    while (*p == ' ' || *p == '\t' || *p == '\n')
      p++;
    if (!*p)
      continue;

    if ((p = checkcmd(buf, "NameFormat"))) {
      if (cfg->name_format)
	free(cfg->name_format);
      cfg->name_format = strdup(p);

      if (!cfg->name_format) {
	print_error("Out of memory");
	return 1;
      }
    }
    else if ((p = checkcmd(buf, "OutputDir"))) {
      if (cfg->output_dir)
	free(cfg->output_dir);
      cfg->output_dir = strdup(p);

      if (!cfg->output_dir) {
	print_error("Out of memory");
	return 1;
      }
    }
    else if ((p = checkcmd(buf, "ForbidChars"))) {
      if (cfg->forbid_chars)
	free(cfg->forbid_chars);
      cfg->forbid_chars = NULL;
      if (add_forbidden_chars(cfg, p))
	return 1;
    }
    else if ((p = checkcmd(buf, "AllowUppercase"))) {
      if (*p == 't' || *p == 'T')
	cfg->allowupper = 1;
      else
	cfg->allowupper = 0;
    }
    else if ((p = checkcmd(buf, "AllowUTF8"))) {
      if (*p == 't' || *p == 'T')
	cfg->allowutf8 = 1;
      else if (*p == 'f' || *p == 'F')
	cfg->allowutf8 = 0;
      else
	cfg->allowutf8 = cfg->utf8locale;
    }
  }

  fclose(cfgfile);
  free(cfgname);
  return 0;
}