---
name: "krb5_set_error_string"
section: "3"
platform: "linux"
package: "heimdal-dev"
version: "1.2.dfsg.1-2.1+lenny1"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/krb5_have_error_string"
---

# krb5\_set\_error\_string(3)

Heimdal warning and error functions

Part of [krb5\_have\_error\_string(3)](/krb5_have_error_string/3.md).

## NAME

**krb5\_abort**, **krb5\_abortx**, **krb5\_clear\_error\_string**, **krb5\_err**, **krb5\_errx**, **krb5\_free\_error\_string**, **krb5\_get\_err\_text**, **krb5\_get\_error\_message**, **krb5\_get\_error\_string**, **krb5\_have\_error\_string**, **krb5\_set\_error\_string**, **krb5\_set\_warn\_dest**, **krb5\_get\_warn\_dest**, **krb5\_vabort**, **krb5\_vabortx**, **krb5\_verr**, **krb5\_verrx**, **krb5\_vset\_error\_string**, **krb5\_vwarn**, **krb5\_vwarnx**, **krb5\_warn**, **krb5\_warnx** – Heimdal warning and error functions

## LIBRARY

Kerberos 5 Library (libkrb5, -lkrb5)

## SYNOPSIS

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

*krb5\_error\_code*\

**krb5\_abort**(*krb5\_context context*, *krb5\_error\_code code*, *const char \*fmt*, *...*);

*krb5\_error\_code*\

**krb5\_abortx**(*krb5\_context context*, *krb5\_error\_code code*, *const char \*fmt*, *...*);

*void*\

**krb5\_clear\_error\_string**(*krb5\_context context*);

*krb5\_error\_code*\

**krb5\_err**(*krb5\_context context*, *int eval*, *krb5\_error\_code code*, *const char \*format*, *...*);

*krb5\_error\_code*\

**krb5\_errx**(*krb5\_context context*, *int eval*, *const char \*format*, *...*);

*void*\

**krb5\_free\_error\_string**(*krb5\_context context*, *char \*str*);

*krb5\_error\_code*\

**krb5\_verr**(*krb5\_context context*, *int eval*, *krb5\_error\_code code*, *const char \*format*, *va\_list ap*);

*krb5\_error\_code*\

**krb5\_verrx**(*krb5\_context context*, *int eval*, *const char \*format*, *va\_list ap*);

*krb5\_error\_code*\

**krb5\_vset\_error\_string**(*krb5\_context context*, *const char \*fmt*, *va\_list args*);

*krb5\_error\_code*\

**krb5\_vwarn**(*krb5\_context context*, *krb5\_error\_code code*, *const char \*format*, *va\_list ap*);

*krb5\_error\_code*\

**krb5\_vwarnx**(*krb5\_context context*, *const char \*format*, *va\_list ap*);

*krb5\_error\_code*\

**krb5\_warn**(*krb5\_context context*, *krb5\_error\_code code*, *const char \*format*, *...*);

*krb5\_error\_code*\

**krb5\_warnx**(*krb5\_context context*, *const char \*format*, *...*);

*krb5\_error\_code*\

**krb5\_set\_error\_string**(*krb5\_context context*, *const char \*fmt*, *...*);

*krb5\_error\_code*\

**krb5\_set\_warn\_dest**(*krb5\_context context*, *krb5\_log\_facility \*facility*);

*char \**\

*krb5\_log\_facility* *\**\

**krb5\_get\_warn\_dest**(*krb5\_context context*);

**krb5\_get\_err\_text**(*krb5\_context context*, *krb5\_error\_code code*);

*char\**\

**krb5\_get\_error\_string**(*krb5\_context context*);

*char\**\

**krb5\_get\_error\_message**(*krb5\_context context, krb5\_error\_code code*);

*krb5\_boolean*\

**krb5\_have\_error\_string**(*krb5\_context context*);

*krb5\_error\_code*\

**krb5\_vabortx**(*krb5\_context context*, *const char \*fmt*, *va\_list ap*);

*krb5\_error\_code*\

**krb5\_vabort**(*krb5\_context context*, *const char \*fmt*, *va\_list ap*);

## DESCRIPTION

These functions print a warning message to some destination. *format* is a printf style format specifying the message to print. The forms not ending in an “x” print the error string associated with *code* along with the message. The “err” functions exit with exit status *eval* after printing the message.

Applications that want to get the error message to report it to a user or store it in a log want to use **krb5\_get\_error\_message**().

The **krb5\_set\_warn\_func**() function sets the destination for warning messages to the specified *facility*. Messages logged with the “warn” functions have a log level of 1, while the “err” functions log with level 0.

**krb5\_get\_err\_text**() fetches the human readable strings describing the error-code.

**krb5\_abort**() and  **krb5\_abortx** behaves like **krb5\_err** and **krb5\_errx** but instead of exiting using the [exit(3)](/exit/3.md) call, [abort(3)](/abort/3.md) is used.

**krb5\_free\_error\_string**() frees the error string *str* returned by **krb5\_get\_error\_string**().

**krb5\_clear\_error\_string**() clears the error string from the *context*.

**krb5\_set\_error\_string**() and **krb5\_vset\_error\_string**() sets an verbose error string in *context*.

**krb5\_get\_error\_string**() fetches the error string from *context*. The error message in the context is consumed and must be freed using **krb5\_free\_error\_string**() by the caller. See also **krb5\_get\_error\_message**(), what is usually less verbose to use.

**krb5\_have\_error\_string**() returns TRUE if there is a verbose error message in the *context*.

**krb5\_get\_error\_message**() fetches the error string from the context, or if there is no customized error string in *context*, uses *code* to return a error string. In either case, the error message in the context is consumed and must be freed using **krb5\_free\_error\_string**() by the caller.

**krb5\_set\_warn\_dest**() and **krb5\_get\_warn\_dest**() sets and get the log context that is used by **krb5\_warn**() and friends.  By using this the application can control where the output should go.  For example, this is imperative to inetd servers where logging status and error message will end up on the output stream to the client.

## EXAMPLES

Below is a simple example how to report error messages from the Kerberos library in an application.

```
#include <krb5.h>
krb5_error_code
function (krb5_context context)
{
    krb5_error_code ret;
    ret = krb5_function (context, arg1, arg2);
    if (ret) {
	char *s = krb5_get_error_message(context, ret);
	if (s == NULL)
	     errx(1, "kerberos error: %d (and out of memory)", ret);
	application_logger("krb5_function failed: %s", s);
	krb5_free_error_string(context, s);
	return ret;
    }
    return 0;
}
```

## SEE ALSO

[krb5(3)](/krb5/3.md), [krb5\_openlog(3)](/krb5_openlog/3.md)
