IMPORTANT: commit dcache authorization database file to an appropriate place in cvs repository dcache.kpwd every time you change it manually or via command line interface!

Before the description of commands for manipulating of the dcache authorization database is given, the short description of how the authentication and authorization is done in dcache might be appropriate.

There are two types of authentication methods supported in dcache: cryptographically strong authentication and password based or weak authentication. Two cryptographically strong authentication mechanisms are kerberos and grid security infrastructure (gsi) based. 

First the description of cryptographically strong authentication is given.

After dcache client contacts dcache, user credentials  (kerberos ticket in case of kerberos or x509 certificate in case of gsi) are presented to dcache service and on basis of these credentials the secure id (kerberos principal or x509 certificate Distinguished Name (DN))  becomes available to the service. Example of the kerberos principal is timur@FNAL.GOV and example of DN is "/DC=gov/DC=fnal/O=Fermilab/OU=People/CN=Tim F. Perelmutov/USERID=timur".

Then client supplies a user name or special name, that tells that the user name is not available and should be derived from secure id. In later case the dcache consults the authorization database and checks if there is a "mapping" record that maps the secure id to a particular user account name (just "user" from now on). If such record does not exist, authorization fails.

Now dcache has both "secure id" and "user" for the client connection. Dcache checks the authorization database for the existence of the "login" record for the "user".
If that record contains the "secure id" in the list authorized secure ids, then  the information about the user uid, gid, user home, user root, and, optionally, user fsroot  is given to dcache and is used to determine if the user can perform requested operation.

In case of password based authentication client presents user name ("user" ) and password to the dcache. Then dcache checks that the "passwd" record exists in dcache authorization database. If it exists, then the password from the record compared with password given by client (or it could be hash values of the passwords). If passwords are the same then  the information about the user uid, gid, user home, user root, and, optionally, user fsroot  is given to dcache and is used to determine if the user can perform requested operation.

So there are tree types of records in dcache authorization database:"mapping", "login" and "password". You can learn about the structure of the database file by looking at the dcache.kpwd in dcache config direcory. The formal definition is included at the end of this README too.

1. For creating a mapping entry the dcmapadd command is used: 
 Usage: dcmapadd [-debug] "secureId" user
         where secureId is either kerberos principal or x509 cert DN

 Example:
 bash$./dcmapadd "/DC=gov/DC=fnal/O=Fermilab/OU=People/CN=Tim F. Perelmutov/USERID=timur" timur
this command will create a mapping from secure id "/DC=gov/DC=fnal/O=Fermilab/OU=People/CN=Tim F. Perelmutov/USERID=timur" to a user account "timur".

2.For modifying existing mapping entry use dcmapmod command:
 Usage: dcmapmod [-debug] "secureId" user
         where secureId is either kerberos principal or x509 cert DN
 Example:
bash$./dcmapmod "/DC=gov/DC=fnal/O=Fermilab/OU=People/CN=Tim F. Perelmutov/USERID=timur" enstore
this command will change the existing mapping (that we created with a previous command) to a mapping from secure id "/DC=gov/DC=fnal/O=Fermilab/OU=People/CN=Tim F. Perelmutov/USERID=timur" to a user account "enstore".

Note: the mappings from two different secure ids even to the same user are considered different and can coexist in the database, but two mappings from the same secure id to two different user accounts can not exist.

3.For deleting a mapping from a given secure id, command dcmapdel can be used:
 Usage: dcmapdel [-debug] "secureId"
         where secureId is either kerberos principal or x509 cert DN
 Example:
bash$ ./dcmapdel "/DC=gov/DC=fnal/O=Fermilab/OU=People/CN=Tim F. Perelmutov/USERID=timur"

4. For listing of all mapping or to view a mapping from a given secure id use dcmaplist command:
 Usage: dcmaplist [-debug] [ "secureId"]
         if secureId is not specified all mappings are listed
Example1:
bash$./dcmaplist
Example2:
bash$./dcmaplist timur@fnal.gov

5. To see all the secure ids mapped to a given user account use dcmappedtolist command:
 Usage: dcmappedtolist [-debug] user
         all secureIds that are mapped to the given user are listed
Example:
bash$./dcmappedtolist timur

