Exemplo n.º 1
0
BOOL fIsCellInCellServDB (LPCTSTR pszCell)
{
   BOOL fFound = FALSE;
   CELLSERVDB CellServDB;
   char cellname[256], i;

   /* we pray for all ascii cellnames */
   for ( i=0 ; pszCell[i] && i < (sizeof(cellname)-1) ; i++ )
       cellname[i] = pszCell[i];
   cellname[i] = '\0';

   ULONG code = cm_SearchCellRegistry(1, cellname, NULL, NULL, NULL, NULL);
   if (code == 0)
      fFound = TRUE;
   if (!fFound && 
       (code != CM_ERROR_FORCE_DNS_LOOKUP) && 
       CSDB_ReadFile (&CellServDB, NULL))
   {
       if (CSDB_FindCell (&CellServDB, pszCell))
           fFound = TRUE;
       CSDB_FreeFile (&CellServDB);
   }
   if ( fFound == FALSE ) {
       int ttl;
       fFound = !cm_SearchCellByDNS(cellname, NULL, &ttl, NULL, NULL);
   }
   done:

   return fFound;
}
Exemplo n.º 2
0
BOOL fIsCellInCellServDB (LPCTSTR pszCell)
{
   BOOL fFound = FALSE;
   CELLSERVDB CellServDB;

   if (CSDB_ReadFile (&CellServDB, NULL))
   {
       if (CSDB_FindCell (&CellServDB, pszCell))
           fFound = TRUE;
       CSDB_FreeFile (&CellServDB);
   }
#ifdef AFS_AFSDB_ENV
    if ( fFound == FALSE ) {
        int ttl;
        char cellname[128], i;

        /* we pray for all ascii cellnames */
        for ( i=0 ; pszCell[i] && i < (sizeof(cellname)-1) ; i++ )
            cellname[i] = pszCell[i];
        cellname[i] = '\0';

        fFound = !cm_SearchCellByDNS(cellname, NULL, &ttl, NULL, NULL);
    }
#endif
   return fFound;
}
Exemplo n.º 3
0
/*
 * ClientCellServDbUpdate() -- add or remove a client CellServDB entry.
 *
 *     Common function implementing cfg_ClientCellServDb{Add/Remove}().
 */
