Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net-snmp-create-v3-user: fix directory variable references #394

Closed
wants to merge 1 commit into from
Closed

net-snmp-create-v3-user: fix directory variable references #394

wants to merge 1 commit into from

Conversation

eehakkin
Copy link

With the default configure directories, the net-snmp-create-v3-user tries to write to ${datarootdir}/snmp/snmpd.conf without setting datarootdir thus in essence it tries to write to /snmp/snmpd.conf which usually does not exist.

This patch fixes the problem by setting datarootdir and prefix (the default datarootdir is ${prefix}/share thus prefix must be set too).

@@ -134,8 +134,12 @@ if test ! -d "$outfile"; then
touch "$outfile"
fi
echo "$line" >> "$outfile"
# Avoid that configure complains that this script ignores @datarootdir@
echo "@datarootdir@" >/dev/null
prefix="@prefix@"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default this is /usr/local.

# Avoid that configure complains that this script ignores @datarootdir@
echo "@datarootdir@" >/dev/null
prefix="@prefix@"
datarootdir="@datarootdir@"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default this is ${prefix}/share.

# Avoid that shellcheck complains about unused variables.
# The data directory (@datadir@) may contain references
# to these variables.
: "${prefix}" "${datarootdir}"
outfile="@datadir@/snmp/snmpd.conf"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default this is ${datarootdir}/snmp/snmpd.conf.

@bvanassche
Copy link
Contributor

How about replacing the patch in this pull request with the patch below?

Subject: [PATCH] CHANGES: net-snmp-create-v3-user: Create snmpd.conf in the correct path

@datadir@ is expanded in ${datarootdir} so datarootdir must be set before
@datadir@ is used. See also
https://github.com/net-snmp/net-snmp/pull/394.

Fixes: d784eb53f38a ("NEWS: misc: separate user management from net-snmp-config into new net-snmp-create-v3-user script")
---
 net-snmp-create-v3-user.in | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net-snmp-create-v3-user.in b/net-snmp-create-v3-user.in
index b0c71d9676f1..00f9b4eff10c 100644
--- a/net-snmp-create-v3-user.in
+++ b/net-snmp-create-v3-user.in
@@ -134,8 +134,7 @@ if test ! -d "$outfile"; then
     touch "$outfile"
 fi
 echo "$line" >> "$outfile"
-# Avoid that configure complains that this script ignores @datarootdir@
-echo "@datarootdir@" >/dev/null
+datarootdir="@datarootdir@"
 outfile="@datadir@/snmp/snmpd.conf"
 line="$token $user"
 echo "adding the following line to $outfile:"

@eehakkin
Copy link
Author

How about replacing the patch in this pull request with the patch below?

Unfortunately that is not enough.

Subject: [PATCH] CHANGES: net-snmp-create-v3-user: Create snmpd.conf in the correct path

@datadir@ is expanded in ${datarootdir} so datarootdir must be set before
@datadir@ is used. See also

That is correct, but then @datarootdir@ is expanded in ${prefix}/share so prefix must be set before @datarootdir@ is used.

https://github.com/net-snmp/net-snmp/pull/394.

Fixes: d784eb53f38a ("NEWS: misc: separate user management from net-snmp-config into new net-snmp-create-v3-user script")
---
 net-snmp-create-v3-user.in | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net-snmp-create-v3-user.in b/net-snmp-create-v3-user.in
index b0c71d9676f1..00f9b4eff10c 100644
--- a/net-snmp-create-v3-user.in
+++ b/net-snmp-create-v3-user.in
@@ -134,8 +134,7 @@ if test ! -d "$outfile"; then
     touch "$outfile"
 fi
 echo "$line" >> "$outfile"
-# Avoid that configure complains that this script ignores @datarootdir@
-echo "@datarootdir@" >/dev/null
+datarootdir="@datarootdir@"
 outfile="@datadir@/snmp/snmpd.conf"

After expansion, this will be

datarootdir="${prefix}/share"
outfile="${datarootdir}/snmp/snmpd.conf"

while prefix is not defined anywhere while it should be.

Additionally, it is possible to pass --datadir=DIR and/or --datarootdir=DIR options to configure in which case it is possible that @datadir@ expansion does not refer to ${datarootdir} and/or @datarootdir@ expansion does not refer to ${prefix} in which case prefix and/or datarootdir may become unused variables which causes shellcheck warnings. Those can be silenced with

: "${prefix}" "${datarootdir}"

for instance.

So in the end, you cannot really leave anything away from my patch. You can of course implement it a bit differently if you wish.

 line="$token $user"
 echo "adding the following line to $outfile:"

@bvanassche
Copy link
Contributor

How about the patch below? I prefer using $datadir over $prefix since that is similar to how get_configuration_directory() builds a path.

[PATCH] CHANGES: net-snmp-create-v3-user: Create snmpd.conf in the correct path

@datadir@ is expanded in ${datarootdir} so datarootdir must be set before
@datadir@ is used. See also
https://github.com/net-snmp/net-snmp/pull/394.

Fixes: d784eb53f38a ("NEWS: misc: separate user management from net-snmp-config into new net-snmp-create-v3-user script")
---
 net-snmp-create-v3-user.in | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/net-snmp-create-v3-user.in b/net-snmp-create-v3-user.in
index b0c71d9676f1..19895a178b90 100644
--- a/net-snmp-create-v3-user.in
+++ b/net-snmp-create-v3-user.in
@@ -134,8 +134,10 @@ if test ! -d "$outfile"; then
     touch "$outfile"
 fi
 echo "$line" >> "$outfile"
-# Avoid that configure complains that this script ignores @datarootdir@
-echo "@datarootdir@" >/dev/null
+prefix=@prefix@
+datarootdir=@datarootdir@
+# To suppress shellcheck complaints about $prefix and $datarootdir.
+: "$prefix" "$datarootdir"
 outfile="@datadir@/snmp/snmpd.conf"
 line="$token $user"
 echo "adding the following line to $outfile:"

@eehakkin
Copy link
Author

Looks good to me.

bvanassche added a commit that referenced this pull request Dec 21, 2021
@datadir@ is expanded in ${datarootdir} so datarootdir must be set before
@datadir@ is used. See also
#394 .

Fixes: d784eb5 ("NEWS: misc: separate user management from net-snmp-config into new net-snmp-create-v3-user script")
@bvanassche
Copy link
Contributor

Thanks for having reported this issue. @jridky , please take a look at commit 72dee02.

@bvanassche bvanassche closed this Dec 21, 2021
@eehakkin eehakkin deleted the fix/net-snmp-create-v3-user branch December 21, 2021 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants