--- configure.ac.orig	2022-09-30 07:45:52 UTC
+++ configure.ac
@@ -12,6 +12,9 @@ dnl Checks for header files.
 AC_DISABLE_STATIC
 LT_INIT
 
+AC_DEFINE(_BSD_SOURCE, 1, BSD functions)
+AC_DEFINE(__BSD_VISIBLE, 1, BSD extensions)
+
 AC_HEADER_STDC
 AC_CHECK_HEADER_STDBOOL
 AC_CHECK_HEADERS([arpa/inet.h fcntl.h libintl.h limits.h locale.h malloc.h \
@@ -47,7 +50,7 @@ AC_CHECK_FUNCS([atexit ftruncate gettimeofday localtim
 		strdup strerror strncasecmp strrchr strstr strtol strtoul])
 
 dnl Used in various scripts
-AC_PATH_PROG([ID], [id], [/us/bin/id])
+AC_PATH_PROG([ID], [id], [/usr/bin/id])
 AC_PATH_PROG([USERMOD], [usermod], [/usr/sbin/usermod])
 AC_PATH_PROG([GROUPADD], [groupadd], [/usr/sbin/groupadd])
 AC_PATH_PROG([CAT], [cat], [/bin/cat])
@@ -71,18 +74,26 @@ fi
 AC_CHECK_LIB([itm], [_ITM_commitTransaction], [itm=yes], [itm=no])
 
 OPENLDAP_LIBS=
+if test "x$enable_icsftok" = "xyes"; then
 AC_CHECK_HEADERS([lber.h ldap.h],
 		[OPENLDAP_LIBS="-llber -lldap"],
 		[AC_MSG_ERROR([lber.h and ldap.h are missing. Please install
 			      'openldap-devel'.])])
 AC_SUBST([OPENLDAP_LIBS])
+fi
 
 dnl Define custom variables
 
-lockdir=$localstatedir/lock/opencryptoki
+AC_ARG_WITH([lockdir],
+	[AS_HELP_STRING([--with-lockdir],[lock directory])],
+	[lockdir=$withval],
+	[lockdir=$localstatedir/lock/opencryptoki])
 AC_SUBST(lockdir)
 
-logdir=$localstatedir/log/opencryptoki
+AC_ARG_WITH([logdir],
+	[AS_HELP_STRING([--with-logdir],[log directory])],
+	[logdir=$withval],
+	[logdir=$localstatedir/log/opencryptoki])
 AC_SUBST(logdir)
 
 dnl ---
@@ -244,6 +255,19 @@ AC_ARG_WITH([libudev],
 	[],
 	[with_libudev=check])
 
+dnl --- check for pkcs11 user
+AC_ARG_WITH([pkcs11user],
+	AC_HELP_STRING([--with-pkcs11user[[=USER]]], [set pkcs11 user [[pkcs11]]]),
+	[pkcs11_user=$withval],
+	[pkcs11_user=_pkcs11])
+dnl --- check for pkcs11 group
+AC_ARG_WITH(pkcs11group,
+	AC_HELP_STRING([--with-pkcs11group[[=GROUP]]], [set pkcs11 group [[pkcs11]]]),
+	[pkcs11_group=$withval],
+	[pkcs11_group=_pkcs11])
+AC_SUBST(PKCS11USER, $pkcs11_user)
+AC_SUBST(PKCS11GROUP, $pkcs11_group)
+
 dnl ---
 dnl ---
 dnl --- Now that we have all the options, let's check for a valid build
@@ -674,10 +698,14 @@ else
 fi
 AM_CONDITIONAL([ENABLE_MD2], [test "x$enable_md2" = "xyes"])
 
-CFLAGS="$CFLAGS -DPKCS64 -D_XOPEN_SOURCE=600 -Wall -Wextra"
+CFLAGS="$CFLAGS -Wall -Wextra -Wno-pointer-sign"
 
-CFLAGS+=' -DCONFIG_PATH=\"$(localstatedir)/lib/opencryptoki\" -DSBIN_PATH=\"$(sbindir)\" -DLIB_PATH=\"$(libdir)\" -DLOCKDIR_PATH=\"$(lockdir)\" -DOCK_CONFDIR=\"$(sysconfdir)/opencryptoki\" -DOCK_LOGDIR=\"$(logdir)\"'
+CPPFX='-DCONFIG_PATH=\"$(localstatedir)/lib/opencryptoki\" -DSBIN_PATH=\"$(sbindir)\" -DLIB_PATH=\"$(libdir)\" -DLOCKDIR_PATH=\"$(lockdir)\" -DOCK_CONFDIR=\"$(sysconfdir)/opencryptoki\" -DOCK_LOGDIR=\"$(logdir)\"'
 
+CPPFLAGS="$CPPFLAGS -DPKCS64 -D_XOPEN_SOURCE=600 $CPPFX"
+CPPFLAGS="$CPPFLAGS -DPKCS11USER=\\\"${pkcs11_user}\\\""
+CPPFLAGS="$CPPFLAGS -DPKCS11GROUP=\\\"${pkcs11_group}\\\""
+
 # At this point, CFLAGS is set to something sensible
 AC_PROG_CC
 AC_PROG_CXX
@@ -690,6 +718,10 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
     #endif]])],,
   [AC_MSG_ERROR([C++ compiler is missing on your system. Please install 'gcc-c++'.])])
 AC_LANG_POP([C++])
+
+AC_SUBST(FPIC, $lt_prog_compiler_pic)
+
+AC_SUBST(LOCALBASE, $LOCALBASE)
 
 AC_CONFIG_MACRO_DIRS([m4])
 
