File: net-snmp-config.in

package info (click to toggle)
net-snmp 5.1.2-6.2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,340 kB
  • ctags: 12,062
  • sloc: ansic: 134,798; perl: 10,855; sh: 10,237; makefile: 5,003
file content (500 lines) | stat: -rwxr-xr-x 14,317 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
#!/bin/sh
#
# $Id: net-snmp-config.in,v 5.26.2.2 2004/06/17 13:39:28 hardaker Exp $
#
# this shell script is designed to merely dump the configuration
# information about how the net-snmp package was compiled.  The
# information is particularily useful for applications that need to
# link against the net-snmp libraries and hence must know about any
# other libraries that must be linked in as well.

check_build_dir()
{
      build_dir=$1

      if test "x$build_dir" = "x" ; then
         echo "You must specify a build directory."
         exit 1
      fi
      # is it the src dir?
      if test -f $build_dir/net-snmp-config.in ; then
         return
      fi
      # make sure we can find build dir
      if ! test -d $build_dir/snmplib/.libs ; then
         echo "$build_dir does not appear to be a build directory."
         exit 1
      fi
}

prefix=@prefix@
exec_prefix=@exec_prefix@
NSC_LDFLAGS="@LDFLAGS@"
NSC_LIBDIR=-L@libdir@
NSC_LIBS="@LIBS@"
NSC_AGENTLIBS="@AGENTLIBS@ @WRAPLIBS@"
NSC_PREFIX=@prefix@
NSC_EXEC_PREFIX=@exec_prefix@
NSC_SRCDIR=@srcdir@
NSC_BASE_SUBAGENT_LIBS="-lnetsnmpagent -lnetsnmphelpers -lnetsnmp"
NSC_BASE_AGENT_LIBS="-lnetsnmpagent -lnetsnmpmibs -lnetsnmphelpers -lnetsnmp"
NSC_SRC_LIBDIRS="agent/.libs snmplib/.libs agent/helpers/.libs"
NSC_SRC_LIBDEPS="agent/.libs/libnetsnmpagent.a agent/.libs/libnetsnmpmibs.a snmplib/.libs/libnetsnmp.a agent/helpers/.libs/libnetsnmphelpers.a"

if test "x$NSC_SRCDIR" = "x." ; then
   NSC_SRCDIR="NET-SNMP-SOURCE-DIR"
fi

if test "x$1" = "x"; then
  usage="yes"
