Exemplo n.º 1
0
/* channel link <channeltag> <channeltag> */
bool cfg_conf_channel_link(struct cfg_state *cmd, char *args)
{
	int		fields = countfields(args);
	char		tag_a[25], tag_b[25];
	struct channel	*ch_a, *ch_b;

	/* Link requires 2 variables */
	if (	fields != 2 ||
		!copyfield(args, 1, tag_a, sizeof(tag_a)) ||
		!copyfield(args, 2, tag_b, sizeof(tag_b)))
	{
		sock_printf(cmd->sock, "400 The command is: channel link <channeltag> <channeltag>\n");
		return false;
	}

	ch_a = channel_find_tag(tag_a);
	if (!ch_a)
	{
		sock_printf(cmd->sock, "400 Channel '%s' does not exist\n", tag_a);
		return false;
	}
	ch_b = channel_find_tag(tag_b);
	if (!ch_b)
	{
		sock_printf(cmd->sock, "400 Channel '%s' does not exist\n", tag_b);
		return false;
	}

	channel_link(ch_a, ch_b);

	sock_printf(cmd->sock, "200 Channels are linked\n");
	return true;
}
Exemplo n.º 2
0
/* server connect <servertag> */
bool cfg_conf_server_connect(struct cfg_state *cmd, char *args)
{
	int		fields = countfields(args);
	char		tag[25], var[25], val[1000];
	struct server	*srv;
	struct channel	*ch;

	/* Add requires 1 variables */
	if (	fields != 1 ||
		!copyfield(args, 1, tag, sizeof(tag)))
	{
		sock_printf(cmd->sock, "400 The command is: server connect <servertag>\n");
		return false;
	}

	srv = server_find_tag(tag);

	if (!srv)
	{
		sock_printf(cmd->sock, "400 Server '%s' does not exist\n");
		return false;
	}
	
	server_connect(srv);

	sock_printf(cmd->sock, "200 Connecting to server\n");
	return true;
}
Exemplo n.º 3
0
static int monkeypatch(lua_State *L) {
  lua_getglobal(L, "string");
  /* NOTE: keep the third argument here updated for the number of functions */
  lua_createtable(L, 0, 7);  /* local t = {} */
  copyfield(L, -2, -1, "find");  /* t.find = string.find */
  copyfield(L, -2, -1, "match");  /* t.match = string.match */
  copyfield(L, -2, -1, "gmatch");  /* t.gmatch = string.gmatch */
  copyfield(L, -2, -1, "gsub");  /* t.gsub = string.gsub */
  lua_setfield(L, -2, "original");  /* string.original = t */
#if LUA_VERSION_NUM == 501
  luaL_register(L, NULL, matchext_lib);
#else
  luaL_setfuncs(L, matchext_lib, 0);
#endif
  return 0;
}
Exemplo n.º 4
0
/* server add <servertag> <RFC1459|Timestamp|P10|User|BitlBee> <hostname> <service|portnumber> <nickname|none> <localname> <password|none> <identity> */
bool cfg_conf_server_add(struct cfg_state *cmd, char *args)
{
	int		fields = countfields(args);
	char		tag[25], type[10], hostname[24], service[24], nick[24], local[24], pass[24], identity[24];
	enum srv_types	typ = SRV_BITLBEE;

	/* Add requires 8 variables */
	if (	fields != 8 ||
		!copyfield(args, 1, tag,	sizeof(tag)) ||
		!copyfield(args, 2, type,	sizeof(type)) ||
		!copyfield(args, 3, hostname,	sizeof(hostname)) ||
		!copyfield(args, 4, service,	sizeof(service)) ||
		!copyfield(args, 5, nick,	sizeof(nick)) ||
		!copyfield(args, 6, local,	sizeof(local)) ||
		!copyfield(args, 7, pass,	sizeof(pass)) ||
		!copyfield(args, 8, identity,	sizeof(identity)))
	{
		sock_printf(cmd->sock, "400 The command is: server add <servertag> <RFC1459|Timestamp|P10|User|BitlBee> <hostname> <service|portnumber> <nickname|none> <localname> <password> <identity>\n");
		return false;
	}

	if (	 strcasecmp(type, "rfc1459"	) == 0) typ = SRV_RFC1459;
	else if (strcasecmp(type, "timestamp"	) == 0) typ = SRV_TS;
	else if (strcasecmp(type, "bitlbee"	) == 0) typ = SRV_BITLBEE;
	else if (strcasecmp(type, "user"	) == 0) typ = SRV_USER;
	else
	{
		sock_printf(cmd->sock, "400 '%s' is an unsupported server type\n", type);
		return false;
	}
	
	if (server_find_tag(tag))
	{
		sock_printf(cmd->sock, "400 Server '%s' already exists\n", tag);
		return false;
	}

	if (server_add(tag, typ, hostname, service,
		strcasecmp(nick, "none") == 0 ? NULL : nick,
		local,
		strcasecmp(pass, "none") == 0 ? NULL : pass,
		identity, g_conf->service_description))
	{
		sock_printf(cmd->sock, "200 Added server %s\n", tag);
		return true;
	}
	sock_printf(cmd->sock, "400 Server addition failed\n");
	return false;
}
Exemplo n.º 5
0
/* channel add <servertag> <channeltag> <name> */
bool cfg_conf_channel_add(struct cfg_state *cmd, char *args)
{
	int		fields = countfields(args);
	char		stag[24], ctag[24], name[24];
	struct server	*srv;

	/* Add requires 3 variables */
	if (	fields != 3 ||
		!copyfield(args, 1, stag,	sizeof(stag)) ||
		!copyfield(args, 2, ctag,	sizeof(ctag)) ||
		!copyfield(args, 3, name,	sizeof(name)))
	{
		sock_printf(cmd->sock, "400 The command is: channel add <servertag> <channeltag> <name>\n");
		return false;
	}
	
	srv = server_find_tag(stag);
	if (!srv)
	{
		sock_printf(cmd->sock, "400 Server '%s' does not exist\n", stag);
		return false;
	}

	if (channel_find_tag(ctag))
	{
		sock_printf(cmd->sock, "400 Channel '%s' does already exist\n", ctag);
		return false;
	}

	if (channel_add(srv, name, ctag))
	{
		sock_printf(cmd->sock, "200 Added channel %s\n", ctag);
		return true;
	}
	sock_printf(cmd->sock, "400 Channel addition failed\n");
	return false;
}
Exemplo n.º 6
0
void TestQgsFields::copy()
{
    QgsFields original;
    //add field
    QgsField field( "testfield" );
    original.append( field );
    QCOMPARE( original.count(), 1 );
    QgsFields copy( original );
    QCOMPARE( copy.count(), 1 );
    QVERIFY( copy == original );

    QgsField copyfield( "copyfield" );
    copy.append( copyfield );
    QCOMPARE( copy.count(), 2 );
    QCOMPARE( original.count(), 1 );
    QVERIFY( copy != original );
}
Exemplo n.º 7
0
void TestQgsFields::assignment()
{
  QgsFields original;
  //add field
  QgsField field( QStringLiteral( "testfield" ) );
  original.append( field );

  QgsFields copy;
  copy = original;
  QVERIFY( copy == original );

  QgsField copyfield( QStringLiteral( "copyfield" ) );
  copy.append( copyfield );
  QCOMPARE( original.count(), 1 );
  QCOMPARE( copy.count(), 2 );
  QVERIFY( copy != original );
}
Exemplo n.º 8
0
bool cfg_auth_authenticate(struct cfg_state *cmd, char *args)
{
	struct MD5Context	md5;
	int			fields = countfields(args);
	char			buf[256], res[256];
	unsigned char		challenge[20];
	int			i;

	if (	fields != 1 ||
		!copyfield(args, 1, buf, sizeof(buf)))
	{
		sock_printf(cmd->sock, "400 Command is: authenticate <response>\n");
		return false;
	}

	/* Generate a MD5 from the password and the challenge */
	MD5Init(&md5);
	MD5Update(&md5, g_conf->config_password, (unsigned int)strlen((const char *)g_conf->config_password));
	MD5Update(&md5, (const unsigned char *)&cmd->challenge, (unsigned int)strlen((const char *)&cmd->challenge));
	MD5Final(challenge, &md5);

	memset(res, 0, sizeof(res));

	/* Generate the Digest */
        for (i = 0; i < 16; i++)
        {
                snprintf(&res[i*2], 3, "%02x", challenge[i]);
        }

	if (strcmp(buf, res) != 0)
	{
		sock_printf(cmd->sock, "400 Incorrect authentication token (user: '******', us: '%s')\n", buf, res);
		return false;
	}

	sock_printf(cmd->sock, "200 Welcome to The Talamasca (C) Copyright Jeroen Massar 2004 All Rights Reserved on %s\n", g_conf->service_name);

	/*
	 * The user logged in so set the level and title accordingly
	 * At the moment we don't have any user classes, thus
	 * we simply set everybody to allow Configuration commands
	 */
	cmd->level = LEVEL_CONFIG;
	return true;
}
Exemplo n.º 9
0
bool cfg_conf_set(struct cfg_state *cmd, char *args)
{
	int	fields = countfields(args);
	char	var[50], val[1024], val2[1024], val3[1024];

	/* Require a value */
	if (	fields < 2 ||
		!copyfield(args, 1, var, sizeof(var)) ||
		!copyfield(args, 2, val, sizeof(val)))
	{
		sock_printf(cmd->sock, "400 The command is: set <variable> <value> [<value> ...]\n");
		return false;
	}

	if (fields > 2) copyfield(args, 3, val2, sizeof(val2));
	if (fields > 3) copyfields(args, 4, 0, val3, sizeof(val3));

	if (strcasecmp(var, "service_name") == 0 && fields == 2)
	{
		if (g_conf->service_name) free(g_conf->service_name);
		g_conf->service_name = strdup(val);
		return true;
	}
	if (strcasecmp(var, "service_description") == 0 && fields == 2)
	{
		if (g_conf->service_description) free(g_conf->service_description);
		g_conf->service_description = strdup(val);
		return true;
	}
	if (strcasecmp(var, "admin_location1") == 0 && fields == 2)
	{
		if (g_conf->admin_location1) free(g_conf->admin_location1);
		g_conf->admin_location1 = strdup(val);
		return true;
	}
	if (strcasecmp(var, "admin_location2") == 0 && fields == 2)
	{
		if (g_conf->admin_location2) free(g_conf->admin_location2);
		g_conf->admin_location2 = strdup(val);
		return true;
	}
	if (strcasecmp(var, "admin_email") == 0 && fields == 2)
	{
		if (g_conf->admin_email) free(g_conf->admin_email);
		g_conf->admin_email = strdup(val);
		return true;
	}
	if (strcasecmp(var, "motd_file") == 0 && fields == 2)
	{
		if (g_conf->motd_file) free(g_conf->motd_file);
		g_conf->motd_file = strdup(val);
		return true;
	}
	if (strcasecmp(var, "config_password") == 0 && fields == 2)
	{
		if (g_conf->config_password) free(g_conf->config_password);
		g_conf->config_password = (unsigned char *)strdup(val);
		return true;
	}
	if (strcasecmp(var, "bitlbee_auto_add") == 0 && fields == 2)
	{
		if (	strcasecmp(val, "true") == 0 ||
			strcasecmp(val, "on") == 0)
		{
			g_conf->bitlbee_auto_add = true;
		}
		else g_conf->bitlbee_auto_add = false;
		return true;
	}

	if (strcasecmp(var, "verbose") == 0 && fields == 2)
	{
		if (	strcasecmp(val, "on") == 0 ||
			strcasecmp(val, "true") == 0 )
		{
			g_conf->verbose = true;

			/* Report back */
			sock_printf(cmd->sock, "200 Verbosity Activated\n");
			return true;
		}
		else if (strcasecmp(val, "off") == 0 ||
			strcasecmp(val, "false") == 0 )
		{
			g_conf->verbose = true;

			/* Report back */
			sock_printf(cmd->sock, "200 Verbosity Disabled\n");
			return true;
		}
		sock_printf(cmd->sock, "400 verbose only accepts 'on' and 'off' and not '%s'\n", var);
		return false;
	}

	sock_printf(cmd->sock, "400 Unknown settable value '%s' with %u fields\n", var, fields);
	return false;
}
Exemplo n.º 10
0
bool cfg_auth_login(struct cfg_state *cmd, char *args)
{
	unsigned char		secret[20] = "TheTalamasca", c, challenge[16];
	unsigned int		i,r;
	struct MD5Context	md5;
	int			fields = countfields(args);

	/* Require a username */
	if (fields != 1 ||
		!copyfield(args, 1, cmd->user, sizeof(cmd->user)))
	{
		sock_printf(cmd->sock, "400 The command is: login <username>\n");
		return false;
	}

	/*
	 * Check that the username is in lower case
	 * and contains only ascii
	 */
	for (i=0; i < strlen(cmd->user); i++)
	{
		if (	cmd->user[i] < 'a' ||
			cmd->user[i] > 'z')
		{
			sock_printf(cmd->sock, "400 Username contains unacceptable characters\n");
			return false;
		}
	}

	/* Clear out the secret */
	memset(secret, 0, sizeof(secret));

	/* Randomize the string */
	for (i=0; i < (sizeof(secret)-1); i++)
	{
		/* Pick random number between 1 and 62 */
		r = (random() % 63) + 1;

		/* [ 1,10] => [0,9] */
		if (r < 11)		c = (r+48-1);
		/* [11,36] => [A,Z] */
		else if (r < 37)	c = (r+65-10);
		/* [37,62] => [a,z] */
		else			c = (r+97-36);

		/* Randomize */
		secret[i] = c;
	}

	/* Generate a MD5 */
	MD5Init(&md5);
	MD5Update(&md5, (const unsigned char *)&secret, (unsigned int)strlen((const char *)&secret));
	MD5Final(challenge, &md5);

	memset(&cmd->challenge, 0, sizeof(cmd->challenge));

	/* Generate the Digest */
        for (i = 0; i < sizeof(challenge); i++)
        {
                snprintf(&cmd->challenge[i*2], 3, "%02x", challenge[i]);
        }

	/* Return the challenge to the client */
	sock_printf(cmd->sock, "200 %s\n", cmd->challenge);

	/* Upgrade the level */
	cmd->level = LEVEL_LOGIN;

	return true;
}
Exemplo n.º 11
0
/* server set <servertag> <variable> <value> */
bool cfg_conf_server_set(struct cfg_state *cmd, char *args)
{
	int		fields = countfields(args);
	char		tag[25], var[25], val[1000];
	struct server	*srv;
	struct channel	*ch;

	/* Add requires 8 variables */
	if (	fields != 3 ||
		!copyfield(args, 1, tag, sizeof(tag)) ||
		!copyfield(args, 2, var, sizeof(var)) ||
		!copyfield(args, 3, val, sizeof(val)))
	{
		sock_printf(cmd->sock, "400 The command is: server set <servertag> <variable> <value>\n");
		return false;
	}

	srv = server_find_tag(tag);

	if (!srv)
	{
		sock_printf(cmd->sock, "400 Server '%s' does not exist\n");
		return false;
	}

	if (strcasecmp(var, "bitlbee_identifypass") == 0)
	{
		if (srv->bitlbee_identifypass) free(srv->bitlbee_identifypass);
		srv->bitlbee_identifypass = strdup(val);
		
		sock_printf(cmd->sock, "200 Configured the BitlBee password\n");
		return true;
	}

	if (strcasecmp(var, "defaultchannel") == 0)
	{
		if (	srv->type != SRV_USER &&
			srv->type != SRV_BITLBEE)
		{
			sock_printf(cmd->sock, "400 Defaultchannels are only required for user and BitlBee links\n", val);
			return false;
		}

		ch = channel_find_tag(val);
		if (!ch)
		{
			sock_printf(cmd->sock, "400 Channel '%s' does not exist\n", val);
			return false;
		}
		srv->defaultchannel = ch;

		/* Make sure that our user is also there */
		channel_adduser(ch, srv->user);

		sock_printf(cmd->sock, "200 Configured the default channel\n");
		return true;
	}

	sock_printf(cmd->sock, "400 Unknown settable value '%s'\n", var);
	return false;
}
Exemplo n.º 12
0
Arquivo: tic.c Projeto: twikz/maiccu
struct TIC_sTunnel *tic_ListTunnels(struct TIC_conf *tic)
{
	char			buf[1024], buf2[1024];
	struct TIC_sTunnel	*start = NULL, *last = NULL, *tun = NULL;
	int			i;

/* Request a list of Tunnels */
	sock_printf(tic->sock, "tunnel list\n");

