aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-03-01 21:46:15 +0800
committerYuqian Yang <crupest@crupest.life>2025-03-01 21:47:38 +0800
commitab5eb9b1a6026dbdc9d9259934b85170422c1538 (patch)
tree862b4dc5a38c333de5617fd74ec6a7d301007029
parent5cb97aee88271dfd25c20629052b3d89f05e63c2 (diff)
downloadpam-dev.tar.gz
pam-dev.tar.bz2
pam-dev.zip
HALF WORK: MAX_PATHdev
-rw-r--r--examples/xsh.c25
-rw-r--r--libpam/include/pam_inline.h52
-rw-r--r--libpam/include/test_assert.h4
-rw-r--r--modules/pam_canonicalize_user/tst-pam_canonicalize_user-retval.c8
-rw-r--r--modules/pam_debug/tst-pam_debug-retval.c8
-rw-r--r--modules/pam_deny/tst-pam_deny-retval.c8
-rw-r--r--modules/pam_echo/pam_echo.c14
-rw-r--r--modules/pam_echo/tst-pam_echo-retval.c8
-rw-r--r--modules/pam_env/tst-pam_env-retval.c7
-rw-r--r--modules/pam_faildelay/tst-pam_faildelay-retval.c8
-rw-r--r--modules/pam_faillock/tst-pam_faillock-retval.c8
-rw-r--r--modules/pam_listfile/tst-pam_listfile-retval.c8
-rw-r--r--modules/pam_localuser/tst-pam_localuser-retval.c8
-rw-r--r--modules/pam_mkhomedir/mkhomedir_helper.c47
-rw-r--r--modules/pam_mkhomedir/tst-pam_mkhomedir-retval.c8
-rw-r--r--modules/pam_namespace/pam_namespace.c6
-rw-r--r--modules/pam_nologin/tst-pam_nologin-retval.c8
-rw-r--r--modules/pam_permit/tst-pam_permit-retval.c8
-rw-r--r--modules/pam_pwhistory/tst-pam_pwhistory-retval.c8
-rw-r--r--modules/pam_rootok/tst-pam_rootok-retval.c8
-rw-r--r--modules/pam_sepermit/tst-pam_sepermit-retval.c8
-rw-r--r--modules/pam_succeed_if/tst-pam_succeed_if-retval.c8
-rw-r--r--modules/pam_time/tst-pam_time-retval.c8
-rw-r--r--modules/pam_warn/tst-pam_warn-retval.c8
-rw-r--r--tests/tst-dlopen.c15
25 files changed, 206 insertions, 100 deletions
diff --git a/examples/xsh.c b/examples/xsh.c
index 5b34fc17..29f4dc00 100644
--- a/examples/xsh.c
+++ b/examples/xsh.c
@@ -32,6 +32,22 @@ static struct pam_conv conv = {
/* ------- the application itself -------- */
+static char *xgethostname() {
+ long max_host_name;
+ char *buffer;
+
+ max_host_name = sysconf(_SC_HOST_NAME_MAX);
+ buffer = malloc(max_host_name + 1);
+
+ if (gethostname(buffer, max_host_name + 1)) {
+ free(buffer);
+ return NULL;
+ }
+
+ buffer[max_host_name] = '\0';
+ return buffer;
+}
+
int main(int argc, char **argv)
{
pam_handle_t *pamh=NULL;
@@ -58,7 +74,7 @@ int main(int argc, char **argv)
/* fill in the RUSER and RHOST etc. fields */
{
- char buffer[100];
+ char *myhostname;
struct passwd *pw;
const char *tty;
@@ -68,13 +84,14 @@ int main(int argc, char **argv)
bail_out(pamh,1,retcode,"pam_set_item(PAM_RUSER)");
}
- retcode = gethostname(buffer, sizeof(buffer)-1);
- if (retcode) {
+ myhostname = xgethostname();
+ if (!myhostname) {
perror("failed to look up hostname");
retcode = pam_end(pamh, PAM_ABORT);
bail_out(pamh,1,retcode,"pam_end");
}
- retcode = pam_set_item(pamh, PAM_RHOST, buffer);
+ retcode = pam_set_item(pamh, PAM_RHOST, myhostname);
+ free(myhostname);
bail_out(pamh,1,retcode,"pam_set_item(PAM_RHOST)");
tty = ttyname(fileno(stdin));
diff --git a/libpam/include/pam_inline.h b/libpam/include/pam_inline.h
index cc302248..39803191 100644
--- a/libpam/include/pam_inline.h
+++ b/libpam/include/pam_inline.h
@@ -9,6 +9,7 @@
#define PAM_INLINE_H
#include "pam_cc_compat.h"
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -209,4 +210,55 @@ pam_consttime_streq(const char *userinput, const char *secret) {
return ret == 0;
}
+
+static inline char *xreadlink(const char *restrict path) {
+ char *buffer;
+ size_t allocated = 128;
+ ssize_t len;
+
+ while (1) {
+ buffer = (char*) malloc(allocated);
+ if (!buffer) { return NULL; }
+ len = readlink(path, buffer, allocated);
+ if (len < (ssize_t) allocated) { return buffer; }
+ free(buffer);
+ if (len >= (ssize_t) allocated) { allocated *= 2; continue; }
+ return NULL;
+ }
+ }
+
+
+static inline char *xgethostname() {
+ long max_host_name;
+ char *buffer;
+
+ max_host_name = sysconf(_SC_HOST_NAME_MAX);
+ buffer = malloc(max_host_name + 1);
+
+ if (gethostname(buffer, max_host_name + 1)) {
+ free(buffer);
+ return NULL;
+ }
+
+ buffer[max_host_name] = '\0';
+ return buffer;
+}
+
+static inline char *xgetcwd() {
+ char *buffer;
+ size_t allocated = 128;
+
+ while (1) {
+ buffer = (char*) malloc(allocated);
+ if (!buffer) { return NULL; }
+ getcwd(buffer, allocated);
+ if (buffer) return buffer;
+ free(buffer);
+ if (errno == ERANGE) { allocated *= 2; continue; }
+ return NULL;
+ }
+}
+
+
+
#endif /* PAM_INLINE_H */
diff --git a/libpam/include/test_assert.h b/libpam/include/test_assert.h
index 879f5814..a6739a4b 100644
--- a/libpam/include/test_assert.h
+++ b/libpam/include/test_assert.h
@@ -51,8 +51,4 @@
ASSERT_((expected_), #expected_, >=, (seen_), #seen_) \
/* End of ASSERT_LT definition. */
-# ifndef PATH_MAX
-# define PATH_MAX 4096
-# endif
-
#endif /* TEST_ASSERT_H */
diff --git a/modules/pam_canonicalize_user/tst-pam_canonicalize_user-retval.c b/modules/pam_canonicalize_user/tst-pam_canonicalize_user-retval.c
index 1c8af396..73a1740f 100644
--- a/modules/pam_canonicalize_user/tst-pam_canonicalize_user-retval.c
+++ b/modules/pam_canonicalize_user/tst-pam_canonicalize_user-retval.c
@@ -5,6 +5,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <errno.h>
#include <limits.h>
@@ -62,9 +63,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
+ char *cwd;
- char cwd[PATH_MAX];
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
struct passwd *pw;
ASSERT_NE(NULL, (pw = getpwuid(0)));
@@ -193,5 +195,7 @@ main(void)
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_debug/tst-pam_debug-retval.c b/modules/pam_debug/tst-pam_debug-retval.c
index e83c89d5..b0c5529f 100644
--- a/modules/pam_debug/tst-pam_debug-retval.c
+++ b/modules/pam_debug/tst-pam_debug-retval.c
@@ -5,6 +5,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <limits.h>
#include <stdio.h>
@@ -31,9 +32,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
- char cwd[PATH_MAX];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
ASSERT_NE(NULL, fp = fopen(service_file, "w"));
ASSERT_LT(0, fprintf(fp, "#%%PAM-1.0\n"
@@ -61,5 +63,7 @@ main(void)
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_deny/tst-pam_deny-retval.c b/modules/pam_deny/tst-pam_deny-retval.c
index 665fcef4..95828742 100644
--- a/modules/pam_deny/tst-pam_deny-retval.c
+++ b/modules/pam_deny/tst-pam_deny-retval.c
@@ -5,6 +5,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <limits.h>
#include <stdio.h>
@@ -24,9 +25,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
- char cwd[PATH_MAX];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
ASSERT_NE(NULL, fp = fopen(service_file, "w"));
ASSERT_LT(0, fprintf(fp, "#%%PAM-1.0\n"
@@ -54,5 +56,7 @@ main(void)
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_echo/pam_echo.c b/modules/pam_echo/pam_echo.c
index 5a882028..d58f0ac6 100644
--- a/modules/pam_echo/pam_echo.c
+++ b/modules/pam_echo/pam_echo.c
@@ -47,10 +47,6 @@
#include <sys/types.h>
#include <sys/stat.h>
-#ifndef HOST_NAME_MAX
-#define HOST_NAME_MAX 255
-#endif
-
#include <security/pam_modules.h>
#include <security/pam_modutil.h>
#include <security/_pam_macros.h>
@@ -62,7 +58,7 @@ replace_and_print (pam_handle_t *pamh, const char *mesg)
{
char *output;
size_t length = strlen (mesg) + PAM_MAX_MSG_SIZE;
- char myhostname[HOST_NAME_MAX+1];
+ char *myhostname = NULL;
const void *str = NULL;
const char *p, *q;
int item;
@@ -108,10 +104,8 @@ replace_and_print (pam_handle_t *pamh, const char *mesg)
}
if (item == -2)
{
- if (gethostname (myhostname, sizeof (myhostname)) == -1)
- str = NULL;
- else
- str = &myhostname;
+ myhostname = xgethostname();
+ str = myhostname;
}
else
{
@@ -128,6 +122,8 @@ replace_and_print (pam_handle_t *pamh, const char *mesg)
pam_info (pamh, "%s", output);
free (output);
+ if (myhostname) { free(myhostname); }
+
return PAM_SUCCESS;
}
diff --git a/modules/pam_echo/tst-pam_echo-retval.c b/modules/pam_echo/tst-pam_echo-retval.c
index 8264cb0e..31432dc6 100644
--- a/modules/pam_echo/tst-pam_echo-retval.c
+++ b/modules/pam_echo/tst-pam_echo-retval.c
@@ -5,6 +5,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <limits.h>
#include <stdio.h>
@@ -24,9 +25,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
- char cwd[PATH_MAX];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
/* PAM_SUCCESS -> PAM_SUCCESS, PAM_IGNORE -> PAM_PERM_DENIED */
ASSERT_NE(NULL, fp = fopen(service_file, "w"));
@@ -97,5 +99,7 @@ main(void)
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_env/tst-pam_env-retval.c b/modules/pam_env/tst-pam_env-retval.c
index c08f44c3..153d913c 100644
--- a/modules/pam_env/tst-pam_env-retval.c
+++ b/modules/pam_env/tst-pam_env-retval.c
@@ -6,6 +6,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <errno.h>
#include <libgen.h>
@@ -153,9 +154,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
- char cwd[PATH_MAX];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
setup();
@@ -285,6 +287,7 @@ main(void)
/* cleanup */
cleanup();
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
return 0;
}
diff --git a/modules/pam_faildelay/tst-pam_faildelay-retval.c b/modules/pam_faildelay/tst-pam_faildelay-retval.c
index 72b16ef9..8cfdc4c1 100644
--- a/modules/pam_faildelay/tst-pam_faildelay-retval.c
+++ b/modules/pam_faildelay/tst-pam_faildelay-retval.c
@@ -5,6 +5,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <limits.h>
#include <stdio.h>
@@ -24,9 +25,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
- char cwd[PATH_MAX];
+ char* cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
/* PAM_IGNORE -> PAM_PERM_DENIED */
ASSERT_NE(NULL, fp = fopen(service_file, "w"));
@@ -84,5 +86,7 @@ main(void)
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_faillock/tst-pam_faillock-retval.c b/modules/pam_faillock/tst-pam_faillock-retval.c
index cbdc1684..3db2838a 100644
--- a/modules/pam_faillock/tst-pam_faillock-retval.c
+++ b/modules/pam_faillock/tst-pam_faillock-retval.c
@@ -3,6 +3,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <limits.h>
#include <stdio.h>
@@ -23,9 +24,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
- char cwd[PATH_MAX];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
ASSERT_NE(NULL, fp = fopen(config_filename, "w"));
ASSERT_LT(0, fprintf(fp,
@@ -116,5 +118,7 @@ main(void)
ASSERT_EQ(0,unlink(user_name));
ASSERT_EQ(0,unlink(config_filename));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_listfile/tst-pam_listfile-retval.c b/modules/pam_listfile/tst-pam_listfile-retval.c
index 02ed9446..78925409 100644
--- a/modules/pam_listfile/tst-pam_listfile-retval.c
+++ b/modules/pam_listfile/tst-pam_listfile-retval.c
@@ -5,6 +5,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <errno.h>
#include <limits.h>
@@ -27,9 +28,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
+ char *cwd;
- char cwd[PATH_MAX];
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
struct passwd *pw;
ASSERT_NE(NULL, (pw = getpwuid(geteuid())));
@@ -616,5 +618,7 @@ main(void)
ASSERT_EQ(0, unlink(list_file));
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_localuser/tst-pam_localuser-retval.c b/modules/pam_localuser/tst-pam_localuser-retval.c
index f6c22f97..e50d08c8 100644
--- a/modules/pam_localuser/tst-pam_localuser-retval.c
+++ b/modules/pam_localuser/tst-pam_localuser-retval.c
@@ -5,6 +5,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <limits.h>
#include <stdio.h>
@@ -31,10 +32,11 @@ main(void)
static struct pam_conv conv;
pam_handle_t *pamh = NULL;
FILE *fp;
- char cwd[PATH_MAX];
char name[BUFSIZ];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
/* default passwd */
ASSERT_NE(NULL, fp = fopen(service_file, "w"));
@@ -140,5 +142,7 @@ main(void)
ASSERT_EQ(0, unlink(service_file));
ASSERT_EQ(0, unlink(passwd_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_mkhomedir/mkhomedir_helper.c b/modules/pam_mkhomedir/mkhomedir_helper.c
index eefb5999..3b8ea454 100644
--- a/modules/pam_mkhomedir/mkhomedir_helper.c
+++ b/modules/pam_mkhomedir/mkhomedir_helper.c
@@ -9,6 +9,7 @@
*/
#include "config.h"
+#include "pam_inline.h"
#include <stdarg.h>
#include <sys/types.h>
@@ -121,38 +122,11 @@ copy_entry(struct dir_spec *parent, const struct passwd *pwd, mode_t dir_mode,
/* If it's a symlink, create a new link. */
if (S_ISLNK(st.st_mode))
{
- int pointedlen = 0;
-#ifndef PATH_MAX
- char *pointed = NULL;
- {
- int size = 100;
-
- while (1)
- {
- pointed = malloc(size);
- if (pointed == NULL)
- {
- retval = PAM_BUF_ERR;
- goto go_out;
- }
- pointedlen = readlink(newsource, pointed, size);
- if (pointedlen < 0) break;
- if (pointedlen < size) break;
- free(pointed);
- size *= 2;
- }
- }
- if (pointedlen < 0)
- free(pointed);
- else
- pointed[pointedlen] = 0;
-#else
- char pointed[PATH_MAX] = {};
+ char *pointed;
- pointedlen = readlink(newsource, pointed, sizeof(pointed) - 1);
-#endif
+ pointed = xreadlink(newsource);
- if (pointedlen >= 0)
+ if (pointed)
{
if (symlinkat(pointed, parent->fd, dent->d_name) != 0)
{
@@ -161,9 +135,8 @@ copy_entry(struct dir_spec *parent, const struct passwd *pwd, mode_t dir_mode,
if (retval != PAM_SUCCESS)
pam_syslog(NULL, LOG_DEBUG, "unable to create link %s/%s: %m",
parent->path, dent->d_name);
-#ifndef PATH_MAX
- free(pointed);
-#endif
+
+ free(pointed);
goto go_out;
}
@@ -173,15 +146,11 @@ copy_entry(struct dir_spec *parent, const struct passwd *pwd, mode_t dir_mode,
pam_syslog(NULL, LOG_DEBUG,
"unable to change perms on link %s/%s: %m",
parent->path, dent->d_name);
-#ifndef PATH_MAX
- free(pointed);
-#endif
retval = PAM_PERM_DENIED;
+ free(pointed);
goto go_out;
}
-#ifndef PATH_MAX
- free(pointed);
-#endif
+ free(pointed);
}
retval = PAM_SUCCESS;
goto go_out;
diff --git a/modules/pam_mkhomedir/tst-pam_mkhomedir-retval.c b/modules/pam_mkhomedir/tst-pam_mkhomedir-retval.c
index 282c5cd0..0d7b0a4b 100644
--- a/modules/pam_mkhomedir/tst-pam_mkhomedir-retval.c
+++ b/modules/pam_mkhomedir/tst-pam_mkhomedir-retval.c
@@ -5,6 +5,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <fcntl.h>
#include <limits.h>
@@ -30,9 +31,10 @@ main(void)
FILE *fp;
struct passwd *pw;
struct stat st;
- char cwd[PATH_MAX];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
/* PAM_USER_UNKNOWN */
ASSERT_NE(NULL, fp = fopen(service_file, "w"));
@@ -106,5 +108,7 @@ main(void)
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_namespace/pam_namespace.c b/modules/pam_namespace/pam_namespace.c
index 4b62700d..b0bc138b 100644
--- a/modules/pam_namespace/pam_namespace.c
+++ b/modules/pam_namespace/pam_namespace.c
@@ -1778,9 +1778,10 @@ cleanup:
static int cwd_in(char *dir, struct instance_data *idata)
{
int retval = 0;
- char cwd[PATH_MAX];
+ char *cwd;
- if (getcwd(cwd, PATH_MAX) == NULL) {
+ cwd = xgetcwd();
+ if (cwd == NULL) {
pam_syslog(idata->pamh, LOG_ERR, "Can't get current dir, %m");
return -1;
}
@@ -1794,6 +1795,7 @@ static int cwd_in(char *dir, struct instance_data *idata)
pam_syslog(idata->pamh, LOG_DEBUG, "cwd is outside %s", dir);
}
+ free(cwd);
return retval;
}
diff --git a/modules/pam_nologin/tst-pam_nologin-retval.c b/modules/pam_nologin/tst-pam_nologin-retval.c
index 4d44a380..5ecbc073 100644
--- a/modules/pam_nologin/tst-pam_nologin-retval.c
+++ b/modules/pam_nologin/tst-pam_nologin-retval.c
@@ -5,6 +5,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <limits.h>
#include <stdio.h>
@@ -28,9 +29,10 @@ main(void)
pam_handle_t *pamh = NULL;
FILE *fp;
struct passwd *pw;
- char cwd[PATH_MAX];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
/* PAM_IGNORE -> PAM_PERM_DENIED */
ASSERT_NE(NULL, fp = fopen(service_file, "w"));
@@ -222,5 +224,7 @@ main(void)
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_permit/tst-pam_permit-retval.c b/modules/pam_permit/tst-pam_permit-retval.c
index aacdedba..7d8116bc 100644
--- a/modules/pam_permit/tst-pam_permit-retval.c
+++ b/modules/pam_permit/tst-pam_permit-retval.c
@@ -5,6 +5,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <limits.h>
#include <stdio.h>
@@ -24,9 +25,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
- char cwd[PATH_MAX];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
ASSERT_NE(NULL, fp = fopen(service_file, "w"));
ASSERT_LT(0, fprintf(fp, "#%%PAM-1.0\n"
@@ -83,5 +85,7 @@ main(void)
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_pwhistory/tst-pam_pwhistory-retval.c b/modules/pam_pwhistory/tst-pam_pwhistory-retval.c
index aa2c24e8..24546580 100644
--- a/modules/pam_pwhistory/tst-pam_pwhistory-retval.c
+++ b/modules/pam_pwhistory/tst-pam_pwhistory-retval.c
@@ -5,6 +5,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <limits.h>
#include <stdio.h>
@@ -23,9 +24,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
- char cwd[PATH_MAX];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
/* PAM_USER_UNKNOWN */
ASSERT_NE(NULL, fp = fopen(service_file, "w"));
@@ -56,5 +58,7 @@ main(void)
/* cleanup */
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_rootok/tst-pam_rootok-retval.c b/modules/pam_rootok/tst-pam_rootok-retval.c
index 990ee126..ba8ac28f 100644
--- a/modules/pam_rootok/tst-pam_rootok-retval.c
+++ b/modules/pam_rootok/tst-pam_rootok-retval.c
@@ -5,6 +5,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <limits.h>
#include <stdio.h>
@@ -24,9 +25,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
- char cwd[PATH_MAX];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
ASSERT_NE(NULL, fp = fopen(service_file, "w"));
ASSERT_LT(0, fprintf(fp, "#%%PAM-1.0\n"
@@ -68,5 +70,7 @@ main(void)
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_sepermit/tst-pam_sepermit-retval.c b/modules/pam_sepermit/tst-pam_sepermit-retval.c
index 4132f286..21ebaba2 100644
--- a/modules/pam_sepermit/tst-pam_sepermit-retval.c
+++ b/modules/pam_sepermit/tst-pam_sepermit-retval.c
@@ -5,6 +5,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <limits.h>
#include <stdio.h>
@@ -25,9 +26,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
- char cwd[PATH_MAX];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
/* PAM_USER_UNKNOWN */
ASSERT_NE(NULL, fp = fopen(service_file, "w"));
@@ -154,5 +156,7 @@ main(void)
ASSERT_EQ(0, unlink(config_file));
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_succeed_if/tst-pam_succeed_if-retval.c b/modules/pam_succeed_if/tst-pam_succeed_if-retval.c
index f665040b..37f5d634 100644
--- a/modules/pam_succeed_if/tst-pam_succeed_if-retval.c
+++ b/modules/pam_succeed_if/tst-pam_succeed_if-retval.c
@@ -6,6 +6,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <limits.h>
#include <stdio.h>
@@ -25,9 +26,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
- char cwd[PATH_MAX];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
ASSERT_NE(NULL, fp = fopen(service_file, "w"));
ASSERT_LT(0, fprintf(fp, "#%%PAM-1.0\n"
@@ -83,5 +85,7 @@ main(void)
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_time/tst-pam_time-retval.c b/modules/pam_time/tst-pam_time-retval.c
index 3fcf4591..22544f35 100644
--- a/modules/pam_time/tst-pam_time-retval.c
+++ b/modules/pam_time/tst-pam_time-retval.c
@@ -6,6 +6,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <limits.h>
#include <stdio.h>
@@ -25,9 +26,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
- char cwd[PATH_MAX];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
/* PAM_USER_UNKNOWN */
ASSERT_NE(NULL, fp = fopen(service_file, "w"));
@@ -103,5 +105,7 @@ main(void)
ASSERT_EQ(0, unlink(config_file));
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/modules/pam_warn/tst-pam_warn-retval.c b/modules/pam_warn/tst-pam_warn-retval.c
index 48b1f311..c34c609f 100644
--- a/modules/pam_warn/tst-pam_warn-retval.c
+++ b/modules/pam_warn/tst-pam_warn-retval.c
@@ -5,6 +5,7 @@
*/
#include "test_assert.h"
+#include "pam_inline.h"
#include <limits.h>
#include <stdio.h>
@@ -24,9 +25,10 @@ main(void)
{
pam_handle_t *pamh = NULL;
FILE *fp;
- char cwd[PATH_MAX];
+ char *cwd;
- ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+ cwd = xgetcwd();
+ ASSERT_NE(NULL, cwd);
/* PAM_IGNORE -> PAM_PERM_DENIED */
ASSERT_NE(NULL, fp = fopen(service_file, "w"));
@@ -84,5 +86,7 @@ main(void)
ASSERT_EQ(0, unlink(service_file));
+ free(cwd);
+
return 0;
}
diff --git a/tests/tst-dlopen.c b/tests/tst-dlopen.c
index cba3e9a8..d62a3878 100644
--- a/tests/tst-dlopen.c
+++ b/tests/tst-dlopen.c
@@ -11,32 +11,35 @@
#include <dlfcn.h>
#include <stdio.h>
+#include <stdlib.h>
#include <limits.h>
+#include <string.h>
#include <sys/stat.h>
-#ifndef PATH_MAX
-# define PATH_MAX 4096
-#endif
-
/* Simple program to see if dlopen() would succeed. */
int main(int argc, char **argv)
{
int i;
struct stat st;
- char buf[PATH_MAX];
+ char *buf;
+ int buf_size;
for (i = 1; i < argc; i++) {
if (dlopen(argv[i], RTLD_NOW)) {
fprintf(stdout, "dlopen() of \"%s\" succeeded.\n",
argv[i]);
} else {
- snprintf(buf, sizeof(buf), "./%s", argv[i]);
+ buf_size = 3 + strlen(argv[i]);
+ buf = malloc(buf_size);
+ snprintf(buf, sizeof(buf_size), "./%s", argv[i]);
if ((stat(buf, &st) == 0) && dlopen(buf, RTLD_NOW)) {
fprintf(stdout, "dlopen() of \"./%s\" "
"succeeded.\n", argv[i]);
+ free(buf);
} else {
fprintf(stdout, "dlopen() of \"%s\" failed: "
"%s\n", argv[i], dlerror());
+ free(buf);
return 1;
}
}