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: ASSIGNED --- QA Contact: LDAP QA Team <idm-ds-qe-bugs>
Severity: medium Docs Contact: Zuzana Zoubkova <zzoubkov>
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: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 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.