changing silly rename scheme take 2
reverting patch 4d18cf9ce7.
it was wrong to append the timestamp to create a silly renamed name
because it was not a reproducable name.
instead, take an fh and md5(fh) then append as before.
This commit is contained in:
parent
7fe39f0a53
commit
92d3500bd2
4 changed files with 56 additions and 17 deletions
|
|
@ -815,7 +815,7 @@ static int handle_close(nfs41_upcall *upcall)
|
||||||
|
|
||||||
if (args->renamed) {
|
if (args->renamed) {
|
||||||
dprintf(1, "removing a renamed file %s\n", name->name);
|
dprintf(1, "removing a renamed file %s\n", name->name);
|
||||||
create_silly_rename(&state->path, name);
|
create_silly_rename(&state->path, &state->file.fh, name);
|
||||||
status = do_nfs41_close(state);
|
status = do_nfs41_close(state);
|
||||||
if (status)
|
if (status)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
||||||
|
|
@ -223,7 +223,7 @@ static int handle_nfs41_rename(setattr_upcall_args *args)
|
||||||
path_fh_init(&dst_dir, &dst_path);
|
path_fh_init(&dst_dir, &dst_path);
|
||||||
fh_copy(&dst_dir.fh, &state->parent.fh);
|
fh_copy(&dst_dir.fh, &state->parent.fh);
|
||||||
|
|
||||||
create_silly_rename(&dst_path, &dst_name);
|
create_silly_rename(&dst_path, &state->file.fh, &dst_name);
|
||||||
dprintf(1, "silly rename: %s -> %s\n", src_name->name, dst_name.name);
|
dprintf(1, "silly rename: %s -> %s\n", src_name->name, dst_name.name);
|
||||||
|
|
||||||
/* break any delegations and truncate before silly rename */
|
/* break any delegations and truncate before silly rename */
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
#include <strsafe.h>
|
#include <strsafe.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <wincrypt.h> /* for Crypt*() functions */
|
||||||
|
|
||||||
#include "daemon_debug.h"
|
#include "daemon_debug.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
@ -349,35 +350,72 @@ void path_fh_copy(
|
||||||
fh_copy(&dst->fh, &src->fh);
|
fh_copy(&dst->fh, &src->fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DWORD MAX_DWORD = 4294967295 -- max string for the timestamp */
|
|
||||||
int create_silly_rename(
|
int create_silly_rename(
|
||||||
IN nfs41_abs_path *path,
|
IN nfs41_abs_path *path,
|
||||||
|
IN const nfs41_fh *fh,
|
||||||
OUT nfs41_component *silly)
|
OUT nfs41_component *silly)
|
||||||
{
|
{
|
||||||
|
HCRYPTPROV context;
|
||||||
|
HCRYPTHASH hash;
|
||||||
|
PBYTE buffer;
|
||||||
|
DWORD length;
|
||||||
const char *end = path->path + NFS41_MAX_PATH_LEN;
|
const char *end = path->path + NFS41_MAX_PATH_LEN;
|
||||||
char name[NFS41_MAX_COMPONENT_LEN+1], *tmp, stime[13];
|
const unsigned short extra_len = 2 + 16; //md5 is 16
|
||||||
int status = NO_ERROR;
|
char name[NFS41_MAX_COMPONENT_LEN+1];
|
||||||
const DWORD ntime = GetTickCount();
|
unsigned char fhmd5[17] = { 0 };
|
||||||
|
char *tmp;
|
||||||
|
int status = NO_ERROR, i;
|
||||||
|
|
||||||
StringCchPrintf(stime, 13, "%u", ntime);
|
if (path->len + extra_len >= NFS41_MAX_PATH_LEN) {
|
||||||
if (path->len + 13 >= NFS41_MAX_PATH_LEN) {
|
|
||||||
status = ERROR_BUFFER_OVERFLOW;
|
status = ERROR_BUFFER_OVERFLOW;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set up the md5 hash generator */
|
||||||
|
if (!CryptAcquireContext(&context, NULL, NULL,
|
||||||
|
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
|
||||||
|
status = GetLastError();
|
||||||
|
eprintf("CryptAcquireContext() failed with %d\n", status);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
if (!CryptCreateHash(context, CALG_MD5, 0, 0, &hash)) {
|
||||||
|
status = GetLastError();
|
||||||
|
eprintf("CryptCreateHash() failed with %d\n", status);
|
||||||
|
goto out_context;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CryptHashData(hash, (const BYTE*)fh->fh, (DWORD)fh->len, 0)) {
|
||||||
|
status = GetLastError();
|
||||||
|
eprintf("CryptHashData() failed with %d\n", status);
|
||||||
|
goto out_hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* extract the hash buffer */
|
||||||
|
buffer = (PBYTE)fhmd5;
|
||||||
|
length = 16;
|
||||||
|
if (!CryptGetHashParam(hash, HP_HASHVAL, buffer, &length, 0)) {
|
||||||
|
status = GetLastError();
|
||||||
|
eprintf("CryptGetHashParam(val) failed with %d\n", status);
|
||||||
|
goto out_hash;
|
||||||
|
}
|
||||||
|
|
||||||
last_component(path->path, path->path + path->len, silly);
|
last_component(path->path, path->path + path->len, silly);
|
||||||
if (silly->len + 13 > NFS41_MAX_COMPONENT_LEN) {
|
|
||||||
status = ERROR_BUFFER_OVERFLOW;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringCchCopyNA(name, NFS41_MAX_COMPONENT_LEN+1, silly->name, silly->len);
|
StringCchCopyNA(name, NFS41_MAX_COMPONENT_LEN+1, silly->name, silly->len);
|
||||||
|
|
||||||
tmp = (char*)silly->name;
|
tmp = (char*)silly->name;
|
||||||
StringCchPrintf(tmp, end - tmp, ".%s.%s", name, stime);
|
StringCchPrintf(tmp, end - tmp, ".%s.", name);
|
||||||
|
tmp += silly->len + 2;
|
||||||
|
|
||||||
path->len = (unsigned short)strlen(path->path);
|
for (i = 0; i < 16; i++, tmp++)
|
||||||
silly->len = (unsigned short)strlen(silly->name);
|
StringCchPrintf(tmp, end - tmp, "%x", fhmd5[i]);
|
||||||
|
|
||||||
|
path->len = path->len + extra_len;
|
||||||
|
silly->len = silly->len + extra_len;
|
||||||
|
|
||||||
|
out_hash:
|
||||||
|
CryptDestroyHash(hash);
|
||||||
|
out_context:
|
||||||
|
CryptReleaseContext(context, 0);
|
||||||
out:
|
out:
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
@ -165,6 +165,7 @@ static __inline void nfstime_abs(
|
||||||
|
|
||||||
int create_silly_rename(
|
int create_silly_rename(
|
||||||
IN nfs41_abs_path *path,
|
IN nfs41_abs_path *path,
|
||||||
|
IN const nfs41_fh *fh,
|
||||||
OUT nfs41_component *silly);
|
OUT nfs41_component *silly);
|
||||||
|
|
||||||
bool_t multi_addr_find(
|
bool_t multi_addr_find(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue