]> mj.ucw.cz Git - subauth.git/commitdiff
Server: Maximum comment size is limited (configurable)
authorMartin Mares <mj@ucw.cz>
Wed, 6 Sep 2017 21:01:12 +0000 (23:01 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 6 Sep 2017 21:02:32 +0000 (23:02 +0200)
Otherwise, the clients could easily overflow the maximum packet size.

etc/subauthd
server/cmd.c
server/subauthd.c
server/subauthd.h

index ea26479228bb7abb2afe2768dfb6d5383a7d8f3b..8268151ddcbb8372a626fce43ea4083e6caee0ec 100644 (file)
@@ -16,6 +16,9 @@ SubauthD {
        # Maximum packet size (default: 16k)
        MaxPacketSize   16k
 
+       # Maximum size of a user comment (default: 100)
+       MaxCommentSize  100
+
 #ifndef CONFIG_LOCAL
        # Log to a given stream (configured below)
        LogStream       syslog
index 28ec103baf920f7bd3a089c526c40aec4167ff44..106d1ef142be01c55d99bed9bc57368b14f4b413 100644 (file)
@@ -260,8 +260,12 @@ static void cmd_create_token(struct client *c)
   if (clist_size(&aa->tokens) >= aa->zone->allow_tokens)
     cmd_error(c, "Maximum number of tokens was reached");
 
+  const char *comment = get_string(c->request, "comment");
+  if (comment && strlen(comment) > max_comment_size)
+    cmd_error(c, "Comment too long");
+
   struct auth_token *at = auth_create_token(aa);
-  char *tok = auth_set_token_generated(at, get_string(c->request, "comment"), c->pool);
+  char *tok = auth_set_token_generated(at, comment, c->pool);
   set_string(c, c->reply, "token", tok);
 
   msg(L_INFO, "Created token: login=<%s> zone=<%s> id=<%s>", aa->user->login, aa->zone->name, at->ident);
index 0df6ab954c0aa6bd04209481bbd01fdd020d99f9..4d1110b2e230c04c1260f522f4392b76ea3c0459 100644 (file)
@@ -29,6 +29,7 @@ char *database_name = "subauthd.db";
 char *temp_key_file;
 char *log_stream_name;
 static uint max_packet_size = 16384;
+uint max_comment_size = 100;
 
 static struct main_file listen_socket;
 static uint num_connections;
@@ -318,6 +319,7 @@ static struct cf_section daemon_config = {
     CF_STRING("SocketPath", &socket_path),
     CF_UINT("MaxConnections", &max_connections),
     CF_UINT("MaxPacketSize", &max_packet_size),
+    CF_UINT("MaxCommentSize", &max_comment_size),
     CF_LIST("Zone", &zone_list, &zone_config),
     CF_STRING("Database", &database_name),
     CF_STRING("TempKeyFile", &temp_key_file),
index 657250075e2ba25374adf979283b0da42522c5df..1e867541ef2991231f41f3434d186bfd2ce30097 100644 (file)
@@ -29,6 +29,7 @@ struct client {
 extern clist zone_list;                        // of struct auth_zone
 extern char *database_name;
 extern char *temp_key_file;
+extern uint max_comment_size;
 
 /* cmd.c */