Add -R restricted flag

master
C. McEnroe 2020-02-11 22:39:29 -05:00
parent 252428f97a
commit 10ae7bedbd
4 changed files with 39 additions and 21 deletions

View File

@ -1,4 +1,4 @@
.Dd February 10, 2020
.Dd February 11, 2020
.Dt CATGIRL 1
.Os
.
@ -8,7 +8,7 @@
.
.Sh SYNOPSIS
.Nm
.Op Fl ev
.Op Fl Rev
.Op Fl C Ar copy
.Op Fl H Ar hash
.Op Fl O Ar open
@ -70,6 +70,17 @@ The default is the first available of
.Xr open 1 ,
.Xr xdg-open 1 .
.
.It Fl R , Cm restrict
Disable the
.Ic /copy ,
.Ic /debug ,
.Ic /join ,
.Ic /msg ,
.Ic /open ,
.Ic /query ,
.Ic /quote
commands.
.
.It Fl a Ar user Ns : Ns Ar pass , Cm sasl-plain = Ar user Ns : Ns Ar pass
Authenticate as
.Ar user

4
chat.c
View File

@ -93,12 +93,13 @@ int main(int argc, char *argv[]) {
const char *user = NULL;
const char *real = NULL;
const char *Opts = "!C:H:O:a:c:eh:j:k:n:p:r:s:u:vw:";
const char *Opts = "!C:H:O:Ra:c:eh:j:k:n:p:r:s:u:vw:";
const struct option LongOpts[] = {
{ "insecure", no_argument, NULL, '!' },
{ "copy", required_argument, NULL, 'C' },
{ "hash", required_argument, NULL, 'H' },
{ "open", required_argument, NULL, 'O' },
{ "restrict", no_argument, NULL, 'R' },
{ "sasl-plain", required_argument, NULL, 'a' },
{ "cert", required_argument, NULL, 'c' },
{ "sasl-external", no_argument, NULL, 'e' },
@ -122,6 +123,7 @@ int main(int argc, char *argv[]) {
break; case 'C': urlCopyUtil = optarg;
break; case 'H': hashInit = strtoul(optarg, NULL, 0);
break; case 'O': urlOpenUtil = optarg;
break; case 'R': self.restricted = true;
break; case 'a': sasl = true; self.plain = optarg;
break; case 'c': cert = optarg;
break; case 'e': sasl = true;

1
chat.h
View File

@ -85,6 +85,7 @@ enum Cap {
extern struct Self {
bool debug;
bool restricted;
char *plain;
const char *join;
enum Cap caps;

View File

@ -194,25 +194,26 @@ static void commandHelp(size_t id, char *params) {
static const struct Handler {
const char *cmd;
Command *fn;
bool restricted;
} Commands[] = {
{ "/close", commandClose },
{ "/copy", commandCopy },
{ "/debug", commandDebug },
{ "/help", commandHelp },
{ "/join", commandJoin },
{ "/me", commandMe },
{ "/msg", commandMsg },
{ "/names", commandNames },
{ "/nick", commandNick },
{ "/notice", commandNotice },
{ "/open", commandOpen },
{ "/part", commandPart },
{ "/query", commandQuery },
{ "/quit", commandQuit },
{ "/quote", commandQuote },
{ "/topic", commandTopic },
{ "/whois", commandWhois },
{ "/window", commandWindow },
{ "/close", .fn = commandClose },
{ "/copy", .fn = commandCopy, .restricted = true },
{ "/debug", .fn = commandDebug, .restricted = true },
{ "/help", .fn = commandHelp },
{ "/join", .fn = commandJoin, .restricted = true },
{ "/me", .fn = commandMe },
{ "/msg", .fn = commandMsg, .restricted = true },
{ "/names", .fn = commandNames },
{ "/nick", .fn = commandNick },
{ "/notice", .fn = commandNotice },
{ "/open", .fn = commandOpen, .restricted = true },
{ "/part", .fn = commandPart },
{ "/query", .fn = commandQuery, .restricted = true },
{ "/quit", .fn = commandQuit },
{ "/quote", .fn = commandQuote, .restricted = true },
{ "/topic", .fn = commandTopic },
{ "/whois", .fn = commandWhois },
{ "/window", .fn = commandWindow },
};
static int compar(const void *cmd, const void *_handler) {
@ -258,6 +259,9 @@ void command(size_t id, char *input) {
const struct Handler *handler = bsearch(
cmd, Commands, ARRAY_LEN(Commands), sizeof(*handler), compar
);
if (self.restricted && handler && handler->restricted) {
handler = NULL;
}
if (handler) {
if (input) {
input += strspn(input, " ");