Browse Source

Merge branch 'master' into ppa

ppa
Timo Röhling 11 years ago
parent
commit
58fd844341
7 changed files with 131 additions and 17 deletions
  1. 5
    0
      .travis.yml
  2. 10
    4
      CMakeLists.txt
  3. 16
    7
      postinstall.cmake.in
  4. 5
    3
      postsrsd.c
  5. 2
    2
      postsrsd.lsb_init.in
  6. 92
    0
      postsrsd.rh_init.in
  7. 1
    1
      postsrsd.upstart.in

+ 5
- 0
.travis.yml View File

1
+language: c
2
+compiler:
3
+  - gcc
4
+script: make
5
+

+ 10
- 4
CMakeLists.txt View File

5
 option(USE_APPARMOR "Enable AppArmor profile" OFF)
5
 option(USE_APPARMOR "Enable AppArmor profile" OFF)
6
 
6
 
7
 set(CHROOT_DIR "${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME}" CACHE PATH "Chroot jail for daemon")
7
 set(CHROOT_DIR "${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME}" CACHE PATH "Chroot jail for daemon")
8
+set(CONFIG_DIR "/etc/default" CACHE PATH "Location of configuration file")
8
 
9
 
9
 find_program(HELP2MAN help2man DOC "path to help2man executable")
10
 find_program(HELP2MAN help2man DOC "path to help2man executable")
10
 find_program(DD dd DOC "path to dd executable")
11
 find_program(DD dd DOC "path to dd executable")
11
 find_program(BASE64 base64 DOC "path to base64 executable")
12
 find_program(BASE64 base64 DOC "path to base64 executable")
12
 find_program(INSSERV insserv DOC "path to insserv executable")
13
 find_program(INSSERV insserv DOC "path to insserv executable")
14
+find_program(CHKCONFIG chkconfig DOC "path to chkconfig executable")
13
 
15
 
14
 if(NOT DEFINED INIT_FLAVOR)
16
 if(NOT DEFINED INIT_FLAVOR)
15
     if(IS_DIRECTORY "/etc/init" AND EXISTS "/lib/init/upstart-job")
17
     if(IS_DIRECTORY "/etc/init" AND EXISTS "/lib/init/upstart-job")
16
         message(STATUS "Detected init flavor: upstart")
18
         message(STATUS "Detected init flavor: upstart")
17
         set(INIT_FLAVOR "upstart" CACHE STRING "Init daemon of this system")
19
         set(INIT_FLAVOR "upstart" CACHE STRING "Init daemon of this system")
18
-    elseif(IS_DIRECTORY "/etc/init.d")
19
-        message(STATUS "Detected init flavor: sysv")
20
-        set(INIT_FLAVOR "sysv" CACHE STRING "Init daemon of this system")
20
+    elseif(IS_DIRECTORY "/etc/init.d" AND EXISTS "/lib/lsb/init-functions")
21
+        message(STATUS "Detected init flavor: sysv-lsb")
22
+        set(INIT_FLAVOR "sysv-lsb" CACHE STRING "Init daemon of this system")
23
+    elseif(IS_DIRECTORY "/etc/init.d" AND EXISTS "/etc/init.d/functions")
24
+        message(STATUS "Detected init flavor: sysv-redhat")
25
+        set(INIT_FLAVOR "sysv-redhat" CACHE STRING "Init daemon of this system")
21
     else()
26
     else()
22
         message(STATUS "Detected init flavor: none")
27
         message(STATUS "Detected init flavor: none")
23
         message(STATUS "System startup files will not be installed")
28
         message(STATUS "System startup files will not be installed")
33
 string(REGEX REPLACE "^/+" "" APPARMOR_PROFILE "${APPARMOR_PROFILE}")
38
 string(REGEX REPLACE "^/+" "" APPARMOR_PROFILE "${APPARMOR_PROFILE}")
34
 string(REPLACE "/" "." APPARMOR_PROFILE "${APPARMOR_PROFILE}")
39
 string(REPLACE "/" "." APPARMOR_PROFILE "${APPARMOR_PROFILE}")
35
 
40
 
36
-configure_file(${PROJECT_NAME}.init.in ${PROJECT_NAME}.init @ONLY)
41
+configure_file(${PROJECT_NAME}.lsb_init.in ${PROJECT_NAME}.lsb_init @ONLY)
42
+configure_file(${PROJECT_NAME}.rh_init.in ${PROJECT_NAME}.rh_init @ONLY)
37
 configure_file(${PROJECT_NAME}.upstart.in ${PROJECT_NAME}.upstart @ONLY)
