*** ../netsnmp-lib/agent/snmpd.c	Mon Oct  8 15:02:23 2001
--- agent/snmpd.c	Fri Oct 26 10:55:21 2001
***************
*** 206,212 ****
  int snmp_input (int, struct snmp_session *, int, struct snmp_pdu *, void *);
  static void usage (char *);
  int main (int, char **);
- static void SnmpTrapNodeDown (void);
  static int receive(void);
  int snmp_check_packet(struct snmp_session*, snmp_ipaddr);
  int snmp_check_parse(struct snmp_session*, struct snmp_pdu*, int);
--- 206,211 ----
***************
*** 218,230 ****
  	printf(" [-u uid] [-g gid]");
  #endif
  	printf("\n");
- 	printf("\n\tVersion:  %s\n",VersionInfo);
- 	printf("\tAuthor:   Wes Hardaker\n");
- 	printf("\tEmail:    net-snmp-coders@lists.sourceforge.net\n");
  	printf("\n-h\t\tThis usage message.\n");
  	printf("-H\t\tDisplay configuration file directives understood.\n");
- 	printf("-v\t\tVersion information.\n");
- 	printf("-f\t\tDon't fork from the shell.\n");
  	printf("-a\t\tLog addresses.\n");
  	printf("-d\t\tDump sent and received UDP SNMP packets\n");
  	printf("-V\t\tVerbose display\n");
--- 217,224 ----
***************
*** 257,299 ****
  	printf("-g \t\tChange to this gid after opening port\n");
  	printf("-u \t\tChange to this uid after opening port\n");
  #endif
  	printf("\n");
  	exit(1);
  }
  
! 	RETSIGTYPE
! SnmpdShutDown(int a)
  {
! 	running = 0;
! }
  
! #ifdef SIGHUP
! 	RETSIGTYPE
! SnmpdReconfig(int a)
! {
! 	reconfig = 1;
! 	signal(SIGHUP, SnmpdReconfig);
  }
- #endif
  
- #ifdef SIGUSR1
- extern void dump_registry( void );
- 	RETSIGTYPE
- SnmpdDump(int a)
- {
- 	dump_registry();
- 	signal(SIGUSR1, SnmpdDump);
- }
- #endif
- 
- 
- 	static void
- SnmpTrapNodeDown(void)
- {
-     send_easy_trap (SNMP_TRAP_ENTERPRISESPECIFIC, 2);
-     /* XXX  2 - Node Down #define it as NODE_DOWN_TRAP */
- }
- 
  /*******************************************************************-o-******
   * main
   *
--- 248,279 ----
  	printf("-g \t\tChange to this gid after opening port\n");
  	printf("-u \t\tChange to this uid after opening port\n");
  #endif
+         printf("-y DIR\t\tThe persistent directory to be used.\n");
  	printf("\n");
  	exit(1);
  }
  
! int
! init_configuration_paths(void)
  {
! char defaultPath[SPRINT_MAX_LEN];
! char *homepath=getenv("HOME");
  
!     if (NULL == ds_get_string(DS_LIBRARY_ID, DS_LIB_CONFIGURATION_DIR)) {
!         sprintf(defaultPath,"%s%s", 
!                   ((homepath == NULL) ? "" : homepath),
!                   ((homepath == NULL) ? "" : "/.snmp"));
!         ds_set_string(DS_LIBRARY_ID, DS_LIB_CONFIGURATION_DIR, defaultPath);
!     }
!     if (NULL == ds_get_string(DS_LIBRARY_ID, DS_LIB_PERSISTENT_DIR)) {
!         ds_set_string(DS_LIBRARY_ID, DS_LIB_PERSISTENT_DIR, PERSISTENT_DIRECTORY);
!     }
!     fprintf(stderr, "Configpaths:\t%s\n\t\t%s\n",
!             ds_get_string(DS_LIBRARY_ID, DS_LIB_CONFIGURATION_DIR),
!             ds_get_string(DS_LIBRARY_ID, DS_LIB_PERSISTENT_DIR));
!     return(0);
  }
  
  /*******************************************************************-o-******
   * main
   *
***************
*** 314,320 ****
  {
  	int             arg, i;
  	int             ret;
- 	int             dont_fork = 0;
  	char            logfile[PATH_MAX + 1] = { 0 };
  	char           *cptr, **argvptr;
  	char           *pid_file = NULL;
--- 294,299 ----
***************
*** 331,343 ****
  	strncpy(logfile, LOGFILE, PATH_MAX);
  #endif
  
- #ifdef NO_ROOT_ACCESS
          /* default to no */
          ds_set_boolean(DS_APPLICATION_ID, DS_AGENT_NO_ROOT_ACCESS, 1);
