Пример #1
0
void *agent (void *data) {
  struct agent_args *args = (struct agent_args*) data;
  struct mailbox *inbox = args->inbox;
  bool block = true;
  bool stop = false;
  while (!stop && !panic) {
    struct message *mail = get_mail(inbox, block);
    if (mail != NULL && mail->type == STOP_MESSAGE_TYPE) {
      stop = true;
    } else {
      // maybe `get_mail' generated some panic
      if (!panic)
        block = args->handler(mail);
    }
    if (mail != NULL) {
      if (mail->data != NULL) {
        free(mail->data);
      }
      free(mail);
    }
  }

  struct message *stop_m = get_stop_message();
  if (stop_m != NULL) {
    args->handler(stop_m);
    free(stop_m);
  }
  free(args);
  return NULL;
}
Пример #2
0
void parse_config()
{
	FILE *f = NULL;

	fprintf(stderr,"Reading configuration file: \"%s\" ...\n",config_path);
	
	if( (f=fopen (config_path, "r")) == NULL )
	{
		perror("fopen");
		exit(1);
	}

	LIBXML_TEST_VERSION;

	/* create a parser context */
	ctxt = xmlNewParserCtxt();
	if (ctxt == NULL)
	{
		fprintf(stderr, "Failed to allocate parser context\n");
		fclose(f);
		return;
	}
	/* parse the file, activating the DTD validation option */
	doc = xmlCtxtReadFile(ctxt, config_path, NULL, XML_PARSE_DTDVALID);
	/* check if parsing suceeded */
	if (doc == NULL)
	{
		fprintf(stderr, "Failed to parse %s\n", config_path);
	}
	else
	{
		/* check if validation suceeded */
		if (ctxt->valid == 0)
			fprintf(stderr, "Failed to validate %s\n", config_path);
		/* free up the resulting document */
		else
		{
			xmlXPathInit();
			xpctxt= xmlXPathNewContext(doc);
		}
	}

	autoconf();
	get_mail();
	init_syslog();
	parse_routers();
	parse_actions();
#ifdef _COUNTERMEASURES_
        parse_countermeasures();
#endif
	free_xml();
	fclose(f);
	fprintf(stderr,"    Done.\n");
}
Пример #3
0
bool user_handler::send_mail(const std::string& to_user,
		const std::string& /*subject*/, const std::string& /*message*/) {

	//If this user is registered at all
	if(!user_exists(to_user)) {
		throw error("Could not send email. No user with the name '" + to_user + "' exists.");
	}

	// If this user did not provide an email
	if(get_mail(to_user) == "") {
		throw error("Could not send email. The email address of the user '" + to_user + "' is empty.");
	}

	throw user_handler::error("This server is configured not to send email.");
}
Пример #4
0
int
main()
{
	int i;
	FILE *fp;
	if (fork())
		exit(0);
	chdir(MY_BBS_HOME);
	for (i = 0; i <= getdtablesize(); i++)
		close(i);
	for (i = 1; i <= NSIG; i++)
		signal(i, SIG_IGN);
	signal(SIGALRM, SIG_DFL);
	last = time(0) - 86400;	//首次运行的缺省值: 1天以内的文章。
	fp = fopen("etc/bbsinnd.last", "r");
	if (fp) {
		fscanf(fp, "%d", &last);
		fclose(fp);
	}
	while (1) {
		int r;
		char host[80], oboard[80], iboard[80];
		for (i = 0; iconf[i] != 0; i++) {
			r = sscanf(iconf[i], "%s %s %s", host, oboard, iboard);
			if (r < 3)
				continue;
			if (fork() > 0) {
				alarm(900);
				get_mail(host, oboard, iboard);
				exit(0);
			}
			sleep(3);
		}
		last = time(0);
		fp = fopen("etc/bbsinnd.last", "w");
		fprintf(fp, "%d\n", last);
		fclose(fp);
		sleep(1000);
	}
}
Пример #5
0
int
main (int argc, char *argv[])
{
  struct stats s, s0;
  int print = 0;

  FILE *fp = fopen(STATS_FILE, "rb");
  if (fp != NULL)
    {
      fread(&s0, sizeof(struct stats), 1, fp);
      fclose(fp);
      print = 1;
    }

  get_times(&s);
  get_temp(&s);
  get_mail(&s);
  get_cputime(&s);
  get_power(&s);
  get_mem(&s);
  get_txrx(&s);

  if (print)
    {
      int i;
      double temp = 1e-3*s.temp;
      double charge = 100*s.charge_now/s.charge_full;
      double tx = (s.tx-s0.tx)/(s.t-s0.t);
      double rx = (s.rx-s0.rx)/(s.t-s0.t);
      double mem = s.mem*9.5367431640625e-07;
      double cpu_pct[MAX_CPUS];
      for (i=0; i < s.n_cpus; i++)
        {
          double idle = s.cpu_idle[i] - s0.cpu_idle[i];
          double total = s.cpu_total[i] - s0.cpu_total[i];
          cpu_pct[i] = 1-idle/total;
        }

      fputs(" [", stdout);
      begin_color(color_bar);
      fputs(th_spc, stdout);
      for (i=0; i < s.n_cpus; i++)
        {
          print_bar(cpu_pct[i]);
          fputs(th_spc, stdout);
        }
      end_color();
      fputc(']', stdout);

      begin_color (color_div);
      fputs(spc, stdout);
      fputs(divider, stdout);
      end_color();

      begin_color_coded (temp, LO_TEMP, HI_TEMP);
      num_print (temp, 3, degc);
      end_color();

      begin_color (color_div);
      fputs(spc, stdout);
      fputs(divider, stdout);
      fputs(spc, stdout);
      end_color();

      begin_color_coded (mem, LO_MEM, HI_MEM);
      num_print (mem, 4, "MB");
      end_color();

      begin_color (color_div);
      fputs(spc, stdout);
      fputs(divider, stdout);
      fputs(spc, stdout);
      end_color();

      begin_color (s.ac_connected ? "cyan" : "red");
      fputs(s.ac_connected ? acon : acoff, stdout);
      fputc(' ', stdout);
      end_color();
      begin_color_coded (100-charge, LO_CHARGE, HI_CHARGE);
      num_print (charge, 3, "%");
      end_color();

      begin_color (color_div);
      fputs(spc, stdout);
      fputs(divider, stdout);
      end_color();

      begin_color_coded (tx, LO_RATE, HI_RATE);
      num_print (tx, 0, "B/s  ");
      end_color();
      begin_color (color_up);
      fputs(up, stdout);
      end_color();
      begin_color_coded (rx, LO_RATE, HI_RATE);
      fputs(spc, stdout);
      num_print (rx, 0, "B/s  ");
      end_color();
      begin_color (color_down);
      fputs(down, stdout);
      end_color();

      fputs(spc, stdout);
      begin_color (color_div);
      fputs(divider, stdout);
      fputs(spc, stdout);
      end_color();

      if (s.gmail)
        {
          begin_color (color_mail);
          printf ("%2d/g", s.gmail);
          end_color();
        }
          
      if (s.uiucmail)
        {
          begin_color (color_mail);
          printf ("%2d/u", s.uiucmail);
          end_color();
        }

      if (s.uiucmail || s.gmail)
        {
          fputs(spc, stdout);
          begin_color (color_div);
          fputs(divider, stdout);
          fputs(spc, stdout);
          end_color();
        }
      
      begin_color (color_date);
      fputs(s.date, stdout);
      end_color();

      fputs(spc, stdout);
      begin_color (color_div);
      fputs(divider, stdout);
      end_color();
    }

  fp = fopen(STATS_FILE, "wb");
  fwrite(&s, sizeof(struct stats), 1, fp);
  fclose(fp);

  return 0;
}
Пример #6
0
/**
 * compare attribute to LDAP in case of LDAP_INAPPROPRIATE_MATCHING
 *
 * \param ld AddressBook resource
 * \param server Reference to server
 * \param dn dn for the entry
 * \param attr Attribute
 * \param value New value
 * \return int, return will be LDAP_MOD_ADD, LDAP_MOD_REPLACE, or LDAP_MOD_DELETE
 */
