[Pkg-privacy-commits] [onioncat] 209/340: - options are parsed sequentially (-f and -I first) - config file is always read from SYSCONFDIR (usually /etc or /usr/local/etc) - changed Makefile.am to not install header files

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:04:40 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch debian
in repository onioncat.

commit 70cd90059404138b7039778bea6c890d77d89220
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date:   Sun Jan 24 18:55:24 2010 +0000

     - options are parsed sequentially (-f and -I first)
     - config file is always read from SYSCONFDIR (usually /etc or /usr/local/etc)
     - changed Makefile.am to not install header files
    
    
    
    git-svn-id: http://www.cypherpunk.at/svn/onioncat/trunk@538 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
 ChangeLog              |   3 ++
 configure              |  22 ++++-----
 src/Makefile.am        |   3 +-
 src/Makefile.in        |  51 ++++++--------------
 src/cygwin/Makefile.am |   2 +-
 src/cygwin/Makefile.in |  48 ++++---------------
 src/ocat.c             | 124 +++++++++++++++++++++++++++++--------------------
 src/ocat.h             |   4 ++
 src/ocat_netdesc.c     |   2 +
 src/ocat_netdesc.h     |   1 +
 src/ocatctrl.c         |  38 +++++++--------
 src/ocatsetup.c        |  10 +++-
 12 files changed, 148 insertions(+), 160 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8605e2a..ce1e469 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
 * version 0.2.2
+ - options are parsed sequentially (-f and -I first)
+ - config file is always read from SYSCONFDIR (usually /etc or /usr/local/etc)
+ - changed Makefile.am to not install header files
  - separate name for connect log and pid file for OC/GC.
  - mode detection (OC/GC) improved
  - GarliCat branch merged back into trunk
diff --git a/configure b/configure
index fabc2ac..f193aea 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.62 for onioncat 0.2.2.r536.
+# Generated by GNU Autoconf 2.62 for onioncat 0.2.2.r538.
 #
 # Report bugs to <rahra at cypherpunk.at>.
 #
@@ -596,8 +596,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
 # Identity of this package.
 PACKAGE_NAME='onioncat'
 PACKAGE_TARNAME='onioncat'
-PACKAGE_VERSION='0.2.2.r536'
-PACKAGE_STRING='onioncat 0.2.2.r536'
+PACKAGE_VERSION='0.2.2.r538'
+PACKAGE_STRING='onioncat 0.2.2.r538'
 PACKAGE_BUGREPORT='rahra at cypherpunk.at'
 
 ac_subst_vars='SHELL
