Exemple #1
0
/*
 * Locate or allocate connection cache entry.
 */
static void dict_ldap_conn_find(DICT_LDAP *dict_ldap)
{
    VSTRING *keybuf = vstring_alloc(10);
    char   *key;
    int     len;

#ifdef LDAP_API_FEATURE_X_OPENLDAP
    int     sslon = dict_ldap->start_tls || dict_ldap->ldap_ssl;

#endif
    LDAP_CONN *conn;

#define ADDSTR(vp, s) vstring_memcat((vp), (s), strlen((s))+1)
#define ADDINT(vp, i) vstring_sprintf_append((vp), "%lu", (unsigned long)(i))

    ADDSTR(keybuf, dict_ldap->server_host);
    ADDINT(keybuf, dict_ldap->server_port);
    ADDINT(keybuf, dict_ldap->bind);
    ADDSTR(keybuf, dict_ldap->bind ? dict_ldap->bind_dn : "");
    ADDSTR(keybuf, dict_ldap->bind ? dict_ldap->bind_pw : "");
    ADDINT(keybuf, dict_ldap->dereference);
    ADDINT(keybuf, dict_ldap->chase_referrals);
    ADDINT(keybuf, dict_ldap->debuglevel);
    ADDINT(keybuf, dict_ldap->version);
#ifdef LDAP_API_FEATURE_X_OPENLDAP
    ADDINT(keybuf, dict_ldap->ldap_ssl);
    ADDINT(keybuf, dict_ldap->start_tls);
    ADDINT(keybuf, sslon ? dict_ldap->tls_require_cert : 0);
    ADDSTR(keybuf, sslon ? dict_ldap->tls_ca_cert_file : "");
    ADDSTR(keybuf, sslon ? dict_ldap->tls_ca_cert_dir : "");
    ADDSTR(keybuf, sslon ? dict_ldap->tls_cert : "");
    ADDSTR(keybuf, sslon ? dict_ldap->tls_key : "");
    ADDSTR(keybuf, sslon ? dict_ldap->tls_random_file : "");
    ADDSTR(keybuf, sslon ? dict_ldap->tls_cipher_suite : "");
#endif

    key = vstring_str(keybuf);
    len = VSTRING_LEN(keybuf);

    if (conn_hash == 0)
	conn_hash = binhash_create(0);

    if ((dict_ldap->ht = binhash_locate(conn_hash, key, len)) == 0) {
	conn = (LDAP_CONN *) mymalloc(sizeof(LDAP_CONN));
	conn->conn_ld = 0;
	conn->conn_refcount = 0;
	dict_ldap->ht = binhash_enter(conn_hash, key, len, (char *) conn);
    }
    ++DICT_LDAP_CONN(dict_ldap)->conn_refcount;

    vstring_free(keybuf);
}
Exemple #2
0
int main(int argc, char **argv)
{
	unsigned int i;
	struct strcode sc[] = {
		ADDSTR("\n"),
		ADDSTR("\0\0"),
		ADDSTR("XXXxXXX"),
		ADDSTR("LALALALALALALAKALASBALLE\n"),
	};

	t_set_colors(0);
	t_start("iocache_use_delim() test");
	for (i = 0; i < ARRAY_SIZE(sc); i++) {
		t_start("Testing delimiter of len %d", sc[i].len);
		test_delimiter(sc[i].str, sc[i].len);
		t_end();
	}

	return t_end();
}
Exemple #3
0
static int test_delimiter(const char *delim, unsigned int delim_len)
{
	struct strcode sc[] = {
		ADDSTR("Charlie Chaplin"),
		ADDSTR("Madonna Something something"),
		ADDSTR("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla turpis augue, laoreet eleifend ultricies et, tincidunt non felis. Suspendisse vitae accumsan dolor. Vivamus posuere venenatis dictum. Integer hendrerit est eget turpis scelerisque porttitor. Donec ullamcorper sodales purus, sed bibendum odio porttitor sit amet. Donec pretium sem ac sapien iaculis feugiat. Quisque commodo consequat quam, ac cursus est sodales euismod. Sed nec massa felis, sit amet varius dui. Morbi fermentum varius tellus, eget tempus felis imperdiet quis. Praesent congue auctor ligula, a tempor ipsum malesuada at. Proin pharetra tempor adipiscing. Aenean egestas tellus vitae arcu sagittis non ultrices turpis cursus."),
		ADDSTR("Emma Blomqvist"),
		ADDSTR("Random message"),
		ADDSTR("Random\0message\0with\0nuls\0embedded"),
		{ NULL, 0, },
	};
	int i;
	iocache *ioc;

	ioc = iocache_create(512 * 1024);
	if (!test(ioc != NULL, "iocache_create must work"))
		crash("can't test with no available memory");

	for (i = 0; sc[i].str; i++) {
		memcpy(&ioc->ioc_buf[ioc->ioc_buflen], sc[i].str, sc[i].len);
		ioc->ioc_buflen += sc[i].len;
		memcpy(ioc->ioc_buf + ioc->ioc_buflen, delim, delim_len);
		ioc->ioc_buflen += delim_len;
	}

	for (i = 0; sc[i].str; i++) {
		char *ptr;
		unsigned long len;
		int error = 0;
		ptr = iocache_use_delim(ioc, delim, delim_len, &len);
		t_req(ptr != NULL);
		if (!ptr) {
			printf("Null pointer. What weird shit is this??\n");
			exit(1);
		}
		test(len == sc[i].len, "len check, string %d, delim_len %d", i, delim_len);
		test(!memcmp(ptr, sc[i].str, len), "memcmp() check, string %d, delim_len %d", i, delim_len);
		if (error) {
			printf("delim_len: %d. i: %d; len: %lu; sc[i].len: %d\n",
				   delim_len, i, len, sc[i].len);
			printf("sc[i].str: %s\n", sc[i].str);
			printf("ptr      : %s\n", ptr);
			printf("strlen(sc[i].str): %lu\n", strlen(sc[i].str));
			printf("strlen(ptr)      : %lu\n", strlen(ptr));
			exit(1);
		}
	}
	iocache_destroy(ioc);
	return 0;
}
Exemple #4
0
FILE *smfPrintStart(FILE *fp, char *name, void *p, size_t l, BOOL *f, BOOL *newFile,columnHeader_t **h)
{
  FILE *fpNew = fp;
  BOOL first = *f;
  int i;

  offsetH=0;
  offsetD=0;
  columnCount=0;
  tableName = name;
  columnHeadersTmp = h;
  localFirst = first;
  /* Dump the entire record in hex */
  if (debugLevel >=1 )
  {
    printDEBUG(name,p,(l));
  }

  if (first) {
    switch (outputFormat)
    {
    case OF_CSV:
    case OF_SQL:
      fpNew = fopencsv(name,newFile);
      if (outputFormat == OF_SQL)
        openDDL(name);

      if (!fpNew)
      {
        exit(1);
      }
      break;
    case OF_JSON:
      if (!fpNew)
      {
        fpNew = fopenext("MQSMF","json",newFile);
        if (!fpNew)
        {
          exit(1);
        }
      }
      break;
    }
    for(i=0;i<HEADINGS_COUNT;i++) {
      h[i] = 0;
    }
  }
  if (outputFormat == OF_JSON)
    jsonNew(fpNew,name);

  ADDSTR ("Date",commonF.recordDate,8);
  ADDSTR ("Time",commonF.recordTime,16);
  ADDSTRN("LPAR",commonF.systemId,4,4);
  ADDSTRN("QMgr",commonF.qMgr,4,4);
  ADDSTRN("MQ_Version",commonF.mqVer,3,3);

  if (recordType == 115 && commonF.intstart != 0)
  {
    char *dt[2];
    unsigned long long du = conv64(commonF.intduration)/1000000L;
    ADDTIME("Interval_Start",commonF.intstart);
    ADDHEAD("Interval_Duration",DDL_I,0);
    /* Not documented, but this subtype uses a different scale for */
    /* measuring the duration.                                     */
    if (recordSubType == 231)
    {
      ADDDATA(ODT_I64,"%llu,",du/4096L);
    } else {
      ADDDATA(ODT_I64,"%llu,",du);
    }
  }
  *f = first;

  return fpNew;
}
char *
qcs__make_qchat_msg(
	const qcs_msg * msg,
	ssize_t * pmsg_len )
{
	char * msg_buf;
	ssize_t slen;

	assert(msg && pmsg_len);

	msg_buf = (char*) malloc(QCP_MAXUDPSIZE);
	*pmsg_len = 0;
	if( msg_buf==NULL ) {
		errno = ENOMEM;
		return NULL;
	}

	switch(msg->msg) {
	case QCS_MSG_REFRESH_REQUEST:
		ADDCHAR('0');
		ADDSTR(msg->src);
		break;
	case QCS_MSG_REFRESH_ACK:
		ADDCHAR('1');
		ADDSTR(msg->dst);
		ADDSTR(msg->src);
		ADDCHAR(qcs__net_qcumode(msg->umode));
		ADDCHAR('0');
		ADDCHAR(qcs__net_qcuactive(msg->uactive));
		break;
	case QCS_MSG_CHANNEL_BROADCAST:
		ADDCHAR('2');
		ADDCHAN(msg->chan);
		ADDSTR(msg->src);
		ADDSTR(msg->text);
		break;
	case QCS_MSG_CHANNEL_JOIN:
		ADDCHAR('4');
		ADDSTR(msg->src);
		ADDCHAN(msg->chan);
		ADDCHAR(qcs__net_qcumode(msg->umode));
		ADDCHAR('0');		/* unknown purpose !! */
		break;
	case QCS_MSG_CHANNEL_LEAVE:
		ADDCHAR('5');
		ADDSTR(msg->src);
		ADDCHAN(msg->chan);
		ADDCHAR('0');		/* unknown */
		break;
	case QCS_MSG_CHANNEL_ME:
		ADDCHAR('A');
		ADDCHAN(msg->chan);
		ADDSTR(msg->src);
		ADDSTR(msg->text);
		break;
	case QCS_MSG_MESSAGE_ACK:
		ADDCHAR('7');
		ADDCHAR(qcs__net_qcumode(msg->umode));
		ADDSTR(msg->dst);
		ADDSTR(msg->src);
		ADDCHAR('0');		/* unknown purpose */
		ADDSTR(msg->text);
		break;
	case QCS_MSG_MESSAGE_MASS:
		ADDCHAR('E');
		ADDSTR(msg->src);
		ADDSTR(msg->dst);
		ADDSTR(msg->text);
		break;
	case QCS_MSG_MESSAGE_SEND:
		ADDCHAR('6');
		ADDSTR(msg->src);
		ADDSTR(msg->dst);
		ADDSTR(msg->text);
		break;
	case QCS_MSG_RENAME:
		ADDCHAR('3');
		ADDSTR(msg->src);
		ADDSTR(msg->text);
		ADDCHAR('0');		/* unknown */
		break;
	case QCS_MSG_MODE_CHANGE:
		ADDCHAR('D');
		ADDSTR(msg->src);
		ADDCHAR(qcs__net_qcumode(msg->umode));
		ADDCHAR('0');		/* unknown */
		break;
	case QCS_MSG_ACTIVE_CHANGE:
		ADDCHAR('M');
		ADDSTR(msg->src);
		ADDCHAR(qcs__net_qcuactive(msg->uactive));
		break;
	case QCS_MSG_TOPIC_REPLY:
		ADDCHAR('C');
		ADDSTR(msg->dst);
		ADDSTR(msg->text);
		if(msg->chan==NULL || strcasecmp(msg->chan, "Main")) {
			free(msg_buf);
			errno = ENOMSG;
			return NULL;
		}
		break;
	case QCS_MSG_TOPIC_CHANGE:
		/* check that the channel is "Main",
		 * in QC1.x topic is the same for all channels
		 * (while each channel has it's topic in Vypress Chat)
		 */
		if(msg->chan==NULL || strcasecmp(msg->chan, "Main")) {
			free(msg_buf);
			errno = ENOMSG;
			return NULL;
		}

		ADDCHAR('B');
		ADDSTR(msg->text);
		break;
	case QCS_MSG_INFO_REPLY:
		ADDCHAR('G');
		ADDSTR(msg->dst);
		ADDSTR(msg->src);
		ADDSTR(msg->text);
		ADDSTR("(Unknown)");
		ADDSTR("0 %");
		ADDSTR("0 Kb");
		ADDSTR(msg->chan);
		ADDSTR(msg->supp);
		break;
	case QCS_MSG_INFO_REQUEST:
		ADDCHAR('F');
		ADDSTR(msg->dst);
		ADDSTR(msg->src);
		break;
	case QCS_MSG_CHANMEMBER_REPLY:
		ADDCHAR('K');
		ADDSTR(msg->dst);
		ADDSTR(msg->chan);
		ADDSTR(msg->src);
		break;
	case QCS_MSG_CHANMEMBER_REQUEST:
		ADDCHAR('L');
		ADDSTR(msg->src);
		break;
	case QCS_MSG_CHANLIST_REPLY:
		ADDCHAR('O');
		ADDSTR(msg->dst);
		ADDSTR(msg->chan);
		break;
	case QCS_MSG_CHANLIST_REQUEST:
		ADDCHAR('N');
		ADDSTR(msg->src);
		break;
	case QCS_MSG_BEEP_SEND:
	case QCS_MSG_BEEP_ACK:
		ADDCHAR('H');
		ADDCHAR((msg->msg==QCS_MSG_BEEP_ACK)?'1':'0');
		ADDSTR(msg->dst);
		ADDSTR(msg->src);
		if(msg->msg==QCS_MSG_BEEP_ACK) {
			ADDCHAR('0');	/* dummy ? */
		}
		break;
	case QCS_MSG_PRIVATE_ME:
	case QCS_MSG_PRIVATE_TEXT:
		ADDCHAR('J');
		ADDCHAR(msg->msg==QCS_MSG_PRIVATE_ME ? '3': '2');
		ADDSTR(msg->src);
		ADDSTR(msg->dst);
		ADDSTR(msg->text);
		break;
	case QCS_MSG_PRIVATE_OPEN:
	case QCS_MSG_PRIVATE_CLOSE:
		ADDCHAR('J');
		ADDCHAR(msg->msg==QCS_MSG_PRIVATE_CLOSE ? '1': '0');
		ADDSTR(msg->src);
		ADDSTR(msg->dst);
		ADDCHAR('0');		/* dummy/unknown */
		break;
	default:
		errno = ENOMSG;
		free(msg_buf);
		return NULL;
	}

	return msg_buf;
}
char * qcs__make_vypress_msg(
	const qcs_msg * msg,
	int * pmsg_len )
{
	int raw_len = 0, slen;
	char * msg_buf,
		* raw_msg = (char *)malloc(QCP_MAXUDPSIZE);
	
	if( raw_msg==NULL ) {
		errno = ENOMEM;
		return NULL;
	}

	switch(msg->msg)
	{	/* process differences qc16<->vypresschat10 */

	case QCS_MSG_TOPIC_CHANGE:
		ADDCHAR('B');
		ADDCHAN(msg->chan);
		ADDSTR(msg->text);
		break;
		
	case QCS_MSG_TOPIC_REPLY:
		ADDCHAR('C');
		ADDSTR(msg->dst);
		ADDCHAN(msg->chan);
		ADDSTR(msg->text);
		break;

	case QCS_MSG_INFO_REPLY:
		ADDCHAR('G');
		ADDSTR(msg->dst);
		ADDSTR(msg->src);
		ADDSTR(msg->text);
		ADDSTR("VcProto1.0");
		ADDSTR("0.0.0.0");
		ADDSTR(msg->chan);
		ADDSTR(msg->supp);
		break;
	default:
		/* fallback to qc16 makeup */
		free(raw_msg);
		raw_msg = (char*)qcs__make_qchat_msg(msg, &raw_len);
		break;
	}

	/* allocate buffer for final version */
	msg_buf = malloc(QCP_MAXUDPSIZE+10);
	if( msg_buf==NULL ) {
		free(raw_msg);
		errno = ENOMEM;
		return NULL;
	}

	/* append msg id and register for duplicates */
	qcs__generate_signature( msg_buf );

	/* build up final "version" */
	memcpy(msg_buf+10, raw_msg, raw_len);
	if( pmsg_len ) {
		*pmsg_len = raw_len + 10;
	}

	free(raw_msg);

	return msg_buf;
}