コード例 #1
0
ファイル: cfgclient.c プロジェクト: bagdxk/openafs
/*
 * cfg_ClientQueryStatus() -- Query status of static client configuration
 *     on host, i.e., status of required configuration files, etc.
 *     Upon successful completion *configStP is set to the client
 *     configuration status, with a value of zero (0) indicating that
 *     the configuration is valid.
 *
 *     If client configuration is not valid then *cellNameP is set to NULL;
 *     otherwise, *cellNameP is an allocated buffer containing client cell.
 *
 *     If client software (cache-manager) is not installed then *versionP is
 *     undefined; otherwise *versionP is 34 for 3.4, 35 for 3.5, etc.
 *
 *     Note: Client configuration is checked even if the client software
 *           is not installed.  This is useful for tools that require
 *           client configuration information but NOT the actual
 *           client (cache-manager); for example, the AFS Server Manager.
 */
int ADMINAPI
cfg_ClientQueryStatus(const char *hostName,	/* name of host */
		      short *isInstalledP,	/* client software installed */
		      unsigned *versionP,	/* client software version */
		      afs_status_p configStP,	/* client config status */
		      char **cellNameP,	/* client's cell */
		      afs_status_p st)
{				/* completion status */
    int rc = 1;
    afs_status_t tst2, tst = 0;
    afs_status_t clientSt = 0;
    char *clientCellName = NULL;
    short cmInstalled = 0;
    unsigned cmVersion = 0;

    /* validate parameters */

    if (hostName == NULL || *hostName == '\0') {
	tst = ADMCFGHOSTNAMENULL;
    } else if (strlen(hostName) > (MAXHOSTCHARS - 1)) {
	tst = ADMCFGHOSTNAMETOOLONG;
    } else if (isInstalledP == NULL) {
	tst = ADMCFGINSTALLEDFLAGPNULL;
    } else if (versionP == NULL) {
	tst = ADMCFGVERSIONPNULL;
    } else if (configStP == NULL) {
	tst = ADMCFGCONFIGSTATUSPNULL;
    } else if (cellNameP == NULL) {
	tst = ADMCFGCELLNAMEPNULL;
    }

    /* remote configuration not yet supported; hostName must be local host */

    if (tst == 0) {
	short isLocal;

	if (!cfgutil_HostNameIsLocal(hostName, &isLocal, &tst2)) {
	    tst = tst2;
	} else if (!isLocal) {
	    tst = ADMCFGNOTSUPPORTED;
	}
    }

    /* determine if client software (CM) is installed and if so what version */

#ifdef AFS_NT40_ENV
    /* Windows - cache manager is a service */
    if (tst == 0) {
	DWORD svcState;

	if (!cfgutil_WindowsServiceQuery
	    (AFSREG_CLT_SVC_NAME, &svcState, &tst2)) {
	    /* CM not installed, or insufficient privilege to check */
	    if (tst2 == ADMNOPRIV) {
		tst = tst2;
	    } else {
		cmInstalled = 0;
	    }
	} else {
	    /* CM installed, get version */
	    unsigned major, minor, patch;

	    cmInstalled = 1;

	    if (afssw_GetClientVersion(&major, &minor, &patch)) {
		/* failed to retrieve version information */
		if (errno == EACCES) {
		    tst = ADMNOPRIV;
		} else {
		    tst = ADMCFGCLIENTVERSIONNOTREAD;
		}
	    } else {
		cmVersion = (major * 10) + minor;
	    }
	}
    }
#else
    if (tst == 0) {
	/* function not yet implemented for Unix */
	tst = ADMCFGNOTSUPPORTED;
    }
#endif /* AFS_NT40_ENV */


    /* check static client configuration; not necessary that client
     * software (CM) be installed for this information to be valid and useable.
     */

    if (tst == 0) {
	struct afsconf_dir *confdir;

	if ((confdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH)) == NULL) {
	    /* the client configuration appears to be missing/invalid */
	    clientSt = ADMCFGCLIENTBASICINFOINVALID;
	} else {
	    struct afsconf_entry *cellentry;

	    if (confdir->cellName == NULL || *confdir->cellName == '\0') {
		/* no cell set for client */
		clientSt = ADMCFGCLIENTNOTINCELL;
	    } else {
		for (cellentry = confdir->entries; cellentry != NULL;
		     cellentry = cellentry->next) {
		    if (!strcasecmp
			(confdir->cellName, cellentry->cellInfo.name)) {
			break;
		    }
		}

		if (cellentry == NULL) {
		    clientSt = ADMCFGCLIENTCELLNOTINDB;
		} else if (cellentry->cellInfo.numServers <= 0) {
		    clientSt = ADMCFGCLIENTCELLHASNODBENTRIES;
		}
	    }

	    if (tst == 0 && clientSt == 0) {
		/* everything looks good; malloc cell name buffer to return */
		clientCellName = strdup(cellentry->cellInfo.name);
		if (clientCellName == NULL)
		    tst = ADMNOMEM;
	    }

	    (void)afsconf_Close(confdir);
	}
    }

    /* return result of query */

    if (tst == 0) {
	/* return client status and cell name */
	*isInstalledP = cmInstalled;
	*versionP = cmVersion;
	*configStP = clientSt;

	if (clientSt == 0) {
	    *cellNameP = clientCellName;
	} else {
	    *cellNameP = NULL;
	}
    } else {
	/* indicate failure */
	rc = 0;

	/* free cell name if allocated before failure */
	if (clientCellName != NULL) {
	    free(clientCellName);
	}
    }
    if (st != NULL) {
	*st = tst;
    }
    return rc;
}
コード例 #2
0
ファイル: cfghost.c プロジェクト: maxendpoint/openafs_cvs
/*
 * cfg_HostInvalidate() -- Invalidate static server configuration on host.
 *
 *     Server configuration invalidated only if BOS server is not running.
 */
