summaryrefslogtreecommitdiff
path: root/libexec/identd/proxy.c
blob: beaa85b229e1f034cb764bcee1b85a89296986c6 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*	$NetBSD: proxy.c,v 1.5 1998/07/15 07:31:57 msaitoh Exp $	*/

/*
** proxy.c                         This file implements the proxy() call.
**
** This program is in the public domain and may be used freely by anyone
** who wants to. 
**
** Last update: 12 Dec 1992
**
** Please send bug fixes/bug reports to: Peter Eriksson <pen@lysator.liu.se>
*/

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

#include <sys/types.h>
#include <sys/time.h>
#include <netinet/in.h>

#include "identd.h"

#ifdef INCLUDE_PROXY
int proxy __P((struct in_addr *, struct in_addr *, int, int, struct timeval *));
#else
int proxy __P((void *, void *, int, int, void *));
#endif

/*
** This function should establish a connection to a remote IDENT
** server and query it for the information associated with the
** specified connection and the return that to the caller.
**
** Should there be three different timeouts (Connection Establishment,
** Query Transmit and Query Receive)?
*/
int proxy(laddr, faddr, lport, fport, timeout)
#ifdef INCLUDE_PROXY
    struct in_addr *laddr;
    struct in_addr *faddr;
#else
    void *laddr, *faddr;
#endif
    int lport;
    int fport;
#ifdef INCLUDE_PROXY
    struct timeval *timeout;
#else
    void *timeout;
#endif
{
#ifndef INCLUDE_PROXY
    /* Just here to make the compiler shut up! */
    laddr = faddr = NULL;
    timeout = NULL;
	
    printf("%d , %d : ERROR : %s\r\n",
	   lport, fport,
	   unknown_flag ? "UNKNOWN-ERROR" : "X-NOT-YET-IMPLEMENTED");
    
    return -1;
#else
  id_t *idp;
  char *answer;
  char *opsys;
  char *charset;
  
  idp = id_open(laddr, faddr, timeout);
  if (!idp)
  {
    printf("%d , %d : ERROR : %s\r\n",
	   lport, fport,
	   unknown_flag ? "UNKNOWN-ERROR" : "X-CONNECTION-REFUSED");
    return -1;
  }

  if (id_query(idp, lport, fport, timeout) < 0)
  {
    printf("%d , %d : ERROR : %s\r\n",
	   lport, fport,
	   unknown_flag ? "UNKNOWN-ERROR" : "X-TRANSMIT-QUERY-ERROR");
    id_close(idp);
    return -1;
  }

  switch (id_parse(idp, timeout, &lport, &fport, &answer, &opsys, &charset))
  {
    case 1:
      printf("%d , %d : USERID : %s %s%s : %s\r\n",
	     lport, fport,
	     opsys,
	     charset ? "," : "",
	     charset ? charset : "",
	     answer);
      break;
      
    case 2:
      printf("%d , %d : ERROR : %s\r\n",
	     lport, fport, answer);
      break;
      
    case 0:  /* More to parse - fix this later! */
    case -1: /* Internal error */
    default:
      printf("%d , %d : ERROR : %s\r\n",
	     lport, fport,
	     unknown_flag ? "UNKNOWN-ERROR" : "X-PARSE-REPLY-ERROR");
  }

  id_close(idp);
#endif  
}