43
 configure_file(${PROJECT_NAME}.upstart.in ${PROJECT_NAME}.upstart @ONLY)
38
 configure_file(${PROJECT_NAME}.apparmor.in ${PROJECT_NAME}.apparmor @ONLY)
44
 configure_file(${PROJECT_NAME}.apparmor.in ${PROJECT_NAME}.apparmor @ONLY)
39
 configure_file(postinstall.cmake.in postinstall.cmake @ONLY)
45
 configure_file(postinstall.cmake.in postinstall.cmake @ONLY)

+ 16
- 7
postinstall.cmake.in View File

1
 set(GENERATE_SRS_SECRET "@GENERATE_SRS_SECRET@")
1
 set(GENERATE_SRS_SECRET "@GENERATE_SRS_SECRET@")
2
 set(CHROOT_DIR "@CHROOT_DIR@")
2
 set(CHROOT_DIR "@CHROOT_DIR@")
3
+set(CONFIG_DIR "@CONFIG_DIR@")
3
 set(INIT_FLAVOR "@INIT_FLAVOR@")
4
 set(INIT_FLAVOR "@INIT_FLAVOR@")
4
 set(SECRET_FILE "@PROJECT_NAME@.secret")
5
 set(SECRET_FILE "@PROJECT_NAME@.secret")
5
 set(DD "@DD@")
6
 set(DD "@DD@")
6
 set(BASE64 "@BASE64@")
7
 set(BASE64 "@BASE64@")
7
 set(INSSERV "@INSSERV@")
8
 set(INSSERV "@INSSERV@")
9
+set(CHKCONFIG "@CHKCONFIG@")
8
 
10
 
9
 if(CHROOT_DIR AND NOT EXISTS "$ENV{DESTDIR}${CHROOT_DIR}")
11
 if(CHROOT_DIR AND NOT EXISTS "$ENV{DESTDIR}${CHROOT_DIR}")
10
 	message(STATUS "Chroot jail: $ENV{DESTDIR}${CHROOT_DIR}")
12
 	message(STATUS "Chroot jail: $ENV{DESTDIR}${CHROOT_DIR}")
11
 	file(MAKE_DIRECTORY "$ENV{DESTDIR}${CHROOT_DIR}")
13
 	file(MAKE_DIRECTORY "$ENV{DESTDIR}${CHROOT_DIR}")
12
 endif()
14
 endif()
13
 
15
 
14
-if(INIT_FLAVOR AND NOT EXISTS "$ENV{DESTDIR}/etc/default/@PROJECT_NAME@")
15
-	file(INSTALL "@CMAKE_CURRENT_SOURCE_DIR@/@PROJECT_NAME@.default" DESTINATION "/etc/default" RENAME "@PROJECT_NAME@")
16
+if(INIT_FLAVOR AND NOT EXISTS "$ENV{DESTDIR}${CONFIG_DIR}/@PROJECT_NAME@")
17
+	file(INSTALL FILES "@CMAKE_CURRENT_SOURCE_DIR@/@PROJECT_NAME@.default" DESTINATION "${CONFIG_DIR}" RENAME "@PROJECT_NAME@")
16
 endif()
18
 endif()
17
 
19
 
18
-if(INIT_FLAVOR STREQUAL "sysv")
19
-	file(INSTALL "@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.init" TYPE PROGRAM DESTINATION "/etc/init.d" RENAME "@PROJECT_NAME@")
20
+if(INIT_FLAVOR STREQUAL "sysv-lsb")
21
+	file(INSTALL FILES "@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.lsb_init" TYPE PROGRAM DESTINATION "/etc/init.d" RENAME "@PROJECT_NAME@")
20
 	if(INSSERV)
22
 	if(INSSERV)
21
 		execute_process(
23
 		execute_process(
22
 			COMMAND ${INSSERV} -p "$ENV{DESTDIR}/etc/init.d" @PROJECT_NAME@
24
 			COMMAND ${INSSERV} -p "$ENV{DESTDIR}/etc/init.d" @PROJECT_NAME@
23
 		)
25
 		)
24
 	endif()
26
 	endif()
27
+elseif(INIT_FLAVOR STREQUAL "sysv-redhat")
28
+	file(INSTALL FILES "@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.rh_init" TYPE PROGRAM DESTINATION "/etc/init.d" RENAME "@PROJECT_NAME@")
29
+	if(CHKCONFIG AND NOT "$ENV{DESTDIR}")
30
+		execute_process(
31
+			COMMAND ${CHKCONFIG} --add @PROJECT_NAME@
32
+		)
33
+	endif()
25
 elseif(INIT_FLAVOR STREQUAL "upstart")
