/usr/sbin/sysadminctl success output is directed to stderr instead of stdout

Originator:cwindus
Number:rdar://34249356 Date Originated:2017-09-05
Status:New Resolved:
Product:mac OS Product Version:10.12.6
Classification:Other Reproducible:Always
 
Area:
Something not on this list

Summary:
The output of a successful `sysadminctl` is directed to stderr rather than stdout. This is atypical behaviour for command line binaries that is unexpected.

Steps to Reproduce:
1. Open up Terminal.app
2. Elevate privileges to equivalent of root using `sudo -s` and supply appropriate password.
3. Start an interactive python session with `python`
4. Use the following code to create a test account. Substitute for a valid UID for the account that is free on the test machine. In this case it is 504.
[test_macOS:~] # python
Python 2.7.10 (default, Jul 15 2017, 17:16:57) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> cmd = ['/usr/sbin/sysadminctl', '-addUser', 'test', '-fullName', 'test account', '-password', 'test_password', '-home', '/Users/test', '-UID', '504']
>>> (result, error) = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
>>> result
''
>>> error
'2017-09-05 13:15:17.155 sysadminctl[4918:25366] ----------------------------\n2017-09-05 13:15:17.155 sysadminctl[4918:25366] No clear text password or interactive option was specified (adduser, change/reset password will not allow user to use FDE) !\n2017-09-05 13:15:17.155 sysadminctl[4918:25366] ----------------------------\n2017-09-05 13:15:17.209 sysadminctl[4918:25366] Creating user record\xe2\x80\xa6\n2017-09-05 13:15:18.538 sysadminctl[4918:25366] Assigning UID: 504\n2017-09-05 13:15:18.657 sysadminctl[4918:25366] Home directory is assigned (not created!) at /Users/test\n'
>>> 


This is also confirmed by using a redirect of stderr like so:
[test_macOS:~] # /usr/sbin/sysadminctl -addUser test2 -fullName Test2 -password test_password2 -home /Users/test2 -UID 504 2> stderr_output.txt
[test_macOS:~] # less stderr_output.txt
2017-09-05 13:19:38.766 sysadminctl[5116:26342] ----------------------------
2017-09-05 13:19:38.766 sysadminctl[5116:26342] No clear text password or interactive option was specified (adduser, change/reset password will not allow user to use FDE) !
2017-09-05 13:19:38.766 sysadminctl[5116:26342] ----------------------------
2017-09-05 13:19:38.822 sysadminctl[5116:26342] Creating user record  
2017-09-05 13:19:40.164 sysadminctl[5116:26342] Assigning UID: 504
2017-09-05 13:19:40.176 sysadminctl[5116:26342] ### Error:-14135 File:/BuildRoot/Library/Caches/com.apple.xbs/Sources/Admin/Admin-670/DSRecord.m Line:418
2017-09-05 13:19:40.283 sysadminctl[5116:26342] Home directory is assigned (not created!) at /Users/test2
stderr_output.txt (END)

Expected Results:
The result should be stored in `result` which is `stdout` output.

Actual Results:
The result is stored in `error` which is `stderr`.

Version/Build:
macOS 10.12.6 (16G29) and all builds of macOS 10.13

Configuration:
N/A

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!