---
name: "kafs_settoken"
section: "3"
platform: "linux"
package: "heimdal-dev"
version: "7.8.git20221117.28daf24+dfsg-9+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/kafs_settoken"
---

# kafs\_settoken(3)

AFS library

## NAME

**k\_hasafs**, **k\_hasafs\_recheck**, **k\_pioctl**, **k\_unlog**, **k\_setpag**, **k\_afs\_cell\_of\_file**, **kafs\_set\_verbose**, **kafs\_settoken\_rxkad**, **kafs\_settoken**, **krb\_afslog**, **krb\_afslog\_uid**, **kafs\_settoken5**, **krb5\_afslog**, **krb5\_afslog\_uid** – AFS library

## LIBRARY

AFS cache manager access library (libkafs, -lkafs)

## SYNOPSIS

**#include \<kafs.h\>**

*int*\

**k\_afs\_cell\_of\_file**(*const char \*path*, *char \*cell*, *int len*);

*int*\

**k\_hasafs**(*void*);

*int*\

**k\_hasafs\_recheck**(*void*);

*int*\

**k\_pioctl**(*char \*a\_path*, *int o\_opcode*, *struct ViceIoctl \*a\_paramsP*, *int a\_followSymlinks*);

*int*\

**k\_setpag**(*void*);

*int*\

**k\_unlog**(*void*);

*void*\

**kafs\_set\_verbose**(*void (\*func)(void \*, const char \*, int)*, *void \**);

*int*\

**kafs\_settoken\_rxkad**(*const char \*cell*, *struct ClearToken \*token*, *void \*ticket*, *size\_t ticket\_len*);

*int*\

**kafs\_settoken**(*const char \*cell*, *uid\_t uid*, *CREDENTIALS \*c*);

**krb\_afslog**(*char \*cell*, *char \*realm*);

*int*\

**krb\_afslog\_uid**(*char \*cell*, *char \*realm*, *uid\_t uid*);

*krb5\_error\_code*\

**krb5\_afslog\_uid**(*krb5\_context context*, *krb5\_ccache id*, *const char \*cell*, *krb5\_const\_realm realm*, *uid\_t uid*);

*int*\

**kafs\_settoken5**(*const char \*cell*, *uid\_t uid*, *krb5\_creds \*c*);

*krb5\_error\_code*\

**krb5\_afslog**(*krb5\_context context*, *krb5\_ccache id*, *const char \*cell*, *krb5\_const\_realm realm*);

## DESCRIPTION

**k\_hasafs**() initializes some library internal structures, and tests for the presence of AFS in the kernel, none of the other functions should be called before **k\_hasafs**() is called, or if it fails.

**k\_hasafs\_recheck**() forces a recheck if a AFS client has started since last time **k\_hasafs**() or **k\_hasafs\_recheck**() was called.

**kafs\_set\_verbose**() set a log function that will be called each time the kafs library does something important so that the application using libkafs can output verbose logging. Calling the function *kafs\_set\_verbose* with the function argument set to NULL will stop libkafs from calling the logging function (if set).

**kafs\_settoken\_rxkad**() set rxkad with the *token* and *ticket* (that have the length *ticket\_len*) for a given *cell*.

**kafs\_settoken**() and **kafs\_settoken5**() work the same way as **kafs\_settoken\_rxkad**() but internally converts the Kerberos 4 or 5 credential to a afs cleartoken and ticket.

**krb\_afslog**(), and **krb\_afslog\_uid**() obtains new tokens (and possibly tickets) for the specified *cell* and *realm*. If *cell* is NULL, the local cell is used. If *realm* is NULL, the function tries to guess what realm to use. Unless you  have some good knowledge of what cell or realm to use, you should pass NULL. **krb\_afslog**() will use the real user-id for the ViceId field in the token, **krb\_afslog\_uid**() will use *uid*.

**krb5\_afslog**(), and **krb5\_afslog\_uid**() are the Kerberos 5 equivalents of **krb\_afslog**(), and **krb\_afslog\_uid**().

**krb5\_afslog**(), **kafs\_settoken5**() can be configured to behave differently via a **krb5\_appdefault** option afs-use-524 in *krb5.conf*. Possible values for afs-use-524 are:

- yes

  use the 524 server in the realm to convert the ticket

- no

  use the Kerberos 5 ticket directly, can be used with if the afs cell support 2b token.

- local, 2b

  convert the Kerberos 5 credential to a 2b token locally (the same work as a 2b 524 server should have done).

Example:

```
[appdefaults]
	SU.SE = { afs-use-524 = local }
	PDC.KTH.SE = { afs-use-524 = yes }
	afs-use-524 = yes
```

libkafs will use the libkafs as application name when running the **krb5\_appdefault** function call.

The (uppercased) cell name is used as the realm to the **krb5\_appdefault** **function.**

**k\_afs\_cell\_of\_file**() will in *cell* return the cell of a specified file, no more than *len* characters is put in *cell*.

**k\_pioctl**() does a **pioctl**() system call with the specified arguments. This function is equivalent to **lpioctl**().

**k\_setpag**() initializes a new PAG.

**k\_unlog**() removes destroys all tokens in the current PAG.

## RETURN VALUES

**k\_hasafs**() returns 1 if AFS is present in the kernel, 0 otherwise. **krb\_afslog**() and **krb\_afslog\_uid**() returns 0 on success, or a Kerberos error number on failure. **k\_afs\_cell\_of\_file**(), **k\_pioctl**(), **k\_setpag**(), and **k\_unlog**() all return the value of the underlaying system call, 0 on success.

## ENVIRONMENT

The following environment variable affect the mode of operation of **kafs**:

- AFS\_SYSCALL

  Normally, **kafs** will try to figure out the correct system call(s) that are used by AFS by itself.  If it does not manage to do that, or does it incorrectly, you can set this variable to the system call number or list of system call numbers that should be used.

## EXAMPLES

The following code from **login** will obtain a new PAG and tokens for the local cell and the cell of the users home directory.

```
if (k_hasafs()) {
	char cell[64];
	k_setpag();
	if(k_afs_cell_of_file(pwd->pw_dir, cell, sizeof(cell)) == 0)
		krb_afslog(cell, NULL);
	krb_afslog(NULL, NULL);
}
```

## ERRORS

If any of these functions (apart from **k\_hasafs**()) is called without AFS being present in the kernel, the process will usually (depending on the operating system) receive a SIGSYS signal.

## SEE ALSO

[krb5\_appdefault(3)](/krb5_appdefault/3.md), [krb5.conf(5)](/krb5.conf/5.md) Transarc Corporation, “File Server/Cache Manager Interface”, *AFS-3 Programmer's Reference*, 1991.

## FILES

libkafs will search for *ThisCell* *and* *TheseCells* in the following locations: */usr/vice/etc*, */etc/openafs*, */var/db/openafs/etc*, */usr/arla/etc*, */etc/arla*, and */etc/afs*

## BUGS

AFS\_SYSCALL has no effect under AIX.
