Duc
Duc

Reputation: 507

How to use XauGetAuthByAddr

This function seems pretty straightforward, but I can't get it to return results. I wrote a little helper program to try to figure out what parameters it wants:

#include <iostream>
#include <string.h>

#include <X11/X.h>
#include <X11/Xauth.h>

int main(int argc, char * argv[])
{
    Xauth * xauth_ptr = XauGetAuthByAddr(FamilyInternet,
                                         strlen(argv[1]),
                                         argv[1],
                                         strlen(argv[2]),
                                         argv[2],
                                         strlen("MIT-MAGIC-COOKIE-1"),
                                         "MIT-MAGIC-COOKIE-1");
    if (!xauth_ptr)
    {
        std::cerr << "Could not look up " << argv[1] << ":" << argv[2] << std::endl;
        return -1;
    }

    std::cout << "Name: " << xauth_ptr->name << std::endl;
    return 0;
}

xauth list displays what I should be able to look up:

$ xauth list
ubuntu/unix:17  MIT-MAGIC-COOKIE-1  181bc2c2aa5c9e7b8d5bde61d2dbe6bb
ubuntu/unix:18  MIT-MAGIC-COOKIE-1  7ef7984fb5d2f18083ffc8b16f675c66
ubuntu/unix:15  MIT-MAGIC-COOKIE-1  c6c31dc60627288c0b3b4d1768cc490d
ubuntu/unix:16  MIT-MAGIC-COOKIE-1  05dfde3b782fda7df4aaf8a840645bba

I've fed my program '127.0.0.1', my actual IP, 'localhost', 'ubuntu', 'ubuntu/unix' to no avail. Thanks for helping.

Upvotes: 0

Views: 107

Answers (1)

alanc
alanc

Reputation: 4180

You've specified FamilyInternet (indicating a TCP address) but all your sample addresses from xauth list are marked /unix, indicating they're Unix domain sockets addressed via FamilyLocal as you can see in the dump_entry function in the xauth sources.

Upvotes: 1

Related Questions