network.c-Dateireferenz

#include "/secure/master.h"
Include-Abhängigkeitsdiagramm für network.c:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define BBMASTER   "/secure/bbmaster"
#define DEBUG(x)
#define UDP_DEBUG(x)   (write_file("/log/ARCH/udp.log",(x)))

Funktionen

static string mail_normalize (string str)
static string * mk_rec_list (string str)
static int CheckPasswd (string name, string passwd)
static void FtpAccess (string host, string message, int port)
static int doReadMail (string file)
public void mailread ()
static void udp_query (string query, string host, int port)
void receive_udp (string host, string message, int port)

Variablen

nosave int mails_last_hour

Makro-Dokumentation

#define BBMASTER   "/secure/bbmaster"

Definiert in Zeile 10 der Datei network.c.

#define DEBUG ( x   ) 

Definiert in Zeile 23 der Datei network.c.

#define UDP_DEBUG ( x   )     (write_file("/log/ARCH/udp.log",(x)))

Definiert in Zeile 388 der Datei network.c.

Wird benutzt von receive_udp().


Dokumentation der Funktionen

static int CheckPasswd ( string  name,
string  passwd 
) [static]

Definiert in Zeile 41 der Datei network.c.

Benutzt crypt, get_full_userinfo() und USER_PASSWORD.

Wird benutzt von FtpAccess().

00041                                                      {
00042     mixed *uinf;
00043 
00044     if (!stringp(passwd) || !strlen(passwd))
00045  return 0;
00046     if ( sizeof(uinf = get_full_userinfo(name)) < 2 )
00047         return 0;
00048 
00049     string pwhash = uinf[USER_PASSWORD+1];
00050     if (strlen(pwhash) > 13) {
00051  // MD5-Hash
00052  passwd = md5_crypt(passwd, pwhash);
00053     }
00054     else if (strlen(pwhash) > 2) {
00055  // Crypt-Hash
00056  passwd = crypt(passwd, pwhash[0..1]);
00057     }
00058     else return 0;
00059 
00060     return (passwd == pwhash);
00061 }

Hier ist ein Graph der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

static int doReadMail ( string  file  )  [static]

Definiert in Zeile 185 der Datei network.c.

Benutzt DEBUG, i, lines, mail_normalize(), message, mk_rec_list(), MSG_BCC, MSG_BODY, MSG_CC, MSG_FROM, MSG_RECIPIENT, MSG_SENDER und MSG_SUBJECT.

Wird benutzt von mailread().

