Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/dll/identd/identd.c
1072 views
1
/*
2
* experimental identd module for bx.
3
* adds a /set identd on/off toggle.
4
* adds a /set identd_user <username>
5
* and implements a identd server for bx. This obviously won't work unless
6
* your running as root. And is mainly meant for use with os/2 and win95
7
* ports.
8
* Copyright 1998 Colten Edwards.
9
*/
10
11
#include "irc.h"
12
#include "struct.h"
13
#include "ircaux.h"
14
#include "output.h"
15
#include "vars.h"
16
#include "module.h"
17
#define INIT_MODULE
18
#include "modval.h"
19
20
void identd_read(int s)
21
{
22
char buffer[100];
23
char *bufptr;
24
unsigned int lport = 0, rport = 0;
25
*buffer = 0;
26
bufptr = buffer;
27
if (recv(s, buffer, sizeof(buffer)-1, 0) <=0)
28
{
29
bitchsay("ERROR in identd request");
30
close_socketread(s);
31
return;
32
}
33
if (sscanf(bufptr, "%d , %d", &lport, &rport) == 2)
34
{
35
if (lport < 1 || rport < 1 || lport > 32767 || rport > 32767)
36
{
37
close_socketread(s);
38
bitchsay("ERROR port for identd bad [%d:%d]", lport, rport);
39
return;
40
}
41
sprintf(buffer, "%hu , %hu : USERID : UNIX : %s", lport, rport, get_dllstring_var("identd_user"));
42
dcc_printf(s, "%s\r\n", buffer);
43
bitchsay("Sent IDENTD request %s", buffer);
44
set_socketflags(identd, now);
45
}
46
close_socketread(s);
47
}
48
49
void identd_handler(int s)
50
{
51
struct sockaddr_in remaddr;
52
int sra = sizeof(struct sockaddr_in);
53
int sock = -1;
54
#if 0
55
if (!(get_dllint_var("identd")) || !(get_dllstring_var("identd_user")))
56
{
57
int opt = 0;
58
int optlen = sizeof(opt);
59
getsockopt(sock, SOL_SOCKET, SO_ERROR, (char *)&opt, optlen);
60
return;
61
}
62
#endif
63
if ((sock = accept(s, (struct sockaddr *) &remaddr, &sra)) > -1)
64
{
65
if (!(get_dllint_var("identd")) || !(get_dllstring_var("identd_user")))
66
{
67
close(sock);
68
return;
69
}
70
add_socketread(sock, s, 0, inet_ntoa(remaddr.sin_addr), identd_read, NULL);
71
add_sockettimeout(sock, 20, NULL);
72
}
73
}
74
75
int start_identd(void)
76
{
77
int sock = -1;
78
unsigned short port = 113;
79
if (identd != -1)
80
return -1;
81
if ((sock = connect_by_number(NULL, &port, SERVICE_SERVER, PROTOCOL_TCP, 1)) > -1)
82
add_socketread(sock, port, 0, NULL, identd_handler, NULL);
83
identd = sock;
84
return 0;
85
}
86
87
int Identd_Cleanup(IrcCommandDll **intp, Function_ptr *global_table)
88
{
89
if (identd != -1)
90
{
91
close_socketread(identd);
92
identd = -1;
93
}
94
remove_module_proc(VAR_PROC, MODULENAME, NULL, NULL);
95
return 0;
96
}
97
98
int Identd_Init(IrcCommandDll **intp, Function_ptr *global_table)
99
{
100
#if !defined(__EMX__) && !defined(WINNT)
101
if (getuid() && geteuid())
102
{
103
return -1;
104
}
105
#endif
106
initialize_module("Identd");
107
add_module_proc(VAR_PROC, MODULENAME, "identd", NULL, BOOL_TYPE_VAR, 0, NULL, NULL);
108
add_module_proc(VAR_PROC, MODULENAME, "identd_user", NULL, STR_TYPE_VAR, 0, NULL, NULL);
109
put_it("%s", convert_output_format("$G $0 v$1 by panasync", "%s %s", MODULENAME, "0.01"));
110
return start_identd();
111
}
112
113