Bug 2151868

Summary: `dscreate ds-root` doesn't normalize paths
Product: Red Hat Directory Server Reporter: Viktor Ashirov <vashirov>
Component: 389-ds-baseAssignee: Pierre Rogier <progier>
Status: CLOSED ERRATA QA Contact: LDAP QA Team <idm-ds-qe-bugs>
Severity: medium Docs Contact: Evgenia Martynyuk <emartyny>
Priority: high    
Version: 12.2CC: emartyny, idm-ds-dev-bugs, mreynolds, pasik, progier
Target Milestone: DS12.3Keywords: Triaged
Target Release: dirsrv-12.3   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: sync-to-jira
Fixed In Version: redhat-ds-12-9030020230711000312-1674d57 Doc Type: Bug Fix
Doc Text:
.The `dscreate ds-root` command now normalizes paths Previously, when you created an instance under a non-root user and provided a `bin_dir` argument value that contained a trailing slash, `dscreate ds-root` failed to find the `bin_dir` value in the `$PATH` variable. As a result, the instance under a non-root user was not created. With this update, `dscreate ds-root` command normalizes paths, and the instance is created as expected.
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-11-21 15:13:16 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Viktor Ashirov 2022-12-08 11:50:43 UTC
Description of problem:
I'm trying to create an instance under non-root user. When bin_dir contains a trailing slash, dscreate fails to find it in $PATH.

Version-Release number of selected component (if applicable):
389-ds-base-2.2.4-1.module+el9dsrv+17401+48b1309a.x86_64 

How reproducible:
always

Steps to Reproduce:
$ mkdir -p bin
$ dscreate ds-root $HOME/test $HOME/bin/


Actual results:
$ dscreate ds-root $HOME/test $HOME/bin/
bin_dir argument should be before /usr/sbin in PATH
$ echo $?
1

If I remove the trailing slash, it succeeds:
$ dscreate ds-root $HOME/test $HOME/bin
$ echo $?
0

Expected results:
dscreate should normalize paths

Additional info:

Comment 1 Pierre Rogier 2022-12-08 14:49:31 UTC
I agree:  We should use os.path.samefile to compare the paths

Comment 2 Viktor Ashirov 2022-12-08 16:43:24 UTC
Not only that, but we should actually normalize the paths (os.path.normpath). User input can't be trusted. Right now dscreate gladly takes this:

$ dscreate -v ds-root $HOME/test/// $HOME/bin
DEBUG: The 389 Directory Server Creation Tool
DEBUG: Inspired by works of: ITS, The University of Adelaide
DEBUG: Called with: Namespace(verbose=True, json=False, root_dir='/home/user/test///', bin_dir='/home/user/bin', func=<function prepare_ds_root at 0x7f03b769faf0>)
DEBUG: Creating /home/user/bin/dsconf wrapper
DEBUG: Creating /home/user/bin/dscreate wrapper
DEBUG: Creating /home/user/bin/dsctl wrapper
DEBUG: Creating /home/user/bin/dsidm wrapper
DEBUG: Copying /usr/share/dirsrv/ into /home/user/test////share/dirsrv/
DEBUG: Copying /etc/dirsrv/config into /home/user/test/////etc/dirsrv/config
DEBUG: Copying /etc/dirsrv/schema into /home/user/test/////etc/dirsrv/schema
DEBUG: Creating directory /home/user/test/////tmp
DEBUG: Copying /usr/sbin/ns-slapd into /home/user/test////sbin/ns-slapd
DEBUG: Update /home/user/test////share/dirsrv/data/template-dse-minimal.ldif from /usr/share/dirsrv/data/template-dse-minimal.ldif
DEBUG: Update /home/user/test////share/dirsrv/data/template-dse.ldif from /usr/share/dirsrv/data/template-dse.ldif
DEBUG: Update /home/user/test////share/dirsrv/inf/defaults.inf from /usr/share/dirsrv/inf/defaults.inf

Or this:
$ dscreate -v ds-root test $HOME/bin
DEBUG: The 389 Directory Server Creation Tool
DEBUG: Inspired by works of: ITS, The University of Adelaide
DEBUG: Called with: Namespace(verbose=True, json=False, root_dir='test', bin_dir='/home/user/bin', func=<function prepare_ds_root at 0x7f48dc5eaaf0>)
DEBUG: Creating /home/user/bin/dsconf wrapper
DEBUG: Creating /home/user/bin/dscreate wrapper
DEBUG: Creating /home/user/bin/dsctl wrapper
DEBUG: Creating /home/user/bin/dsidm wrapper
DEBUG: Copying /usr/share/dirsrv/ into test/share/dirsrv/
DEBUG: Copying /etc/dirsrv/config into test//etc/dirsrv/config
DEBUG: Copying /etc/dirsrv/schema into test//etc/dirsrv/schema
DEBUG: Creating directory test//tmp
DEBUG: Copying /usr/sbin/ns-slapd into test/sbin/ns-slapd
DEBUG: Update test/share/dirsrv/data/template-dse-minimal.ldif from /usr/share/dirsrv/data/template-dse-minimal.ldif
DEBUG: Update test/share/dirsrv/data/template-dse.ldif from /usr/share/dirsrv/data/template-dse.ldif
DEBUG: Update test/share/dirsrv/inf/defaults.inf from /usr/share/dirsrv/inf/defaults.inf


And then fails with dscreate, because socket path is 
$ grep socket test/share/dirsrv/inf/defaults.inf
ldapi = test/run/slapd-{instance_name}.socket

So we should check if it's an absolute path too.

Comment 3 Viktor Ashirov 2023-08-15 11:57:52 UTC
Build tested: 389-ds-base-2.3.5-1.module+el9dsrv+19320+04706864.x86_64

Last test case (relative path instead of absolute) fails:
$ dscreate ds-root test $HOME/bin

$ grep socket test/share/dirsrv/inf/defaults.inf
ldapi = test/run/slapd-{instance_name}.socket

It writes relative paths to defaults.inf.

Moving to ASSIGNED.

Comment 4 Viktor Ashirov 2023-08-21 16:10:12 UTC
For the remaining problem I opened https://bugzilla.redhat.com/show_bug.cgi?id=2233176

Marking this one as VERIFIED.

Comment 6 Evgenia Martynyuk 2023-11-20 17:07:19 UTC
RN text passed all reviews

Comment 8 errata-xmlrpc 2023-11-21 15:13:16 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (redhat-ds:12 bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2023:7429