Xau(3)

πŸ“¦
version 1.0.12 Β· 3 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0

✨ Xau β€” the X authority database besties πŸ’…

okay so this is Xau(3) from the Library Functions Manual, and it's literally the whole X authority database situation. XauFileName, XauReadAuth, XauLockAuth, XauUnlockAuth, XauWriteAuth, XauDisposeAuth, XauGetAuthByAddr, XauGetBestAuthByAddr β€” all of them, right here, no cap. πŸŽ€


🌸 SYNOPSIS 🌸

#include <X11/Xauth.h>

typedef struct xauth {
        unsigned short  family;
        unsigned short  address_length;
        char    *address;
        unsigned short  number_length;
        char    *number;
        unsigned short  name_length;
        char    *name;
        unsigned short  data_length;
        char    *data;
} Xauth;

char *XauFileName (void);

Xauth *XauReadAuth (FILE *auth_file);

int XauWriteAuth (FILE *auth_file, Xauth *auth);

Xauth *XauGetAuthByAddr (unsigned short family, unsigned short
       address_length, const char *address, unsigned short
       number_length, const char *number, unsigned short
       name_length, const char *name);

Xauth *XauGetBestAuthByAddr (unsigned short family, unsigned short
       address_length, const char *address, unsigned short
       number_length, const char *number, int types_length,
       char **types, const int *type_lengths);

int XauLockAuth (const char *file_name, int retries, int
       timeout, long dead);

int XauUnlockAuth (const char *file_name);

int XauDisposeAuth (Xauth *auth);

πŸ¦‹ DESCRIPTION πŸ¦‹

πŸ’– XauFileName

XauFileName figures out the default authorization file name for you, and it's giving very "I already know what you need" energy. First it checks the XAUTHORITY environment variable if it's set, and otherwise it hands you back $HOME/.Xauthority. 🫢

bestie listen. this name is statically allocated and should not be freed. do NOT free it. put the free() down. πŸ™ˆ

πŸ“– XauReadAuth

XauReadAuth reads the next entry from auth_file. The entry is not statically allocated, so when you're done with it you free it by calling XauDisposeAuth. every read needs its dispose, it's a whole matching set ✨

✍️ XauWriteAuth

XauWriteAuth writes an authorization entry to auth_file. It returns 1 on success, 0 on failure. simple as that, icon behavior πŸ’…

πŸ” XauGetAuthByAddr

XauGetAuthByAddr searches for an entry that matches the given network address/display number pair. and again β€” the entry is not statically allocated, so free it with XauDisposeAuth. same deal, no exceptions πŸŽ€

πŸ‘‘ XauGetBestAuthByAddr

XauGetBestAuthByAddr is basically XauGetAuthByAddr's more discerning older sister. the difference? you hand her a list of acceptable authentication methods, and Xau picks the file entry that matches the earliest entry in that list (so like… the most secure authentication method, periodt πŸ‘‘).

  • types is an array of strings β€” one string for each authentication method.
  • types_length tells it how many elements are in the types array.
  • types_lengths is an array of integers representing the length of each string.

πŸ”’ XauLockAuth

XauLockAuth does the work necessary to synchronously update an authorization file. the way she does it:

  1. First she makes two file names β€” one with -c appended to file_name, and the other with -l appended.
  2. If the -c file already exists and is more than dead seconds old, XauLockAuth removes it and the associated -l file.
  3. To prevent possible synchronization troubles with NFS, a dead value of zero forces the files to be removed. 🫣
  4. XauLockAuth makes retries attempts to create and link the file names, pausing timeout seconds between each attempt.

XauLockAuth returns a collection of values depending on the results:

  • LOCK_ERROR β€” a system error occurred, either a file_name that's too long, or an unexpected failure from a system call. errno may prove useful.
  • LOCK_TIMEOUT β€” retries attempts failed.
  • LOCK_SUCCESS β€” the lock succeeded. slay πŸ”₯

πŸ”“ XauUnlockAuth

XauUnlockAuth undoes the work of XauLockAuth by unlinking both the -c and -l file names. cleanup crew, we love to see it 🧚

πŸ—‘οΈ XauDisposeAuth

XauDisposeAuth frees storage allocated to hold an authorization entry. the little goodbye kiss at the end of every auth entry's life πŸ˜­πŸ’œ


🌈 SEE ALSO 🌈


πŸ’œ AUTHOR πŸ’œ

Keith Packard, MIT X Consortium β€” the originator, the blueprint, main character energy fr fr πŸ‘‘


and that's the whole page bestie!! this came to you from X Version 11, libXau 1.0.12, filed under Xau(3) β€” so go forth, lock your auth files, dispose your Xauth structs, and don't you dare free that statically allocated file name. ily, bye πŸ’–βœ¨πŸŽ€πŸ¦‹