*--delete-token*::
Delete a given token. Requires *--zone* and *--ident*.
+*--change-token*::
+ Change parameters of an existing token. Currently, only the comment
+ can be changed; setting to an empty string removes the comment.
+ Requires *--zone* and *--ident*.
+
*--temp-token*::
Create a temporary token. Requires *--zone*.
Optionally, token validity can be set with *--expire* (otherwise,
op_run();
}
+static void cmd_change_token(void)
+{
+ if (!arg_zone || !arg_ident)
+ opt_failure("--zone and --ident must be given");
+
+ op_new("change-token");
+ set_string(rq, "zone", arg_zone);
+ set_string(rq, "ident", arg_ident);
+ set_string(rq, "comment", arg_comment);
+
+ op_run();
+}
+
static void cmd_create_acct(void)
{
if (!arg_zone || !arg_user)
CMD_DELETE_PASSWD,
CMD_CREATE_TOKEN,
CMD_DELETE_TOKEN,
+ CMD_CHANGE_TOKEN,
CMD_CREATE_ACCT,
CMD_DELETE_ACCT,
CMD_DELETE_USER,
[CMD_DELETE_PASSWD] = cmd_delete_passwd,
[CMD_CREATE_TOKEN] = cmd_create_token,
[CMD_DELETE_TOKEN] = cmd_delete_token,
+ [CMD_CHANGE_TOKEN] = cmd_change_token,
[CMD_CREATE_ACCT] = cmd_create_acct,
[CMD_DELETE_ACCT] = cmd_delete_acct,
[CMD_DELETE_USER] = cmd_delete_user,
OPT_SWITCH(0, "delete-passwd", command, CMD_DELETE_PASSWD, OPT_SINGLE, "\tRemove password"),
OPT_SWITCH(0, "create-token", command, CMD_CREATE_TOKEN, OPT_SINGLE, "\tCreate a new token"),
OPT_SWITCH(0, "delete-token", command, CMD_DELETE_TOKEN, OPT_SINGLE, "\tRemove an existing token"),
+ OPT_SWITCH(0, "change-token", command, CMD_CHANGE_TOKEN, OPT_SINGLE, "\tChange the comment of an existing token"),
OPT_SWITCH(0, "login", command, CMD_LOGIN, OPT_SINGLE, "\tTry to log in"),
OPT_SWITCH(0, "temp-token", command, CMD_TEMP_TOKEN, OPT_SINGLE, "\tCreate a temporary token"),
OPT_HELP(""),
}
}
+void auth_change_token_comment(struct auth_token *at, const char *comment)
+{
+ xfree(at->comment);
+ at->comment = xstrdup(comment);
+}
+
static void db_read(void)
{
struct fastbuf *fb = bopen_try(database_name, O_RDONLY, 65536);
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);
{ "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 },
void auth_set_token_passwd(struct auth_token *at, const char *passwd);
char *auth_set_token_generated(struct auth_token *at, const char *comment, struct mempool *pool);
bool auth_check_token(struct auth_token *at, const char *passwd);
+void auth_change_token_comment(struct auth_token *at, const char *comment);
extern struct auth_token *auth_fake_token;