The TCFS library

In this document we describe the TCFS  development librery that provides an interface between application and the TCFS kernel. It is expected that this library will make it easier the development of new utilities for TCFS and TCFS-aware applications.

Management of the key database

The tcfs encrypion keys (tcfskeys) are stored in the file /etc/tcfspwdb in gdbm format. A record of this database has the following format;
#include < tcfslib.h>

typedef struct tcfspwdb_r {
                char user[UserLen];
                char upw[UUSIZE];
                          } tcfspwdb;
In order to manage the database, the library provide the following set of procedures. These procedures return 0 if an error occurs, else the return value is non zero.

int tcfspwdbr_new(tcfspwdb **p)
Allocates a record and store its pointer in *p.

int tcfspwdbr_edit(tcfspwdb *record, int flags, ...)
Fills the fields of the strucutre pointed to by record with the strings passed to the procedure after the flags parameter. flags specifies the fields to be filled according to the following rules.

The macros F_USR and F_UPW are defined in the file tcfspwdb.h.

int tcfspwdbr_read(tcfspwdb *record, int flags, ...)
Copies the content of the fields specified by flags following the convention adopted for tcfspwdbr_edit of the structure pointed to by record into the strings passed after flags.

int tcfspwdbr_dispose(tcfspwdb *record)
Frees the memory pointed to by record;

tcfspwdb *tcfs_getpwnam(char *name, tcfspwdb *dest)
Searches the database for a record with field user equal to the string pointed to by name and store the result in the structure pointed to by dest. If dest is NULL, the procedure allocates a record and returns it. In case of success returns a pointer to the record.

int tcfs_putpwnam(char *user, tcfspwdb *src, int flags)
Stores the record pointed to by src in the database using the key specified by user. The procedure assumes src is a new entry if flags ==U_NEW, and overwrites if flags ==U_CHG. If a record with a key specified by user and flags==U_NEW, or if no such record exists and flags==U_CHG, tcfs_putpwnam returns an error. If flags==U_DEL, the content of src is ignored, and the record with key (if exists) will be erased from the database.

int tcfs_decrypt_key(char *user, char *key, char *uuk, char **res)
Decrypts the string uuk using as key the string key and stores the pointer to the result in res. Argument user is ignored. No allocation is done.

int tcfs_encrypt_key(char *user, char *passwd, char *k, char **uuk)
As tcfs_decrypt_key but it performs encryption instead of decryption.

Keys management

int tcfs_chgkey(char *name, char *old, char *new)
Searches the database for a record with the filed user equal to name, decrypts the field upw using old and re-encrypts the resulting and stores in the database the string obtained using new. This is typically used to re-encrypt the users's key when the login password is changed.

Interfacing to TCFS

int tcfs_enable(char *u, char *tcfskey)
Enables the cryptographic filesystem for the user u, with key tcfskey.

int tcfs_enable_default(char *u, char *pass)
Enables the cryptographic filesystem for the user u, using the the default key. User must provide his UNIX password in pass in order to decrypt the key.

int tcfs_disable(char *u, int flags)
Disables the tcfs features for the user u.

int tcfs_permanent(char *u, int flags)
Sets or removes the permanent flag for the user u. If flags equals to SET, the permanent flag is set, else it is removed.

int tcfs_getcount(char *user)
Returns the counter associated to the user's key.

int tcfs_getpermanent (char *user)
Returns the status of the permenent flag.