This file is indexed.

/usr/share/gocode/src/github.com/lxc/lxd/lxd/devlxd_gccgo.go is in golang-github-lxc-lxd-dev 2.0.2-0ubuntu1~16.04.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// +build gccgo
// +build cgo

package main

import (
	"errors"
)

/*
#define _GNU_SOURCE
#include <sys/socket.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>

void getucred(int sock, uint *uid, uint *gid, int *pid) {
	struct ucred peercred;
	socklen_t len;

	len = sizeof(struct ucred);

	if (getsockopt(sock, SOL_SOCKET, SO_PEERCRED, &peercred, &len) != 0 || len != sizeof(peercred)) {
		fprintf(stderr, "getsockopt failed: %s\n", strerror(errno));
		return;
	}

	*uid = peercred.uid;
	*gid = peercred.gid;
	*pid = peercred.pid;

	return;
}
*/
import "C"

func getUcred(fd int) (uint32, uint32, int32, error) {
	uid := C.uint(0)
	gid := C.uint(0)
	pid := C.int(-1)

	C.getucred(C.int(fd), &uid, &gid, &pid)

	if uid == 0 || gid == 0 || pid == -1 {
		return 0, 0, -1, errors.New("Failed to get the ucred")
	}

	return uint32(uid), uint32(gid), int32(pid), nil
}