6. For creating the "login" and "password" records please use dcuseradd command.
 Usage: dcuseradd [-debug] -u uid -g gid -h home -r root [-f fsroot] [-d] [-p passwd]
         [-s secureId1 [-s secureId2 [...[-s secreIdN]]]] user
         where passwd is the password to be used for weak authentication 
         and secureId is ether kerberos principal or x509 cert DN 
         if secureId contains white spaces, enclose it in double quotes (")
        uid and gid are integers in the range 1-65535 and are  user unix 
                    account uid and gid
        root is the root of the user (user is restricted to this derectory)
        home is the default derictory for the user (home is relative to root)
        if option -d is specified then the "password" record will be temporarily 
                    disabled, and can be reactived with dcusermod with a new pasword 
                    argument
        -p password specifies a password, if it is present then the new "passwd" record     
                    for the user is created.
         If one or more -s options with following secure ids are present then the new 
                    "login" record is created and all of specified secure ids will be included
                     in  the  record's secure ids list.
Example: 
bash$./dcuseradd -u 9276 -g 1530 -h / -r /pnfs/fnal.gov/usr/cdfen/jon/timur -p passWord1 -s zalokar@FNAL.GOV -s timur@FNAL.GOV -s "/O=doesciencegrid.org/OU=People/CN=Timur Perelmutov 366162" zalokar

this command will create two records, one of type "passwd" and one of type "login" each for the user zalokar, with uid=9276 gid=1530 with root = "/pnfs/fnal.gov/usr/cdfen/jon/timur" and home equal to "/". passwd record will contain password (or actually a hash value of the string ) "passWord1" and a login record will contain three secure ids: two kerberos principals zalokar@FNAL.GOV  and timur@FNAL.GOV  and one x509 certificate DN "/O=doesciencegrid.org/OU=People/CN=Timur Perelmutov 366162". This means that the user who knows the password "passWord1" for user zalokar or the owner of kerberos ticket for kerberos principals  zalokar@FNAL.GOV  or timur@FNAL.GOV, or an owner of a x509 certificate with DN "/O=doesciencegrid.org/OU=People/CN=Timur Perelmutov 366162" will be able to use dcache clients to perform transfers to or from dcache.

7. For modifying an existing "login" or "passwd" records please use dcusermod command. Please note that this command can not create a new "passwd" record for a user account for which the "login" record only have existed and ot create a new "login" record for a user account for which the "passwd" record only have existed.
dcusermod
 Usage: dcusermod [-debug] [-u uid] [-g gid] [-h home] [-r root] [-f fsroot] [-d] [-p passwd]  [-s addSecureId1 [-s addSecureId2 [...[-s addSecureIdN]]]] [-sd removeSecureId1 [-sd removeSecureId2 [...[-sd removeSecureIdN]]]]user
         where passwd is the password to be used for weak authentication 
         and secureId is ether kerberos principal or x509 cert DN 
         if secureId contains white spaces, enclose it in double quotes (")
Note that the usage is the allmost the same as for dcuseradd and the meaning of the options is exactly the same. The difference is that all options other then the "user" are optional. You can also delete secure ids using -sd option.

Example1:
bash$./dcusermod -u 10401  zalokar
this will change the uid for user account zalokar (Note: it have nothing to do with local unix accounts).
Example2:
bash$./dcusermod -sd "timur@fnal.gov"  zalokar
this will remove the kerberos ticket from the list of secure ids for user zalocar.


8. to delete user account from dcache authorization database use dcuserdel command:
 Usage: dcuserdel [-debug] user
 this will delite all "passwd" and "login" records for the user 
example:
bash$./dcuserdel timur

9. For list of existing user accounts in the dcache authorization database, or for the details of a particular user record(s) use dcuserrlist:
 Usage: dcuserlist [-debug] [user]
         if user is not specified all users (with no details) are listed
         if user is specified, then user details will be desplayed
example1:
bash$./dcuserlist timur
example:
bash$./dcuserlist 

10. to have the actual database file printed to standard out (to the screen) use dclist command:
 Usage: dclist [-debug] 
              reads kpwd data and prints the data on standard 
              out in a format suitable for kpwd file
Example:
bash$./dclist

Appendix: example of dcache database file containing the formal definition of the format of this file :

# This file was automatically generated by KAuthFile class
# Semiformal definition of the file format follows
#
# The file has the following format:
# FILE = TOKENS
# TOKENS = TOKEN | TONENS NL TOKEN
# TOKEN = COMMENT | MAPPING | RECORD | PWDRECORD | EMPTYLINE 
# NL =<new line symbol>
# WS = <any number of spaces or tabs> 
# COMMENT = WS '#' <any number of any symbols terminated by new line symbol>
# PWDRECORD =  WS passwd  WS USER WS PASSWDHASH WS UID WS GID WS HOME WS ROOT WS [FSROOT WS]
# PASSWDHASH = <hash of password generated using a crytografically strong hash function>
# PWDRECORD =  WS USER WS PASSWDHASH WS UID WS GID WS HOME WS ROOT WS [FSROOT WS]
# RECORD = USERAUTHENTICATION [SECUREIDS] EMPTYLINE 
# USERAUTHENTICATION = WS login  WS USER WS UID WS GID WS HOME WS ROOT WS [FSROOT WS]
# USER = <username (no white spaces allowed)> 
# UID = <integer> 
# GID = <integer> 
# HOME = <fully qualified unix path> 
# ROOT = <fully qualified unix path> 
# FSROOT = <fully qualified unix path> 
# SECUREIDS = SECUREIDS ([COMMENT] |[SECUREIDLINE]) NL 
# SECUREIDLINE = WS SECUREID WS NL
# SECUREID = <kerberos principal>|<grid identity (DN from x509 cert)>
# EMPTYLINE = WS NL
# MAPPING = WS mapping  WS <double quote> SECUREID <double quote> USER NL
# 

# the following are the mappings from secure credetials ids to user names
# these are used to map credentials to the default user, 
# if user is not supplied and can not be derived from credentials
# in user created files this do not have to be in a separate section

mapping "/O=doesciencegrid.org/OU=People/CN=Timur Perelmutov 366162" timur
mapping "/O=doesciencegrid.org/OU=People/CN=Bryan Hess" timur
mapping "/O=doesciencegrid.org/OU=People/CN=Alexander Sim 937593" timur
mapping "timur22@FNAL.GOV" timur
mapping "zalokar@FNAL.GOV" zalokar

# the following are the user auth records
login enstore 6209 5744 / /pnfs/fnal.gov/usr/test /pnfs/fnal.gov/usr/test
  enstore/cd/cdfensrv3.fnal.gov@FNAL.GOV

login timur 1530 10401 / /pnfs/fnal.gov/usr/cdfen /pnfs/fnal.gov/usr/cdfen
  /O=doesciencegrid.org/OU=People/CN=Timur Perelmutov 366162
  /O=doesciencegrid.org/OU=People/CN=Bryan Hess
  /DC=gov/DC=fnal/O=Fermilab/OU=People/CN=Tim F. Perelmutov/USERID=timur
  /O=doesciencegrid.org/OU=People/CN=Alexander Sim 93759
  timur@FNAL.GOV

login wellner 1530 8977 / /pnfs/fnal.gov/usr/test /pnfs/fnal.gov/usr/test
  wellner@FNAL.GOV

login bakken 1530 5406 / /pnfs/fnal.gov/usr/test /pnfs/fnal.gov/usr/test
  bakken@FNAL.GOV

login aik 1530 3015 / /pnfs/fnal.gov/usr/cdfen /pnfs/fnal.gov/usr/cdfen
  aik@FNAL.GOV

login zalokar 1530 9276 / /pnfs/fnal.gov/usr/cdfen/jon/timur /pnfs/fnal.gov/usr/cdfen/jon/timur
  timur@FNAL.GOV
  zalokar@FNAL.GOV

login kosart 5440 4147 / /pnfs/fnal.gov/usr/test/NeST /pnfs/fnal.gov/usr/test/NeST
  jon@FNAL.GOV
  timur@FNAL.GOV
  kosart@FNAL.GOV

# the following are the user passwd records
passwd timur1 c9a1de5c 10402 1530 / /pnfs/fs /pnfs/fnal.gov

passwd zalokar 956c0749 1530 9276 / /pnfs/fnal.gov/usr/cdfen/jon/timur /pnfs/fnal.gov/usr/cdfen/jon/timur

