Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 1 | From 236d6c8c0dd7e15d9a9795813b94bc87ce09eec5 Mon Sep 17 00:00:00 2001 |
| 2 | From: Peter Kjellerstedt <peter.kjellerstedt@axis.com> |
| 3 | Date: Fri, 29 Apr 2022 19:32:29 +0200 |
| 4 | Subject: [PATCH] Make it possible to build without debconf support |
| 5 | |
| 6 | Not all systems have the debconfclient library available. |
| 7 | |
| 8 | Upstream-Status: Backport [https://salsa.debian.org/debian/base-passwd/-/commit/c72aa5dd25a952da25e307761f4526db2c8c39ec] |
| 9 | Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> |
| 10 | --- |
| 11 | Makefile.am | 1 - |
| 12 | configure.ac | 13 +++++++++++++ |
| 13 | update-passwd.c | 15 +++++++++++++++ |
| 14 | 3 files changed, 28 insertions(+), 1 deletion(-) |
| 15 | |
| 16 | diff --git a/Makefile.am b/Makefile.am |
| 17 | index 223916f..4bdd769 100644 |
| 18 | --- a/Makefile.am |
| 19 | +++ b/Makefile.am |
| 20 | @@ -3,7 +3,6 @@ SUBDIRS = doc man |
| 21 | sbin_PROGRAMS = update-passwd |
| 22 | |
| 23 | update_passwd_SOURCES = update-passwd.c |
| 24 | -update_passwd_LDADD = -ldebconfclient |
| 25 | |
| 26 | pkgdata_DATA = passwd.master group.master |
| 27 | |
| 28 | diff --git a/configure.ac b/configure.ac |
| 29 | index 9d1ace5..1e35ad1 100644 |
| 30 | --- a/configure.ac |
| 31 | +++ b/configure.ac |
| 32 | @@ -14,6 +14,19 @@ AC_SYS_LARGEFILE |
| 33 | dnl Scan for things we need |
| 34 | AC_CHECK_FUNCS([putgrent]) |
| 35 | |
| 36 | +dnl Check for debconf |
| 37 | +AC_MSG_CHECKING([whether to enable debconf support]) |
| 38 | +AC_ARG_ENABLE([debconf], |
| 39 | + [AS_HELP_STRING([--disable-debconf], [disable support for debconf])], |
| 40 | + [], |
| 41 | + [enable_debconf=yes]) |
| 42 | +AC_MSG_RESULT($enable_debconf) |
| 43 | +AS_IF([test "x$enable_debconf" != xno], |
| 44 | + [AC_CHECK_LIB([debconfclient], [debconfclient_new], [], |
| 45 | + [AC_MSG_ERROR( |
| 46 | + [debconf support not available (use --disable-debconf to disable)])]) |
| 47 | + AC_DEFINE([HAVE_DEBCONF], [1], [Define if you have libdebconfclient])]) |
| 48 | + |
| 49 | dnl Finally output everything |
| 50 | AC_CONFIG_FILES([Makefile doc/Makefile man/Makefile]) |
| 51 | AC_OUTPUT |
| 52 | diff --git a/update-passwd.c b/update-passwd.c |
| 53 | index 3f3dffa..5b49740 100644 |
| 54 | --- a/update-passwd.c |
| 55 | +++ b/update-passwd.c |
| 56 | @@ -39,7 +39,9 @@ |
| 57 | #include <stdarg.h> |
| 58 | #include <ctype.h> |
| 59 | |
| 60 | +#ifdef HAVE_DEBCONF |
| 61 | #include <cdebconf/debconfclient.h> |
| 62 | +#endif |
| 63 | |
| 64 | #define DEFAULT_PASSWD_MASTER "/usr/share/base-passwd/passwd.master" |
| 65 | #define DEFAULT_GROUP_MASTER "/usr/share/base-passwd/group.master" |
| 66 | @@ -143,6 +145,7 @@ int flag_debconf = 0; |
| 67 | const char* user_domain = DEFAULT_DEBCONF_DOMAIN; |
| 68 | const char* group_domain = DEFAULT_DEBCONF_DOMAIN; |
| 69 | |
| 70 | +#ifdef HAVE_DEBCONF |
| 71 | struct debconfclient* debconf = NULL; |
| 72 | |
| 73 | /* Abort the program if talking to debconf fails. Use ret exactly once. */ |
| 74 | @@ -162,6 +165,10 @@ struct debconfclient* debconf = NULL; |
| 75 | DEBCONF_CHECK(debconf_register(debconf, (template), (question))) |
| 76 | #define DEBCONF_SUBST(question, var, value) \ |
| 77 | DEBCONF_CHECK(debconf_subst(debconf, (question), (var), (value))) |
| 78 | +#else |
| 79 | +#define DEBCONF_REGISTER(template, question) |
| 80 | +#define DEBCONF_SUBST(question, var, value) |
| 81 | +#endif |
| 82 | |
| 83 | |
| 84 | /* malloc() with out-of-memory checking. |
| 85 | @@ -621,6 +628,7 @@ void version() { |
| 86 | * flag. Aborts the problem on any failure. |
| 87 | */ |
| 88 | int ask_debconf(const char* priority, const char* question) { |
| 89 | +#ifdef HAVE_DEBCONF |
| 90 | int ret; |
| 91 | const char* response; |
| 92 | |
| 93 | @@ -640,6 +648,9 @@ int ask_debconf(const char* priority, const char* question) { |
| 94 | return 1; |
| 95 | else |
| 96 | return 0; |
| 97 | +#else |
| 98 | + return 0; |
| 99 | +#endif |
| 100 | } |
| 101 | |
| 102 | |
| 103 | @@ -1427,6 +1438,7 @@ int main(int argc, char** argv) { |
| 104 | /* If DEBIAN_HAS_FRONTEND is set in the environment, we're running under |
| 105 | * debconf. Enable debconf prompting unless --dry-run was also given. |
| 106 | */ |
| 107 | +#ifdef HAVE_DEBCONF |
| 108 | if (getenv("DEBIAN_HAS_FRONTEND")!=NULL && !opt_dryrun) { |
| 109 | debconf=debconfclient_new(); |
| 110 | if (debconf==NULL) { |
| 111 | @@ -1435,6 +1447,7 @@ int main(int argc, char** argv) { |
| 112 | } |
| 113 | flag_debconf=1; |
| 114 | } |
| 115 | +#endif |
| 116 | |
| 117 | if (read_passwd(&master_accounts, master_passwd)!=0) |
| 118 | return 2; |
| 119 | @@ -1480,8 +1493,10 @@ int main(int argc, char** argv) { |
| 120 | if (!unlock_files()) |
| 121 | return 5; |
| 122 | |
| 123 | +#ifdef HAVE_DEBCONF |
| 124 | if (debconf!=NULL) |
| 125 | debconfclient_delete(debconf); |
| 126 | +#endif |
| 127 | |
| 128 | if (opt_dryrun) |
| 129 | return flag_dirty; |