add --prefix option: some fixes + fixed pwd.lock file location
This commit is contained in:
parent
54551c7d6e
commit
65b4f58703
@ -375,10 +375,11 @@ bool commonio_present (const struct commonio_db *db)
|
||||
|
||||
int commonio_lock_nowait (struct commonio_db *db, bool log)
|
||||
{
|
||||
char* file;
|
||||
char* lock;
|
||||
char* file = NULL;
|
||||
char* lock = NULL;
|
||||
size_t lock_file_len;
|
||||
size_t file_len;
|
||||
int err;
|
||||
|
||||
if (db->locked) {
|
||||
return 1;
|
||||
@ -386,26 +387,36 @@ int commonio_lock_nowait (struct commonio_db *db, bool log)
|
||||
file_len = strlen(db->filename) + 11;/* %lu max size */
|
||||
lock_file_len = strlen(db->filename) + 6; /* sizeof ".lock" */
|
||||
file = (char*)malloc(file_len);
|
||||
if(file == NULL) {
|
||||
err = ENOMEM;
|
||||
goto cleanup_ENOMEM;
|
||||
}
|
||||
lock = (char*)malloc(lock_file_len);
|
||||
if(lock == NULL) {
|
||||
err = ENOMEM;
|
||||
goto cleanup_ENOMEM;
|
||||
}
|
||||
snprintf (file, file_len, "%s.%lu",
|
||||
db->filename, (unsigned long) getpid ());
|
||||
snprintf (lock, lock_file_len, "%s.lock", db->filename);
|
||||
if (do_lock_file (file, lock, log) != 0) {
|
||||
db->locked = true;
|
||||
lock_count++;
|
||||
free(file);
|
||||
free(lock);
|
||||
return 1;
|
||||
err = 1;
|
||||
}
|
||||
free(file);
|
||||
free(lock);
|
||||
return 0;
|
||||
cleanup_ENOMEM:
|
||||
if(file)
|
||||
free(file);
|
||||
if(lock)
|
||||
free(lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
int commonio_lock (struct commonio_db *db)
|
||||
{
|
||||
#ifdef HAVE_LCKPWDF
|
||||
/*#ifdef HAVE_LCKPWDF*/ /* not compatible with prefix option*/
|
||||
#if 0
|
||||
/*
|
||||
* only if the system libc has a real lckpwdf() - the one from
|
||||
* lockpw.c calls us and would cause infinite recursion!
|
||||
|
@ -168,9 +168,8 @@ extern struct group *prefix_getgrnam(const char *name)
|
||||
fclose(fg);
|
||||
return grp;
|
||||
}
|
||||
else {
|
||||
return getgrnam(name);
|
||||
}
|
||||
|
||||
return getgrnam(name);
|
||||
}
|
||||
|
||||
extern struct group *prefix_getgrgid(gid_t gid)
|
||||
@ -189,9 +188,8 @@ extern struct group *prefix_getgrgid(gid_t gid)
|
||||
fclose(fg);
|
||||
return grp;
|
||||
}
|
||||
else {
|
||||
return getgrgid(gid);
|
||||
}
|
||||
|
||||
return getgrgid(gid);
|
||||
}
|
||||
|
||||
extern struct passwd *prefix_getpwuid(uid_t uid)
|
||||
|
@ -835,7 +835,7 @@ static int remove_mailbox (void)
|
||||
}
|
||||
|
||||
len = strlen (prefix) + strlen (maildir) + strlen (user_name) + 2;
|
||||
mailfile = alloca (len);
|
||||
mailfile = xmalloc (len);
|
||||
|
||||
if (prefix[0]) {
|
||||
(void) snprintf (mailfile, len, "%s/%s/%s",
|
||||
@ -852,6 +852,7 @@ static int remove_mailbox (void)
|
||||
fprintf (stderr,
|
||||
_("%s: %s mail spool (%s) not found\n"),
|
||||
Prog, user_name, mailfile);
|
||||
free(mailfile);
|
||||
return 0;
|
||||
} else {
|
||||
fprintf (stderr,
|
||||
@ -864,6 +865,7 @@ static int remove_mailbox (void)
|
||||
user_name, (unsigned int) user_id,
|
||||
SHADOW_AUDIT_FAILURE);
|
||||
#endif /* WITH_AUDIT */
|
||||
free(mailfile);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -892,6 +894,7 @@ static int remove_mailbox (void)
|
||||
SHADOW_AUDIT_SUCCESS);
|
||||
}
|
||||
#endif /* WITH_AUDIT */
|
||||
free(mailfile);
|
||||
return errors;
|
||||
}
|
||||
i = is_owner (user_id, mailfile);
|
||||
@ -908,8 +911,10 @@ static int remove_mailbox (void)
|
||||
user_name, (unsigned int) user_id,
|
||||
SHADOW_AUDIT_FAILURE);
|
||||
#endif /* WITH_AUDIT */
|
||||
free(mailfile);
|
||||
return 1;
|
||||
} else if (i == -1) {
|
||||
free(mailfile);
|
||||
return 0; /* mailbox doesn't exist */
|
||||
}
|
||||
if (unlink (mailfile) != 0) {
|
||||
@ -935,6 +940,7 @@ static int remove_mailbox (void)
|
||||
SHADOW_AUDIT_SUCCESS);
|
||||
}
|
||||
#endif /* WITH_AUDIT */
|
||||
free(mailfile);
|
||||
return errors;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user