! #endif
! 			/* Default to NOT running an AgentX master */
          ds_set_boolean(DS_APPLICATION_ID, DS_AGENT_AGENTX_MASTER, 0);
  
  	/*
  	 * usage: snmpd
  	 */
--- 310,323 ----
  	strncpy(logfile, LOGFILE, PATH_MAX);
  #endif
  
          /* default to no */
          ds_set_boolean(DS_APPLICATION_ID, DS_AGENT_NO_ROOT_ACCESS, 1);
! 
! 	/* Default to NOT running an AgentX master */
          ds_set_boolean(DS_APPLICATION_ID, DS_AGENT_AGENTX_MASTER, 0);
  
+        setenv("MIBS", "", 1);
+ 
  	/*
  	 * usage: snmpd
  	 */
***************
*** 346,367 ****
              if (argv[arg][0] == '-') {
                switch (argv[arg][1]) {
  
                  case 'c':
                    if (++arg == argc)
                      usage(argv[0]);
!                   ds_set_string(DS_LIBRARY_ID, DS_LIB_OPTIONALCONFIG,
                                   argv[arg]);
                    break;
  
-                 case 'C':
-                     ds_set_boolean(DS_LIBRARY_ID, DS_LIB_DONT_READ_CONFIGS, 1);
-                     break;
- 
- 		case 'd':
-                     snmp_set_dump_packet(++snmp_dump_packet);
- 		    ds_set_boolean(DS_APPLICATION_ID, DS_AGENT_VERBOSE, 1);
- 		    break;
- 
  		case 'q':
  		    snmp_set_quick_print(1);
  		    break;
--- 326,344 ----
              if (argv[arg][0] == '-') {
                switch (argv[arg][1]) {
  
+ 		case 'y':
+ 	            if (++arg == argc)
+                         usage(argv[0]);
+                     ds_set_string(DS_LIBRARY_ID, DS_LIB_PERSISTENT_DIR, argv[arg]);
+ 		  break;
+ 
                  case 'c':
                    if (++arg == argc)
                      usage(argv[0]);
!                   ds_set_string(DS_LIBRARY_ID, DS_LIB_CONFIGURATION_DIR,
                                   argv[arg]);
                    break;
  
  		case 'q':
  		    snmp_set_quick_print(1);
  		    break;
***************
*** 433,443 ****
  #endif
                    break;
  
- 		case 'r':
-                     ds_toggle_boolean(DS_APPLICATION_ID,
-                                       DS_AGENT_NO_ROOT_ACCESS);
- 		    break;
- 
                  case 'P':
                    if (++arg == argc)
                      usage(argv[0]);
--- 410,415 ----
***************
*** 452,461 ****
                    ds_set_boolean(DS_APPLICATION_ID, DS_AGENT_VERBOSE, 1);
                    break;
  
-                 case 'f':
-                   dont_fork = 1;
-                   break;
- 
                  case 'l':
                    if (++arg == argc) {
                      usage(argv[0]);
--- 424,429 ----
***************
*** 473,486 ****
  		    stderr_log=1;
                      break;
  
- 		case 's':
- 		    syslog_log=1;
- 		    break;
- 
-                 case 'A':
-                     dont_zero_log = 1;
-                     break;
- 
                  case 'I':
                    if (++arg == argc) usage(argv[0]);
                    add_to_init_list(argv[arg]);
--- 441,446 ----
***************
*** 598,707 ****
       * Initialize the world.  Detach from the shell.
       * Create initial user.
       */
- #if HAVE_FORK
-     if (!dont_fork && fork() != 0) {
-       exit(0);
-     }
- #endif
  
! #if HAVE_GETPID
!     if (pid_file != NULL) {
!       if ((PID = fopen(pid_file, "w")) == NULL) {
!         snmp_log_perror("fopen");
!         if (!ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_NO_ROOT_ACCESS))
!           exit(1);
!       }
!       else {
!         fprintf(PID, "%d\n", (int)getpid());
!         fclose(PID);
!       }
!     }
! #endif
  
-     /*  Honor selection of standard error output.  */
-     if (!stderr_log) {
-       snmp_disable_stderrlog();
-     }
- 
      SOCK_STARTUP;
!     init_agent("snmpd");		/* do what we need to do first. */
!     init_mib_modules();
!     
  
-     /* start library */
-     init_snmp("snmpd");
- 
      ret = init_master_agent( 0,
                         snmp_check_packet,
                         snmp_check_parse );
! 	if( ret != 0 )
! 		Exit(1); /* Exit logs exit val for us */
  
! #ifdef SIGTERM
!     signal(SIGTERM, SnmpdShutDown);
! #endif
! #ifdef SIGINT
!     signal(SIGINT, SnmpdShutDown);
! #endif
! #ifdef SIGHUP
!     signal(SIGHUP, SnmpdReconfig);
! #endif
! #ifdef SIGUSR1
!     signal(SIGUSR1, SnmpdDump);
! #endif
! #ifdef SIGPIPE
!     signal(SIGPIPE, SIG_IGN);	/* 'Inline' failure of wayward readers */
! #endif
  
-     /* store persistent data immediately in case we crash later */
-     snmp_store("snmpd");
- 
-     /* send coldstart trap via snmptrap(1) if possible */
-     send_easy_trap (0, 0);
-         
- #if HAVE_UNISTD_H
- #ifdef HAVE_SETGID
- 	if ((gid = ds_get_int(DS_APPLICATION_ID, DS_AGENT_GROUPID)) != 0) {
- 		DEBUGMSGTL(("snmpd", "Changing gid to %d.\n", gid));
- 		if (setgid(gid)==-1
- #ifdef HAVE_SETGROUPS
- 		 || setgroups(1, &gid)==-1
- #endif
- 		) {
- 			snmp_log_perror("setgid failed");
- 			if (!ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_NO_ROOT_ACCESS))
- 			    exit(1);
- 		}
- 	}
- #endif
- #ifdef HAVE_SETUID
- 	if ((uid = ds_get_int(DS_APPLICATION_ID, DS_AGENT_USERID)) != 0) {
- 		DEBUGMSGTL(("snmpd", "Changing uid to %d.\n", uid));
- 		if(setuid(uid)==-1) {
- 			snmp_log_perror("setuid failed");
- 			if (!ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_NO_ROOT_ACCESS))
- 			    exit(1);
- 		}
- 	}
- #endif
- #endif
- 
- 	/* we're up, log our version number */
- 	snmp_log(LOG_INFO, "UCD-SNMP version %s\n", VersionInfo);
- 
- 	memset(addrCache, 0, sizeof(addrCache));
- 	/* 
- 	 * Forever monitor the dest_port for incoming PDUs.
- 	 */
- 	DEBUGMSGTL(("snmpd", "We're up.  Starting to process data.\n"));
- 	receive();
- #include "mib_module_shutdown.h"
- 	DEBUGMSGTL(("snmpd", "sending shutdown trap\n"));
- 	SnmpTrapNodeDown();
- 	DEBUGMSGTL(("snmpd", "Bye...\n"));
- 	snmp_shutdown("snmpd");
- 	return 0;
- 
  }  /* End main() -- snmpd */
  
  /*******************************************************************-o-******
--- 558,583 ----
       * Initialize the world.  Detach from the shell.
       * Create initial user.
       */
  
!     init_configuration_paths();
  
      SOCK_STARTUP;
!     init_agent("snmpd");/* do what we need to do first. */
!     init_mib_modules(); /* Start up the MIB modules. */
!     init_snmp("snmpd"); /* Start the library */
  
      ret = init_master_agent( 0,
                         snmp_check_packet,
                         snmp_check_parse );
!     if ( ret != 0 ) {
!         fprintf(stderr, "Something went wrong\n");
! 	return(0); /* Exit logs exit val for us */
!     }
  
!     /* We shut down directly and not go into the request handling loop. */
!     snmp_shutdown("snmpd");
!     return 0;
  
  }  /* End main() -- snmpd */
  
  /*******************************************************************-o-******