static int
ClientCellServDbUpdate(int updateOp, void *hostHandle, const char *cellName,
		       const char *dbentry, afs_status_p st)
{
    int rc = 1;
    afs_status_t tst2, tst = 0;
    cfg_host_p cfg_host = (cfg_host_p) hostHandle;
    char dbentryFull[MAXHOSTCHARS];

    /* validate parameters and resolve dbentry to fully qualified name */

    if (!cfgutil_HostHandleValidate(cfg_host, &tst2)) {
	tst = tst2;
    } else if (cellName == NULL || *cellName == '\0') {
	tst = ADMCFGCELLNAMENULL;
    } else if (strlen(cellName) > (MAXCELLCHARS - 1)) {
	tst = ADMCFGCELLNAMETOOLONG;
    } else if (dbentry == NULL || *dbentry == '\0') {
	tst = ADMCFGHOSTNAMENULL;
    } else if (strlen(dbentry) > (MAXHOSTCHARS - 1)) {
	tst = ADMCFGHOSTNAMETOOLONG;
    } else if (!cfgutil_HostNameGetFull(dbentry, dbentryFull, &tst2)) {
	tst = tst2;
    }

    /* remote configuration not yet supported in this function */

    if (tst == 0) {
	if (!cfg_host->is_local) {
	    tst = ADMCFGNOTSUPPORTED;
	}
    }

    /* modify local client CellServDB entry for specified cell */

#ifdef AFS_NT40_ENV
    if (tst == 0) {
	CELLSERVDB clientDb;

	if (!CSDB_ReadFile(&clientDb, AFSDIR_CLIENT_CELLSERVDB_FILEPATH)) {
	    tst = ADMCFGCLIENTCELLSERVDBNOTREAD;
	} else {
	    CELLDBLINE *cellLinep = CSDB_FindCell(&clientDb, cellName);
	    CELLDBLINE *serverLinep = NULL;
	    int serverLineCount = 0;

	    if (cellLinep != NULL) {
		/* found cellName, now find server to add/remove */
		CELLDBLINE *workingLinep;

		for (workingLinep = cellLinep->pNext; workingLinep != NULL;
		     workingLinep = workingLinep->pNext) {
		    CELLDBLINEINFO lineInfo;

		    if (!CSDB_CrackLine(&lineInfo, workingLinep->szLine)) {
			/* not a server (or cell) line; perhaps a comment */
			continue;
		    } else if (lineInfo.szCell[0] != '\0') {
			/* hit a new cell line */
			break;
		    } else {
			/* found a server line; check if is host of interest */
			short isValid;
			int dbentryAddr = ntohl(lineInfo.ipServer);

			serverLineCount++;

			if (!cfgutil_HostAddressIsValid
			    (dbentryFull, dbentryAddr, &isValid, &tst2)) {
			    tst = tst2;
			    break;
			} else if (isValid) {
			    /* found server of interest */
			    serverLinep = workingLinep;
			    break;
			}
		    }
		}
	    }

	    if (tst == 0) {
		if (updateOp == CSDB_OP_ADD && serverLinep == NULL) {
		    if (cellLinep == NULL) {
			cellLinep =
			    CSDB_AddCell(&clientDb, cellName, NULL, NULL);
		    }

		    if (cellLinep == NULL) {
			tst = ADMNOMEM;
		    } else if (serverLineCount >= MAXHOSTSPERCELL) {
			tst = ADMCFGCLIENTCELLSERVDBNOSPACE;
		    } else {
			const char *dbentryAddrStr;

			if (!cfgutil_HostNameGetAddressString
			    (dbentryFull, &dbentryAddrStr, &tst2)) {
			    tst = tst2;
			} else {
			    serverLinep =
				CSDB_AddCellServer(&clientDb, cellLinep,
						   dbentryAddrStr,
						   dbentryFull);
			    if (serverLinep == NULL) {
				tst = ADMNOMEM;
			    }
			}
		    }
		} else if (updateOp == CSDB_OP_REM && serverLinep != NULL) {
		    (void)CSDB_RemoveLine(&clientDb, serverLinep);
		}

		if (tst == 0) {
		    if (!CSDB_WriteFile(&clientDb)) {
			tst = ADMCFGCLIENTCELLSERVDBNOTWRITTEN;
		    }
		}
	    }

	    CSDB_FreeFile(&clientDb);
	}
    }
#else
    if (tst == 0) {
	/* function not yet implemented for Unix */
	tst = ADMCFGNOTSUPPORTED;
    }
#endif /* AFS_NT40_ENV */

    if (tst != 0) {
	/* indicate failure */
	rc = 0;
    }
    if (st != NULL) {
	*st = tst;
    }
    return rc;
}
Exemplo n.º 4
0
/*
 * cfg_ClientSetCell() -- Define default client cell for host.
 *
 *     The cellDbHosts argument is a multistring containing the names of
 *     the existing database servers already configured in the cell; this
 *     multistring list can be obtained via cfg_CellServDbEnumerate().
 *     If configuring the first server in a new cell then the cellDbHosts
 *     list contains only the name of that host.
 *
 *     Warning: client (cache-manager) should be stopped prior to setting cell.
 */
