diff options
author | June McEnroe <june@causal.agency> | 2020-02-11 22:39:29 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-02-11 22:39:29 -0500 |
commit | 10ae7bedbd1dac946ee97c3fb27676cde2237621 (patch) | |
tree | 9d9f3123d94681ffb9aa90b9c79211343609f1a8 | |
parent | Add chroot target (diff) | |
download | catgirl-10ae7bedbd1dac946ee97c3fb27676cde2237621.tar.gz catgirl-10ae7bedbd1dac946ee97c3fb27676cde2237621.zip |
Add -R restricted flag
-rw-r--r-- | catgirl.1 | 15 | ||||
-rw-r--r-- | chat.c | 4 | ||||
-rw-r--r-- | chat.h | 1 | ||||
-rw-r--r-- | command.c | 40 |
4 files changed, 39 insertions, 21 deletions
diff --git a/catgirl.1 b/catgirl.1 index 7c51b08..abb9dd7 100644 --- a/catgirl.1 +++ b/catgirl.1 @@ -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 diff --git a/chat.c b/chat.c index 4577bb7..14a02cb 100644 --- a/chat.c +++ b/chat.c @@ -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; diff --git a/chat.h b/chat.h index bd1ff4e..39be36e 100644 --- a/chat.h +++ b/chat.h @@ -85,6 +85,7 @@ enum Cap { extern struct Self { bool debug; + bool restricted; char *plain; const char *join; enum Cap caps; diff --git a/command.c b/command.c index 5cb43cf..3505a5e 100644 --- a/command.c +++ b/command.c @@ -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, " "); |