Product Documentation

FairCom ISAM for C

Previous Topic

Next Topic

SA_FILES

Performs FairCom DB file administration operations.

Short Name

SA_FILES()

Type

System Administration

Declaration

NINT SA_FILES(COUNT action, saFILINFO * filinfo)

Description

The SA_FILES() function performs FairCom DB file administration operations. SA_FILES() accepts action, indicating the operation to perform, and filinfo, a pointer to an saFILINFO structure containing the data used in carrying out the specified operation.

The following action values are described in detail below:

Value

Symbolic Constant

Explanation

1

ctfPASS

Change file password.

2

ctfPERM

Change file permission mask.

3

ctfGROUP

Change file group.

4

ctfOWNER

Change file owner.

filinfo points to the FILE definition structure, saFILINFO, defined below. Each action value uses specific values in the saFILINFO structure. The other values are ignored.

typedef struct

{

TEXT fil_pass[PWZ]; // File Password

TEXT fil_group[IDZ]; // File Group

TEXT fil_name[MAX_NAME]; // File name

TEXT fil_mask[16]; // File Permission mask

TEXT fil_owner[IDZ]; // File Owner

} saFILINFO;

The operations that SA_FILES() supports are described in detail below:

CHANGE FILE PASSWORD

To change the password for a file, declare a variable of type saFILINFO, set the fil_name field to the name of the file, and set the fil_pass field to the new password. Call SA_FILES() with the fPASS action and the address of your saFILINFO structure.

Example

COUNT rc;

saFILINFO filinfo;


ctsfill(&filinfo, 0, sizeof(saFILINFO));

strcpy(filinfo.fil_name, "data\\custmast.dat");

strcpy(filinfo.fil_pass, "p%9ffL2x");


if ((rc = SA_FILES(ctfPASS, &filinfo)) != 0)

printf("Change file password failed with error %d (%d).\n",

rc, isam_err);

else

printf("Successfully changed file password.\n");

CHANGE FILE PERMISSIONS

To change the security permissions for a file, declare a variable of type saFILINFO, set the fil_name field to the name of the file, and set the fil_mask field to the new permission mask. The fil_mask field is interpreted as a 15-byte permission mask containing owner, group, and world permissions:

(offset)

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

------OWNER------ ------GROUP------ ------WORLD------

r w f d p r w f d p r w f d p

r = Read w = Write f = define d = Delete p = noPass

To set a permission, set the byte at the corresponding offset of fil_mask to a value of ‘+’; to reset a specified permission, set the corresponding byte to ‘-’. In the example below, the specified mask sets all OWNER and WORLD permissions, and resets all GROUP permissions.

Call SA_FILES() with the fPERM action and the address of your saFILINFO structure.

Example

COUNT rc;

saFILINFO filinfo;


ctsfill(&filinfo, 0, sizeof(saFILINFO));

strcpy(filinfo.fil_name, "data\\custmast.dat");

strcpy(filinfo.fil_mask, "+++++-----+++++");


if ((rc = SA_FILES(ctfPERM, &filinfo)) != 0)

printf("Change file permission mask failed: Error %d (%d).\n", rc,

isam_err);

else

printf("Successfully changed file permission mask.\n");

CHANGE FILE GROUP

To change the group to which a file belongs, declare a variable of type saFILINFO, set the fil_name field to the name of the file, and set the fil_group field to the new group. Call SA_FILES() with the fGROUP action and the address of your saFILINFO structure.

Example

COUNT rc;

saFILINFO filinfo;


ctsfill(&filinfo, 0, sizeof(saFILINFO));

strcpy(filinfo.fil_name, "data\\custmast.dat");

strcpy(filinfo.fil_group, "SUPPORT");


if ((rc = SA_FILES(ctfGROUP, &filinfo)) != 0)

printf("Change file group failed with error %d (%d).\n", rc, isam_err);

else

printf("Successfully changed file group.\n");

CHANGE FILE OWNER

To change the owner for a file, declare a variable of type saFILINFO, set the fil_name field to the name of the file, and set the fil_owner field to the new owner. Call SA_FILES() with the fOWNER action and the address of your saFILINFO structure.

Example

COUNT rc;

saFILINFO filinfo;


ctsfill(&filinfo, 0, sizeof(saFILINFO));

strcpy(filinfo.fil_name, "data\\custmast.dat");

strcpy(filinfo.fil_owner, "ADMIN");


if ((rc = SA_FILES(ctfOWNER, &filinfo)) != 0)

printf("Change file owner failed with error %d (%d).\n", rc, isam_err);

else

printf("Successfully changed file owner.\n");

Return

All server administration functions return a zero value to indicate success and a non-zero value (defined in cthelp.h) to indicate failure. In the case of failure, the global variable isam_err will be set to the FairCom DB error value. See c-tree Error Codes in the FairCom DB Programmer’s Reference Guide for a complete listing of error values.

Limitations

Requires SA_LOGON() call.

See also

SA_GROUP(), SA_USERS(), SA_LOGON(), SA_LOGOF()

TOCIndex