@@ -1260,7 +1260,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures onioncat 0.2.2.r536 to adapt to many kinds of systems.
+\`configure' configures onioncat 0.2.2.r538 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1330,7 +1330,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of onioncat 0.2.2.r536:";;
+     short | recursive ) echo "Configuration of onioncat 0.2.2.r538:";;
    esac
   cat <<\_ACEOF
 
@@ -1422,7 +1422,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-onioncat configure 0.2.2.r536
+onioncat configure 0.2.2.r538
 generated by GNU Autoconf 2.62
 
 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1436,7 +1436,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by onioncat $as_me 0.2.2.r536, which was
+It was created by onioncat $as_me 0.2.2.r538, which was
 generated by GNU Autoconf 2.62.  Invocation command line was
 
   $ $0 $@
@@ -2085,7 +2085,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='onioncat'
- VERSION='0.2.2.r536'
+ VERSION='0.2.2.r538'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -2236,7 +2236,7 @@ ac_config_headers="$ac_config_headers config.h"
 
 
 cat >>confdefs.h <<\_ACEOF
-#define SVN_REVISION "536"
+#define SVN_REVISION "538"
 _ACEOF
 
 
@@ -5220,7 +5220,7 @@ exec 6>&1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by onioncat $as_me 0.2.2.r536, which was
+This file was extended by onioncat $as_me 0.2.2.r538, which was
 generated by GNU Autoconf 2.62.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -5273,7 +5273,7 @@ Report bugs to <bug-autoconf at gnu.org>."
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_version="\\
-onioncat config.status 0.2.2.r536
+onioncat config.status 0.2.2.r538
 configured by $0, generated by GNU Autoconf 2.62,
   with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 0c9737b..7d21e59 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,7 @@
 bin_PROGRAMS = ocat
 ocat_SOURCES = ocat.c ocatlog.c ocatroute.c ocatthread.c ocattun.c ocatv6conv.c ocatcompat.c ocatpeer.c ocatsetup.c ocatipv4route.c ocateth.c ocatsocks.c ocatlibe.c ocatctrl.c ocatipv6route.c ocaticmp.c ocat_wintuntap.c ocat_netdesc.c
-include_HEADERS = ocat.h ocat_netdesc.h strlcpy.c strlcat.c
+noinst_HEADERS = ocat.h ocat_netdesc.h strlcpy.c strlcat.c
+AM_CFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"
 
 install-exec-hook:
 	$(LN_S) -f $(DESTDIR)$(bindir)/ocat$(EXEEXT) \
diff --git a/src/Makefile.in b/src/Makefile.in
index 4e91f5b..034113b 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -39,7 +39,7 @@ build_triplet = @build@
 host_triplet = @host@
 bin_PROGRAMS = ocat$(EXEEXT)
 subdir = src
-DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
+DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
 	$(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/acx_pthread.m4 \
@@ -49,7 +49,7 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
 mkinstalldirs = $(SHELL) $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/config.h
 CONFIG_CLEAN_FILES =
-am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)"
+am__installdirs = "$(DESTDIR)$(bindir)"
 binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
 PROGRAMS = $(bin_PROGRAMS)
 am_ocat_OBJECTS = ocat.$(OBJEXT) ocatlog.$(OBJEXT) ocatroute.$(OBJEXT) \
@@ -70,14 +70,7 @@ CCLD = $(CC)
 LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
 SOURCES = $(ocat_SOURCES)
 DIST_SOURCES = $(ocat_SOURCES)
-am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
-am__vpath_adj = case $$p in \
-    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
-    *) f=$$p;; \
-  esac;
-am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
-includeHEADERS_INSTALL = $(INSTALL_HEADER)
-HEADERS = $(include_HEADERS)
+HEADERS = $(noinst_HEADERS)
 ETAGS = etags
 CTAGS = ctags
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -170,7 +163,8 @@ sharedstatedir = @sharedstatedir@
 sysconfdir = @sysconfdir@
 target_alias = @target_alias@
 ocat_SOURCES = ocat.c ocatlog.c ocatroute.c ocatthread.c ocattun.c ocatv6conv.c ocatcompat.c ocatpeer.c ocatsetup.c ocatipv4route.c ocateth.c ocatsocks.c ocatlibe.c ocatctrl.c ocatipv6route.c ocaticmp.c ocat_wintuntap.c ocat_netdesc.c
-include_HEADERS = ocat.h ocat_netdesc.h strlcpy.c strlcat.c
+noinst_HEADERS = ocat.h ocat_netdesc.h strlcpy.c strlcat.c
+AM_CFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"
 all: all-am
 
 .SUFFIXES:
@@ -270,23 +264,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
 uninstall-info-am:
-install-includeHEADERS: $(include_HEADERS)
-	@$(NORMAL_INSTALL)
-	test -z "$(includedir)" || $(mkdir_p) "$(DESTDIR)$(includedir)"
-	@list='$(include_HEADERS)'; for p in $$list; do \
-	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
-	  f=$(am__strip_dir) \
-	  echo " $(includeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(includedir)/$$f'"; \
-	  $(includeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(includedir)/$$f"; \
-	done
-
-uninstall-includeHEADERS:
-	@$(NORMAL_UNINSTALL)
-	@list='$(include_HEADERS)'; for p in $$list; do \
-	  f=$(am__strip_dir) \
-	  echo " rm -f '$(DESTDIR)$(includedir)/$$f'"; \
-	  rm -f "$(DESTDIR)$(includedir)/$$f"; \
-	done
 
 ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
 	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
@@ -367,7 +344,7 @@ check-am: all-am
 check: check-am
 all-am: Makefile $(PROGRAMS) $(HEADERS)
 installdirs:
-	for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)"; do \
+	for dir in "$(DESTDIR)$(bindir)"; do \
 	  test -z "$$dir" || $(mkdir_p) "$$dir"; \
 	done
 install: install-am
@@ -414,7 +391,7 @@ info: info-am
 
 info-am:
 
-install-data-am: install-includeHEADERS
+install-data-am:
 
 install-exec-am: install-binPROGRAMS
 	@$(NORMAL_INSTALL)
@@ -443,20 +420,18 @@ ps: ps-am
 
 ps-am:
 
-uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \
-	uninstall-info-am
+uninstall-am: uninstall-binPROGRAMS uninstall-info-am
 
 .PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
 	clean-generic ctags distclean distclean-compile \
 	distclean-generic distclean-tags distdir dvi dvi-am html \
 	html-am info info-am install install-am install-binPROGRAMS \
 	install-data install-data-am install-exec install-exec-am \
-	install-exec-hook install-includeHEADERS install-info \
-	install-info-am install-man install-strip installcheck \
-	installcheck-am installdirs maintainer-clean \
-	maintainer-clean-generic mostlyclean mostlyclean-compile \
-	mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \
-	uninstall-am uninstall-binPROGRAMS uninstall-includeHEADERS \
+	install-exec-hook install-info install-info-am install-man \
+	install-strip installcheck installcheck-am installdirs \
+	maintainer-clean maintainer-clean-generic mostlyclean \
+	mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \
+	tags uninstall uninstall-am uninstall-binPROGRAMS \
 	uninstall-info-am
 
 
diff --git a/src/cygwin/Makefile.am b/src/cygwin/Makefile.am
index cf195af..cf50f84 100644
--- a/src/cygwin/Makefile.am
+++ b/src/cygwin/Makefile.am
@@ -1,2 +1,2 @@
-include_HEADERS = ocat_cygwin.h openbsd_netinet_icmp6.h openbsd_netinet_if_ether.h openbsd_netinet_ip6.h
+noinst_HEADERS = ocat_cygwin.h openbsd_netinet_icmp6.h openbsd_netinet_if_ether.h openbsd_netinet_ip6.h
 
diff --git a/src/cygwin/Makefile.in b/src/cygwin/Makefile.in
index a741444..7bc9f5c 100644
--- a/src/cygwin/Makefile.in
+++ b/src/cygwin/Makefile.in
@@ -37,7 +37,7 @@ POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
 subdir = src/cygwin
-DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
+DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
 	$(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/acx_pthread.m4 \
@@ -49,15 +49,7 @@ CONFIG_HEADER = $(top_builddir)/config.h
 CONFIG_CLEAN_FILES =
 SOURCES =
 DIST_SOURCES =
-am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
-am__vpath_adj = case $$p in \
-    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
-    *) f=$$p;; \
-  esac;
-am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
-am__installdirs = "$(DESTDIR)$(includedir)"
-includeHEADERS_INSTALL = $(INSTALL_HEADER)
-HEADERS = $(include_HEADERS)
+HEADERS = $(noinst_HEADERS)
 ETAGS = etags
 CTAGS = ctags
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -149,7 +141,7 @@ sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 sysconfdir = @sysconfdir@
 target_alias = @target_alias@
-include_HEADERS = ocat_cygwin.h openbsd_netinet_icmp6.h openbsd_netinet_if_ether.h openbsd_netinet_ip6.h
+noinst_HEADERS = ocat_cygwin.h openbsd_netinet_icmp6.h openbsd_netinet_if_ether.h openbsd_netinet_ip6.h
 all: all-am
 
 .SUFFIXES:
@@ -183,23 +175,6 @@ $(top_srcdir)/configure:  $(am__configure_deps)
 $(ACLOCAL_M4):  $(am__aclocal_m4_deps)
 	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 uninstall-info-am:
-install-includeHEADERS: $(include_HEADERS)
-	@$(NORMAL_INSTALL)
-	test -z "$(includedir)" || $(mkdir_p) "$(DESTDIR)$(includedir)"
-	@list='$(include_HEADERS)'; for p in $$list; do \
-	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
-	  f=$(am__strip_dir) \
-	  echo " $(includeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(includedir)/$$f'"; \
-	  $(includeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(includedir)/$$f"; \
-	done
-
-uninstall-includeHEADERS:
-	@$(NORMAL_UNINSTALL)
-	@list='$(include_HEADERS)'; for p in $$list; do \
-	  f=$(am__strip_dir) \
-	  echo " rm -f '$(DESTDIR)$(includedir)/$$f'"; \
-	  rm -f "$(DESTDIR)$(includedir)/$$f"; \
-	done
 
 ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
 	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
@@ -280,9 +255,6 @@ check-am: all-am
 check: check-am
 all-am: Makefile $(HEADERS)
 installdirs:
-	for dir in "$(DESTDIR)$(includedir)"; do \
-	  test -z "$$dir" || $(mkdir_p) "$$dir"; \
-	done
 install: install-am
 install-exec: install-exec-am
 install-data: install-data-am
@@ -325,7 +297,7 @@ info: info-am
 
 info-am:
 
-install-data-am: install-includeHEADERS
+install-data-am:
 
 install-exec-am:
 
@@ -351,18 +323,16 @@ ps: ps-am
 
 ps-am:
 
-uninstall-am: uninstall-includeHEADERS uninstall-info-am
+uninstall-am: uninstall-info-am
 
 .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
 	ctags distclean distclean-generic distclean-tags distdir dvi \
 	dvi-am html html-am info info-am install install-am \
 	install-data install-data-am install-exec install-exec-am \
-	install-includeHEADERS install-info install-info-am \
-	install-man install-strip installcheck installcheck-am \
-	installdirs maintainer-clean maintainer-clean-generic \
-	mostlyclean mostlyclean-generic pdf pdf-am ps ps-am tags \
-	uninstall uninstall-am uninstall-includeHEADERS \
-	uninstall-info-am
+	install-info install-info-am install-man install-strip \
+	installcheck installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-generic pdf \
+	pdf-am ps ps-am tags uninstall uninstall-am uninstall-info-am
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
diff --git a/src/ocat.c b/src/ocat.c
index 8b32ef1..df4095b 100644
--- a/src/ocat.c
+++ b/src/ocat.c
@@ -31,7 +31,7 @@ void usage(const char *s)
          "   -h                    display usage message\n"
          "   -C                    disable local controller interface\n"
          "   -d <n>                set debug level to n, default = %d\n"
-         "   -f <config_file>      read config from config_file\n"
+         "   -f <config_file>      read config from config_file (default = %s)\n"
          "   -i                    convert onion hostname to IPv6 and exit\n"
          "   -I                    GarliCat mode, use I2P instead of Tor\n"
          "   -l [<ip>:]<port>      set ocat listen address and port, default = 127.0.0.1:%d\n"
@@ -52,7 +52,7 @@ void usage(const char *s)
          // option defaults start here
          OCAT_DIR, NDESC(clog_file), CNF(create_clog), 
          CNF(daemon), CNF(daemon) ^ 1,
-         CNF(debug_level), NDESC(listen_port),
+         CNF(debug_level), CNF(config_file), NDESC(listen_port),
          CNF(pid_file),
          CNF(ocat_dest_port), ntohs(CNF(socks_dst)->sin_port), 
 #ifndef WITHOUT_TUN
@@ -270,28 +270,46 @@ void cleanup_system(void)
 }
 
 
-int main(int argc, char *argv[])
+void parse_opt_early(int argc, char *argv[])
 {
-   char *s, ip6addr[INET6_ADDRSTRLEN], hw[20], def[100], pwdbuf[SIZE_1K];
-   int c, runasroot = 0;
-   struct passwd *pwd, pwdm;
-   int urlconv = 0, mode_detect = 0;
+   int c;
 
-   init_setup();
-   // detect network type by command file name
-   // FIXME: this should be not hardcoded in that way
-   // FIXME: basename() should better be used instead of strstr()
-   if (strstr(argv[0], "gcat"))
-   {
-      CNF(net_type) = NTYPE_I2P;
-      snprintf(def, 100, "127.0.0.1:%d", NDESC(listen_port));
-      post_init_setup();
-      mode_detect = 1;
-   }
+   opterr = 0;
+   while ((c = getopt(argc, argv, "f:hI")) != -1)
+      switch (c)
+      {
+         case 'f':
+            free(CNF(config_file));
+            CNF(config_file) = optarg;
+            CNF(config_read) = 0;
+            break;
 
-   while ((c = getopt(argc, argv, "abBCd:f:hrRiIopl:t:T:s:u:4L:P:")) != -1)
+         case 'I':
+            CNF(net_type) = NTYPE_I2P;
+            break;
+         case 'h':
+            usage(argv[0]);
+            exit(1);
+         case '?':
+            break;
+      }
+}
+
+ 
+int parse_opt(int argc, char *argv[])
+{
+   int c, urlconv = 0;
+
+   opterr = 1;
+   optind = 1;
+   while ((c = getopt(argc, argv, "f:IabBCd:rRiopl:t:T:s:u:4L:P:")) != -1)
       switch (c)
       {
+         // those options are parsed in parse_opt_early()
+         case 'f':
+         case 'I':
+            break;
+
          case 'a':
             CNF(create_clog) = 1;
             break;
@@ -312,19 +330,10 @@ int main(int argc, char *argv[])
             CNF(debug_level) = atoi(optarg);
             break;
 
-         case 'f':
-            CNF(config_file) = optarg;
-            CNF(config_read) = 0;
-            break;
-
          case 'i':
             urlconv = 1;
             break;
 
-         case 'I':
-            CNF(net_type) = NTYPE_I2P;
-            break;
-
          case 'l':
             add_listener(optarg);
             break;
@@ -353,7 +362,7 @@ int main(int argc, char *argv[])
             break;
 
          case 'r':
-            runasroot = 1;
+            CNF(runasroot) = 1;
             CNF(usrname) = "root";
             break;
 
@@ -384,18 +393,49 @@ int main(int argc, char *argv[])
             CNF(ipv4_enable) = 1;
             break;
 
-         case 'h':
          default:
             usage(argv[0]);
             exit(1);
       }
 
+   return urlconv;
+}
+
+
+int main(int argc, char *argv[])
+{
+   char *s, ip6addr[INET6_ADDRSTRLEN], hw[20], def[100], pwdbuf[SIZE_1K];
+   int c;
+   struct passwd *pwd, pwdm;
+   int urlconv = 0, mode_detect = 0;
+
+   init_setup();
+   // detect network type by command file name
+   // FIXME: this should be not hardcoded in that way
+   // FIXME: basename() should better be used instead of strstr()
+   if (strstr(argv[0], "gcat"))
+   {
+      CNF(net_type) = NTYPE_I2P;
+      snprintf(def, 100, "127.0.0.1:%d", NDESC(listen_port));
+      post_init_setup();
+      mode_detect = 1;
+   }
+
+   parse_opt_early(argc, argv);
+
    if (!mode_detect)
    {
       snprintf(def, 100, "127.0.0.1:%d", NDESC(listen_port));
       post_init_setup();
    }
 
+   if ((c = open(CNF(config_file), O_RDONLY)) == -1)
+      CNF(config_failed) = errno;
+   else
+      ctrl_handler((void*) (long) c);
+
+   urlconv = parse_opt(argc, argv);
+
    // usage output must be after mode detection (Tor/I2P)
    if (argc < 2)
       usage(argv[0]), exit(1);
@@ -417,6 +457,9 @@ int main(int argc, char *argv[])
    (void) init_ocat_thread("main");
    detach_thread();
 
+   if (CNF(config_failed))
+      log_msg(LOG_NOTICE, "could not open config file %s: %s", CNF(config_file), strerror(CNF(config_failed)));
+
    if (urlconv == 2)
    {
       if ((c = inet_pton(AF_INET6, argv[optind], &CNF(ocat_addr))) < 0)
@@ -461,16 +504,6 @@ int main(int argc, char *argv[])
 
    log_msg(LOG_INFO, "%s", CNF(version));
 
-#if 0
-   if (CNF(config_file))
-   {
-      log_msg(LOG_INFO, "reading config file %s", CNF(config_file));
-      if ((c = open(CNF(config_file), O_RDONLY)) == -1)
-         log_msg(LOG_ERR, "error opening file: %s", strerror(errno)), exit(1);
-      ctrl_handler((void*) c);
-   }
-#endif
-
    memcpy(&CNF(ocat_hwaddr[3]), &CNF(ocat_addr.s6_addr[13]), 3);
    if (CNF(use_tap))
       log_msg(LOG_INFO, "MAC address %s", ether_ntoa_r((struct ether_addr*) CNF(ocat_hwaddr), hw));
@@ -527,7 +560,7 @@ int main(int argc, char *argv[])
    if (CNF(create_pid_file))
       mk_pid_file(pwd->pw_uid);
 
-   if (!runasroot && !getuid())
+   if (!CNF(runasroot) && !getuid())
    {
       log_msg(LOG_INFO, "running as root, changing uid/gid to %s (uid %d/gid %d)", CNF(usrname), pwd->pw_uid, pwd->pw_gid);
       if (setgid(pwd->pw_gid))
@@ -561,15 +594,6 @@ int main(int argc, char *argv[])
          socks_queue(CNF(root_peer[c]), 1);
 #endif
 
-   // reading config file
-   if (CNF(config_file))
-   {
-      log_msg(LOG_INFO, "reading config file %s", CNF(config_file));
-      if ((c = open(CNF(config_file), O_RDONLY)) == -1)
-         log_msg(LOG_ERR, "error opening file: %s", strerror(errno)), exit(1);
-      ctrl_handler((void*) (long) c);
-   }
-
    // install signal handler
    install_sig();
 
diff --git a/src/ocat.h b/src/ocat.h
index 051085b..4038458 100644
--- a/src/ocat.h
+++ b/src/ocat.h
@@ -219,6 +219,9 @@
 #define NTYPE_TOR 0
 #define NTYPE_I2P 1
 
+#ifndef SYSCONFDIR
+#define SYSCONFDIR "/etc"
+#endif
 
 struct OcatSetup
 {
@@ -256,6 +259,7 @@ struct OcatSetup
    int ocat_addr4_mask;
    char *config_file;
    int config_read;
+   int config_failed;
    int use_tap;
    //! local OnionCat MAC address
    uint8_t ocat_hwaddr[ETHER_ADDR_LEN];
diff --git a/src/ocat_netdesc.c b/src/ocat_netdesc.c
index 8f74811..b3b6453 100644
--- a/src/ocat_netdesc.c
+++ b/src/ocat_netdesc.c
@@ -32,6 +32,7 @@ const struct NetDesc netdesc_[2] =
       TOR_SOCKS_PORT,
       TOR_OCAT_CONNECT_LOG,
       TOR_PID_FILE,
+      "ocat.conf",
    },
    {
       I2P_PREFIX, I2P_PREFIX_LEN,
@@ -44,6 +45,7 @@ const struct NetDesc netdesc_[2] =
       I2P_SOCKS_PORT,
       I2P_OCAT_CONNECT_LOG,
       I2P_PID_FILE,
+      "gcat.conf",
    },
 };
 
diff --git a/src/ocat_netdesc.h b/src/ocat_netdesc.h
index 69f9de5..27050ee 100644
--- a/src/ocat_netdesc.h
+++ b/src/ocat_netdesc.h
@@ -38,6 +38,7 @@ struct NetDesc
    short socks_port;
    char *clog_file;
    char *pid_file;
+   char *config_file;
 };
 
 extern const struct NetDesc netdesc_[2];
diff --git a/src/ocatctrl.c b/src/ocatctrl.c
index 9985095..a762d4f 100644
--- a/src/ocatctrl.c
+++ b/src/ocatctrl.c
@@ -37,7 +37,7 @@ void *ctrl_handler(void *p)
 {
    int fd, c;
    FILE *ff, *fo;
-   char buf[FRAME_SIZE], addrstr[INET6_ADDRSTRLEN], onionstr[NDESC(name_size)], timestr[32], *s, *tokbuf;
+   char buf[FRAME_SIZE], addrstr[INET6_ADDRSTRLEN], onionstr[NDESC(name_size)], timestr[32], *s, *tokbuf, *bufp;
    int rlen, cfd;
    struct tm *tm;
    OcatPeer_t *peer;
@@ -71,7 +71,7 @@ void *ctrl_handler(void *p)
          return NULL;
       }
       log_debug("fd %d fdopen'ed \"r\"", fd);
-      fo = CNF(logf);
+      fo = CNF(logf) ? CNF(logf) : stderr;
       //CNF(config_read) = 1;
    }
 
@@ -132,14 +132,14 @@ void *ctrl_handler(void *p)
       if (!(rlen = oe_remtr(buf)))
          continue;
 
-      if (!strtok_r(buf, " \t\r\n", &tokbuf))
+      if (!(bufp = strtok_r(buf, " \t\r\n", &tokbuf)))
          continue;
 
       // "exit"/"quit" => terminate thread
-      if (!strncmp(buf, "exit", 4) || !strncmp(buf, "quit", 4))
+      if (!strncmp(bufp, "exit", 4) || !strncmp(bufp, "quit", 4))
          break;
       // "status"
-      else if (!strcmp(buf, "status"))
+      else if (!strcmp(bufp, "status"))
       {
          lock_peers();
          for (peer = get_first_peer(); peer; peer = peer->next)
@@ -158,9 +158,9 @@ void *ctrl_handler(void *p)
             }
          unlock_peers();
       }
-      else if (!strcmp(buf, "close"))
+      else if (!strcmp(bufp, "close"))
       {
-         cfd = atoi(&buf[6]);
+         cfd = atoi(bufp +6);
          lock_peers();
          for (peer = get_first_peer(); peer; peer = peer->next)
             if (peer->tcpfd == cfd)
@@ -177,21 +177,21 @@ void *ctrl_handler(void *p)
          }
          unlock_peers();
       }
-      else if (!strcmp(buf, "threads"))
+      else if (!strcmp(bufp, "threads"))
       {
          print_threads(ff);
       }
-      else if (!strcmp(buf, "terminate"))
+      else if (!strcmp(bufp, "terminate"))
       {
          log_msg(LOG_INFO, "terminate request from control port");
          kill(getpid(), SIGINT);
       }
-      else if (!strcmp(buf, "route"))
+      else if (!strcmp(bufp, "route"))
       {
          if (rlen > 6)
          {
-            if ((c = parse_route(&buf[6])) == E_RT_SYNTAX)
-               if ((c = ipv6_parse_route(&buf[6])) > 0)
+            if ((c = parse_route(bufp + 6)) == E_RT_SYNTAX)
+               if ((c = ipv6_parse_route(bufp + 6)) > 0)
                   c = 0;
             switch (c)
             {
@@ -223,12 +223,12 @@ void *ctrl_handler(void *p)
             ipv6_print_routes(fo);
          }
       }
-      else if (!strcmp(buf, "connect"))
+      else if (!strcmp(bufp, "connect"))
       {
          if ((s = strtok_r(NULL, " \t\r\n", &tokbuf)))
          {
             if ((strlen(s) != 16) || (oniontipv6(s, &in6) == -1))
-               fprintf(ff, "ERR \"%s\" not valid .onion-URL\n", &buf[8]);
+               fprintf(ff, "ERR \"%s\" not valid .onion-URL\n", bufp + 8);
             else
             {
                if (!(s = strtok_r(NULL, " \t\r\n", &tokbuf)))
@@ -242,11 +242,11 @@ void *ctrl_handler(void *p)
          else
             fprintf(ff, "ERR missing args\n");
       }
-      else if (!strcmp(buf, "macs"))
+      else if (!strcmp(bufp, "macs"))
       {
          print_mac_tbl(ff);
       }
-      else if (!strcmp(buf, "queue"))
+      else if (!strcmp(bufp, "queue"))
       {
          print_socks_queue((FILE*) (long) pfd[1]);
          for (;;)
@@ -257,15 +257,15 @@ void *ctrl_handler(void *p)
             fprintf(ff, "%c", buf[0]);
          }
       }
-      else if (!strcmp(buf, "setup"))
+      else if (!strcmp(bufp, "setup"))
       {
          print_setup_struct(ff);
       }
-      else if (!strcmp(buf, "version"))
+      else if (!strcmp(bufp, "version"))
       {
          fprintf(ff, "%s\n", CNF(version));
       }
-      else if (!strcmp(buf, "help") || !strcmp(buf, "?"))
+      else if (!strcmp(bufp, "help") || !strcmp(bufp, "?"))
       {
          fprintf(fo,
                "commands:\n"
diff --git a/src/ocatsetup.c b/src/ocatsetup.c
index 90286c0..a632e8a 100644
--- a/src/ocatsetup.c
+++ b/src/ocatsetup.c
@@ -56,7 +56,8 @@ struct OcatSetup setup_ =
    0, 
    //ADDR4_PREFIX, ADDR4_MASK
    {0}, 0,
-   NULL, 1,
+   // config_file, config_read, config_failed
+   NULL, 0, 0,
 #ifdef __CYGWIN__
    1,
 #else
@@ -147,11 +148,18 @@ void init_setup(void)
 
 void post_init_setup(void)
 {
+   size_t l;
    setup_.ocat_addr4 = NDESC(prefix4);
    setup_.ocat_addr4_mask = NDESC(addr4_mask);
    setup_.ocat_dest_port = NDESC(vdest_port);
    setup_.ocat_ctrl_port = NDESC(ctrl_port);
 
+   l = strlen(SYSCONFDIR) + strlen(NDESC(config_file)) + 2;
+   if ((setup_.config_file = malloc(l)) != NULL)
+      snprintf(setup_.config_file, l, "%s/%s", SYSCONFDIR, NDESC(config_file));
+   else
+      log_msg(LOG_WARNING, "could not get memory for config file string: \"%s\"", strerror(errno));
+
    if (!setup_.socks_dst->sin_port)
       setup_.socks_dst->sin_port = htons(NDESC(socks_port));
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onioncat.git



More information about the Pkg-privacy-commits mailing list