else
  case $1 in
    --debug-tokens)
      echo "find $NSC_SRCDIR -name \"*.c\" -print | xargs grep DEBUGMSGT | grep \\\" | cut -f 2 -d\\\" | sort -u"
      if test "x$NSC_SRCDIR" != "xNET-SNMP-SOURCE-DIR" ; then
        /usr/bin/find $NSC_SRCDIR -name "*.c" -print | xargs grep DEBUGMSGT | grep \" | cut -f 2 -d\" | sort -u
      fi
      ;;
    --indent-options)
      echo "indent -orig -nbc -bap -nut -nfca `(cd NET-SNMP-INCLUDE-DIR; perl -n -e 'print "-T $1 " if (/}\s*(netsnmp_\w+)\s*;/);' */*.h)`"
      ;;
    --configure-options)
      echo @CONFIGURE_OPTIONS@
      ;;
    --snmpd-module-list)
      echo @MODULE_LIST@
      ;;
    #################################################### compile
    --base-cflags)
      echo @CFLAGS@ @CPPFLAGS@ -I@includedir@
      ;;
    --cflags)
      echo @CFLAGS@ @DEVFLAGS@ @CPPFLAGS@ -I. -I@includedir@
      ;;
    --srcdir)
      echo $NSC_SRCDIR
      ;;
    #################################################### linking
    --lib-dir)
      echo $NSC_LIBDIR
      ;;
    --ldflags)
      echo $NSC_LDFLAGS
      ;;
    --build-lib-dirs)
      shift
      build_dir=$1
      check_build_dir $build_dir
      for dir in $NSC_SRC_LIBDIRS; do
          result="$result -L$build_dir/$dir"
      done
      echo $result
      ;;
    --build-lib-deps)
      shift
      build_dir=$1
      check_build_dir $build_dir
      for dir in $NSC_SRC_LIBDEPS; do
          result="$result $build_dir/$dir"
      done
      echo $result
      ;;
    --build-includes)
      shift
      build_dir=$1
      check_build_dir $build_dir
      result="-I$build_dir/include"
      if test "$build_dir" != "$NSC_SRCDIR" -a "$NSC_SRCDIR" != "NET-SNMP-SOURCE-DIR"
      then
          result="$result -I$NSC_SRCDIR/include"
      fi
      echo $result
      ;;
    #################################################### client lib
    --libs)
      # use this one == --netsnmp-libs + --external-libs
      echo $NSC_LDFLAGS $NSC_LIBDIR -lnetsnmp $NSC_LIBS @WRAPLIBS@
      ;;
    --netsnmp-libs)
      echo $NSC_LIBDIR -lnetsnmp
      ;;
    --external-libs)
      echo $NSC_LDFLAGS $NSC_LIBS @WRAPLIBS@
      ;;
    #################################################### agent lib
    --base-agent-libs)
      echo $NSC_BASE_AGENT_LIBS
      ;;
    --base-subagent-libs)
      echo $NSC_BASE_SUBAGENT_LIBS
      ;;
    --agent-libs)
      # use this one == --netsnmp-agent-libs + --external-libs
      echo $NSC_LDFLAGS $NSC_LIBDIR $NSC_BASE_AGENT_LIBS $NSC_AGENTLIBS @WRAPLIBS@
      ;;
    --netsnmp-agent-libs)
      echo $NSC_LIBDIR $NSC_BASE_AGENT_LIBS
      ;;
    --external-agent-libs)
      echo $NSC_LDFLAGS $NSC_AGENTLIBS @WRAPLIBS@
      ;;
    ####################################################
    --version)
      echo @VERSION@
      ;;
    --help)
      usage="yes"
      ;;
    --prefix)
      echo $NSC_PREFIX
      ;;
    --exec-prefix)
      echo $NSC_EXEC_PREFIX
      ;;
    --create-snmpv3-user)
      if @PSCMD@ | egrep ' snmpd *$' > /dev/null 2>&1 ; then
         echo "Apparently at least one snmpd demon is already running."
         echo "You must stop them in order to use this command."
         exit 1
      fi

      Aalgorithm="MD5"
      Xalgorithm="DES"
      token=rwuser
      shift
      while test "x$done" = "x" -a "x$1" != "x" ; do
	case $1 in
	    -A)
		shift
		if test "x$1" = "x" ; then
		    echo "You must specify an authentication algorithm"
		    exit 1
		fi
		Aalgorithm=$1
		shift
		;;
	    -X)
		shift
		if test "x$1" = "x" ; then
		    echo "You must specify an encryption algorithm"
		    exit 1
		fi
		Xalgorithm=$1
		shift
		;;
	    -a)
		shift
		if test "x$1" = "x" ; then
		    echo "You must specify an authentication pass phrase"
		    exit 1
		fi
		apassphrase=$1
		shift
		;;
	    -x)
		shift
		if test "x$1" = "x" ; then
		    echo "You must specify an encryption pass phrase"
		    exit 1
		fi
		xpassphrase=$1
		shift
		;;
	    -ro)
	        token="rouser"
		shift
		;;
 	    -*)
		echo "unknown suboption to --create-snmpv3-user: $1"
		exit 1
		;;
	    *)
	        done=1
		;;
	esac
      done
      
      if test "x$1" = "x" ; then
          prompt=yes
	  echo "Enter a SNMPv3 user name to create: "
	  read user
      else
          user=$1
          shift
      fi
      if test "x$user" = "x" ; then
          echo "You must specify a user name"
	  exit 1
      fi

      if test "x$apassphrase" = "x" ; then
          prompt=yes
	  echo "Enter authentication pass-phrase: "
	  read apassphrase
      fi
      if test "x$apassphrase" = "x" ; then
          echo "You must specify an authentication pass-phrase"
	  exit 1
      fi

      if test "x$prompt" = "xyes" -a "x$xpassphrase" = "x" ; then
	  echo "Enter encryption pass-phrase: "
	  echo "  [press return to reuse the authentication pass-phrase]"
	  read xpassphrase
      fi

      outfile="@PERSISTENT_DIRECTORY@/snmpd.conf"
      line="createUser $user $Aalgorithm \"$apassphrase\" $Xalgorithm $xpassphrase"
      echo "adding the following line to $outfile:"
      echo "  " $line
      echo $line >> $outfile

      outfile="@datadir@/snmp/snmpd.conf"
      line="$token $user"
      echo "adding the following line to $outfile:"
      echo "  " $line
      echo $line >> $outfile
      ;;

    --compile-subagent)
      shift
      while test "x$done" = "x" -a "x$1" != "x" ; do
	case $1 in
            --norm)
	        norm=1
	        shift
		;;
            --cflags)
	        shift
	        if test "x$1" = "x" ; then
	            echo "You must specify the extra cflags"
	            exit 1
	        fi
	        cflags=$1
	        echo "setting extra cflags: $cflags"
	        shift
		;;
            --ldflags)
	        shift
	        if test "x$1" = "x" ; then
	            echo "You must specify the extra ldflags"
	            exit 1
	        fi
	        ldflags=$1
	        echo "setting extra ldflags: $ldflags"
	        shift
		;;
 	    --*)
		echo "unknown suboption to --compile-subagent: $1"
		exit 1
		;;
	    *)
                if test "x$outname" = "x"; then
                  outname=$1
                  shift
                else
	          done=1
                fi
		;;
	esac
      done
      tmpfile=netsnmptmp.$$.c
      if test -f $tmpfile; then
	echo "Ack.  Can't create $tmpfile: already exists"
	exit 1
      fi
      echo "generating the tmporary code file: $tmpfile"
      rm -f $tmpfile
      cat > $tmpfile <<EOF
