blob: 26767a516895e32639d5479648e1566a6d42d486 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// MorgenGrauen MUDlib
2//
3// master/network.c - UDP-Handling
4//
5// $Id: network.c 8934 2014-09-10 21:57:12Z Zesstra $
6
7#pragma strict_types
8
9#include "/secure/master.h"
10#define BBMASTER "/secure/bbmaster"
11
12/*
13#undef DEBUG
14#define DEBUG(x) if (call_sefun("find_player","zesstra")) \
15 tell_object(call_sefun("find_player","zesstra"),x);
16*/
17
18//ich will hieraus momentan kein Debug, ist zuviel. Zesstra
19
20#ifdef DEBUG
21#undef DEBUG
22#endif
23#define DEBUG(x)
24
25nosave int mails_last_hour;
26
27static string mail_normalize( string str )
28{
29 str = regreplace( str, "[^<]*<(.*)>[^>]*", "\\1", 0);
30 return regreplace( str, " *([^ ][^ ]*).*", "\\1", 0);
31}
32
33
34static string *mk_rec_list( string str )
35{
36 return map( explode( lower_case(str), "," ) - ({""}),
37 "mail_normalize", this_object() );
38}
39
40
41static int CheckPasswd( string name, string passwd ) {
42 mixed *uinf;
43
44 if (!stringp(passwd) || !sizeof(passwd))
45 return 0;
46 if ( sizeof(uinf = get_full_userinfo(name)) < 2 )
47 return 0;
48
49 string pwhash = uinf[USER_PASSWORD+1];
50 if (sizeof(pwhash) > 13) {
51 // MD5-Hash
52 passwd = md5_crypt(passwd, pwhash);
53 }
54 else if (sizeof(pwhash) > 2) {
55 // Crypt-Hash
56 passwd = crypt(passwd, pwhash[0..1]);
57 }
58 else return 0;
59
60 return (passwd == pwhash);
61}
62
MG Mud User88f12472016-06-24 23:31:02 +020063static void udp_query( string query, string host, int port )
64{
65#if __EFUN_DEFINED__(send_udp)
66 string *mess;
67 mixed *data;
68 int i, j;
69
70 mess = explode( query, " " );
Zesstraac1317a2019-09-27 16:14:44 +020071
MG Mud User88f12472016-06-24 23:31:02 +020072 switch ( mess[1] ){
73 case "wholist":
74 case "who":
Zesstrad872d182019-11-28 20:13:02 +010075 data = ({string*})"/obj/werliste"->QueryWhoListe();
MG Mud User88f12472016-06-24 23:31:02 +020076 break;
77
78 case "uptime":
79 data = ({ call_sefun("uptime") });
80 break;
81
82 case "finger":
83 if ( sizeof(mess) < 3 )
84 data = ({ "Error: Wen soll ich fingern ?" });
85 else
Zesstraac1317a2019-09-27 16:14:44 +020086 data = explode( "/p/daemon/finger"->
MG Mud User88f12472016-06-24 23:31:02 +020087 finger_single( lower_case(mess[2]), 0 ), "\n" );
88 break;
89
MG Mud User88f12472016-06-24 23:31:02 +020090 default:
91 data = ({ "Error: unknown request " + mess[1] + "\n" });
92 }
93
94
Zesstraac1317a2019-09-27 16:14:44 +020095 send_udp( host, port,
96 to_bytes(sprintf( "%s 0 %d", mess[0], sizeof(data)),
97 "ASCII//TRANSLIT"));
MG Mud User88f12472016-06-24 23:31:02 +020098
99 for ( i = 0, j = sizeof(data); i < j; i++ )
Zesstraac1317a2019-09-27 16:14:44 +0200100 send_udp( host, port,
101 to_bytes(sprintf( "%s %d %s", mess[0], i+1, data[i]),
102 "ASCII//TRANSLIT") );
MG Mud User88f12472016-06-24 23:31:02 +0200103#endif
104}
105
106#define UDP_DEBUG(x)
107//#define UDP_DEBUG(x) (write_file("/log/ARCH/udp.log",(x)))
108
Zesstra3d090312019-09-30 21:26:34 +0200109void receive_udp(string host, bytes message, int port)
MG Mud User88f12472016-06-24 23:31:02 +0200110{
Zesstra3d090312019-09-30 21:26:34 +0200111 // Traditionell sind einkommende Nachrichten via UDP immer ASCII-pur
112 // gewesen. Davon geht auch aller hier gerufener Code aus. Daher wird jetzt
113 // hier zentral die Bytesequenz als ASCII interpretiert und in string
114 // gewandelt, der dann wie bislang auch verarbeitet wird.
Zesstrad872d182019-11-28 20:13:02 +0100115 string msg_text;
116 if (catch(msg_text = to_text(message, "ASCII");publish))
117 {
118 msg_text = to_text(message, "ISO8859-1");
119 log_file("UDP_INVALID",sprintf(
120 "Nachricht von %s mit nicht-ASCII-Zeichen: %s\n",
121 host, msg_text));
122 }
MG Mud User88f12472016-06-24 23:31:02 +0200123
Zesstra3d090312019-09-30 21:26:34 +0200124 UDP_DEBUG(sprintf("%s %s:%d: %s\n",strftime(),host,port,msg_text));
125
126 // Nicht mehr benutzt, zur Sicherheit abfangen vor dem inetd.
127 if (strstr(msg_text, "EXTREQ:") == 0
128 || strstr(msg_text, "IPNAME") == 0
129 || strstr(msg_text, "AUTH") == 0)
130 {
MG Mud User88f12472016-06-24 23:31:02 +0200131 return;
132 }
133
Zesstra3d090312019-09-30 21:26:34 +0200134 // Die folgenden Services sind keine Intermud-Dienste
135 if(strstr(msg_text, "IPLOOKUP\n") == 0)
136 {
137 "/p/daemon/iplookup"->update( msg_text );
MG Mud User88f12472016-06-24 23:31:02 +0200138 return;
139 }
140
Zesstra3d090312019-09-30 21:26:34 +0200141 if( strstr(msg_text, "DNSLOOKUP\n") == 0)
142 {
143 "/p/daemon/dnslookup"->update( msg_text );
MG Mud User88f12472016-06-24 23:31:02 +0200144 return;
145 }
146
Zesstra3d090312019-09-30 21:26:34 +0200147 if (strstr(msg_text, "udp_query:") == 0)
148 {
149 return udp_query(msg_text[10..],host,port);
MG Mud User88f12472016-06-24 23:31:02 +0200150 }
Zesstra3d090312019-09-30 21:26:34 +0200151 // Rest an inetd fuer Bearbeitung als Intermud-Nachricht.
152 "secure/inetd"->_receive_udp(host, msg_text);
MG Mud User88f12472016-06-24 23:31:02 +0200153}
154
155