From 4310d6e4d305d93a63d64b59bd5763d3215abd54 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Thu, 1 Sep 2005 01:07:41 +0000 Subject: [PATCH] STABLE14-windows-cell-expiration-20050831 When updating cell information from DNS, be sure to set a new timeout. When obtaining cell information from a file, check every two hours to see if it changed. (cherry picked from commit 27b81213dfffc5c4d8979f1cc381084d924ea8e1) --- src/WINNT/afsd/cm_cell.c | 23 ++-- src/WINNT/afsd/cm_config.c | 212 +++++++++++++++++++++---------------- src/WINNT/afsd/cm_volume.c | 8 +- 3 files changed, 142 insertions(+), 101 deletions(-) diff --git a/src/WINNT/afsd/cm_cell.c b/src/WINNT/afsd/cm_cell.c index 58a9acb09..3c8eef86e 100644 --- a/src/WINNT/afsd/cm_cell.c +++ b/src/WINNT/afsd/cm_cell.c @@ -70,10 +70,10 @@ cm_cell_t *cm_UpdateCell(cm_cell_t * cp) #ifdef AFS_FREELANCE_CLIENT && !(cp->flags & CM_CELLFLAG_FREELANCE) #endif - ) + ) || (time(0) > cp->timeout) #ifdef AFS_AFSDB_ENV || (cm_dnsEnabled && (cp->flags & CM_CELLFLAG_DNS) && - ((cp->flags & CM_CELLFLAG_VLSERVER_INVALID) || (time(0) > cp->timeout))) + ((cp->flags & CM_CELLFLAG_VLSERVER_INVALID))) #endif ) { /* must empty cp->vlServersp */ @@ -92,6 +92,7 @@ cm_cell_t *cm_UpdateCell(cm_cell_t * cp) if (code == 0) { /* got cell from DNS */ cp->flags |= CM_CELLFLAG_DNS; cp->flags &= ~CM_CELLFLAG_VLSERVER_INVALID; + cp->timeout = time(0) + ttl; #ifdef DEBUG fprintf(stderr, "cell %s: ttl=%d\n", cp->name, ttl); #endif @@ -107,9 +108,10 @@ cm_cell_t *cm_UpdateCell(cm_cell_t * cp) { cp = NULL; /* return NULL to indicate failure */ } - } + } else { + cp->timeout = time(0) + 7200; + } } - return cp; } @@ -169,13 +171,16 @@ cm_cell_t *cm_GetCell_Gen(char *namep, char *newnamep, long flags) cp->flags &= ~CM_CELLFLAG_VLSERVER_INVALID; cp->timeout = time(0) + ttl; } - } else + } else { #endif - { cp = NULL; goto done; - } - } +#ifdef AFS_AFSDB_ENV + } +#endif + } else { + cp->timeout = time(0) + 7200; /* two hour timeout */ + } /* randomise among those vlservers having the same rank*/ cm_RandomizeServer(&cp->vlServersp); @@ -207,8 +212,6 @@ cm_cell_t *cm_GetCell_Gen(char *namep, char *newnamep, long flags) cm_cell_t *cm_FindCellByID(long cellID) { cm_cell_t *cp; - int ttl; - int code; lock_ObtainWrite(&cm_cellLock); for (cp = cm_data.allCellsp; cp; cp=cp->nextp) { diff --git a/src/WINNT/afsd/cm_config.c b/src/WINNT/afsd/cm_config.c index 3d71d37fd..c7df6db68 100644 --- a/src/WINNT/afsd/cm_config.c +++ b/src/WINNT/afsd/cm_config.c @@ -125,57 +125,81 @@ BOOL WINAPI DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved) static long cm_ParsePair(char *lineBufferp, char *leftp, char *rightp) { - char *tp; + char *tp; char tc; int sawEquals; - int sawBracket; + int sawBracket; sawEquals = 0; - sawBracket = 0; + sawBracket = 0; for(tp = lineBufferp; *tp; tp++) { tc = *tp; - if (sawBracket) { - if (tc == ']') - sawBracket = 0; - continue; - } + if (sawBracket) { + if (tc == ']') + sawBracket = 0; + continue; + } - /* comment or line end */ + /* comment or line end */ if (tc == '#' || tc == '\r' || tc == '\n') break; - /* square bracket comment -- look for closing delim */ - if (tc == '[') { + /* square bracket comment -- look for closing delim */ + if (tc == '[') { sawBracket = 1; continue; - } + } - /* space or tab */ + /* space or tab */ if (tc == ' ' || tc == '\t') continue; if (tc == '=') { sawEquals = 1; continue; - } - + } + /* now we have a real character, put it in the appropriate bucket */ if (sawEquals == 0) { - *leftp++ = tc; - } - else { - *rightp++ = tc; + *leftp++ = tc; + } + else { + *rightp++ = tc; } } - /* null terminate the strings */ - *leftp = 0; + /* null terminate the strings */ + *leftp = 0; *rightp = 0; return 0; /* and return success */ } +static int +IsWindowsModule(const char * name) +{ + char * p; + int i; + + /* Do not perform searches for probable Windows modules */ + for (p = name, i=0; *p; p++) { + if ( *p == '.' ) + i++; + } + p = strrchr(name, '.'); + if (p) { + if (i == 1 && + (!stricmp(p,".dll") || + !stricmp(p,".exe") || + !stricmp(p,".ini") || + !stricmp(p,".db") || + !stricmp(p,".drv"))) + return 1; + } + return 0; +} + /* search for a cell, and either return an error code if we don't find it, * or return 0 if we do, in which case we also fill in the addresses in * the cellp field. @@ -198,12 +222,15 @@ long cm_SearchCellFile(char *cellNamep, char *newCellNamep, int inRightCell; int foundCell = 0; long code; - int tracking = 1, partial = 0; + int tracking = 1, partial = 0; #if defined(DJGPP) || defined(AFS_WIN95_ENV) char *afsconf_path; DWORD dwSize; #endif + if ( IsWindowsModule(cellNamep) ) + return -3; + cm_GetCellServDB(wdir); tfilep = fopen(wdir, "r"); @@ -226,7 +253,8 @@ long cm_SearchCellFile(char *cellNamep, char *newCellNamep, strcat(wdir, AFS_CELLSERVDB); /*fprintf(stderr, "opening cellservdb file %s\n", wdir);*/ tfilep = fopen(wdir, "r"); - if (!tfilep) return -2; + if (!tfilep) + return -2; } #else /* If we are NT or higher, we don't do DJGPP, So just fail */ @@ -234,40 +262,40 @@ long cm_SearchCellFile(char *cellNamep, char *newCellNamep, return -2; #endif - bestp = fopen(wdir, "r"); + bestp = fopen(wdir, "r"); #ifdef DEBUG DebugEvent_local("AFS- cm_searchfile fopen", "Handle[%x], wdir[%s]", bestp, wdir); #endif - /* have we seen the cell line for the guy we're looking for? */ - inRightCell = 0; - while (1) { + /* have we seen the cell line for the guy we're looking for? */ + inRightCell = 0; + while (1) { tp = fgets(lineBuffer, sizeof(lineBuffer), tfilep); if (tracking) - (void) fgets(lineBuffer, sizeof(lineBuffer), bestp); - if (tp == NULL) { - if (feof(tfilep)) { - /* hit EOF */ - if (partial) { - /* - * found partial match earlier; - * now go back to it - */ - tempp = bestp; - bestp = tfilep; - tfilep = tempp; - inRightCell = 1; - partial = 0; - continue; - } - else { - fclose(tfilep); - fclose(bestp); - return (foundCell? 0 : -3); - } - } - } + (void) fgets(lineBuffer, sizeof(lineBuffer), bestp); + if ( tp == NULL) { + if (feof(tfilep)) { + /* hit EOF */ + if (partial) { + /* + * found partial match earlier; + * now go back to it + */ + tempp = bestp; + bestp = tfilep; + tfilep = tempp; + inRightCell = 1; + partial = 0; + continue; + } + else { + fclose(tfilep); + fclose(bestp); + return (foundCell? 0 : -3); + } + } + } /* turn trailing cr or lf into null */ tp = strchr(lineBuffer, '\r'); @@ -275,11 +303,11 @@ long cm_SearchCellFile(char *cellNamep, char *newCellNamep, tp = strchr(lineBuffer, '\n'); if (tp) *tp = 0; - /* skip blank lines */ + /* skip blank lines */ if (lineBuffer[0] == 0) continue; if (lineBuffer[0] == '>') { - /* trim off at white space or '#' chars */ + /* trim off at white space or '#' chars */ tp = strchr(lineBuffer, ' '); if (tp) *tp = 0; tp = strchr(lineBuffer, '\t'); @@ -287,54 +315,55 @@ long cm_SearchCellFile(char *cellNamep, char *newCellNamep, tp = strchr(lineBuffer, '#'); if (tp) *tp = 0; - /* now see if this is the right cell */ + /* now see if this is the right cell */ if (stricmp(lineBuffer+1, cellNamep) == 0) { - /* found the cell we're looking for */ - if (newCellNamep) - strcpy(newCellNamep, lineBuffer+1); + /* found the cell we're looking for */ + if (newCellNamep) + strcpy(newCellNamep, lineBuffer+1); inRightCell = 1; - tracking = 0; + tracking = 0; #ifdef DEBUG DebugEvent_local("AFS- cm_searchfile is cell", "inRightCell[%x], linebuffer[%s]", - inRightCell, lineBuffer); + inRightCell, lineBuffer); #endif - } - else if (strnicmp(lineBuffer+1, cellNamep, - strlen(cellNamep)) == 0) { - /* partial match */ - if (partial) { /* ambiguous */ - fclose(tfilep); - fclose(bestp); - return -5; - } - if (newCellNamep) - strcpy(newCellNamep, lineBuffer+1); - inRightCell = 0; - tracking = 0; - partial = 1; - } + } + else if (strnicmp(lineBuffer+1, cellNamep, + strlen(cellNamep)) == 0) { + /* partial match */ + if (partial) { /* ambiguous */ + fclose(tfilep); + fclose(bestp); + return -5; + } + if (newCellNamep) + strcpy(newCellNamep, lineBuffer+1); + inRightCell = 0; + tracking = 0; + partial = 1; + } else inRightCell = 0; } else { #if !defined(DJGPP) && !defined(AFS_WIN95_ENV) valuep = strchr(lineBuffer, '#'); - if (valuep == NULL) { - fclose(tfilep); - fclose(bestp); - return -4; - } + if (valuep == NULL) { + fclose(tfilep); + fclose(bestp); + return -4; + } valuep++; /* skip the "#" */ valuep += strspn(valuep, " \t"); /* skip SP & TAB */ /* strip spaces and tabs in the end. They should not be there according to CellServDB format - so do this just in case */ + * so do this just in case + */ while (valuep[strlen(valuep) - 1] == ' ' || valuep[strlen(valuep) - 1] == '\t') valuep[strlen(valuep) - 1] = '\0'; #endif /* !DJGPP */ - if (inRightCell) { + if (inRightCell) { #if !defined(DJGPP) && !defined(AFS_WIN95_ENV) - /* add the server to the VLDB list */ + /* add the server to the VLDB list */ WSASetLastError(0); thp = gethostbyname(valuep); #ifdef DEBUG @@ -346,25 +375,25 @@ long cm_SearchCellFile(char *cellNamep, char *newCellNamep, } #endif if (thp) { - memcpy(&vlSockAddr.sin_addr.s_addr, thp->h_addr, + memcpy(&vlSockAddr.sin_addr.s_addr, thp->h_addr, sizeof(long)); vlSockAddr.sin_family = AF_INET; /* sin_port supplied by connection code */ - if (procp) - (*procp)(rockp, &vlSockAddr, valuep); + if (procp) + (*procp)(rockp, &vlSockAddr, valuep); foundCell = 1; - } + } #else thp = 0; #endif /* !DJGPP */ if (!thp) { long ip_addr; - int c1, c2, c3, c4; - char aname[241] = ""; + int c1, c2, c3, c4; + char aname[241] = ""; /* Since there is no gethostbyname() data - * available we will read the IP address - * stored in the CellServDB file + * available we will read the IP address + * stored in the CellServDB file */ code = sscanf(lineBuffer, "%d.%d.%d.%d #%s", &c1, &c2, &c3, &c4, aname); @@ -403,6 +432,9 @@ long cm_SearchCellByDNS(char *cellNamep, char *newCellNamep, int *ttl, #ifdef DEBUG DebugEvent_local("AFS SearchCellDNS-","Doing search for [%s]", cellNamep); #endif + + if ( IsWindowsModule(cellNamep) ) + return -1; rc = getAFSServer(cellNamep, cellHostAddrs, cellHostNames, &numServers, ttl); if (rc == 0 && numServers > 0) { /* found the cell */ for (i = 0; i < numServers; i++) { @@ -420,7 +452,7 @@ long cm_SearchCellByDNS(char *cellNamep, char *newCellNamep, int *ttl, else return -1; /* not found */ #else - return -1; /* not found */ + return -1; /* not found */ #endif /* AFS_AFSDB_ENV */ } diff --git a/src/WINNT/afsd/cm_volume.c b/src/WINNT/afsd/cm_volume.c index 86de5c823..04e5553cb 100644 --- a/src/WINNT/afsd/cm_volume.c +++ b/src/WINNT/afsd/cm_volume.c @@ -168,11 +168,11 @@ long cm_UpdateVolume(struct cm_cell *cellp, cm_user_t *userp, cm_req_t *reqp, #endif { /* now we have volume structure locked and held; make RPC to fill it */ + osi_Log2(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s", volp->cellp->name, volp->namep); do { code = cm_ConnByMServers(cellp->vlServersp, userp, reqp, &connp); if (code) continue; - osi_Log1(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s", volp->namep); #ifdef MULTIHOMED code = VL_GetEntryByNameU(connp->callp, volp->namep, &uvldbEntry); type = 2; @@ -188,6 +188,12 @@ long cm_UpdateVolume(struct cm_cell *cellp, cm_user_t *userp, cm_req_t *reqp, } } while (cm_Analyze(connp, userp, reqp, NULL, NULL, cellp->vlServersp, NULL, code)); code = cm_MapVLRPCError(code, reqp); + if ( code ) + osi_Log3(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s FAILURE, code 0x%x", + volp->cellp->name, volp->namep, code); + else + osi_Log2(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s:%s SUCCESS", + volp->cellp->name, volp->namep); } if (code == 0) { afs_int32 flags; -- 2.39.5