示例#1
0
文件: specs.c 项目: XthemeOrg/Xtheme
static void os_cmd_specs(sourceinfo_t *si, int parc, char *parv[])
{
	user_t *tu = NULL;
	operclass_t *cl = NULL;
	const char *targettype = parv[0];
	const char *target = parv[1];
	unsigned int i;
	int j, n;

	if (!has_any_privs(si))
	{
		command_fail(si, fault_noprivs, _("You are not authorized to use %s."), si->service->nick);
		return;
	}

	if (targettype != NULL)
	{
		if (!has_priv(si, PRIV_VIEWPRIVS))
		{
			command_fail(si, fault_noprivs, STR_NO_PRIVILEGE, PRIV_VIEWPRIVS);
			return;
		}
		if (target == NULL)
			target = "?";
		if (!strcasecmp(targettype, "USER"))
		{
			tu = user_find_named(target);
			if (tu == NULL)
			{
				command_fail(si, fault_nosuch_target, _("\2%s\2 is not on IRC."), target);
				return;
			}
			if (!has_any_privs_user(tu))
			{
				command_success_nodata(si, _("\2%s\2 is unprivileged."), tu->nick);
				return;
			}
			if (is_internal_client(tu))
			{
				command_fail(si, fault_noprivs, _("\2%s\2 is an internal client."), tu->nick);
				return;
			}
		}
		else if (!strcasecmp(targettype, "OPERCLASS") || !strcasecmp(targettype, "CLASS"))
		{
			cl = operclass_find(target);
			if (cl == NULL)
			{
				command_fail(si, fault_nosuch_target, _("No such oper class \2%s\2."), target);
				return;
			}
		}
		else
		{
			command_fail(si, fault_badparams, _("Valid target types: USER, OPERCLASS."));
			return;
		}
	}
	else
		tu = si->su;

	if (targettype == NULL)
		command_success_nodata(si, _("Privileges for \2%s\2:"), get_source_name(si));
	else if (tu)
		command_success_nodata(si, _("Privileges for \2%s\2:"), tu->nick);
	else
		command_success_nodata(si, _("Privileges for oper class \2%s\2:"), cl->name);

	for (i = 0; i < ARRAY_SIZE(priv_categories); i++)
	{
		struct priv_category *cat = priv_categories[i];

		command_success_nodata(si, "\2%s\2:", _(cat->name));

		for (j = n = 0; cat->privs[j].priv != NULL; j++)
		{
			if (targettype == NULL ? has_priv(si, cat->privs[j].priv) : (tu ? has_priv_user(tu, cat->privs[j].priv) : has_priv_operclass(cl, cat->privs[j].priv)))
			{
				command_success_nodata(si, "    %s (%s)", cat->privs[j].priv, _(cat->privs[j].desc));
				++n;
			}
		}

		if (!n)
			command_success_nodata(si, "    %s", _("(no privileges held)"));
	}

	command_success_nodata(si, _("End of privileges"));

	if (targettype == NULL)
		logcommand(si, CMDLOG_ADMIN, "SPECS");
	else if (tu)
		logcommand(si, CMDLOG_ADMIN, "SPECS:USER: \2%s!%s@%s\2", tu->nick, tu->user, tu->vhost);
	else
		logcommand(si, CMDLOG_ADMIN, "SPECS:OPERCLASS: \2%s\2", cl->name);
}
示例#2
0
static void os_cmd_specs(char *origin)
{
	user_t *u = user_find_named(origin), *tu = NULL;
	operclass_t *cl = NULL;
	char *targettype = strtok(NULL, " ");
	char *target = strtok(NULL, " ");
	char nprivs[BUFSIZE], cprivs[BUFSIZE], gprivs[BUFSIZE], oprivs[BUFSIZE];
	int i;

	if (!has_any_privs(u))
	{
		notice(opersvs.nick, origin, "You are not authorized to use %s.", opersvs.nick);
		return;
	}

	if (targettype != NULL)
	{
		if (!has_priv(u, PRIV_VIEWPRIVS))
		{
			notice(opersvs.nick, origin, "You do not have %s privilege.", PRIV_VIEWPRIVS);
			return;
		}
		if (target == NULL)
			target = "?";
		if (!strcasecmp(targettype, "USER"))
		{
			tu = user_find_named(target);
			if (tu == NULL)
			{
				notice(opersvs.nick, origin, "\2%s\2 is not on IRC.", target);
				return;
			}
			if (!has_any_privs(tu))
			{
				notice(opersvs.nick, origin, "\2%s\2 is unprivileged.", tu->nick);
				return;
			}
			if (is_internal_client(tu))
			{
				notice(opersvs.nick, origin, "\2%s\2 is an internal client.", tu->nick);
				return;
			}
		}
		else if (!strcasecmp(targettype, "OPERCLASS") || !strcasecmp(targettype, "CLASS"))
		{
			cl = operclass_find(target);
			if (cl == NULL)
			{
				notice(opersvs.nick, origin, "No such oper class \2%s\2.", target);
				return;
			}
		}
		else
		{
			notice(opersvs.nick, origin, "Valid target types: USER, OPERCLASS.");
			return;
		}
	}
	else
		tu = u;

	i = 0;
	*nprivs = *cprivs = *gprivs = *oprivs = '\0';
	while (privnames[i].priv != NULL)
	{
		if (tu ? has_priv(tu, privnames[i].priv) : has_priv_operclass(cl, privnames[i].priv))
		{
			if (privnames[i].npriv != NULL)
			{
				if (*nprivs)
					strcat(nprivs, ", ");
				strcat(nprivs, privnames[i].npriv);
			}
			if (privnames[i].cpriv != NULL)
			{
				if (*cprivs)
					strcat(cprivs, ", ");
				strcat(cprivs, privnames[i].cpriv);
			}
			if (privnames[i].gpriv != NULL)
			{
				if (*gprivs)
					strcat(gprivs, ", ");
				strcat(gprivs, privnames[i].gpriv);
			}
			if (privnames[i].opriv != NULL)
			{
				if (*oprivs)
					strcat(oprivs, ", ");
				strcat(oprivs, privnames[i].opriv);
			}
		}
		i++;
	}

	if (tu)
		notice(opersvs.nick, origin, "Privileges for \2%s\2:", tu->nick);
	else
		notice(opersvs.nick, origin, "Privileges for oper class \2%s\2:", cl->name);

	if (*nprivs)
		notice(opersvs.nick, origin, "\2Nicknames/accounts\2: %s", nprivs);
	if (*cprivs)
		notice(opersvs.nick, origin, "\2Channels\2: %s", cprivs);
	if (*gprivs)
		notice(opersvs.nick, origin, "\2General\2: %s", gprivs);
	if (*oprivs)
		notice(opersvs.nick, origin, "\2OperServ\2: %s", oprivs);
	notice(opersvs.nick, origin, "End of privileges");

	if (tu)
		logcommand(opersvs.me, user_find_named(origin), CMDLOG_ADMIN, "SPECS USER %s!%s@%s", tu->nick, tu->user, tu->vhost);
	else
		logcommand(opersvs.me, user_find_named(origin), CMDLOG_ADMIN, "SPECS OPERCLASS %s", cl->name);
}