34
 elseif(INIT_FLAVOR STREQUAL "upstart")
26
-	file(INSTALL "@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.upstart" DESTINATION "/etc/init" RENAME "@PROJECT_NAME@.conf")
35
+	file(INSTALL FILES "@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.upstart" DESTINATION "/etc/init" RENAME "@PROJECT_NAME@.conf")
27
 endif()
36
 endif()
28
 
37
 
29
 if(GENERATE_SRS_SECRET AND DD AND BASE64 AND EXISTS "/dev/urandom" AND NOT EXISTS "$ENV{DESTDIR}/etc/${SECRET_FILE}")
38
 if(GENERATE_SRS_SECRET AND DD AND BASE64 AND EXISTS "/dev/urandom" AND NOT EXISTS "$ENV{DESTDIR}/etc/${SECRET_FILE}")
30
 	message(STATUS "Generating secret key")
39
 	message(STATUS "Generating secret key")
31
 	execute_process(
40
 	execute_process(
32
 		COMMAND ${DD} if=/dev/urandom bs=18 count=1
41
 		COMMAND ${DD} if=/dev/urandom bs=18 count=1
33
-		COMMAND ${BASE64} -w0
42
+		COMMAND ${BASE64}
34
 		OUTPUT_FILE "@CMAKE_CURRENT_BINARY_DIR@/${SECRET_FILE}"
43
 		OUTPUT_FILE "@CMAKE_CURRENT_BINARY_DIR@/${SECRET_FILE}"
35
 		ERROR_QUIET
44
 		ERROR_QUIET
36
 		OUTPUT_STRIP_TRAILING_WHITESPACE
45
 		OUTPUT_STRIP_TRAILING_WHITESPACE
37
 	)
46
 	)
38
-file(INSTALL "@CMAKE_CURRENT_BINARY_DIR@/${SECRET_FILE}" DESTINATION "/etc" FILE_PERMISSIONS OWNER_READ OWNER_WRITE)
47
+file(INSTALL FILES "@CMAKE_CURRENT_BINARY_DIR@/${SECRET_FILE}" DESTINATION "/etc" RENAME "${SECRET_FILE}" FILE_PERMISSIONS OWNER_READ OWNER_WRITE)
39
 file(REMOVE "@CMAKE_CURRENT_BINARY_DIR@/${SECRET_FILE}")
48
 file(REMOVE "@CMAKE_CURRENT_BINARY_DIR@/${SECRET_FILE}")
40
 endif()
49
 endif()

+ 5
- 3
postsrsd.c View File

32
 #include <syslog.h>
32
 #include <syslog.h>
33
 
33
 
34
 #ifndef VERSION
34
 #ifndef VERSION
35
-#define VERSION "1.0"
35
+#define VERSION "1.1"
36
 #endif
36
 #endif
37
 
37
 
38
 static char *self = NULL;
38
 static char *self = NULL;
307
         return EXIT_SUCCESS;
307
         return EXIT_SUCCESS;
308
     }
308
     }
309
   }
309
   }
310
+  if (optind < argc) {
311
+    fprintf (stderr, "%s: extra argument on command line: %s\n", self, argv[optind]);
312
+    return EXIT_FAILURE;
313
+  }
310
   if (domain == NULL) {
314
   if (domain == NULL) {
311
     fprintf (stderr, "%s: You must set a home domain (-d)\n", self);
315
     fprintf (stderr, "%s: You must set a home domain (-d)\n", self);
312
-    show_help();
313
     return EXIT_FAILURE;
316
     return EXIT_FAILURE;
314
   }
317
   }
315
 
318
 
333
     }
336
     }
334
   } else {
337
   } else {
335
     fprintf (stderr, "%s: You must set a secret (-s)\n", self);
338
     fprintf (stderr, "%s: You must set a secret (-s)\n", self);
336
-    show_help();
337
     return EXIT_FAILURE;
339
     return EXIT_FAILURE;
338
   }
340
   }
339
   /* Bind ports. May require privileges if the config specifies ports below 1024 */
341
   /* Bind ports. May require privileges if the config specifies ports below 1024 */

postsrsd.init.in → postsrsd.lsb_init.in View File

36
 CHROOT=@CHROOT_DIR@
36
 CHROOT=@CHROOT_DIR@
37
 
37
 
38
 # Read config file if it is present.
38
 # Read config file if it is present.