00186 {
00187     string str, *lines, *parts, *tmp;
00188     mixed *message;
00189     int i, j;
00190 
00191     if ( (i = file_size(file)) > 50000 || i < 5 ){
00192         rm(file);
00193         DEBUG( "Mail size invalid\n" );
00194         return -1;
00195     }
00196 
00197     if ( !(str = read_bytes( file, 0, 50000 )) )
00198         return -1;
00199 
00200     if ( !(j = sizeof(lines = explode( str, "\n" ))) )
00201         return -2;
00202 
00203     i = 0;
00204 
00205     while ( i < j && lines[i] != "" )
00206         i++;
00207 
00208     if ( i == j )
00209         return -2;
00210 
00211  DEBUG( sprintf( "Have %d headerlines:\n", i ) );
00212 
00213     message= allocate(9);
00214     message[MSG_CC] = ({});
00215     message[MSG_BCC] = ({});
00216     message[MSG_BODY] = implode( lines[i..], "\n" );
00217 
00218     for ( j = 0; j < i; j++ ){
00219         parts = explode( lines[j], ":" );
00220 
00221         if ( sizeof(parts) > 1 ){
00222             str = lower_case(parts[0]);
00223             parts[0] = implode( parts[1..], ":" );
00224 
00225             switch (str){
00226             case "subject":
00227                 message[MSG_SUBJECT] = parts[0];
00228                 break;
00229 
00230             case "from":
00231                 DEBUG( "Found from\n" );
00232                 DEBUG( sprintf( "PARTS[0]=%s\n", parts[0] ) );
00233                 message[MSG_FROM] = mail_normalize(parts[0]);
00234                 message[MSG_SENDER] = parts[0];
00235                 DEBUG( sprintf( "FROM: %s\nSENDER: %s\n",
00236                                 message[MSG_FROM],
00237                                 message[MSG_SENDER] ) );
00238                 break;
00239 
00240             case "cc":
00241                 DEBUG( sprintf("FOUND CC: %O\n", parts[0]) );
00242                 message[MSG_CC] += mk_rec_list(parts[0]);
00243                 break;
00244 
00245             case "bcc":
00246                 DEBUG( sprintf("FOUND BCC: %O\n", parts[0]) );
00247                 message[MSG_BCC] += mk_rec_list(parts[0]);
00248                 break;
00249 
00250             case "to":
00251                 DEBUG( sprintf("FOUND TO: %O\n", parts[0]) );
00252                 tmp = mk_rec_list(parts[0]);
00253 
00254                 if ( !message[MSG_RECIPIENT] )
00255                     message[MSG_RECIPIENT] = tmp[0];
00256 
00257                 message[MSG_CC] += tmp;
00258                 break;
00259 
00260             // Das MUD-TO: wird vom Perlskript als erste Headerzeile eingefuegt
00261             case "mud-to":
00262                 DEBUG( sprintf("FOUND MUD-TO: %O\n", parts[0]) );
00263                 message[MSG_RECIPIENT] = mail_normalize(lower_case(parts[0]));
00264                 break;
00265             }
00266         }
00267     }
00268 
00269     // Eigentlichen Empfaenger aus CC: loeschen
00270     message[MSG_CC] -= ({ message[MSG_RECIPIENT],
00271                           message[MSG_RECIPIENT]+"@mg.mud.de",
00272                           message[MSG_RECIPIENT]+"@morgengrauen.mud.de" });
00273 
00274 
00275  DEBUG( sprintf( "TO: %O\n", message[MSG_RECIPIENT] ) );
00276     DEBUG( sprintf( "CC: %O\n", message[MSG_CC] ) );
00277     DEBUG( sprintf( "BCC: %O\n", message[MSG_BCC] ) );
00278 
00279     if ( !stringp(message[MSG_FROM]) )
00280         return -2;
00281 
00282     if ( !stringp(message[MSG_RECIPIENT]) ){
00283         str = explode( file, "/" )[<1];
00284         i = 0;
00285         j = strlen(str);
00286 
00287         while ( i < j && str[i] <= '9' && str[i] >= '0' )
00288             i++;
00289 
00290         if ( i >= j )
00291             return -2;
00292         
00293         message[MSG_RECIPIENT] = str[i..];
00294   DEBUG( sprintf( "EMERGENCY RECIPIENT=%s\n", str[i..] ) );
00295     }
00296 
00297     rm(file);
00298 
00299     // Da vom Master besser nichts von ausserhalb /secure #include't wird,
00300     // direkt die '5'. Normalerweise hiesse der Aufruf:
00301     // DeliverMail( message, NO_USER_ALIASES|NO_CARBON_COPIES );
00302     "/secure/mailer"->DeliverMail( message, 5 );
00303     return 1;
00304 }

Hier ist ein Graph der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

static void FtpAccess ( string  host,
string  message,
int  port 
) [static]

Definiert in Zeile 64 der Datei network.c.

Benutzt ARCH_LVL, BBMASTER, CheckPasswd(), ctime(), DEBUG, get_wiz_level(), IS_LEARNER, log_file, QueryTBanished(), valid_read() und valid_write().

Wird benutzt von receive_udp().

