From 16b81da684ed20aa94346f4979fa1a4e8cb1abad Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 22 Oct 2021 15:49:42 +0200 Subject: [PATCH] homectl: validate CIFS service name before accepting it --- src/home/homectl.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/home/homectl.c b/src/home/homectl.c index 3af1381eb4..502329eedd 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -14,6 +14,7 @@ #include "fd-util.h" #include "fileio.h" #include "format-table.h" +#include "fs-util.h" #include "glyph-util.h" #include "home-util.h" #include "homectl-fido2.h" @@ -2446,8 +2447,7 @@ static int parse_argv(int argc, char *argv[]) { case ARG_LOCATION: case ARG_ICON_NAME: case ARG_CIFS_USER_NAME: - case ARG_CIFS_DOMAIN: - case ARG_CIFS_SERVICE: { + case ARG_CIFS_DOMAIN: { const char *field = c == ARG_EMAIL_ADDRESS ? "emailAddress" : @@ -2455,7 +2455,6 @@ static int parse_argv(int argc, char *argv[]) { c == ARG_ICON_NAME ? "iconName" : c == ARG_CIFS_USER_NAME ? "cifsUserName" : c == ARG_CIFS_DOMAIN ? "cifsDomain" : - c == ARG_CIFS_SERVICE ? "cifsService" : NULL; assert(field); @@ -2475,6 +2474,25 @@ static int parse_argv(int argc, char *argv[]) { break; } + case ARG_CIFS_SERVICE: + if (isempty(optarg)) { + r = drop_from_identity("cifsService"); + if (r < 0) + return r; + + break; + } + + r = parse_cifs_service(optarg, NULL, NULL, NULL); + if (r < 0) + return log_error_errno(r, "Failed to validate CIFS service name: %s", optarg); + + r = json_variant_set_field_string(&arg_identity_extra, "cifsService", optarg); + if (r < 0) + return log_error_errno(r, "Failed to set cifsService field: %m"); + + break; + case ARG_PASSWORD_HINT: if (isempty(optarg)) { r = drop_from_identity("passwordHint"); -- 2.25.1