Exemplo n.º 1
0
static int
auth_conv(int num_msg, const struct pam_message **msg,
	  struct pam_response **resp, void *appdata)
{
	int i;
	cred_t *cred = (cred_t *) appdata;
	struct pam_response *reply =
			malloc(sizeof(struct pam_response) * num_msg);

	for (i = 0; i < num_msg; i++) {
		switch (msg[i]->msg_style) {
		case PAM_PROMPT_ECHO_ON:	/* assume want user name */
			reply[i].resp_retcode = PAM_SUCCESS;
			reply[i].resp = COPY_STRING(cred->uname);
			/* PAM frees resp. */
			break;
		case PAM_PROMPT_ECHO_OFF:	/* assume want password */
			reply[i].resp_retcode = PAM_SUCCESS;
			reply[i].resp = COPY_STRING(cred->pass);
			/* PAM frees resp. */
			break;
		case PAM_TEXT_INFO:
		case PAM_ERROR_MSG:
			reply[i].resp_retcode = PAM_SUCCESS;
			reply[i].resp = NULL;
			break;
		default:			/* unknown message style */
			free(reply);
			return PAM_CONV_ERR;
		}
	}

	*resp = reply;
	return PAM_SUCCESS;
}
Exemplo n.º 2
0
void sprint_hw_oq_drops(router_state *rs, char **buf, unsigned int *len) {
	char *buffer = calloc(2*HW_OQ_DROPS_LEN + 1, sizeof(char));
	unsigned int total_len = 0;

	if (rs->is_netfpga) {
		char* port_names[8] = {"Q0", "Q1", "Q2", "Q3", "Q4", "Q5", "Q6", "Q7"};
		char line[HW_OQ_DROPS_LEN];
		bzero(line, HW_OQ_DROPS_LEN);

		snprintf(line, HW_OQ_DROPS_LEN, "%4s %10u %4s %10u %4s %10u %4s %10u\n",
			port_names[0], get_oq_num_pkts_dropped(&rs->netfpga, 0),
			port_names[1], get_oq_num_pkts_dropped(&rs->netfpga, 1),
			port_names[2], get_oq_num_pkts_dropped(&rs->netfpga, 2),
			port_names[3], get_oq_num_pkts_dropped(&rs->netfpga, 3));
		COPY_STRING(buffer, total_len, line);

		snprintf(line, HW_OQ_DROPS_LEN, "%4s %10u %4s %10u %4s %10u %4s %10u\n",
			port_names[4], get_oq_num_pkts_dropped(&rs->netfpga, 4),
			port_names[5], get_oq_num_pkts_dropped(&rs->netfpga, 5),
			port_names[6], get_oq_num_pkts_dropped(&rs->netfpga, 6),
			port_names[7], get_oq_num_pkts_dropped(&rs->netfpga, 7));
		COPY_STRING(buffer, total_len, line);
	}

	*buf = buffer;
	*len = total_len;
}
Exemplo n.º 3
0
void sprint_hw_local_ip_filter(router_state *rs, char **buf, unsigned int *len) {
	char *buffer = calloc((1+ROUTER_OP_LUT_DST_IP_FILTER_TABLE_DEPTH)*HW_LOCAL_IP_FILTER_LEN + 1, sizeof(char));
	unsigned int total_len = 0;

	if (rs->is_netfpga) {
		int i;
		COPY_STRING(buffer, total_len, HW_LOCAL_IP_FILTER_HEADER);
		char line[HW_LOCAL_IP_FILTER_LEN];
		bzero(line, HW_LOCAL_IP_FILTER_LEN);
		char ip_str[16];

		struct in_addr ip;
		for (i = 0; i < ROUTER_OP_LUT_DST_IP_FILTER_TABLE_DEPTH; ++i) {
			writeReg(&rs->netfpga, ROUTER_OP_LUT_DST_IP_FILTER_TABLE_RD_ADDR_REG, i);
			readReg(rs->netfpga_regs, ROUTER_OP_LUT_DST_IP_FILTER_TABLE_ENTRY_IP_REG, &ip.s_addr);
			ip.s_addr = htonl(ip.s_addr);
			inet_ntop(AF_INET, &ip, ip_str, 16);
			snprintf(line, HW_LOCAL_IP_FILTER_LEN, "%3u %15s\n", i, ip_str);
			COPY_STRING(buffer, total_len, line);
		}
	}

	*buf = buffer;
  *len = total_len;
}
Exemplo n.º 4
0
void http_request_header_add(const http_request_t * const request, char * name, char * value)
{

  char * name_copy, * value_copy;
  size_t name_length = strlen(name);
  size_t value_length = strlen(value);
  COPY_STRING(name_copy, name, name_length);
  COPY_STRING(value_copy, value, value_length);

  header_list_push(request->headers, name_copy, name_length, true, value_copy, value_length, true);
}
Exemplo n.º 5
0
void sprint_hw_nat_table(router_state *rs, char **buf, unsigned int *len) {

        struct in_addr ext_ip;
        char ext_ip_str[16];
        uint32_t ext_port;
        uint32_t ext_sum;
        struct in_addr int_ip;
        char int_ip_str[16];
        uint32_t int_port;
        uint32_t int_sum;
        uint32_t hits;
        unsigned int i;

        char *buffer = (char *)calloc(strlen(HW_NAT_COL) + 16*HW_NAT_ENTRY_TO_STRING_LEN + 1, sizeof(uint8_t));
        unsigned int total_len = 0;

        COPY_STRING(buffer, total_len, HW_NAT_COL);
        for(i=0; i<16; i++) {

                /* write the row number */
                //writeReg(&(rs->netfpga), ROUTER_OP_LUT_NAT_RD_ADDR_REG, i);

                /* read the 7-tuple (e-ip, e-port, e-sum, i-ip, i-port, i-sum, hits) from hw registers */
                //readReg(&(rs->netfpga), ROUTER_OP_LUT_NAT_INT_IP_REG, &int_ip.s_addr);
                //readReg(&(rs->netfpga), ROUTER_OP_LUT_NAT_INT_PORT_REG, &int_port);
                //readReg(&(rs->netfpga), ROUTER_OP_LUT_NAT_INT_CHKSUM_REG, &int_sum);
                //readReg(&(rs->netfpga), ROUTER_OP_LUT_NAT_EXT_IP_REG, &ext_ip.s_addr);
                //readReg(&(rs->netfpga), ROUTER_OP_LUT_NAT_EXT_PORT_REG, &ext_port);
                //readReg(&(rs->netfpga), ROUTER_OP_LUT_NAT_EXT_CHKSUM_REG, &ext_sum);
                //readReg(&(rs->netfpga), ROUTER_OP_LUT_NAT_HIT_REG, &hits);

								int_ip.s_addr = htonl(int_ip.s_addr);
								ext_ip.s_addr = htonl(ext_ip.s_addr);

                char line[HW_NAT_ENTRY_TO_STRING_LEN];
                bzero(line, HW_NAT_ENTRY_TO_STRING_LEN);
                snprintf(line, HW_NAT_ENTRY_TO_STRING_LEN, "%-3i %-15s %5i 0x%04X %-15s %5i 0x%04X %7u\n",
                        i,
                        inet_ntop(AF_INET, &ext_ip, ext_ip_str, 16),
                        ext_port,
                        ext_sum,
                        inet_ntop(AF_INET, &int_ip, int_ip_str, 16),
                        int_port,
                        int_sum,
                        hits);

                COPY_STRING(buffer, total_len, line);
        }

        *buf = buffer;
        *len = total_len;
}
Exemplo n.º 6
0
void sprint_hw_arp_cache(router_state *rs, char **buf, unsigned int *len) {

	uint8_t mac[6];
	struct in_addr gw;
	bzero(&gw, sizeof(struct in_addr));
	char gw_str[16];
	bzero(gw_str, 16);
	unsigned int mac_lo = 0;
	unsigned int mac_hi = 0;
	int i;

	char *buffer = calloc(strlen(HW_ARP_CACHE_COL) + ROUTER_OP_LUT_ARP_TABLE_DEPTH*HW_ARP_CACHE_ENTRY_TO_STRING_LEN, sizeof(char));
	unsigned int total_len = 0;

	COPY_STRING(buffer, total_len, HW_ARP_CACHE_COL);

	for(i=0; i < ROUTER_OP_LUT_ARP_TABLE_DEPTH; i++) {

		/* write the row number */
		writeReg(rs->netfpga_regs, ROUTER_OP_LUT_ARP_TABLE_RD_ADDR_REG, i);

		/* read the four-touple (mac hi, mac lo, gw, num of misses) */
		readReg(rs->netfpga_regs, ROUTER_OP_LUT_ARP_TABLE_ENTRY_MAC_HI_REG, &mac_hi);
		readReg(rs->netfpga_regs, ROUTER_OP_LUT_ARP_TABLE_ENTRY_MAC_LO_REG, &mac_lo);
		readReg(rs->netfpga_regs, ROUTER_OP_LUT_ARP_TABLE_ENTRY_NEXT_HOP_IP_REG, &gw.s_addr);
		gw.s_addr = htonl(gw.s_addr);

		mac[5] = (uint8_t)(mac_hi >> 8);
		mac[4] = (uint8_t)mac_hi;
		mac[3] = (uint8_t)(mac_lo >> 24);
		mac[2] = (uint8_t)(mac_lo >> 16);
		mac[1] = (uint8_t)(mac_lo >> 8);
		mac[0] = (uint8_t)mac_lo;


		char line[HW_ARP_CACHE_ENTRY_TO_STRING_LEN];
		bzero(line, HW_ARP_CACHE_ENTRY_TO_STRING_LEN);
		snprintf(line, HW_ARP_CACHE_ENTRY_TO_STRING_LEN, "%02X:%02X:%02X:%02X:%02X:%02X\t%-15s\n",
			mac[5], mac[4], mac[3], mac[2], mac[1], mac[0],
			inet_ntop(AF_INET, &gw, gw_str, 16) );

		COPY_STRING(buffer, total_len, line);

		mac_hi = 0;
		mac_lo = 0;
		gw.s_addr = 0;
	}

	*buf = buffer;
	*len = total_len;

}
Exemplo n.º 7
0
/** Dialogue between RADIUS and PAM modules
 *
 * Uses PAM's appdata_ptr so it's thread safe, and doesn't
 * have any nasty static variables hanging around.
 */
