]> mj.ucw.cz Git - subauth.git/blobdiff - server/cmd.c
Server: create_token returns the ident of the new token
[subauth.git] / server / cmd.c
index 106d1ef142be01c55d99bed9bc57368b14f4b413..8959d078c8d94e52871e5b28c646be9bfbc0d43f 100644 (file)
@@ -267,6 +267,7 @@ static void cmd_create_token(struct client *c)
   struct auth_token *at = auth_create_token(aa);
   char *tok = auth_set_token_generated(at, comment, c->pool);
   set_string(c, c->reply, "token", tok);
+  set_string(c, c->reply, "ident", at->ident);
 
   msg(L_INFO, "Created token: login=<%s> zone=<%s> id=<%s>", aa->user->login, aa->zone->name, at->ident);
 
@@ -297,6 +298,25 @@ static void cmd_delete_token(struct client *c)
   cmd_ok(c);
 }
 
+static void cmd_change_token(struct client *c)
+{
+  struct auth_acct *aa = cmd_need_target_acct(c);
+  const char *ident = cmd_need_string(c, "ident");
+  struct auth_token *at = auth_find_token_generated(aa, ident);
+  if (!at)
+    cmd_error(c, "No such token");
+
+  const char *comment = get_string(c->request, "comment");
+  if (comment && !strcmp(comment, ""))
+    comment = NULL;
+  auth_change_token_comment(at, comment);
+
+  msg(L_INFO, "Changed token: login=<%s> zone=<%s> id=<%s>", aa->user->login, aa->zone->name, at->ident);
+
+  db_write();
+  cmd_ok(c);
+}
+
 static void cmd_create_temp(struct client *c)
 {
   struct auth_acct *aa = cmd_need_target_acct(c);
@@ -496,6 +516,7 @@ static void cmd_list_zones(struct client *c)
       set_string(c, jz, "desc", az->desc);
       set_uint(c, jz, "allow-passwd", az->allow_passwd);
       set_uint(c, jz, "allow-tokens", az->allow_tokens);
+      set_uint(c, jz, "max-temp-validity", az->max_temp_validity);
     }
 
   cmd_ok(c);
@@ -512,6 +533,7 @@ static const struct command command_table[] = {
   { "delete-acct",     cmd_delete_acct },
   { "create-token",    cmd_create_token },
   { "delete-token",    cmd_delete_token },
+  { "change-token",    cmd_change_token },
   { "set-passwd",      cmd_set_passwd },
   { "delete-passwd",   cmd_delete_passwd },
   { "create-temp",     cmd_create_temp },