summaryrefslogtreecommitdiff
path: root/libexec/identd/netbsd.c
blob: d357cc644d713d762989aab2f8a743eedfae4b1d (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*	$NetBSD: netbsd.c,v 1.21 2003/07/05 12:34:12 tsutsui Exp $	*/

/*
** netbsd.c		Low level kernel access functions for NetBSD
**
** This program is in the public domain and may be used freely by anyone
** who wants to. 
**
** Last update: 15 July 1998
**
** Please send bug fixes/bug reports to: Peter Eriksson <pen@lysator.liu.se>
*/

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/socket.h>

#include <netinet/in.h>
#include <netinet/ip_var.h>
#include <netinet/tcp.h>
#include <netinet/tcp_timer.h>
#include <netinet/tcp_var.h>

#include "identd.h"
#include "error.h"


int k_open()
{
  return 0;
}


/*
** Return the user number for the connection owner
*/
int k_getuid(
	struct in_addr *faddr,
	int fport,
	struct in_addr *laddr,
	int lport,
	int *uid
#ifdef ALLOW_FORMAT
	, int *pid
	, char **cmd
	, char **cmd_and_args
#endif
)
{
	int mib[8];
	uid_t myuid = -1;
	size_t uidlen = sizeof(myuid);
	int rv;

	mib[0] = CTL_NET;
	mib[1] = PF_INET;
	mib[2] = IPPROTO_TCP;
	mib[3] = TCPCTL_IDENT;
	mib[4] = (int)faddr->s_addr;
	mib[5] = fport;
	mib[6] = (int)laddr->s_addr;
	mib[7] = lport;

	if ((rv = sysctl(mib, sizeof(mib) / sizeof(mib[0]), &myuid, &uidlen,
	    NULL, 0)) < 0) {
		ERROR1("k_getuid: sysctl 1: %s", strerror(errno));
		return -1;
	}

	*uid = myuid;
	return 0;
}