/**
 * Copyright (C), 2024, OpenKylin, Inc
 * @file  : common/KMXauth.h
 * @date  : 2024-07-19
 * @brief : 封装xauth相关操作
 */


#include <string>
#include <sys/utsname.h>

#include "config.h" // Include ENABLE_XAUTH define

#ifdef ENABLE_XAUTH
#include <X11/Xauth.h>
#endif


#ifndef ENABLE_XAUTH
    /* When not doing Xauth, any distinct values will do, but use the same
    * ones Xauth does so that we can refer to them in our unit test. */
    # define FamilyLocal (256)	/* not part of X standard (i.e. X.h) */
    # define FamilyWild  (65535)
    # define FamilyNetname    (254)   /* not part of X standard */
    # define FamilyKrb5Principal (253) /* Kerberos 5 principal name */
    # define FamilyLocalHost (252)	/* for local non-net authentication */
#endif // !ENABLE_XAUTH

/* This is part of the X11 protocol, so we can safely hard-code it here */
#define FamilyInternet6 (6)

#ifdef ENABLE_XAUTH

class KMXauth
{
public:
    static bool authEq(const char *str, const char *auth, size_t authLen);

    static bool xauthEntryShouldPropagate(const Xauth *xa, int family, const char *remoteHostname, const char *localHostname, const char *number);

    static void writeXauth(int family, const char *remoteHostArg, const char *number, FILE *output);
};

#endif