00065 {
00066     string *comp, reply, head;
00067 #if __EFUN_DEFINED__(send_udp)
00068     comp = efun::explode( message, "\t" );
00069 #define FTP_ID   0
00070 #define FTP_SEQ  1
00071 #define FTP_TAG  2
00072 #define FTP_CMD  3
00073 #define FTP_ARG1 4
00074 #define FTP_ARG2 5
00075 #define FTP_ARG3 6
00076 
00077   if ( sizeof(comp) <= FTP_CMD || lower_case(comp[FTP_TAG]) != "req" ){
00078       log_file( "IMP_MSGS", "Host: " + host + ":" + port + " - '" +
00079                 message + "'\n" );
00080       return;
00081   }
00082 
00083   reply = "INVALID";
00084 
00085   head = sprintf( "%s\t%s\tRPLY\t%s\t",
00086                   comp[FTP_ID], comp[FTP_SEQ], comp[FTP_CMD] );
00087 
00088   switch ( lower_case(comp[FTP_CMD]) ){
00089   case "user":
00090       if ( sizeof(comp) <= FTP_ARG1 )
00091           break;
00092 
00093       if ( IS_LEARNER(lower_case(comp[FTP_ARG1])) )
00094           reply = "/players/" + lower_case(comp[FTP_ARG1]);
00095       else
00096           reply = "NONE";
00097       break;
00098 
00099   case "pass":
00100       if ( sizeof(comp) <= FTP_ARG2 )
00101           break;
00102 
00103       comp[FTP_ARG1] = lower_case(comp[FTP_ARG1]);
00104 
00105       if ( IS_LEARNER(comp[FTP_ARG1]) &&
00106            !"/secure/master"->QueryTBanished(comp[FTP_ARG1]) ){
00107           if ( CheckPasswd( comp[FTP_ARG1], comp[FTP_ARG2] ) )
00108               reply = "OK";
00109           else {
00110               if ( get_wiz_level( comp[FTP_ARG1] ) < ARCH_LVL )
00111                   log_file( "LOGINFAIL",
00112                             sprintf( "PASSWORD:      (FTP)     %s %s\n",
00113                                      comp[FTP_ARG1],
00114                                      ctime(time()) ) );
00115               else
00116                   log_file( "ARCH/LOGINFAIL",
00117                             sprintf( "PASSWORD:      (FTP)     %s %s\n",
00118                                      comp[FTP_ARG1],
00119                                      ctime(time()) ) );
00120           }
00121       }
00122       else
00123           reply = "FAIL";
00124       break;
00125 
00126   case "read":
00127 DEBUG("-FtpAccess----\nHost:"+host+"Message:\n"+message+"\n--------------\n");
00128       if ( sizeof(comp) <= FTP_ARG2 )
00129           break;
00130 
00131       if ( comp[FTP_ARG2][0] == '/' &&
00132            valid_read( comp[FTP_ARG2], lower_case(comp[FTP_ARG1]),
00133                        "read_file", 0 ) ){
00134 
00135           BBMASTER->ftpbb( lower_case(comp[FTP_ARG1]),
00136                            "read " + comp[FTP_ARG2] + "\n" );
00137           reply = "OK";
00138           }
00139       else
00140           reply = "FAIL";
00141       break;
00142 
00143   case "writ":
00144 DEBUG("-FtpAccess----\nHost:"+host+"Message:\n"+message+"\n--------------\n");
00145       if ( sizeof(comp) <= FTP_ARG2 )
00146           break;
00147 
00148       if ( comp[FTP_ARG2][0] == '/' &&
00149            valid_write( comp[FTP_ARG2], lower_case(comp[FTP_ARG1]),
00150                        "write_file", 0 ) ){
00151 
00152           BBMASTER->ftpbb( lower_case(comp[FTP_ARG1]),
00153                            "write " + comp[FTP_ARG2] + "\n" );
00154           reply = "OK";
00155           }
00156        else
00157           reply = "FAIL";
00158       break;
00159 
00160   case "list":
00161 DEBUG("-FtpAccess----\nHost:"+host+"Message:\n"+message+"\n--------------\n");
00162       if ( sizeof(comp) <= FTP_ARG2 )
00163           break;
00164 
00165       if ( comp[FTP_ARG2][0] == '/' &&
00166            valid_read( comp[FTP_ARG2], lower_case(comp[FTP_ARG1]),
00167                        "read_file", 0 ) )
00168           reply = "OK";
00169       else
00170           reply = "FAIL";
00171       break;
00172 
00173   default:
00174 DEBUG("-FtpAccess----\nHost:"+host+"Message:\n"+message+"\n--------------\n");
00175       log_file( "IMP_MSGS", "Host: " + host + ":" + port + " - '" +
00176                 message + "'\n" );
00177       break;
00178   }
00179 
00180   send_udp( host, port, head+reply );
00181 #endif
00182 }

Hier ist ein Graph der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

static string mail_normalize ( string  str  )  [static]

Definiert in Zeile 27 der Datei network.c.

Wird benutzt von doReadMail().

00028 {
00029     str = regreplace( str, "[^<]*<(.*)>[^>]*", "\\1", 0);
00030     return regreplace( str, " *([^ ][^ ]*).*", "\\1", 0);
00031 }

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

public void mailread (  ) 

Definiert in Zeile 307 der Datei network.c.

Benutzt DEBUG, doReadMail(), i, mails_last_hour, MAX_MAILS_PER_HOUR, message, MSG_BODY, MSG_FROM, MSG_RECIPIENT, MSG_SENDER und MSG_SUBJECT.

Wird benutzt von udp_query().

