aboutsummaryrefslogtreecommitdiff
path: root/modules/pam_faillock/faillock.c
diff options
context:
space:
mode:
Diffstat (limited to 'modules/pam_faillock/faillock.c')
-rw-r--r--modules/pam_faillock/faillock.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/modules/pam_faillock/faillock.c b/modules/pam_faillock/faillock.c
index 091f253a..92484747 100644
--- a/modules/pam_faillock/faillock.c
+++ b/modules/pam_faillock/faillock.c
@@ -36,42 +36,39 @@
#include "config.h"
#include <string.h>
+#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
-#include <sys/stat.h>
#include <fcntl.h>
#include <security/pam_modutil.h>
#include "faillock.h"
-#define ignore_return(x) if (1==((int)x)) {;}
+#define ignore_return(x) if (1==((int)(x))) {;}
int
open_tally (const char *dir, const char *user, uid_t uid, int create)
{
char *path;
int flags = O_RDWR;
- int fd;
+ int fd, r;
if (dir == NULL || strstr(user, "../") != NULL)
/* just a defensive programming as the user must be a
* valid user on the system anyway
*/
return -1;
- path = malloc(strlen(dir) + strlen(user) + 2);
- if (path == NULL)
+ if (*dir && dir[strlen(dir) - 1] != '/')
+ r = asprintf(&path, "%s/%s", dir, user);
+ else
+ r = asprintf(&path, "%s%s", dir, user);
+ if (r < 0)
return -1;
- strcpy(path, dir);
- if (*dir && dir[strlen(dir) - 1] != '/') {
- strcat(path, "/");
- }
- strcat(path, user);
-
if (create) {
flags |= O_CREAT;
if (access(dir, F_OK) != 0) {