Selaa lähdekoodia

* Bots will now email owners once a day if their uname() output changes.
* email() now uses the login name if a botname is not set.


svn: 542

Bryan Drewery 22 vuotta sitten
vanhempi
commit
a6ea839cea
4 muutettua tiedostoa jossa 42 lisäystä ja 2 poistoa
  1. 1 0
      doc/UPDATES
  2. 2 1
      src/main.c
  3. 38 1
      src/misc.c
  4. 1 0
      src/proto.h

+ 1 - 0
doc/UPDATES

@@ -3,6 +3,7 @@ This is a summary of ChangeLog basically.
 1.0.15
 1.cmd_randstring is now limited to 300.
 2.cmd_botversion and cmd_netversion are now HUB only.
+3.Bots will now email owners once a day if their uname() output changes.
 
 1.0.14
 1.Fixed order of log/info for cmd_whoami.

+ 2 - 1
src/main.c

@@ -541,7 +541,7 @@ int clear_tmp()
   if (!(tmp = opendir(tempdir))) return 1;
   while ((dir_ent = readdir(tmp))) {
     if (strncmp(dir_ent->d_name, ".pid.", 4) && strncmp(dir_ent->d_name, ".u", 2) && strcmp(dir_ent->d_name, ".bin.old")
-       && strcmp(dir_ent->d_name, ".") && strcmp(dir_ent->d_name, "..")) {
+       && strcmp(dir_ent->d_name, ".") && strcmp(dir_ent->d_name, ".un") && strcmp(dir_ent->d_name, "..")) {
       char *file = nmalloc(strlen(dir_ent->d_name) + strlen(tempdir) + 1);
       file[0] = 0;
       strcat(file, tempdir);
@@ -1662,6 +1662,7 @@ if (1) {		/* config shit */
         int r = 0;
         newsplit(&temps);
         if ((r = strcmp(temps, my_uname()))) {
+          baduname(temps, my_uname());
           sdprintf(STR("wrong uname, conf: %s :: %s"), temps, my_uname());
           werr(ERR_WRONGUNAME);
         }

+ 38 - 1
src/misc.c

@@ -2255,8 +2255,10 @@ int email(char *subject, char *msg, int who)
     sprintf(open, "/usr/bin/mail %s -a \"From: %s@%s\" -s \"%s\" -a \"Content-Type: text/plain\"", addrs, (origbotname && origbotname[0]) ? origbotname : "none", un.nodename, subject);
   if ((f = popen(open, "w"))) {
     if (sendmail) {
+      struct passwd *pw;
+      pw = getpwuid(geteuid());
       fprintf(f, "To: %s\n", addrs);
-      fprintf(f, "From: %s@%s\n", (origbotname && origbotname[0]) ? origbotname : "none", un.nodename);
+      fprintf(f, "From: %s@%s\n", (origbotname && origbotname[0]) ? origbotname : pw->pw_name, un.nodename);
       fprintf(f, "Subject: %s\n", subject);
       fprintf(f, "Content-Type: text/plain\n");
     }
@@ -2270,3 +2272,38 @@ int email(char *subject, char *msg, int who)
   return 0;
 }
 
+void baduname(char *conf, char *my_uname) {
+  char *tmpfile = nmalloc(strlen(tempdir) + 3 + 1);
+  int send = 0;
+
+  tmpfile[0] = 0;
+  sprintf(tmpfile, "%s.un", tempdir);
+  sdprintf("CHECKING %s", tmpfile);
+  if (is_file(tmpfile)) {
+    struct stat ss;
+    stat(tmpfile, &ss);
+    time_t diff = now - ss.st_mtime;
+    if (diff >= 86400) send++;		/* only send once a day */
+  } else {
+    FILE *fp;
+    if ((fp = fopen(tmpfile, "w"))) {
+      fprintf(fp, "\n");
+      fflush(fp);
+      fclose(fp);
+      send++;		/* only send if we could write the file. */
+    } 
+  }
+  if (send) {
+    struct passwd *pw;
+    struct utsname un;
+    char msg[501], subject[31];
+
+    pw = getpwuid(geteuid());
+    if (!pw) return;
+    uname(&un);
+    egg_snprintf(subject, sizeof subject, "CONF/UNAME() mismatch notice");
+    egg_snprintf(msg, sizeof msg, "This is an auto email from a wraith bot which has you in it's OWNER_EMAIL list..\n \nThe uname() output on this box has changed, probably due to a kernel upgrade...\nMy login is: %s\nConf   : %s\nUname(): %s\n \nThis email will only be sent once a day while this error is present.\nYou need to login to my shell (%s) and fix my local config.\n", pw->pw_name, conf, my_uname, un.nodename);
+    email(subject, msg, EMAIL_OWNERS);
+  }
+  nfree(tmpfile);
+}

+ 1 - 0
src/proto.h

@@ -232,6 +232,7 @@ void set_cmd_pass(char *, int);
 #endif /* S_DCCPASS */
 
 /* misc.c */
+void baduname(char *, char *);
 int email(char *, char *, int);
 char *color(int, int, int);
 void shuffle(char *, char *);