1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

lib: Move extract_snapshot_token() to util_path.c

Make it available to replace clistr_is_previous_version_path() in
libsmb/

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke 2022-09-17 10:13:27 -07:00 committed by Jeremy Allison
parent f010801551
commit bfe07fda67
5 changed files with 86 additions and 84 deletions

View File

@ -454,18 +454,6 @@ Offset Data length.
#define NOTIFY_ACTION_REMOVED_STREAM 7
#define NOTIFY_ACTION_MODIFIED_STREAM 8
/*
* Timestamp format used in "previous versions":
* This is the windows-level format of the @GMT- token.
* It is a fixed format not to be confused with the
* format for the POSIX-Level token of the shadow_copy2
* VFS module that can be configured via the "shadow:format"
* configuration option but defaults to the same format.
* See the shadow_copy2 module.
*/
#define GMT_NAME_LEN 24 /* length of a @GMT- name */
#define GMT_FORMAT "@GMT-%Y.%m.%d-%H.%M.%S"
/* where to find the base of the SMB packet proper */
#define smb_base(buf) (((const char *)(buf))+4)

View File

@ -24,6 +24,7 @@
#include "replace.h"
#include <talloc.h>
#include "lib/util/samba_util.h"
#include "lib/util/debug.h"
#include "lib/util_path.h"
struct loadparm_substitution;
@ -204,3 +205,74 @@ char *canonicalize_absolute_path(TALLOC_CTX *ctx, const char *pathname_in)
*p++ = '\0';
return pathname;
}
static bool find_snapshot_token(
const char *filename,
const char **_start,
const char **_next_component,
NTTIME *twrp)
{
const char *start = NULL;
const char *end = NULL;
struct tm tm;
time_t t;
start = strstr_m(filename, "@GMT-");
if (start == NULL) {
return false;
}
if ((start > filename) && (start[-1] != '/')) {
/* the GMT-token does not start a path-component */
return false;
}
end = strptime(start, GMT_FORMAT, &tm);
if (end == NULL) {
/* Not a valid timestring. */
return false;
}
if ((end[0] != '\0') && (end[0] != '/')) {
/*
* It is not a complete path component, i.e. the path
* component continues after the gmt-token.
*/
return false;
}
tm.tm_isdst = -1;
t = timegm(&tm);
unix_to_nt_time(twrp, t);
DBG_DEBUG("Extracted @GMT-Timestamp %s\n",
nt_time_string(talloc_tos(), *twrp));
*_start = start;
if (end[0] == '/') {
end += 1;
}
*_next_component = end;
return true;
}
bool extract_snapshot_token(char *fname, NTTIME *twrp)
{
const char *start = NULL;
const char *next = NULL;
size_t remaining;
bool found;
found = find_snapshot_token(fname, &start, &next, twrp);
if (!found) {
return false;
}
remaining = strlen(next);
memmove(discard_const_p(char, start), next, remaining+1);
return true;
}

View File

@ -26,10 +26,24 @@
#include "replace.h"
#include <talloc.h>
#include "lib/util/time.h"
/*
* Timestamp format used in "previous versions":
* This is the windows-level format of the @GMT- token.
* It is a fixed format not to be confused with the
* format for the POSIX-Level token of the shadow_copy2
* VFS module that can be configured via the "shadow:format"
* configuration option but defaults to the same format.
* See the shadow_copy2 module.
*/
#define GMT_NAME_LEN 24 /* length of a @GMT- name */
#define GMT_FORMAT "@GMT-%Y.%m.%d-%H.%M.%S"
char *lock_path(TALLOC_CTX *mem_ctx, const char *name);
char *state_path(TALLOC_CTX *mem_ctx, const char *name);
char *cache_path(TALLOC_CTX *mem_ctx, const char *name);
char *canonicalize_absolute_path(TALLOC_CTX *ctx, const char *abs_path);
bool extract_snapshot_token(char *fname, NTTIME *twrp);
#endif

View File

@ -87,77 +87,6 @@ static bool mangled_equal(const char *name1,
return strequal(name1, mname);
}
static bool find_snapshot_token(
const char *filename,
const char **_start,
const char **_next_component,
NTTIME *twrp)
{
const char *start = NULL;
const char *end = NULL;
struct tm tm;
time_t t;
start = strstr_m(filename, "@GMT-");
if (start == NULL) {
return false;
}
if ((start > filename) && (start[-1] != '/')) {
/* the GMT-token does not start a path-component */
return false;
}
end = strptime(start, GMT_FORMAT, &tm);
if (end == NULL) {
/* Not a valid timestring. */
return false;
}
if ((end[0] != '\0') && (end[0] != '/')) {
/*
* It is not a complete path component, i.e. the path
* component continues after the gmt-token.
*/
return false;
}
tm.tm_isdst = -1;
t = timegm(&tm);
unix_to_nt_time(twrp, t);
DBG_DEBUG("Extracted @GMT-Timestamp %s\n",
nt_time_string(talloc_tos(), *twrp));
*_start = start;
if (end[0] == '/') {
end += 1;
}
*_next_component = end;
return true;
}
bool extract_snapshot_token(char *fname, NTTIME *twrp)
{
const char *start = NULL;
const char *next = NULL;
size_t remaining;
bool found;
found = find_snapshot_token(fname, &start, &next, twrp);
if (!found) {
return false;
}
remaining = strlen(next);
memmove(discard_const_p(char, start), next, remaining+1);
return true;
}
/*
* Strip a valid @GMT-token from any incoming filename path,
* adding any NTTIME encoded in the pathname into the

View File

@ -350,7 +350,6 @@ NTSTATUS sync_file(connection_struct *conn, files_struct *fsp, bool write_throug
uint32_t ucf_flags_from_smb_request(struct smb_request *req);
uint32_t filename_create_ucf_flags(struct smb_request *req, uint32_t create_disposition);
bool extract_snapshot_token(char *fname, NTTIME *twrp);
NTSTATUS canonicalize_snapshot_path(struct smb_filename *smb_fname,
uint32_t ucf_flags,
NTTIME twrp);