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

Diff of /imapfilter/memory.c

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

revision 1.14 by lefcha, Sat Mar 29 14:04:10 2003 UTC revision 1.15 by lefcha, Tue May 20 12:17:52 2003 UTC
# Line 14  Line 14 
14    
15  extern unsigned int options;  extern unsigned int options;
16    
 #ifdef MEMORY_LOCK  
 extern uid_t ruid, euid;  
   
 #endif  
   
17  static secmem_t *smem = NULL;   /* First node of secure memory linked list. */  static secmem_t *smem = NULL;   /* First node of secure memory linked list. */
18    
19    
# Line 94  xstrdup(const char *s) Line 89  xstrdup(const char *s)
89  void *  void *
90  smalloc(size_t size)  smalloc(size_t size)
91  {  {
 #ifdef MEMORY_LOCK  
         int r;  
         static int w = 0;  
   
 #endif  
92          void *ptr;          void *ptr;
93          secmem_t *node;          secmem_t *node;
94    
95          ptr = xmalloc(size);          ptr = xmalloc(size);
96    
 #ifdef MEMORY_LOCK  
         seteuid(euid);          /* Gain root privileges. */  
         r = mlock(ptr, size);  
         seteuid(ruid);          /* Drop root privileges. */  
   
         if (getuid() != geteuid())  
                 fatal(ERROR_SETUID, "failed to drop privileges\n");  
   
   
         if (options & OPTION_WARNING && r == -1 && !w) {  
                 error("warning: using insecure memory\n");  
                 w = 1;  
         }  
 #endif  
97          node = (secmem_t *) xmalloc(sizeof(secmem_t));          node = (secmem_t *) xmalloc(sizeof(secmem_t));
98    
99          node->buf = ptr;          node->buf = ptr;
# Line 260  secmem_clear(void) Line 236  secmem_clear(void)
236  }  }
237    
238    
 #ifdef MEMORY_LOCK  
 /*  
  * Lock memory of allocated buffers.  
  */  
 void  
 secmem_lock(void)  
 {  
         secmem_t *p;  
   
         seteuid(euid);          /* Gain root privileges. */  
         for (p = smem; p != NULL; p = p->next)  
                 mlock(p->buf, p->size);  
         seteuid(ruid);          /* Drop root privileges. */  
   
         if (getuid() != geteuid())  
                 fatal(ERROR_SETUID, "failed to drop privileges\n");  
 }  
   
 #endif  
   
   
239  /*  /*
240   * Disable core file dumping.   * Disable core file dumping.
241   */   */

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26