File pam_mount-2.20-ismountpoint.patch of Package pam_mount
diff -rub pam_mount-2.20.orig/config/pam_mount.conf.xml pam_mount-2.20.patch/config/pam_mount.conf.xml
--- pam_mount-2.20.orig/config/pam_mount.conf.xml 2023-08-17 23:28:38.000000000 +0930
+++ pam_mount-2.20.patch/config/pam_mount.conf.xml 2023-08-30 19:56:10.099765017 +0930
@@ -39,6 +39,9 @@
<!-- pam_mount parameters: Volume-related -->
<mkmountpoint enable="1" remove="true" />
+<!--
+<ismountpoint mountover="true" />
+-->
</pam_mount>
diff -rub pam_mount-2.20.orig/config/pam_mount.conf.xml.dtd pam_mount-2.20.patch/config/pam_mount.conf.xml.dtd
--- pam_mount-2.20.orig/config/pam_mount.conf.xml.dtd 2023-08-17 23:28:38.000000000 +0930
+++ pam_mount-2.20.patch/config/pam_mount.conf.xml.dtd 2023-08-30 19:56:10.099765017 +0930
@@ -1,9 +1,9 @@
<!ELEMENT pam_mount
(debug?,volume*,luserconf?,mntoptions*,
- path?,logout?,mkmountpoint?,fsck?,cifsmount?,
- smbmount?,smbumount?,ncpmount?,ncpumount?,fusemount?,
- fuseumount?,fd0ssh?,ofl?,umount?,
- lclmount?,cryptmount?,nfsmount?,pmvarrun?,
+ path?,logout?,mkmountpoint?,ismountpoint?,
+ fsck?,cifsmount?,smbmount?,smbumount?,ncpmount?,
+ ncpumount?,fusemount?,fuseumount?,fd0ssh?,ofl?,
+ umount?,lclmount?,cryptmount?,nfsmount?,pmvarrun?,
msg-authpw?,msg-sessionpw?)>
<!ELEMENT debug EMPTY>
<!ATTLIST debug
@@ -13,6 +13,10 @@
enable CDATA #IMPLIED
remove CDATA #IMPLIED
>
+<!ELEMENT ismountpoint EMPTY>
+<!ATTLIST ismountpoint
+ mountover CDATA #IMPLIED
+>
<!ATTLIST fsckloop
device CDATA #IMPLIED
>
diff -rub pam_mount-2.20.orig/doc/pam_mount.conf.5.in pam_mount-2.20.patch/doc/pam_mount.conf.5.in
--- pam_mount-2.20.orig/doc/pam_mount.conf.5.in 2023-08-17 23:28:38.000000000 +0930
+++ pam_mount-2.20.patch/doc/pam_mount.conf.5.in 2023-08-30 19:56:10.099765017 +0930
@@ -224,6 +224,12 @@
this way are retained after logout, but \fBremove\fP may be set to \fBtrue\fP
to remove the mountpoint again, \fIbut only\fP if it was automatically created
by pam_mount in the same session before.
+.TP
+\fB<ismountpoint mountover="true" />\fP
+Controls whether pam_mount will mount over an active mountpoint. If a
+mountpoint is already active, pam_mount can be instructed to mount over it
+using the \fBmountover\fP attribute. Normally, pam_mount will not mount over
+an active mountpoint.
.SS Auxiliary programs
.PP
Some mount programs need special default parameters to properly function. It is
diff -rub pam_mount-2.20.orig/src/mount.c pam_mount-2.20.patch/src/mount.c
--- pam_mount-2.20.orig/src/mount.c 2023-08-17 23:28:38.000000000 +0930
+++ pam_mount-2.20.patch/src/mount.c 2023-08-30 19:56:10.099765017 +0930
@@ -35,6 +35,7 @@
/* Functions */
static inline bool mkmountpoint(struct vol *, const char *);
+static inline bool ismountpoint(const char *);
//-----------------------------------------------------------------------------
/**
@@ -386,6 +387,46 @@
}
/**
+ * ismountpoint - determine if directory is already an active mountpoint
+ * @d: directory to check
+ *
+ * Checks to see if the directory already is an active mountpoint.
+ */
+static bool ismountpoint(const char *d)
+{
+ struct stat sb;
+ hxmc_t *dtmp;
+ char *last;
+ bool newdev = false;
+ dev_t device;
+ dev_t olddev = 0;
+
+ dtmp = HXmc_strinit(d);
+ if (dtmp == NULL || HXmc_strcat(&dtmp, "/") == NULL) {
+ l0g("HXmc_strinit: %s\n", strerror(errno));
+ HXmc_free(dtmp);
+ return true;
+ }
+ w4rn("%s: checking /\n", __func__);
+ if (stat("/", &sb) != 0)
+ return true;
+ olddev = sb.st_dev;
+ last = dtmp;
+ while ((last = strchr(last + 1, '/')) != NULL) {
+ *last = '\0';
+ w4rn("%s: checking %s\n", __func__, dtmp);
+ if (stat(dtmp, &sb) != 0)
+ return true;
+ device = sb.st_dev;
+ newdev = (device != olddev);
+ olddev = device;
+ *last = '/';
+ }
+ HXmc_free(dtmp);
+ return newdev;
+}
+
+/**
* do_unmount -
* @config: current config
* @vpt: volume descriptor
@@ -650,6 +691,11 @@
vpt->volume);
return 0;
}
+ if (!config->mountover && ismountpoint(vpt->mountpoint)) {
+ l0g("mount point %s is already an active mount point (pam_mount not "
+ "configured to mount over it)\n", vpt->mountpoint);
+ return 0;
+ }
if (config->command[vpt->type]->items == 0) {
l0g("proper mount command not defined in "
diff -rub pam_mount-2.20.orig/src/pam_mount.h pam_mount-2.20.patch/src/pam_mount.h
--- pam_mount-2.20.orig/src/pam_mount.h 2023-08-17 23:28:38.000000000 +0930
+++ pam_mount-2.20.patch/src/pam_mount.h 2023-08-30 19:56:10.099765017 +0930
@@ -101,7 +101,7 @@
/* user logging in */
char *user;
unsigned int debug;
- bool mkmntpoint, rmdir_mntpt;
+ bool mkmntpoint, rmdir_mntpt, mountover;
bool seen_mntoptions_require, seen_mntoptions_allow;
hxmc_t *luserconf;
struct HXdeque *command[_CMD_MAX];
diff -rub pam_mount-2.20.orig/src/rdconf1.c pam_mount-2.20.patch/src/rdconf1.c
--- pam_mount-2.20.orig/src/rdconf1.c 2023-08-17 23:28:38.000000000 +0930
+++ pam_mount-2.20.patch/src/rdconf1.c 2023-08-30 19:56:10.099765017 +0930
@@ -794,6 +794,16 @@
return NULL;
}
+static const char *rc_ismountpoint(xmlNode *node, struct config *config,
+ unsigned int command)
+{
+ char *s;
+ if ((s = xml_getprop(node, "mountover")) != NULL)
+ config->mountover = parse_bool(s);
+ free(s);
+ return NULL;
+}
+
static const char *rc_mntoptions(xmlNode *node, struct config *config,
unsigned int command)
{
@@ -1499,6 +1509,7 @@
{"logout", rc_logout, CMD_NONE},
{"luserconf", rc_luserconf, CMD_NONE},
{"mkmountpoint", rc_mkmountpoint, CMD_NONE},
+ {"ismountpoint", rc_ismountpoint, CMD_NONE},
{"mntoptions", rc_mntoptions, CMD_NONE},
{"msg-authpw", rc_string, CMDA_AUTHPW},
{"msg-sessionpw", rc_string, CMDA_SESSIONPW},