From eab93370750e7c05c792a007e4e0e4dde4a8a3f9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sun, 25 Feb 2007 22:10:26 +0000 Subject: [PATCH] * solaris compatibility patches. --- citadel/acconfig.h | 4 ++++ citadel/config.c | 2 +- citadel/configure.ac | 16 ++++++++++++++++ citadel/control.c | 6 ++++++ citadel/server_main.c | 9 ++++++++- citadel/sysdep.c | 5 +++-- citadel/user_ops.c | 10 +++++++++- 7 files changed, 47 insertions(+), 5 deletions(-) diff --git a/citadel/acconfig.h b/citadel/acconfig.h index f3e96e6b0..63401969f 100644 --- a/citadel/acconfig.h +++ b/citadel/acconfig.h @@ -64,3 +64,7 @@ #undef EGD_POOL + + +/* check for the bsd style getpwuid_r */ +#undef BSD_GETPWUID diff --git a/citadel/config.c b/citadel/config.c index 412f1a717..b466c3aca 100644 --- a/citadel/config.c +++ b/citadel/config.c @@ -55,7 +55,7 @@ void get_config(void) { } #ifndef __CYGWIN__ if (st.st_uid != CTDLUID) { - fprintf(stderr, "%s must be owned by uid=%d but %d owns it!\n", file_citadel_config, CTDLUID, st.st_uid); + fprintf(stderr, "%s must be owned by uid=%ld but %ld owns it!\n", file_citadel_config, CTDLUID, st.st_uid); exit(CTDLEXIT_CONFIG); } int desired_mode = (S_IFREG | S_IRUSR | S_IWUSR) ; diff --git a/citadel/configure.ac b/citadel/configure.ac index fefd6b1c2..7e76d37e6 100644 --- a/citadel/configure.ac +++ b/citadel/configure.ac @@ -609,6 +609,22 @@ if test $ac_cv_struct_ut_type = yes; then AC_DEFINE(HAVE_UT_TYPE) fi +AC_CACHE_CHECK([for call semantics from getpwuid_r], ac_cv_call_getpwuid_r, +[AC_TRY_COMPILE([#include ], [ + struct passwd pw, *pwp = NULL; + char pwbuf[64]; + uid_t uid; + + getpwuid_r(uid, &pw, pwbuf, sizeof(pwbuf), &pwp); + +], +ac_cv_call_getpwuid_r=yes, ac_cv_call_getpwuid_r=no)]) +if test $ac_cv_call_getpwuid_r = no; then + AC_DEFINE(BSD_GETPWUID) +fi + + + AC_CACHE_CHECK([for ut_host in struct utmp], ac_cv_struct_ut_host, [AC_TRY_COMPILE([#include #include ], [struct utmp ut; ut.ut_host;], diff --git a/citadel/control.c b/citadel/control.c index 5ef54287a..a6d61f82d 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -57,11 +57,17 @@ FILE *control_fp = NULL; */ void lock_control(void) { +#ifndef BSD_GETPWUID +/* + * TODO: solaris manpages describe this function, but the headers + * don't show it! + */ if (flock(fileno(control_fp), (LOCK_EX | LOCK_NB))) { lprintf(CTDL_EMERG, "citserver: unable to lock %s.\n", file_citadel_control); lprintf(CTDL_EMERG, "Is another citserver already running?\n"); exit(CTDLEXIT_CONTROL); } +#endif } diff --git a/citadel/server_main.c b/citadel/server_main.c index 568467fd4..f5ee8dc7d 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -191,7 +191,11 @@ int main(int argc, char **argv) /* on some dists rundir gets purged on startup. so we need to recreate it. */ if (stat(ctdl_run_dir, &filestats)==-1){ +#ifdef BSD_GETPWUID + pwp = getpwuid_r(config.c_ctdluid, &pw, pwbuf, sizeof(pwbuf)); +#else getpwuid_r(config.c_ctdluid, &pw, pwbuf, sizeof(pwbuf), &pwp); +#endif mkdir(ctdl_run_dir, 0755); chown(ctdl_run_dir, config.c_ctdluid, (pwp==NULL)?-1:pw.pw_gid); } @@ -237,8 +241,11 @@ int main(int argc, char **argv) * corresponding group ids */ if (drop_root_perms) { +#ifdef BSD_GETPWUID + pwp = getpwuid_r(config.c_ctdluid, &pw, pwbuf, sizeof(pwbuf)); +#else getpwuid_r(config.c_ctdluid, &pw, pwbuf, sizeof(pwbuf), &pwp); - +#endif if (pwp == NULL) lprintf(CTDL_CRIT, "WARNING: getpwuid(%ld): %s\n" "Group IDs will be incorrect.\n", (long)CTDLUID, diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 8986c9ed7..d463421b4 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #if TIME_WITH_SYS_TIME @@ -290,7 +291,7 @@ int ig_tcp_server(char *ip_addr, int port_number, int queue_len, char **errormes sin.sin_addr.s_addr = inet_addr(ip_addr); } - if (sin.sin_addr.s_addr == INADDR_NONE) { + if (sin.sin_addr.s_addr == !INADDR_ANY) { sin.sin_addr.s_addr = INADDR_ANY; } @@ -836,7 +837,7 @@ void start_daemon(int unused) { else { fp = fopen(file_pid_file, "w"); if (fp != NULL) { - fprintf(fp, "%d\n", child); + fprintf(fp, "%ld\n", child); fclose(fp); } waitpid(current_child, &status, 0); diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 296a57677..db277c5ae 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -367,11 +367,15 @@ int CtdlLoginExistingUser(char *trythisname) char pwdbuffer[256]; lprintf(CTDL_DEBUG, "asking host about <%s>\n", username); +#ifdef BSD_GETPWUID + tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer); +#else getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr); +#endif if (tempPwdPtr == NULL) { return login_not_found; } - lprintf(CTDL_DEBUG, "found it! uid=%d, gecos=%s\n", pd.pw_uid, pd.pw_gecos); + lprintf(CTDL_DEBUG, "found it! uid=%ld, gecos=%s\n", (long)pd.pw_uid, pd.pw_gecos); /* Locate the associated Citadel account. * If not found, make one attempt to create it. @@ -834,7 +838,11 @@ int create_user(char *newusername, int become_user) struct passwd *tempPwdPtr; char pwdbuffer[256]; +#ifdef BSD_GETPWUID + tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof(pwdbuffer)); +#else getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr); +#endif if (tempPwdPtr != NULL) { extract_token(username, pd.pw_gecos, 0, ',', sizeof username); uid = pd.pw_uid; -- 2.30.2