Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for macOS #182

Merged
merged 11 commits into from
Jun 26, 2024
Merged

Support for macOS #182

merged 11 commits into from
Jun 26, 2024

Conversation

pkern
Copy link
Member

@pkern pkern commented Jun 20, 2024

This implements some source changes to make the code base compatible with macOS. Which is, of course, a little frustrating to fix. I have no idea how compatibility with other awkward OSes (like BSDs) will be after this change.

@pkern pkern force-pushed the macos branch 2 times, most recently from e8211a2 to 8173d7b Compare June 20, 2024 20:19
pkern added 3 commits June 20, 2024 22:40
Apparently C has deprecated them, while undeprecating them in the newest - not
quite available version, in alignment with C++.
Otherwise the include path is not plumbed through for consumption by login.c's
compilation process when openssl is in a non-standard path (like with Homebrew
on macOS).
pkern added 3 commits June 20, 2024 22:43
Darwin does not define HOST_NAME_MAX and also Linux is setting it to 64 instead
of 255 as defined by the minimum of _POSIX_HOST_NAME_MAX. What a mess.
At least on macOS you don't get vsyslog() if you set _POSIX_SOURCE this way.
@pkern pkern requested a review from vvidic June 20, 2024 20:57
@pkern pkern marked this pull request as ready for review June 20, 2024 20:58
login/pam.c Outdated
Comment on lines 36 to 39
#ifndef PAM_GLOME_LINUX
void pam_syslog(void *pamh, ...) { (void)(pamh); }
void pam_vsyslog(void *pamh, ...) { (void)(pamh); }
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here could be clearer if the meson config would determine HAVE_PAM_EXT and then we'd

#ifdef HAVE_PAM_EXT
#include <security/pam_ext.h>
#else 
void pam_syslog(void *pamh, ...) { (void)(pamh); }
void pam_vsyslog(void *pamh, ...) { (void)(pamh); }
#endif

and

#ifdef PLATFORM_DARWIN
#include <security/pam_appl.h>
#endif

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the define to HAVE_PAM_EXT but made the include conditional on the else branch.

@@ -29,6 +33,11 @@

#define MODULE_NAME "pam_glome"

#ifndef PAM_GLOME_LINUX
void pam_syslog(void *pamh, ...) { (void)(pamh); }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we implement this in terms of syslog instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With syslog it might end up in a different log file or with different format than the other PAM modules so not sure about that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fair: I have only made this compile and did not test against PAM's Darwin implementation. I suspect that way lies a lot of pain. My main worry here would be how to do it properly on the other BSD flavors.

For instance pam_krb5 documents these options:

  • debug: turns on debugging via syslog(3). Debugging messages are logged with priority LOG_DEBUG.
  • debug_sensitive: turns on debugging of sensitive information via syslog(3). Debug messages are logged with priority LOG_DEBUG.

Russ Albery wrote https://github.com/rra/pam-krb5/blob/main/portable/pam_vsyslog.c which I find amusing. Presumably we could handle compatibility the same way...

And there I was thinking that PAM is the proper abstraction between different OSes. ;-)

@burgerdev
Copy link
Collaborator

Maybe we should just abandon vsyslog.

diff --git a/login/login.c b/login/login.c
index 0f6689b..1f20804 100644
--- a/login/login.c
+++ b/login/login.c
@@ -12,10 +12,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-// For vsyslog
-#define _BSD_SOURCE
-#define _DEFAULT_SOURCE
-
 #include "login.h"
 
 #include <assert.h>
@@ -211,9 +207,15 @@ void login_syslog(glome_login_config_t* config, pam_handle_t* pamh,
                   int priority, const char* format, ...) {
   UNUSED(pamh);
   if (config->options & SYSLOG) {
+    char* buf = calloc(1024, 1);
+    if (!buf) {
+      return;
+    }
+
     va_list args;
     va_start(args, format);
-    vsyslog(LOG_MAKEPRI(LOG_AUTH, priority), format, args);
+    vsnprintf(buf, 1024, format, args);
+    syslog(priority, "%s", buf);
     va_end(args);
   }
 }
diff --git a/meson.build b/meson.build
index 64a51d4..a23b0b0 100644
--- a/meson.build
+++ b/meson.build
@@ -19,9 +19,7 @@ pkg = import('pkgconfig')
 
 sysconfdir = join_paths(get_option('prefix'), get_option('sysconfdir'))
 add_project_arguments('-DSYSCONFDIR="' + sysconfdir + '"', language : 'c')
-if host_machine.system() != 'darwin'
-    add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c')
-endif
+add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c')
 add_project_arguments('-DOPENSSL_API_COMPAT=10100', language : 'c')
 
 openssl_dep = dependency('openssl', version : '>=1.1')

login/login.c Outdated
@@ -308,6 +308,7 @@ int login_prompt(glome_login_config_t* config, pam_handle_t* pamh,
static char* create_login_message(glome_login_config_t* config,
pam_handle_t* pamh, const char** error_tag) {
char* host_id = NULL;
int max_hostname_len = sysconf(_SC_HOST_NAME_MAX) + 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check return value of sysconf?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, yes. Let's pick _POSIX_HOST_NAME_MAX (given that it's per standard the minimum, even if Linux disagrees) as the fallback value.

@@ -29,6 +33,11 @@

#define MODULE_NAME "pam_glome"

#ifndef PAM_GLOME_LINUX
void pam_syslog(void *pamh, ...) { (void)(pamh); }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With syslog it might end up in a different log file or with different format than the other PAM modules so not sure about that.

pkern and others added 2 commits June 24, 2024 10:44
vsnprintf is part of C99 and thus does not need feature test macros.

Co-authored-by: Philipp Kern <pkern@google.com>
@pkern
Copy link
Member Author

pkern commented Jun 24, 2024

Maybe we should just abandon vsyslog.

Applied, thank you! C99 ftw.

@pkern pkern merged commit 729ad51 into google:master Jun 26, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants