[1] | 1 | /* SAMHAIN file system integrity testing */
|
---|
| 2 | /* Copyright (C) 1999, 2000 Rainer Wichmann */
|
---|
| 3 | /* */
|
---|
| 4 | /* This program is free software; you can redistribute it */
|
---|
| 5 | /* and/or modify */
|
---|
| 6 | /* it under the terms of the GNU General Public License as */
|
---|
| 7 | /* published by */
|
---|
| 8 | /* the Free Software Foundation; either version 2 of the License, or */
|
---|
| 9 | /* (at your option) any later version. */
|
---|
| 10 | /* */
|
---|
| 11 | /* This program is distributed in the hope that it will be useful, */
|
---|
| 12 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
---|
| 13 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
---|
| 14 | /* GNU General Public License for more details. */
|
---|
| 15 | /* */
|
---|
| 16 | /* You should have received a copy of the GNU General Public License */
|
---|
| 17 | /* along with this program; if not, write to the Free Software */
|
---|
| 18 | /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
---|
| 19 |
|
---|
| 20 | #include "config_xor.h"
|
---|
| 21 |
|
---|
| 22 | #include <stdlib.h>
|
---|
| 23 | #include <stdio.h>
|
---|
| 24 | #include <string.h>
|
---|
| 25 | #include <limits.h>
|
---|
| 26 | #include <errno.h>
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | #include "samhain.h"
|
---|
| 30 | #include "sh_error.h"
|
---|
| 31 | #include "sh_getopt.h"
|
---|
[367] | 32 | #include "sh_unix.h"
|
---|
[1] | 33 | #include "sh_files.h"
|
---|
| 34 | #include "sh_utils.h"
|
---|
| 35 | #include "sh_mail.h"
|
---|
| 36 | #include "sh_forward.h"
|
---|
| 37 | #include "sh_hash.h"
|
---|
| 38 |
|
---|
| 39 | #if defined(WITH_EXTERNAL)
|
---|
| 40 | #include "sh_extern.h"
|
---|
| 41 | #endif
|
---|
| 42 |
|
---|
[20] | 43 | extern int sh_calls_set_bind_addr (const char *);
|
---|
[1] | 44 |
|
---|
| 45 | #undef FIL__
|
---|
| 46 | #define FIL__ _("sh_getopt.c")
|
---|
| 47 |
|
---|
| 48 | #define HAS_ARG_NO 0
|
---|
| 49 | #define HAS_ARG_YES 1
|
---|
| 50 | #define DROP_PRIV_NO 0
|
---|
| 51 | #define DROP_PRIV_YES 1
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | typedef struct options {
|
---|
[170] | 55 | const char * longopt;
|
---|
[1] | 56 | const char shortopt;
|
---|
[170] | 57 | const char * usage;
|
---|
[1] | 58 | int hasArg;
|
---|
[20] | 59 | int (*func)(const char * opt);
|
---|
[1] | 60 | } opttable_t;
|
---|
| 61 |
|
---|
| 62 | /*@noreturn@*/
|
---|
[20] | 63 | static int sh_getopt_usage (const char * dummy);
|
---|
[1] | 64 | #if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
|
---|
[20] | 65 | static int sh_getopt_forever (const char * dummy);
|
---|
[1] | 66 | #endif
|
---|
[20] | 67 | static int sh_getopt_copyright (const char * dummy);
|
---|
[76] | 68 | static int sh_getopt_version (const char * dummy);
|
---|
[1] | 69 |
|
---|
| 70 | static opttable_t op_table[] = {
|
---|
| 71 |
|
---|
| 72 | #if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
|
---|
| 73 | { N_("set-checksum-test"),
|
---|
| 74 | 't',
|
---|
| 75 | N_("Set checksum testing to 'init', 'update', or 'check'"),
|
---|
| 76 | HAS_ARG_YES,
|
---|
| 77 | sh_util_setchecksum },
|
---|
| 78 | { N_("interactive"),
|
---|
| 79 | 'i',
|
---|
| 80 | N_("Run update in interactive mode"),
|
---|
| 81 | HAS_ARG_NO,
|
---|
| 82 | sh_util_set_interactive },
|
---|
[355] | 83 | { N_("listfile"),
|
---|
| 84 | '-',
|
---|
| 85 | N_("Run update with listfile"),
|
---|
| 86 | HAS_ARG_YES,
|
---|
| 87 | sh_util_update_file },
|
---|
[1] | 88 | #endif
|
---|
[27] | 89 | #if defined(SH_WITH_SERVER) || defined(SH_WITH_CLIENT)
|
---|
| 90 | { N_("server-port"),
|
---|
| 91 | '-',
|
---|
| 92 | N_("Set the server port to connect to"),
|
---|
| 93 | HAS_ARG_YES,
|
---|
| 94 | sh_forward_server_port },
|
---|
| 95 | #endif
|
---|
[1] | 96 | #ifdef SH_WITH_SERVER
|
---|
| 97 | { N_("server"),
|
---|
| 98 | 'S',
|
---|
| 99 | N_("Run as log server (obsolete)"),
|
---|
| 100 | HAS_ARG_NO,
|
---|
| 101 | sh_util_setserver },
|
---|
| 102 | { N_("qualified"),
|
---|
| 103 | 'q',
|
---|
| 104 | N_("Log fully qualified name of client host"),
|
---|
| 105 | HAS_ARG_NO,
|
---|
| 106 | sh_forward_set_strip },
|
---|
| 107 | { N_("chroot"),
|
---|
| 108 | '-',
|
---|
| 109 | N_("Chroot to specified directory"),
|
---|
| 110 | HAS_ARG_YES,
|
---|
| 111 | sh_unix_set_chroot },
|
---|
| 112 | #endif
|
---|
| 113 | { N_("daemon"),
|
---|
| 114 | 'D',
|
---|
| 115 | N_("Run as daemon"),
|
---|
| 116 | HAS_ARG_NO,
|
---|
| 117 | sh_unix_setdeamon },
|
---|
| 118 | { N_("foreground"),
|
---|
| 119 | '-',
|
---|
| 120 | N_("Stay in the foreground"),
|
---|
| 121 | HAS_ARG_NO,
|
---|
| 122 | sh_unix_setnodeamon },
|
---|
| 123 | { N_("bind-address"),
|
---|
| 124 | '-',
|
---|
| 125 | N_("Bind to this address (interface) for outgoing connections"),
|
---|
| 126 | HAS_ARG_YES,
|
---|
| 127 | sh_calls_set_bind_addr },
|
---|
[27] | 128 | #if defined(SH_WITH_SERVER) || defined(SH_WITH_CLIENT)
|
---|
[1] | 129 | { N_("set-export-severity"),
|
---|
| 130 | 'e',
|
---|
| 131 | N_("Set severity threshold for export to remote log server"),
|
---|
| 132 | HAS_ARG_YES,
|
---|
| 133 | sh_error_setexport },
|
---|
| 134 | #endif
|
---|
| 135 | { N_("set-syslog-severity"),
|
---|
| 136 | 's',
|
---|
| 137 | N_("Set severity threshold for syslog"),
|
---|
| 138 | HAS_ARG_YES,
|
---|
| 139 | sh_error_set_syslog },
|
---|
| 140 | #ifdef WITH_EXTERNAL
|
---|
| 141 | { N_("set-extern-severity"),
|
---|
| 142 | 'x',
|
---|
| 143 | N_("Set severity threshold for logging by external program(s)"),
|
---|
| 144 | HAS_ARG_YES,
|
---|
| 145 | sh_error_set_external },
|
---|
| 146 | #endif
|
---|
| 147 | #ifdef HAVE_LIBPRELUDE
|
---|
| 148 | { N_("set-prelude-severity"),
|
---|
| 149 | '-',
|
---|
| 150 | N_("Set severity threshold for logging to prelude"),
|
---|
| 151 | HAS_ARG_YES,
|
---|
| 152 | sh_error_set_prelude },
|
---|
| 153 | #endif
|
---|
| 154 | #if defined(WITH_DATABASE)
|
---|
| 155 | { N_("set-database-severity"),
|
---|
| 156 | '-',
|
---|
| 157 | N_("Set severity threshold for logging to RDBMS"),
|
---|
| 158 | HAS_ARG_YES,
|
---|
| 159 | sh_error_set_database },
|
---|
| 160 | #endif
|
---|
| 161 | { N_("set-log-severity"),
|
---|
| 162 | 'l',
|
---|
| 163 | N_("Set severity threshold for logfile"),
|
---|
| 164 | HAS_ARG_YES,
|
---|
| 165 | sh_error_setlog },
|
---|
| 166 | #if defined(SH_WITH_MAIL)
|
---|
| 167 | { N_("set-mail-severity"),
|
---|
| 168 | 'm',
|
---|
| 169 | N_("Set severitythreshold for e-mail"),
|
---|
| 170 | HAS_ARG_YES,
|
---|
| 171 | sh_error_setseverity },
|
---|
| 172 | #endif
|
---|
| 173 | { N_("set-print-severity"),
|
---|
| 174 | 'p',
|
---|
| 175 | N_("Set the severity threshold for terminal/console log"),
|
---|
| 176 | HAS_ARG_YES,
|
---|
| 177 | sh_error_setprint },
|
---|
| 178 | #if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
|
---|
| 179 | { N_("recursion"),
|
---|
| 180 | 'r',
|
---|
| 181 | N_("Set recursion level for directories"),
|
---|
| 182 | HAS_ARG_YES,
|
---|
| 183 | sh_files_setrecursion },
|
---|
| 184 | #endif
|
---|
| 185 | { N_("verify-log"),
|
---|
| 186 | 'L',
|
---|
| 187 | N_("Verify the audit trail"),
|
---|
| 188 | HAS_ARG_YES,
|
---|
| 189 | sh_error_logverify },
|
---|
| 190 | { N_("just-list"),
|
---|
| 191 | 'j',
|
---|
| 192 | N_("Modify -L to just list the audit trail"),
|
---|
| 193 | HAS_ARG_NO,
|
---|
| 194 | sh_error_logverify_mod },
|
---|
| 195 | #if defined(SH_WITH_MAIL)
|
---|
| 196 | { N_("verify-mail"),
|
---|
| 197 | 'M',
|
---|
| 198 | N_("Verify the mailbox"),
|
---|
| 199 | HAS_ARG_YES,
|
---|
| 200 | sh_mail_sigverify
|
---|
| 201 | },
|
---|
| 202 | #endif
|
---|
| 203 | { N_("add-key"),
|
---|
| 204 | 'V',
|
---|
| 205 | N_("Add key for the mail/log signature"),
|
---|
| 206 | HAS_ARG_YES,
|
---|
| 207 | sh_util_set_newkey
|
---|
| 208 | },
|
---|
| 209 | { N_("hash-string"),
|
---|
| 210 | 'H',
|
---|
| 211 | N_("Print the hash of a string"),
|
---|
| 212 | HAS_ARG_YES,
|
---|
| 213 | sh_error_verify },
|
---|
| 214 | #if defined (SH_WITH_SERVER)
|
---|
| 215 | { N_("password"),
|
---|
| 216 | 'P',
|
---|
| 217 | N_("Compute a client registry entry for password"),
|
---|
| 218 | HAS_ARG_YES,
|
---|
| 219 | sh_forward_make_client },
|
---|
| 220 | { N_("gen-password"),
|
---|
| 221 | 'G',
|
---|
| 222 | N_("Generate a random password"),
|
---|
| 223 | HAS_ARG_NO,
|
---|
| 224 | sh_forward_create_password },
|
---|
| 225 | #endif
|
---|
| 226 |
|
---|
| 227 | #if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
|
---|
| 228 | { N_("forever"),
|
---|
| 229 | 'f',
|
---|
| 230 | N_("Loop forever, even if not daemon"),
|
---|
| 231 | HAS_ARG_NO,
|
---|
| 232 | sh_getopt_forever},
|
---|
[169] | 233 | { N_("list-file"),
|
---|
| 234 | '-',
|
---|
| 235 | N_("Modify -d to list content of a single file"),
|
---|
| 236 | HAS_ARG_YES,
|
---|
| 237 | set_list_file},
|
---|
[1] | 238 | { N_("full-detail"),
|
---|
| 239 | 'a',
|
---|
| 240 | N_("Modify -d to list full details"),
|
---|
| 241 | HAS_ARG_NO,
|
---|
| 242 | set_full_detail},
|
---|
| 243 | { N_("delimited"),
|
---|
| 244 | '-',
|
---|
| 245 | N_("Modify -d to list full details, comma delimited"),
|
---|
| 246 | HAS_ARG_NO,
|
---|
| 247 | set_list_delimited},
|
---|
| 248 | { N_("list-database"),
|
---|
| 249 | 'd',
|
---|
| 250 | N_("List database content (like ls -l)"),
|
---|
| 251 | HAS_ARG_YES,
|
---|
| 252 | sh_hash_list_db},
|
---|
| 253 | { N_("init2stdout"),
|
---|
| 254 | '-',
|
---|
| 255 | N_("Write database to stdout on init"),
|
---|
| 256 | HAS_ARG_NO,
|
---|
| 257 | sh_hash_pushdata_stdout},
|
---|
| 258 | #endif
|
---|
| 259 | { N_("trace-logfile"),
|
---|
| 260 | '-',
|
---|
| 261 | N_("Logfile for trace"),
|
---|
| 262 | HAS_ARG_YES,
|
---|
| 263 | sl_trace_file },
|
---|
| 264 | { N_("trace-enable"),
|
---|
| 265 | '-',
|
---|
| 266 | N_("Enable tracing"),
|
---|
| 267 | HAS_ARG_NO,
|
---|
| 268 | sl_trace_use },
|
---|
| 269 | { N_("copyright"),
|
---|
| 270 | 'c',
|
---|
| 271 | N_("Print copyright information"),
|
---|
| 272 | HAS_ARG_NO,
|
---|
| 273 | sh_getopt_copyright },
|
---|
| 274 | { N_("help"),
|
---|
| 275 | 'h',
|
---|
| 276 | N_("Print usage information"),
|
---|
| 277 | HAS_ARG_NO,
|
---|
| 278 | sh_getopt_usage },
|
---|
[76] | 279 | { N_("version"),
|
---|
| 280 | 'v',
|
---|
| 281 | N_("Show version and compiled-in options"),
|
---|
| 282 | HAS_ARG_NO,
|
---|
| 283 | sh_getopt_version },
|
---|
[181] | 284 | #if defined(HAVE_LIBPRELUDE)
|
---|
[20] | 285 | /* need to skip over these */
|
---|
| 286 | { N_("prelude"),
|
---|
| 287 | '-',
|
---|
| 288 | N_("Prelude generic options"),
|
---|
| 289 | HAS_ARG_NO,
|
---|
| 290 | NULL },
|
---|
| 291 | { N_("profile"),
|
---|
| 292 | '-',
|
---|
| 293 | N_("Profile to use for this analyzer"),
|
---|
| 294 | HAS_ARG_YES,
|
---|
| 295 | NULL },
|
---|
| 296 | { N_("heartbeat-interval"),
|
---|
| 297 | '-',
|
---|
| 298 | N_("Number of seconds between two heartbeats"),
|
---|
| 299 | HAS_ARG_YES,
|
---|
| 300 | NULL },
|
---|
| 301 | { N_("server-addr"),
|
---|
| 302 | '-',
|
---|
| 303 | N_("Address where this sensor should report to"),
|
---|
| 304 | HAS_ARG_YES,
|
---|
| 305 | NULL },
|
---|
| 306 | { N_("analyzer-name"),
|
---|
| 307 | '-',
|
---|
| 308 | N_("Name for this analyzer"),
|
---|
| 309 | HAS_ARG_YES,
|
---|
| 310 | NULL },
|
---|
| 311 | #endif
|
---|
[1] | 312 | /* last entry -- required !! -- */
|
---|
| 313 | { NULL,
|
---|
| 314 | '\0',
|
---|
| 315 | NULL,
|
---|
| 316 | HAS_ARG_NO,
|
---|
| 317 | NULL }
|
---|
| 318 | };
|
---|
| 319 |
|
---|
[76] | 320 |
|
---|
[170] | 321 | static void sh_getopt_print_log_facilities (void)
|
---|
[76] | 322 | {
|
---|
[171] | 323 | int num = 0;
|
---|
[76] | 324 |
|
---|
[171] | 325 | fputs (_("Compiled-in log facilities:\n"), stdout);
|
---|
| 326 |
|
---|
[76] | 327 | #ifndef DEFAULT_CONSOLE
|
---|
[171] | 328 | if (num > 0) fputc ('\n', stdout);
|
---|
[210] | 329 | printf ("%s", _(" console (/dev/console)")); ++num;
|
---|
[76] | 330 | #else
|
---|
[171] | 331 | if (num > 0) fputc ('\n', stdout);
|
---|
[76] | 332 | if (0 == strcmp (DEFAULT_CONSOLE, _("NULL")))
|
---|
[210] | 333 | { printf ("%s", _("console (/dev/console)")); ++num; }
|
---|
[76] | 334 | else
|
---|
[171] | 335 | { printf (_("console (%s)"), DEFAULT_CONSOLE); ++num; }
|
---|
[76] | 336 | #endif
|
---|
[171] | 337 | if (num > 0) fputc ('\n', stdout);
|
---|
| 338 | fputs (_(" syslog"), stdout); ++num;
|
---|
| 339 | if (num > 0) fputc ('\n', stdout);
|
---|
| 340 | printf (_(" logfile (%s)"), DEFAULT_ERRFILE); ++num;
|
---|
[76] | 341 |
|
---|
| 342 | #if defined(WITH_EXTERNAL)
|
---|
[171] | 343 | if (num > 0) fputc ('\n', stdout);
|
---|
| 344 | fputs (_(" external program"), stdout); ++num;
|
---|
[76] | 345 | #endif
|
---|
| 346 |
|
---|
| 347 | #if defined(WITH_MESSAGE_QUEUE)
|
---|
[171] | 348 | if (num > 0) fputc ('\n', stdout);
|
---|
| 349 | fputs (_(" message queue"), stdout); ++num;
|
---|
[76] | 350 | #endif
|
---|
| 351 |
|
---|
| 352 | #if defined(WITH_DATABASE)
|
---|
[171] | 353 | if (num > 0) fputc ('\n', stdout);
|
---|
| 354 | fputs (_(" database"), stdout); ++num;
|
---|
[76] | 355 | #ifdef WITH_ODBC
|
---|
| 356 | fputs (_(" (odbc)"), stdout);
|
---|
| 357 | #endif
|
---|
| 358 | #ifdef WITH_ORACLE
|
---|
| 359 | fputs (_(" (Oracle)"), stdout);
|
---|
| 360 | #endif
|
---|
| 361 | #ifdef WITH_POSTGRES
|
---|
| 362 | fputs (_(" (PostgreSQL)"), stdout);
|
---|
| 363 | #endif
|
---|
| 364 | #ifdef WITH_MYSQL
|
---|
| 365 | fputs (_(" (MySQL)"), stdout);
|
---|
| 366 | #endif
|
---|
| 367 | #endif
|
---|
| 368 |
|
---|
| 369 | #if defined(SH_WITH_CLIENT) || defined(SH_WITH_SERVER)
|
---|
[171] | 370 | if (num > 0) fputc ('\n', stdout);
|
---|
| 371 | fputs (_(" server"), stdout); ++num;
|
---|
[76] | 372 | #endif
|
---|
| 373 |
|
---|
| 374 | #if defined(SH_WITH_MAIL)
|
---|
[171] | 375 | if (num > 0) fputc ('\n', stdout);
|
---|
| 376 | fputs (_(" email"), stdout); ++num;
|
---|
[76] | 377 | #endif
|
---|
| 378 |
|
---|
| 379 | #ifdef HAVE_LIBPRELUDE
|
---|
[171] | 380 | if (num > 0) fputc ('\n', stdout); ++num;
|
---|
[181] | 381 | fputs (_(" prelude (0.9.6+)"), stdout);
|
---|
[76] | 382 | #endif
|
---|
| 383 |
|
---|
[171] | 384 | if (num == 0)
|
---|
| 385 | fputs (_(" none"), stdout);
|
---|
[76] | 386 | fputc ('\n', stdout);
|
---|
| 387 | return;
|
---|
| 388 | }
|
---|
| 389 |
|
---|
[170] | 390 | static void sh_getopt_print_options (void)
|
---|
[76] | 391 | {
|
---|
| 392 | int num = 0;
|
---|
| 393 |
|
---|
| 394 |
|
---|
| 395 | #if defined(SH_STANDALONE)
|
---|
| 396 | if (num > 0) fputc ('\n', stdout);
|
---|
| 397 | fputs (_("Standalone executable"), stdout); ++num;
|
---|
| 398 | #endif
|
---|
| 399 | #if defined(SH_WITH_CLIENT)
|
---|
| 400 | if (num > 0) fputc ('\n', stdout);
|
---|
| 401 | printf (_("Client executable (port %d)"), SH_DEFAULT_PORT); ++num;
|
---|
| 402 | #endif
|
---|
[415] | 403 | #if defined(SH_WITH_SERVER)
|
---|
[76] | 404 | if (num > 0) fputc ('\n', stdout);
|
---|
| 405 | printf (_("Server executable (port %d, user %s)"),
|
---|
| 406 | SH_DEFAULT_PORT, DEFAULT_IDENT);
|
---|
| 407 | ++num;
|
---|
| 408 | #endif
|
---|
[295] | 409 | #if defined(USE_IPVX)
|
---|
| 410 | fputs (_(", IPv6 supported"), stdout);
|
---|
| 411 | #endif
|
---|
[76] | 412 |
|
---|
| 413 | fputs (_(", compiled-in options:"), stdout);
|
---|
| 414 |
|
---|
[182] | 415 | #if defined(USE_SYSTEM_MALLOC)
|
---|
[171] | 416 | if (num > 0) fputc ('\n', stdout);
|
---|
[210] | 417 | fputs (_(" using system malloc"), stdout); ++num;
|
---|
[171] | 418 | #else
|
---|
| 419 | if (num > 0) fputc ('\n', stdout);
|
---|
[210] | 420 | fputs (_(" using dnmalloc"), stdout); ++num;
|
---|
[171] | 421 | #endif
|
---|
| 422 |
|
---|
[76] | 423 | #if defined(HAVE_EGD_RANDOM)
|
---|
| 424 | if (num > 0) fputc ('\n', stdout);
|
---|
[171] | 425 | printf (_(" using entropy gathering daemon (%s)"), EGD_SOCKET_NAME); ++num;
|
---|
[76] | 426 | #endif
|
---|
| 427 | #if defined(HAVE_UNIX_RANDOM)
|
---|
| 428 | if (num > 0) fputc ('\n', stdout);
|
---|
[171] | 429 | fputs (_(" using unix entropy gatherer"), stdout); ++num;
|
---|
[76] | 430 | #endif
|
---|
| 431 | #if defined(HAVE_URANDOM)
|
---|
| 432 | if (num > 0) fputc ('\n', stdout);
|
---|
[171] | 433 | printf (_(" using entropy device (%s)"), NAME_OF_DEV_RANDOM); ++num;
|
---|
[76] | 434 | #endif
|
---|
| 435 |
|
---|
| 436 | #ifdef WITH_GPG
|
---|
| 437 | if (num > 0) fputc ('\n', stdout);
|
---|
| 438 | printf (_(" GnuPG signatures (%s)"), DEFAULT_GPG_PATH); ++num;
|
---|
| 439 | #ifdef HAVE_GPG_CHECKSUM
|
---|
| 440 | if (num > 0) fputc ('\n', stdout);
|
---|
| 441 | printf (_(" -- GnuPG checksum: %s"), GPG_HASH); ++num;
|
---|
| 442 | #endif
|
---|
| 443 | #ifdef USE_FINGERPRINT
|
---|
| 444 | if (num > 0) fputc ('\n', stdout);
|
---|
| 445 | printf (_(" -- Key fingerprint: %s"), SH_GPG_FP); ++num;
|
---|
| 446 | #endif
|
---|
| 447 | #endif
|
---|
| 448 |
|
---|
[347] | 449 | #if defined(SH_SHELL_EVAL)
|
---|
| 450 | if (num > 0) fputc ('\n', stdout);
|
---|
| 451 | fputs (_(" shell expansion in configuration file supported"), stdout); ++num;
|
---|
| 452 | #endif
|
---|
| 453 |
|
---|
[76] | 454 | #if defined(SL_DEBUG)
|
---|
| 455 | if (num > 0) fputc ('\n', stdout);
|
---|
[171] | 456 | fputs (_(" debug build (do not use for production)"), stdout); ++num;
|
---|
[76] | 457 | #endif
|
---|
| 458 | #if defined(SCREW_IT_UP)
|
---|
| 459 | if (num > 0) fputc ('\n', stdout);
|
---|
| 460 | fputs (_(" anti-debugger"), stdout); ++num;
|
---|
| 461 | #endif
|
---|
| 462 | #if defined(SH_USE_XML)
|
---|
| 463 | if (num > 0) fputc ('\n', stdout);
|
---|
| 464 | fputs (_(" xml log format"), stdout); ++num;
|
---|
| 465 | #endif
|
---|
| 466 | #if defined(HAVE_NTIME)
|
---|
| 467 | if (num > 0) fputc ('\n', stdout);
|
---|
[171] | 468 | fputs (_(" using time server"), stdout); ++num;
|
---|
[76] | 469 | #endif
|
---|
[272] | 470 | #if defined(HAVE_REGEX_H)
|
---|
| 471 | if (num > 0) fputc ('\n', stdout);
|
---|
| 472 | fputs (_(" posix regex support"), stdout); ++num;
|
---|
| 473 | #endif
|
---|
[76] | 474 |
|
---|
[272] | 475 |
|
---|
[76] | 476 | #if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
|
---|
[169] | 477 | #if defined(HAVE_LIBZ)
|
---|
| 478 | if (num > 0) fputc ('\n', stdout);
|
---|
| 479 | fputs (_(" optionally store full text for files"), stdout); ++num;
|
---|
| 480 | #endif
|
---|
[294] | 481 | #if !defined(SH_COMPILE_STATIC) && defined(__linux__) && defined(HAVE_AUPARSE_H) && defined(HAVE_AUPARSE_LIB)
|
---|
| 482 | if (num > 0) fputc ('\n', stdout);
|
---|
| 483 | fputs (_(" optionally report auditd record of changed file"), stdout); ++num;
|
---|
| 484 | #endif
|
---|
[76] | 485 | #if defined(USE_XATTR)
|
---|
| 486 | if (num > 0) fputc ('\n', stdout);
|
---|
| 487 | fputs (_(" check SELinux attributes"), stdout); ++num;
|
---|
| 488 | #endif
|
---|
| 489 | #if defined(USE_ACL)
|
---|
| 490 | if (num > 0) fputc ('\n', stdout);
|
---|
| 491 | fputs (_(" check Posix ACLs"), stdout); ++num;
|
---|
| 492 | #endif
|
---|
| 493 | #if defined(RELOAD_DATABASE)
|
---|
| 494 | if (num > 0) fputc ('\n', stdout);
|
---|
| 495 | fputs (_(" fetch database on reload"), stdout); ++num;
|
---|
| 496 | #endif
|
---|
| 497 | #endif
|
---|
| 498 |
|
---|
| 499 | #if defined(SH_WITH_SERVER)
|
---|
| 500 |
|
---|
| 501 | #if !defined(HAVE_GETPEEREID) && !defined(SO_PEERCRED) && !defined(HAVE_STRUCT_CMSGCRED) && !defined(HAVE_STRUCT_FCRED) && !(defined(HAVE_STRUCT_SOCKCRED) && defined(LOCAL_CREDS))
|
---|
| 502 | if (num > 0) fputc ('\n', stdout);
|
---|
| 503 | fputs (_(" command socket authentication: use SetSocketPassword"), stdout);
|
---|
| 504 | ++num;
|
---|
| 505 | #else
|
---|
| 506 | if (num > 0) fputc ('\n', stdout);
|
---|
| 507 | fputs (_(" command socket authentication: use SetSocketAllowUID"), stdout);
|
---|
| 508 | ++num;
|
---|
| 509 | #endif
|
---|
| 510 |
|
---|
| 511 | #if defined(SH_USE_LIBWRAP)
|
---|
| 512 | if (num > 0) fputc ('\n', stdout);
|
---|
| 513 | fputs (_(" support tcp wrapper"), stdout); ++num;
|
---|
| 514 | #endif
|
---|
| 515 | #if defined(INET_SYSLOG)
|
---|
| 516 | if (num > 0) fputc ('\n', stdout);
|
---|
| 517 | fputs (_(" support listening on 514/udp (syslog)"), stdout); ++num;
|
---|
| 518 | #endif
|
---|
| 519 | #endif
|
---|
| 520 |
|
---|
| 521 | if (num == 0)
|
---|
| 522 | fputs (_(" none"), stdout);
|
---|
| 523 | fputc ('\n', stdout);
|
---|
| 524 | return;
|
---|
| 525 | }
|
---|
| 526 |
|
---|
[170] | 527 | static void sh_getopt_print_modules (void)
|
---|
[76] | 528 | {
|
---|
| 529 | #if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
|
---|
| 530 | int num = 0;
|
---|
| 531 |
|
---|
[171] | 532 | fputs (_("Compiled-in modules:\n"), stdout);
|
---|
[76] | 533 | #ifdef SH_USE_UTMP
|
---|
| 534 | if (num > 0) fputc (',', stdout);
|
---|
| 535 | fputs (_(" login/logout"), stdout); ++num;
|
---|
| 536 | #endif
|
---|
| 537 | #ifdef SH_USE_MOUNTS
|
---|
| 538 | if (num > 0) fputc (',', stdout);
|
---|
| 539 | fputs (_(" mount options"), stdout); ++num;
|
---|
| 540 | #endif
|
---|
| 541 | #ifdef SH_USE_USERFILES
|
---|
| 542 | if (num > 0) fputc (',', stdout);
|
---|
| 543 | fputs (_(" userfiles"), stdout); ++num;
|
---|
| 544 | #endif
|
---|
| 545 | #ifdef SH_USE_KERN
|
---|
| 546 | if (num > 0) fputc (',', stdout);
|
---|
| 547 | fputs (_(" kernel"), stdout); ++num;
|
---|
| 548 | #endif
|
---|
| 549 | #ifdef SH_USE_SUIDCHK
|
---|
| 550 | if (num > 0) fputc (',', stdout);
|
---|
| 551 | fputs (_(" suid"), stdout); ++num;
|
---|
| 552 | #endif
|
---|
| 553 | #ifdef SH_USE_PROCESSCHECK
|
---|
| 554 | if (num > 0) fputc (',', stdout);
|
---|
| 555 | fputs (_(" processes"), stdout); ++num;
|
---|
| 556 | #endif
|
---|
| 557 | #ifdef SH_USE_PORTCHECK
|
---|
| 558 | if (num > 0) fputc (',', stdout);
|
---|
| 559 | fputs (_(" ports"), stdout); ++num;
|
---|
| 560 | #endif
|
---|
[183] | 561 | #ifdef USE_LOGFILE_MONITOR
|
---|
| 562 | if (num > 0) fputc (',', stdout);
|
---|
| 563 | fputs (_(" logfile monitor"), stdout); ++num;
|
---|
| 564 | #endif
|
---|
[422] | 565 | #if defined(USE_REGISTRY_CHECK)
|
---|
| 566 | if (num > 0) fputc ('\n', stdout);
|
---|
| 567 | fputs (_(" Windows registry"), stdout); ++num;
|
---|
| 568 | #endif
|
---|
[76] | 569 | if (num == 0)
|
---|
| 570 | fputs (_(" none"), stdout);
|
---|
| 571 | fputc ('\n', stdout);
|
---|
| 572 | #endif
|
---|
| 573 | return;
|
---|
| 574 | }
|
---|
| 575 |
|
---|
| 576 | static int sh_getopt_version (const char * dummy)
|
---|
| 577 | {
|
---|
| 578 | (void) dummy;
|
---|
| 579 | fprintf (stdout,
|
---|
| 580 | _("This is samhain (%s), "\
|
---|
[161] | 581 | "(c) 1999-2008 Rainer Wichmann (http://la-samhna.de).\n"),
|
---|
[76] | 582 | VERSION);
|
---|
[210] | 583 | fprintf (stdout, "%s",_("This software comes with ABSOLUTELY NO WARRANTY. "));
|
---|
| 584 | fprintf (stdout, "%s",_("Use at own risk.\n\n"));
|
---|
[76] | 585 |
|
---|
| 586 | sh_getopt_print_log_facilities ();
|
---|
| 587 | sh_getopt_print_modules ();
|
---|
| 588 | sh_getopt_print_options ();
|
---|
| 589 |
|
---|
| 590 | _exit (EXIT_SUCCESS);
|
---|
| 591 | /*@notreached@*/
|
---|
| 592 | return 0; /* make compilers happy */
|
---|
| 593 | }
|
---|
[20] | 594 | static int sh_getopt_copyright (const char * dummy)
|
---|
[1] | 595 | {
|
---|
[210] | 596 | fprintf (stdout, "%s",
|
---|
[161] | 597 | _("Copyright (C) 1999-2008 Rainer Wichmann"\
|
---|
[1] | 598 | " (http://la-samhna.de).\n\n"));
|
---|
| 599 |
|
---|
[210] | 600 | fprintf (stdout, "%s",
|
---|
[1] | 601 | _("This program is free software; "\
|
---|
| 602 | "you can redistribute it and/or modify\n"));
|
---|
[210] | 603 | fprintf (stdout, "%s",_("it under the terms of the GNU General "\
|
---|
[1] | 604 | "Public License as published by\n"));
|
---|
[210] | 605 | fprintf (stdout, "%s",_("the Free Software Foundation; either version 2 "\
|
---|
[1] | 606 | "of the License, or\n"));
|
---|
[210] | 607 | fprintf (stdout, "%s",_("(at your option) any later version.\n\n"));
|
---|
[1] | 608 |
|
---|
[210] | 609 | fprintf (stdout, "%s",_("This program is distributed in the hope "\
|
---|
[1] | 610 | "that it will be useful,\n"));
|
---|
[210] | 611 | fprintf (stdout, "%s",_("but WITHOUT ANY WARRANTY; "\
|
---|
[1] | 612 | "without even the implied warranty of\n"));
|
---|
[210] | 613 | fprintf (stdout, "%s",_("MERCHANTABILITY or FITNESS FOR A PARTICULAR "\
|
---|
| 614 | "PURPOSE. See the\n"));
|
---|
| 615 | fprintf (stdout, "%s",_("GNU General Public License for more details.\n\n"));
|
---|
[1] | 616 |
|
---|
[210] | 617 | fprintf (stdout, "%s",_("You should have received a copy of the "\
|
---|
[1] | 618 | "GNU General Public License\n"));
|
---|
[210] | 619 | fprintf (stdout, "%s",_("along with this program; "\
|
---|
[1] | 620 | "if not, write to the Free Software\n"));
|
---|
[210] | 621 | fprintf (stdout, "%s",_("Foundation, Inc., 59 Temple Place - Suite 330, "\
|
---|
[1] | 622 | "Boston, MA 02111-1307, USA.\n\n"));
|
---|
| 623 |
|
---|
[210] | 624 | fprintf (stdout, "%s",_("This product makes use of the reference "\
|
---|
| 625 | "implementation of the TIGER message\n"));
|
---|
| 626 | fprintf (stdout, "%s",_("digest algorithm. This code is copyright Eli Biham "\
|
---|
[1] | 627 | "(biham@cs.technion.ac.il)\n"));
|
---|
[210] | 628 | fprintf (stdout, "%s",_("and Ross Anderson (rja14@cl.cam.ac.uk). It can be used "\
|
---|
[1] | 629 | "freely without any\n"));
|
---|
[210] | 630 | fprintf (stdout, "%s",_("restrictions.\n"));
|
---|
[1] | 631 | #if defined(USE_SRP_PROTOCOL) && !defined(SH_STANDALONE)
|
---|
| 632 | #if (!defined(HAVE_LIBGMP) || !defined(HAVE_GMP_H))
|
---|
[210] | 633 | fprintf (stdout, "%s",_("This product makes use of the 'bignum' library by "\
|
---|
[1] | 634 | "Henrik Johansson\n"));
|
---|
[210] | 635 | fprintf (stdout, "%s",_("(Henrik.Johansson@Nexus.Comm.SE). If you are "\
|
---|
| 636 | "including this library in a\n"));
|
---|
| 637 | fprintf (stdout, "%s",_("commercial product, be sure to distribute ALL of"\
|
---|
[1] | 638 | " it with the product.\n"));
|
---|
| 639 | #endif
|
---|
[210] | 640 | fprintf (stdout, "%s",_("This product uses the 'Secure Remote Password' "\
|
---|
[1] | 641 | "cryptographic\n"));
|
---|
[210] | 642 | fprintf (stdout, "%s",_("authentication system developed by Tom Wu "\
|
---|
[1] | 643 | "(tjw@CS.Stanford.EDU).\n"));
|
---|
| 644 | #endif
|
---|
[210] | 645 | fprintf (stdout, "%s",_("\nPlease refer to the file COPYING in the source "\
|
---|
[1] | 646 | "distribution for a"));
|
---|
[210] | 647 | fprintf (stdout, "%s",_("\nfull list of incorporated code and associated "\
|
---|
[1] | 648 | "licenses.\n"));
|
---|
| 649 |
|
---|
| 650 | if (dummy)
|
---|
| 651 | _exit (EXIT_SUCCESS);
|
---|
| 652 | else
|
---|
| 653 | _exit (EXIT_SUCCESS);
|
---|
| 654 | /*@notreached@*/
|
---|
| 655 | return 0; /* make compilers happy */
|
---|
| 656 | }
|
---|
| 657 |
|
---|
| 658 | /*@noreturn@*/
|
---|
[20] | 659 | static int sh_getopt_usage (const char * dummy)
|
---|
[1] | 660 | {
|
---|
| 661 | int i;
|
---|
| 662 | char fmt[64];
|
---|
| 663 |
|
---|
| 664 | char opts[64];
|
---|
| 665 |
|
---|
| 666 | for (i = 0; i < 64; ++i) /* splint does not grok char opts[64] = { '\0' }; */
|
---|
| 667 | opts[i] = '\0';
|
---|
| 668 |
|
---|
| 669 | fprintf (stdout,
|
---|
| 670 | _("This is samhain (%s), "\
|
---|
[76] | 671 | "(c) 1999-2006 Rainer Wichmann (http://la-samhna.de).\n"),
|
---|
[1] | 672 | VERSION);
|
---|
[210] | 673 | fprintf (stdout, "%s",_("This software comes with ABSOLUTELY NO WARRANTY. "));
|
---|
| 674 | fprintf (stdout, "%s",_("Use at own risk.\n"));
|
---|
[1] | 675 |
|
---|
[210] | 676 | fprintf (stdout, "%s",_("Usage:\n\n"));
|
---|
[1] | 677 |
|
---|
| 678 | for (i = 0; op_table[i].longopt != NULL; ++i) {
|
---|
| 679 |
|
---|
| 680 | if (i == 63)
|
---|
| 681 | break;
|
---|
| 682 |
|
---|
| 683 | if (op_table[i].shortopt != '-' &&
|
---|
| 684 | strchr(opts, op_table[i].shortopt) != NULL)
|
---|
[210] | 685 | fprintf (stdout, "%s",_("Short option char collision !\n"));
|
---|
[1] | 686 | opts[i] = op_table[i].shortopt;
|
---|
| 687 |
|
---|
| 688 |
|
---|
| 689 | if (op_table[i].hasArg == HAS_ARG_NO) {
|
---|
| 690 | if (sl_strlen(op_table[i].longopt) < 10)
|
---|
[22] | 691 | sl_strlcpy(fmt,_("%c%c%c --%-s,\t\t\t %s\n"), sizeof(fmt));
|
---|
[1] | 692 | else if (sl_strlen(op_table[i].longopt) < 17)
|
---|
[22] | 693 | sl_strlcpy(fmt, _("%c%c%c --%-s,\t\t %s\n"), sizeof(fmt));
|
---|
[1] | 694 | else
|
---|
[22] | 695 | sl_strlcpy(fmt, _("%c%c%c --%-s,\t %s\n"), sizeof(fmt));
|
---|
| 696 | /* flawfinder: ignore */
|
---|
| 697 | fprintf (stdout, fmt,
|
---|
[1] | 698 | (op_table[i].shortopt == '-') ? ' ' : '-',
|
---|
| 699 | (op_table[i].shortopt == '-') ? ' ' : op_table[i].shortopt,
|
---|
| 700 | (op_table[i].shortopt == '-') ? ' ' : ',',
|
---|
| 701 | _(op_table[i].longopt),
|
---|
| 702 | _(op_table[i].usage));
|
---|
| 703 | } else {
|
---|
| 704 | if (sl_strlen(op_table[i].longopt) < 12)
|
---|
[22] | 705 | sl_strlcpy(fmt, _("%c%c %s --%-s=<arg>,\t\t %s\n"), sizeof(fmt));
|
---|
[1] | 706 | else
|
---|
[22] | 707 | sl_strlcpy(fmt, _("%c%c %s --%-s=<arg>,\t %s\n"), sizeof(fmt));
|
---|
| 708 | /* flawfinder: ignore */
|
---|
| 709 | fprintf (stdout, fmt,
|
---|
[1] | 710 | (op_table[i].shortopt == '-') ? ' ' : '-',
|
---|
| 711 | (op_table[i].shortopt == '-') ? ' ' : op_table[i].shortopt,
|
---|
| 712 | (op_table[i].shortopt == '-') ? _(" ") : _("<arg>,"),
|
---|
| 713 | _(op_table[i].longopt),
|
---|
| 714 | _(op_table[i].usage));
|
---|
| 715 | }
|
---|
| 716 | }
|
---|
| 717 |
|
---|
[210] | 718 | fprintf (stdout, "%s",
|
---|
[1] | 719 | _("\nPlease report bugs to support@la-samhna.de.\n"));
|
---|
| 720 |
|
---|
| 721 | (void) fflush(stdout);
|
---|
| 722 |
|
---|
| 723 | if ( dummy != NULL)
|
---|
| 724 | {
|
---|
| 725 | if (sl_strcmp( dummy, _("fail")) == 0 )
|
---|
| 726 | _exit (EXIT_FAILURE);
|
---|
| 727 | }
|
---|
| 728 |
|
---|
| 729 | _exit (EXIT_SUCCESS);
|
---|
| 730 | /*@notreached@*/
|
---|
| 731 | return 0; /* make compilers happy */
|
---|
| 732 | }
|
---|
| 733 |
|
---|
| 734 | #if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
|
---|
[20] | 735 | static int sh_getopt_forever (const char * dummy)
|
---|
[1] | 736 | {
|
---|
[170] | 737 | (void) dummy;
|
---|
[1] | 738 | SL_ENTER(_("sh_getopt_forever"));
|
---|
| 739 | sh.flag.loop = S_TRUE;
|
---|
| 740 | SL_RETURN(0, _("sh_getopt_forever"));
|
---|
| 741 | }
|
---|
| 742 | #endif
|
---|
| 743 |
|
---|
| 744 | int sh_getopt_get (int argc, char * argv[])
|
---|
| 745 | {
|
---|
| 746 | int count = 0;
|
---|
| 747 | size_t len = 0;
|
---|
| 748 | int foundit = 0;
|
---|
| 749 | int i;
|
---|
| 750 | size_t k;
|
---|
| 751 | char * theequal;
|
---|
| 752 |
|
---|
| 753 | SL_ENTER(_("sh_getopt_get"));
|
---|
| 754 |
|
---|
| 755 | /* -- Return if no args. --
|
---|
| 756 | */
|
---|
| 757 | if (argc < 2)
|
---|
| 758 | SL_RETURN(0, _("sh_getopt_get"));
|
---|
| 759 |
|
---|
| 760 | while (argc > 1 && argv[1][0] == '-')
|
---|
| 761 | {
|
---|
| 762 |
|
---|
| 763 | /* Initialize
|
---|
| 764 | */
|
---|
| 765 | foundit = 0;
|
---|
| 766 | len = sl_strlen (argv[1]);
|
---|
| 767 |
|
---|
| 768 | /* a '-' with no argument: error
|
---|
| 769 | */
|
---|
| 770 | if (len == 1)
|
---|
| 771 | (void) sh_getopt_usage(_("fail"));
|
---|
| 772 |
|
---|
| 773 | /* a '--' with no argument: stop argument processing
|
---|
| 774 | */
|
---|
| 775 | if (len == 2 && argv[1][1] == '-')
|
---|
| 776 | SL_RETURN( count, _("sh_getopt_get"));
|
---|
| 777 |
|
---|
| 778 | /* a short option: process it
|
---|
| 779 | */
|
---|
| 780 | if (len >= 2 && argv[1][1] != '-')
|
---|
| 781 | {
|
---|
| 782 | for (k = 1; k < len; ++k)
|
---|
| 783 | {
|
---|
| 784 | for (i = 0; op_table[i].shortopt != '\0'; ++i)
|
---|
| 785 | {
|
---|
| 786 |
|
---|
| 787 | if ( op_table[i].shortopt == argv[1][k] )
|
---|
| 788 | {
|
---|
| 789 | foundit = 1;
|
---|
| 790 | if ( op_table[i].hasArg == HAS_ARG_YES )
|
---|
| 791 | {
|
---|
| 792 | if (k != (len - 1))
|
---|
| 793 | {
|
---|
| 794 | /* not last option
|
---|
| 795 | */
|
---|
[210] | 796 | fprintf (stderr, "%s",
|
---|
[1] | 797 | _("Error: short option with argument is not last in option string\n"));
|
---|
| 798 | (void) sh_getopt_usage(_("fail"));
|
---|
| 799 | }
|
---|
| 800 | if (argc < 3)
|
---|
| 801 | {
|
---|
| 802 | /* argument required, but no avail
|
---|
| 803 | */
|
---|
[210] | 804 | fprintf (stderr, "%s",
|
---|
| 805 | _("Error: missing argument\n"));
|
---|
[1] | 806 | (void) sh_getopt_usage(_("fail"));
|
---|
| 807 | }
|
---|
| 808 | else
|
---|
| 809 | {
|
---|
| 810 | /* call function with argument */
|
---|
| 811 | --argc; ++argv;
|
---|
[20] | 812 | if (NULL != op_table[i].func &&
|
---|
| 813 | 0 != (* op_table[i].func )(argv[1]))
|
---|
[1] | 814 | fprintf (stderr,
|
---|
[42] | 815 | _("Error processing option -%c\n"),
|
---|
[1] | 816 | op_table[i].shortopt);
|
---|
| 817 | break;
|
---|
| 818 | }
|
---|
| 819 | }
|
---|
| 820 | else
|
---|
| 821 | {
|
---|
[20] | 822 | if (NULL != op_table[i].func &&
|
---|
| 823 | 0 != (* op_table[i].func )(NULL))
|
---|
[1] | 824 | fprintf (stderr,
|
---|
[42] | 825 | _("Error processing option -%c\n"),
|
---|
[1] | 826 | op_table[i].shortopt);
|
---|
| 827 | break;
|
---|
| 828 | }
|
---|
| 829 | }
|
---|
| 830 | }
|
---|
| 831 | }
|
---|
| 832 |
|
---|
| 833 | /* 'break' should get here
|
---|
| 834 | */
|
---|
| 835 | if (foundit == 1)
|
---|
| 836 | {
|
---|
| 837 | --argc; ++argv;
|
---|
| 838 | continue;
|
---|
| 839 | }
|
---|
| 840 | else
|
---|
| 841 | {
|
---|
| 842 | /* unrecognized short option */
|
---|
[210] | 843 | fprintf (stderr, "%s",_("Error: unrecognized short option\n"));
|
---|
[1] | 844 | (void) sh_getopt_usage(_("fail"));
|
---|
| 845 | }
|
---|
| 846 | }
|
---|
| 847 |
|
---|
| 848 | /* a long option: process it
|
---|
| 849 | */
|
---|
| 850 | if (len > 2)
|
---|
| 851 | {
|
---|
| 852 |
|
---|
| 853 | for (i = 0; op_table[i].longopt != NULL; ++i)
|
---|
| 854 | {
|
---|
[27] | 855 |
|
---|
[1] | 856 | if (sl_strncmp(_(op_table[i].longopt),
|
---|
| 857 | &argv[1][2],
|
---|
| 858 | sl_strlen(op_table[i].longopt)) == 0 )
|
---|
| 859 | {
|
---|
| 860 | foundit = 1;
|
---|
| 861 | if ( op_table[i].hasArg == HAS_ARG_YES )
|
---|
| 862 | {
|
---|
[27] | 863 | theequal = strchr(argv[1], '=');
|
---|
| 864 | if (theequal == NULL)
|
---|
[1] | 865 | {
|
---|
[20] | 866 | if (argc < 3)
|
---|
| 867 | {
|
---|
| 868 | /* argument required, but no avail
|
---|
| 869 | */
|
---|
[210] | 870 | fprintf (stderr, "%s",
|
---|
| 871 | _("Error: missing argument\n"));
|
---|
[20] | 872 | (void) sh_getopt_usage(_("fail"));
|
---|
| 873 | }
|
---|
| 874 | else
|
---|
| 875 | {
|
---|
| 876 | /* call function with argument */
|
---|
| 877 | --argc; ++argv;
|
---|
| 878 | if (NULL != op_table[i].func &&
|
---|
| 879 | 0 != (* op_table[i].func )(argv[1]))
|
---|
| 880 | fprintf (stderr,
|
---|
[42] | 881 | _("Error processing option -%s\n"),
|
---|
[20] | 882 | op_table[i].longopt);
|
---|
| 883 | break;
|
---|
| 884 | }
|
---|
[1] | 885 | }
|
---|
| 886 | else
|
---|
| 887 | {
|
---|
| 888 | if (sl_strlen (theequal) > 1)
|
---|
| 889 | {
|
---|
| 890 | ++theequal;
|
---|
| 891 | /* call function with argument */
|
---|
[20] | 892 | if (NULL != op_table[i].func &&
|
---|
| 893 | 0 != (* op_table[i].func )(theequal))
|
---|
[1] | 894 | fprintf (stderr,
|
---|
[42] | 895 | _("Error processing option -%s\n"),
|
---|
[1] | 896 | op_table[i].longopt);
|
---|
| 897 | break;
|
---|
| 898 | }
|
---|
| 899 | else
|
---|
| 900 | {
|
---|
[210] | 901 | fprintf (stderr, "%s",
|
---|
| 902 | _("Error: invalid argument\n"));
|
---|
[1] | 903 | /* argument required, but no avail */
|
---|
| 904 | (void) sh_getopt_usage(_("fail"));
|
---|
| 905 | }
|
---|
| 906 | }
|
---|
| 907 | }
|
---|
| 908 | else
|
---|
| 909 | {
|
---|
[20] | 910 | if (NULL != op_table[i].func &&
|
---|
| 911 | 0 != (* op_table[i].func )(NULL))
|
---|
[1] | 912 | fprintf (stderr,
|
---|
[42] | 913 | _("Error processing option -%s\n"),
|
---|
[1] | 914 | op_table[i].longopt);
|
---|
| 915 | break;
|
---|
| 916 | }
|
---|
| 917 | }
|
---|
| 918 | }
|
---|
| 919 |
|
---|
| 920 | /* 'break' should get here */
|
---|
| 921 | if (foundit == 1)
|
---|
| 922 | {
|
---|
| 923 | ++count;
|
---|
| 924 | --argc;
|
---|
| 925 | ++argv;
|
---|
| 926 | continue;
|
---|
| 927 | }
|
---|
| 928 | else
|
---|
| 929 | {
|
---|
| 930 | /* unrecognized long option */
|
---|
[210] | 931 | fprintf (stderr, "%s",_("Error: unrecognized long option\n"));
|
---|
[1] | 932 | (void) sh_getopt_usage(_("fail"));
|
---|
| 933 | }
|
---|
| 934 | }
|
---|
| 935 | }
|
---|
| 936 |
|
---|
| 937 | SL_RETURN( count, _("sh_getopt_get"));
|
---|
| 938 | }
|
---|