00308 {
00309     string *files;
00310     int i;
00311 
00312     DEBUG( "mailread called\n" );
00313 
00314     if ( mails_last_hour >= MAX_MAILS_PER_HOUR )
00315         return;
00316 
00317     files = (get_dir( "/mail/inbound/*" )||({})) - ({ "..", "." });
00318     i = sizeof(files);
00319 
00320     while ( i-- && mails_last_hour < MAX_MAILS_PER_HOUR ){
00321         DEBUG( "FOUND FILE \"" + files[i] + "\" ...\n" );
00322         mails_last_hour++;
00323 
00324         if ( doReadMail( "/mail/inbound/" + files[i]) < -1 ){
00325             mixed message;
00326 
00327             message = allocate(9);
00328             mails_last_hour++;
00329             rename( "/mail/inbound/" + files[i],
00330                     "/secure/ARCH/MAIL/" + files[i] );
00331             message[MSG_SENDER] = geteuid();
00332             message[MSG_FROM] = getuid();
00333             message[MSG_SUBJECT] = "Fehlerhafte Mail: /secure/ARCH/MAIL/" +
00334                 files[i];
00335             message[MSG_RECIPIENT] = "mud@mg.mud.de";
00336             message[MSG_BODY] = "Bitte Ueberpruefen!\n";
00337             // NO_SYSTEM_ALIASES|NO_USER_ALIASES == 3
00338             "/secure/mailer"->DeliverMail( message, 3 );
00339         }
00340     }
00341 }

Hier ist ein Graph der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

static string* mk_rec_list ( string  str  )  [static]

Definiert in Zeile 34 der Datei network.c.

Wird benutzt von doReadMail().

00035 {
00036     return map( explode( lower_case(str), "," ) - ({""}),
00037                       "mail_normalize", this_object() );
00038 }

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

void receive_udp ( string  host,
string  message,
int  port 
)

Definiert in Zeile 390 der Datei network.c.

Benutzt DEBUG, FtpAccess(), FTPD_IP, strftime(), UDP_DEBUG und udp_query().

00391 {
00392   mixed *tmp;
00393   UDP_DEBUG(sprintf("%s %s:%d: %s\n",strftime(),host,port,message));
00394 
00395   if (message[0..6]=="EXTREQ:"
00396                 || message[0..5]=="IPNAME"
00397                 || message[0..3]=="AUTH"
00398   ) {           
00399     return;
00400   }
00401 
00402   if( message[0..8]=="IPLOOKUP\n" ) {
00403     "/p/daemon/iplookup"->update( message );
00404     return;
00405   }
00406 
00407   if (message[0..4]=="NFTPD") {
00408 #if __HOST_NAME__==MUDHOST
00409     if (host!=FTPD_IP) {
00410       DEBUG(sprintf("INVALID HOST: %s\n",host));
00411       return;
00412     }
00413 #endif
00414     FtpAccess(host,message,port);
00415     return;
00416   }
00417 
00418   if (message[0..9]=="udp_query:") {
00419     return udp_query(message[10..],host,port);
00420   }
00421 
00422   "secure/inetd"->_receive_udp(host, message);
00423 }

Hier ist ein Graph der zeigt, was diese Funktion aufruft:

static void udp_query ( string  query,
string  host,
int  port 
) [static]

Definiert in Zeile 344 der Datei network.c.

Benutzt data, finger_single(), i, mailread(), mess() und QueryWhoListe().

Wird benutzt von receive_udp().

00345 {
00346 #if __EFUN_DEFINED__(send_udp)
00347     string *mess;
00348     mixed *data;
00349     int i, j;
00350 
00351     mess = explode( query, " " );
00352     
00353     switch ( mess[1] ){
00354     case "wholist":
00355     case "who":
00356         data = (string *)"/obj/werliste"->QueryWhoListe();
00357         break;
00358 
00359     case "uptime":
00360         data = ({ funcall( symbol_function("uptime") ) });
00361         break;
00362 
00363     case "finger":
00364         if ( sizeof(mess) < 3 )
00365             data = ({ "Error: Wen soll ich fingern ?" });
00366         else
00367             data = explode( (string)"p/daemon/finger"->
00368                             finger_single( lower_case(mess[2]), 0 ), "\n" );
00369         break;
00370 
00371     case "mailread":
00372         data = ({ "Okay" });
00373         mailread();
00374         break;
00375 
00376     default:
00377         data = ({ "Error: unknown request " + mess[1] + "\n" });
00378     }
00379 
00380 
00381     send_udp( host, port, sprintf( "%s 0 %d", mess[0], sizeof(data) ) );
00382 
00383     for ( i = 0, j = sizeof(data); i < j; i++ )
00384         send_udp( host, port, sprintf( "%s %d %s", mess[0], i+1, data[i] ) );
00385 #endif
00386 }

Hier ist ein Graph der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:


Variablen-Dokumentation

nosave int mails_last_hour

Definiert in Zeile 25 der Datei network.c.

Wird benutzt von mailread().

Erzeugt am Thu Jun 3 14:41:34 2010 für MorgenGrauen Mudlib von  doxygen 1.6.3