Fix weird flock uses

Change-Id: If8593b8f8d6ef2f91a9ad9c3a0b9f0a02d52444d
This commit is contained in:
Lionel Sambuc 2015-10-29 01:49:45 +01:00
parent 6dc59ac7dc
commit 0a4059ee41
2 changed files with 42 additions and 0 deletions

View File

@ -443,7 +443,13 @@ md_lock(boolean l)
if (l) {
setegid(egid);
#if defined(__minix)
/* LSC: Minix flock implementation is a wrapper around fctl, which
* requires writeable fds for LOCK_EX to succeed. */
if ((fd = open(_PATH_SCOREFILE, O_RDWR)) < 1) {
#else
if ((fd = open(_PATH_SCOREFILE, O_RDONLY)) < 1) {
#endif /* defined(__minix) */
setegid(gid);
messagef(0, "cannot lock score file");
return;

View File

@ -381,7 +381,13 @@ creategid(char *group, int gid, const char *name)
warnx("Can't create group `%s': already exists", group);
return 0;
}
#if defined(__minix)
/* LSC: Minix flock implementation is a wrapper around fctl, which
* requires writeable fds for LOCK_EX to succeed. */
if ((from = fopen(_PATH_GROUP, "r+")) == NULL) {
#else
if ((from = fopen(_PATH_GROUP, "r")) == NULL) {
#endif /* defined(__minix) */
warn("Can't create group `%s': can't open `%s'", name,
_PATH_GROUP);
return 0;
@ -445,7 +451,13 @@ modify_gid(char *group, char *newent)
int fd;
int cc;
#if defined(__minix)
/* LSC: Minix flock implementation is a wrapper around fctl, which
* requires writeable fds for LOCK_EX to succeed. */
if ((from = fopen(_PATH_GROUP, "r+")) == NULL) {
#else
if ((from = fopen(_PATH_GROUP, "r")) == NULL) {
#endif /* defined(__minix) */
warn("Can't modify group `%s': can't open `%s'",
group, _PATH_GROUP);
return 0;
@ -568,7 +580,13 @@ append_group(char *user, int ngroups, const char **groups)
}
}
}
#if defined(__minix)
/* LSC: Minix flock implementation is a wrapper around fctl, which
* requires writeable fds for LOCK_EX to succeed. */
if ((from = fopen(_PATH_GROUP, "r+")) == NULL) {
#else
if ((from = fopen(_PATH_GROUP, "r")) == NULL) {
#endif /* defined(__minix) */
warn("Can't append group(s) for `%s': can't open `%s'",
user, _PATH_GROUP);
return 0;
@ -1083,7 +1101,13 @@ adduser(char *login_name, user_t *up)
login_name, up->u_class);
}
#endif
#if defined(__minix)
/* LSC: Minix flock implementation is a wrapper around fctl, which
* requires writeable fds for LOCK_EX to succeed. */
if ((masterfd = open(_PATH_MASTERPASSWD, O_RDWR)) < 0) {
#else
if ((masterfd = open(_PATH_MASTERPASSWD, O_RDONLY)) < 0) {
#endif /* defined(__minix) */
err(EXIT_FAILURE, "Can't add user `%s': can't open `%s'",
login_name, _PATH_MASTERPASSWD);
}
@ -1316,7 +1340,13 @@ rm_user_from_groups(char *login_name)
buf);
return 0;
}
#if defined(__minix)
/* LSC: Minix flock implementation is a wrapper around fctl, which
* requires writeable fds for LOCK_EX to succeed. */
if ((from = fopen(_PATH_GROUP, "r+")) == NULL) {
#else
if ((from = fopen(_PATH_GROUP, "r")) == NULL) {
#endif /* defined(__minix) */
warn("Can't remove user `%s' from `%s': can't open `%s'",
login_name, _PATH_GROUP, _PATH_GROUP);
return 0;
@ -1445,7 +1475,13 @@ moduser(char *login_name, char *newlogin, user_t *up, int allow_samba)
/* keep dir name in case we need it for '-m' */
homedir = pwp->pw_dir;
#if defined(__minix)
/* LSC: Minix flock implementation is a wrapper around fctl, which
* requires writeable fds for LOCK_EX to succeed. */
if ((masterfd = open(_PATH_MASTERPASSWD, O_RDWR)) < 0) {
#else
if ((masterfd = open(_PATH_MASTERPASSWD, O_RDONLY)) < 0) {
#endif /* defined(__minix) */
err(EXIT_FAILURE, "Can't modify user `%s': can't open `%s'",
login_name, _PATH_MASTERPASSWD);
}