From: Lennart Poettering Date: Fri, 22 Oct 2021 13:49:42 +0000 (+0200) Subject: homectl: validate CIFS service name before accepting it X-Git-Tag: v250-rc1~396^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16b81da684ed20aa94346f4979fa1a4e8cb1abad;p=thirdparty%2Fsystemd.git homectl: validate CIFS service name before accepting it --- diff --git a/src/home/homectl.c b/src/home/homectl.c index 3af1381eb42..502329eedd9 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");