Exemplo n.º 1
0
//*******************************************************************
// UPDATE SERVER COLOR
//*******************************************************************
static void update_server_color(trx *t, struct probe_result *prv)
{
  dbi_result result;
  int maxcolor, newcolor;

  if (t->def->server < 2) return;

  if (t->probe->fuse && (t->res->color < prv->color)) {
    // if this probe acts like a fuse, use the previous color if it's higher
    newcolor = prv->color;
  } else {
    newcolor = t->res->color;
  }
  maxcolor = newcolor; // init

  result = db_query(t->probe->db, 0,
                    "select max(color) as color from pr_status where server = '%u'", t->def->server);
  if (result && dbi_result_next_row(result)) {
    maxcolor = dbi_result_get_uint(result, "color");
  }
  dbi_result_free(result);
  //if (t->res->color <= maxcolor) return;

  result = db_query(t->probe->db, 0,
                    // update server set color = '200' where id = '345'
                    "update %s set %s = '%u' where %s = '%u'",
                     OPT_ARG(SERVER_TABLE_NAME), OPT_ARG(SERVER_TABLE_COLOR_FIELD), 
                     maxcolor, OPT_ARG(SERVER_TABLE_ID_FIELD), t->def->server);
  dbi_result_free(result);
}
Exemplo n.º 2
0
static gnutls_x509_crt_t
load_cert (void)
{
  gnutls_x509_crt_t crt;
  int ret;
  gnutls_datum_t dat;
  size_t size;

  if (!HAVE_OPT(LOAD_CERT))
    error (EXIT_FAILURE, 0, "missing --load-cert");

  ret = gnutls_x509_crt_init (&crt);
  if (ret < 0)
    error (EXIT_FAILURE, 0, "crt_init: %s", gnutls_strerror (ret));

  dat.data = (void*)read_binary_file (OPT_ARG(LOAD_CERT), &size);
  dat.size = size;

  if (!dat.data)
    error (EXIT_FAILURE, errno, "reading --load-cert: %s", OPT_ARG(LOAD_CERT));

  ret = gnutls_x509_crt_import (crt, &dat, encoding);
  free (dat.data);
  if (ret < 0)
    error (EXIT_FAILURE, 0, "importing --load-cert: %s: %s",
           OPT_ARG(LOAD_CERT), gnutls_strerror (ret));

  return crt;
}
Exemplo n.º 3
0
int run(void)
{
  database *db;

  if (!cache) {
    cache = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, free_probe);
  }
  
  LOG(LOG_INFO, "reading info from database (group %u)", (unsigned)OPT_VALUE_GROUPID); 
  uw_setproctitle("reading info from database (group %u)", (unsigned)OPT_VALUE_GROUPID);
  db = open_database(OPT_ARG(DBTYPE), OPT_ARG(DBHOST), OPT_VALUE_DBPORT, OPT_ARG(DBNAME), 
			OPT_ARG(DBUSER), OPT_ARG(DBPASSWD));
  if (db) {
    refresh_database(db);
    close_database(db);
  }

  if (g_hash_table_size(cache) > 0) {
    LOG(LOG_INFO, "running %d probes from group %u", g_hash_table_size(cache), (unsigned)OPT_VALUE_GROUPID);
    uw_setproctitle("running %d probes from group %u", g_hash_table_size(cache), (unsigned)OPT_VALUE_GROUPID);
    run_actual_probes(); /* this runs the actual probes */

    LOG(LOG_INFO, "writing results"); 
    uw_setproctitle("writing results");
    write_results();
  }

  return(g_hash_table_size(cache));
}
Exemplo n.º 4
0
int run(void)
{
#ifdef USE_ST
  st_usleep(1); //force context switch so timers will work
#endif
  g_hash_table_foreach(hash, create_q_threads, NULL);
#ifdef USE_ST
  if (debug > 3) { LOG(LOG_DEBUG, "waiting for all threads to finish"); }
  while (thread_count) {
    st_usleep(10000); /* 10 ms */
  }
#endif
  if (HAVE_OPT(HANGUPSCRIPT) && online) {
    int status;

    status = system(OPT_ARG(HANGUPSCRIPT));
    if (WIFEXITED(status)) {
      if (WEXITSTATUS(status) != 0) {
        LOG(LOG_WARNING, "%s: error %d", OPT_ARG(HANGUPSCRIPT), WEXITSTATUS(status));
      }
    } else {
      LOG(LOG_ERR, "%s exited abnormally", OPT_ARG(HANGUPSCRIPT));
    }
  }
  online = FALSE;
  uw_setproctitle("sleeping");
  return 0;
}
Exemplo n.º 5
0
int find_expired_probes(struct dbspec *dbspec)
{
  xmlDocPtr doc;
  xmlNodePtr probe;
  dbi_result result;
  dbi_conn conn;
  int count = 0;
  char buf[10];

  sprintf(buf, "%d", dbspec->port);

  conn = open_database(OPT_ARG(DBTYPE), dbspec->host, buf, dbspec->db,
                     dbspec->user, dbspec->password);
  if (!conn) return 0;

  doc = UpwatchXmlDoc("result", NULL);

  // find all expired probes, but skip those for which processing
  // has been stopped for some reason
  result = db_query(conn, 0, "select probe.name, pr_status.probe, " 
                             "       pr_status.server, pr_status.color, "
                             "       pr_status.expires "
                             "from   pr_status, probe "
                             "where  probe.id = pr_status.class and color <> 400 "
                             "       and expires < UNIX_TIMESTAMP()-30 "
                             "       and expires < probe.lastseen"
                             "       and probe.expiry = 'yes'");
  if (!result) goto errexit;

  while (dbi_result_next_row(result)) {
    char buffer[256];
    time_t now = time(NULL);

    probe = xmlNewChild(xmlDocGetRootElement(doc), NULL, dbi_result_get_string(result, "name"), NULL);
    xmlSetProp(probe, "realm", dbspec->realm);
    xmlSetProp(probe, "id", dbi_result_get_string(result, "probe"));
    xmlSetProp(probe, "server", dbi_result_get_string(result, "server"));
    sprintf(buffer, "%u", (int) now);	xmlSetProp(probe, "date", buffer);
    xmlSetProp(probe, "expires", dbi_result_get_string(result, "expires"));

    xmlNewChild(probe, NULL, "color", "400");  // PURPLE
    xmlNewChild(probe, NULL, "prevcolor", dbi_result_get_string(result, "color"));

    LOG(LOG_INFO, "%s: purpled %s %d", dbspec->realm, dbi_result_get_string(result, "name"), 
                                                      dbi_result_get_uint(result, "probe"));
    count++;
  }
  if (count) {
    xmlSetDocCompressMode(doc, OPT_VALUE_COMPRESS);
    spool_result(OPT_ARG(SPOOLDIR), OPT_ARG(OUTPUT), doc, NULL);
    LOG(LOG_INFO, "%s: purpled %u probes", dbspec->realm, count);
  }

errexit:
  if (result) dbi_result_free(result);
  if (conn) close_database(conn);
  if (doc) xmlFreeDoc(doc);
  return count;
}
Exemplo n.º 6
0
int main(int argc, char **argv)
{
	int ret;

	if ((ret = gnutls_global_init()) < 0) {
		fprintf(stderr, "global_init: %s\n", gnutls_strerror(ret));
		exit(1);
	}

	optionProcess(&ocsptoolOptions, argc, argv);

	gnutls_global_set_log_function(tls_log_func);
	gnutls_global_set_log_level(OPT_VALUE_DEBUG);

	if (HAVE_OPT(OUTFILE)) {
		outfile = fopen(OPT_ARG(OUTFILE), "wb");
		if (outfile == NULL) {
			fprintf(stderr, "%s\n", OPT_ARG(OUTFILE));
			exit(1);
		}
	} else
		outfile = stdout;

	if (HAVE_OPT(INFILE)) {
		infile = fopen(OPT_ARG(INFILE), "rb");
		if (infile == NULL) {
			fprintf(stderr, "%s\n", OPT_ARG(INFILE));
			exit(1);
		}
	} else
		infile = stdin;

	if (ENABLED_OPT(INDER))
		encoding = GNUTLS_X509_FMT_DER;
	else
		encoding = GNUTLS_X509_FMT_PEM;

	if (HAVE_OPT(REQUEST_INFO))
		request_info();
	else if (HAVE_OPT(RESPONSE_INFO))
		response_info();
	else if (HAVE_OPT(GENERATE_REQUEST))
		generate_request(NULL);
	else if (HAVE_OPT(VERIFY_RESPONSE))
		verify_response(NULL);
	else if (HAVE_OPT(ASK))
		ask_server(OPT_ARG(ASK));
	else {
		USAGE(1);
	}

	return 0;
}
Exemplo n.º 7
0
static xmlNodePtr
printHeader( xmlDocPtr pDoc )
{
    tSCC zDef[] = "AutoGen Definitions %s%s;\n";
    char const* pzSfx = ".tpl";

    xmlNodePtr pRootNode = xmlDocGetRootElement( pDoc );
    xmlChar*   pTpl = NULL;
    xmlChar*   pzTpl;

    if (pRootNode == NULL) {
        fprintf( stderr, "Root node not found\n" );
        exit( EXIT_FAILURE );
    }

    if (HAVE_OPT( OVERRIDE_TPL )) {
        if (strchr( OPT_ARG( OVERRIDE_TPL ), '.' ) != NULL)
            pzSfx = "";
        pzTpl = (xmlChar*)(void*)OPT_ARG( OVERRIDE_TPL );
    }
    else {
        pTpl = xmlGetProp( pRootNode, (xmlChar*)(void*)"template" );
        if (pTpl == NULL) {
            fprintf( stderr, "No template was specified.\n" );
            exit( EXIT_FAILURE );
        }

        pzTpl = pTpl;
        if (strchr( (char*)pzTpl, '.' ) != NULL)
            pzSfx = "";
    }

    fprintf( outFp, zDef, pzTpl, pzSfx );
    if (pTpl != NULL)
        free( pTpl );

    if (pDoc->name != NULL)
        fprintf( outFp, "XML-name = '%s';\n", TRIM( pDoc->name, NULL ));

    if (pDoc->version != NULL)
        fprintf( outFp, "XML-version = '%s';\n", TRIM( pDoc->version, NULL ));

    if (pDoc->encoding != NULL)
        fprintf( outFp, "XML-encoding = '%s';\n", TRIM( pDoc->encoding, NULL ));

    if (pDoc->URL != NULL)
        fprintf( outFp, "XML-URL = '%s';\n", TRIM( pDoc->URL, NULL ));

    if (pDoc->standalone)
        fputs( "XML-standalone = true;\n", outFp );

    return pRootNode;
}
Exemplo n.º 8
0
Arquivo: system.c Projeto: Jaharmi/zsh
static int
bin_syserror(char *nam, char **args, Options ops, UNUSED(int func))
{
    int num = 0;
    char *errvar = NULL, *msg, *pfx = "", *str;

    /* variable in which to write error message */
    if (OPT_ISSET(ops, 'e')) {
	errvar = OPT_ARG(ops, 'e');
	if (!isident(errvar)) {
	    zwarnnam(nam, "not an identifier: %s", errvar);
	    return 1;
	}
    }
    /* prefix for error message */
    if (OPT_ISSET(ops, 'p'))
	pfx = OPT_ARG(ops, 'p');

    if (!*args)
	num = errno;
    else {
	char *ptr = *args;
	while (*ptr && idigit(*ptr))
	    ptr++;
	if (!*ptr && ptr > *args)
	    num = atoi(*args);
	else {
	    const char **eptr;
	    for (eptr = sys_errnames; *eptr; eptr++) {
		if (!strcmp(*eptr, *args)) {
		    num = (eptr - sys_errnames) + 1;
		    break;
		}
	    }
	    if (!*eptr)
		return 2;
	}
    }

    msg = strerror(num);
    if (errvar) {
	str = (char *)zalloc(strlen(msg) + strlen(pfx) + 1);
	sprintf(str, "%s%s", pfx, msg);
	setsparam(errvar, str);
    } else {
	fprintf(stderr, "%s%s\n", pfx, msg);
    }

    return 0;
}
Exemplo n.º 9
0
static void
request_info (void)
{
  gnutls_ocsp_req_t req;
  int ret;
  gnutls_datum_t dat;
  size_t size;

  ret = gnutls_ocsp_req_init (&req);
  if (ret < 0)
    error (EXIT_FAILURE, 0, "ocsp_req_init: %s", gnutls_strerror (ret));

  if (HAVE_OPT(LOAD_REQUEST))
    dat.data = (void*)read_binary_file (OPT_ARG(LOAD_REQUEST), &size);
  else
    dat.data = (void*)fread_file (infile, &size);
  if (dat.data == NULL)
    error (EXIT_FAILURE, errno, "reading request");
  dat.size = size;

  ret = gnutls_ocsp_req_import (req, &dat);
  free (dat.data);
  if (ret < 0)
    error (EXIT_FAILURE, 0, "importing request: %s", gnutls_strerror (ret));

  ret = gnutls_ocsp_req_print (req, GNUTLS_OCSP_PRINT_FULL, &dat);
  if (ret != 0)
    error (EXIT_FAILURE, 0, "ocsp_req_print: %s", gnutls_strerror (ret));

  printf ("%.*s", dat.size, dat.data);
  gnutls_free (dat.data);

  gnutls_ocsp_req_deinit (req);
}
Exemplo n.º 10
0
static void verify_response(gnutls_datum_t *nonce)
{
	gnutls_datum_t dat;
	size_t size;
	gnutls_x509_crt_t signer;
	int v;

	if (HAVE_OPT(LOAD_RESPONSE))
		dat.data =
		    (void *) read_binary_file(OPT_ARG(LOAD_RESPONSE),
					      &size);
	else
		dat.data = (void *) fread_file(infile, &size);
	if (dat.data == NULL) {
		fprintf(stderr, "error reading response\n");
		exit(1);
	}
	dat.size = size;

	signer = load_signer();

	v = _verify_response(&dat, nonce, signer);
	if (v && !HAVE_OPT(IGNORE_ERRORS))
		exit(1);
}
Exemplo n.º 11
0
Arquivo: system.c Projeto: phy1729/zsh
static int
bin_sysopen(char *nam, char **args, Options ops, UNUSED(int func))
{
    int read = OPT_ISSET(ops, 'r');
    int write = OPT_ISSET(ops, 'w');
    int append = OPT_ISSET(ops, 'a') ? O_APPEND : 0;
    int flags = O_NOCTTY | append | ((append || write) ?
	(read ? O_RDWR : O_WRONLY) : O_RDONLY);
    char *opt, *ptr, *nextopt, *fdvar;
    int o, fd, explicit = -1;
    mode_t perms = 0666;
#if defined(FD_CLOEXEC) && !defined(O_CLOEXEC)
    int fdflags;
#endif

    if (!OPT_ISSET(ops, 'u')) {
	zwarnnam(nam, "file descriptor not specified");
	return 1;
    }

    /* file descriptor, either 0-9 or a variable name */
    fdvar = OPT_ARG(ops, 'u');
    if (idigit(*fdvar) && !fdvar[1]) {
	explicit = atoi(fdvar);
    } else if (!isident(fdvar)) {
Exemplo n.º 12
0
/*
 * Redirect logging to a file if requested with -l.
 * The ntp.conf logfile directive does not use this code, see
 * config_vars() in ntp_config.c.
 */
void
setup_logfile(
	void
	)
{
	if (HAVE_OPT( LOGFILE )) {
		const char *my_optarg = OPT_ARG( LOGFILE );
		FILE *new_file;

		if(strcmp(my_optarg, "stderr") == 0)
			new_file = stderr;
		else if(strcmp(my_optarg, "stdout") == 0)
			new_file = stdout;
		else
			new_file = fopen(my_optarg, "a");
		if (new_file != NULL) {
			NLOG(NLOG_SYSINFO)
				msyslog(LOG_NOTICE, "logging to file %s", my_optarg);
			if (syslog_file != NULL &&
				fileno(syslog_file) != fileno(new_file))
				(void)fclose(syslog_file);

			syslog_file = new_file;
			syslogit = 0;
		}
		else
			msyslog(LOG_ERR,
				"Cannot open log file %s",
				my_optarg);
	}
}
Exemplo n.º 13
0
static void cmd_parser(int argc, char **argv)
{
	const char *rest = NULL;
	int optct = optionProcess(&gnutls_cli_debugOptions, argc, argv);
	argc -= optct;
	argv += optct;

	if (rest == NULL && argc > 0)
		rest = argv[0];

	if (HAVE_OPT(PORT))
		port = OPT_VALUE_PORT;
	else {
		if (HAVE_OPT(STARTTLS_PROTO))
			port = starttls_proto_to_port(OPT_ARG(STARTTLS_PROTO));
		else
			port = 443;
	}

	if (rest == NULL)
		hostname = "localhost";
	else
		hostname = rest;

	if (HAVE_OPT(DEBUG))
		debug = OPT_VALUE_DEBUG;

	if (HAVE_OPT(VERBOSE))
		verbose++;

}
Exemplo n.º 14
0
// determine - given the servername - the db realm it belongs to.
int bb_cpu_find_realm(trx *t)
{
  int i, server;

  query_server_by_name = NULL;
  for (i=0; i < dblist_cnt; i++) {
    t->probe->db = open_realm(dblist[i].realm, OPT_ARG(DBTYPE), OPT_ARG(DBHOST), OPT_VALUE_DBPORT, OPT_ARG(DBNAME), OPT_ARG(DBUSER), OPT_ARG(DBPASSWD));
    server = realm_server_by_name(dblist[i].realm, t->res->hostname);
    if (server > 1) {
      t->res->server = server;
      t->res->realm = strdup(dblist[i].realm);
      query_server_by_name = dblist[i].srvrbyname;
      break;
    }
  }
  return 1;
}
Exemplo n.º 15
0
Arquivo: system.c Projeto: Jaharmi/zsh
static int
bin_syswrite(char *nam, char **args, Options ops, UNUSED(int func))
{
    int outfd = 1, len, count, totcount;
    char *countvar = NULL;

    /* -o: output file descriptor if not stdout */
    if (OPT_ISSET(ops, 'o')) {
	outfd = getposint(OPT_ARG(ops, 'o'), nam);
	if (outfd < 0)
	    return 1;
    }

    /* -c: variable in which to store count of bytes written */
    if (OPT_ISSET(ops, 'c')) {
	countvar = OPT_ARG(ops, 'c');
	if (!isident(countvar)) {
	    zwarnnam(nam, "not an identifier: %s", countvar);
	    return 1;
	}
    }

    totcount = 0;
    unmetafy(*args, &len);
    while (len) {
	while ((count = write(outfd, *args, len)) < 0) {
	    if (errno != EINTR || errflag || retflag || breaks || contflag)
	    {
		if (countvar)
		    setiparam(countvar, totcount);
		return 2;
	    }
	}
	*args += count;
	totcount += count;
	len -= count;
    }
    if (countvar)
	setiparam(countvar, totcount);

    return 0;
}
Exemplo n.º 16
0
/* Receive raw data */
int
recvdata (
		SOCKET rsock,
		sockaddr_u *sender,
		char *rdata,
		int rdata_length
	 )
{
	struct timeval timeout_tv = { 0 };
	fd_set recv_fd;
	GETSOCKNAME_SOCKLEN_TYPE slen;
	int recvc;

#ifdef DEBUG
	printf("sntp recvdata: Trying to receive data from...\n");
#endif
	// Is the socket ready?
	FD_ZERO(&recv_fd);
	FD_SET(rsock, &recv_fd);
	
	if(ENABLED_OPT(TIMEOUT)) {
		timeout_tv.tv_sec = (int) OPT_ARG(TIMEOUT);
	} else {
		timeout_tv.tv_sec = 15; 
	}
	switch(select(rsock + 1, &recv_fd, 0, 0, &timeout_tv)) {
		case 0:
			if(ENABLED_OPT(NORMALVERBOSE))
				printf("sntp recvdata: select() reached timeout (%u sec), aborting.\n", 
				       (unsigned)timeout_tv.tv_sec);
			return SERVER_UNUSEABLE;

		case -1:
			return SERVER_UNUSEABLE;
		default:
			
			slen = sizeof(sender->sas);
			recvc = recvfrom(rsock, rdata, rdata_length, 0, 
							 &sender->sa, &slen);
#ifdef DEBUG
			if (recvc > 0) {
				printf("Received %d bytes from %s:\n", recvc, stoa(sender));

				pkt_output((struct pkt *) rdata, recvc, stdout);
			} else {
				saved_errno = errno;
				printf("recvfrom error %d (%s)\n", errno, strerror(errno));
				errno = saved_errno;
			}
#endif
	}

	return recvc;
}
Exemplo n.º 17
0
void add_sysstat_info(xmlNodePtr node)
{
  char info[32768];

  if (st.load) {
    if (st.load->min1 >= atof(OPT_ARG(LOADAVG_YELLOW))) { 
      char cmd[1024];
      char buffer[24];
      FILE *in;

      if (st.load->min1 >= atof(OPT_ARG(LOADAVG_YELLOW))) sprintf(buffer, "%d", STAT_YELLOW);
      if (st.load->min1 >= atof(OPT_ARG(LOADAVG_RED))) sprintf(buffer, "%d", STAT_RED);
      xmlSetProp(node, "color", buffer);

      sprintf(cmd, "%s > /tmp/.uw_sysstat.tmp", OPT_ARG(TOP_COMMAND));
      LOG(LOG_INFO, cmd);
      uw_setproctitle("running %s", OPT_ARG(TOP_COMMAND));
      system(cmd);
      in = fopen("/tmp/.uw_sysstat.tmp", "r");
      if (in) {
        signed char *s = info;
        size_t len;

        for (len=0; len < sizeof(info)-1; len++) {
          int c;
          if ((c = fgetc(in)) != EOF) {
            if (c < 0) c = ' ';
            *s++ = c;
          }
        }
        *s = 0;
        fclose(in);
      } else {
        strcpy(info, strerror(errno));
      }
      unlink("/tmp/.uw_sysstat.tmp");
      xmlNewTextChild(node, NULL, "info", info);
    }
  }
}
Exemplo n.º 18
0
int run(void)
{
  dbi_conn conn;

  if (!cache) {
    cache = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, free_probe);
  }
  
  LOG(LOG_INFO, "reading info from database"); 
  uw_setproctitle("reading info from database");
  conn = open_database(OPT_ARG(DBTYPE), OPT_ARG(DBHOST), OPT_ARG(DBPORT), OPT_ARG(DBNAME), 
			OPT_ARG(DBUSER), OPT_ARG(DBPASSWD));
  if (conn) {
    refresh_database(conn);
    close_database(conn);
  }

  if (g_hash_table_size(cache) > 0) {
    LOG(LOG_INFO, "running %d probes", g_hash_table_size(cache));
    uw_setproctitle("running %d probes", g_hash_table_size(cache));
    run_actual_probes(); /* this runs the actual probes */

    LOG(LOG_INFO, "writing results"); 
    uw_setproctitle("writing results");
    write_results();
  }

  return(g_hash_table_size(cache));
}
Exemplo n.º 19
0
/*
** handle_lookup
*/
void
handle_lookup(
	const char *name,
	int flags
	)
{
	struct addrinfo	hints;	/* Local copy is OK */
	struct dns_ctx *ctx;
	char *		name_copy;
	size_t		name_sz;
	size_t		octets;

	TRACE(1, ("handle_lookup(%s,%#x)\n", name, flags));

	ZERO(hints);
	hints.ai_family = ai_fam_pref;
	hints.ai_flags = AI_CANONNAME | Z_AI_NUMERICSERV;
	/*
	** Unless we specify a socktype, we'll get at least two
	** entries for each address: one for TCP and one for
	** UDP. That's not what we want.
	*/
	hints.ai_socktype = SOCK_DGRAM;
	hints.ai_protocol = IPPROTO_UDP;

	name_sz = 1 + strlen(name);
	octets = sizeof(*ctx) + name_sz;	// Space for a ctx and the name
	ctx = emalloc_zero(octets);		// ctx at ctx[0]
	name_copy = (char *)(ctx + 1);		// Put the name at ctx[1]
	memcpy(name_copy, name, name_sz);	// copy the name to ctx[1]
	ctx->name = name_copy;			// point to it...
	ctx->flags = flags;
	ctx->timeout = response_tv;
	ctx->key = NULL;

	/* The following should arguably be passed in... */
	if (ENABLED_OPT(AUTHENTICATION)) {
		ctx->key_id = OPT_VALUE_AUTHENTICATION;
		get_key(ctx->key_id, &ctx->key);
		if (NULL == ctx->key) {
			fprintf(stderr, "%s: Authentication with keyID %d requested, but no matching keyID found in <%s>!\n",
				progname, ctx->key_id, OPT_ARG(KEYFILE));
			exit(1);
		}
	} else {
		ctx->key_id = -1;
	}

	++n_pending_dns;
	getaddrinfo_sometime(name, "123", &hints, 0,
			     &sntp_name_resolved, ctx);
}
Exemplo n.º 20
0
/**
 * \brief Call this to parse AutoOpts arguments for the DLT encoder plugin
 *
 * Was previously part of tcpedit_dlt_init(), but moved into it's own function
 * to allow a full programtic API.  Basically, if you're not using this function
 * you'll need to roll your own!
 * Returns 0 on success, -1 on error
 */
int 
tcpedit_dlt_post_args(tcpedit_t *tcpedit)
{
    tcpeditdlt_t *ctx;
    const char *dst_dlt_name = NULL;
    int rcode;
    
    assert(tcpedit);
    ctx = tcpedit->dlt_ctx;
    assert(ctx);
    
    /* Select the encoder plugin */
    dst_dlt_name = OPT_ARG(DLT) ? OPT_ARG(DLT) : ctx->decoder->name;
    if ((ctx->encoder = tcpedit_dlt_getplugin_byname(ctx, dst_dlt_name)) == NULL) {
        tcpedit_seterr(tcpedit, "No output DLT plugin available for: %s", dst_dlt_name);
        return TCPEDIT_ERROR;
    }
    
    /* Figure out if we're skipping braodcast & multicast */
    if (HAVE_OPT(SKIPL2BROADCAST))
        ctx->skip_broadcast = 1;

    /* init encoder plugin if it's not the decoder plugin */
    if (ctx->encoder->dlt != ctx->decoder->dlt) {
        if ((rcode = ctx->encoder->plugin_init(ctx)) != TCPEDIT_OK) {
            /* plugin should generate the error */
            return TCPEDIT_ERROR;
        }
    }

    /* parse the DLT specific options */
    if ((rcode = tcpedit_dlt_parse_opts(ctx)) != TCPEDIT_OK) {
        /* parser should generate the error */
        return TCPEDIT_ERROR;
    }

    /* we're OK */
    return tcpedit_dlt_post_init(ctx);
} 
Exemplo n.º 21
0
void add_systemp(xmlNodePtr node)
{
  char buffer[24];
  int systemp = 0;

  if (HAVE_OPT(SYSTEMP_COMMAND)) {
    char cmd[1024];
    FILE *in;

    sprintf(cmd, "%s > /tmp/.uw_sysstat.tmp", OPT_ARG(SYSTEMP_COMMAND));
    uw_setproctitle("running %s", OPT_ARG(SYSTEMP_COMMAND));
    system(cmd);
    in = fopen("/tmp/.uw_sysstat.tmp", "r");
    if (in) {
      fscanf(in, "%d", &systemp);
      fclose(in);
    }
    unlink("tmp/.uw_sysstat.tmp");
  }
  sprintf(buffer, "%d", systemp);
  xmlNewChild(node, NULL, "systemp", buffer);
}
Exemplo n.º 22
0
Arquivo: datetime.c Projeto: Lujaw/zsh
static int
bin_strftime(char *nam, char **argv, Options ops, UNUSED(int func))
{
    int bufsize, x;
    char *endptr = NULL, *scalar = NULL, *buffer;
    time_t secs;
    struct tm *t;

    if (OPT_ISSET(ops,'s')) {
	scalar = OPT_ARG(ops, 's');
	if (!isident(scalar)) {
	    zwarnnam(nam, "not an identifier: %s", scalar);
	    return 1;
	}
    }
    if (OPT_ISSET(ops, 'r'))
	return reverse_strftime(nam, argv, scalar, OPT_ISSET(ops, 'q'));

    errno = 0;
    secs = (time_t)strtoul(argv[1], &endptr, 10);
    if (errno != 0) {
	zwarnnam(nam, "%s: %e", argv[1], errno);
	return 1;
    } else if (*endptr != '\0') {
	zwarnnam(nam, "%s: invalid decimal number", argv[1]);
	return 1;
    }

    t = localtime(&secs);
    if (!t) {
	zwarnnam(nam, "%s: unable to convert to time", argv[1]);
	return 1;
    }
    bufsize = strlen(argv[0]) * 8;
    buffer = zalloc(bufsize);

    for (x=0; x < 4; x++) {
        if (ztrftime(buffer, bufsize, argv[0], t) >= 0)
	    break;
	buffer = zrealloc(buffer, bufsize *= 2);
    }

    if (scalar) {
	setsparam(scalar, metafy(buffer, -1, META_DUP));
    } else {
	printf("%s\n", buffer);
    }
    zfree(buffer, bufsize);

    return 0;
}
Exemplo n.º 23
0
/**
 * post AutoGen argument processing
 */
void 
post_args(_U_ int argc, _U_ char *argv[])
{
    char ebuf[PCAP_ERRBUF_SIZE];

#ifdef DEBUG
    if (HAVE_OPT(DBUG))
        debug = OPT_VALUE_DBUG;
#else
    if (HAVE_OPT(DBUG))
        warn("not configured with --enable-debug.  Debugging disabled.");
#endif


#ifdef ENABLE_VERBOSE
    if (HAVE_OPT(VERBOSE))
        options.verbose = 1;

    if (HAVE_OPT(DECODE))
        tcpdump.args = safe_strdup(OPT_ARG(DECODE));
#endif


#ifdef ENABLE_FRAGROUTE
    if (HAVE_OPT(FRAGROUTE))
        options.fragroute_args = safe_strdup(OPT_ARG(FRAGROUTE));

    options.fragroute_dir = FRAGROUTE_DIR_BOTH;
    if (HAVE_OPT(FRAGDIR)) {
        if (strcmp(OPT_ARG(FRAGDIR), "c2s") == 0) {
            options.fragroute_dir = FRAGROUTE_DIR_C2S;
        } else if (strcmp(OPT_ARG(FRAGDIR), "s2c") == 0) {
            options.fragroute_dir = FRAGROUTE_DIR_S2C;
        } else if (strcmp(OPT_ARG(FRAGDIR), "both") == 0) {
            options.fragroute_dir = FRAGROUTE_DIR_BOTH;
        } else {
            errx(-1, "Unknown --fragdir value: %s", OPT_ARG(FRAGDIR));
        }
    }
#endif

    /* open up the input file */
    options.infile = safe_strdup(OPT_ARG(INFILE));
    if ((options.pin = pcap_open_offline(options.infile, ebuf)) == NULL)
        errx(-1, "Unable to open input pcap file: %s", ebuf);

#ifdef HAVE_PCAP_SNAPSHOT
    if (pcap_snapshot(options.pin) < 65535)
        warnx("%s was captured using a snaplen of %d bytes.  This may mean you have truncated packets.",
                options.infile, pcap_snapshot(options.pin));
#endif

}
Exemplo n.º 24
0
Arquivo: files.c Projeto: AMDmi3/zsh
static int
bin_mkdir(char *nam, char **args, Options ops, UNUSED(int func))
{
    mode_t oumask = umask(0);
    mode_t mode = 0777 & ~oumask;
    int err = 0;

    umask(oumask);
    if(OPT_ISSET(ops,'m')) {
	char *str = OPT_ARG(ops,'m'), *ptr;

	mode = zstrtol(str, &ptr, 8);
	if(!*str || *ptr) {
	    zwarnnam(nam, "invalid mode `%s'", str);
	    return 1;
	}
    }
    for(; *args; args++) {
	char *ptr = strchr(*args, 0);

	while(ptr > *args + (**args == '/') && *--ptr == '/')
	    *ptr = 0;
	if(OPT_ISSET(ops,'p')) {
	    char *ptr = *args;

	    for(;;) {
		while(*ptr == '/')
		    ptr++;
		while(*ptr && *ptr != '/')
		    ptr++;
		if(!*ptr) {
		    err |= domkdir(nam, *args, mode, 1);
		    break;
		} else {
		    int e;

		    *ptr = 0;
		    e = domkdir(nam, *args, mode | 0300, 1);
		    if(e) {
			err = 1;
			break;
		    }
		    *ptr = '/';
		}
	    }
	} else
	    err |= domkdir(nam, *args, mode, 0);
    }
    return err;
}
Exemplo n.º 25
0
static gnutls_x509_crt_t load_cert(void)
{
	gnutls_x509_crt_t crt;
	int ret;
	gnutls_datum_t dat;
	size_t size;

	if (!HAVE_OPT(LOAD_CERT)) {
		fprintf(stderr, "missing --load-cert\n");
		exit(1);
	}

	ret = gnutls_x509_crt_init(&crt);
	if (ret < 0) {
		fprintf(stderr, "crt_init: %s\n", gnutls_strerror(ret));
		exit(1);
	}

	dat.data = (void *) read_binary_file(OPT_ARG(LOAD_CERT), &size);
	dat.size = size;

	if (!dat.data) {
		fprintf(stderr, "reading --load-cert: %s\n",
			OPT_ARG(LOAD_CERT));
		exit(1);
	}

	ret = gnutls_x509_crt_import(crt, &dat, encoding);
	free(dat.data);
	if (ret < 0) {
		fprintf(stderr, "importing --load-cert: %s: %s\n",
			OPT_ARG(LOAD_CERT), gnutls_strerror(ret));
		exit(1);
	}

	return crt;
}
Exemplo n.º 26
0
void write_results(void)
{
  int ct  = STACKCT_OPT(OUTPUT);
  char **output = (char **) &STACKLST_OPT(OUTPUT);
  int i;
  xmlDocPtr doc;

  doc = UpwatchXmlDoc("result", NULL);

  g_hash_table_foreach(cache, write_probe, doc);
  xmlSetDocCompressMode(doc, OPT_VALUE_COMPRESS);
  for (i=0; i < ct; i++) {
    spool_result(OPT_ARG(SPOOLDIR), output[i], doc, NULL);
  }
  xmlFreeDoc(doc);
}
Exemplo n.º 27
0
static void
verify_response (void)
{
  gnutls_datum_t dat;
  size_t size;

  if (HAVE_OPT(LOAD_RESPONSE))
    dat.data = (void*)read_binary_file (OPT_ARG(LOAD_RESPONSE), &size);
  else
    dat.data = (void*)fread_file (infile, &size);
  if (dat.data == NULL)
    error (EXIT_FAILURE, errno, "reading response");
  dat.size = size;
  
  _verify_response(&dat);
}
Exemplo n.º 28
0
static FILE*
open_ag_file(char ** pzBase)
{
    switch (WHICH_IDX_AUTOGEN) {
    case INDEX_OPT_OUTPUT:
    {
        static char const zFileFmt[] = " *      %s\n";
        FILE*  fp;

        if (*pzBase != NULL)
            free(*pzBase);

        if (strcmp(OPT_ARG(OUTPUT), "-") == 0)
            return stdout;

        unlink(OPT_ARG(OUTPUT));
        fp = fopen(OPT_ARG(OUTPUT), "w" FOPEN_BINARY_FLAG);
        fprintf(fp, zDne, OPT_ARG(OUTPUT));

        if (HAVE_OPT(INPUT)) {
            int    ct  = STACKCT_OPT(INPUT);
            char const ** ppz = STACKLST_OPT(INPUT);
            do  {
                fprintf(fp, zFileFmt, *ppz++);
            } while (--ct > 0);
        }

        fputs(" */\n", fp);
        return fp;
    }

    case INDEX_OPT_AUTOGEN:
        if (! ENABLED_OPT(AUTOGEN)) {
            if (*pzBase != NULL)
                free(*pzBase);

            return stdout;
        }

        if (  ( OPT_ARG(AUTOGEN) != NULL)
              && (*OPT_ARG(AUTOGEN) != NUL ))
            pzAutogen = OPT_ARG(AUTOGEN);

        break;
    }

    return NULL;
}
Exemplo n.º 29
0
static void *read_queue(void *data)
{
  struct q_info *q = (struct q_info *)data;
extern int forever;
static char path[PATH_MAX];
  G_CONST_RETURN gchar *filename;
  GDir *dir;
 
  q->fatal = 0;
  //sprintf(path, "%s/%s/new", OPT_ARG(SPOOLDIR), q->name);
  strcpy(path, OPT_ARG(SPOOLDIR));
  strcat(path, "/");
  strcat(path, q->name);
  strcat(path, "/new");
  if (debug > 3) { LOG(LOG_DEBUG, "reading queue %s", path); }
  dir = g_dir_open (path, 0, NULL);
  while ((filename = g_dir_read_name(dir)) != NULL && !q->fatal && forever) {
    char buffer[PATH_MAX];
    struct thr_data *td;
 
    sprintf(buffer, "%s/%s", path, filename);
    td = g_malloc0(sizeof(struct thr_data));
    td->q = q;
    td->filename = strdup(buffer);
#ifdef USE_ST
    if (st_thread_create(push, td, 0, 0) == NULL) { 
      LOG(LOG_WARNING, "couldn't create thread");
      st_sleep(1);
    } else {
      q->thread_count++;
      thread_count++;
    }
    while (q->thread_count >= q->maxthreads) {
      st_usleep(10000); /* 10 ms */
    }
#else
    push(td);
#endif
  }
  g_dir_close(dir);
#ifdef USE_ST
  thread_count--;
#endif
  return NULL;
}
Exemplo n.º 30
0
static void request_info(void)
{
	gnutls_ocsp_req_t req;
	int ret;
	gnutls_datum_t dat;
	size_t size;

	ret = gnutls_ocsp_req_init(&req);
	if (ret < 0) {
		fprintf(stderr, "ocsp_req_init: %s\n", gnutls_strerror(ret));
		exit(1);
	}

	if (HAVE_OPT(LOAD_REQUEST))
		dat.data =
		    (void *) read_binary_file(OPT_ARG(LOAD_REQUEST),
					      &size);
	else
		dat.data = (void *) fread_file(infile, &size);
	if (dat.data == NULL) {
		fprintf(stderr, "error reading request\n");
		exit(1);
	}
	dat.size = size;

	ret = gnutls_ocsp_req_import(req, &dat);
	free(dat.data);
	if (ret < 0) {
		fprintf(stderr, "error importing request: %s\n",
			gnutls_strerror(ret));
		exit(1);
	}

	ret = gnutls_ocsp_req_print(req, GNUTLS_OCSP_PRINT_FULL, &dat);
	if (ret != 0) {
		fprintf(stderr, "ocsp_req_print: %s\n",
			gnutls_strerror(ret));
		exit(1);
	}

	printf("%.*s", dat.size, dat.data);
	gnutls_free(dat.data);

	gnutls_ocsp_req_deinit(req);
}