/* generated from net-snmp-config */
#include <net-snmp/net-snmp-config.h>
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif /* HAVE_SIGNAL_H */
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
EOF

    # If we were only given a single filename
    # (and no explicit output name)
    # then use that as the base of the output name
    #
    # If we weren't even given that, then bomb out
    if test "x$1" = "x"; then
      if test "x$outname" = "x"; then
        echo "No MIB module codefile specified"
        rm -f $tmpfile
        exit 1
      else
        cfiles=$outname
        outname=`basename $cfiles | sed 's/\.[co]$//'`
        if test -f $outname.h; then
          if grep "init_$outname" $outname.h; then
            echo "  #include \"$outname.h\"" >> $tmpfile
          fi
        fi
      fi
    fi

    # add include files
    while test "$1" != ""; do
      cfiles="$cfiles $1"
      name=`basename $1 | sed 's/\.[co]$//'`
      if test -f $name.h; then
        if grep "init_$name" $name.h; then
          echo "  #include \"$name.h\"" >> $tmpfile
        fi
      fi
      shift
    done

      cat >> $tmpfile <<EOF
static int keep_running;

RETSIGTYPE
stop_server(int a) {
    keep_running = 0;
}

int
main (int argc, char **argv) {
  /* print log errors to stderr */
  snmp_enable_stderrlog();
 /* we are a subagent */
  netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);

  /* initialize the agent library */
  init_agent("$outname");

  /* initialize your mib code here */
EOF

    # add init routines
    for i in $cfiles ; do
      name=`basename $i | sed 's/\.[co]$//'`
      echo checking for init_$name in $i
      if grep "init_$name" $i ; then
        echo "  init_${name}();" >> $tmpfile
      fi
      shift
    done

    # finish file
    cat >> $tmpfile <<EOF

  /* ustMain will be used to read ustMain.conf files. */
  init_snmp("$outname");

  /* In case we recevie a request to stop (kill -TERM or kill -INT) */
  keep_running = 1;
#ifdef SIGTERM
  signal(SIGTERM, stop_server);
#endif
#ifdef SIGINT
  signal(SIGINT, stop_server);
#endif

  /* main loop here... */
  while(keep_running) {
    agent_check_and_process(1);
  }

  /* at shutdown time */
  snmp_shutdown("$outname");
  exit(0);
}

EOF
      if test "$?" != 0 -o ! -f "$tmpfile" ; then
        echo "Ack.  Can't create $tmpfile."
	exit 1
      fi
      cmd="@CC@ $cflags @CFLAGS@ @DEVFLAGS@ -I. -I@includedir@ -o $outname $tmpfile $cfiles $NSC_LDFLAGS -L$NSC_EXEC_PREFIX/lib -lnetsnmpagent -lnetsnmphelpers -lnetsnmpmibs -lnetsnmp $NSC_AGENTLIBS @WRAPLIBS@ $ldflags"
      echo "running: $cmd"
      `$cmd`
      if test "x$norm" != "x1" ; then
        echo "removing the tmporary code file: $tmpfile"
        rm -f $tmpfile
      else
        echo "leaving the tmporary code file: $tmpfile"
      fi
      if test -f $outname ; then
        echo "subagent program $outname created"
      fi
      ;;

    *)
      echo "unknown option $1"
      usage="yes"
      ;;
  esac
fi

if test "x$usage" = "xyes"; then
  echo ""
  echo "Usage:"
  echo "  net-snmp-config [--cflags] [--agent-libs] [--libs] [--version]"
  echo "                  ... [see below for complete flag list]"
  echo ""
  echo "    --version         displays the net-snmp version number"
  echo "    --indent-options  displays the indent options from the Coding Style"
  echo "    --debug-tokens    displays a example command line to search to source"
  echo "                      code for a list of available debug tokens"
  echo ""
  echo "  SNMP Setup commands:"
  echo ""
  echo "    --create-snmpv3-user [-ro] [-a authpass] [-x privpass] [-X DES]"
  echo "                         [-A MD5|SHA] [username]"
  echo ""
  echo "  These options produce the various compilation flags needed when"
  echo "  building external SNMP applications:"
  echo ""
  echo "    --base-cflags     lists additional compilation flags needed"
  echo "    --cflags          lists additional compilation flags needed"
  echo "                      (includes -I. and extra developer warning flags)"
  echo ""
  echo "  These options produce the various link flags needed when"
  echo "  building external SNMP applications:"
  echo ""
  echo "    --libs            lists libraries needed for building applications"
  echo "    --agent-libs      lists libraries needed for building subagents"
  echo ""
  echo "  These options produce various link flags broken down into parts."
  echo "  (Most of the time the simple options above should be used.)"
  echo ""
  echo "    --libdir              path to netsnmp libraries"
  echo ""
  echo "    --base-agent-libs     netsnmp specific agent libraries"
  echo ""
  echo "    --netsnmp-libs        netsnmp specific libraries (with path)"
  echo "    --netsnmp-agent-libs  netsnmp specific agent libraries (with path)"
  echo ""
  echo "    --ldflags             link flags for external libraries"
  echo "    --external-libs       external libraries needed by netsnmp libs"
  echo "    --external-agent-libs external libraries needed by netsnmp agent libs"
  echo ""
  echo "  These options produce various link flags used when linking an"
  echo "  external application against an uninstalled build directory."
  echo ""
  echo "    --build-includes      include path to build/source includes"
  echo "    --build-lib-dirs      link path to libraries"
  echo "    --build-lib-deps      path to libraries for dependency target"
  echo ""
  echo "  Automatted subagent building (produces an OUTPUTNAME binary file):"
  echo "  [this feature has not been tested very well yet.  use at your risk.]"
  echo ""
  echo "    --compile-subagent OUTPUTNAME [--norm] [--cflags flags]"
  echo "                                  [--ldflags flags] mibmodule1.c [...]]"
  echo ""
  echo "         --norm           leave the generated .c file around to read."
  echo "         --cflags flags   extra cflags to use (e.g. -I...)."
  echo "         --ldflags flags  extra ld flags to use (e.g. -L... -l...)."
  echo ""
  echo "  Details on how the net-nsmp package was compiled:"
  echo ""
  echo "    --configure-options   Display original configure arguments"
  echo "    --snmpd-module-list   Display the modules compiled into the agent"
  echo "    --prefix              Display the installation prefix"
  echo ""
  exit
fi