Red Hat Bugzilla – Bug 211089
"id -Z root" throws an error when running as root
Last modified: 2007-11-30 17:07:35 EST
# id -Z root
id: cannot display context when selinux not enabled or when displaying the id
# id -Z
The attached patch tries to check whether the username passed is the same as the
current one, and displays the context properly:
# id -Z root
Created attachment 138673 [details]
No, I don't really like this patch. Why would you run 'id -Z root'? Its output
is nothing like that of 'id root', even if that's the user running the command.
'id -Z' has special output not like any other options.
It's a similar situation to the reason 'id' is different to 'id root' -- one is
contextual and depends on the environment and history of the (parent) process,
the other is not and just reads the user database.
Then please consider this a request to fix the usage output, the man page, and
the wrongly worded error message.
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux major release. Product Management has requested further
review of this request by Red Hat Engineering, for potential inclusion in a Red
Hat Enterprise Linux Major release. This request is not yet committed for
Created attachment 141473 [details]
How about this?
Would still need man page and usage output changes, but looks good.
Do you think adding 'of the current process' is sufficient? Otherwise, would
you like to suggest alternate wording? Thanks.
+ error (1, 0, _("\
+cannot display context when not displaying current user"));
when I do "id -Z root", it is displaying the current user.
The usage and man page need to make it clear that "-Z" is stand-alone, and not
an option to which you can append a username.
Running 'id' without a user-name is asking it to tell you "the current user".
id basically has two modes: telling you about the "current" anything (effective
user ID, security context, group list), and telling you things from the pw
database. The first is related to the context in which you have run 'id'; the
second is nothing to do with that context, and just reports objective facts from
the system-wide pw database.
When you add 'root' to the command line, you are trying to ask about something
in the pw database, not something related to the context in which 'id' is
running -- but that sort of usage makes no sense with -Z. There are no
objective facts about security contexts to look up in the pw database. Were you
trying to find out the default SELinux context for root logging in? It's a more
complicated question than that.
I still don't really understand why you are trying to run it like this. I don't
really understand why you will ever see this error message. What do you really
expect 'id -Z root' to tell you?
(In reply to comment #11)
> I still don't really understand why you are trying to run it like this. I don't
> really understand why you will ever see this error message. What do you really
> expect 'id -Z root' to tell you?
Because the man page:
id [OPTION]... [USERNAME]
and the usage output:
Usage: id [OPTION]... [USERNAME]
tell me I can.
I expect "id -Z root" to work as in comment 0, or for the usage and man pages to
I'm going to change the error to this then:
id: cannot print security context in default format
modelled on the error message you get from 'id -r root'.
(In reply to comment #13)
> I'm going to change the error to this then:
> id: cannot print security context in default format
> modelled on the error message you get from 'id -r root'.
Not the most eloquent of error messages, but I guess it's better than a
misleading one :)
Or even better:
id: cannot print security context when user specified
QE ack for RHEL5.
A package has been built which should help the problem described in
this bug report. This report is therefore being closed with a resolution
of CURRENTRELEASE. You may reopen this bug report if the solution does
not work for you.