static int pam_conv(int num_msg, struct pam_message const **msg, struct pam_response **resp, void *appdata_ptr)
{
	int count;
	struct pam_response *reply;
	REQUEST *request;
	rlm_pam_data_t *pam_config = (rlm_pam_data_t *) appdata_ptr;

	request = pam_config->request;

/* strdup(NULL) doesn't work on some platforms */
#define COPY_STRING(s) ((s) ? strdup(s) : NULL)

	reply = rad_malloc(num_msg * sizeof(struct pam_response));
	memset(reply, 0, num_msg * sizeof(struct pam_response));
	for (count = 0; count < num_msg; count++) {
		switch (msg[count]->msg_style) {
		case PAM_PROMPT_ECHO_ON:
			reply[count].resp_retcode = PAM_SUCCESS;
			reply[count].resp = COPY_STRING(pam_config->username);
			break;

		case PAM_PROMPT_ECHO_OFF:
			reply[count].resp_retcode = PAM_SUCCESS;
			reply[count].resp = COPY_STRING(pam_config->password);
			break;

		case PAM_TEXT_INFO:
			RDEBUG2("%s", msg[count]->msg);
			break;

		case PAM_ERROR_MSG:
		default:
			RERROR("PAM conversation failed");
			/* Must be an error of some sort... */
			for (count = 0; count < num_msg; count++) {
				if (msg[count]->msg_style == PAM_ERROR_MSG) RERROR("%s", msg[count]->msg);
				if (reply[count].resp) {
	  				/* could be a password, let's be sanitary */
	  				memset(reply[count].resp, 0, strlen(reply[count].resp));
	  				free(reply[count].resp);
				}
			}
			free(reply);
			pam_config->error = true;
			return PAM_CONV_ERR;
		}
	}
	*resp = reply;
	/* PAM frees reply (including reply[].resp) */

	return PAM_SUCCESS;
}
Exemplo n.º 8
0
void sprint_hw_rtable(router_state *rs, char **buffer, unsigned int *len) {

	struct in_addr ip;
	struct in_addr mask;
	struct in_addr gw;
	char ip_str[16];
	char mask_str[16];
	char gw_str[16];
	unsigned int port;
	char iface[IF_LEN];
	int i;

	char *buf = (char *)calloc(strlen(HW_RTABLE_COL) + ROUTER_OP_LUT_ROUTE_TABLE_DEPTH*HW_RTABLE_ENTRY_TO_STRING_LEN, sizeof(uint8_t));
	unsigned int total_len = 0;

	COPY_STRING(buf, total_len, HW_RTABLE_COL);
	for(i=0; i < ROUTER_OP_LUT_ROUTE_TABLE_DEPTH; i++) {
		bzero(&ip, sizeof(struct in_addr));
		bzero(&mask, sizeof(struct in_addr));
		bzero(&gw, sizeof(struct in_addr));

		/* write the row number */
		writeReg(rs->netfpga_regs, ROUTER_OP_LUT_ROUTE_TABLE_RD_ADDR_REG, i);

		/* read the four-tuple (ip, gw, mask, iface) from the hw registers */
		readReg(rs->netfpga_regs, ROUTER_OP_LUT_ROUTE_TABLE_ENTRY_IP_REG, &ip.s_addr);
		readReg(rs->netfpga_regs, ROUTER_OP_LUT_ROUTE_TABLE_ENTRY_MASK_REG, &mask.s_addr);
		readReg(rs->netfpga_regs, ROUTER_OP_LUT_ROUTE_TABLE_ENTRY_NEXT_HOP_IP_REG, &gw.s_addr);
		readReg(rs->netfpga_regs, ROUTER_OP_LUT_ROUTE_TABLE_ENTRY_OUTPUT_PORT_REG, &port);

		ip.s_addr = ntohl(ip.s_addr);
		mask.s_addr = ntohl(mask.s_addr);
		gw.s_addr = ntohl(gw.s_addr);

		getIfaceFromOneHotPortNumber(iface, IF_LEN, port);

		char line[HW_RTABLE_ENTRY_TO_STRING_LEN];
		bzero(line, HW_RTABLE_ENTRY_TO_STRING_LEN);
		snprintf(line, HW_RTABLE_ENTRY_TO_STRING_LEN, "%-5i%-20s%-20s%-20s%-20s\n",
			i,
			inet_ntop(AF_INET, &ip, ip_str, 16),
			inet_ntop(AF_INET, &gw, gw_str, 16),
			inet_ntop(AF_INET, &mask, mask_str, 16),
			iface);
		COPY_STRING(buf, total_len, line);
	}

	*buffer = buf;
	*len = total_len;
}
Exemplo n.º 9
0
/* NOT THREAD SAFE */
void sprint_if_list(router_state *rs, char **buf, int *len)
{
	assert(rs);
	assert(buf);
	assert(len);

	node *iface_walker = 0;
	iface_entry *iface = 0;
	struct in_addr ip;
	struct in_addr mask;
	char *buffer = 0;
	int total_len = 0;

	char ip_str[16];
	char mask_str[16];

	buffer = calloc(strlen(IFACE_COL) + IFACE_ENTRY_TO_STRING_LEN * node_length(rs->if_list), sizeof(char));
	COPY_STRING(buffer, total_len, IFACE_COL);

	iface_walker = rs->if_list;
	while(iface_walker)
	{
		iface = (iface_entry *)iface_walker->data;

		char if_name[IFACE_MAX_IFACE_LEN+1];
		snprintf(if_name, IFACE_MAX_IFACE_LEN, "%s", iface->name);
		if_name[IFACE_MAX_IFACE_LEN] = '\0';

		ip.s_addr = iface->ip;
		mask.s_addr = iface->mask;

		char line[IFACE_ENTRY_TO_STRING_LEN];
		snprintf(line, IFACE_ENTRY_TO_STRING_LEN, "%-21s %02X:%02X:%02X:%02X:%02X:%02X %-15s %-15s %-5i %-2s %-2s\n",
			if_name, (unsigned char)iface->addr[0], (unsigned char)iface->addr[1], (unsigned char)iface->addr[2],
			(unsigned char)iface->addr[3], (unsigned char)iface->addr[4], (unsigned char)iface->addr[5],
			inet_ntop(AF_INET, &ip, ip_str, 16), inet_ntop(AF_INET, &mask, mask_str, 16), iface->speed,
			(iface->is_active == 1) ? "Y" : "N",
			(iface->is_wan == 1) ? "Y" : "N");


		COPY_STRING(buffer, total_len, line);

		iface_walker = iface_walker->next;
	}

	*buf = buffer;
	*len = total_len;

}
Exemplo n.º 10
0
/* NOT THREAD SAFE */
void sprint_arp_cache(router_state *rs, char **buf, int *len)
{
	assert(rs);
	assert(buf);
	assert(len);

	node *arp_walker = 0;
	arp_cache_entry *arp_entry = 0;
	time_t now;
	double diff;
	char *buffer = 0;
	int total_len = 0;


	buffer = calloc(strlen(ARP_CACHE_COL) + ARP_CACHE_ENTRY_TO_STRING_LEN * node_length(rs->arp_cache), sizeof(char));
	COPY_STRING(buffer, total_len, ARP_CACHE_COL);

	arp_walker = rs->arp_cache;
	while(arp_walker)
	{
		arp_entry = (arp_cache_entry *)arp_walker->data;

		char addr[INET_ADDRSTRLEN];
		inet_ntop(AF_INET, &(arp_entry->ip), addr, INET_ADDRSTRLEN);

		char ttl[47];
		if (arp_entry->is_static == 0) {
			time(&now);
			diff = difftime(now, arp_entry->TTL);
			snprintf(ttl, 47, "%f", rs->arp_ttl - diff);
		} else {
			snprintf(ttl, 47, "%s", "static");
		}

		char line[ARP_CACHE_ENTRY_TO_STRING_LEN];
		snprintf(line, ARP_CACHE_ENTRY_TO_STRING_LEN, "%-15s %02X:%02X:%02X:%02X:%02X:%02X %-46s\n",
			addr, (unsigned char)arp_entry->arp_ha[0], (unsigned char)arp_entry->arp_ha[1], (unsigned char)arp_entry->arp_ha[2],
			(unsigned char)arp_entry->arp_ha[3], (unsigned char)arp_entry->arp_ha[4], (unsigned char)arp_entry->arp_ha[5],
			ttl);

		COPY_STRING(buffer, total_len, line);

		arp_walker = arp_walker->next;
	}

	*buf = buffer;
	*len = total_len;
}
Exemplo n.º 11
0
void sprint_hw_iface(router_state *rs, char **buf, unsigned int *len) {

	char *name;
	unsigned int mac_lo = 0;
	unsigned int mac_hi = 0;
	uint8_t mac[6];
	int i = 0;

	char *buffer = calloc(strlen(HW_IFACE_COL) + 4*HW_IFACE_ENTRY_TO_STRING_LEN, sizeof(char));
	unsigned int total_len = 0;
	COPY_STRING(buffer, total_len, HW_IFACE_COL);

	for(i=0; i<4; i++) {

		switch(i) {
			case 0: name = ETH0; break;
			case 1: name = ETH1; break;
			case 2: name = ETH2; break;
			case 3: name = ETH3; break;
			default: name = NULL; break;
		}

		read_hw_iface_mac(rs, i, &mac_hi, &mac_lo);

		mac[5] = (uint8_t)(mac_hi >> 8);
		mac[4] = (uint8_t)mac_hi;
		mac[3] = (uint8_t)(mac_lo >> 24);
		mac[2] = (uint8_t)(mac_lo >> 16);
		mac[1] = (uint8_t)(mac_lo >> 8);
		mac[0] = (uint8_t)mac_lo;

		char line[HW_IFACE_ENTRY_TO_STRING_LEN];
		bzero(line, HW_IFACE_ENTRY_TO_STRING_LEN);
		snprintf(line, HW_IFACE_ENTRY_TO_STRING_LEN, "%-5s\t%02X:%02X:%02X:%02X:%02X:%02X\n",
			name,
			mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
		COPY_STRING(buffer, total_len, line);


		name = NULL;
		mac_hi = 0;
		mac_lo = 0;
	}

	*buf = buffer;
	*len = total_len;
}
Exemplo n.º 12
0
unicorn_config* read_config_file(char *name) {
  char path[2048];
  char buf[1024];
  unicorn_config *conf = malloc(sizeof(unicorn_config));
  conf->keys = malloc(sizeof(char*) * 128);
  conf->values = malloc(sizeof(char*) * 128);
  conf->num_keys = 0;

  sprintf(path, "%s/unicorn_%s.conf", CONFIG_PATH_PREFIX, name);
  FILE *f = fopen(path, "r");
  if(f) {
    while(fgets(buf, 1024, f)) {
      char var[1024], val[1024];
      int i = 0, read_var = 1;
      char *p = var;

      memset(var, 0, 1024); memset(val, 0, 1024);
      if(buf[0] == '#') continue;

      while(i < strlen(buf)) {
        if(buf[i] == '\0' || buf[i] == '\n') {
          *p = '\0'; break;
        } else if(read_var && buf[i] == '=') {
          read_var = 0;
          *p = '\0';
          p = val;
          i++;
          continue;
        }
        *p = buf[i]; p++; i++;
      }

      if(read_var == 0 && strlen(var) > 0 && strlen(val) > 0) {
        int key = conf->num_keys;
        COPY_STRING(conf->keys[key], var);
        COPY_STRING(conf->values[key], val);
        conf->num_keys++;
      }
    }
    fclose(f);
    return conf;
  } else {
    printf("Can't find config file at %s.\n", path);
    exit(1);
  }
  return NULL;
}
Exemplo n.º 13
0
void sprint_nat_table(router_state *rs, char **buf, unsigned int *len) {

	char ext_ip_str[16];
	char int_ip_str[16];
	int nat_table_size = node_length(rs->nat_table);
	time_t now;
	uint32_t diff = 0;

	char *buffer = (char *)calloc(strlen(NAT_COL) + nat_table_size*NAT_ENTRY_TO_STR_LEN, sizeof(char));
	unsigned int total_len = 0;

	COPY_STRING(buffer, total_len, NAT_COL);

	node *n = rs->nat_table;
	while(n) {
		nat_entry *ne = (nat_entry *)n->data;

		char last_update[47];
		bzero(last_update, 47);
		time(&now);
		diff = (int)difftime(now, ne->last_hits_time);
		inet_ntop(AF_INET, &(ne->nat_ext.ip), ext_ip_str, 16);
		inet_ntop(AF_INET, &(ne->nat_int.ip), int_ip_str, 16);

		char line[NAT_ENTRY_TO_STR_LEN];
		bzero(line, NAT_ENTRY_TO_STR_LEN);
		snprintf(line, NAT_ENTRY_TO_STR_LEN, "%-15s %-6u %-15s %-6u %-6u %-6u %-7.2f %-12u %-3u %-1s\n",
				ext_ip_str,
				ntohs(ne->nat_ext.port),
				int_ip_str,
				ntohs(ne->nat_int.port),
				ne->hits,
				ne->last_hits,
				ne->avg_hits_per_second,
				diff,
				ne->hw_row,
				(ne->is_static == 1) ? "Y" : "N");
		COPY_STRING(buffer, total_len, line);

		n = n->next;
	}


	*buf = buffer;
	*len = total_len;
}
Exemplo n.º 14
0
static int PAM_conv (int num_msg,
                     const struct pam_message **msg,
                     struct pam_response **resp,
                     void *appdata_ptr) {
  int count;
  struct pam_response *reply;
  my_PAM *pam_config = (my_PAM *) appdata_ptr;

/* strdup(NULL) doesn't work on some platforms */
#define COPY_STRING(s) ((s) ? strdup(s) : NULL)

  reply = rad_malloc(num_msg * sizeof(struct pam_response));
  memset(reply, 0, num_msg * sizeof(struct pam_response));
  for (count = 0; count < num_msg; count++) {
    switch (msg[count]->msg_style) {
    case PAM_PROMPT_ECHO_ON:
      reply[count].resp_retcode = PAM_SUCCESS;
      reply[count].resp = COPY_STRING(pam_config->username);
      break;
    case PAM_PROMPT_ECHO_OFF:
      reply[count].resp_retcode = PAM_SUCCESS;
      reply[count].resp = COPY_STRING(pam_config->password);
      break;
    case PAM_TEXT_INFO:
      /* ignore it... */
      break;
    case PAM_ERROR_MSG:
    default:
      /* Must be an error of some sort... */
      for (count = 0; count < num_msg; count++) {
        if (reply[count].resp) {
          /* could be a password, let's be sanitary */
          memset(reply[count].resp, 0, strlen(reply[count].resp));
          free(reply[count].resp);
        }
      }
      free(reply);
      pam_config->error = 1;
      return PAM_CONV_ERR;
    }
  }
  *resp = reply;
  /* PAM frees reply (including reply[].resp) */

  return PAM_SUCCESS;
}
Exemplo n.º 15
0
// we don't actually have to fill this data structure, but thought it might be easier
// to work with if we did when changes come about.
bool FillINFOQuery ( const mem_t* data, int data_len, A2S_INFO_t &info, mem_t **pPlayers, mem_t **pPassword ) {
	if ( (data[0]!=0xFF) && (data[1]!=0xFF) && (data[2]!=0xFF) && (data[3]!=0xFF) ) return false;
	int strcount=0;
	mem_t* start = (mem_t *)data;

	//byte	type;
	//byte	netversion;
	//char	server_name[256];
	//char	map[256];
	//char	gamedir[256];
	//char	gamedesc[256];
	//short	appid;
	//byte	players;
	//byte	maxplayers;
	//byte	bots;
	//char	dedicated;
	//char	os;
	//bool	passwordset;
	//bool	secure;
	//char	version[256];

	data+=4;
	COPY_BYTE(info.type);
	COPY_BYTE(info.netversion);
	COPY_STRING(info.server_name);
	COPY_STRING(info.map);
	COPY_STRING(info.gamedir);
	COPY_STRING(info.gamedesc);
	COPY_SHORT(&info.appid);
	*pPlayers = (mem_t *)data;
	COPY_BYTE(info.players);
	COPY_BYTE(info.maxplayers);
	COPY_BYTE(info.bots);
	COPY_BYTE(info.dedicated);
	COPY_BYTE(info.os);
	*pPassword = (mem_t *)data;
	COPY_BOOL(info.passwordset);
	COPY_BOOL(info.secure);
	COPY_STRING(info.version);

	return true;
}
Exemplo n.º 16
0
/* NOT THREAD SAFE */
void sprint_rtable(router_state *rs, char **buf, int *len)
{

	assert(rs);
	assert(buf);
	assert(len);

	node *rtable_walker = 0;
	rtable_entry *re = 0;
	char *buffer = 0;
	int total_len = 0;

	char ip_str[16];
	char gw_str[16];
	char mask_str[16];

	buffer = calloc(strlen(RTABLE_COL) + RTABLE_ENTRY_TO_STRING_LEN * node_length(rs->rtable), sizeof(char) );
	COPY_STRING(buffer, total_len, RTABLE_COL);

	rtable_walker = rs->rtable;
	while(rtable_walker) {
		re = (rtable_entry *)rtable_walker->data;

		char if_name[RTABLE_MAX_IFACE_LEN+1];
		snprintf(if_name, RTABLE_MAX_IFACE_LEN, "%s", re->iface);
		if_name[RTABLE_MAX_IFACE_LEN] = '\0';

		char line[RTABLE_ENTRY_TO_STRING_LEN];
		snprintf(line, RTABLE_ENTRY_TO_STRING_LEN, "%-15s %-15s %-15s %-18s %-6s %-6s\n",
			inet_ntop(AF_INET, &(re->ip), ip_str, 16), inet_ntop(AF_INET, &(re->gw), gw_str, 16),
			inet_ntop(AF_INET, &(re->mask), mask_str, 16), if_name,
			(re->is_static == 1) ? "Y" : "N", (re->is_active == 1) ? "Y" : "N");

		rtable_walker = rtable_walker->next;

		COPY_STRING(buffer, total_len, line);
	}

	*buf = buffer;
	*len = total_len;

}
Exemplo n.º 17
0
static int PAM_conv (int num_msg,
#ifdef sun
		     struct pam_message **msg,
#else
		     const struct pam_message **msg,
#endif
		     struct pam_response **resp,
		     void *appdata_ptr) {
	int count = 0, replies = 0;
	struct pam_response *reply = NULL;

#define PAM_RESPONSE_SIZE	sizeof(struct pam_response)
	size_t size = PAM_RESPONSE_SIZE;

#define COPY_STRING(s) (s) ? strdup(s) : (char*)NULL

	for (count = 0; count < num_msg; count++) {
		switch (msg[count]->msg_style) {
		case PAM_PROMPT_ECHO_ON:
			/* user name given to PAM already */
			return PAM_CONV_ERR;
		case PAM_PROMPT_ECHO_OFF:
			/* wants password */
			if (reply) {
				reply = realloc(reply, size);
				bzero(reply + size - PAM_RESPONSE_SIZE, PAM_RESPONSE_SIZE);
			} else {
				reply = (struct pam_response*)malloc(size);
				bzero(reply, size);
			}

			if (!reply)
				return PAM_CONV_ERR;

			size += PAM_RESPONSE_SIZE;
			
			reply[replies].resp_retcode = PAM_SUCCESS;
			reply[replies].resp = COPY_STRING(PAM_password);
			/* PAM frees resp */
			break;
		case PAM_TEXT_INFO:
			/* ignore the informational mesage */
			break;
		default:
			/* unknown or PAM_ERROR_MSG */
			if (reply) free (reply);
			return PAM_CONV_ERR;
		}
	}

#undef COPY_STRING
	if (reply) *resp = reply;
	return PAM_SUCCESS;
}
Exemplo n.º 18
0
static int conversation (int num_msg,
#ifndef SOL2
    const
#endif
    struct pam_message **msg,
    struct pam_response **resp, void *appdata_ptr)
{
    int replies = 0;
    struct pam_response *reply = NULL;

    reply = malloc(sizeof(struct pam_response) * num_msg);
    if (!reply) return PAM_CONV_ERR;

    for (replies = 0; replies < num_msg; replies++) {
        switch (msg[replies]->msg_style) {
            case PAM_PROMPT_ECHO_ON:
                reply[replies].resp_retcode = PAM_SUCCESS;
                reply[replies].resp = COPY_STRING(PAM_username);
                /* PAM frees resp */
                break;
            case PAM_PROMPT_ECHO_OFF:
                reply[replies].resp_retcode = PAM_SUCCESS;
                reply[replies].resp = COPY_STRING(PAM_password);
                /* PAM frees resp */
                break;
            case PAM_TEXT_INFO:
                /* fall through */
            case PAM_ERROR_MSG:
                /* ignore it, but pam still wants a NULL response... */
                reply[replies].resp_retcode = PAM_SUCCESS;
                reply[replies].resp = NULL;
                break;
            default:
                /* Must be an error of some sort... */
                free (reply);
                return PAM_CONV_ERR;
        }
    }
    *resp = reply;
    return PAM_SUCCESS;
}
Exemplo n.º 19
0
NMEAMessageRMB::NMEAMessageRMB(const char *message) : BaseNMEAMessage() {
    char *fragments[15];
    int fragmentCount = 0;
    splitMessageIntoFragments(message, strlen(message), fragments, &fragmentCount);

    _status = statusFromFragment(fragments[1]);
    _xte = atof(fragments[2]);
    _directionToSteer = lateralityFromFragment(fragments[3]);
    COPY_STRING(_toWaypointID, fragments[4]);
    COPY_STRING(_fromWaypointID, fragments[5]);
    _destinationLatitude = degreesFromCoordinateString(fragments[6], fragments[7][0]);
    _destinationLongitude = degreesFromCoordinateString(fragments[8], fragments[9][0]);
    _rangeToDestiation = atof(fragments[10]);
    _bearingToDestination = headingFromFragments(fragments[11], "T");
    _destinationClosingVelocity = atof(fragments[12]);
    _isArrived = fragments[13][0] == 'A' ? true : false;

    for (int i = 0; i < fragmentCount; i++) {
        free(fragments[i]);
    }
}
Exemplo n.º 20
0
ERetVal CFile::OpenWrite( const char* _pszFileName )
{
	ERetVal eRetVal = RET_OK;
		
	ASSERT( _pszFileName );

	if (_pszFileName==NULL )
	{
		eRetVal = RET_ERR;
		LOG(("ERR: Nombre de fichero NULL en OpenWrite"));
	}
		
	if (eRetVal==RET_OK)
	{
		SAFE_DELETE_ARRAY( m_pszFileName );
		m_pszFileName     = ALLOC_COPY_STRING( _pszFileName );
				 
		FILE* fp = fopen( m_pszFileName, "wb" );
				
		if (!fp)  // if there is an error, assumes it is because the directory is not created, and so it tries to create all the directory chain
		{
			char szDir[ MAX_FILENAME_SIZE ];
			COPY_STRING( szDir, m_pszFileName );        
			char* psz = szDir;
			char* pszSlash = NULL;
			do
			{
				char* pszSlash = strchr( psz, '/' );
				if (pszSlash)
				{
					*pszSlash = 0;
					_mkdir( szDir );
					*pszSlash = '/';
					psz = pszSlash + 1;
				}
			} while (pszSlash!=0);
						
			fp = fopen( m_pszFileName, "wb" );  // then tries to create the file again
		}
				
		if (!fp)  // if still cant, then error
		{
			eRetVal = RET_ERR;
			if (m_bLog)
				LOG(("ERR: when trying to open the file (does not exist or cant be read): '%s'", m_pszFileName));
		}
						
		m_pFile = fp;
	}
		
	UpdateError( eRetVal );
	return eRetVal;
}
Exemplo n.º 21
0
int
pbs_python_ext_alloc_python_script(
	const char *script_path,
	struct python_script **py_script /* returned value */
	) {
	static char func_id[] = "pbs_python_ext_alloc_python_script";

#ifdef PYTHON                 /* --- BEGIN PYTHON BLOCK --- */

	struct python_script *tmp_py_script = (struct python_script *) NULL;
	size_t nbytes = sizeof(struct python_script);
	struct stat sbuf;

	*py_script = (struct python_script *) NULL; /* init, to be safe */

	if (!(tmp_py_script = (struct python_script *) malloc(nbytes))) {
		log_err(errno, func_id, "failed to malloc struct python_script");
		goto ERROR_EXIT;
	}
	(void) memset(tmp_py_script, 0, nbytes);
	/* check for recompile true by default */
	tmp_py_script->check_for_recompile = 1;

	COPY_STRING(tmp_py_script->path, script_path);
	/* store the stat */
	if ((stat(script_path, &sbuf) == -1)) {
		snprintf(log_buffer, LOG_BUF_SIZE-1,
			"failed to stat <%s>", script_path);
		log_buffer[LOG_BUF_SIZE-1] = '\0';
		log_err(errno, func_id, log_buffer);
		goto ERROR_EXIT;
	}
	(void) memcpy(&(tmp_py_script->cur_sbuf), &sbuf,
		sizeof(tmp_py_script->cur_sbuf));
	/* ok, we are set with py_script */
	*py_script = tmp_py_script;
	return 0;

ERROR_EXIT:
	if (tmp_py_script) {
		pbs_python_ext_free_python_script(tmp_py_script);
		free(tmp_py_script);
	}
	return -1;
#else

	log_err(-1, func_id, "--> Python is disabled <--");
	return -1;
#endif                        /* --- END   PYTHON BLOCK --- */
}
Exemplo n.º 22
0
void
tracker_add_process (tracker_t * tracker,
		     pid_t	 pid,
		     const char *command_line)
{
    new_process_t event;

#if 0
    g_print ("Add new process %s %d to tracker ", command_line, pid);
#endif
    
    event.header = MAKE_HEADER (NEW_PROCESS, pid);
    COPY_STRING (event.command_line, command_line);

    tracker_append (tracker, &event, sizeof (event));
}
Exemplo n.º 23
0
OPTIONS *copy_options(const OPTIONS *o)
{
    OPTIONS *op = malloc(sizeof(OPTIONS));
    memcpy(op, o, sizeof(OPTIONS));

#define COPY_STRING(n) if (o->n) op->n = strdup(o->n)

    COPY_STRING(device);
    COPY_STRING(watch_name);
    COPY_STRING(run_as_user);
#ifdef UNSAFE
    COPY_STRING(file);
#endif
    COPY_STRING(activity_store);
    COPY_STRING(race);
    COPY_STRING(history_entry);
    COPY_STRING(setting_spec);
    COPY_STRING(post_processor);

#undef COPY_STRING
    return op;
}
Exemplo n.º 24
0
int find_master_input(zloop_t *loop, zmq_pollitem_t *item, void *arg) {
    maneater_client *cli = (maneater_client *)arg;
    zframe_t *incoming = zframe_recv(cli->local_socket);
    unsigned char *data = zframe_data(incoming);
    int size = zframe_size(incoming);
    msgpack_unpacked msg;
    size_t off;
    MSG_NEXT(&msg, data, size, &off);
    assert(msg.data.type == MSGPACK_OBJECT_POSITIVE_INTEGER);
    uint64_t msgid = msg.data.via.u64;

    int ret = 0, i = 0;

    if (msgid == MID_IS_MASTER) {
        MSG_NEXT(&msg, data, size, &off);
        assert(msg.data.type == MSGPACK_OBJECT_RAW);
        char *host;
        COPY_STRING(host, msg.data.via.raw.ptr);

        cli->master = host;

        cli->master_socket = NULL;
        for (i=0; i < cli->num_hosts; i++) {
            if (!strcmp(cli->hosts[i], host)) {
                cli->master_socket = cli->sockets[i];
                break;
            }
        }

        assert(cli->master_socket);
        struct timeval tim;
        gettimeofday(&tim, NULL);
        cli->last_tick = tim.tv_sec;

        zclock_log("got master: %s", host);

        ret = -1;
    }

    zframe_destroy(&incoming);
    return ret;
}
Exemplo n.º 25
0
/**
 * Parses the ':authority' special header
 * into the host and port
 */
static void parse_authority(http_request_t * const request)
{
  char * authority = http_request_header_get(request, ":authority");
  request->authority = authority;

  if (authority) {
    char * port = strchr(authority, ':');

    if (port) {
      COPY_STRING(request->host, authority, port - authority);
      request->port = strtoul(port + 1, NULL, 10);
    } else {
      request->host = strdup(authority);
      request->port = 80;
    }
  } else {
    request->host = NULL;
    request->port = 0;
  }
}
Exemplo n.º 26
0
/**
 * Parses the ':path' special header into a plain
 * path and a query string
 */
static bool parse_path(http_request_t * const request)
{
  char * path = http_request_header_get(request, ":path");

  if (!path) {
    log_append(request->log, LOG_ERROR, "No :path header provided");
    return false;
  }

  char * query = strchr(path, '?');

  if (query) {
    COPY_STRING(request->path, path, query - path);
  } else {
    request->path = strdup(path);
  }

  request->query_string = query ? strdup(query + 1) : NULL;
  return true;
}
Exemplo n.º 27
0
void
tracker_add_map (tracker_t * tracker,
		 pid_t	     pid,
		 uint64_t    start,
		 uint64_t    end,
		 uint64_t    offset,
		 uint64_t    inode,
		 const char *filename)
{
    new_map_t event;

    event.header = MAKE_HEADER (NEW_MAP, pid);
    COPY_STRING (event.filename, filename);
    event.start = start;
    event.end = end;
    event.offset = offset;
    event.inode = inode;

    tracker_append (tracker, &event, sizeof (event));
}
Exemplo n.º 28
0
void sprint_hw_drops(router_state *rs, char **buf, unsigned int *len) {
	char *buffer = calloc(1*HW_DROPS_LEN + 1, sizeof(char));
	unsigned int total_len = 0;

	if (rs->is_netfpga) {
		char* port_names[4] = {"eth0", "eth1", "eth2", "eth3"};
		char line[HW_DROPS_LEN];
		bzero(line, HW_DROPS_LEN);
		snprintf(line, HW_DROPS_LEN, "%4s %10u %4s %10u %4s %10u %4s %10u\n",
			port_names[0], get_rx_queue_num_pkts_dropped_full(&rs->netfpga, 0) + get_rx_queue_num_pkts_dropped_bad(&rs->netfpga, 0),
			port_names[1], get_rx_queue_num_pkts_dropped_full(&rs->netfpga, 1) + get_rx_queue_num_pkts_dropped_bad(&rs->netfpga, 1),
			port_names[2], get_rx_queue_num_pkts_dropped_full(&rs->netfpga, 2) + get_rx_queue_num_pkts_dropped_bad(&rs->netfpga, 2),
			port_names[3], get_rx_queue_num_pkts_dropped_full(&rs->netfpga, 3) + get_rx_queue_num_pkts_dropped_bad(&rs->netfpga, 3));

		COPY_STRING(buffer, total_len, line);
	}

	*buf = buffer;
	*len = total_len;
}
Exemplo n.º 29
0
void sprint_hw_stats(router_state *rs, char **buf, unsigned int *len) {
	char *buffer = calloc(4*HW_STATS_LEN + 1, sizeof(char));
	unsigned int total_len = 0;
	char* port_names[8] = {"eth0", "eth1", "eth2", "eth3", "cpu0", "cpu1", "cpu2", "cpu3"};

	lock_netfpga_stats(rs);
	int i;
	char line[HW_STATS_LEN];
	bzero(line, HW_STATS_LEN);
	for (i = 0; i < 4; ++i) {
		snprintf(line, HW_STATS_LEN, "%-4s %12.2f PPS %12.2f kB/s %-4s %12.2f PPS %12.2f kB/s\n",
			port_names[i], rs->stats_avg[i][0], rs->stats_avg[i][1],
			port_names[i+4], rs->stats_avg[i+4][0], rs->stats_avg[i+4][1]);
		COPY_STRING(buffer, total_len, line);
	}

	unlock_netfpga_stats(rs);

	*buf = buffer;
	*len = total_len;
}
Exemplo n.º 30
0
NMEAMessageAPB::NMEAMessageAPB(const char *message) : BaseNMEAMessage() {
    char *fragments[15];
    int fragmentCount = 0;
    splitMessageIntoFragments(message, strlen(message), fragments, &fragmentCount);

    _isUnreliableFix = fragments[1][0] == 'V' ? true : false;
    _isCycleLockWarning = fragments[2][0] == 'V' ? true : false;
    _xte = atof(fragments[3]);
    _directionToSteer = lateralityFromFragment(fragments[4]);
    // TODO: Do XTE units ever change? If so, implement units for XTE
    _isArrived = fragments[6][0] == 'A' ? true : false;
    _isPerpendicularPassed = fragments[7][0] == 'A' ? true : false;
    _bearingOriginToDestination = headingFromFragments(fragments[8], fragments[9]);
    COPY_STRING(_destinationWaypointID, fragments[10]);
    _bearingPresentToDestination = headingFromFragments(fragments[11], fragments[12]);
    _headingToSteerToWaypoint = headingFromFragments(fragments[13], fragments[14]);

    for (int i = 0; i < fragmentCount; i++) {
        free(fragments[i]);
    }
}