(PYVMS LOGO) Python on OpenVMS

(go to: table of contents, index, list of pyvms, prev: HISTORY_SHOW)


UAF_GET_USERNAMES - Get list of usernames from authorization file


Returns a list of all usernames that exist in SYSUAF.DAT

pyvms.uaf_get_usernames() does _not_ raise an exception when one of the system services (SYS$OPEN, SYS$CONNECT, SYS$GET, SYS$CLOSE) returns an error. The routine stores two additional keys in the dictionary that is returned to the user.

Warning! This routine requires file access to SYSUAF.DAT. The Python executable should NOT be installed with privileges to provide this access. The interpreter and its VMS extensions have NO safeguards build in to limit privilege usage to this routine!

Note: the system services SYS$GETUAI and SYS$SETUAI provide a 'context' argument, but it can only be used for repeated access to the SAME username.

Format:

    dict = vms_lib.uaf_get_usernames ()
Returns:
dict
A dictionary that has the following keys:
'sts'
The condition value returned in FAB$L_STS or RAB$L_STS.
'stv'
the condition value returned in FAB$L_STS or RAB$L_STS.
'usernames'
A list of all usernames that are stored in SYSUAF.DAT. If no access to the file can be established, then this key is missing.
Arguments:

None

Examples:

>>> import pyvms

>>> dict = pyvms.uaf_get_usernames ()

>>> type (dict)
<type 'dictionary'>

>>> dict
{'sts': 98938, 'stv': 0, 'usernames': ['DECNET', 'DEFAULT',
'FAL$SERVER', 'FIELD', 'GETUAI_TST', 'HTTP_SERVER', 'MAIL$SERVER',
'MIRRO$SERVER', 'NML$SERVER', 'NOPRIV', 'PHONE$SERVER', 'RAYTRACE',
'SETUAI_TST', 'SYSTEM', 'SYSTEST', 'SYSTEST_CLIG', 'SYS_ARCHIVE',
'SYS_BACKUP', 'SYS_CRON', 'SYS_MONITOR', 'UCX$BIND', 'UCX$FTP',
'UCX$PORTM', 'UUCP_DAEMON', 'UUCP_LOGIN', 'UUCP_TEST', 'VPM$SERVER',
'ZESSIN']}

>>> sts = dict.get('sts')
>>> import vms_sys
>>> print vms_sys.getmsg (sts)
('%RMS-E-EOF, end of file detected', (0, 0, 0, 0))
>>>

>>> usernames = dict.get('usernames')

>>> dict = pyvms.uaf_get_usernames (None,None,'UAF_GET_USERNAMES_TST', \
...   ('UAI$_OWNER', 'UAI$_EXPIRATION'))
>>> returned_items = dict.items()
>>> returned_items.sort()
>>> for itm in range(len(returned_items)):
...   print returned_items[itm]
...
('UAI$_EXPIRATION', 44585444967800000L)
('UAI$_OWNER', 'PYVMS-uaf_get_usernames-TEST')
('status', 1)
>>>

>>> q_expdat = dict.get('UAI$_EXPIRATION')
>>> q_expdat
44585444967800000L
>>> type (q_expdat)
<type 'long int'>
>>> pyvms.asctim (q_expdat)
'29-FEB-2000 12:34:56.78'
>>>


>>> # UAI$_CPUTIM is expressed in 10ms steps
>>> # this example shows how to make this into a delta-time

>>> dict = pyvms.uaf_get_usernames (None,None,'UAF_GET_USERNAMES_TST', \
...                                 ('UAI$_CPUTIM',))
>>> #                                             ^
>>> # even a single item-code must be passed as a tuple

>>> l_cputim = dict.get('UAI$_CPUTIM')
>>> # convert 10ms ticks into 100ns ticks
>>> q_cputim = l_cputim * 100000L
>>> # a delta-time must be negative
>>> q_cputim = -q_cputim
>>> # show ASCII representation
>>> pyvms.asctim (q_cputim)
'  11 22:33:44.55'
>>>


>>> dict = pyvms.uaf_get_usernames (None,None,'UAF_GET_USERNAMES_TST',
... ('UAI$_EXPIRATION'
... ,'UAI$_LASTLOGIN_I'
... ,'UAI$_LASTLOGIN_N'
... ,'UAI$_PWD_DATE'
... ,'UAI$_PWD2_DATE'
... ,'UAI$_PWD_LIFETIME'
... ))
>>>