int ADMINAPI
cfg_HostInvalidate(void *hostHandle,	/* host config handle */
		   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;
    }

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

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

    /* make sure bosserver is not running on host */

#ifdef AFS_NT40_ENV
    /* Windows - bosserver is controlled via the BOS control service */
    if (tst == 0) {
	DWORD svcState;

	if (!cfgutil_WindowsServiceQuery
	    (AFSREG_SVR_SVC_NAME, &svcState, &tst2)) {
	    tst = tst2;
	} else if (svcState != SERVICE_STOPPED) {
	    tst = ADMCFGBOSSERVERACTIVE;
	}
    }
#else
    if (tst == 0) {
	/* function not yet implemented for Unix */
	tst = ADMCFGNOTSUPPORTED;
    }
#endif /* AFS_NT40_ENV */


    /* remove server state files */

    if (tst == 0) {
	int i;
	const char *cfgdir[3];

	cfgdir[0] = AFSDIR_SERVER_ETC_DIRPATH;
	cfgdir[1] = AFSDIR_SERVER_DB_DIRPATH;
	cfgdir[2] = AFSDIR_SERVER_LOCAL_DIRPATH;

	for (i = 0; i < 3 && tst == 0; i++) {
	    if (!cfgutil_CleanDirectory(cfgdir[i], &tst2)) {
		tst = tst2;
	    }
	}
    }

    /* remove all vice partition table entries */

#ifdef AFS_NT40_ENV
    if (tst == 0) {
	struct vpt_iter vpiter;
	struct vptab vpentry;

	/* note: ignore errors except from removal attempts */

	if (!vpt_Start(&vpiter)) {
	    while (!vpt_NextEntry(&vpiter, &vpentry)) {
		if (vpt_RemoveEntry(vpentry.vp_name)) {
		    /* ENOENT implies entry does not exist; consider removed */
		    if (errno != ENOENT) {
			if (errno == EACCES) {
			    tst = ADMNOPRIV;
			} else {
			    tst = ADMCFGVPTABLEWRITEFAILED;
			}
		    }
		}
	    }
	    (void)vpt_Finish(&vpiter);
	}
    }
#else
    /* function not yet implemented for unix */
    if (tst == 0) {
	tst = ADMCFGNOTSUPPORTED;
    }
#endif /* AFS_NT40_ENV */

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