/[imapfilter]/imapfilter/memory.c
ViewVC logotype

Diff of /imapfilter/memory.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11 by lefcha, Fri Jul 26 18:18:42 2002 UTC revision 1.12 by lefcha, Tue Sep 24 18:49:34 2002 UTC
# Line 8  Line 8 
8  #include <sys/resource.h>  #include <sys/resource.h>
9    
10    
11    #include "config.h"
12  #include "imapfilter.h"  #include "imapfilter.h"
13    
14    
15  extern unsigned int options;  extern unsigned int options;
16    #ifdef MEMORY_LOCK
17  extern uid_t ruid, euid;  extern uid_t ruid, euid;
18    #endif
19    
20  static secmem_t *smem = NULL;   /* First node of secure memory linked list. */  static secmem_t *smem = NULL;   /* First node of secure memory linked list. */
21    
# Line 84  char *xstrdup(const char *s) Line 87  char *xstrdup(const char *s)
87   */   */
88  void *smalloc(size_t size)  void *smalloc(size_t size)
89  {  {
90    #ifdef MEMORY_LOCK
91      int r;      int r;
     void *ptr;  
92      static int w = 0;      static int w = 0;
93    #endif
94        void *ptr;
95      secmem_t *node;      secmem_t *node;
96    
97      ptr = xmalloc(size);      ptr = xmalloc(size);
98    
99    #ifdef MEMORY_LOCK
100      seteuid(euid);              /* Gain root privileges. */      seteuid(euid);              /* Gain root privileges. */
101      r = mlock(ptr, size);      r = mlock(ptr, size);
102      seteuid(ruid);              /* Drop root privileges. */      seteuid(ruid);              /* Drop root privileges. */
# Line 98  void *smalloc(size_t size) Line 104  void *smalloc(size_t size)
104      if (getuid() != geteuid())      if (getuid() != geteuid())
105          fatal(ERROR_SETUID, "imapfilter: failed to drop privileges\n");          fatal(ERROR_SETUID, "imapfilter: failed to drop privileges\n");
106    
107    
108      if (options & OPTION_WARNING && r && !w) {      if (options & OPTION_WARNING && r && !w) {
109          error("imapfilter: warning: using insecure memory\n");          error("imapfilter: warning: using insecure memory\n");
110          w = 1;          w = 1;
111      }      }
112    #endif
113      node = (secmem_t *) xmalloc(sizeof(secmem_t));      node = (secmem_t *) xmalloc(sizeof(secmem_t));
114    
115      node->buf = ptr;      node->buf = ptr;
# Line 233  void secmem_clear(void) Line 241  void secmem_clear(void)
241  }  }
242    
243    
244    #ifdef MEMORY_LOCK
245  /*  /*
246   * Lock memory of allocated buffers.   * Lock memory of allocated buffers.
247   */   */
# Line 249  void secmem_lock(void) Line 258  void secmem_lock(void)
258          fatal(ERROR_SETUID, "imapfilter: failed to drop privileges\n");          fatal(ERROR_SETUID, "imapfilter: failed to drop privileges\n");
259  }  }
260    
261    #endif
262    
263    
264  /*  /*
265   * Disable core file dumping.   * Disable core file dumping.

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26