39
-if [ -r /etc/default/$NAME ]
39
+if [ -r @CONFIG_DIR@/$NAME ]
40
 then
40
 then
41
-    . /etc/default/$NAME
41
+    . @CONFIG_DIR@/$NAME
42
 fi
42
 fi
43
 
43
 
44
 test -r "$SRS_SECRET" -a -n "$SRS_DOMAIN" || exit 0
44
 test -r "$SRS_SECRET" -a -n "$SRS_DOMAIN" || exit 0

+ 92
- 0
postsrsd.rh_init.in View File

1
+#! /bin/sh
2
+#
3
+# @PROJECT_NAME@
4
+#               start/stop the @PROJECT_NAME@ daemon for Postfix
5
+#
6
+# chkconfig: 2345 75 35
7
+# description: Sender Rewriting Scheme (SRS) for Postfix.
8
+# processname: @POSTSRSD@
9
+# pidfile: /var/run/@PROJECT_NAME@.pid
10
+# config: @CONFIG_DIR@/@PROJECT_NAME@
11
+
12
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
13
+DAEMON=@CMAKE_INSTALL_PREFIX@/sbin/@POSTSRSD@
14
+NAME=@PROJECT_NAME@
15
+prog=@POSTSRSD@
16
+DESC="Postfix Sender Rewriting Scheme daemon"
17
+
18
+PIDFILE=/var/run/$NAME.pid
19
+SCRIPTNAME=/etc/init.d/$NAME
20
+
21
+# Gracefully exit if the package has been removed.
22
+test -x $DAEMON || exit 0
23
+
24
+. /etc/init.d/functions
25
+
26
+# Default configuration
27
+SRS_DOMAIN=`postconf -h mydomain || true`
28
+SRS_FORWARD_PORT=10001
29
+SRS_REVERSE_PORT=10002
30
+SRS_SECRET=/etc/@PROJECT_NAME@.secret
31
+RUN_AS=nobody
32
+CHROOT=@CHROOT_DIR@
33
+
34
+# Read config file if it is present.
35
+if [ -r @CONFIG_DIR@/$NAME ]
36
+then
37
+    . @CONFIG_DIR@/$NAME
38
+fi
39
+
40
+test -r "$SRS_SECRET" -a -n "$SRS_DOMAIN" || exit 0
41
+
42
+do_start()
43
+{
44
+	echo -n "Starting $DESC: "
45
+	daemon $DAEMON -4 -f"$SRS_FORWARD_PORT" -r"$SRS_REVERSE_PORT" -d"$SRS_DOMAIN" -s"$SRS_SECRET" \
46
+	               -u"$RUN_AS" -p"$PIDFILE" -c"$CHROOT" -X"$SRS_EXCLUDE_DOMAINS" -D
47
+	RETVAL=$?
48
+	echo
49
+    	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$NAME
50
+    	return $RETVAL
51
+}
52
+
53
+do_stop()
54
+{
55
+	echo -n "Stopping $DESC: "
56
+	killproc $prog
57
+        RETVAL=$?
58
+        echo
59
+        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$NAME
60
+        return $RETVAL
61
+}
62
+
63
+case "$1" in
64
+  start)
65
+	do_start
66
+	;;
67
+  stop)
68
+	do_stop
69
+	;;
70
+  status)
71
+	status $NAME
72
+	;;
73
+  restart|force-reload)
74
+	do_stop
75
+	do_start
76
+	;;
77
+  reload)
78
+	;;
79
+  condrestart|try-restart)
80
+	if [ -f /var/lock/subsys/$NAME ]; then
81
+		do_stop
82
+		do_start
83
+	fi
84
+	;;
85
+  *)
86
+	echo "Usage: $NAME {start|stop|restart|condrestart|try-restart|reload|force-reload|status|usage}"
87
+	[ "$1" = "usage" ] && exit 0
88
+	exit 2
89
+	;;
90
+esac
91
+exit $?
92
+

+ 1
- 1
postsrsd.upstart.in View File

5
 stop on runlevel [!2345]
5
 stop on runlevel [!2345]
6
 respawn
6
 respawn
7
 
7
 
8
-env DEFAULTFILE=/etc/default/@PROJECT_NAME@
8
+env DEFAULTFILE=@CONFIG_DIR@/@PROJECT_NAME@
9
 
9
 
10
 script
10
 script
11
 	SRS_DOMAIN=`postconf -h mydomain || true`
11
 	SRS_DOMAIN=`postconf -h mydomain || true`

Loading…
Cancel
Save