Skip to content

Commit 9d983ee

Browse files
authored
Merge pull request #5864 from nickanderson/CFE-4562/3.21.x
CFE-4494: Fixed CIFS mounts in filesystem table (3.21)
2 parents 373ab83 + 1b499ae commit 9d983ee

File tree

1 file changed

+44
-11
lines changed

1 file changed

+44
-11
lines changed

cf-agent/nfs.c

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -468,29 +468,62 @@ int VerifyInFstab(EvalContext *ctx, char *name, const Attributes *a, const Promi
468468
mountpt = name;
469469
fstype = a->mount.mount_type;
470470

471+
char device[CF_BUFSIZE];
472+
if (StringEqual(fstype, "cifs") || StringEqual(fstype, "panfs"))
473+
{
474+
NDEBUG_UNUSED int ret = snprintf(device, sizeof(device), "%s%s", host, rmountpt);
475+
assert(ret >= 0 && ret < CF_BUFSIZE);
476+
}
477+
else
478+
{
479+
NDEBUG_UNUSED int ret = snprintf(device, sizeof(device), "%s:%s", host, rmountpt);
480+
assert(ret >= 0 && ret < CF_BUFSIZE);
481+
}
482+
471483
#if defined(__QNX__) || defined(__QNXNTO__)
472-
snprintf(fstab, CF_BUFSIZE, "%s:%s \t %s %s\t%s 0 0", host, rmountpt, mountpt, fstype, opts);
484+
// QNX documents 4 fstab fields : https://www.qnx.com/developers/docs/7.1/index.html#com.qnx.doc.neutrino.utilities/topic/f/fstab.html
485+
// specialdevice mountpoint type mountoptions
486+
// TODO Remove DUMP and PASS options used here (unsupported)?
487+
NDEBUG_UNUSED int ret = snprintf(fstab, CF_BUFSIZE, "%s \t %s %s\t%s 0 0", device, mountpt, fstype, opts);
488+
assert(ret >= 0 && ret < CF_BUFSIZE);
473489
#elif defined(_CRAY)
474490
char fstype_upper[CF_BUFSIZE];
475491
strlcpy(fstype_upper, fstype, CF_BUFSIZE);
476492
ToUpperStrInplace(fstype_upper);
477493

478-
snprintf(fstab, CF_BUFSIZE, "%s:%s \t %s %s\t%s", host, rmountpt, mountpt, fstype_upper, opts);
494+
NDEBUG_UNUSED int ret = snprintf(fstab, CF_BUFSIZE, "%s \t %s %s\t%s", device, mountpt, fstype_upper, opts);
495+
assert(ret >= 0 && ret < CF_BUFSIZE);
479496
break;
480497
#elif defined(__hpux)
481-
snprintf(fstab, CF_BUFSIZE, "%s:%s %s \t %s \t %s 0 0", host, rmountpt, mountpt, fstype, opts);
498+
// HP-UX documents 7 fstab fields: https://nixdoc.net/man-pages/HP-UX/man4/fstab.4.html
499+
// deviceSpecialFile directory type options backupFrequency passNumber comment
500+
// TODO Bring promise comment in as the 7th comment field # promise comment (stripped of newlines)
501+
NDEBUG_UNUSED int ret = snprintf(fstab, CF_BUFSIZE, "%s %s \t %s \t %s 0 0", device, mountpt, fstype, opts);
502+
assert(ret >= 0 && ret < CF_BUFSIZE);
482503
#elif defined(_AIX)
483-
snprintf(fstab, CF_BUFSIZE,
484-
"%s:\n\tdev\t= %s\n\ttype\t= %s\n\tvfs\t= %s\n\tnodename\t= %s\n\tmount\t= true\n\toptions\t= %s\n\taccount\t= false\n",
485-
mountpt, rmountpt, fstype, fstype, host, opts);
504+
// AIX uses /etc/filesystems: https://www.ibm.com/docs/en/aix/7.2.0?topic=files-filesystems-file
505+
NDEBUG_UNUSED int ret = snprintf(fstab, CF_BUFSIZE,
506+
"%s:\n\tdev\t= %s\n\ttype\t= %s\n\tvfs\t= %s\n\tnodename\t= %s\n\tmount\t= true\n\toptions\t= %s\n\taccount\t= false\n",
507+
mountpt, rmountpt, fstype, fstype, host, opts);
508+
assert(ret >= 0 && ret < CF_BUFSIZE);
486509
#elif defined(__linux__)
487-
snprintf(fstab, CF_BUFSIZE, "%s:%s \t %s \t %s \t %s", host, rmountpt, mountpt, fstype, opts);
510+
NDEBUG_UNUSED int ret = snprintf(fstab, CF_BUFSIZE, "%s \t %s \t %s \t %s", device, mountpt, fstype, opts);
511+
assert(ret >= 0 && ret < CF_BUFSIZE);
488512
#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__APPLE__)
489-
snprintf(fstab, CF_BUFSIZE, "%s:%s \t %s \t %s \t %s 0 0", host, rmountpt, mountpt, fstype, opts);
513+
// BSDs document 6 fstab fields https://man.freebsd.org/cgi/man.cgi?fstab(5)
514+
// Device Mountpoint FStype Options Dump Pass
515+
NDEBUG_UNUSED int ret = snprintf(fstab, CF_BUFSIZE, "%s \t %s \t %s \t %s 0 0", device, mountpt, fstype, opts);
516+
assert(ret >= 0 && ret < CF_BUFSIZE);
490517
#elif defined(__sun) || defined(sco) || defined(__SCO_DS)
491-
snprintf(fstab, CF_BUFSIZE, "%s:%s - %s %s - yes %s", host, rmountpt, mountpt, fstype, opts);
518+
// SunOS uses /etc/fstab and documents 7 fields: https://docs.oracle.com/cd/E19455-01/805-6331/fsadm-59727/index.html
519+
// deviceToMount deviceToFsck mountPoint FStype fsckPass automount? mountOptions
520+
// - is used for deviceToFsck for read-only and network based file systems
521+
NDEBUG_UNUSED int ret = snprintf(fstab, CF_BUFSIZE, "%s - %s %s - yes %s", device, mountpt, fstype, opts);
522+
assert(ret >= 0 && ret < CF_BUFSIZE);
492523
#elif defined(__CYGWIN__)
493-
snprintf(fstab, CF_BUFSIZE, "/bin/mount %s:%s %s", host, rmountpt, mountpt);
524+
// https://cygwin.com/cygwin-ug-net/using.html#mount-table
525+
NDEBUG_UNUSED int ret = snprintf(fstab, CF_BUFSIZE, "/bin/mount %s %s", device, mountpt);
526+
assert(ret >= 0 && ret < CF_BUFSIZE);
494527
#else
495528
#error "Could not determine format of fstab entry on this platform."
496529
#endif
@@ -503,7 +536,7 @@ int VerifyInFstab(EvalContext *ctx, char *name, const Attributes *a, const Promi
503536
{
504537
AppendItem(&FSTABLIST, fstab, NULL);
505538
FSTAB_EDITS++;
506-
cfPS(ctx, LOG_LEVEL_INFO, PROMISE_RESULT_CHANGE, pp, a, "Adding file system '%s:%s' to '%s'", host, rmountpt,
539+
cfPS(ctx, LOG_LEVEL_INFO, PROMISE_RESULT_CHANGE, pp, a, "Adding file system entry '%s' to '%s'", fstab,
507540
VFSTAB[VSYSTEMHARDCLASS]);
508541
*result = PromiseResultUpdate(*result, PROMISE_RESULT_CHANGE);
509542
changes += 1;

0 commit comments

Comments
 (0)