fs: add option to evaluate symlink or mtpt Currently, several fs subcommands for Windows offer an option (-literal) to evaluate symlink / mount point rather than the object it refers to. Provide the same option on Unix for fs_getfid. Change-Id: I55ab5f96d5b9e63efbe7e938647edba05a1787ed Reviewed-on: https://gerrit.openafs.org/14542 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: Benjamin Kaduk <kaduk@mit.edu>
fs: Trim trailing lsmount and flushmount path slashes Remove trailing slashes from paths given to `fs lsmount` and `fs flushmount`. This makes for a more pleasant user experience when shell tab completion is used to specify the paths. Thanks to Stephan Wiesand for pointing out this issue. Change-Id: I756c4d7d9b3fe5cd41e02165caf1d6866a0210e6 Reviewed-on: https://gerrit.openafs.org/14779 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
fs: Avoid unnecessary cell DNS lookups Currently, many routines in 'fs' cause afsconf_GetCellInfo to be called for the given cell, which causes an AFSDB/SRV lookup for the given cell if the cell has no dbservers specified in the local CellServDB. Sites often define such CellServDB records to indicate that the given cell exists, but the dbserver IPs should only be looked up via DNS. However, 'fs' is only calling afsconf_GetCellInfo in order to canonicalize the cell name (we're allowed to give an abbreviated name for a cell on the command line if the abbreviation is unambiguous, but we want to give the full name to the kernel). We don't care about the other cell info at all, so triggering a DNS lookup is completely unnecessary. If our DNS server is not responding, e.g. because we've lost network access entirely, this causes the relevant 'fs' commands to fail, possibly after a long delay. Some fs commands such as 'fs setcell' are often run during client startup, and can still otherwise run fine without network access, and so such failures are unnecessary. To fix this, we introduce a new function, called afsconf_GetCellName, which only returns the full name for a cell, and does not require a DNS lookup for such "empty" cells in the local CellServDB. For all code paths in 'fs' that just need the cell name (which is all of them besides 'fs mkmount'), use this new function. Change-Id: I45eb1bdc6ba3e3b4653be2306dcbf79c1015724c Reviewed-on: https://gerrit.openafs.org/13540 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Remove dead code There is a perhaps-surprisingly large amount of code disabled behind directives like '#if 0', '#ifdef notdef', and '#ifdef notyet'. At best, this code is clutter, and at worst some of it is confusing/outdated, and/or confusingly nested inside other preprocessor conditionals. Sometimes this disabled code shows up when grepping the tree, and causes a nuisance when refactoring related areas of code. Get rid of all of it. If anyone ever wants this code back, it can always be restored by reverting portions of this commit. Also delete some comments that clearly refer to the disabled code, and in some cases, adjust the adjacent comments to make sense accordingly. This commit doesn't touch any files in src/external/. Change-Id: If260a41257e8d107930bd3c177eddb8ab336f0d1 Reviewed-on: https://gerrit.openafs.org/13683 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: Benjamin Kaduk <kaduk@mit.edu>
venus: appease gcc8's -Wformat-string Interestingly, even before this commit, the buffer size was larger than what the kernel would accept. Since the kernel does its own length checking, it's simplest to just allow slightly larger requests here and have them fail later. Change-Id: I9ed636e4ad025240cb27b3cc066a8f2a72959396 Reviewed-on: https://gerrit.openafs.org/13471 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
venus: fix memory leak In GetPrefCmd, when we request server prefs from the kernel and our output buffer is not big enough, pioctl() will return E2BIG and we allocate more memory and try again. However, if the size of the output buffer reaches 16k bytes and this space is still not enough (or if pioctl fails and errno != E2BIG), we return without releasing the memory that was previously allocated. To fix this problem, free our output buffer when this happens. Change-Id: Ib34cb12629528ddf2a763386f0ac5494eb8be695 Reviewed-on: https://gerrit.openafs.org/12293 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
venus: convert fs.c to safer string functions Convert string handling to safer functions to avoid buffer overflows. Change-Id: Ibb4f18d78724d87a002e2b0458cba2cceee8670c Reviewed-on: https://gerrit.openafs.org/12923 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
venus: fix format overflow warning Recent versions of gcc generate a format overflow warning on the dfstring buffer in fs.c. Increase the size of the buffer to avoid a possible buffer overflow. fs.c: In function ‘AclToString’: fs.c:770:30: error: ‘%s’ directive writing up to 1024 bytes into a region of size between 13 and 23 [-Werror=format-overflow=] sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell); ^~ fs.c:770:2: note: ‘sprintf’ output between 8 and 1042 bytes into a destination of size 30 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Change-Id: Iead8b153a62f2928fabaeee1ed126535f67d7d49 Reviewed-on: https://gerrit.openafs.org/12917 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
venus: fix memory leak The fs getserverprefs command displays preference ranks for file / volume location server machine interfaces. In order to get the complete set of preference ranks, the VIOC_GETSPREFS system call might have to be called several times. If so, the memory previously allocated should be released. Change-Id: I8491117ead626e70aac40343923d52284f274efd Reviewed-on: https://gerrit.openafs.org/12315 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
cmd: avoid piggy-backing flags in the help string Remove the hack to piggy-back the hidden command option in the help string argument. Change-Id: Iedcb6b96e98b766e3ef2c87cd6e5d41874f2c0b7 Reviewed-on: http://gerrit.openafs.org/10982 Reviewed-by: D Brashear <shadow@your-file-system.com> Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil> Tested-by: BuildBot <buildbot@rampaginggeek.com>
cmd: add flags argument to create syntax function Add the flags argument to cmd_CreateSyntax() and update all callers. The flags argument will be used to set command options, such as CMD_HIDDEN. Change-Id: Ia51be9635f262516cb084d236a9e0756f608bf16 Reviewed-on: http://gerrit.openafs.org/11430 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
fs: display cell not available on ESRCH The cache manager pioctls abuse ESRCH to represent errors due to unavailable cell information. Give a more sensible error message to the user when a pioctl returns an ESRCH error, instead of "no such process", which is the conventional meaning of ESRCH. The new error message is consistent with the Windows implementation of fs. For example, on a host with a misconfigured ThisCell and/or CellServDB. $ fs wscell fs: No such process becomes: $ fs wscell fs: Cell name not recognized. Change-Id: Ibdcb0957118205b9540cae07b3cafa65c51ff497 Reviewed-on: http://gerrit.openafs.org/10824 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: D Brashear <shadow@your-file-system.com>
Fix scanf buffer overflows Fix potential buffer overflows caused by misuse of the scanf function in the fileserver and ptserver. Also fix similar issues in the client side fs command and libadmin library. Change-Id: Ia6a46981c50537da1673507c2bc777f96e43f95a (This change was applied to the 1.6 branch as a security fix for 1.6.2 as commit d1855f8e04; this commit brings the fix into master.) Reviewed-on: http://gerrit.openafs.org/9962 Reviewed-by: Derrick Brashear <shadow@your-file-system.com> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
fs: Fix improper use of readlink readlink returns a non-NUL terminated buffer. If we are going to terminate its response, we need to make sure that there's space to do so. So the length passed to readlink should be one less than the real length of the buffer. Caught by coverity (#985596) Change-Id: I47081877a54a7b3d99ab8e6ec52d4663acd2eeb6 Reviewed-on: http://gerrit.openafs.org/9328 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
fs: Catch pioctl failure in mkmount If the VIOC_FILE_CELL_NAME pioctl fails in fs mkmount, return an error to the caller, instead of ploughing on with potentially bad data. Caught by coverity (#988418) Change-Id: I68df5dd26d955db860dd016c76109f7d262bad17 Reviewed-on: http://gerrit.openafs.org/9267 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil> Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
fs: Remove redundant variable assignments Remove a number of redundant variable assignments that clang warns about. Caught by clang-analyzer Change-Id: I248e0e3a9f9241084436604532424d6e4b900e31 Reviewed-on: http://gerrit.openafs.org/9194 Reviewed-by: Derrick Brashear <shadow@your-file-system.com> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
fs: Free parent_dir later in lsmount and flushmount If lsmount or flushmount encounter an error, then they may include the contents of parent_dir in their error message. However, in both cases, this was freed a couple of lines earlier. Just move the free() later, so that the contents of this variable are still available. Caught by clang-analyzer Change-Id: Ideba52b7ba98f034baf923194007239a6cf0221f Reviewed-on: http://gerrit.openafs.org/9193 Reviewed-by: Derrick Brashear <shadow@your-file-system.com> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
libafs: fs flushall for unix cm Implement the fs flushall command on the unix cache manager to flush all volume data. Uses a new common pioctl code point VIOC_FLUSHALL (14), registered with the grand.central.org assigned numbers. Change-Id: I214d8c762573b308d79fa7122a91d48ddd403eb9 Reviewed-on: http://gerrit.openafs.org/7540 Reviewed-by: Derrick Brashear <shadow@your-file-system.com> Tested-by: BuildBot <buildbot@rampaginggeek.com>
afs: casting NULL is generally unnecessary Casting NULL shouldn't be necessary in most cases. Eliminate this in favor of shorter lines and consistency. Function pointers, variadic arguments should still be cast. Change-Id: Ibcd67378556e45c2b24f7aa85a4d73c72cd88e02 Reviewed-on: http://gerrit.openafs.org/8151 Reviewed-by: Garrett Wollman <wollman@csail.mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Don't cast returns from malloc() malloc() returns a (void *) on all of our current platforms. So, don't bother casting the return value before assigning it - it is unnecessary noise. Change-Id: Ie328ebd2d31160bf07b86b760fbb5ce7108a532d Reviewed-on: http://gerrit.openafs.org/7473 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Derrick Brashear <shadow@dementix.org>