X Tutup
Skip to content

Commit 2aea588

Browse files
committed
userdbctl: drop redundant user name validity check
The userdb_by_name() invocation immediately following does the same check anyway, no need to do this twice. (Also, make sure we exit the function early on failure)
1 parent 8ff8ce6 commit 2aea588

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/userdb/userdbctl.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,16 +541,15 @@ static int ssh_authorized_keys(int argc, char *argv[], void *userdata) {
541541
_cleanup_(user_record_unrefp) UserRecord *ur = NULL;
542542
int r;
543543

544-
if (!valid_user_group_name(argv[1]))
545-
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid user name '%s'.", argv[1]);
546-
547544
r = userdb_by_name(argv[1], arg_userdb_flags, &ur);
548545
if (r == -ESRCH)
549-
log_error_errno(r, "User %s does not exist.", argv[1]);
546+
return log_error_errno(r, "User %s does not exist.", argv[1]);
550547
else if (r == -EHOSTDOWN)
551-
log_error_errno(r, "Selected user database service is not available for this request.");
548+
return log_error_errno(r, "Selected user database service is not available for this request.");
549+
else if (r == -EINVAL)
550+
return log_error_errno(r, "Failed to find user %s: %m (Invalid user name?)", argv[1]);
552551
else if (r < 0)
553-
log_error_errno(r, "Failed to find user %s: %m", argv[1]);
552+
return log_error_errno(r, "Failed to find user %s: %m", argv[1]);
554553

555554
if (strv_isempty(ur->ssh_authorized_keys))
556555
log_debug("User record for %s has no public SSH keys.", argv[1]);

0 commit comments

Comments
 (0)
X Tutup