[28847] in Source-Commits
moira commit [debian]: Add a query to only update twofactor_status and update stanley to use it.
daemon@ATHENA.MIT.EDU (Anders Kaseorg)
Wed Apr 25 23:50:16 2018
Date: Wed, 25 Apr 2018 23:49:54 -0400
From: Anders Kaseorg <andersk@mit.edu>
Message-Id: <201804260349.w3Q3nspL024830@drugstore.mit.edu>
To: source-commits@mit.edu
https://github.com/mit-athena/moira/commit/9b01e917b8060adf6f6fa70a12f80f69d1dbe208
commit 9b01e917b8060adf6f6fa70a12f80f69d1dbe208
Author: Garry Zacheiss <zacheiss@mit.edu>
Date: Thu Dec 8 16:01:37 2016 -0500
Add a query to only update twofactor_status and update stanley to use it.
moira/clients/stanley/stanley.c | 34 +++++++++++++++++++++-----------
moira/server/queries2.c | 40 +++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+), 12 deletions(-)
diff --git a/moira/clients/stanley/stanley.c b/moira/clients/stanley/stanley.c
index 6063d84..f165f07 100644
--- a/moira/clients/stanley/stanley.c
+++ b/moira/clients/stanley/stanley.c
@@ -35,7 +35,7 @@ struct string_list {
/* flags from command line */
int info_flag, update_flag, create_flag, deact_flag, reg_flag;
int list_res_flag, update_res_flag, unformatted_flag, verbose, noauth;
-int list_vpn_group_flag, set_vpn_group_flag;
+int list_vpn_group_flag, set_vpn_group_flag, set_twofactor_status_flag;
int count;
@@ -96,7 +96,7 @@ int main(int argc, char **argv)
/* clear all flags & lists */
info_flag = update_flag = create_flag = deact_flag = reg_flag = 0;
list_res_flag = update_res_flag = unformatted_flag = verbose = noauth = 0;
- list_vpn_group_flag = set_vpn_group_flag = 0;
+ list_vpn_group_flag = set_vpn_group_flag = set_twofactor_status_flag = 0;
newlogin = uid = shell = winshell = last = first = middle = NULL;
u_status = clearid = class = comment = secure = NULL;
winhomedir = winprofiledir = expiration = alternate_email = alternate_phone = NULL;
@@ -284,6 +284,7 @@ int main(int argc, char **argv)
twofactor_status = *arg;
} else
usage(argv);
+ set_twofactor_status_flag++;
}
else if (argis("lv", "listvpn")) {
list_vpn_group_flag++;
@@ -345,7 +346,8 @@ int main(int argc, char **argv)
/* default to info_flag if nothing else was specified */
if(!(info_flag || update_flag || create_flag || \
deact_flag || reg_flag || list_res_flag || \
- update_res_flag || list_vpn_group_flag || set_vpn_group_flag)) {
+ update_res_flag || list_vpn_group_flag || set_vpn_group_flag || \
+ set_twofactor_status_flag)) {
info_flag++;
}
@@ -449,13 +451,7 @@ int main(int argc, char **argv)
argv[U_ALT_EMAIL] = alternate_email;
if (alternate_phone)
argv[U_ALT_PHONE] = alternate_phone;
- if (twofactor_status)
- argv[U_TWOFACTOR] = twofactor_status;
- else
- if (!strcmp(class, "G") || !strncmp(class, "20", 2))
- argv[U_TWOFACTOR] = "0";
- else
- argv[U_TWOFACTOR] = "2";
+ argv[U_TWOFACTOR] = "2";
if (sponsor)
{
argv[U_SPONSOR_NAME] = sponsor->name;
@@ -577,8 +573,6 @@ int main(int argc, char **argv)
argv[19] = alternate_email;
if (alternate_phone)
argv[20] = alternate_phone;
- if (twofactor_status)
- argv[21] = twofactor_status;
if (sponsor)
{
argv[17] = sponsor->name;
@@ -833,6 +827,22 @@ int main(int argc, char **argv)
}
}
+ if (set_twofactor_status_flag)
+ {
+ char *args[2];
+
+ args[0] = username;
+ args[1] = twofactor_status;
+
+ status = wrap_mr_query("set_user_twofactor_status", 2, args,
+ NULL, NULL);
+ if (status)
+ {
+ com_err(whoami, status, "while setting user twofactor status.");
+ exit(1);
+ }
+ }
+
/* We're done! */
mr_disconnect();
exit(0);
diff --git a/moira/server/queries2.c b/moira/server/queries2.c
index ea38f13..ea0c61b 100644
--- a/moira/server/queries2.c
+++ b/moira/server/queries2.c
@@ -1311,6 +1311,28 @@ static struct validate supo_validate = {
set_modtime_by_id,
};
+static char *sutf_fields[] = {
+ "login",
+ "twofactor_status",
+};
+
+static struct valobj sutf_valobj[] = {
+ {V_ID, 0, USERS_TABLE, "login", "users_id", MR_USER},
+ {V_NUM, 1},
+};
+
+static struct validate sutf_validate = {
+ sutf_valobj,
+ 2,
+ 0,
+ 0,
+ 0,
+ "users_id",
+ 0,
+ 0,
+ set_modtime_by_id,
+};
+
static char *suvg_fields[] = {
"login",
"listname",
@@ -6286,6 +6308,24 @@ struct query Queries[] = {
},
{
+ /* Q_SUTF - SET_USET_TWOFACTOR_STATUS */
+ "set_user_twofactor_status",
+ "sutf",
+ 2,
+ MR_Q_UPDATE,
+ "u",
+ USERS_TABLE,
+ "users SET twofactor_status = %s",
+ sutf_fields,
+ 2,
+ 1,
+ "users_id = %d",
+ 1,
+ NULL,
+ &sutf_validate,
+ },
+
+ {
/* Q_DUSR - DELETE_USER */
"delete_user",
"dusr",