Esempio n. 1
0
/*
 * cfg_HostPartitionTableEnumerate() -- Enumerate AFS partition table entries.
 *
 *     If the partition table is empty (or does not exist) then *tablePP
 *     is set to NULL and *nEntriesP is set to zero (0).
 *
 *     Partitions in table are not necessarily those being exported; a table
 *     entry may have been added or removed since the fileserver last started.
 */
int ADMINAPI
cfg_HostPartitionTableEnumerate(void *hostHandle,	/* host config handle */
				cfg_partitionEntry_t ** tablePP,	/* table */
				int *nEntriesP,	/* table entry count */
				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 (tablePP == NULL) {
	tst = ADMCFGVPTABLEPNULL;
    } else if (nEntriesP == NULL) {
	tst = ADMCFGVPTABLECOUNTPNULL;
    }

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

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

    /* enumerate the vice partition table */

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

	/* count table entries */

	if (vpt_Start(&vpiter)) {
	    /* ENOENT implies table does not exist (which is OK) */
	    if (errno != ENOENT) {
		if (errno == EACCES) {
		    tst = ADMNOPRIV;
		} else {
		    tst = ADMCFGVPTABLEREADFAILED;
		}
	    }
	} else {
	    while (!vpt_NextEntry(&vpiter, &vpentry)) {
		vpentryCountMax++;
	    }
	    if (errno != ENOENT) {
		tst = ADMCFGVPTABLEREADFAILED;
	    }
	    (void)vpt_Finish(&vpiter);
	}

	/* alloc storage for table entries; handle any entry count change */

	if (tst == 0) {
	    if (vpentryCountMax == 0) {
		*nEntriesP = 0;
		*tablePP = NULL;
	    } else {
		/* return a two-part table; first points into second */
		void *metaTablep;
		size_t metaTableSize;

		metaTableSize =
		    vpentryCountMax * (sizeof(cfg_partitionEntry_t) +
				       sizeof(struct vptab));

		if ((metaTablep = (void *)malloc(metaTableSize)) == NULL) {
		    tst = ADMNOMEM;
		} else {
		    int i;
		    cfg_partitionEntry_t *cpePart;
		    struct vptab *vptPart;
		    int vpentryCount = 0;

		    cpePart = (cfg_partitionEntry_t *) metaTablep;
		    vptPart = (struct vptab *)(&cpePart[vpentryCountMax]);

		    for (i = 0; i < vpentryCountMax; i++) {
			cpePart[i].partitionName = vptPart[i].vp_name;
			cpePart[i].deviceName = vptPart[i].vp_dev;
		    }

		    if (vpt_Start(&vpiter)) {
			/* ENOENT implies table does not exist (which is OK) */
			if (errno != ENOENT) {
			    if (errno == EACCES) {
				tst = ADMNOPRIV;
			    } else {
				tst = ADMCFGVPTABLEREADFAILED;
			    }
			}
		    } else {
			for (i = 0; i < vpentryCountMax; i++) {
			    if (vpt_NextEntry(&vpiter, &vptPart[i])) {
				break;
			    }
			}

			if (i < vpentryCountMax && errno != ENOENT) {
			    tst = ADMCFGVPTABLEREADFAILED;
			} else {
			    vpentryCount = i;
			}
			(void)vpt_Finish(&vpiter);
		    }

		    if (tst == 0) {
			*nEntriesP = vpentryCount;

			if (vpentryCount != 0) {
			    *tablePP = (cfg_partitionEntry_t *) metaTablep;
			} else {
			    *tablePP = NULL;
			    free(metaTablep);
			}
		    } else {
				free(metaTablep);
		    }
		}
	    }
	}
    }
#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;
}
Esempio n. 2
0
int
VAttachPartitions(void)
{
    struct DiskPartition64 *partP, *prevP, *nextP;
    struct vpt_iter iter;
    struct vptab entry;

    if (vpt_Start(&iter) < 0) {
	Log("No partitions to attach.\n");
	return 0;
    }

    while (0 == vpt_NextEntry(&iter, &entry)) {
	if (!VValidVPTEntry(&entry)) {
	    continue;
	}

	/* This test for duplicates relies on the fact that the method
	 * of storing the partition names in the NT registry means the same
	 * partition name will never appear twice in the list.
	 */
	for (partP = DiskPartitionList; partP; partP = partP->next) {
	    if (*partP->devName == *entry.vp_dev) {
		Log("Same drive (%s) used for both partition %s and partition %s, ignoring both.\n", entry.vp_dev, partP->name, entry.vp_name);
		partP->flags = PART_DUPLICATE;
		break;		/* Only one entry will ever be in this list. */
	    }
	}
	if (partP)
	    continue;		/* found a duplicate */

	if (VCheckPartition(entry.vp_dev) < 0)
	    continue;
	/* This test allows for manually inserting the FORCESALVAGE flag
	 * and thereby invoking the salvager. scandisk obviously won't be
	 * doing this for us.
	 */
	if (programType == fileServer) {
	    struct afs_stat status;
	    char salvpath[MAXPATHLEN];
	    strcpy(salvpath, entry.vp_dev);
	    strcat(salvpath, "\\FORCESALVAGE");
	    if (afs_stat(salvpath, &status) == 0) {
		Log("VAttachPartitions: Found %s; aborting\n", salvpath);
		exit(1);
	    }
	}
	VInitPartition(entry.vp_name, entry.vp_dev, *entry.vp_dev - 'A');
    }
    vpt_Finish(&iter);

    /* Run through partition list and clear out the dupes. */
    prevP = nextP = NULL;
    for (partP = DiskPartitionList; partP; partP = nextP) {
	nextP = partP->next;
	if (partP->flags == PART_DUPLICATE) {
	    if (prevP)
		prevP->next = partP->next;
	    else
		DiskPartitionList = partP->next;
	    free(partP);
	} else
	    prevP = partP;
    }

    return 0;
}
Esempio n. 3
0
/*
 * 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;
}