コード例 #1
0
ファイル: read_refcount.cpp プロジェクト: 0xbadfca11/junk
int __cdecl wmain(int argc, PWSTR argv[])
{
	setlocale(LC_ALL, "");
	for (int i = 1; i < argc; i++)
	{
		_putws(argv[i]);
		ATL::CHandle h(CreateFileW(argv[i], 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, 0, nullptr));
		if (h == INVALID_HANDLE_VALUE)
		{
			pwerror();
			h.Detach();
			continue;
		}
		ULONG fs_flags;
		ATLENSURE(GetVolumeInformationByHandleW(h, nullptr, 0, nullptr, nullptr, &fs_flags, nullptr, 0));
		if (!(fs_flags & FILE_SUPPORTS_BLOCK_REFCOUNTING))
		{
			SetLastError(ERROR_NOT_CAPABLE);
			pwerror();
			continue;
		}
		puts("                 VCN           Contiguous   RefCount                  LCN");
		STARTING_VCN_INPUT_BUFFER Vcn = {};
		union
		{
			RETRIEVAL_POINTERS_AND_REFCOUNT_BUFFER refcount_buf;
			BYTE buf[offsetof(RETRIEVAL_POINTERS_AND_REFCOUNT_BUFFER, Extents) + sizeof(RETRIEVAL_POINTERS_AND_REFCOUNT_BUFFER::Extents) * 128];
		};
		ULONG junk;
		for (;;)
		{
			BOOL ret = DeviceIoControl(h, FSCTL_GET_RETRIEVAL_POINTERS_AND_REFCOUNT, &Vcn, sizeof Vcn, &refcount_buf, sizeof buf, &junk, nullptr);
			ULONG err = GetLastError();
			if (ret || err == ERROR_MORE_DATA)
			{
				printf(
					"% 20llu % 20llu % 10lu % 20llu\n",
					refcount_buf.StartingVcn.QuadPart,
					refcount_buf.Extents[0].NextVcn.QuadPart - refcount_buf.StartingVcn.QuadPart,
					refcount_buf.Extents[0].ReferenceCount,
					refcount_buf.Extents[0].Lcn.QuadPart
				);
				if (refcount_buf.ExtentCount > 1)
				{
					for (ULONG j = 1; j < refcount_buf.ExtentCount; j++)
					{
						printf(
							"% 20llu % 20llu % 10lu % 20llu\n",
							refcount_buf.Extents[j - 1].NextVcn.QuadPart,
							refcount_buf.Extents[j].NextVcn.QuadPart - refcount_buf.Extents[j - 1].NextVcn.QuadPart,
							refcount_buf.Extents[j].ReferenceCount,
							refcount_buf.Extents[j].Lcn.QuadPart
						);
					}
				}
				Vcn.StartingVcn = refcount_buf.Extents[refcount_buf.ExtentCount - 1].NextVcn;
			}
			else
			{
				if (err != ERROR_HANDLE_EOF)
				{
					pwerror();
				}
				break;
			}
		}
	}
}
コード例 #2
0
ファイル: yp_passwd.c プロジェクト: DragonQuan/minix3
static char *
getnewpasswd(struct passwd *pw, char **old_pass)
{
	int tries;
	const char *p, *t;
	char *result;
	static char buf[_PASSWORD_LEN + 1];
	char salt[_PASSWORD_LEN + 1];
	char option[LINE_MAX], *key, *opt;

	(void)printf("Changing NIS password for %s.\n", pw->pw_name);

	if (old_pass) {
		*old_pass = NULL;
	
		if (pw->pw_passwd[0]) {
			if (strcmp(crypt(p = getpass("Old password:"******"Sorry.\n");
				pwerror(NULL, 0, 1);
			}
		} else {
			p = "";
		}

		*old_pass = strdup(p);
		if (!*old_pass) {
			(void)printf("not enough core.\n");
			pwerror(NULL, 0, 1);
		}
	}
	for (buf[0] = '\0', tries = 0;;) {
		p = getpass("New password:"******"Password unchanged.\n");
			pwerror(NULL, 0, 0);
		}
		if (strlen(p) <= 5 && ++tries < 2) {
			(void)printf("Please enter a longer password.\n");
			continue;
		}
		for (t = p; *t && islower((unsigned char)*t); ++t);
		if (!*t && ++tries < 2) {
			(void)printf("Please don't use an all-lower case "
			    "password.\nUnusual capitalization, "
			    "control characters or digits are "
			    "suggested.\n");
			continue;
		}
		(void)strlcpy(buf, p, sizeof(buf));
		if (!strcmp(buf, getpass("Retype new password:"******"Mismatch; try again, EOF to quit.\n");
	}

	pw_getpwconf(option, sizeof(option), pw, "ypcipher");
	opt = option;
	key = strsep(&opt, ",");
	if (pw_gensalt(salt, _PASSWORD_LEN, key, opt) == -1) {
		warn("Couldn't generate salt");
		pwerror(NULL, 0, 0);
	}
	result = strdup(crypt(buf, salt));
	if (!result) {
		(void)printf("not enough core.\n");
		pwerror(NULL, 0, 0);
	}
	return result;
}