>>> for key in dict.keys():
...   if (key != 'status'):
...     print key, pyvms.asctim (dict.get(key))
...
UAI$_EXPIRATION 29-FEB-2000 12:34:56.78
UAI$_LASTLOGIN_I 17-NOV-1858 00:00:00.00  <-- no login, yet
UAI$_PWD2_DATE 17-NOV-1858 00:00:00.00
UAI$_PWD_DATE    0 00:00:00.00
UAI$_PWD_LIFETIME   12 21:43:56.87
UAI$_LASTLOGIN_N 17-NOV-1858 00:00:00.00
>>>


>>> # UIC of username
>>> dict = pyvms.uaf_get_usernames (None,None,'UAF_GET_USERNAMES_TST',
...   ('UAI$_GRP','UAI$_MEM'))
>>> w_grp = dict.get('UAI$_GRP')
>>> w_mem = dict.get('UAI$_MEM')
>>> # oct() puts a '0' in front - [1:] removes this
>>> t_uic = '[' + oct(w_grp)[1:] + ',' + oct(w_mem)[1:] + ']'
>>> t_uic
'[12345,13524]'
>>>


>>> # calculate date of next password expiration
>>> # 'dict' is from a different account

>>> dict = pyvms.uaf_get_usernames (None,None,'NOPRIV',
...   ('UAI$_PWD_DATE','UAI$_PWD_LIFETIME'))
>>> q_expdate = dict.get('UAI$_PWD_DATE') + \
...             dict.get('UAI$_PWD_LIFETIME')
>>> pyvms.asctim (dict.get('UAI$_PWD_DATE'))
'25-SEP-1998 20:10:42.78'
>>> pyvms.asctim (dict.get('UAI$_PWD_LIFETIME'))
'  30 00:00:00.00'
>>> pyvms.asctim (q_expdate)
'26-AUG-1998 20:10:42.78'
>>>


>>> # try access to a non-existent username
>>> dict = pyvms.uaf_get_usernames (None,None,'NO_USER',('UAI$_FILLM',))
>>> l_status = dict.get('status')
>>> l_status
98994
>>>
>>> pyvms.getmsg (l_status)[0]
'%RMS-E-RNF, record not found'
>>>


------------------------------

>>> dict = pyvms.uaf_get_usernames ('BAD-ARG')
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: function requires exactly 0 arguments; 1 given
>>>


>>> # no privilege to access SYSUAF.DAT
>>> dict = pyvms.uaf_get_usernames ()
>>> dict
{'sts': 98970, 'stv': 36}
>>> sts = dict.get('sts')
>>> print vms_sys.getmsg (sts)
('%RMS-E-PRV, insufficient privilege or file protection violation',\
 (0, 0, 0, 0))
>>> stv = dict.get('stv')
>>> print vms_sys.getmsg (stv)
('%SYSTEM-F-NOPRIV, insufficient privilege or object protection\
 violation', (0, 0, 0, 0))
>>>


$ define SYSUAF XX

>>> import vms_sys
>>> dict = pyvms.uaf_get_usernames ()
>>> dict
{'sts': 98962, 'stv': 2320}

>>> sts = dict.get('sts')
>>> print vms_sys.getmsg (sts)
('%RMS-E-FNF, file not found', (0, 0, 0, 0))
>>> stv = dict.get('stv')
>>> print vms_sys.getmsg (stv)
('%SYSTEM-W-NOSUCHFILE, no such file', (0, 0, 0, 0))
>>>


$ define sysuaf no_disk:[000000]SYSUAF.DAT

>>> dict = pyvms.uaf_get_usernames ()
>>> dict
{'sts': 99524, 'stv': 324}
>>> sts = dict.get('sts')
>>> print vms_sys.getmsg (sts)
('%RMS-F-DEV, error in device name or inappropriate device type\
 for operation', (0, 0, 0, 0))
>>> stv = dict.get('stv')
>>> print vms_sys.getmsg (stv)
('%SYSTEM-F-IVDEVNAM, invalid device name', (0, 0, 0, 0))
>>>

(go to: table of contents, index, list of pyvms, prev: HISTORY_SHOW)

22-NOV-1998 ZE.