2011-06-20 11:52:21 +04:00
/*
2013-12-04 18:50:26 +04:00
* shadow_copy2 : a shadow copy module ( second implementation )
2008-01-16 12:21:38 +03:00
*
2011-06-20 11:52:21 +04:00
* Copyright ( C ) Andrew Tridgell 2007 ( portions taken from shadow_copy2 )
* Copyright ( C ) Ed Plese 2009
* Copyright ( C ) Volker Lendecke 2011
* Copyright ( C ) Christian Ambach 2011
2013-12-04 16:40:14 +04:00
* Copyright ( C ) Michael Adam 2013
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
* Copyright ( C ) Rajesh Joseph 2016
2008-01-16 12:21:38 +03:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
2011-06-20 11:52:21 +04:00
*
2008-01-16 12:21:38 +03:00
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
2011-06-20 11:52:21 +04:00
*
2008-01-16 12:21:38 +03:00
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
/*
2013-12-04 18:55:19 +04:00
* This is a second implemetation of a shadow copy module for exposing
* file system snapshots to windows clients as shadow copies .
*
* See the manual page for documentation .
2008-01-16 12:21:38 +03:00
*/
2011-06-20 11:52:21 +04:00
# include "includes.h"
2015-10-24 00:54:31 +03:00
# include "smbd/smbd.h"
2011-06-20 11:52:21 +04:00
# include "system/filesys.h"
# include "include/ntioctl.h"
# include "util_tdb.h"
2017-01-20 23:00:08 +03:00
# include "lib/util_path.h"
2008-01-16 12:21:38 +03:00
2013-05-24 03:35:44 +04:00
struct shadow_copy2_config {
char * gmt_format ;
bool use_sscanf ;
bool use_localtime ;
char * snapdir ;
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
char * delimiter ;
2013-05-24 03:35:44 +04:00
bool snapdirseverywhere ;
bool crossmountpoints ;
bool fixinodes ;
char * sort_order ;
bool snapdir_absolute ;
2013-05-30 19:26:44 +04:00
char * mount_point ;
2015-11-03 10:15:12 +03:00
char * rel_connectpath ; /* share root, relative to a snapshot root */
2013-10-04 02:07:15 +04:00
char * snapshot_basepath ; /* the absolute version of snapdir */
2013-05-24 03:35:44 +04:00
} ;
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
/* Data-structure to hold the list of snap entries */
struct shadow_copy2_snapentry {
char * snapname ;
char * time_fmt ;
struct shadow_copy2_snapentry * next ;
struct shadow_copy2_snapentry * prev ;
} ;
struct shadow_copy2_snaplist_info {
struct shadow_copy2_snapentry * snaplist ; /* snapshot list */
regex_t * regex ; /* Regex to filter snaps */
time_t fetch_time ; /* snaplist update time */
} ;
2016-07-11 14:27:37 +03:00
/*
* shadow_copy2 private structure . This structure will be
* used to keep module specific information
*/
struct shadow_copy2_private {
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
struct shadow_copy2_config * config ;
struct shadow_copy2_snaplist_info * snaps ;
2017-01-20 22:50:49 +03:00
char * shadow_cwd ; /* Absolute $cwd path. */
/* Absolute connectpath - can vary depending on $cwd. */
char * shadow_connectpath ;
2017-06-30 21:32:59 +03:00
/* talloc'ed realpath return. */
struct smb_filename * shadow_realpath ;
2016-07-11 14:27:37 +03:00
} ;
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
static int shadow_copy2_get_shadow_copy_data (
vfs_handle_struct * handle , files_struct * fsp ,
struct shadow_copy_data * shadow_copy2_data ,
bool labels ) ;
/**
* This function will create a new snapshot list entry and
* return to the caller . This entry will also be added to
* the global snapshot list .
*
* @ param [ in ] priv shadow_copy2 specific data structure
* @ return Newly created snapshot entry or NULL on failure
*/
static struct shadow_copy2_snapentry * shadow_copy2_create_snapentry (
struct shadow_copy2_private * priv )
{
struct shadow_copy2_snapentry * tmpentry = NULL ;
tmpentry = talloc_zero ( priv - > snaps , struct shadow_copy2_snapentry ) ;
if ( tmpentry = = NULL ) {
DBG_ERR ( " talloc_zero() failed \n " ) ;
errno = ENOMEM ;
return NULL ;
}
DLIST_ADD ( priv - > snaps - > snaplist , tmpentry ) ;
return tmpentry ;
}
/**
* This function will delete the entire snaplist and reset
* priv - > snaps - > snaplist to NULL .
*
* @ param [ in ] priv shadow_copye specific data structure
*/
static void shadow_copy2_delete_snaplist ( struct shadow_copy2_private * priv )
{
struct shadow_copy2_snapentry * tmp = NULL ;
while ( ( tmp = priv - > snaps - > snaplist ) ! = NULL ) {
DLIST_REMOVE ( priv - > snaps - > snaplist , tmp ) ;
talloc_free ( tmp ) ;
}
}
/**
* Given a timestamp this function searches the global snapshot list
* and returns the complete snapshot directory name saved in the entry .
*
* @ param [ in ] priv shadow_copy2 specific structure
* @ param [ in ] timestamp timestamp corresponding to one of the snapshot
* @ param [ out ] snap_str buffer to copy the actual snapshot name
* @ param [ in ] len length of snap_str buffer
*
* @ return Length of actual snapshot name , and - 1 on failure
*/
static ssize_t shadow_copy2_saved_snapname ( struct shadow_copy2_private * priv ,
struct tm * timestamp ,
char * snap_str , size_t len )
{
ssize_t snaptime_len = - 1 ;
struct shadow_copy2_snapentry * entry = NULL ;
snaptime_len = strftime ( snap_str , len , GMT_FORMAT , timestamp ) ;
if ( snaptime_len = = 0 ) {
DBG_ERR ( " strftime failed \n " ) ;
return - 1 ;
}
snaptime_len = - 1 ;
for ( entry = priv - > snaps - > snaplist ; entry ; entry = entry - > next ) {
if ( strcmp ( entry - > time_fmt , snap_str ) = = 0 ) {
snaptime_len = snprintf ( snap_str , len , " %s " ,
entry - > snapname ) ;
return snaptime_len ;
}
}
snap_str [ 0 ] = 0 ;
return snaptime_len ;
}
/**
* This function will check if snaplist is updated or not . If snaplist
* is empty then it will create a new list . Each time snaplist is updated
* the time is recorded . If the snapshot time is greater than the snaplist
* update time then chances are we are working on an older list . Then discard
* the old list and fetch a new snaplist .
*
* @ param [ in ] handle VFS handle struct
* @ param [ in ] snap_time time of snapshot
*
* @ return true if the list is updated else false
*/
static bool shadow_copy2_update_snaplist ( struct vfs_handle_struct * handle ,
time_t snap_time )
{
int ret = - 1 ;
bool snaplist_updated = false ;
struct files_struct fsp = { 0 } ;
struct smb_filename smb_fname = { 0 } ;
double seconds = 0.0 ;
struct shadow_copy2_private * priv = NULL ;
SMB_VFS_HANDLE_GET_DATA ( handle , priv , struct shadow_copy2_private ,
return false ) ;
seconds = difftime ( snap_time , priv - > snaps - > fetch_time ) ;
/*
* Fetch the snapshot list if either the snaplist is empty or the
* required snapshot time is greater than the last fetched snaplist
* time .
*/
if ( seconds > 0 | | ( priv - > snaps - > snaplist = = NULL ) ) {
2016-09-25 04:30:19 +03:00
smb_fname . base_name = discard_const_p ( char , " . " ) ;
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
fsp . fsp_name = & smb_fname ;
ret = shadow_copy2_get_shadow_copy_data ( handle , & fsp ,
NULL , false ) ;
if ( ret = = 0 ) {
snaplist_updated = true ;
} else {
DBG_ERR ( " Failed to get shadow copy data \n " ) ;
}
}
return snaplist_updated ;
}
2011-06-20 11:52:21 +04:00
static bool shadow_copy2_find_slashes ( TALLOC_CTX * mem_ctx , const char * str ,
size_t * * poffsets ,
unsigned * pnum_offsets )
2008-01-16 12:21:38 +03:00
{
2011-06-20 11:52:21 +04:00
unsigned num_offsets ;
size_t * offsets ;
2009-09-16 05:22:56 +04:00
const char * p ;
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
num_offsets = 0 ;
2010-01-21 10:30:01 +03:00
2011-06-20 11:52:21 +04:00
p = str ;
while ( ( p = strchr ( p , ' / ' ) ) ! = NULL ) {
num_offsets + = 1 ;
p + = 1 ;
}
2010-01-21 10:30:01 +03:00
2011-06-20 11:52:21 +04:00
offsets = talloc_array ( mem_ctx , size_t , num_offsets ) ;
if ( offsets = = NULL ) {
return false ;
2010-01-21 10:30:01 +03:00
}
2011-06-20 11:52:21 +04:00
p = str ;
num_offsets = 0 ;
while ( ( p = strchr ( p , ' / ' ) ) ! = NULL ) {
offsets [ num_offsets ] = p - str ;
num_offsets + = 1 ;
p + = 1 ;
2009-12-07 06:03:06 +03:00
}
2010-01-21 10:30:01 +03:00
2011-06-20 11:52:21 +04:00
* poffsets = offsets ;
* pnum_offsets = num_offsets ;
return true ;
2010-01-21 10:30:01 +03:00
}
2013-05-24 19:20:42 +04:00
/**
2013-12-12 15:08:58 +04:00
* Given a timestamp , build the posix level GMT - tag string
2013-05-31 01:51:02 +04:00
* based on the configurable format .
2013-05-24 19:20:42 +04:00
*/
2016-07-11 15:28:46 +03:00
static ssize_t shadow_copy2_posix_gmt_string ( struct vfs_handle_struct * handle ,
2013-05-31 01:51:02 +04:00
time_t snapshot ,
char * snaptime_string ,
size_t len )
2009-09-16 05:22:56 +04:00
{
2011-06-20 11:52:21 +04:00
struct tm snap_tm ;
2016-07-11 15:28:46 +03:00
ssize_t snaptime_len ;
2013-05-24 03:35:44 +04:00
struct shadow_copy2_config * config ;
2016-07-11 14:27:37 +03:00
struct shadow_copy2_private * priv ;
2009-09-16 05:22:56 +04:00
2016-07-11 14:27:37 +03:00
SMB_VFS_HANDLE_GET_DATA ( handle , priv , struct shadow_copy2_private ,
2013-05-31 01:51:02 +04:00
return 0 ) ;
2012-07-02 13:31:58 +04:00
2016-07-11 14:27:37 +03:00
config = priv - > config ;
2013-05-24 03:35:44 +04:00
if ( config - > use_sscanf ) {
snaptime_len = snprintf ( snaptime_string ,
2013-05-31 01:51:02 +04:00
len ,
2013-05-24 03:35:44 +04:00
config - > gmt_format ,
( unsigned long ) snapshot ) ;
2012-07-02 16:31:49 +04:00
if ( snaptime_len < = 0 ) {
2012-07-02 13:31:58 +04:00
DEBUG ( 10 , ( " snprintf failed \n " ) ) ;
2016-07-11 15:28:46 +03:00
return - 1 ;
2012-07-02 13:31:58 +04:00
}
} else {
2013-05-24 03:35:44 +04:00
if ( config - > use_localtime ) {
2012-07-02 16:31:49 +04:00
if ( localtime_r ( & snapshot , & snap_tm ) = = 0 ) {
DEBUG ( 10 , ( " gmtime_r failed \n " ) ) ;
2013-05-31 01:51:02 +04:00
return - 1 ;
2012-07-02 16:31:49 +04:00
}
} else {
if ( gmtime_r ( & snapshot , & snap_tm ) = = 0 ) {
DEBUG ( 10 , ( " gmtime_r failed \n " ) ) ;
2013-05-31 01:51:02 +04:00
return - 1 ;
2012-07-02 16:31:49 +04:00
}
}
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
if ( priv - > snaps - > regex ! = NULL ) {
snaptime_len = shadow_copy2_saved_snapname ( priv ,
& snap_tm , snaptime_string , len ) ;
if ( snaptime_len > = 0 )
return snaptime_len ;
/*
* If we fail to find the snapshot name , chances are
* that we have not updated our snaplist . Make sure the
* snaplist is updated .
*/
if ( ! shadow_copy2_update_snaplist ( handle , snapshot ) ) {
DBG_DEBUG ( " shadow_copy2_update_snaplist "
" failed \n " ) ;
return - 1 ;
}
return shadow_copy2_saved_snapname ( priv ,
& snap_tm , snaptime_string , len ) ;
}
2013-05-24 03:35:44 +04:00
snaptime_len = strftime ( snaptime_string ,
2013-05-31 01:51:02 +04:00
len ,
2013-05-24 03:35:44 +04:00
config - > gmt_format ,
& snap_tm ) ;
2012-07-02 16:31:49 +04:00
if ( snaptime_len = = 0 ) {
2012-07-02 13:31:58 +04:00
DEBUG ( 10 , ( " strftime failed \n " ) ) ;
2016-07-11 15:28:46 +03:00
return - 1 ;
2012-07-02 13:31:58 +04:00
}
2009-09-16 05:22:56 +04:00
}
2013-05-29 19:12:21 +04:00
2013-05-31 01:51:02 +04:00
return snaptime_len ;
}
/**
2013-12-12 15:08:58 +04:00
* Given a timestamp , build the string to insert into a path
2013-05-31 01:51:02 +04:00
* as a path component for creating the local path to the
* snapshot at the given timestamp of the input path .
*
* In the case of a parallel snapdir ( specified with an
* absolute path ) , this is the inital portion of the
* local path of any snapshot file . The complete path is
* obtained by appending the portion of the file ' s path
* below the share root ' s mountpoint .
*/
static char * shadow_copy2_insert_string ( TALLOC_CTX * mem_ctx ,
struct vfs_handle_struct * handle ,
time_t snapshot )
{
fstring snaptime_string ;
2016-07-11 15:28:46 +03:00
ssize_t snaptime_len = 0 ;
2013-05-31 01:51:02 +04:00
char * result = NULL ;
struct shadow_copy2_config * config ;
2016-07-11 14:27:37 +03:00
struct shadow_copy2_private * priv ;
2013-05-31 01:51:02 +04:00
2016-07-11 14:27:37 +03:00
SMB_VFS_HANDLE_GET_DATA ( handle , priv , struct shadow_copy2_private ,
2013-05-31 01:51:02 +04:00
return NULL ) ;
2016-07-11 14:27:37 +03:00
config = priv - > config ;
2013-05-31 01:51:02 +04:00
snaptime_len = shadow_copy2_posix_gmt_string ( handle ,
snapshot ,
snaptime_string ,
sizeof ( snaptime_string ) ) ;
if ( snaptime_len < = 0 ) {
return NULL ;
}
2013-05-29 19:12:21 +04:00
if ( config - > snapdir_absolute ) {
result = talloc_asprintf ( mem_ctx , " %s/%s " ,
config - > snapdir , snaptime_string ) ;
} else {
result = talloc_asprintf ( mem_ctx , " /%s/%s " ,
config - > snapdir , snaptime_string ) ;
}
if ( result = = NULL ) {
DEBUG ( 1 , ( __location__ " talloc_asprintf failed \n " ) ) ;
}
return result ;
2009-09-16 05:22:56 +04:00
}
2013-05-31 02:18:52 +04:00
/**
* Build the posix snapshot path for the connection
* at the given timestamp , i . e . the absolute posix path
* that contains the snapshot for this file system .
*
* This only applies to classical case , i . e . not
* to the " snapdirseverywhere " mode .
*/
static char * shadow_copy2_snapshot_path ( TALLOC_CTX * mem_ctx ,
struct vfs_handle_struct * handle ,
time_t snapshot )
{
fstring snaptime_string ;
2016-07-11 15:28:46 +03:00
ssize_t snaptime_len = 0 ;
2013-05-31 02:18:52 +04:00
char * result = NULL ;
2016-07-11 14:27:37 +03:00
struct shadow_copy2_private * priv ;
2013-05-31 02:18:52 +04:00
2016-07-11 14:27:37 +03:00
SMB_VFS_HANDLE_GET_DATA ( handle , priv , struct shadow_copy2_private ,
2013-05-31 02:18:52 +04:00
return NULL ) ;
snaptime_len = shadow_copy2_posix_gmt_string ( handle ,
snapshot ,
snaptime_string ,
sizeof ( snaptime_string ) ) ;
if ( snaptime_len < = 0 ) {
return NULL ;
}
result = talloc_asprintf ( mem_ctx , " %s/%s " ,
2016-07-11 14:27:37 +03:00
priv - > config - > snapshot_basepath , snaptime_string ) ;
2013-05-31 02:18:52 +04:00
if ( result = = NULL ) {
DEBUG ( 1 , ( __location__ " talloc_asprintf failed \n " ) ) ;
}
return result ;
}
2017-01-20 23:00:08 +03:00
static char * make_path_absolute ( TALLOC_CTX * mem_ctx ,
struct shadow_copy2_private * priv ,
const char * name )
{
char * newpath = NULL ;
char * abs_path = NULL ;
if ( name [ 0 ] ! = ' / ' ) {
newpath = talloc_asprintf ( mem_ctx ,
" %s/%s " ,
priv - > shadow_cwd ,
name ) ;
if ( newpath = = NULL ) {
return NULL ;
}
name = newpath ;
}
abs_path = canonicalize_absolute_path ( mem_ctx , name ) ;
TALLOC_FREE ( newpath ) ;
return abs_path ;
}
/* Return a $cwd-relative path. */
static bool make_relative_path ( const char * cwd , char * abs_path )
{
size_t cwd_len = strlen ( cwd ) ;
size_t abs_len = strlen ( abs_path ) ;
if ( abs_len < cwd_len ) {
return false ;
}
if ( memcmp ( abs_path , cwd , cwd_len ) ! = 0 ) {
return false ;
}
2017-04-11 13:03:20 +03:00
/* The cwd_len != 1 case is for $cwd == '/' */
if ( cwd_len ! = 1 & &
abs_path [ cwd_len ] ! = ' / ' & &
abs_path [ cwd_len ] ! = ' \0 ' )
{
2017-01-20 23:00:08 +03:00
return false ;
}
if ( abs_path [ cwd_len ] = = ' / ' ) {
cwd_len + + ;
}
memmove ( abs_path , & abs_path [ cwd_len ] , abs_len + 1 - cwd_len ) ;
return true ;
}
2017-01-26 21:35:50 +03:00
static bool shadow_copy2_snapshot_to_gmt ( vfs_handle_struct * handle ,
const char * name ,
char * gmt , size_t gmt_len ) ;
/*
* Check if an incoming filename is already a snapshot converted pathname .
*
* If so , it returns the pathname truncated at the snapshot point which
* will be used as the connectpath .
*/
static int check_for_converted_path ( TALLOC_CTX * mem_ctx ,
struct vfs_handle_struct * handle ,
struct shadow_copy2_private * priv ,
char * abs_path ,
bool * ppath_already_converted ,
char * * pconnectpath )
{
size_t snapdirlen = 0 ;
char * p = strstr_m ( abs_path , priv - > config - > snapdir ) ;
char * q = NULL ;
char * connect_path = NULL ;
char snapshot [ GMT_NAME_LEN + 1 ] ;
* ppath_already_converted = false ;
if ( p = = NULL ) {
/* Must at least contain shadow:snapdir. */
return 0 ;
}
if ( priv - > config - > snapdir [ 0 ] = = ' / ' & &
p ! = abs_path ) {
/* Absolute shadow:snapdir must be at the start. */
return 0 ;
}
snapdirlen = strlen ( priv - > config - > snapdir ) ;
if ( p [ snapdirlen ] ! = ' / ' ) {
/* shadow:snapdir must end as a separate component. */
return 0 ;
}
if ( p > abs_path & & p [ - 1 ] ! = ' / ' ) {
/* shadow:snapdir must start as a separate component. */
return 0 ;
}
p + = snapdirlen ;
p + + ; /* Move past the / */
/*
* Need to return up to the next path
* component after the time .
* This will be used as the connectpath .
*/
q = strchr ( p , ' / ' ) ;
if ( q = = NULL ) {
/*
* No next path component .
* Use entire string .
*/
connect_path = talloc_strdup ( mem_ctx ,
abs_path ) ;
} else {
connect_path = talloc_strndup ( mem_ctx ,
abs_path ,
q - abs_path ) ;
}
if ( connect_path = = NULL ) {
return ENOMEM ;
}
/*
* Point p at the same offset in connect_path as
* it is in abs_path .
*/
p = & connect_path [ p - abs_path ] ;
/*
* Now ensure there is a time string at p .
* The SMB - format @ GMT - token string is returned
* in snapshot .
*/
if ( ! shadow_copy2_snapshot_to_gmt ( handle ,
p ,
snapshot ,
sizeof ( snapshot ) ) ) {
TALLOC_FREE ( connect_path ) ;
return 0 ;
}
if ( pconnectpath ! = NULL ) {
* pconnectpath = connect_path ;
}
* ppath_already_converted = true ;
DBG_DEBUG ( " path |%s| is already converted. "
" connect path = |%s| \n " ,
abs_path ,
connect_path ) ;
return 0 ;
}
2013-05-24 01:32:15 +04:00
/**
2017-01-26 21:49:51 +03:00
* This function does two things .
*
* 1 ) . Checks if an incoming filename is already a
* snapshot converted pathname .
* If so , it returns the pathname truncated
* at the snapshot point which will be used
* as the connectpath , and then does an early return .
*
* 2 ) . Checks if an incoming filename contains an
* SMB - layer @ GMT - style timestamp .
* If so , it strips the timestamp , and returns
* both the timestamp and the stripped path
* ( making it cwd - relative ) .
2013-05-24 01:32:15 +04:00
*/
2017-01-26 21:49:51 +03:00
2017-01-20 22:54:56 +03:00
static bool shadow_copy2_strip_snapshot_internal ( TALLOC_CTX * mem_ctx ,
2011-06-20 11:52:21 +04:00
struct vfs_handle_struct * handle ,
2017-01-20 22:56:21 +03:00
const char * orig_name ,
2011-06-20 11:52:21 +04:00
time_t * ptimestamp ,
2017-01-20 22:54:56 +03:00
char * * pstripped ,
char * * psnappath )
2011-06-20 11:52:21 +04:00
{
struct tm tm ;
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
2011-06-20 11:52:21 +04:00
const char * p ;
char * q ;
2017-01-20 22:42:39 +03:00
char * stripped = NULL ;
2011-06-20 11:52:21 +04:00
size_t rest_len , dst_len ;
2016-07-11 14:27:37 +03:00
struct shadow_copy2_private * priv ;
2012-10-18 17:24:39 +04:00
ptrdiff_t len_before_gmt ;
2017-01-20 22:56:21 +03:00
const char * name = orig_name ;
2017-01-26 21:49:51 +03:00
char * abs_path = NULL ;
bool ret = true ;
bool already_converted = false ;
int err = 0 ;
2013-05-24 03:35:44 +04:00
2016-07-11 14:27:37 +03:00
SMB_VFS_HANDLE_GET_DATA ( handle , priv , struct shadow_copy2_private ,
2013-05-24 03:35:44 +04:00
return false ) ;
2009-06-16 23:01:13 +04:00
2013-05-30 01:57:30 +04:00
DEBUG ( 10 , ( __location__ " : enter path '%s' \n " , name ) ) ;
2017-01-26 21:49:51 +03:00
abs_path = make_path_absolute ( mem_ctx , priv , name ) ;
if ( abs_path = = NULL ) {
ret = false ;
goto out ;
}
name = abs_path ;
DEBUG ( 10 , ( __location__ " : abs path '%s' \n " , name ) ) ;
err = check_for_converted_path ( mem_ctx ,
handle ,
priv ,
abs_path ,
& already_converted ,
psnappath ) ;
if ( err ! = 0 ) {
/* error in conversion. */
ret = false ;
goto out ;
}
if ( already_converted ) {
goto out ;
}
/*
* From here we ' re only looking to strip an
* SMB - layer @ GMT - token .
*/
2011-06-20 11:52:21 +04:00
p = strstr_m ( name , " @GMT- " ) ;
if ( p = = NULL ) {
2012-10-15 20:13:33 +04:00
DEBUG ( 11 , ( " @GMT not found \n " ) ) ;
2017-01-26 21:49:51 +03:00
goto out ;
2011-06-20 11:52:21 +04:00
}
if ( ( p > name ) & & ( p [ - 1 ] ! = ' / ' ) ) {
2013-05-29 19:14:49 +04:00
/* the GMT-token does not start a path-component */
2012-10-15 20:13:33 +04:00
DEBUG ( 10 , ( " not at start, p=%p, name=%p, p[-1]=%d \n " ,
p , name , ( int ) p [ - 1 ] ) ) ;
2017-01-26 21:49:51 +03:00
goto out ;
2011-06-20 11:52:21 +04:00
}
2012-10-18 17:24:39 +04:00
len_before_gmt = p - name ;
2011-06-20 11:52:21 +04:00
q = strptime ( p , GMT_FORMAT , & tm ) ;
if ( q = = NULL ) {
2012-10-15 20:13:33 +04:00
DEBUG ( 10 , ( " strptime failed \n " ) ) ;
2017-01-26 21:49:51 +03:00
goto out ;
2011-06-20 11:52:21 +04:00
}
tm . tm_isdst = - 1 ;
2012-07-02 16:31:49 +04:00
timestamp = timegm ( & tm ) ;
2011-06-20 11:52:21 +04:00
if ( timestamp = = ( time_t ) - 1 ) {
2012-10-15 20:13:33 +04:00
DEBUG ( 10 , ( " timestamp==-1 \n " ) ) ;
2017-01-26 21:49:51 +03:00
goto out ;
2011-06-20 11:52:21 +04:00
}
2012-10-15 20:16:44 +04:00
if ( q [ 0 ] = = ' \0 ' ) {
2014-06-26 23:43:03 +04:00
/*
* The name consists of only the GMT token or the GMT
* token is at the end of the path . XP seems to send
* @ GMT - at the end under certain circumstances even
* with a path prefix .
*/
2011-06-20 11:52:21 +04:00
if ( pstripped ! = NULL ) {
2017-04-11 13:03:52 +03:00
if ( len_before_gmt > 1 ) {
2016-08-16 19:43:37 +03:00
/*
2017-04-11 13:03:52 +03:00
* There is a path ( and not only a slash )
* before the @ GMT - . Remove the trailing
* slash character .
2016-08-16 19:43:37 +03:00
*/
len_before_gmt - = 1 ;
}
2016-08-16 19:41:43 +03:00
stripped = talloc_strndup ( mem_ctx , name ,
len_before_gmt ) ;
2011-06-20 11:52:21 +04:00
if ( stripped = = NULL ) {
2017-01-26 21:49:51 +03:00
ret = false ;
goto out ;
}
if ( orig_name [ 0 ] ! = ' / ' ) {
if ( make_relative_path ( priv - > shadow_cwd ,
stripped ) = = false ) {
DEBUG ( 10 , ( __location__ " : path '%s' "
2017-04-11 12:18:30 +03:00
" doesn't start with cwd '%s' \n " ,
2017-01-26 21:49:51 +03:00
stripped , priv - > shadow_cwd ) ) ;
ret = false ;
errno = ENOENT ;
goto out ;
}
2011-06-20 11:52:21 +04:00
}
* pstripped = stripped ;
}
* ptimestamp = timestamp ;
2017-01-26 21:49:51 +03:00
goto out ;
2011-06-20 11:52:21 +04:00
}
if ( q [ 0 ] ! = ' / ' ) {
2013-05-29 19:14:49 +04:00
/*
2014-06-26 23:43:03 +04:00
* It is not a complete path component , i . e . the path
* component continues after the gmt - token .
2013-05-29 19:14:49 +04:00
*/
2012-10-15 20:13:33 +04:00
DEBUG ( 10 , ( " q[0] = %d \n " , ( int ) q [ 0 ] ) ) ;
2017-01-26 21:49:51 +03:00
goto out ;
2011-06-20 11:52:21 +04:00
}
q + = 1 ;
rest_len = strlen ( q ) ;
2016-08-17 20:49:50 +03:00
dst_len = len_before_gmt + rest_len ;
2011-06-20 11:52:21 +04:00
if ( pstripped ! = NULL ) {
stripped = talloc_array ( mem_ctx , char , dst_len + 1 ) ;
if ( stripped = = NULL ) {
2017-01-26 21:49:51 +03:00
ret = false ;
goto out ;
2011-06-20 11:52:21 +04:00
}
if ( p > name ) {
2016-08-17 20:49:50 +03:00
memcpy ( stripped , name , len_before_gmt ) ;
2011-06-20 11:52:21 +04:00
}
if ( rest_len > 0 ) {
2016-08-17 20:49:50 +03:00
memcpy ( stripped + len_before_gmt , q , rest_len ) ;
2011-06-20 11:52:21 +04:00
}
stripped [ dst_len ] = ' \0 ' ;
2017-01-26 21:49:51 +03:00
if ( orig_name [ 0 ] ! = ' / ' ) {
if ( make_relative_path ( priv - > shadow_cwd ,
stripped ) = = false ) {
DEBUG ( 10 , ( __location__ " : path '%s' "
2017-04-11 12:18:30 +03:00
" doesn't start with cwd '%s' \n " ,
2017-01-26 21:49:51 +03:00
stripped , priv - > shadow_cwd ) ) ;
ret = false ;
errno = ENOENT ;
goto out ;
}
}
2011-06-20 11:52:21 +04:00
* pstripped = stripped ;
}
* ptimestamp = timestamp ;
2017-01-26 21:49:51 +03:00
ret = true ;
out :
TALLOC_FREE ( abs_path ) ;
return ret ;
2011-06-20 11:52:21 +04:00
}
2008-01-16 12:21:38 +03:00
2017-01-20 22:54:56 +03:00
static bool shadow_copy2_strip_snapshot ( TALLOC_CTX * mem_ctx ,
struct vfs_handle_struct * handle ,
const char * orig_name ,
time_t * ptimestamp ,
char * * pstripped )
{
return shadow_copy2_strip_snapshot_internal ( mem_ctx ,
handle ,
orig_name ,
ptimestamp ,
pstripped ,
NULL ) ;
}
2011-06-20 11:52:21 +04:00
static char * shadow_copy2_find_mount_point ( TALLOC_CTX * mem_ctx ,
vfs_handle_struct * handle )
2008-01-16 12:21:38 +03:00
{
char * path = talloc_strdup ( mem_ctx , handle - > conn - > connectpath ) ;
dev_t dev ;
struct stat st ;
char * p ;
if ( stat ( path , & st ) ! = 0 ) {
talloc_free ( path ) ;
return NULL ;
}
dev = st . st_dev ;
while ( ( p = strrchr ( path , ' / ' ) ) & & p > path ) {
* p = 0 ;
if ( stat ( path , & st ) ! = 0 ) {
talloc_free ( path ) ;
return NULL ;
}
if ( st . st_dev ! = dev ) {
* p = ' / ' ;
break ;
}
}
2011-06-20 11:52:21 +04:00
return path ;
2008-01-16 12:21:38 +03:00
}
2013-05-29 03:13:57 +04:00
/**
* Convert from a name as handed in via the SMB layer
* and a timestamp into the local path of the snapshot
* of the provided file at the provided time .
2015-11-01 23:28:46 +03:00
* Also return the path in the snapshot corresponding
* to the file ' s share root .
2013-05-29 03:13:57 +04:00
*/
2015-11-01 23:28:46 +03:00
static char * shadow_copy2_do_convert ( TALLOC_CTX * mem_ctx ,
struct vfs_handle_struct * handle ,
const char * name , time_t timestamp ,
size_t * snaproot_len )
2008-01-16 12:21:38 +03:00
{
2011-06-20 11:52:21 +04:00
struct smb_filename converted_fname ;
char * result = NULL ;
size_t * slashes = NULL ;
unsigned num_slashes ;
char * path = NULL ;
size_t pathlen ;
char * insert = NULL ;
char * converted = NULL ;
2015-11-01 23:28:46 +03:00
size_t insertlen , connectlen = 0 ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
int i ;
2011-06-20 11:52:21 +04:00
size_t min_offset ;
2013-05-24 03:35:44 +04:00
struct shadow_copy2_config * config ;
2016-07-11 14:27:37 +03:00
struct shadow_copy2_private * priv ;
2015-11-01 23:28:46 +03:00
size_t in_share_offset = 0 ;
2013-05-24 03:35:44 +04:00
2016-07-11 14:27:37 +03:00
SMB_VFS_HANDLE_GET_DATA ( handle , priv , struct shadow_copy2_private ,
2013-05-24 03:35:44 +04:00
return NULL ) ;
2011-06-20 11:52:21 +04:00
2016-07-11 14:27:37 +03:00
config = priv - > config ;
2013-05-23 18:23:03 +04:00
DEBUG ( 10 , ( " converting '%s' \n " , name ) ) ;
if ( ! config - > snapdirseverywhere ) {
int ret ;
char * snapshot_path ;
snapshot_path = shadow_copy2_snapshot_path ( talloc_tos ( ) ,
handle ,
timestamp ) ;
if ( snapshot_path = = NULL ) {
goto fail ;
}
if ( config - > rel_connectpath = = NULL ) {
converted = talloc_asprintf ( mem_ctx , " %s/%s " ,
snapshot_path , name ) ;
} else {
converted = talloc_asprintf ( mem_ctx , " %s/%s/%s " ,
snapshot_path ,
config - > rel_connectpath ,
name ) ;
}
if ( converted = = NULL ) {
goto fail ;
}
ZERO_STRUCT ( converted_fname ) ;
converted_fname . base_name = converted ;
ret = SMB_VFS_NEXT_LSTAT ( handle , & converted_fname ) ;
DEBUG ( 10 , ( " Trying[not snapdirseverywhere] %s: %d (%s) \n " ,
converted ,
ret , ret = = 0 ? " ok " : strerror ( errno ) ) ) ;
if ( ret = = 0 ) {
DEBUG ( 10 , ( " Found %s \n " , converted ) ) ;
result = converted ;
converted = NULL ;
2015-11-01 23:28:46 +03:00
if ( snaproot_len ! = NULL ) {
* snaproot_len = strlen ( snapshot_path ) ;
if ( config - > rel_connectpath ! = NULL ) {
* snaproot_len + =
strlen ( config - > rel_connectpath ) + 1 ;
}
}
2013-05-23 18:23:03 +04:00
goto fail ;
} else {
errno = ENOENT ;
goto fail ;
}
/* never reached ... */
}
2015-11-01 23:28:46 +03:00
connectlen = strlen ( handle - > conn - > connectpath ) ;
2012-10-17 14:08:26 +04:00
if ( name [ 0 ] = = 0 ) {
path = talloc_strdup ( mem_ctx , handle - > conn - > connectpath ) ;
} else {
path = talloc_asprintf (
mem_ctx , " %s/%s " , handle - > conn - > connectpath , name ) ;
}
2011-06-20 11:52:21 +04:00
if ( path = = NULL ) {
errno = ENOMEM ;
goto fail ;
2008-01-16 12:21:38 +03:00
}
2011-06-20 11:52:21 +04:00
pathlen = talloc_get_size ( path ) - 1 ;
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
if ( ! shadow_copy2_find_slashes ( talloc_tos ( ) , path ,
& slashes , & num_slashes ) ) {
goto fail ;
2008-01-16 12:21:38 +03:00
}
2013-05-29 17:06:22 +04:00
2011-06-20 11:52:21 +04:00
insert = shadow_copy2_insert_string ( talloc_tos ( ) , handle , timestamp ) ;
if ( insert = = NULL ) {
goto fail ;
2008-01-16 12:21:38 +03:00
}
2011-06-20 11:52:21 +04:00
insertlen = talloc_get_size ( insert ) - 1 ;
2013-05-29 17:06:22 +04:00
2013-12-11 12:41:38 +04:00
/*
* Note : We deliberatly don ' t expensively initialize the
* array with talloc_zero here : Putting zero into
* converted [ pathlen + insertlen ] below is sufficient , because
* in the following for loop , the insert string is inserted
* at various slash places . So the memory up to position
* pathlen + insertlen will always be initialized when the
* converted string is used .
*/
2013-12-11 12:34:47 +04:00
converted = talloc_array ( mem_ctx , char , pathlen + insertlen + 1 ) ;
2011-06-20 11:52:21 +04:00
if ( converted = = NULL ) {
goto fail ;
2008-01-16 12:21:38 +03:00
}
2011-06-20 11:52:21 +04:00
if ( path [ pathlen - 1 ] ! = ' / ' ) {
/*
* Append a fake slash to find the snapshot root
*/
size_t * tmp ;
tmp = talloc_realloc ( talloc_tos ( ) , slashes ,
size_t , num_slashes + 1 ) ;
if ( tmp = = NULL ) {
goto fail ;
}
slashes = tmp ;
slashes [ num_slashes ] = pathlen ;
num_slashes + = 1 ;
2010-04-14 12:05:56 +04:00
}
2011-06-20 11:52:21 +04:00
min_offset = 0 ;
2013-05-24 03:35:44 +04:00
if ( ! config - > crossmountpoints ) {
2013-05-31 02:46:01 +04:00
min_offset = strlen ( config - > mount_point ) ;
2009-09-16 05:22:56 +04:00
}
2011-06-20 11:52:21 +04:00
memcpy ( converted , path , pathlen + 1 ) ;
converted [ pathlen + insertlen ] = ' \0 ' ;
2010-01-21 10:30:01 +03:00
2011-06-20 11:52:21 +04:00
ZERO_STRUCT ( converted_fname ) ;
converted_fname . base_name = converted ;
2010-01-21 10:30:01 +03:00
2011-06-20 11:52:21 +04:00
for ( i = num_slashes - 1 ; i > = 0 ; i - - ) {
int ret ;
size_t offset ;
2009-12-07 06:03:06 +03:00
2011-06-20 11:52:21 +04:00
offset = slashes [ i ] ;
2010-01-21 10:30:01 +03:00
2011-06-20 11:52:21 +04:00
if ( offset < min_offset ) {
errno = ENOENT ;
goto fail ;
}
2008-01-16 12:21:38 +03:00
2015-11-01 23:28:46 +03:00
if ( offset > = connectlen ) {
in_share_offset = offset ;
}
2011-06-20 11:52:21 +04:00
memcpy ( converted + offset , insert , insertlen ) ;
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
offset + = insertlen ;
memcpy ( converted + offset , path + slashes [ i ] ,
pathlen - slashes [ i ] ) ;
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
ret = SMB_VFS_NEXT_LSTAT ( handle , & converted_fname ) ;
2008-01-16 12:21:38 +03:00
2013-05-31 02:45:16 +04:00
DEBUG ( 10 , ( " Trying[snapdirseverywhere] %s: %d (%s) \n " ,
converted ,
2011-06-20 11:52:21 +04:00
ret , ret = = 0 ? " ok " : strerror ( errno ) ) ) ;
if ( ret = = 0 ) {
/* success */
2015-11-01 23:28:46 +03:00
if ( snaproot_len ! = NULL ) {
* snaproot_len = in_share_offset + insertlen ;
}
2011-06-20 11:52:21 +04:00
break ;
}
if ( errno = = ENOTDIR ) {
/*
* This is a valid condition : We appended the
* . snaphots / @ GMT . . to a file name . Just try
* with the upper levels .
*/
continue ;
}
if ( errno ! = ENOENT ) {
/* Other problem than "not found" */
goto fail ;
}
}
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
if ( i > = 0 ) {
/*
* Found something
*/
DEBUG ( 10 , ( " Found %s \n " , converted ) ) ;
result = converted ;
converted = NULL ;
} else {
errno = ENOENT ;
}
fail :
2017-01-23 21:20:13 +03:00
if ( result = = NULL ) {
saved_errno = errno ;
}
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( converted ) ;
TALLOC_FREE ( insert ) ;
TALLOC_FREE ( slashes ) ;
TALLOC_FREE ( path ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return result ;
2008-01-16 12:21:38 +03:00
}
2015-11-01 23:28:46 +03:00
/**
* Convert from a name as handed in via the SMB layer
* and a timestamp into the local path of the snapshot
* of the provided file at the provided time .
*/
static char * shadow_copy2_convert ( TALLOC_CTX * mem_ctx ,
struct vfs_handle_struct * handle ,
const char * name , time_t timestamp )
{
return shadow_copy2_do_convert ( mem_ctx , handle , name , timestamp , NULL ) ;
}
2008-01-16 12:21:38 +03:00
/*
modify a sbuf return to ensure that inodes in the shadow directory
are different from those in the main directory
*/
2011-06-20 11:52:21 +04:00
static void convert_sbuf ( vfs_handle_struct * handle , const char * fname ,
SMB_STRUCT_STAT * sbuf )
2008-01-16 12:21:38 +03:00
{
2016-07-11 14:27:37 +03:00
struct shadow_copy2_private * priv ;
2013-05-24 03:35:44 +04:00
2016-07-11 14:27:37 +03:00
SMB_VFS_HANDLE_GET_DATA ( handle , priv , struct shadow_copy2_private ,
2013-05-24 03:35:44 +04:00
return ) ;
2016-07-11 14:27:37 +03:00
if ( priv - > config - > fixinodes ) {
2008-01-16 12:21:38 +03:00
/* some snapshot systems, like GPFS, return the name
device : inode for the snapshot files as the current
files . That breaks the ' restore ' button in the shadow copy
GUI , as the client gets a sharing violation .
This is a crude way of allowing both files to be
open at once . It has a slight chance of inode
number collision , but I can ' t see a better approach
without significant VFS changes
*/
2015-03-12 18:00:58 +03:00
TDB_DATA key = { . dptr = discard_const_p ( uint8_t , fname ) ,
. dsize = strlen ( fname ) } ;
2011-06-20 11:52:21 +04:00
uint32_t shash ;
2015-03-12 18:00:58 +03:00
shash = tdb_jenkins_hash ( & key ) & 0xFF000000 ;
2008-01-16 12:21:38 +03:00
if ( shash = = 0 ) {
shash = 1 ;
}
2009-05-14 17:34:42 +04:00
sbuf - > st_ex_ino ^ = shash ;
2008-01-16 12:21:38 +03:00
}
}
2012-03-28 06:22:03 +04:00
static DIR * shadow_copy2_opendir ( vfs_handle_struct * handle ,
2016-02-27 01:53:12 +03:00
const struct smb_filename * smb_fname ,
const char * mask ,
uint32_t attr )
2011-06-20 11:52:21 +04:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2012-03-28 06:22:03 +04:00
DIR * ret ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
2011-06-20 11:52:21 +04:00
char * conv ;
2016-02-27 01:53:12 +03:00
struct smb_filename * conv_smb_fname = NULL ;
2011-06-20 11:52:21 +04:00
2016-02-27 01:53:12 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ) ) {
2011-06-20 11:52:21 +04:00
return NULL ;
}
if ( timestamp = = 0 ) {
2016-02-27 01:53:12 +03:00
return SMB_VFS_NEXT_OPENDIR ( handle , smb_fname , mask , attr ) ;
2011-06-20 11:52:21 +04:00
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return NULL ;
}
2016-02-27 01:53:12 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
2016-03-19 07:19:38 +03:00
NULL ,
smb_fname - > flags ) ;
2016-02-27 01:53:12 +03:00
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
return NULL ;
}
ret = SMB_VFS_NEXT_OPENDIR ( handle , conv_smb_fname , mask , attr ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = NULL ) {
saved_errno = errno ;
}
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2016-02-27 01:53:12 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
}
2008-01-16 12:21:38 +03:00
static int shadow_copy2_rename ( vfs_handle_struct * handle ,
2009-07-01 04:04:38 +04:00
const struct smb_filename * smb_fname_src ,
const struct smb_filename * smb_fname_dst )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp_src = 0 ;
time_t timestamp_dst = 0 ;
2017-01-27 04:19:24 +03:00
char * snappath_src = NULL ;
char * snappath_dst = NULL ;
2011-06-20 11:52:21 +04:00
2017-01-27 04:19:24 +03:00
if ( ! shadow_copy2_strip_snapshot_internal ( talloc_tos ( ) , handle ,
2011-06-20 11:52:21 +04:00
smb_fname_src - > base_name ,
2017-01-27 04:19:24 +03:00
& timestamp_src , NULL , & snappath_src ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
2017-01-27 04:19:24 +03:00
if ( ! shadow_copy2_strip_snapshot_internal ( talloc_tos ( ) , handle ,
2011-06-20 11:52:21 +04:00
smb_fname_dst - > base_name ,
2017-01-27 04:19:24 +03:00
& timestamp_dst , NULL , & snappath_dst ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
if ( timestamp_src ! = 0 ) {
2010-12-16 14:26:02 +03:00
errno = EXDEV ;
return - 1 ;
}
2011-06-20 11:52:21 +04:00
if ( timestamp_dst ! = 0 ) {
errno = EROFS ;
return - 1 ;
}
2017-01-27 04:19:24 +03:00
/*
* Don ' t allow rename on already converted paths .
*/
if ( snappath_src ! = NULL ) {
errno = EXDEV ;
return - 1 ;
}
if ( snappath_dst ! = NULL ) {
errno = EROFS ;
return - 1 ;
}
2011-06-20 11:52:21 +04:00
return SMB_VFS_NEXT_RENAME ( handle , smb_fname_src , smb_fname_dst ) ;
2008-01-16 12:21:38 +03:00
}
static int shadow_copy2_symlink ( vfs_handle_struct * handle ,
2017-06-09 02:25:58 +03:00
const char * link_contents ,
const struct smb_filename * new_smb_fname )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp_old = 0 ;
time_t timestamp_new = 0 ;
2017-01-27 04:19:24 +03:00
char * snappath_old = NULL ;
char * snappath_new = NULL ;
2008-01-16 12:21:38 +03:00
2017-06-09 02:25:58 +03:00
if ( ! shadow_copy2_strip_snapshot_internal ( talloc_tos ( ) ,
handle ,
link_contents ,
& timestamp_old ,
NULL ,
& snappath_old ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
2017-06-09 02:25:58 +03:00
if ( ! shadow_copy2_strip_snapshot_internal ( talloc_tos ( ) ,
handle ,
new_smb_fname - > base_name ,
& timestamp_new ,
NULL ,
& snappath_new ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
if ( ( timestamp_old ! = 0 ) | | ( timestamp_new ! = 0 ) ) {
errno = EROFS ;
return - 1 ;
}
2017-01-27 04:19:24 +03:00
/*
* Don ' t allow symlinks on already converted paths .
*/
if ( ( snappath_old ! = NULL ) | | ( snappath_new ! = NULL ) ) {
errno = EROFS ;
return - 1 ;
}
2017-06-09 02:25:58 +03:00
return SMB_VFS_NEXT_SYMLINK ( handle , link_contents , new_smb_fname ) ;
2008-01-16 12:21:38 +03:00
}
2011-06-20 11:52:21 +04:00
static int shadow_copy2_link ( vfs_handle_struct * handle ,
2017-06-03 00:21:54 +03:00
const struct smb_filename * old_smb_fname ,
const struct smb_filename * new_smb_fname )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp_old = 0 ;
time_t timestamp_new = 0 ;
2017-01-27 04:19:24 +03:00
char * snappath_old = NULL ;
char * snappath_new = NULL ;
2008-01-16 12:21:38 +03:00
2017-06-03 00:21:54 +03:00
if ( ! shadow_copy2_strip_snapshot_internal ( talloc_tos ( ) ,
handle ,
old_smb_fname - > base_name ,
& timestamp_old ,
NULL ,
& snappath_old ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
2017-06-03 00:21:54 +03:00
if ( ! shadow_copy2_strip_snapshot_internal ( talloc_tos ( ) ,
handle ,
new_smb_fname - > base_name ,
& timestamp_new ,
NULL ,
& snappath_new ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
if ( ( timestamp_old ! = 0 ) | | ( timestamp_new ! = 0 ) ) {
errno = EROFS ;
return - 1 ;
}
2017-01-27 04:19:24 +03:00
/*
* Don ' t allow links on already converted paths .
*/
if ( ( snappath_old ! = NULL ) | | ( snappath_new ! = NULL ) ) {
errno = EROFS ;
return - 1 ;
}
2017-06-03 00:21:54 +03:00
return SMB_VFS_NEXT_LINK ( handle , old_smb_fname , new_smb_fname ) ;
2008-01-16 12:21:38 +03:00
}
static int shadow_copy2_stat ( vfs_handle_struct * handle ,
2009-06-23 02:26:56 +04:00
struct smb_filename * smb_fname )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
char * tmp ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
int ret ;
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) , handle ,
smb_fname - > base_name ,
& timestamp , & stripped ) ) {
return - 1 ;
}
if ( timestamp = = 0 ) {
return SMB_VFS_NEXT_STAT ( handle , smb_fname ) ;
2008-01-16 12:21:38 +03:00
}
2011-06-20 11:52:21 +04:00
tmp = smb_fname - > base_name ;
smb_fname - > base_name = shadow_copy2_convert (
talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
2009-07-02 20:27:44 +04:00
2011-06-20 11:52:21 +04:00
if ( smb_fname - > base_name = = NULL ) {
smb_fname - > base_name = tmp ;
2009-07-02 20:27:44 +04:00
return - 1 ;
}
2011-06-20 11:52:21 +04:00
ret = SMB_VFS_NEXT_STAT ( handle , smb_fname ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( smb_fname - > base_name ) ;
smb_fname - > base_name = tmp ;
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
if ( ret = = 0 ) {
convert_sbuf ( handle , smb_fname - > base_name , & smb_fname - > st ) ;
}
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
2008-01-16 12:21:38 +03:00
}
2011-06-20 11:52:21 +04:00
static int shadow_copy2_lstat ( vfs_handle_struct * handle ,
struct smb_filename * smb_fname )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
char * tmp ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
int ret ;
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) , handle ,
smb_fname - > base_name ,
& timestamp , & stripped ) ) {
return - 1 ;
}
if ( timestamp = = 0 ) {
return SMB_VFS_NEXT_LSTAT ( handle , smb_fname ) ;
}
2009-07-03 00:39:20 +04:00
2011-06-20 11:52:21 +04:00
tmp = smb_fname - > base_name ;
smb_fname - > base_name = shadow_copy2_convert (
talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( smb_fname - > base_name = = NULL ) {
smb_fname - > base_name = tmp ;
2009-07-03 00:39:20 +04:00
return - 1 ;
}
2011-06-20 11:52:21 +04:00
ret = SMB_VFS_NEXT_LSTAT ( handle , smb_fname ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( smb_fname - > base_name ) ;
smb_fname - > base_name = tmp ;
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
if ( ret = = 0 ) {
convert_sbuf ( handle , smb_fname - > base_name , & smb_fname - > st ) ;
}
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
2008-01-16 12:21:38 +03:00
}
2011-06-20 11:52:21 +04:00
static int shadow_copy2_fstat ( vfs_handle_struct * handle , files_struct * fsp ,
SMB_STRUCT_STAT * sbuf )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
2011-06-20 11:52:21 +04:00
int ret ;
2009-09-16 05:22:56 +04:00
2011-06-20 11:52:21 +04:00
ret = SMB_VFS_NEXT_FSTAT ( handle , fsp , sbuf ) ;
if ( ret = = - 1 ) {
return ret ;
}
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) , handle ,
fsp - > fsp_name - > base_name ,
& timestamp , NULL ) ) {
return 0 ;
2009-06-30 16:26:32 +04:00
}
2011-06-20 11:52:21 +04:00
if ( timestamp ! = 0 ) {
convert_sbuf ( handle , fsp - > fsp_name - > base_name , sbuf ) ;
}
return 0 ;
2008-01-16 12:21:38 +03:00
}
2011-06-20 11:52:21 +04:00
static int shadow_copy2_open ( vfs_handle_struct * handle ,
struct smb_filename * smb_fname , files_struct * fsp ,
int flags , mode_t mode )
2009-02-02 13:52:08 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
char * tmp ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
int ret ;
2009-02-02 13:52:08 +03:00
2011-06-20 11:52:21 +04:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) , handle ,
smb_fname - > base_name ,
& timestamp , & stripped ) ) {
return - 1 ;
}
if ( timestamp = = 0 ) {
return SMB_VFS_NEXT_OPEN ( handle , smb_fname , fsp , flags , mode ) ;
2009-02-02 13:52:08 +03:00
}
2011-06-20 11:52:21 +04:00
tmp = smb_fname - > base_name ;
smb_fname - > base_name = shadow_copy2_convert (
talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
2011-03-14 20:35:36 +03:00
2011-06-20 11:52:21 +04:00
if ( smb_fname - > base_name = = NULL ) {
smb_fname - > base_name = tmp ;
return - 1 ;
2009-09-16 05:22:56 +04:00
}
2011-06-20 11:52:21 +04:00
ret = SMB_VFS_NEXT_OPEN ( handle , smb_fname , fsp , flags , mode ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2009-02-02 13:52:08 +03:00
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( smb_fname - > base_name ) ;
smb_fname - > base_name = tmp ;
2009-02-02 13:52:08 +03:00
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2009-02-02 13:52:08 +03:00
return ret ;
}
2011-06-20 11:52:21 +04:00
static int shadow_copy2_unlink ( vfs_handle_struct * handle ,
const struct smb_filename * smb_fname )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
int ret ;
2011-06-20 11:52:21 +04:00
struct smb_filename * conv ;
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) , handle ,
smb_fname - > base_name ,
& timestamp , & stripped ) ) {
return - 1 ;
}
if ( timestamp = = 0 ) {
return SMB_VFS_NEXT_UNLINK ( handle , smb_fname ) ;
}
2013-04-11 17:32:39 +04:00
conv = cp_smb_filename ( talloc_tos ( ) , smb_fname ) ;
if ( conv = = NULL ) {
2011-06-20 11:52:21 +04:00
errno = ENOMEM ;
return - 1 ;
}
conv - > base_name = shadow_copy2_convert (
conv , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv - > base_name = = NULL ) {
return - 1 ;
}
ret = SMB_VFS_NEXT_UNLINK ( handle , conv ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
2008-01-16 12:21:38 +03:00
}
2016-03-02 03:20:25 +03:00
static int shadow_copy2_chmod ( vfs_handle_struct * handle ,
const struct smb_filename * smb_fname ,
mode_t mode )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
2016-03-02 03:20:25 +03:00
char * stripped = NULL ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
int ret ;
2016-03-02 03:20:25 +03:00
char * conv = NULL ;
struct smb_filename * conv_smb_fname ;
2011-06-20 11:52:21 +04:00
2016-03-02 03:20:25 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
if ( timestamp = = 0 ) {
2016-03-02 03:20:25 +03:00
TALLOC_FREE ( stripped ) ;
return SMB_VFS_NEXT_CHMOD ( handle , smb_fname , mode ) ;
2011-06-20 11:52:21 +04:00
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return - 1 ;
}
2016-03-02 03:20:25 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
2016-03-19 07:19:38 +03:00
NULL ,
smb_fname - > flags ) ;
2016-03-02 03:20:25 +03:00
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
errno = ENOMEM ;
return - 1 ;
}
ret = SMB_VFS_NEXT_CHMOD ( handle , conv_smb_fname , mode ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2016-03-02 03:20:25 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
2008-01-16 12:21:38 +03:00
}
2016-03-03 22:54:23 +03:00
static int shadow_copy2_chown ( vfs_handle_struct * handle ,
const struct smb_filename * smb_fname ,
uid_t uid ,
gid_t gid )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
int ret ;
2016-03-03 22:54:23 +03:00
char * conv = NULL ;
struct smb_filename * conv_smb_fname = NULL ;
2011-06-20 11:52:21 +04:00
2016-03-03 22:54:23 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
if ( timestamp = = 0 ) {
2016-03-03 22:54:23 +03:00
return SMB_VFS_NEXT_CHOWN ( handle , smb_fname , uid , gid ) ;
2011-06-20 11:52:21 +04:00
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return - 1 ;
}
2016-03-03 22:54:23 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
2016-03-19 07:19:38 +03:00
NULL ,
smb_fname - > flags ) ;
2016-03-03 22:54:23 +03:00
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
errno = ENOMEM ;
return - 1 ;
}
ret = SMB_VFS_NEXT_CHOWN ( handle , conv_smb_fname , uid , gid ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2016-03-03 22:54:23 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
2008-01-16 12:21:38 +03:00
}
2017-01-20 23:06:55 +03:00
static void store_cwd_data ( vfs_handle_struct * handle ,
const char * connectpath )
{
struct shadow_copy2_private * priv = NULL ;
2017-06-30 00:32:47 +03:00
struct smb_filename * cwd_fname = NULL ;
2017-01-20 23:06:55 +03:00
SMB_VFS_HANDLE_GET_DATA ( handle , priv , struct shadow_copy2_private ,
return ) ;
TALLOC_FREE ( priv - > shadow_cwd ) ;
2017-06-30 00:32:47 +03:00
cwd_fname = SMB_VFS_NEXT_GETWD ( handle , talloc_tos ( ) ) ;
if ( cwd_fname = = NULL ) {
2017-01-20 23:06:55 +03:00
smb_panic ( " getwd failed \n " ) ;
}
2017-06-30 00:32:47 +03:00
DBG_DEBUG ( " shadow cwd = %s \n " , cwd_fname - > base_name ) ;
priv - > shadow_cwd = talloc_strdup ( priv , cwd_fname - > base_name ) ;
TALLOC_FREE ( cwd_fname ) ;
2017-01-20 23:06:55 +03:00
if ( priv - > shadow_cwd = = NULL ) {
smb_panic ( " talloc failed \n " ) ;
}
TALLOC_FREE ( priv - > shadow_connectpath ) ;
if ( connectpath ) {
DBG_DEBUG ( " shadow conectpath = %s \n " , connectpath ) ;
priv - > shadow_connectpath = talloc_strdup ( priv , connectpath ) ;
if ( priv - > shadow_connectpath = = NULL ) {
smb_panic ( " talloc failed \n " ) ;
}
}
}
2011-06-20 11:52:21 +04:00
static int shadow_copy2_chdir ( vfs_handle_struct * handle ,
2017-06-29 21:29:33 +03:00
const struct smb_filename * smb_fname )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2017-01-20 23:06:55 +03:00
char * snappath = NULL ;
int ret = - 1 ;
int saved_errno = 0 ;
char * conv = NULL ;
size_t rootpath_len = 0 ;
2017-06-29 21:29:33 +03:00
struct smb_filename * conv_smb_fname = NULL ;
2011-06-20 11:52:21 +04:00
2017-06-29 21:29:33 +03:00
if ( ! shadow_copy2_strip_snapshot_internal ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ,
& snappath ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
2017-01-20 23:06:55 +03:00
if ( stripped ! = NULL ) {
conv = shadow_copy2_do_convert ( talloc_tos ( ) ,
handle ,
stripped ,
timestamp ,
& rootpath_len ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return - 1 ;
}
2017-06-29 21:29:33 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
NULL ,
smb_fname - > flags ) ;
} else {
conv_smb_fname = cp_smb_filename ( talloc_tos ( ) , smb_fname ) ;
}
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
errno = ENOMEM ;
return - 1 ;
2011-06-20 11:52:21 +04:00
}
2017-01-20 23:06:55 +03:00
2017-06-29 21:29:33 +03:00
ret = SMB_VFS_NEXT_CHDIR ( handle , conv_smb_fname ) ;
2017-01-20 23:06:55 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
2011-06-20 11:52:21 +04:00
}
2017-01-20 23:06:55 +03:00
if ( ret = = 0 ) {
if ( conv ! = NULL & & rootpath_len ! = 0 ) {
conv [ rootpath_len ] = ' \0 ' ;
} else if ( snappath ! = 0 ) {
TALLOC_FREE ( conv ) ;
conv = snappath ;
}
store_cwd_data ( handle , conv ) ;
}
TALLOC_FREE ( stripped ) ;
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2017-06-29 21:29:33 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2017-01-20 23:06:55 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
2008-01-16 12:21:38 +03:00
}
2011-06-20 11:52:21 +04:00
static int shadow_copy2_ntimes ( vfs_handle_struct * handle ,
const struct smb_filename * smb_fname ,
struct smb_file_time * ft )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
int ret ;
2011-06-20 11:52:21 +04:00
struct smb_filename * conv ;
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) , handle ,
smb_fname - > base_name ,
& timestamp , & stripped ) ) {
return - 1 ;
}
if ( timestamp = = 0 ) {
return SMB_VFS_NEXT_NTIMES ( handle , smb_fname , ft ) ;
}
2013-04-11 17:33:44 +04:00
conv = cp_smb_filename ( talloc_tos ( ) , smb_fname ) ;
if ( conv = = NULL ) {
2011-06-20 11:52:21 +04:00
errno = ENOMEM ;
return - 1 ;
}
conv - > base_name = shadow_copy2_convert (
conv , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv - > base_name = = NULL ) {
return - 1 ;
}
ret = SMB_VFS_NEXT_NTIMES ( handle , conv , ft ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
2008-01-16 12:21:38 +03:00
}
2011-06-20 11:52:21 +04:00
static int shadow_copy2_readlink ( vfs_handle_struct * handle ,
2017-06-08 01:03:37 +03:00
const struct smb_filename * smb_fname ,
char * buf ,
size_t bufsiz )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
int ret ;
2017-06-08 01:03:37 +03:00
struct smb_filename * conv = NULL ;
2011-06-20 11:52:21 +04:00
2017-06-08 01:03:37 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) , handle ,
smb_fname - > base_name ,
2011-06-20 11:52:21 +04:00
& timestamp , & stripped ) ) {
return - 1 ;
}
if ( timestamp = = 0 ) {
2017-06-08 01:03:37 +03:00
return SMB_VFS_NEXT_READLINK ( handle , smb_fname , buf , bufsiz ) ;
2011-06-20 11:52:21 +04:00
}
2017-06-08 01:03:37 +03:00
conv = cp_smb_filename ( talloc_tos ( ) , smb_fname ) ;
2011-06-20 11:52:21 +04:00
if ( conv = = NULL ) {
2017-06-08 01:03:37 +03:00
TALLOC_FREE ( stripped ) ;
errno = ENOMEM ;
return - 1 ;
}
conv - > base_name = shadow_copy2_convert (
conv , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv - > base_name = = NULL ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
ret = SMB_VFS_NEXT_READLINK ( handle , conv , buf , bufsiz ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
2008-01-16 12:21:38 +03:00
}
2011-06-20 11:52:21 +04:00
static int shadow_copy2_mknod ( vfs_handle_struct * handle ,
2017-05-20 01:01:52 +03:00
const struct smb_filename * smb_fname ,
mode_t mode ,
SMB_DEV_T dev )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
int ret ;
2017-05-20 01:01:52 +03:00
struct smb_filename * conv = NULL ;
2011-06-20 11:52:21 +04:00
2017-05-20 01:01:52 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) , handle ,
smb_fname - > base_name ,
2011-06-20 11:52:21 +04:00
& timestamp , & stripped ) ) {
return - 1 ;
}
if ( timestamp = = 0 ) {
2017-05-20 01:01:52 +03:00
return SMB_VFS_NEXT_MKNOD ( handle , smb_fname , mode , dev ) ;
2011-06-20 11:52:21 +04:00
}
2017-05-20 01:01:52 +03:00
conv = cp_smb_filename ( talloc_tos ( ) , smb_fname ) ;
2011-06-20 11:52:21 +04:00
if ( conv = = NULL ) {
2017-05-20 01:01:52 +03:00
errno = ENOMEM ;
return - 1 ;
}
conv - > base_name = shadow_copy2_convert (
conv , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv - > base_name = = NULL ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
ret = SMB_VFS_NEXT_MKNOD ( handle , conv , mode , dev ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
2008-01-16 12:21:38 +03:00
}
2017-06-30 21:32:59 +03:00
static struct smb_filename * shadow_copy2_realpath ( vfs_handle_struct * handle ,
TALLOC_CTX * ctx ,
const struct smb_filename * smb_fname )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
2011-06-20 11:52:21 +04:00
char * stripped = NULL ;
2017-06-30 21:32:59 +03:00
struct smb_filename * result_fname = NULL ;
struct smb_filename * conv_fname = NULL ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
2011-06-20 11:52:21 +04:00
2017-06-30 21:32:59 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) , handle ,
smb_fname - > base_name ,
& timestamp , & stripped ) ) {
2011-06-20 11:52:21 +04:00
goto done ;
}
if ( timestamp = = 0 ) {
2017-06-30 21:32:59 +03:00
return SMB_VFS_NEXT_REALPATH ( handle , ctx , smb_fname ) ;
2011-06-20 11:52:21 +04:00
}
2017-06-30 21:32:59 +03:00
conv_fname = cp_smb_filename ( talloc_tos ( ) , smb_fname ) ;
if ( conv_fname = = NULL ) {
goto done ;
}
conv_fname - > base_name = shadow_copy2_convert (
conv_fname , handle , stripped , timestamp ) ;
if ( conv_fname - > base_name = = NULL ) {
2011-06-20 11:52:21 +04:00
goto done ;
}
2017-06-30 21:32:59 +03:00
result_fname = SMB_VFS_NEXT_REALPATH ( handle , ctx , conv_fname ) ;
2011-06-20 11:52:21 +04:00
done :
2017-06-30 21:32:59 +03:00
if ( result_fname = = NULL ) {
2017-01-23 21:20:13 +03:00
saved_errno = errno ;
}
2017-06-30 21:32:59 +03:00
TALLOC_FREE ( conv_fname ) ;
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( stripped ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2017-06-30 21:32:59 +03:00
return result_fname ;
2008-01-16 12:21:38 +03:00
}
2013-05-24 01:59:49 +04:00
/**
* Check whether a given directory contains a
* snapshot directory as direct subdirectory .
* If yes , return the path of the snapshot - subdir ,
* otherwise return NULL .
*/
2011-06-20 11:52:21 +04:00
static char * have_snapdir ( struct vfs_handle_struct * handle ,
const char * path )
2008-01-16 12:21:38 +03:00
{
2011-06-20 11:52:21 +04:00
struct smb_filename smb_fname ;
int ret ;
2016-07-11 14:27:37 +03:00
struct shadow_copy2_private * priv ;
2013-05-24 03:35:44 +04:00
2016-07-11 14:27:37 +03:00
SMB_VFS_HANDLE_GET_DATA ( handle , priv , struct shadow_copy2_private ,
2013-05-24 03:35:44 +04:00
return NULL ) ;
2011-06-20 11:52:21 +04:00
ZERO_STRUCT ( smb_fname ) ;
2013-05-24 03:35:44 +04:00
smb_fname . base_name = talloc_asprintf ( talloc_tos ( ) , " %s/%s " ,
2016-07-11 14:27:37 +03:00
path , priv - > config - > snapdir ) ;
2011-06-20 11:52:21 +04:00
if ( smb_fname . base_name = = NULL ) {
return NULL ;
}
ret = SMB_VFS_NEXT_STAT ( handle , & smb_fname ) ;
if ( ( ret = = 0 ) & & ( S_ISDIR ( smb_fname . st . st_ex_mode ) ) ) {
return smb_fname . base_name ;
}
TALLOC_FREE ( smb_fname . base_name ) ;
return NULL ;
2008-01-16 12:21:38 +03:00
}
2015-10-24 00:54:31 +03:00
static bool check_access_snapdir ( struct vfs_handle_struct * handle ,
const char * path )
{
struct smb_filename smb_fname ;
int ret ;
NTSTATUS status ;
ZERO_STRUCT ( smb_fname ) ;
smb_fname . base_name = talloc_asprintf ( talloc_tos ( ) ,
" %s " ,
path ) ;
if ( smb_fname . base_name = = NULL ) {
return false ;
}
ret = SMB_VFS_NEXT_STAT ( handle , & smb_fname ) ;
if ( ret ! = 0 | | ! S_ISDIR ( smb_fname . st . st_ex_mode ) ) {
TALLOC_FREE ( smb_fname . base_name ) ;
return false ;
}
status = smbd_check_access_rights ( handle - > conn ,
& smb_fname ,
false ,
SEC_DIR_LIST ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " user does not have list permission "
" on snapdir %s \n " ,
smb_fname . base_name ) ) ;
TALLOC_FREE ( smb_fname . base_name ) ;
return false ;
}
TALLOC_FREE ( smb_fname . base_name ) ;
return true ;
}
2013-05-24 02:01:14 +04:00
/**
* Find the snapshot directory ( if any ) for the given
* filename ( which is relative to the share ) .
*/
2013-05-28 19:01:20 +04:00
static const char * shadow_copy2_find_snapdir ( TALLOC_CTX * mem_ctx ,
struct vfs_handle_struct * handle ,
struct smb_filename * smb_fname )
2008-01-16 12:21:38 +03:00
{
2011-06-20 11:52:21 +04:00
char * path , * p ;
2013-05-28 19:01:20 +04:00
const char * snapdir ;
2013-05-24 03:35:44 +04:00
struct shadow_copy2_config * config ;
2016-07-11 14:27:37 +03:00
struct shadow_copy2_private * priv ;
2013-05-24 03:35:44 +04:00
2016-07-11 14:27:37 +03:00
SMB_VFS_HANDLE_GET_DATA ( handle , priv , struct shadow_copy2_private ,
2013-05-24 03:35:44 +04:00
return NULL ) ;
2011-06-20 11:52:21 +04:00
2016-07-11 14:27:37 +03:00
config = priv - > config ;
2013-05-23 18:21:46 +04:00
/*
* If the non - snapdisrseverywhere mode , we should not search !
*/
if ( ! config - > snapdirseverywhere ) {
return config - > snapshot_basepath ;
}
2011-06-20 11:52:21 +04:00
path = talloc_asprintf ( mem_ctx , " %s/%s " ,
handle - > conn - > connectpath ,
smb_fname - > base_name ) ;
if ( path = = NULL ) {
return NULL ;
}
snapdir = have_snapdir ( handle , path ) ;
if ( snapdir ! = NULL ) {
TALLOC_FREE ( path ) ;
return snapdir ;
}
while ( ( p = strrchr ( path , ' / ' ) ) & & ( p > path ) ) {
p [ 0 ] = ' \0 ' ;
snapdir = have_snapdir ( handle , path ) ;
if ( snapdir ! = NULL ) {
TALLOC_FREE ( path ) ;
return snapdir ;
}
}
TALLOC_FREE ( path ) ;
return NULL ;
2008-01-16 12:21:38 +03:00
}
2012-05-08 11:15:12 +04:00
static bool shadow_copy2_snapshot_to_gmt ( vfs_handle_struct * handle ,
2011-06-20 11:52:21 +04:00
const char * name ,
char * gmt , size_t gmt_len )
2008-01-16 12:21:38 +03:00
{
2011-06-20 11:52:21 +04:00
struct tm timestamp ;
time_t timestamp_t ;
2012-07-02 13:31:58 +04:00
unsigned long int timestamp_long ;
2011-06-20 11:52:21 +04:00
const char * fmt ;
2013-05-24 03:35:44 +04:00
struct shadow_copy2_config * config ;
2016-07-11 14:27:37 +03:00
struct shadow_copy2_private * priv ;
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
char * tmpstr = NULL ;
char * tmp = NULL ;
bool converted = false ;
int ret = - 1 ;
2011-06-20 11:52:21 +04:00
2016-07-11 14:27:37 +03:00
SMB_VFS_HANDLE_GET_DATA ( handle , priv , struct shadow_copy2_private ,
2013-05-24 03:35:44 +04:00
return NULL ) ;
2016-07-11 14:27:37 +03:00
config = priv - > config ;
2013-05-24 03:35:44 +04:00
fmt = config - > gmt_format ;
2011-06-20 11:52:21 +04:00
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
/*
* If regex is provided , then we will have to parse the
* filename which will contain both the prefix and the time format .
* e . g . < prefix > < delimiter > < time_format >
*/
if ( priv - > snaps - > regex ! = NULL ) {
tmpstr = talloc_strdup ( talloc_tos ( ) , name ) ;
/* point "name" to the time format */
name = strstr ( name , priv - > config - > delimiter ) ;
if ( name = = NULL ) {
goto done ;
}
/* Extract the prefix */
tmp = strstr ( tmpstr , priv - > config - > delimiter ) ;
2017-02-16 19:15:38 +03:00
if ( tmp = = NULL ) {
goto done ;
}
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
* tmp = ' \0 ' ;
/* Parse regex */
ret = regexec ( priv - > snaps - > regex , tmpstr , 0 , NULL , 0 ) ;
if ( ret ) {
DBG_DEBUG ( " shadow_copy2_snapshot_to_gmt: "
" no regex match for %s \n " , tmpstr ) ;
goto done ;
}
}
2011-06-20 11:52:21 +04:00
ZERO_STRUCT ( timestamp ) ;
2013-05-24 03:35:44 +04:00
if ( config - > use_sscanf ) {
2012-07-02 13:31:58 +04:00
if ( sscanf ( name , fmt , & timestamp_long ) ! = 1 ) {
2013-10-04 15:15:34 +04:00
DEBUG ( 10 , ( " shadow_copy2_snapshot_to_gmt: "
" no sscanf match %s: %s \n " ,
2012-07-02 13:31:58 +04:00
fmt , name ) ) ;
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
goto done ;
2012-07-02 13:31:58 +04:00
}
timestamp_t = timestamp_long ;
2011-06-20 11:52:21 +04:00
gmtime_r ( & timestamp_t , & timestamp ) ;
2012-07-02 13:31:58 +04:00
} else {
if ( strptime ( name , fmt , & timestamp ) = = NULL ) {
2013-10-04 15:15:34 +04:00
DEBUG ( 10 , ( " shadow_copy2_snapshot_to_gmt: "
" no match %s: %s \n " ,
2012-07-02 13:31:58 +04:00
fmt , name ) ) ;
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
goto done ;
2012-07-02 13:31:58 +04:00
}
2013-10-04 15:15:34 +04:00
DEBUG ( 10 , ( " shadow_copy2_snapshot_to_gmt: match %s: %s \n " ,
fmt , name ) ) ;
2012-07-02 13:31:58 +04:00
2013-05-24 03:35:44 +04:00
if ( config - > use_localtime ) {
2012-07-02 13:31:58 +04:00
timestamp . tm_isdst = - 1 ;
timestamp_t = mktime ( & timestamp ) ;
gmtime_r ( & timestamp_t , & timestamp ) ;
}
2011-06-20 11:52:21 +04:00
}
2012-07-02 13:31:58 +04:00
2011-06-20 11:52:21 +04:00
strftime ( gmt , gmt_len , GMT_FORMAT , & timestamp ) ;
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
converted = true ;
done :
TALLOC_FREE ( tmpstr ) ;
return converted ;
2008-01-16 12:21:38 +03:00
}
2009-12-07 06:00:00 +03:00
static int shadow_copy2_label_cmp_asc ( const void * x , const void * y )
{
2011-05-06 03:19:49 +04:00
return strncmp ( ( const char * ) x , ( const char * ) y , sizeof ( SHADOW_COPY_LABEL ) ) ;
2009-12-07 06:00:00 +03:00
}
static int shadow_copy2_label_cmp_desc ( const void * x , const void * y )
{
2011-05-06 03:19:49 +04:00
return - strncmp ( ( const char * ) x , ( const char * ) y , sizeof ( SHADOW_COPY_LABEL ) ) ;
2009-12-07 06:00:00 +03:00
}
/*
sort the shadow copy data in ascending or descending order
*/
static void shadow_copy2_sort_data ( vfs_handle_struct * handle ,
2011-05-30 14:06:31 +04:00
struct shadow_copy_data * shadow_copy2_data )
2009-12-07 06:00:00 +03:00
{
int ( * cmpfunc ) ( const void * , const void * ) ;
const char * sort ;
2016-07-11 14:27:37 +03:00
struct shadow_copy2_private * priv ;
2013-05-24 03:35:44 +04:00
2016-07-11 14:27:37 +03:00
SMB_VFS_HANDLE_GET_DATA ( handle , priv , struct shadow_copy2_private ,
2013-05-24 03:35:44 +04:00
return ) ;
2009-12-07 06:00:00 +03:00
2016-07-11 14:27:37 +03:00
sort = priv - > config - > sort_order ;
2009-12-07 06:00:00 +03:00
if ( sort = = NULL ) {
return ;
}
if ( strcmp ( sort , " asc " ) = = 0 ) {
cmpfunc = shadow_copy2_label_cmp_asc ;
} else if ( strcmp ( sort , " desc " ) = = 0 ) {
cmpfunc = shadow_copy2_label_cmp_desc ;
} else {
return ;
}
if ( shadow_copy2_data & & shadow_copy2_data - > num_volumes > 0 & &
shadow_copy2_data - > labels )
{
2010-02-14 02:01:17 +03:00
TYPESAFE_QSORT ( shadow_copy2_data - > labels ,
shadow_copy2_data - > num_volumes ,
cmpfunc ) ;
2009-12-07 06:00:00 +03:00
}
}
2011-06-20 11:52:21 +04:00
static int shadow_copy2_get_shadow_copy_data (
vfs_handle_struct * handle , files_struct * fsp ,
struct shadow_copy_data * shadow_copy2_data ,
bool labels )
2008-01-16 12:21:38 +03:00
{
2012-03-28 06:22:03 +04:00
DIR * p ;
2008-01-16 12:21:38 +03:00
const char * snapdir ;
2016-02-27 01:53:12 +03:00
struct smb_filename * snapdir_smb_fname = NULL ;
2012-03-28 06:18:14 +04:00
struct dirent * d ;
2011-06-20 11:52:21 +04:00
TALLOC_CTX * tmp_ctx = talloc_stackframe ( ) ;
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
struct shadow_copy2_private * priv = NULL ;
struct shadow_copy2_snapentry * tmpentry = NULL ;
bool get_snaplist = false ;
2016-07-21 12:58:43 +03:00
bool access_granted = false ;
int ret = - 1 ;
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
snapdir = shadow_copy2_find_snapdir ( tmp_ctx , handle , fsp - > fsp_name ) ;
2008-01-16 12:21:38 +03:00
if ( snapdir = = NULL ) {
DEBUG ( 0 , ( " shadow:snapdir not found for %s in get_shadow_copy_data \n " ,
handle - > conn - > connectpath ) ) ;
errno = EINVAL ;
2016-07-21 12:58:43 +03:00
goto done ;
2008-01-16 12:21:38 +03:00
}
2016-07-21 12:58:43 +03:00
access_granted = check_access_snapdir ( handle , snapdir ) ;
if ( ! access_granted ) {
2015-10-24 00:54:31 +03:00
DEBUG ( 0 , ( " access denied on listing snapdir %s \n " , snapdir ) ) ;
errno = EACCES ;
2016-07-21 12:58:43 +03:00
goto done ;
2015-10-24 00:54:31 +03:00
}
2008-01-16 12:21:38 +03:00
2016-02-27 01:53:12 +03:00
snapdir_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
snapdir ,
NULL ,
2016-03-19 07:19:38 +03:00
NULL ,
fsp - > fsp_name - > flags ) ;
2016-02-27 01:53:12 +03:00
if ( snapdir_smb_fname = = NULL ) {
errno = ENOMEM ;
2016-07-21 12:58:43 +03:00
goto done ;
2016-02-27 01:53:12 +03:00
}
p = SMB_VFS_NEXT_OPENDIR ( handle , snapdir_smb_fname , NULL , 0 ) ;
2008-01-16 12:21:38 +03:00
if ( ! p ) {
2009-04-28 13:16:19 +04:00
DEBUG ( 2 , ( " shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s' "
" - %s \n " , snapdir , strerror ( errno ) ) ) ;
errno = ENOSYS ;
2016-07-21 12:58:43 +03:00
goto done ;
2008-01-16 12:21:38 +03:00
}
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
if ( shadow_copy2_data ! = NULL ) {
shadow_copy2_data - > num_volumes = 0 ;
shadow_copy2_data - > labels = NULL ;
}
SMB_VFS_HANDLE_GET_DATA ( handle , priv , struct shadow_copy2_private ,
2016-07-21 12:58:43 +03:00
goto done ) ;
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
/*
* Normally this function is called twice once with labels = false and
* then with labels = true . When labels is false it will return the
* number of volumes so that the caller can allocate memory for that
* many labels . Therefore to eliminate snaplist both the times it is
* good to check if labels is set or not .
*
* shadow_copy2_data is NULL when we only want to update the list and
* don ' t want any labels .
*/
if ( ( priv - > snaps - > regex ! = NULL ) & & ( labels | | shadow_copy2_data = = NULL ) ) {
get_snaplist = true ;
/* Reset the global snaplist */
shadow_copy2_delete_snaplist ( priv ) ;
/* Set the current time as snaplist update time */
time ( & ( priv - > snaps - > fetch_time ) ) ;
}
2008-01-16 12:21:38 +03:00
2009-01-23 07:14:38 +03:00
while ( ( d = SMB_VFS_NEXT_READDIR ( handle , p , NULL ) ) ) {
2011-06-20 11:52:21 +04:00
char snapshot [ GMT_NAME_LEN + 1 ] ;
2008-01-16 12:21:38 +03:00
SHADOW_COPY_LABEL * tlabels ;
2011-06-20 11:52:21 +04:00
/*
* ignore names not of the right form in the snapshot
* directory
*/
if ( ! shadow_copy2_snapshot_to_gmt (
2012-05-08 11:15:12 +04:00
handle , d - > d_name ,
2011-06-20 11:52:21 +04:00
snapshot , sizeof ( snapshot ) ) ) {
DEBUG ( 6 , ( " shadow_copy2_get_shadow_copy_data: "
" ignoring %s \n " , d - > d_name ) ) ;
2008-01-16 12:21:38 +03:00
continue ;
}
2011-06-20 11:52:21 +04:00
DEBUG ( 6 , ( " shadow_copy2_get_shadow_copy_data: %s -> %s \n " ,
d - > d_name , snapshot ) ) ;
2008-01-16 12:21:38 +03:00
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
if ( get_snaplist ) {
/*
* Create a snap entry for each successful
* pattern match .
*/
tmpentry = shadow_copy2_create_snapentry ( priv ) ;
if ( tmpentry = = NULL ) {
DBG_ERR ( " talloc_zero() failed \n " ) ;
2016-07-21 12:58:43 +03:00
goto done ;
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
}
tmpentry - > snapname = talloc_strdup ( tmpentry , d - > d_name ) ;
tmpentry - > time_fmt = talloc_strdup ( tmpentry , snapshot ) ;
}
if ( shadow_copy2_data = = NULL ) {
continue ;
}
2008-01-16 12:21:38 +03:00
if ( ! labels ) {
/* the caller doesn't want the labels */
shadow_copy2_data - > num_volumes + + ;
continue ;
}
2011-05-30 14:11:53 +04:00
tlabels = talloc_realloc ( shadow_copy2_data ,
2008-01-16 12:21:38 +03:00
shadow_copy2_data - > labels ,
2011-06-20 11:52:21 +04:00
SHADOW_COPY_LABEL ,
shadow_copy2_data - > num_volumes + 1 ) ;
2008-01-16 12:21:38 +03:00
if ( tlabels = = NULL ) {
DEBUG ( 0 , ( " shadow_copy2: out of memory \n " ) ) ;
SMB_VFS_NEXT_CLOSEDIR ( handle , p ) ;
2016-07-21 12:58:43 +03:00
goto done ;
2008-01-16 12:21:38 +03:00
}
2010-01-21 10:30:01 +03:00
strlcpy ( tlabels [ shadow_copy2_data - > num_volumes ] , snapshot ,
sizeof ( * tlabels ) ) ;
2008-01-16 12:21:38 +03:00
shadow_copy2_data - > num_volumes + + ;
shadow_copy2_data - > labels = tlabels ;
}
SMB_VFS_NEXT_CLOSEDIR ( handle , p ) ;
2009-12-07 06:00:00 +03:00
shadow_copy2_sort_data ( handle , shadow_copy2_data ) ;
2016-07-21 12:58:43 +03:00
ret = 0 ;
2009-12-07 06:00:00 +03:00
2016-07-21 12:58:43 +03:00
done :
TALLOC_FREE ( tmp_ctx ) ;
return ret ;
2008-01-16 12:21:38 +03:00
}
2011-06-20 11:52:21 +04:00
static NTSTATUS shadow_copy2_fget_nt_acl ( vfs_handle_struct * handle ,
struct files_struct * fsp ,
2015-05-03 06:11:02 +03:00
uint32_t security_info ,
2012-10-10 04:50:27 +04:00
TALLOC_CTX * mem_ctx ,
2011-06-20 11:52:21 +04:00
struct security_descriptor * * ppdesc )
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2011-06-20 11:52:21 +04:00
NTSTATUS status ;
char * conv ;
2016-02-12 21:30:10 +03:00
struct smb_filename * smb_fname = NULL ;
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) , handle ,
fsp - > fsp_name - > base_name ,
& timestamp , & stripped ) ) {
return map_nt_error_from_unix ( errno ) ;
}
if ( timestamp = = 0 ) {
return SMB_VFS_NEXT_FGET_NT_ACL ( handle , fsp , security_info ,
2012-10-10 04:50:27 +04:00
mem_ctx ,
2011-06-20 11:52:21 +04:00
ppdesc ) ;
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return map_nt_error_from_unix ( errno ) ;
}
2016-02-12 21:30:10 +03:00
smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
2016-03-19 07:19:38 +03:00
NULL ,
fsp - > fsp_name - > flags ) ;
2016-02-12 21:30:10 +03:00
if ( smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
return NT_STATUS_NO_MEMORY ;
}
status = SMB_VFS_NEXT_GET_NT_ACL ( handle , smb_fname , security_info ,
2012-10-10 04:50:27 +04:00
mem_ctx , ppdesc ) ;
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2016-02-12 21:30:10 +03:00
TALLOC_FREE ( smb_fname ) ;
2011-06-20 11:52:21 +04:00
return status ;
}
static NTSTATUS shadow_copy2_get_nt_acl ( vfs_handle_struct * handle ,
2016-02-12 21:30:10 +03:00
const struct smb_filename * smb_fname ,
2015-05-03 06:11:02 +03:00
uint32_t security_info ,
2012-10-10 04:50:27 +04:00
TALLOC_CTX * mem_ctx ,
2011-06-20 11:52:21 +04:00
struct security_descriptor * * ppdesc )
2008-01-16 12:21:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2011-06-20 11:52:21 +04:00
NTSTATUS status ;
char * conv ;
2016-02-12 21:30:10 +03:00
struct smb_filename * conv_smb_fname = NULL ;
2008-01-16 12:21:38 +03:00
2016-02-12 21:30:10 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ) ) {
2011-06-20 11:52:21 +04:00
return map_nt_error_from_unix ( errno ) ;
}
if ( timestamp = = 0 ) {
2016-02-12 21:30:10 +03:00
return SMB_VFS_NEXT_GET_NT_ACL ( handle , smb_fname , security_info ,
2012-10-10 04:50:27 +04:00
mem_ctx , ppdesc ) ;
2011-06-20 11:52:21 +04:00
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return map_nt_error_from_unix ( errno ) ;
}
2016-02-12 21:30:10 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
2016-03-19 07:19:38 +03:00
NULL ,
smb_fname - > flags ) ;
2016-02-12 21:30:10 +03:00
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
return NT_STATUS_NO_MEMORY ;
}
status = SMB_VFS_NEXT_GET_NT_ACL ( handle , conv_smb_fname , security_info ,
2012-10-10 04:50:27 +04:00
mem_ctx , ppdesc ) ;
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2016-02-12 21:30:10 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2011-06-20 11:52:21 +04:00
return status ;
}
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
static int shadow_copy2_mkdir ( vfs_handle_struct * handle ,
2016-02-24 00:14:03 +03:00
const struct smb_filename * smb_fname ,
mode_t mode )
2011-06-20 11:52:21 +04:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
int ret ;
2011-06-20 11:52:21 +04:00
char * conv ;
2016-02-24 00:14:03 +03:00
struct smb_filename * conv_smb_fname = NULL ;
2008-01-16 12:21:38 +03:00
2016-02-24 00:14:03 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
if ( timestamp = = 0 ) {
2016-02-24 00:14:03 +03:00
return SMB_VFS_NEXT_MKDIR ( handle , smb_fname , mode ) ;
2011-06-20 11:52:21 +04:00
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return - 1 ;
}
2016-02-24 00:14:03 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
2016-03-19 07:19:38 +03:00
NULL ,
smb_fname - > flags ) ;
2016-02-24 00:14:03 +03:00
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
return - 1 ;
}
ret = SMB_VFS_NEXT_MKDIR ( handle , conv_smb_fname , mode ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2016-02-24 00:14:03 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
}
2016-02-25 01:02:45 +03:00
static int shadow_copy2_rmdir ( vfs_handle_struct * handle ,
const struct smb_filename * smb_fname )
2011-06-20 11:52:21 +04:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
int ret ;
2011-06-20 11:52:21 +04:00
char * conv ;
2016-02-25 01:02:45 +03:00
struct smb_filename * conv_smb_fname = NULL ;
2011-06-20 11:52:21 +04:00
2016-02-25 01:02:45 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
if ( timestamp = = 0 ) {
2016-02-25 01:02:45 +03:00
return SMB_VFS_NEXT_RMDIR ( handle , smb_fname ) ;
2011-06-20 11:52:21 +04:00
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return - 1 ;
}
2016-02-25 01:02:45 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
2016-03-19 07:19:38 +03:00
NULL ,
smb_fname - > flags ) ;
2016-02-25 01:02:45 +03:00
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
return - 1 ;
}
ret = SMB_VFS_NEXT_RMDIR ( handle , conv_smb_fname ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2016-02-25 01:02:45 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
}
2017-05-20 02:15:55 +03:00
static int shadow_copy2_chflags ( vfs_handle_struct * handle ,
const struct smb_filename * smb_fname ,
2011-06-20 11:52:21 +04:00
unsigned int flags )
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
int ret ;
2011-06-20 11:52:21 +04:00
char * conv ;
2017-05-20 02:15:55 +03:00
struct smb_filename * conv_smb_fname = NULL ;
2011-06-20 11:52:21 +04:00
2017-05-20 02:15:55 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
if ( timestamp = = 0 ) {
2017-05-20 02:15:55 +03:00
return SMB_VFS_NEXT_CHFLAGS ( handle , smb_fname , flags ) ;
2011-06-20 11:52:21 +04:00
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return - 1 ;
}
2017-05-20 02:15:55 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
NULL ,
smb_fname - > flags ) ;
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
return - 1 ;
}
ret = SMB_VFS_NEXT_CHFLAGS ( handle , smb_fname , flags ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2017-05-20 02:15:55 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
}
static ssize_t shadow_copy2_getxattr ( vfs_handle_struct * handle ,
2017-05-26 02:42:04 +03:00
const struct smb_filename * smb_fname ,
const char * aname ,
void * value ,
size_t size )
2011-06-20 11:52:21 +04:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2011-06-20 11:52:21 +04:00
ssize_t ret ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
2011-06-20 11:52:21 +04:00
char * conv ;
2017-05-26 02:42:04 +03:00
struct smb_filename * conv_smb_fname = NULL ;
2011-06-20 11:52:21 +04:00
2017-05-26 02:42:04 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
if ( timestamp = = 0 ) {
2017-05-26 02:42:04 +03:00
return SMB_VFS_NEXT_GETXATTR ( handle , smb_fname , aname , value ,
2011-06-20 11:52:21 +04:00
size ) ;
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return - 1 ;
}
2017-05-26 02:42:04 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
NULL ,
smb_fname - > flags ) ;
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
return - 1 ;
}
ret = SMB_VFS_NEXT_GETXATTR ( handle , conv_smb_fname , aname , value , size ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2017-05-26 02:42:04 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
}
static ssize_t shadow_copy2_listxattr ( struct vfs_handle_struct * handle ,
2017-05-23 23:12:29 +03:00
const struct smb_filename * smb_fname ,
2011-06-20 11:52:21 +04:00
char * list , size_t size )
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2011-06-20 11:52:21 +04:00
ssize_t ret ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
2011-06-20 11:52:21 +04:00
char * conv ;
2017-05-23 23:12:29 +03:00
struct smb_filename * conv_smb_fname = NULL ;
2011-06-20 11:52:21 +04:00
2017-05-23 23:12:29 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
if ( timestamp = = 0 ) {
2017-05-23 23:12:29 +03:00
return SMB_VFS_NEXT_LISTXATTR ( handle , smb_fname , list , size ) ;
2011-06-20 11:52:21 +04:00
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return - 1 ;
2008-01-16 12:21:38 +03:00
}
2017-05-23 23:12:29 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
NULL ,
smb_fname - > flags ) ;
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
return - 1 ;
}
ret = SMB_VFS_NEXT_LISTXATTR ( handle , conv_smb_fname , list , size ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2017-05-23 23:12:29 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
}
2008-01-16 12:21:38 +03:00
2011-06-20 11:52:21 +04:00
static int shadow_copy2_removexattr ( vfs_handle_struct * handle ,
2017-05-24 21:35:50 +03:00
const struct smb_filename * smb_fname ,
const char * aname )
2011-06-20 11:52:21 +04:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
int ret ;
2011-06-20 11:52:21 +04:00
char * conv ;
2017-05-24 21:35:50 +03:00
struct smb_filename * conv_smb_fname = NULL ;
2011-06-20 11:52:21 +04:00
2017-05-24 21:35:50 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
if ( timestamp = = 0 ) {
2017-05-24 21:35:50 +03:00
return SMB_VFS_NEXT_REMOVEXATTR ( handle , smb_fname , aname ) ;
2011-06-20 11:52:21 +04:00
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return - 1 ;
}
2017-05-24 21:35:50 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
NULL ,
smb_fname - > flags ) ;
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
return - 1 ;
}
ret = SMB_VFS_NEXT_REMOVEXATTR ( handle , conv_smb_fname , aname ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2017-05-24 21:35:50 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2008-01-16 12:21:38 +03:00
return ret ;
}
2011-06-20 11:52:21 +04:00
static int shadow_copy2_setxattr ( struct vfs_handle_struct * handle ,
2017-05-25 22:41:31 +03:00
const struct smb_filename * smb_fname ,
2011-06-20 11:52:21 +04:00
const char * aname , const void * value ,
size_t size , int flags )
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2011-06-20 11:52:21 +04:00
ssize_t ret ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
2011-06-20 11:52:21 +04:00
char * conv ;
2017-05-25 22:41:31 +03:00
struct smb_filename * conv_smb_fname = NULL ;
2011-06-20 11:52:21 +04:00
2017-05-25 22:41:31 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
if ( timestamp = = 0 ) {
2017-05-25 22:41:31 +03:00
return SMB_VFS_NEXT_SETXATTR ( handle , smb_fname ,
aname , value , size , flags ) ;
2011-06-20 11:52:21 +04:00
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return - 1 ;
}
2017-05-25 22:41:31 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
NULL ,
smb_fname - > flags ) ;
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
return - 1 ;
}
ret = SMB_VFS_NEXT_SETXATTR ( handle , conv_smb_fname ,
aname , value , size , flags ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2017-05-25 22:41:31 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
}
static int shadow_copy2_chmod_acl ( vfs_handle_struct * handle ,
2016-03-02 04:25:25 +03:00
const struct smb_filename * smb_fname ,
mode_t mode )
2011-06-20 11:52:21 +04:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2011-06-20 11:52:21 +04:00
ssize_t ret ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
2016-03-02 04:25:25 +03:00
char * conv = NULL ;
struct smb_filename * conv_smb_fname = NULL ;
2011-06-20 11:52:21 +04:00
2016-03-02 04:25:25 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ) ) {
2011-06-20 11:52:21 +04:00
return - 1 ;
}
if ( timestamp = = 0 ) {
2016-03-02 04:25:25 +03:00
return SMB_VFS_NEXT_CHMOD_ACL ( handle , smb_fname , mode ) ;
2011-06-20 11:52:21 +04:00
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return - 1 ;
}
2016-03-02 04:25:25 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
2016-03-19 07:19:38 +03:00
NULL ,
smb_fname - > flags ) ;
2016-03-02 04:25:25 +03:00
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
errno = ENOMEM ;
return - 1 ;
}
ret = SMB_VFS_NEXT_CHMOD_ACL ( handle , conv_smb_fname , mode ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2016-03-02 04:25:25 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
}
static int shadow_copy2_get_real_filename ( struct vfs_handle_struct * handle ,
const char * path ,
const char * name ,
TALLOC_CTX * mem_ctx ,
char * * found_name )
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2011-06-20 11:52:21 +04:00
ssize_t ret ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
2011-06-20 11:52:21 +04:00
char * conv ;
2012-10-17 14:11:37 +04:00
DEBUG ( 10 , ( " shadow_copy2_get_real_filename called for path=[%s], "
" name=[%s] \n " , path , name ) ) ;
2011-06-20 11:52:21 +04:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) , handle , path ,
& timestamp , & stripped ) ) {
2012-10-17 14:11:37 +04:00
DEBUG ( 10 , ( " shadow_copy2_strip_snapshot failed \n " ) ) ;
2011-06-20 11:52:21 +04:00
return - 1 ;
}
if ( timestamp = = 0 ) {
2012-10-17 14:11:37 +04:00
DEBUG ( 10 , ( " timestamp == 0 \n " ) ) ;
2011-06-20 11:52:21 +04:00
return SMB_VFS_NEXT_GET_REAL_FILENAME ( handle , path , name ,
mem_ctx , found_name ) ;
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
2012-10-17 14:11:37 +04:00
DEBUG ( 10 , ( " shadow_copy2_convert failed \n " ) ) ;
2011-06-20 11:52:21 +04:00
return - 1 ;
}
2012-10-17 14:11:37 +04:00
DEBUG ( 10 , ( " Calling NEXT_GET_REAL_FILE_NAME for conv=[%s], "
" name=[%s] \n " , conv , name ) ) ;
2011-06-20 11:52:21 +04:00
ret = SMB_VFS_NEXT_GET_REAL_FILENAME ( handle , conv , name ,
mem_ctx , found_name ) ;
2012-10-17 14:11:37 +04:00
DEBUG ( 10 , ( " NEXT_REAL_FILE_NAME returned %d \n " , ( int ) ret ) ) ;
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2011-06-20 11:52:21 +04:00
TALLOC_FREE ( conv ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2011-06-20 11:52:21 +04:00
return ret ;
}
2015-11-02 10:08:53 +03:00
static const char * shadow_copy2_connectpath ( struct vfs_handle_struct * handle ,
2017-06-30 23:37:03 +03:00
const struct smb_filename * smb_fname_in )
2015-11-02 10:08:53 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
2015-11-02 10:08:53 +03:00
char * stripped = NULL ;
char * tmp = NULL ;
2017-06-30 23:37:03 +03:00
const char * fname = smb_fname_in - > base_name ;
2017-06-30 21:32:59 +03:00
struct smb_filename smb_fname = { 0 } ;
struct smb_filename * result_fname = NULL ;
2015-11-02 10:08:53 +03:00
char * result = NULL ;
2016-08-24 14:42:23 +03:00
char * parent_dir = NULL ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
2015-11-02 10:08:53 +03:00
size_t rootpath_len = 0 ;
2017-01-20 23:09:08 +03:00
struct shadow_copy2_private * priv = NULL ;
SMB_VFS_HANDLE_GET_DATA ( handle , priv , struct shadow_copy2_private ,
return NULL ) ;
2015-11-02 10:08:53 +03:00
DBG_DEBUG ( " Calc connect path for [%s] \n " , fname ) ;
2017-01-20 23:09:08 +03:00
if ( priv - > shadow_connectpath ! = NULL ) {
DBG_DEBUG ( " cached connect path is [%s] \n " ,
priv - > shadow_connectpath ) ;
return priv - > shadow_connectpath ;
}
2015-11-02 10:08:53 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) , handle , fname ,
& timestamp , & stripped ) ) {
goto done ;
}
if ( timestamp = = 0 ) {
2017-06-30 23:37:03 +03:00
return SMB_VFS_NEXT_CONNECTPATH ( handle , smb_fname_in ) ;
2015-11-02 10:08:53 +03:00
}
tmp = shadow_copy2_do_convert ( talloc_tos ( ) , handle , stripped , timestamp ,
& rootpath_len ) ;
if ( tmp = = NULL ) {
2016-08-24 14:42:23 +03:00
if ( errno ! = ENOENT ) {
goto done ;
}
/*
* If the converted path does not exist , and converting
* the parent yields something that does exist , then
* this path refers to something that has not been
* created yet , relative to the parent path .
* The snapshot finding is relative to the parent .
* ( usually snapshots are read / only but this is not
* necessarily true ) .
* This code also covers getting a wildcard in the
* last component , because this function is called
* prior to sanitizing the path , and in SMB1 we may
* get wildcards in path names .
*/
if ( ! parent_dirname ( talloc_tos ( ) , stripped , & parent_dir ,
NULL ) ) {
errno = ENOMEM ;
goto done ;
}
tmp = shadow_copy2_do_convert ( talloc_tos ( ) , handle , parent_dir ,
timestamp , & rootpath_len ) ;
if ( tmp = = NULL ) {
goto done ;
}
2015-11-02 10:08:53 +03:00
}
DBG_DEBUG ( " converted path is [%s] root path is [%.*s] \n " , tmp ,
( int ) rootpath_len , tmp ) ;
tmp [ rootpath_len ] = ' \0 ' ;
2017-06-30 21:32:59 +03:00
smb_fname = ( struct smb_filename ) { . base_name = tmp } ;
result_fname = SMB_VFS_NEXT_REALPATH ( handle , priv , & smb_fname ) ;
if ( result_fname = = NULL ) {
2015-11-02 10:08:53 +03:00
goto done ;
}
2017-01-23 21:06:44 +03:00
/*
2017-06-30 21:32:59 +03:00
* SMB_VFS_NEXT_REALPATH returns a talloc ' ed string .
2017-01-23 21:06:44 +03:00
* Don ' t leak memory .
*/
2017-06-30 21:32:59 +03:00
TALLOC_FREE ( priv - > shadow_realpath ) ;
priv - > shadow_realpath = result_fname ;
result = priv - > shadow_realpath - > base_name ;
2017-01-23 21:06:44 +03:00
2015-11-02 10:08:53 +03:00
DBG_DEBUG ( " connect path is [%s] \n " , result ) ;
done :
2017-01-23 21:20:13 +03:00
if ( result = = NULL ) {
saved_errno = errno ;
}
2015-11-02 10:08:53 +03:00
TALLOC_FREE ( tmp ) ;
TALLOC_FREE ( stripped ) ;
2016-08-24 14:42:23 +03:00
TALLOC_FREE ( parent_dir ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2015-11-02 10:08:53 +03:00
return result ;
}
2013-06-01 04:14:41 +04:00
static uint64_t shadow_copy2_disk_free ( vfs_handle_struct * handle ,
2017-05-23 20:40:47 +03:00
const struct smb_filename * smb_fname ,
uint64_t * bsize ,
uint64_t * dfree ,
uint64_t * dsize )
2013-06-01 04:14:41 +04:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
2017-05-23 20:40:47 +03:00
char * conv = NULL ;
struct smb_filename * conv_smb_fname = NULL ;
uint64_t ret = ( uint64_t ) - 1 ;
2013-06-01 04:14:41 +04:00
2017-05-23 20:40:47 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ) ) {
return ( uint64_t ) - 1 ;
2013-06-01 04:14:41 +04:00
}
if ( timestamp = = 0 ) {
2017-05-23 20:40:47 +03:00
return SMB_VFS_NEXT_DISK_FREE ( handle , smb_fname ,
2013-06-01 04:14:41 +04:00
bsize , dfree , dsize ) ;
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
2017-05-23 20:40:47 +03:00
return ( uint64_t ) - 1 ;
2013-06-01 04:14:41 +04:00
}
2017-05-23 20:40:47 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
NULL ,
smb_fname - > flags ) ;
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
return ( uint64_t ) - 1 ;
}
ret = SMB_VFS_NEXT_DISK_FREE ( handle , conv_smb_fname ,
bsize , dfree , dsize ) ;
if ( ret = = ( uint64_t ) - 1 ) {
2017-01-23 21:20:13 +03:00
saved_errno = errno ;
}
2013-06-01 04:14:41 +04:00
TALLOC_FREE ( conv ) ;
2017-05-23 20:40:47 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2013-06-01 04:14:41 +04:00
return ret ;
}
2017-06-01 21:45:25 +03:00
static int shadow_copy2_get_quota ( vfs_handle_struct * handle ,
const struct smb_filename * smb_fname ,
enum SMB_QUOTA_TYPE qtype ,
unid_t id ,
SMB_DISK_QUOTA * dq )
2016-01-10 15:13:38 +03:00
{
2017-01-20 22:42:39 +03:00
time_t timestamp = 0 ;
char * stripped = NULL ;
2016-01-10 15:13:38 +03:00
int ret ;
2017-01-23 21:20:13 +03:00
int saved_errno = 0 ;
2016-01-10 15:13:38 +03:00
char * conv ;
2017-06-01 21:45:25 +03:00
struct smb_filename * conv_smb_fname = NULL ;
2016-01-10 15:13:38 +03:00
2017-06-01 21:45:25 +03:00
if ( ! shadow_copy2_strip_snapshot ( talloc_tos ( ) ,
handle ,
smb_fname - > base_name ,
& timestamp ,
& stripped ) ) {
2016-01-10 15:13:38 +03:00
return - 1 ;
}
if ( timestamp = = 0 ) {
2017-06-01 21:45:25 +03:00
return SMB_VFS_NEXT_GET_QUOTA ( handle , smb_fname , qtype , id , dq ) ;
2016-01-10 15:13:38 +03:00
}
conv = shadow_copy2_convert ( talloc_tos ( ) , handle , stripped , timestamp ) ;
TALLOC_FREE ( stripped ) ;
if ( conv = = NULL ) {
return - 1 ;
}
2017-06-01 21:45:25 +03:00
conv_smb_fname = synthetic_smb_fname ( talloc_tos ( ) ,
conv ,
NULL ,
NULL ,
smb_fname - > flags ) ;
if ( conv_smb_fname = = NULL ) {
TALLOC_FREE ( conv ) ;
return - 1 ;
}
ret = SMB_VFS_NEXT_GET_QUOTA ( handle , conv_smb_fname , qtype , id , dq ) ;
2016-01-10 15:13:38 +03:00
2017-01-23 21:20:13 +03:00
if ( ret = = - 1 ) {
saved_errno = errno ;
}
2016-01-10 15:13:38 +03:00
TALLOC_FREE ( conv ) ;
2017-06-01 21:45:25 +03:00
TALLOC_FREE ( conv_smb_fname ) ;
2017-01-23 21:20:13 +03:00
if ( saved_errno ! = 0 ) {
errno = saved_errno ;
}
2016-01-10 15:13:38 +03:00
return ret ;
}
2013-05-24 03:35:44 +04:00
static int shadow_copy2_connect ( struct vfs_handle_struct * handle ,
const char * service , const char * user )
{
struct shadow_copy2_config * config ;
2016-07-11 14:27:37 +03:00
struct shadow_copy2_private * priv ;
2013-05-24 03:35:44 +04:00
int ret ;
const char * snapdir ;
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
const char * snapprefix = NULL ;
const char * delimiter ;
2013-05-24 03:35:44 +04:00
const char * gmt_format ;
const char * sort_order ;
2015-11-03 10:15:12 +03:00
const char * basedir = NULL ;
2015-11-03 11:57:13 +03:00
const char * snapsharepath = NULL ;
2013-05-31 18:36:33 +04:00
const char * mount_point ;
2013-05-24 03:35:44 +04:00
DEBUG ( 10 , ( __location__ " : cnum[%u], connectpath[%s] \n " ,
( unsigned ) handle - > conn - > cnum ,
handle - > conn - > connectpath ) ) ;
ret = SMB_VFS_NEXT_CONNECT ( handle , service , user ) ;
if ( ret < 0 ) {
return ret ;
}
2016-07-11 14:27:37 +03:00
priv = talloc_zero ( handle - > conn , struct shadow_copy2_private ) ;
if ( priv = = NULL ) {
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
DBG_ERR ( " talloc_zero() failed \n " ) ;
errno = ENOMEM ;
return - 1 ;
}
priv - > snaps = talloc_zero ( priv , struct shadow_copy2_snaplist_info ) ;
if ( priv - > snaps = = NULL ) {
DBG_ERR ( " talloc_zero() failed \n " ) ;
2016-07-11 14:27:37 +03:00
errno = ENOMEM ;
return - 1 ;
}
config = talloc_zero ( priv , struct shadow_copy2_config ) ;
2013-05-24 03:35:44 +04:00
if ( config = = NULL ) {
DEBUG ( 0 , ( " talloc_zero() failed \n " ) ) ;
errno = ENOMEM ;
return - 1 ;
}
2016-07-11 14:27:37 +03:00
priv - > config = config ;
2013-05-24 03:35:44 +04:00
gmt_format = lp_parm_const_string ( SNUM ( handle - > conn ) ,
" shadow " , " format " ,
GMT_FORMAT ) ;
config - > gmt_format = talloc_strdup ( config , gmt_format ) ;
if ( config - > gmt_format = = NULL ) {
DEBUG ( 0 , ( " talloc_strdup() failed \n " ) ) ;
errno = ENOMEM ;
return - 1 ;
}
2017-01-26 21:24:52 +03:00
/* config->gmt_format must not contain a path separator. */
if ( strchr ( config - > gmt_format , ' / ' ) ! = NULL ) {
DEBUG ( 0 , ( " shadow:format %s must not contain a / "
" character. Unable to initialize module. \n " ,
config - > gmt_format ) ) ;
errno = EINVAL ;
return - 1 ;
}
2013-05-24 03:35:44 +04:00
config - > use_sscanf = lp_parm_bool ( SNUM ( handle - > conn ) ,
" shadow " , " sscanf " , false ) ;
config - > use_localtime = lp_parm_bool ( SNUM ( handle - > conn ) ,
" shadow " , " localtime " ,
false ) ;
snapdir = lp_parm_const_string ( SNUM ( handle - > conn ) ,
" shadow " , " snapdir " ,
" .snapshots " ) ;
config - > snapdir = talloc_strdup ( config , snapdir ) ;
if ( config - > snapdir = = NULL ) {
DEBUG ( 0 , ( " talloc_strdup() failed \n " ) ) ;
errno = ENOMEM ;
return - 1 ;
}
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
snapprefix = lp_parm_const_string ( SNUM ( handle - > conn ) ,
" shadow " , " snapprefix " ,
NULL ) ;
if ( snapprefix ! = NULL ) {
priv - > snaps - > regex = talloc_zero ( priv - > snaps , regex_t ) ;
if ( priv - > snaps - > regex = = NULL ) {
DBG_ERR ( " talloc_zero() failed \n " ) ;
errno = ENOMEM ;
return - 1 ;
}
/* pre-compute regex rule for matching pattern later */
ret = regcomp ( priv - > snaps - > regex , snapprefix , 0 ) ;
if ( ret ) {
DBG_ERR ( " Failed to create regex object \n " ) ;
return - 1 ;
}
}
delimiter = lp_parm_const_string ( SNUM ( handle - > conn ) ,
" shadow " , " delimiter " ,
" _GMT " ) ;
if ( delimiter ! = NULL ) {
priv - > config - > delimiter = talloc_strdup ( priv - > config , delimiter ) ;
if ( priv - > config - > delimiter = = NULL ) {
DBG_ERR ( " talloc_strdup() failed \n " ) ;
errno = ENOMEM ;
return - 1 ;
}
}
2013-05-24 03:35:44 +04:00
config - > snapdirseverywhere = lp_parm_bool ( SNUM ( handle - > conn ) ,
" shadow " ,
" snapdirseverywhere " ,
false ) ;
config - > crossmountpoints = lp_parm_bool ( SNUM ( handle - > conn ) ,
" shadow " , " crossmountpoints " ,
false ) ;
2015-11-03 11:42:00 +03:00
if ( config - > crossmountpoints & & ! config - > snapdirseverywhere ) {
DBG_WARNING ( " Warning: 'crossmountpoints' depends on "
" 'snapdirseverywhere'. Disabling crossmountpoints. \n " ) ;
}
2013-05-24 03:35:44 +04:00
config - > fixinodes = lp_parm_bool ( SNUM ( handle - > conn ) ,
" shadow " , " fixinodes " ,
false ) ;
sort_order = lp_parm_const_string ( SNUM ( handle - > conn ) ,
" shadow " , " sort " , " desc " ) ;
config - > sort_order = talloc_strdup ( config , sort_order ) ;
if ( config - > sort_order = = NULL ) {
DEBUG ( 0 , ( " talloc_strdup() failed \n " ) ) ;
errno = ENOMEM ;
return - 1 ;
}
2013-05-31 18:36:33 +04:00
mount_point = lp_parm_const_string ( SNUM ( handle - > conn ) ,
" shadow " , " mountpoint " , NULL ) ;
if ( mount_point ! = NULL ) {
if ( mount_point [ 0 ] ! = ' / ' ) {
DEBUG ( 1 , ( __location__ " Warning: 'mountpoint' is "
" relative ('%s'), but it has to be an "
" absolute path. Ignoring provided value. \n " ,
mount_point ) ) ;
mount_point = NULL ;
} else {
char * p ;
p = strstr ( handle - > conn - > connectpath , mount_point ) ;
if ( p ! = handle - > conn - > connectpath ) {
2016-01-13 03:37:24 +03:00
DBG_WARNING ( " Warning: the share root (%s) is "
" not a subdirectory of the "
" specified mountpoint (%s). "
" Ignoring provided value. \n " ,
handle - > conn - > connectpath ,
mount_point ) ;
2013-05-31 18:36:33 +04:00
mount_point = NULL ;
}
}
}
if ( mount_point ! = NULL ) {
config - > mount_point = talloc_strdup ( config , mount_point ) ;
if ( config - > mount_point = = NULL ) {
DEBUG ( 0 , ( __location__ " talloc_strdup() failed \n " ) ) ;
return - 1 ;
}
} else {
config - > mount_point = shadow_copy2_find_mount_point ( config ,
handle ) ;
if ( config - > mount_point = = NULL ) {
2015-06-25 19:43:50 +03:00
DBG_WARNING ( " shadow_copy2_find_mount_point "
" of the share root '%s' failed: %s \n " ,
handle - > conn - > connectpath , strerror ( errno ) ) ;
2013-05-31 18:36:33 +04:00
return - 1 ;
}
2013-05-30 19:26:44 +04:00
}
basedir = lp_parm_const_string ( SNUM ( handle - > conn ) ,
" shadow " , " basedir " , NULL ) ;
if ( basedir ! = NULL ) {
if ( basedir [ 0 ] ! = ' / ' ) {
DEBUG ( 1 , ( __location__ " Warning: 'basedir' is "
" relative ('%s'), but it has to be an "
" absolute path. Disabling basedir. \n " ,
basedir ) ) ;
2015-11-03 10:15:12 +03:00
basedir = NULL ;
2013-05-30 19:26:44 +04:00
} else {
char * p ;
p = strstr ( basedir , config - > mount_point ) ;
if ( p ! = basedir ) {
DEBUG ( 1 , ( " Warning: basedir (%s) is not a "
" subdirectory of the share root's "
" mount point (%s). "
" Disabling basedir \n " ,
basedir , config - > mount_point ) ) ;
2015-11-03 10:15:12 +03:00
basedir = NULL ;
2013-05-30 19:26:44 +04:00
}
}
}
2015-11-03 10:15:12 +03:00
if ( config - > snapdirseverywhere & & basedir ! = NULL ) {
2013-05-30 19:26:44 +04:00
DEBUG ( 1 , ( __location__ " Warning: 'basedir' is incompatible "
" with 'snapdirseverywhere'. Disabling basedir. \n " ) ) ;
2015-11-03 10:15:12 +03:00
basedir = NULL ;
2013-05-30 19:26:44 +04:00
}
2015-11-03 11:57:13 +03:00
snapsharepath = lp_parm_const_string ( SNUM ( handle - > conn ) , " shadow " ,
" snapsharepath " , NULL ) ;
if ( snapsharepath ! = NULL ) {
if ( snapsharepath [ 0 ] = = ' / ' ) {
DBG_WARNING ( " Warning: 'snapsharepath' is "
" absolute ('%s'), but it has to be a "
" relative path. Disabling snapsharepath. \n " ,
snapsharepath ) ;
snapsharepath = NULL ;
}
if ( config - > snapdirseverywhere & & snapsharepath ! = NULL ) {
DBG_WARNING ( " Warning: 'snapsharepath' is incompatible "
" with 'snapdirseverywhere'. Disabling "
" snapsharepath. \n " ) ;
snapsharepath = NULL ;
}
}
if ( basedir ! = NULL & & snapsharepath ! = NULL ) {
DBG_WARNING ( " Warning: 'snapsharepath' is incompatible with "
" 'basedir'. Disabling snapsharepath \n " ) ;
snapsharepath = NULL ;
}
if ( snapsharepath ! = NULL ) {
config - > rel_connectpath = talloc_strdup ( config , snapsharepath ) ;
if ( config - > rel_connectpath = = NULL ) {
DBG_ERR ( " talloc_strdup() failed \n " ) ;
errno = ENOMEM ;
return - 1 ;
}
}
2015-11-03 10:15:12 +03:00
if ( basedir = = NULL ) {
basedir = config - > mount_point ;
2013-05-30 19:26:44 +04:00
}
2015-11-03 11:57:13 +03:00
if ( config - > rel_connectpath = = NULL & &
2017-01-20 22:48:40 +03:00
strlen ( basedir ) < strlen ( handle - > conn - > connectpath ) ) {
2013-10-04 02:04:06 +04:00
config - > rel_connectpath = talloc_strdup ( config ,
2015-11-03 10:15:12 +03:00
handle - > conn - > connectpath + strlen ( basedir ) ) ;
2013-10-04 02:04:06 +04:00
if ( config - > rel_connectpath = = NULL ) {
DEBUG ( 0 , ( " talloc_strdup() failed \n " ) ) ;
errno = ENOMEM ;
return - 1 ;
}
}
2013-05-29 19:10:51 +04:00
if ( config - > snapdir [ 0 ] = = ' / ' ) {
config - > snapdir_absolute = true ;
2013-10-04 02:04:06 +04:00
2013-05-29 19:10:51 +04:00
if ( config - > snapdirseverywhere = = true ) {
DEBUG ( 1 , ( __location__ " Warning: An absolute snapdir "
" is incompatible with 'snapdirseverywhere', "
" setting 'snapdirseverywhere' to false. \n " ) ) ;
config - > snapdirseverywhere = false ;
}
2013-05-30 15:19:50 +04:00
if ( config - > crossmountpoints = = true ) {
DEBUG ( 1 , ( __location__ " Warning: 'crossmountpoints' "
" is not supported with an absolute snapdir. "
" Disabling it. \n " ) ) ;
config - > crossmountpoints = false ;
}
2013-10-04 02:07:15 +04:00
config - > snapshot_basepath = config - > snapdir ;
} else {
config - > snapshot_basepath = talloc_asprintf ( config , " %s/%s " ,
config - > mount_point , config - > snapdir ) ;
if ( config - > snapshot_basepath = = NULL ) {
DEBUG ( 0 , ( " talloc_asprintf() failed \n " ) ) ;
errno = ENOMEM ;
return - 1 ;
}
2013-05-29 19:10:51 +04:00
}
2017-01-20 22:45:54 +03:00
trim_string ( config - > mount_point , NULL , " / " ) ;
trim_string ( config - > rel_connectpath , " / " , " / " ) ;
trim_string ( config - > snapdir , NULL , " / " ) ;
trim_string ( config - > snapshot_basepath , NULL , " / " ) ;
2013-05-31 19:17:27 +04:00
DEBUG ( 10 , ( " shadow_copy2_connect: configuration: \n "
" share root: '%s' \n "
" mountpoint: '%s' \n "
" rel share root: '%s' \n "
" snapdir: '%s' \n "
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
" snapprefix: '%s' \n "
" delimiter: '%s' \n "
2013-05-31 19:17:27 +04:00
" snapshot base path: '%s' \n "
" format: '%s' \n "
" use sscanf: %s \n "
" snapdirs everywhere: %s \n "
" cross mountpoints: %s \n "
" fix inodes: %s \n "
" sort order: %s \n "
" " ,
handle - > conn - > connectpath ,
config - > mount_point ,
config - > rel_connectpath ,
config - > snapdir ,
shadow_copy2: allow configurable prefix for snapshot name
With growing number of snapshots file-systems need some mechanism
to differentiate one set of snapshots from other, e.g. monthly, weekly,
manual, special events, etc. Therefore these file-systems provide
different ways to tag snapshots, e.g. provide a configurable way to
name snapshots, which is not just based on time. With only shadow:format
it is very difficult to filter these snapshots.
As part of this change added two new options, shadow:snapprefix and
shadow:delimiter, in shadow_copy2 config. This option will accept regular
expression (BRE) as input. With this optional parameter, one can specify a
variable prefix component for names of the snapshot directories in the
file-system. If this parameter is set, together with the shadow:format and
shadow:delimiter parameters it determines the possible names of snapshot
directories in the file-system.
e.g.
shadow:snapprefix = [a-z]*[0-9]
When this option is provided then shadow:format option should always
start with <delimiter> string. This delimiter is configurable via a new option,
i.e. shadow:delimiter. Default value for this is "_GMT",
e.g. _GMT-%Y.%m.%d-%H.%M.%S
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-07-13 21:59:18 +03:00
snapprefix ,
config - > delimiter ,
2013-05-31 19:17:27 +04:00
config - > snapshot_basepath ,
config - > gmt_format ,
config - > use_sscanf ? " yes " : " no " ,
config - > snapdirseverywhere ? " yes " : " no " ,
config - > crossmountpoints ? " yes " : " no " ,
config - > fixinodes ? " yes " : " no " ,
config - > sort_order
) ) ;
2016-07-11 14:27:37 +03:00
SMB_VFS_HANDLE_SET_DATA ( handle , priv ,
NULL , struct shadow_copy2_private ,
2013-05-24 03:35:44 +04:00
return - 1 ) ;
return 0 ;
}
2011-06-20 11:52:21 +04:00
static struct vfs_fn_pointers vfs_shadow_copy2_fns = {
2013-05-24 03:35:44 +04:00
. connect_fn = shadow_copy2_connect ,
2011-12-04 08:45:04 +04:00
. opendir_fn = shadow_copy2_opendir ,
2013-06-01 04:14:41 +04:00
. disk_free_fn = shadow_copy2_disk_free ,
2016-01-10 15:13:38 +03:00
. get_quota_fn = shadow_copy2_get_quota ,
2011-12-04 08:45:04 +04:00
. rename_fn = shadow_copy2_rename ,
. link_fn = shadow_copy2_link ,
. symlink_fn = shadow_copy2_symlink ,
. stat_fn = shadow_copy2_stat ,
. lstat_fn = shadow_copy2_lstat ,
. fstat_fn = shadow_copy2_fstat ,
2011-06-20 11:52:21 +04:00
. open_fn = shadow_copy2_open ,
2011-12-04 08:45:04 +04:00
. unlink_fn = shadow_copy2_unlink ,
. chmod_fn = shadow_copy2_chmod ,
. chown_fn = shadow_copy2_chown ,
. chdir_fn = shadow_copy2_chdir ,
. ntimes_fn = shadow_copy2_ntimes ,
. readlink_fn = shadow_copy2_readlink ,
. mknod_fn = shadow_copy2_mknod ,
. realpath_fn = shadow_copy2_realpath ,
. get_nt_acl_fn = shadow_copy2_get_nt_acl ,
. fget_nt_acl_fn = shadow_copy2_fget_nt_acl ,
. get_shadow_copy_data_fn = shadow_copy2_get_shadow_copy_data ,
. mkdir_fn = shadow_copy2_mkdir ,
. rmdir_fn = shadow_copy2_rmdir ,
. getxattr_fn = shadow_copy2_getxattr ,
. listxattr_fn = shadow_copy2_listxattr ,
. removexattr_fn = shadow_copy2_removexattr ,
. setxattr_fn = shadow_copy2_setxattr ,
. chmod_acl_fn = shadow_copy2_chmod_acl ,
. chflags_fn = shadow_copy2_chflags ,
. get_real_filename_fn = shadow_copy2_get_real_filename ,
2015-11-02 10:08:53 +03:00
. connectpath_fn = shadow_copy2_connectpath ,
2011-06-20 11:52:21 +04:00
} ;
2017-12-16 01:32:12 +03:00
static_decl_vfs ;
2017-04-20 22:24:43 +03:00
NTSTATUS vfs_shadow_copy2_init ( TALLOC_CTX * ctx )
2011-06-20 11:52:21 +04:00
{
return smb_register_vfs ( SMB_VFS_INTERFACE_VERSION ,
" shadow_copy2 " , & vfs_shadow_copy2_fns ) ;
}