	/* Fetch the answer */
	if (sock_getline(tic->sock, tic_buf, sizeof(tic_buf), &tic_filled, buf, sizeof(buf)) == -1)
	{
		return NULL;
	}

	/* 201 (start of list) ? */
	if (buf[0] != '2' || buf[1] != '0' || buf[2] != '1')
	{
		dolog(LOG_ERR, "Couldn't list tunnels: %s.\n", &buf[4]);
		return NULL;
	}

	/* Process all the lines */
	while (sock_getline(tic->sock, tic_buf, sizeof(tic_buf), &tic_filled, buf, sizeof(buf)) != -1)
	{
		/* 202 (end of list) ? */
		if (buf[0] == '2' && buf[1] == '0' && buf[2] == '2') break;
		
		i = countfields(buf);
		if (i != 4)
		{
			dolog(LOG_ERR, "Wrong field format when listing tunnels\n");
			break;
		}

		/* Allocate a new struct */
		tun = (struct TIC_sTunnel *)malloc(sizeof(*tun));
		if (!tun)
		{
			dolog(LOG_ERR, "Memory problem while listing tunnels\n");
			break;
		}
		memset(tun, 0, sizeof(*tun));

		/* Copy the fields into the struct */
		if (!copyfield(buf, 1, buf2, sizeof(buf2))) break;
		tun->sId = strdup(buf2);
		if (!copyfield(buf, 2, buf2, sizeof(buf2))) break;
		tun->sIPv6 = strdup(buf2);
		if (!copyfield(buf, 3, buf2, sizeof(buf2))) break;
		tun->sIPv4 = strdup(buf2);
		if (!copyfield(buf, 4, buf2, sizeof(buf2))) break;
		tun->sPOPId = strdup(buf2);
		
		/* Add it into the list */
		if (last)
		{
			last->next = tun;
			last = tun;
		}
		else
		{
			start = last = tun;
		}
	}

	/* All went okay? */
	if (buf[0] == '2' && buf[1] == '0' && buf[2] == '2')
	{
		return start;
	}

	/* Free the structure, it was broken anyway */
	tic_Free_sTunnel(start);

	dolog(LOG_ERR, "Tunnel list went wrong: %s\n", &buf[4]);
	return NULL;
}