From patchwork Mon Aug 14 07:47:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 13352489 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA0E2C04FE0 for ; Mon, 14 Aug 2023 08:02:40 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.583427.913658 (Exim 4.92) (envelope-from ) id 1qVSWz-0006jK-Rp; Mon, 14 Aug 2023 08:02:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 583427.913658; Mon, 14 Aug 2023 08:02:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qVSWz-0006fq-Kl; Mon, 14 Aug 2023 08:02:29 +0000 Received: by outflank-mailman (input) for mailman id 583427; Mon, 14 Aug 2023 08:02:28 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qVSJi-0002SK-GQ for xen-devel@lists.xenproject.org; Mon, 14 Aug 2023 07:48:46 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ff2a92bc-3a76-11ee-b288-6b7b168915f2; Mon, 14 Aug 2023 09:48:45 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8D85C21984; Mon, 14 Aug 2023 07:48:45 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 616BE138EE; Mon, 14 Aug 2023 07:48:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id TH6NFl3c2WRRQgAAMHmgww (envelope-from ); Mon, 14 Aug 2023 07:48:45 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ff2a92bc-3a76-11ee-b288-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1691999325; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TKsSCupJgCOy14CkP0dNJUmpxlUXvXGKgcCx2Ay0CRA=; b=oR81TxzpJQCiV64A1w0J54wH4uOELCDJMrJl8x3+xsqvN8oMwrqrKeP00IbGPTAH+M6Pnc j5a7f1qpIbENbuULGu5hiYljUNjP5/wALJpe051M8hwEukBAGP1e5+aUGiiMVWf1S+dl3q W8Hyl967DMV25sk+7egIae1TRYg7E9E= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v4 17/19] tools/xenstore: introduce get_node_const() Date: Mon, 14 Aug 2023 09:47:05 +0200 Message-Id: <20230814074707.27696-18-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230814074707.27696-1-jgross@suse.com> References: <20230814074707.27696-1-jgross@suse.com> MIME-Version: 1.0 Add a variant of get_node() returning a const struct node pointer. Note that all callers of this new variant don't supply a pointer where to store the canonical node name, while all callers needing a non-const node do supply this pointer. This results in an asymmetric simplification of the two variants. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V3: - new approach (Julien Grall) --- tools/xenstore/xenstored_core.c | 35 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c index 9098b7eee2..7de4df2f28 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -1301,11 +1301,8 @@ static struct node *get_node(struct connection *conn, const void *ctx, const char *name, const char **canonical_name, unsigned int perm, bool allow_special) { - const char *tmp_name; struct node *node; - if (!canonical_name) - canonical_name = &tmp_name; *canonical_name = canonicalize(conn, ctx, name, allow_special); if (!*canonical_name) return NULL; @@ -1316,12 +1313,28 @@ static struct node *get_node(struct connection *conn, const void *ctx, ? node : NULL; } +static const struct node *get_node_const(struct connection *conn, + const void *ctx, const char *name, + unsigned int perm, bool allow_special) +{ + const char *tmp_name; + const struct node *node; + + tmp_name = canonicalize(conn, ctx, name, allow_special); + if (!tmp_name) + return NULL; + + node = read_node_const(conn, ctx, tmp_name); + + return get_node_chk_perm(conn, ctx, node, tmp_name, perm) ? node : NULL; +} + static int send_directory(const void *ctx, struct connection *conn, struct buffered_data *in) { - struct node *node; + const struct node *node; - node = get_node(conn, ctx, onearg(in), NULL, XS_PERM_READ, false); + node = get_node_const(conn, ctx, onearg(in), XS_PERM_READ, false); if (!node) return errno; @@ -1335,14 +1348,14 @@ static int send_directory_part(const void *ctx, struct connection *conn, { unsigned int off, len, maxlen, genlen; char *child, *data; - struct node *node; + const struct node *node; char gen[24]; if (xenstore_count_strings(in->buffer, in->used) != 2) return EINVAL; /* First arg is node name. */ - node = get_node(conn, ctx, in->buffer, NULL, XS_PERM_READ, false); + node = get_node_const(conn, ctx, in->buffer, XS_PERM_READ, false); if (!node) return errno; @@ -1389,9 +1402,9 @@ static int send_directory_part(const void *ctx, struct connection *conn, static int do_read(const void *ctx, struct connection *conn, struct buffered_data *in) { - struct node *node; + const struct node *node; - node = get_node(conn, ctx, onearg(in), NULL, XS_PERM_READ, false); + node = get_node_const(conn, ctx, onearg(in), XS_PERM_READ, false); if (!node) return errno; @@ -1799,11 +1812,11 @@ static int do_rm(const void *ctx, struct connection *conn, static int do_get_perms(const void *ctx, struct connection *conn, struct buffered_data *in) { - struct node *node; + const struct node *node; char *strings; unsigned int len; - node = get_node(conn, ctx, onearg(in), NULL, XS_PERM_READ, true); + node = get_node_const(conn, ctx, onearg(in), XS_PERM_READ, true); if (!node) return errno;