]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bsys.c
Eliminate dependency on man2html.
[bacula/bacula] / bacula / src / lib / bsys.c
index 86b437f07355eadad77e0344faadd6af83019de4..a4dc7231aabdb5f9e060da4c8806bbaa395a8405 100644 (file)
@@ -176,12 +176,16 @@ int cstrlen(const char *str)
 
 
 
-#ifndef DEBUG
+#ifndef bmalloc
 void *bmalloc(size_t size)
 {
   void *buf;
 
+#ifdef SMARTALLOC
+  buf = sm_malloc(file, line, size);
+#else
   buf = malloc(size);
+#endif
   if (buf == NULL) {
      berrno be;
      Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
@@ -207,6 +211,18 @@ void *b_malloc(const char *file, int line, size_t size)
 }
 
 
+void bfree(void *buf)
+{
+#ifdef SMARTALLOC
+  sm_free(__FILE__, __LINE__, buf);
+#else
+  free(buf);
+#endif
+}
+
+
+
+
 void *brealloc (void *buf, size_t size)
 {
    buf = realloc(buf, size);
@@ -497,21 +513,6 @@ static struct s_state_hdr state_hdr = {
    0
 };
 
-#ifdef HAVE_WIN32
-#undef open
-#undef read
-#undef write
-#undef lseek
-#undef close
-#undef O_BINARY 
-#define open _open
-#define read _read
-#define write _write
-#define lseek _lseeki64
-#define close _close
-#define O_BINARY _O_BINARY
-#endif
-
 /*
  * Open and read the state file for the daemon
  */
@@ -621,6 +622,8 @@ void drop(char *uname, char *gname)
    struct passwd *passw = NULL;
    struct group *group = NULL;
    gid_t gid;
+   uid_t uid;
+   char username[1000];         
 
    Dmsg2(900, "uname=%s gname=%s\n", uname?uname:"NONE", gname?gname:"NONE");
    if (!uname && !gname) {
@@ -642,6 +645,10 @@ void drop(char *uname, char *gname)
          uname = passw->pw_name;
       }
    }
+   /* Any OS uname pointer may get overwritten, so save name, uid, and gid */
+   bstrncpy(username, uname, sizeof(username));
+   uid = passw->pw_uid;
+   gid = passw->pw_gid;
    if (gname) {
       if ((group = getgrnam(gname)) == NULL) {
          berrno be;
@@ -649,29 +656,27 @@ void drop(char *uname, char *gname)
             be.strerror());
       }
       gid = group->gr_gid;
-   } else {
-      gid = passw->pw_gid;
    }
-   if (initgroups(passw->pw_name, passw->pw_gid)) {
+   if (initgroups(username, gid)) {
       berrno be;
       if (gname) {
          Emsg3(M_ERROR_TERM, 0, _("Could not initgroups for group=%s, userid=%s: ERR=%s\n"),         
-            gname, uname, be.strerror());
+            gname, username, be.strerror());
       } else {
          Emsg2(M_ERROR_TERM, 0, _("Could not initgroups for userid=%s: ERR=%s\n"),         
-            uname, be.strerror());
+            username, be.strerror());
       }
    }
    if (gname) {
-      if (setgid(group->gr_gid)) {
+      if (setgid(gid)) {
          berrno be;
          Emsg2(M_ERROR_TERM, 0, _("Could not set group=%s: ERR=%s\n"), gname,
             be.strerror());
       }
    }
-   if (setuid(passw->pw_uid)) {
+   if (setuid(uid)) {
       berrno be;
-      Emsg1(M_ERROR_TERM, 0, _("Could not set specified userid: %s\n"), uname);
+      Emsg1(M_ERROR_TERM, 0, _("Could not set specified userid: %s\n"), username);
    }
 #endif
 }