pysmbd: add "session_info" arg tp py_smbd_create_file()
authorRalph Boehme <slow@samba.org>
Tue, 17 Dec 2019 13:58:57 +0000 (14:58 +0100)
committerRalph Boehme <slow@samba.org>
Fri, 20 Dec 2019 11:41:42 +0000 (11:41 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
python/samba/ntacls.py
python/samba/tests/ntacls_backup.py
source3/smbd/pysmbd.c

index fe6eda269fc37e39ef67930a240705bbe72550c4..0dcf958f7273f3534992e0134596f6bbc1dbf6a6 100644 (file)
@@ -573,7 +573,7 @@ def backup_offline(src_service_path, dest_tarfile_path, samdb_conn, smb_conf_pat
             src = os.path.join(dirpath, filename)
             dst = os.path.join(dst_dirpath, filename)
             # create an empty file with metadata
-            smbd.create_file(dst, service)
+            smbd.create_file(dst, session_info, service)
             ntacl_sddl_str = ntacls_helper.getntacl(src, session_info, as_sddl=True)
             _create_ntacl_file(dst, ntacl_sddl_str)
 
@@ -637,7 +637,7 @@ def backup_restore(src_tarfile_path, dst_service_path, samdb_conn, smb_conf_path
                 dst = os.path.join(dst_dirpath, filename)
                 if not os.path.isfile(dst):
                     # dst must be absolute path for smbd API
-                    smbd.create_file(dst, service)
+                    smbd.create_file(dst, session_info, service)
 
                 ntacl_sddl_str = _read_ntacl_file(src)
                 if ntacl_sddl_str:
index d072049cf950e2bbe8016cce35bd83f7b5354888..6ac73d4a1b823b3d0679308cc39fe4ba9468aab3 100644 (file)
@@ -126,7 +126,7 @@ class NtaclsBackupRestoreTests(SmbdBaseTests):
         """
 
         filepath = os.path.join(self.service_root, 'a-file')
-        smbd.create_file(filepath, self.service)
+        smbd.create_file(filepath, system_session_unix(), self.service)
         self.assertTrue(os.path.isfile(filepath))
 
         mode = os.stat(filepath).st_mode
index 2fc197f91ff2c00f869d71dd0451f5311f3dff61..39fe875a385b34db1c010306d354c75c9a0d69a5 100644 (file)
@@ -1059,10 +1059,13 @@ static PyObject *py_smbd_create_file(PyObject *self, PyObject *args, PyObject *k
 {
        const char * const kwnames[] = {
                "fname",
+               "session_info",
                "service",
                NULL
        };
        char *fname, *service = NULL;
+       PyObject *py_session = Py_None;
+       struct auth_session_info *session_info = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
        struct connection_struct *conn = NULL;
        struct files_struct *fsp = NULL;
@@ -1070,16 +1073,33 @@ static PyObject *py_smbd_create_file(PyObject *self, PyObject *args, PyObject *k
 
        if (!PyArg_ParseTupleAndKeywords(args,
                                         kwargs,
-                                        "s|z",
+                                        "sO|z",
                                         discard_const_p(char *,
                                                         kwnames),
                                         &fname,
+                                        &py_session,
                                         &service)) {
                TALLOC_FREE(frame);
                return NULL;
        }
 
-       conn = get_conn_tos(service, NULL);
+       if (!py_check_dcerpc_type(py_session,
+                                 "samba.dcerpc.auth",
+                                 "session_info")) {
+               TALLOC_FREE(frame);
+               return NULL;
+       }
+       session_info = pytalloc_get_type(py_session,
+                                        struct auth_session_info);
+       if (session_info == NULL) {
+               PyErr_Format(PyExc_TypeError,
+                            "Expected auth_session_info for session_info argument got %s",
+                            pytalloc_get_name(py_session));
+               TALLOC_FREE(frame);
+               return NULL;
+       }
+
+       conn = get_conn_tos(service, session_info);
        if (!conn) {
                TALLOC_FREE(frame);
                return NULL;