Windows: Parse Freelance entries and enforce trailing dot but no trailing ws

Make sure that there is a trailing dot and no trailing whitespace
for both Mount Point and Symlink entries read from the Freelance
registry key.

LICENSE MIT

Change-Id: I339d1bd2a8fc3e5f44362c65e872396adf64fdf6
Reviewed-on: http://gerrit.openafs.org/2555
Tested-by: Jeffrey Altman <jaltman@openafs.org>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
This commit is contained in:
Jeffrey Altman 2010-08-13 20:58:43 -04:00 committed by Jeffrey Altman
parent e8bb948db1
commit 5e8d0a7b5f

View File

@ -492,6 +492,57 @@ int cm_reInitLocalMountPoints() {
return 0; return 0;
} }
/*
* cm_enforceTrailingDot
*
* return 0 on failure, non-zero on success
*
*/
static int
cm_enforceTrailingDot(char * line, size_t cchLine, DWORD *pdwSize)
{
if (line[(*pdwSize)-1] == '\0' && line[(*pdwSize)-2] != '.') {
/* remove trailing whitespace */
while (isspace(line[(*pdwSize)-2])) {
line[(*pdwSize)-2] = '\0';
(*pdwSize)--;
}
if ((*pdwSize) >= cchLine) {
afsi_log("no room for trailing dot");
return 0;
}
line[(*pdwSize)-1] = '.';
line[(*pdwSize)] = '\0';
} else if (line[(*pdwSize)-1] != '\0' && line[(*pdwSize)-1] != '.') {
/* remove trailing whitespace */
while (isspace(line[(*pdwSize)-1])) {
line[(*pdwSize)-1] = '\0';
(*pdwSize)--;
}
if ((*pdwSize) >= cchLine) {
afsi_log("no room for trailing dot and nul");
return 0;
}
line[(*pdwSize)] = '.';
line[(*pdwSize)+1] = '\0';
} else if (line[(*pdwSize)-1] != '\0') {
/* remove trailing whitespace */
while (isspace(line[(*pdwSize)-1])) {
line[(*pdwSize)-1] = '\0';
(*pdwSize)--;
}
if ((*pdwSize) >= cchLine) {
afsi_log("no room for trailing nul");
return 0;
}
line[(*pdwSize)] = '\0';
}
return 1;
}
// yj: open up the registry and read all the local mount // yj: open up the registry and read all the local mount
// points that are stored there. Part of the initialization // points that are stored there. Part of the initialization
@ -600,12 +651,13 @@ long cm_InitLocalMountPoints() {
continue; continue;
} }
afsi_log("Mountpoint[%d] = %s",dwIndex, line); /* make sure there is a trailing dot and a nul terminator */
if (!cm_enforceTrailingDot(line, sizeof(line), &dwSize)) {
cm_noLocalMountPoints--;
continue;
}
/* find the trailing dot; null terminate after it */ afsi_log("Mountpoint[%d] = %s", dwIndex, line);
t2 = strrchr(line, '.');
if (t2)
*(t2+1) = '\0';
for ( t=line;*t;t++ ) { for ( t=line;*t;t++ ) {
if ( !isprint(*t) ) { if ( !isprint(*t) ) {
@ -657,12 +709,13 @@ long cm_InitLocalMountPoints() {
continue; continue;
} }
afsi_log("Symlink[%d] = %s",dwIndex, line); /* make sure there is a trailing dot and a nul terminator */
if (!cm_enforceTrailingDot(line, sizeof(line), &dwSize)) {
cm_noLocalMountPoints--;
continue;
}
/* find the trailing dot; null terminate after it */ afsi_log("Symlink[%d] = %s", dwIndex, line);
t2 = strrchr(line, '.');
if (t2)
*(t2+1) = '\0';
for ( t=line;*t;t++ ) { for ( t=line;*t;t++ ) {
if ( !isprint(*t) ) { if ( !isprint(*t) ) {