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

Misleading error from getspnam function of spwd module #62987

Closed
vajrasky mannequin opened this issue Aug 20, 2013 · 12 comments
Closed

Misleading error from getspnam function of spwd module #62987

vajrasky mannequin opened this issue Aug 20, 2013 · 12 comments
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@vajrasky
Copy link
Mannequin

vajrasky mannequin commented Aug 20, 2013

BPO 18787
Nosy @loewis, @pitrou, @rbtcollins, @berkerpeksag, @serhiy-storchaka, @vajrasky
Files
  • fix_error_message_getspnam.patch
  • fix_error_message_getspnam_v2.patch
  • issue18787.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2016-03-19.09:44:42.280>
    created_at = <Date 2013-08-20.04:13:01.870>
    labels = ['extension-modules', 'type-bug']
    title = 'Misleading error from getspnam function of spwd module'
    updated_at = <Date 2016-03-23.20:16:18.707>
    user = 'https://github.com/vajrasky'

    bugs.python.org fields:

    activity = <Date 2016-03-23.20:16:18.707>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-03-19.09:44:42.280>
    closer = 'berker.peksag'
    components = ['Extension Modules']
    creation = <Date 2013-08-20.04:13:01.870>
    creator = 'vajrasky'
    dependencies = []
    files = ['31380', '31382', '40567']
    hgrepos = []
    issue_num = 18787
    keywords = ['patch']
    message_count = 12.0
    messages = ['195678', '195683', '195685', '195688', '195693', '233288', '247375', '251542', '251544', '262034', '262292', '262303']
    nosy_count = 7.0
    nosy_names = ['loewis', 'pitrou', 'rbcollins', 'python-dev', 'berker.peksag', 'serhiy.storchaka', 'vajrasky']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue18787'
    versions = ['Python 3.6']

    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Aug 20, 2013

    As root:

    $ sudo python3
    [sudo] password for ethan: 
    Python 3.2.3 (default, Apr 10 2013, 05:07:54) 
    [GCC 4.7.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import spwd
    >>> spwd.getspnam("I_don't_exist")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    KeyError: 'getspnam(): name not found'
    >>> spwd.getspnam("bin")
    spwd.struct_spwd(sp_nam='bin', sp_pwd='*', sp_lstchg=15259, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)

    As normal user:

    $ python3
    Python 3.2.3 (default, Apr 10 2013, 05:07:54) 
    [GCC 4.7.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import spwd
    >>> spwd.getspnam("I_don't_exist")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    KeyError: 'getspnam(): name not found'
    >>> spwd.getspnam("bin")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    KeyError: 'getspnam(): name not found'

    People can be confused. How could the name not found if the name actually exists?

    Attached the patch to differentiate the error whether the error is really 'name not found' or 'permission denied'.

    I use the error message from the getspnam manual:
    http://man7.org/linux/man-pages/man3/getspnam.3.html

    There is another error message from getspnam beside EACCES (permission denied), which is ERANGE, but I don't think we need to handle this.

    @vajrasky vajrasky mannequin added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Aug 20, 2013
    @serhiy-storchaka
    Copy link
    Member

    PyErr_SetFromErrno(PyExc_OSError) looks more appropriate for permission denied error. However this change is backward incompatible so perhaps we have to left a KeyError.

    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Aug 20, 2013

    Attached the patch to accomodate Serhiy Storchaka's suggestion by using KeyError exception for backward compatibility.

    @serhiy-storchaka
    Copy link
    Member

    It was not a suggestion, it was a doubt.

    See also bpo-10388.

    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Aug 20, 2013

    Sorry about that.

    Okay, so for now, we wait for other people's suggestion, which way we should use to handle this situation?

    @pitrou
    Copy link
    Member

    pitrou commented Jan 1, 2015

    I think we should always raise OSError if errno is non-zero (and not KeyError).

    @rbtcollins
    Copy link
    Member

    Sounds like we want something analogous to http://bugs.python.org/file33404/fix_error_message_getspall_v2.patch for this bug. Moving to patch needed.

    It looks like it would be easily tested too, so I'd like to see a test too please.

    @berkerpeksag
    Copy link
    Member

    Here is a patch with a test.

    @serhiy-storchaka
    Copy link
    Member

    As far as this change breaks compatibility. please add a note in the "Porting to Python 3.6" section in What's New.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 19, 2016

    New changeset a1d738158390 by Berker Peksag in branch 'default':
    Issue bpo-18787: spwd.getspnam() now raises a PermissionError if the user
    https://hg.python.org/cpython/rev/a1d738158390

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 23, 2016

    New changeset 430af393d8f1 by Victor Stinner in branch 'default':
    Try to fix test_spwd on OpenIndiana
    https://hg.python.org/cpython/rev/430af393d8f1

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 23, 2016

    New changeset c1677c8f92e1 by Victor Stinner in branch 'default':
    Fix test_spwd on OpenIndiana
    https://hg.python.org/cpython/rev/c1677c8f92e1

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants