]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_preopen: introduce support for "preopen:posix-basic-regex = yes"
authorStefan Metzmacher <metze@samba.org>
Fri, 11 Jun 2021 19:07:03 +0000 (19:07 +0000)
committerStefan Metzmacher <metze@samba.org>
Thu, 1 Jul 2021 13:02:31 +0000 (13:02 +0000)
This will allow the usage of patterns as
'POSIX Basic Regular Expression'

      vfs objects = preopen
      preopen:posix-basic-regex = yes
      preopen:names = /Re7599Ex\([0-9]\).*\.txt/test\([0-9]*\)\.dat/

The key is that exactly one 'subexpression' starting with '\(' and
ending with '\)' is specified in order to select the position where
the digits are searched.

E.g. given a file name 'Re7599Ex01234.txt' will actually preopen:

  Re7599Ex01234.txt
  Re7599Ex11234.txt
  Re7599Ex21234.txt
  Re7599Ex31234.txt
  Re7599Ex41234.txt

As '\([0-9]\)' will only match the first digit after 'Re7599Ex'.

It also means it's now possible to have digits in the fixed part of the
filename, which was the actual motivation for this patchset.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
docs-xml/manpages/vfs_preopen.8.xml
source3/modules/vfs_preopen.c

index 3c799b62190cada0433133c5f4e2e8df58c09888..d1a90710f1e61c9e5964a65863f5f18b36f970d8 100644 (file)
 
        <variablelist>
 
+               <varlistentry>
+               <term>preopen:posix-basic-regex = BOOL (default: no)</term>
+               <listitem>
+               <para>
+               <command>preopen:posix-basic-regex = yes</command> changes
+               the meaning of the <command>preopen:names</command> option.
+               Further details are described there.
+               </para>
+               </listitem>
+               </varlistentry>
+
                <varlistentry>
                <term>preopen:names = /pattern1/pattern2/</term>
                <listitem>
                the files are numbered incrementally. So if your file names
                are numbered FRAME00000.frm FRAME00001.frm and so on you would
                list them as <command>preopen:names=/FRAME*.frm/</command>.
-               The current algorithm uses the first (at least 3) digits it finds
+               The default algorithm uses the first (at least 3) digits it finds
                in order to calculate the name of the next frames.
                </para>
+
+               <para><command>preopen:posix-basic-regex = yes</command> changes
+               the meaning of the <command>preopen:names</command> option.
+               It means 'POSIX Basic Regular Expression' strings are used
+               as patterns. The key is each pattern requires exactly one
+               'subexpression' starting with '\(' and ending with '\)' in
+               order to specify the position of the digits representing
+               the incrementing frame numbers. Given a file names like
+               Movie7599Frame0v1234.txt, Movie7599Frame1v1234.txt, Movie7599Frame2v1234.txt
+               up to Movie7599Frame9v1234.txt you can use <command>preopen:names = /.*Frame\([0-9]\).*\.txt/</command>
+               in order to match just a single digits, this might not be a real world example,
+               but it shows the flexiblity that is possible here.
+               </para>
+
                </listitem>
                </varlistentry>
 
index 6ee3c059a076a0d856019ba814674aff6d5c9b15..4dc5ba30b1df2896f5e5e8d0ac7a162e552f0e05 100644 (file)
@@ -338,10 +338,16 @@ static struct preopen_state *preopen_state_get(vfs_handle_struct *handle)
                return NULL;
        }
 
-       status = samba_path_matching_mswild_create(state,
-                                                  true, /* case_sensitive */
-                                                  namelist,
-                                                  &state->preopen_names);
+       if (lp_parm_bool(SNUM(handle->conn), "preopen", "posix-basic-regex", false)) {
+               status = samba_path_matching_regex_sub1_create(state,
+                                                              namelist,
+                                                              &state->preopen_names);
+       } else {
+               status = samba_path_matching_mswild_create(state,
+                                                          true, /* case_sensitive */
+                                                          namelist,
+                                                          &state->preopen_names);
+       }
        if (!NT_STATUS_IS_OK(status)) {
                TALLOC_FREE(state);
                return NULL;