int ldapsvr_compare_manual_attr(LDAP *ld, LdapServer *server, gchar *dn, char *attr, char *value) {
	LDAPMessage *res, *e = NULL;
	BerElement *ber;
	struct berval **vals;
	int rc;
	LdapControl *ctl;
	gchar *filter;
	gchar *attribute;
	int retVal = -2, i;
	AttrKeyValue *mail;

	cm_return_val_if_fail(ld != NULL || server != NULL || attr != NULL, -1);
	ctl = server->control;
	mail = get_mail(dn);
	if (! mail)
		return -2;
	filter = g_strdup_printf("(&(mail=%s)(%s=*))", mail->value, attr);
	attrkeyvalue_free(mail);
	if (ctl) {

		rc = ldap_search_ext_s(ld, ctl->baseDN, LDAP_SCOPE_ONELEVEL, filter, NULL, 0, NULL, NULL, NULL, 0, &res);

		if (rc) {
			g_printerr("ldap_search for attr=%s\" failed[0x%x]: %s\n",attr, rc, ldaputil_get_error(ld));
			retVal = -2;
		}
		else {
			e = ldap_first_entry(ld, res);
			/* entry has this attribute */
			if (e) {
				attribute = ldap_first_attribute( ld, e, &ber );
				if (attribute) {
					if (value) {
						if( ( vals = ldap_get_values_len( ld, e, attr ) ) != NULL ) {
							for( i = 0; vals[i] != NULL; i++ ) {
								debug_print("Compare: %s=%s\n", attr, vals[i]->bv_val);
								/* attribute has same value */
								if (strcmp(vals[i]->bv_val, value) == 0)
									retVal = -1;
								/* attribute has new value */
								else
									retVal = LDAP_MOD_REPLACE;
							}
						}
						ldap_value_free_len(vals);
					}
					else
						retVal = LDAP_MOD_DELETE;
				}
				if( ber != NULL ) {
					ber_free( ber, 0 );
				}
				ldap_memfree(attribute);
			}
			/* entry does not have this attribute */
			else {
				/* Only add if this is a real attribute */
				if (value)
					retVal = LDAP_MOD_ADD;
				/* This is dummy value used to avoid ldap_compare error */
				else
					retVal = -1;
			}
		}
	}
	else
		retVal = -2;
	g_free(filter);
	return retVal;
}