Menu

#7 Support passing args to the python script

1.0
closed
None
2019-12-12
2019-12-11
danielpops
No

Support passing args to the python script

I see an error when trying to pass args to my python script =>

/etc/pam.d/sshd =>

auth required pam_python.so my_pam.py --url=http://localhost:8181
Dec 11 14:57:27 the_host /lib/security/my_pam.py[26625]: AttributeError: 'module' object has no attribute 'argv'

From cursory investigation, it looks like PySys_SetArgvEx needs to be called after Py_Initialize.

https://stackoverflow.com/questions/13599724/why-is-sys-argv-not-available-in-sublime-api
https://stackoverflow.com/questions/12230210/attributeerror-module-object-has-no-attribute-argv-when-using-python-h

Discussion

  • Russell Stuart

    Russell Stuart - 2019-12-12

    The module arguments aren't passed via sys.argv. They can't be. The program your module is running in might be a python one, and in that case sys.argv will contain the command line arguments for the host program. Instead they are passed ain the manner the PAM Module Writers Guide perscribes:

    The argc and argv arguments are taken from the line appropriate
    to this module---that is, with the service_name matching that of
    the application---in the configuration file (see the Linux-PAM
    System Administrators' Guide). Together these two parameters
    provide the number of arguments and an array of pointers to the
    individual argument tokens. This will be familiar to C
    programmers as the ubiquitous method of passing command arguments
    to the function main(). Note, however, that the first argument
    (argv[0]) is a true argument and not the name of the module.
    

    Thus for the C function PAM_EXTERN int pam_sm_authenticate(pamh, flags, argc, argv) the equivalent pyhton one is pam_sm_acct_mgmt(pamh, flags, args). The args parameter contains the data you are after.

     

    Last edit: Russell Stuart 2019-12-12
  • Russell Stuart

    Russell Stuart - 2019-12-12
    • status: open --> closed
     

Log in to post a comment.