I need someone other than root (which snmpd runs as) to be able to manipulate the 
persistent store (to add createUser directives).  To that end, I've made the change 
below to the 5.1.1 version of read_config.c.  I'm looking for some feedback before I 
go to the trouble of getting the latest version, patching, etc.

TIA.

                            Chris


--- read_config.c.orig  Thu Feb 26 19:26:56 2004
+++ read_config.c       Thu Sep 16 16:28:19 2004
@@ -1206,6 +1206,12 @@
              "%s/%s.conf", get_persistent_directory(), type);
     file[ sizeof(file)-1 ] = 0;
     if (stat(file, &statbuf) == 0) {
+        // Save the ownership and mode to apply to new file.
+        mode_t mode = statbuf.st_mode;
+        uid_t uid = statbuf.st_uid;
+        gid_t gid = statbuf.st_gid;
+        mode_t mask;
+        
         for (j = 0; j <= MAX_PERSISTENT_BACKUPS; j++) {
             snprintf(fileold, sizeof(fileold),
                      "%s/%s.%d.conf", get_persistent_directory(), type, j);
@@ -1224,6 +1230,12 @@
                 break;
             }
         }
+
+        // Now create the new file and give it the original file's attributes
+        mask = umask(0);
+        close(creat(file, mode));
+        umask(mask);
+        chown(file, uid, gid);
     }
     /*
      * save a warning header to the top of the new file 




-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Net-snmp-coders mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to