int ADMINAPI
cfg_ClientSetCell(void *hostHandle,	/* host config handle */
		  const char *cellName,	/* cell name */
		  const char *cellDbHosts,	/* cell database hosts */
		  afs_status_p st)
{				/* completion status */
    int rc = 1;
    afs_status_t tst2, tst = 0;
    cfg_host_p cfg_host = (cfg_host_p) hostHandle;

    /* validate parameters */

    if (!cfgutil_HostHandleValidate(cfg_host, &tst2)) {
	tst = tst2;
    } else if (cellName == NULL || *cellName == '\0') {
	tst = ADMCFGCELLNAMENULL;
    } else if (strlen(cellName) > (MAXCELLCHARS - 1)) {
	tst = ADMCFGCELLNAMETOOLONG;
    } else if (!cfgutil_HostHandleCellNameCompatible(cfg_host, cellName)) {
	tst = ADMCFGCELLNAMECONFLICT;
    } else if (cellDbHosts == NULL || *cellDbHosts == '\0') {
	tst = ADMCFGCELLDBHOSTSNULL;
    }

    /* remote configuration not yet supported in this function */

    if (tst == 0) {
	if (!cfg_host->is_local) {
	    tst = ADMCFGNOTSUPPORTED;
	}
    }

    /* define cell database hosts */

#ifdef AFS_NT40_ENV
    if (tst == 0) {
	CELLSERVDB clientDb;

	if (!CSDB_ReadFile(&clientDb, AFSDIR_CLIENT_CELLSERVDB_FILEPATH)) {
	    tst = ADMCFGCLIENTCELLSERVDBNOTREAD;
	} else {
	    CELLDBLINE *cellLinep = CSDB_FindCell(&clientDb, cellName);

	    if (cellLinep != NULL) {
		/* cell entry exists; remove host entries */
		if (!CSDB_RemoveCellServers(&clientDb, cellLinep)) {
		    /* should never happen */
		    tst = ADMCFGCLIENTCELLSERVDBEDITFAILED;
		}
	    } else {
		/* cell entry does not exist; add it */
		cellLinep = CSDB_AddCell(&clientDb, cellName, NULL, NULL);

		if (cellLinep == NULL) {
		    tst = ADMNOMEM;
		}
	    }

	    if (tst == 0) {
		/* add new host entries to cell */
		const char *dbHost = cellDbHosts;
		int dbHostCount = 0;

		while (*dbHost != '\0' && tst == 0) {
		    size_t dbHostLen = strlen(dbHost);
		    const char *dbHostAddrStr;

		    if (dbHostLen > (MAXHOSTCHARS - 1)) {
			tst = ADMCFGHOSTNAMETOOLONG;
		    } else if (dbHostCount >= MAXHOSTSPERCELL) {
			tst = ADMCFGCELLDBHOSTCOUNTTOOLARGE;
		    } else
			if (!cfgutil_HostNameGetAddressString
			    (dbHost, &dbHostAddrStr, &tst2)) {
			tst = tst2;
		    } else
			if (CSDB_AddCellServer
			    (&clientDb, cellLinep, dbHostAddrStr,
			     dbHost) == NULL) {
			tst = ADMNOMEM;
		    } else {
			dbHostCount++;
			dbHost += dbHostLen + 1;
		    }
		}

		if (tst == 0) {
		    /* edit successful; write CellServDB */
		    if (!CSDB_WriteFile(&clientDb)) {
			tst = ADMCFGCLIENTCELLSERVDBNOTWRITTEN;
		    }
		}
	    }

	    CSDB_FreeFile(&clientDb);
	}
    }
#else
    if (tst == 0) {
	/* function not yet implemented for Unix */
	tst = ADMCFGNOTSUPPORTED;
    }
#endif /* AFS_NT40_ENV */


    /* define default client cell */

#ifdef AFS_NT40_ENV
    if (tst == 0) {
	if (afssw_SetClientCellName(cellName)) {
	    /* failed to set cell name in registry (ThisCell equivalent) */
	    if (errno == EACCES) {
		tst = ADMNOPRIV;
	    } else {
		tst = ADMCFGCLIENTTHISCELLNOTWRITTEN;
	    }
	}
    }
#else
    if (tst == 0) {
	/* function not yet implemented for Unix */
	tst = ADMCFGNOTSUPPORTED;
    }
#endif /* AFS_NT40_ENV */


    /* help any underlying packages adjust to cell change */

    if (tst == 0) {
	int rc;

	if ((rc = ka_CellConfig(AFSDIR_CLIENT_ETC_DIRPATH)) != 0) {
	    tst = rc;
	}
    }

    if (tst != 0) {
	rc = 0;
    }
    if (st != NULL) {
	*st = tst;
    }
    return rc;
}