Import upstream version 1.2.6+git20210211.1.0b0b9a7
Kali Janitor
2 years ago
0 | pysmb-1.2.6, 9 Dec 2020 | |
1 | ======================= | |
2 | - Fix bug in SMB1 store file implmentation which generates SMB_COM_WRITE_ANDX | |
3 | packets larger than the allowed max buffer size (#175) | |
4 | ||
5 | pysmb-1.2.5, 18 Oct 2020 | |
6 | ======================= | |
7 | - Fix bug in filename encoding which leads to failure for file retrieval and upload operations (#170 #171). | |
8 | - Improve resetFileAttributes() method in SMBConnection class to allow the | |
9 | new attribute to be specified in the reset operation (#172). | |
10 | ||
11 | pysmb-1.2.4, 6 Oct 2020 | |
12 | ======================= | |
13 | - Remove dependency on pycrypto as it is no longer under active maintenance | |
14 | ||
15 | pysmb-1.2.3, 6 Oct 2020 | |
16 | ======================= | |
17 | - Fix bug in session key generation during session negotiation (#166) | |
18 | - Fix bug in SMB message signing which leads to operation failures with Samba services. | |
19 | ||
20 | pysmb-1.2.2, 5 Sep 2020 | |
21 | ======================= | |
22 | - Improve SMB URL handlers to support specifying server's machine name and IP | |
23 | address. (#162) | |
24 | - Improvements to documentation on SMB URLs (#160) | |
25 | ||
26 | pysmb-1.2.1, 17 May 2020 | |
27 | ======================== | |
28 | - Fix bug in deleteFiles() method which can fail for certain search patterns. | |
29 | ||
30 | pysmb-1.2.0, 17 May 2020 | |
31 | ========================= | |
32 | - Add new parameter, delete_matching_folders, to deleteFiles() method to | |
33 | support deletion of child folders that match the search pattern. | |
34 | ||
35 | pysmb-1.1.29, 16 May 2020 | |
36 | ========================= | |
37 | - Fix unhandled exception for short NBNS queries #149 | |
38 | - Fix wildcard file deletion with servers on SMB2 protocol #33 | |
39 | ||
40 | pysmb-1.1.28, 23 Nov 2019 | |
41 | ======================== | |
42 | - SharedFile instances returned from the listPath() method now has a new | |
43 | file_id attribute which represents the file reference number given by the SMB server. | |
44 | ||
45 | pysmb-1.1.27, 9 Jan 2019 | |
46 | ======================== | |
47 | - Remove support for SMB-2.1 dialect as it seems to have issues with Windows 2008 R2 | |
48 | ||
49 | pysmb-1.1.26, 5 Jan 2019 | |
50 | ======================== | |
51 | - Prevents OperationError from being raised when listPath() operation does not | |
52 | return any matching file results. | |
53 | - SMBConnection is now a context manager #122. | |
54 | ||
55 | pysmb-1.1.25, 28 July 2018 | |
56 | ======================== | |
57 | - Fix buggy support for search parameter in listPath() method. Add | |
58 | SMB_FILE_ATTRIBUTE_INCL_NORMAL bit constant to include 'normal' files with | |
59 | other file types in the returned result. From now on, pysmb defines a 'normal' file | |
60 | as a file entry that is not read-only, not hidden, not system, not archive and | |
61 | not a directory; it ignores other attributes like compression, indexed, sparse, | |
62 | temporary and encryption. listPath() method will now include 'normal' files | |
63 | using the default search parameter. | |
64 | - Add isNormal property to SharedFile class to support test if the file is a | |
65 | 'normal' file (according to pysmb definition of 'normal' file). | |
66 | ||
67 | pysmb-1.1.24, 19 July 2018 | |
68 | ======================== | |
69 | - Improve listPath implementation for SMB1 | |
70 | - Support for STATUS_PENDING responses across all SMB2 operations. | |
71 | ||
72 | pysmb-1.1.23, 5 May 2018 | |
73 | ======================== | |
74 | - Fix bug in listShares() method which fails when the remote server has many shares. | |
75 | - Improve echo() method to test and fail if the provided data to echo is not a bytes object. | |
76 | - Fix bug in listPath() method where the path to query is not properly terminated. | |
77 | ||
78 | pysmb-1.1.22, 17 Sep 2017 | |
79 | ======================== | |
80 | - Fix bug in getAttributes() method which should return only the filename | |
81 | instead of the entire path for the filename property for the return result. | |
82 | ||
83 | pysmb-1.1.21, 9 Sep 2017 | |
84 | ======================== | |
85 | - Fix bug where timestamp values for SMB1 getAttributes() response are not | |
86 | converted properly from FILETIME to epoch time values. | |
87 | ||
88 | pysmb-1.1.20, 13 Aug 2017 | |
89 | ========================= | |
90 | - Add getSecurity() method to support security descriptors query via SMB2 | |
91 | - Improve retrieveFile() and retrieveFileFromOffset() methods to allow file | |
92 | retrievals over SMB2 even when the file is being locked on the server. | |
93 | - Silently discards NMB SESSION_KEEPALIVE packets instead of raising warnings. | |
94 | - SMB sessionID will be sent in ECHO requests to conform to SMB2 specs. | |
95 | - Fix type errors for MD4 functions in python3. | |
96 | ||
0 | 97 | pysmb-1.1.19, 13 Nov 2016 |
1 | ======================== | |
98 | ========================= | |
2 | 99 | - Ignore STATUS_PENDING during delete and file store operations |
3 | 100 | |
4 | 101 | pysmb-1.1.18, 9 Apr 2016 |
0 | 0 | |
1 | Copyright (C) 2001-2015 Michael Teo <miketeo (a) miketeo.net> | |
1 | Copyright (C) 2001-2020 Michael Teo <miketeo (a) miketeo.net> | |
2 | 2 | |
3 | 3 | This software is provided 'as-is', without any express or implied warranty. |
4 | 4 | In no event will the author be held liable for any damages arising from the |
0 | include LICENSE | |
1 | include CHANGELOG | |
2 | recursive-include python2 * | |
3 | recursive-exclude python2 *.pyc | |
4 | recursive-exclude python2 *~ | |
5 | recursive-include python3 * | |
6 | recursive-exclude python3 *.pyc | |
7 | recursive-exclude python3 *~ | |
8 | recursive-include sphinx * | |
9 | recursive-include docs * | |
10 | recursive-exclude docs *.zip |
0 | 0 | Metadata-Version: 1.1 |
1 | 1 | Name: pysmb |
2 | Version: 1.1.19 | |
2 | Version: 1.2.6 | |
3 | 3 | Summary: pysmb is an experimental SMB/CIFS library written in Python to support file sharing between Windows and Linux machines |
4 | 4 | Home-page: https://miketeo.net/projects/pysmb |
5 | 5 | Author: Michael Teo |
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
0 | 0 | # Sphinx build info version 1 |
1 | 1 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. |
2 | config: 8ec856095809db2990831edf01ebc5a4 | |
2 | config: 25ba8f2e92503ade60b28e1a69a6901b | |
3 | 3 | tags: 645f666f9bcd5a90fca523b33c5a78b7 |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>Overview: module code — pysmb 1.1.18 documentation</title> | |
8 | <title>Overview: module code — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../index.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../index.html" /> | |
26 | 26 | </head> |
27 | 27 | <body role="document"> |
28 | 28 | <div class="related" role="navigation" aria-label="related navigation"> |
31 | 31 | <li class="right" style="margin-right: 10px"> |
32 | 32 | <a href="../genindex.html" title="General Index" |
33 | 33 | accesskey="I">index</a></li> |
34 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
34 | <li class="right" > | |
35 | <a href="../py-modindex.html" title="Python Module Index" | |
36 | >modules</a> |</li> | |
37 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
35 | 38 | </ul> |
36 | 39 | </div> |
37 | 40 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
63 | 66 | <li><a href="smb/SMBConnection.html">smb.SMBConnection</a></li> |
64 | 67 | <li><a href="smb/SMBProtocol.html">smb.SMBProtocol</a></li> |
65 | 68 | <li><a href="smb/base.html">smb.base</a></li> |
69 | <li><a href="smb/security_descriptors.html">smb.security_descriptors</a></li> | |
66 | 70 | <li><a href="smb/smb_structs.html">smb.smb_structs</a></li> |
67 | 71 | </ul> |
68 | 72 | |
77 | 81 | <li class="right" style="margin-right: 10px"> |
78 | 82 | <a href="../genindex.html" title="General Index" |
79 | 83 | >index</a></li> |
80 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
84 | <li class="right" > | |
85 | <a href="../py-modindex.html" title="Python Module Index" | |
86 | >modules</a> |</li> | |
87 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
81 | 88 | </ul> |
82 | 89 | </div> |
83 | 90 | <div class="footer" role="contentinfo"> |
84 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
91 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
85 | 92 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
86 | 93 | </div> |
87 | 94 | </body> |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>nmb.NetBIOS — pysmb 1.1.18 documentation</title> | |
8 | <title>nmb.NetBIOS — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../../index.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../../index.html" /> | |
26 | 26 | <link rel="up" title="Module code" href="../index.html" /> |
27 | 27 | </head> |
28 | 28 | <body role="document"> |
32 | 32 | <li class="right" style="margin-right: 10px"> |
33 | 33 | <a href="../../genindex.html" title="General Index" |
34 | 34 | accesskey="I">index</a></li> |
35 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.18 documentation</a> »</li> | |
35 | <li class="right" > | |
36 | <a href="../../py-modindex.html" title="Python Module Index" | |
37 | >modules</a> |</li> | |
38 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.2.1 documentation</a> »</li> | |
36 | 39 | <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> »</li> |
37 | 40 | </ul> |
38 | 41 | </div> |
217 | 220 | <li class="right" style="margin-right: 10px"> |
218 | 221 | <a href="../../genindex.html" title="General Index" |
219 | 222 | >index</a></li> |
220 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.18 documentation</a> »</li> | |
223 | <li class="right" > | |
224 | <a href="../../py-modindex.html" title="Python Module Index" | |
225 | >modules</a> |</li> | |
226 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.2.1 documentation</a> »</li> | |
221 | 227 | <li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> »</li> |
222 | 228 | </ul> |
223 | 229 | </div> |
224 | 230 | <div class="footer" role="contentinfo"> |
225 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
231 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
226 | 232 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
227 | 233 | </div> |
228 | 234 | </body> |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>nmb.NetBIOSProtocol — pysmb 1.1.18 documentation</title> | |
8 | <title>nmb.NetBIOSProtocol — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../../index.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../../index.html" /> | |
26 | 26 | <link rel="up" title="Module code" href="../index.html" /> |
27 | 27 | </head> |
28 | 28 | <body role="document"> |
32 | 32 | <li class="right" style="margin-right: 10px"> |
33 | 33 | <a href="../../genindex.html" title="General Index" |
34 | 34 | accesskey="I">index</a></li> |
35 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.18 documentation</a> »</li> | |
35 | <li class="right" > | |
36 | <a href="../../py-modindex.html" title="Python Module Index" | |
37 | >modules</a> |</li> | |
38 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.2.1 documentation</a> »</li> | |
36 | 39 | <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> »</li> |
37 | 40 | </ul> |
38 | 41 | </div> |
209 | 212 | <li class="right" style="margin-right: 10px"> |
210 | 213 | <a href="../../genindex.html" title="General Index" |
211 | 214 | >index</a></li> |
212 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.18 documentation</a> »</li> | |
215 | <li class="right" > | |
216 | <a href="../../py-modindex.html" title="Python Module Index" | |
217 | >modules</a> |</li> | |
218 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.2.1 documentation</a> »</li> | |
213 | 219 | <li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> »</li> |
214 | 220 | </ul> |
215 | 221 | </div> |
216 | 222 | <div class="footer" role="contentinfo"> |
217 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
223 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
218 | 224 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
219 | 225 | </div> |
220 | 226 | </body> |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>smb.SMBConnection — pysmb 1.1.18 documentation</title> | |
8 | <title>smb.SMBConnection — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../../index.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../../index.html" /> | |
26 | 26 | <link rel="up" title="Module code" href="../index.html" /> |
27 | 27 | </head> |
28 | 28 | <body role="document"> |
32 | 32 | <li class="right" style="margin-right: 10px"> |
33 | 33 | <a href="../../genindex.html" title="General Index" |
34 | 34 | accesskey="I">index</a></li> |
35 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.18 documentation</a> »</li> | |
35 | <li class="right" > | |
36 | <a href="../../py-modindex.html" title="Python Module Index" | |
37 | >modules</a> |</li> | |
38 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.2.1 documentation</a> »</li> | |
36 | 39 | <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> »</li> |
37 | 40 | </ul> |
38 | 41 | </div> |
83 | 86 | <span class="sd"> Create a new SMBConnection instance.</span> |
84 | 87 | |
85 | 88 | <span class="sd"> *username* and *password* are the user credentials required to authenticate the underlying SMB connection with the remote server.</span> |
89 | <span class="sd"> *password* can be a string or a callable returning a string.</span> | |
86 | 90 | <span class="sd"> File operations can only be proceeded after the connection has been authenticated successfully.</span> |
87 | 91 | |
88 | 92 | <span class="sd"> Note that you need to call *connect* method to actually establish the SMB connection to the remote server and perform authentication.</span> |
134 | 138 | <span class="n">total_sent</span> <span class="o">=</span> <span class="n">total_sent</span> <span class="o">+</span> <span class="n">sent</span> |
135 | 139 | |
136 | 140 | <span class="c1">#</span> |
141 | <span class="c1"># Support for "with" context</span> | |
142 | <span class="c1">#</span> | |
143 | <span class="k">def</span> <span class="nf">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |
144 | <span class="k">return</span> <span class="bp">self</span> | |
145 | ||
146 | <span class="k">def</span> <span class="nf">__exit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span> | |
147 | <span class="bp">self</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> | |
148 | ||
149 | <span class="c1">#</span> | |
137 | 150 | <span class="c1"># Misc Properties</span> |
138 | 151 | <span class="c1">#</span> |
139 | 152 | |
215 | 228 | <span class="k">return</span> <span class="n">results</span></div> |
216 | 229 | |
217 | 230 | <div class="viewcode-block" id="SMBConnection.listPath"><a class="viewcode-back" href="../../api/smb_SMBConnection.html#smb.SMBConnection.SMBConnection.listPath">[docs]</a> <span class="k">def</span> <span class="nf">listPath</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> |
218 | <span class="n">search</span> <span class="o">=</span> <span class="n">SMB_FILE_ATTRIBUTE_READONLY</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_HIDDEN</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_SYSTEM</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_DIRECTORY</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_ARCHIVE</span><span class="p">,</span> | |
231 | <span class="n">search</span> <span class="o">=</span> <span class="n">SMB_FILE_ATTRIBUTE_READONLY</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_HIDDEN</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_SYSTEM</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_DIRECTORY</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_ARCHIVE</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_INCL_NORMAL</span><span class="p">,</span> | |
219 | 232 | <span class="n">pattern</span> <span class="o">=</span> <span class="s1">'*'</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> |
220 | 233 | <span class="sd">"""</span> |
221 | 234 | <span class="sd"> Retrieve a directory listing of files/folders at *path*</span> |
235 | ||
236 | <span class="sd"> For simplicity, pysmb defines a "normal" file as a file entry that is not read-only, not hidden, not system, not archive and not a directory.</span> | |
237 | <span class="sd"> It ignores other attributes like compression, indexed, sparse, temporary and encryption.</span> | |
238 | ||
239 | <span class="sd"> Note that the default search parameter will query for all read-only (SMB_FILE_ATTRIBUTE_READONLY), hidden (SMB_FILE_ATTRIBUTE_HIDDEN),</span> | |
240 | <span class="sd"> system (SMB_FILE_ATTRIBUTE_SYSTEM), archive (SMB_FILE_ATTRIBUTE_ARCHIVE), normal (SMB_FILE_ATTRIBUTE_INCL_NORMAL) files</span> | |
241 | <span class="sd"> and directories (SMB_FILE_ATTRIBUTE_DIRECTORY).</span> | |
242 | <span class="sd"> If you do not need to include "normal" files in the result, define your own search parameter without the SMB_FILE_ATTRIBUTE_INCL_NORMAL constant.</span> | |
243 | <span class="sd"> SMB_FILE_ATTRIBUTE_NORMAL should be used by itself and not be used with other bit constants.</span> | |
222 | 244 | |
223 | 245 | <span class="sd"> :param string/unicode service_name: the name of the shared folder for the *path*</span> |
224 | 246 | <span class="sd"> :param string/unicode path: path relative to the *service_name* where we are interested to learn about its files/sub-folders.</span> |
225 | 247 | <span class="sd"> :param integer search: integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py).</span> |
226 | <span class="sd"> The default *search* value will query for all read-only, hidden, system, archive files and directories.</span> | |
227 | 248 | <span class="sd"> :param string/unicode pattern: the filter to apply to the results before returning to the client.</span> |
228 | 249 | <span class="sd"> :return: A list of :doc:`smb.base.SharedFile<smb_SharedFile>` instances.</span> |
229 | 250 | <span class="sd"> """</span> |
307 | 328 | <span class="bp">self</span><span class="o">.</span><span class="n">is_busy</span> <span class="o">=</span> <span class="bp">True</span> |
308 | 329 | <span class="k">try</span><span class="p">:</span> |
309 | 330 | <span class="bp">self</span><span class="o">.</span><span class="n">_getAttributes</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">cb</span><span class="p">,</span> <span class="n">eb</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span> |
331 | <span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_busy</span><span class="p">:</span> | |
332 | <span class="bp">self</span><span class="o">.</span><span class="n">_pollForNetBIOSPacket</span><span class="p">(</span><span class="n">timeout</span><span class="p">)</span> | |
333 | <span class="k">finally</span><span class="p">:</span> | |
334 | <span class="bp">self</span><span class="o">.</span><span class="n">is_busy</span> <span class="o">=</span> <span class="bp">False</span> | |
335 | ||
336 | <span class="k">return</span> <span class="n">results</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div> | |
337 | ||
338 | <div class="viewcode-block" id="SMBConnection.getSecurity"><a class="viewcode-back" href="../../api/smb_SMBConnection.html#smb.SMBConnection.SMBConnection.getSecurity">[docs]</a> <span class="k">def</span> <span class="nf">getSecurity</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
339 | <span class="sd">"""</span> | |
340 | <span class="sd"> Retrieve the security descriptor of the file at *path* on the *service_name*.</span> | |
341 | ||
342 | <span class="sd"> :param string/unicode service_name: the name of the shared folder for the *path*</span> | |
343 | <span class="sd"> :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be raised.</span> | |
344 | <span class="sd"> :return: A :class:`smb.security_descriptors.SecurityDescriptor` instance containing the security information of the file.</span> | |
345 | <span class="sd"> """</span> | |
346 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="p">:</span> | |
347 | <span class="k">raise</span> <span class="n">NotConnectedError</span><span class="p">(</span><span class="s1">'Not connected to server'</span><span class="p">)</span> | |
348 | ||
349 | <span class="n">results</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> | |
350 | ||
351 | <span class="k">def</span> <span class="nf">cb</span><span class="p">(</span><span class="n">info</span><span class="p">):</span> | |
352 | <span class="bp">self</span><span class="o">.</span><span class="n">is_busy</span> <span class="o">=</span> <span class="bp">False</span> | |
353 | <span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">info</span><span class="p">)</span> | |
354 | ||
355 | <span class="k">def</span> <span class="nf">eb</span><span class="p">(</span><span class="n">failure</span><span class="p">):</span> | |
356 | <span class="bp">self</span><span class="o">.</span><span class="n">is_busy</span> <span class="o">=</span> <span class="bp">False</span> | |
357 | <span class="k">raise</span> <span class="n">failure</span> | |
358 | ||
359 | <span class="bp">self</span><span class="o">.</span><span class="n">is_busy</span> <span class="o">=</span> <span class="bp">True</span> | |
360 | <span class="k">try</span><span class="p">:</span> | |
361 | <span class="bp">self</span><span class="o">.</span><span class="n">_getSecurity</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">cb</span><span class="p">,</span> <span class="n">eb</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span> | |
310 | 362 | <span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_busy</span><span class="p">:</span> |
311 | 363 | <span class="bp">self</span><span class="o">.</span><span class="n">_pollForNetBIOSPacket</span><span class="p">(</span><span class="n">timeout</span><span class="p">)</span> |
312 | 364 | <span class="k">finally</span><span class="p">:</span> |
412 | 464 | |
413 | 465 | <span class="k">return</span> <span class="n">results</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div> |
414 | 466 | |
415 | <div class="viewcode-block" id="SMBConnection.deleteFiles"><a class="viewcode-back" href="../../api/smb_SMBConnection.html#smb.SMBConnection.SMBConnection.deleteFiles">[docs]</a> <span class="k">def</span> <span class="nf">deleteFiles</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path_file_pattern</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
467 | <div class="viewcode-block" id="SMBConnection.deleteFiles"><a class="viewcode-back" href="../../api/smb_SMBConnection.html#smb.SMBConnection.SMBConnection.deleteFiles">[docs]</a> <span class="k">def</span> <span class="nf">deleteFiles</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path_file_pattern</span><span class="p">,</span> <span class="n">delete_matching_folders</span> <span class="o">=</span> <span class="bp">False</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
416 | 468 | <span class="sd">"""</span> |
417 | 469 | <span class="sd"> Delete one or more regular files. It supports the use of wildcards in file names, allowing for deletion of multiple files in a single request.</span> |
470 | ||
471 | <span class="sd"> If delete_matching_folders is True, immediate sub-folders that match the path_file_pattern will be deleted recursively.</span> | |
418 | 472 | |
419 | 473 | <span class="sd"> :param string/unicode service_name: Contains the name of the shared folder.</span> |
420 | 474 | <span class="sd"> :param string/unicode path_file_pattern: The pathname of the file(s) to be deleted, relative to the service_name.</span> |
434 | 488 | |
435 | 489 | <span class="bp">self</span><span class="o">.</span><span class="n">is_busy</span> <span class="o">=</span> <span class="bp">True</span> |
436 | 490 | <span class="k">try</span><span class="p">:</span> |
437 | <span class="bp">self</span><span class="o">.</span><span class="n">_deleteFiles</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">path_file_pattern</span><span class="p">,</span> <span class="n">cb</span><span class="p">,</span> <span class="n">eb</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="n">timeout</span><span class="p">)</span> | |
491 | <span class="bp">self</span><span class="o">.</span><span class="n">_deleteFiles</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">path_file_pattern</span><span class="p">,</span> <span class="n">delete_matching_folders</span><span class="p">,</span> <span class="n">cb</span><span class="p">,</span> <span class="n">eb</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="n">timeout</span><span class="p">)</span> | |
438 | 492 | <span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_busy</span><span class="p">:</span> |
439 | 493 | <span class="bp">self</span><span class="o">.</span><span class="n">_pollForNetBIOSPacket</span><span class="p">(</span><span class="n">timeout</span><span class="p">)</span> |
440 | 494 | <span class="k">finally</span><span class="p">:</span> |
557 | 611 | <span class="sd">"""</span> |
558 | 612 | <span class="sd"> Send an echo command containing *data* to the remote SMB/CIFS server. The remote SMB/CIFS will reply with the same *data*.</span> |
559 | 613 | |
560 | <span class="sd"> :param string data: Data to send to the remote server.</span> | |
614 | <span class="sd"> :param bytes data: Data to send to the remote server. Must be a bytes object.</span> | |
561 | 615 | <span class="sd"> :return: The *data* parameter</span> |
562 | 616 | <span class="sd"> """</span> |
563 | 617 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="p">:</span> |
655 | 709 | <li class="right" style="margin-right: 10px"> |
656 | 710 | <a href="../../genindex.html" title="General Index" |
657 | 711 | >index</a></li> |
658 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.18 documentation</a> »</li> | |
712 | <li class="right" > | |
713 | <a href="../../py-modindex.html" title="Python Module Index" | |
714 | >modules</a> |</li> | |
715 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.2.1 documentation</a> »</li> | |
659 | 716 | <li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> »</li> |
660 | 717 | </ul> |
661 | 718 | </div> |
662 | 719 | <div class="footer" role="contentinfo"> |
663 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
720 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
664 | 721 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
665 | 722 | </div> |
666 | 723 | </body> |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>smb.SMBProtocol — pysmb 1.1.18 documentation</title> | |
8 | <title>smb.SMBProtocol — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../../index.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../../index.html" /> | |
26 | 26 | <link rel="up" title="Module code" href="../index.html" /> |
27 | 27 | </head> |
28 | 28 | <body role="document"> |
32 | 32 | <li class="right" style="margin-right: 10px"> |
33 | 33 | <a href="../../genindex.html" title="General Index" |
34 | 34 | accesskey="I">index</a></li> |
35 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.18 documentation</a> »</li> | |
35 | <li class="right" > | |
36 | <a href="../../py-modindex.html" title="Python Module Index" | |
37 | >modules</a> |</li> | |
38 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.2.1 documentation</a> »</li> | |
36 | 39 | <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> »</li> |
37 | 40 | </ul> |
38 | 41 | </div> |
239 | 242 | <span class="k">return</span> <span class="n">d</span></div> |
240 | 243 | |
241 | 244 | <div class="viewcode-block" id="SMBProtocolFactory.listPath"><a class="viewcode-back" href="../../api/smb_SMBProtocolFactory.html#smb.SMBProtocol.SMBProtocolFactory.listPath">[docs]</a> <span class="k">def</span> <span class="nf">listPath</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> |
242 | <span class="n">search</span> <span class="o">=</span> <span class="n">SMB_FILE_ATTRIBUTE_READONLY</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_HIDDEN</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_SYSTEM</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_DIRECTORY</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_ARCHIVE</span><span class="p">,</span> | |
245 | <span class="n">search</span> <span class="o">=</span> <span class="n">SMB_FILE_ATTRIBUTE_READONLY</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_HIDDEN</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_SYSTEM</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_DIRECTORY</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_ARCHIVE</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_INCL_NORMAL</span><span class="p">,</span> | |
243 | 246 | <span class="n">pattern</span> <span class="o">=</span> <span class="s1">'*'</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> |
244 | 247 | <span class="sd">"""</span> |
245 | 248 | <span class="sd"> Retrieve a directory listing of files/folders at *path*</span> |
249 | ||
250 | <span class="sd"> For simplicity, pysmb defines a "normal" file as a file entry that is not read-only, not hidden, not system, not archive and not a directory.</span> | |
251 | <span class="sd"> It ignores other attributes like compression, indexed, sparse, temporary and encryption.</span> | |
252 | ||
253 | <span class="sd"> Note that the default search parameter will query for all read-only (SMB_FILE_ATTRIBUTE_READONLY), hidden (SMB_FILE_ATTRIBUTE_HIDDEN),</span> | |
254 | <span class="sd"> system (SMB_FILE_ATTRIBUTE_SYSTEM), archive (SMB_FILE_ATTRIBUTE_ARCHIVE), normal (SMB_FILE_ATTRIBUTE_INCL_NORMAL) files</span> | |
255 | <span class="sd"> and directories (SMB_FILE_ATTRIBUTE_DIRECTORY).</span> | |
256 | <span class="sd"> If you do not need to include "normal" files in the result, define your own search parameter without the SMB_FILE_ATTRIBUTE_INCL_NORMAL constant.</span> | |
257 | <span class="sd"> SMB_FILE_ATTRIBUTE_NORMAL should be used by itself and not be used with other bit constants.</span> | |
246 | 258 | |
247 | 259 | <span class="sd"> :param string/unicode service_name: the name of the shared folder for the *path*</span> |
248 | 260 | <span class="sd"> :param string/unicode path: path relative to the *service_name* where we are interested to learn about its files/sub-folders.</span> |
249 | 261 | <span class="sd"> :param integer search: integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py).</span> |
250 | <span class="sd"> The default *search* value will query for all read-only, hidden, system, archive files and directories.</span> | |
251 | 262 | <span class="sd"> :param string/unicode pattern: the filter to apply to the results before returning to the client.</span> |
252 | 263 | <span class="sd"> :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.</span> |
253 | 264 | <span class="sd"> :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of :doc:`smb.base.SharedFile<smb_SharedFile>` instances.</span> |
430 | 441 | <span class="sd">"""</span> |
431 | 442 | <span class="sd"> Send an echo command containing *data* to the remote SMB/CIFS server. The remote SMB/CIFS will reply with the same *data*.</span> |
432 | 443 | |
433 | <span class="sd"> :param string data: Data to send to the remote server.</span> | |
444 | <span class="sd"> :param bytes data: Data to send to the remote server. Must be a bytes object.</span> | |
434 | 445 | <span class="sd"> :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.</span> |
435 | 446 | <span class="sd"> :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with the *data* parameter.</span> |
436 | 447 | <span class="sd"> """</span> |
474 | 485 | <li class="right" style="margin-right: 10px"> |
475 | 486 | <a href="../../genindex.html" title="General Index" |
476 | 487 | >index</a></li> |
477 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.18 documentation</a> »</li> | |
488 | <li class="right" > | |
489 | <a href="../../py-modindex.html" title="Python Module Index" | |
490 | >modules</a> |</li> | |
491 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.2.1 documentation</a> »</li> | |
478 | 492 | <li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> »</li> |
479 | 493 | </ul> |
480 | 494 | </div> |
481 | 495 | <div class="footer" role="contentinfo"> |
482 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
496 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
483 | 497 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
484 | 498 | </div> |
485 | 499 | </body> |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>smb.base — pysmb 1.1.18 documentation</title> | |
8 | <title>smb.base — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../../index.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../../index.html" /> | |
26 | 26 | <link rel="up" title="Module code" href="../index.html" /> |
27 | 27 | </head> |
28 | 28 | <body role="document"> |
32 | 32 | <li class="right" style="margin-right: 10px"> |
33 | 33 | <a href="../../genindex.html" title="General Index" |
34 | 34 | accesskey="I">index</a></li> |
35 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.18 documentation</a> »</li> | |
35 | <li class="right" > | |
36 | <a href="../../py-modindex.html" title="Python Module Index" | |
37 | >modules</a> |</li> | |
38 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.2.1 documentation</a> »</li> | |
36 | 39 | <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> »</li> |
37 | 40 | </ul> |
38 | 41 | </div> |
67 | 70 | <span class="kn">from</span> <span class="nn">smb2_constants</span> <span class="kn">import</span> <span class="o">*</span> |
68 | 71 | <span class="kn">from</span> <span class="nn">smb_structs</span> <span class="kn">import</span> <span class="o">*</span> |
69 | 72 | <span class="kn">from</span> <span class="nn">smb2_structs</span> <span class="kn">import</span> <span class="o">*</span> |
73 | <span class="kn">from</span> <span class="nn">.security_descriptors</span> <span class="kn">import</span> <span class="n">SecurityDescriptor</span> | |
70 | 74 | <span class="kn">from</span> <span class="nn">nmb.base</span> <span class="kn">import</span> <span class="n">NMBSession</span> |
71 | 75 | <span class="kn">from</span> <span class="nn">utils</span> <span class="kn">import</span> <span class="n">convertFILETIMEtoEpoch</span> |
72 | 76 | <span class="kn">import</span> <span class="nn">ntlm</span><span class="o">,</span> <span class="nn">securityblob</span> |
121 | 125 | <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">my_name</span><span class="p">,</span> <span class="n">remote_name</span><span class="p">,</span> <span class="n">domain</span> <span class="o">=</span> <span class="s1">''</span><span class="p">,</span> <span class="n">use_ntlm_v2</span> <span class="o">=</span> <span class="bp">True</span><span class="p">,</span> <span class="n">sign_options</span> <span class="o">=</span> <span class="n">SIGN_WHEN_REQUIRED</span><span class="p">,</span> <span class="n">is_direct_tcp</span> <span class="o">=</span> <span class="bp">False</span><span class="p">):</span> |
122 | 126 | <span class="n">NMBSession</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">my_name</span><span class="p">,</span> <span class="n">remote_name</span><span class="p">,</span> <span class="n">is_direct_tcp</span> <span class="o">=</span> <span class="n">is_direct_tcp</span><span class="p">)</span> |
123 | 127 | <span class="bp">self</span><span class="o">.</span><span class="n">username</span> <span class="o">=</span> <span class="n">_convert_to_unicode</span><span class="p">(</span><span class="n">username</span><span class="p">)</span> |
124 | <span class="bp">self</span><span class="o">.</span><span class="n">password</span> <span class="o">=</span> <span class="n">_convert_to_unicode</span><span class="p">(</span><span class="n">password</span><span class="p">)</span> | |
128 | <span class="bp">self</span><span class="o">.</span><span class="n">_password</span> <span class="o">=</span> <span class="n">password</span> | |
125 | 129 | <span class="bp">self</span><span class="o">.</span><span class="n">domain</span> <span class="o">=</span> <span class="n">_convert_to_unicode</span><span class="p">(</span><span class="n">domain</span><span class="p">)</span> |
126 | 130 | <span class="bp">self</span><span class="o">.</span><span class="n">sign_options</span> <span class="o">=</span> <span class="n">sign_options</span> |
127 | 131 | <span class="bp">self</span><span class="o">.</span><span class="n">is_direct_tcp</span> <span class="o">=</span> <span class="n">is_direct_tcp</span> |
128 | 132 | <span class="bp">self</span><span class="o">.</span><span class="n">use_ntlm_v2</span> <span class="o">=</span> <span class="n">use_ntlm_v2</span> <span class="c1">#: Similar to LMAuthenticationPolicy and NTAuthenticationPolicy as described in [MS-CIFS] 3.2.1.1</span> |
129 | 133 | <span class="bp">self</span><span class="o">.</span><span class="n">smb_message</span> <span class="o">=</span> <span class="n">SMBMessage</span><span class="p">()</span> |
130 | 134 | <span class="bp">self</span><span class="o">.</span><span class="n">is_using_smb2</span> <span class="o">=</span> <span class="bp">False</span> <span class="c1">#: Are we communicating using SMB2 protocol? self.smb_message will be a SMB2Message instance if this flag is True</span> |
135 | <span class="bp">self</span><span class="o">.</span><span class="n">async_requests</span> <span class="o">=</span> <span class="p">{</span> <span class="p">}</span> <span class="c1">#: AsyncID mapped to _PendingRequest instance</span> | |
131 | 136 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span> <span class="o">=</span> <span class="p">{</span> <span class="p">}</span> <span class="c1">#: MID mapped to _PendingRequest instance</span> |
132 | 137 | <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span> <span class="o">=</span> <span class="p">{</span> <span class="p">}</span> <span class="c1">#: Share name mapped to TID</span> |
133 | 138 | <span class="bp">self</span><span class="o">.</span><span class="n">next_rpc_call_id</span> <span class="o">=</span> <span class="mi">1</span> <span class="c1">#: Next RPC callID value. Not used directly in SMB message. Usually encapsulated in sub-commands under SMB_COM_TRANSACTION or SMB_COM_TRANSACTION2 messages</span> |
166 | 171 | <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">use_ntlm_v2</span> <span class="ow">and</span> <span class="s1">'v2'</span><span class="p">)</span> <span class="ow">or</span> <span class="s1">'v1'</span><span class="p">,</span> |
167 | 172 | <span class="p">(</span><span class="n">SUPPORT_EXTENDED_SECURITY</span> <span class="ow">and</span> <span class="s1">'with'</span><span class="p">)</span> <span class="ow">or</span> <span class="s1">'without'</span><span class="p">)</span> |
168 | 173 | |
174 | <span class="nd">@property</span> | |
175 | <span class="k">def</span> <span class="nf">password</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |
176 | <span class="n">password</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_password</span><span class="p">()</span> <span class="k">if</span> <span class="nb">callable</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_password</span><span class="p">)</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">_password</span> | |
177 | <span class="k">return</span> <span class="n">_convert_to_unicode</span><span class="p">(</span><span class="n">password</span><span class="p">)</span> | |
169 | 178 | |
170 | 179 | <span class="c1">#</span> |
171 | 180 | <span class="c1"># NMBSession Methods</span> |
235 | 244 | <span class="bp">self</span><span class="o">.</span><span class="n">_listShares</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_listShares_SMB1</span> |
236 | 245 | <span class="bp">self</span><span class="o">.</span><span class="n">_listPath</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_listPath_SMB1</span> |
237 | 246 | <span class="bp">self</span><span class="o">.</span><span class="n">_listSnapshots</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_listSnapshots_SMB1</span> |
247 | <span class="bp">self</span><span class="o">.</span><span class="n">_getSecurity</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_getSecurity_SMB1</span> | |
238 | 248 | <span class="bp">self</span><span class="o">.</span><span class="n">_getAttributes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_getAttributes_SMB1</span> |
239 | 249 | <span class="bp">self</span><span class="o">.</span><span class="n">_retrieveFile</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_retrieveFile_SMB1</span> |
240 | 250 | <span class="bp">self</span><span class="o">.</span><span class="n">_retrieveFileFromOffset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_retrieveFileFromOffset_SMB1</span> |
258 | 268 | <span class="bp">self</span><span class="o">.</span><span class="n">_listPath</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_listPath_SMB2</span> |
259 | 269 | <span class="bp">self</span><span class="o">.</span><span class="n">_listSnapshots</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_listSnapshots_SMB2</span> |
260 | 270 | <span class="bp">self</span><span class="o">.</span><span class="n">_getAttributes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_getAttributes_SMB2</span> |
271 | <span class="bp">self</span><span class="o">.</span><span class="n">_getSecurity</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_getSecurity_SMB2</span> | |
261 | 272 | <span class="bp">self</span><span class="o">.</span><span class="n">_retrieveFile</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_retrieveFile_SMB2</span> |
262 | 273 | <span class="bp">self</span><span class="o">.</span><span class="n">_retrieveFileFromOffset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_retrieveFileFromOffset_SMB2</span> |
263 | 274 | <span class="bp">self</span><span class="o">.</span><span class="n">_storeFile</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_storeFile_SMB2</span> |
281 | 292 | <span class="k">if</span> <span class="n">smb_message</span><span class="o">.</span><span class="n">mid</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
282 | 293 | <span class="n">smb_message</span><span class="o">.</span><span class="n">mid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_getNextMID_SMB2</span><span class="p">()</span> |
283 | 294 | |
284 | <span class="k">if</span> <span class="n">smb_message</span><span class="o">.</span><span class="n">command</span> <span class="o">!=</span> <span class="n">SMB2_COM_NEGOTIATE</span> <span class="ow">and</span> <span class="n">smb_message</span><span class="o">.</span><span class="n">command</span> <span class="o">!=</span> <span class="n">SMB2_COM_ECHO</span><span class="p">:</span> | |
295 | <span class="k">if</span> <span class="n">smb_message</span><span class="o">.</span><span class="n">command</span> <span class="o">!=</span> <span class="n">SMB2_COM_NEGOTIATE</span><span class="p">:</span> | |
285 | 296 | <span class="n">smb_message</span><span class="o">.</span><span class="n">session_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">session_id</span> |
286 | 297 | |
287 | 298 | <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_signing_active</span><span class="p">:</span> |
318 | 329 | <span class="k">if</span> <span class="n">result</span> <span class="o">==</span> <span class="n">securityblob</span><span class="o">.</span><span class="n">RESULT_ACCEPT_COMPLETED</span><span class="p">:</span> |
319 | 330 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">True</span> |
320 | 331 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (on SMB2) successful!'</span><span class="p">)</span> |
332 | ||
333 | <span class="c1"># [MS-SMB2]: 3.2.5.3.1</span> | |
334 | <span class="c1"># If the security subsystem indicates that the session was established by an anonymous user,</span> | |
335 | <span class="c1"># Session.SigningRequired MUST be set to FALSE.</span> | |
336 | <span class="c1"># If the SMB2_SESSION_FLAG_IS_GUEST bit is set in the SessionFlags field of the</span> | |
337 | <span class="c1"># SMB2 SESSION_SETUP Response and if Session.SigningRequired is TRUE, this indicates a SESSION_SETUP</span> | |
338 | <span class="c1"># failure and the connection MUST be terminated. If the SMB2_SESSION_FLAG_IS_GUEST bit is set in the SessionFlags</span> | |
339 | <span class="c1"># field of the SMB2 SESSION_SETUP Response and if RequireMessageSigning is FALSE, Session.SigningRequired</span> | |
340 | <span class="c1"># MUST be set to FALSE.</span> | |
341 | <span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">isGuestSession</span> <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">isAnonymousSession</span><span class="p">:</span> | |
342 | <span class="bp">self</span><span class="o">.</span><span class="n">is_signing_active</span> <span class="o">=</span> <span class="bp">False</span> | |
343 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Signing disabled because session is guest/anonymous'</span><span class="p">)</span> | |
344 | ||
321 | 345 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthOK</span><span class="p">()</span> |
322 | 346 | <span class="k">else</span><span class="p">:</span> |
323 | 347 | <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">'SMB2_COM_SESSION_SETUP status is 0 but security blob negResult value is </span><span class="si">%d</span><span class="s1">'</span> <span class="o">%</span> <span class="n">result</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span> |
331 | 355 | <span class="bp">self</span><span class="o">.</span><span class="n">_handleSessionChallenge</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="n">ntlm_token</span><span class="p">)</span> |
332 | 356 | <span class="k">except</span> <span class="p">(</span> <span class="n">securityblob</span><span class="o">.</span><span class="n">BadSecurityBlobError</span><span class="p">,</span> <span class="n">securityblob</span><span class="o">.</span><span class="n">UnsupportedSecurityProvider</span> <span class="p">),</span> <span class="n">ex</span><span class="p">:</span> |
333 | 357 | <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">),</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span> |
334 | <span class="k">elif</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xc000006d</span><span class="p">:</span> <span class="c1"># STATUS_LOGON_FAILURE</span> | |
358 | <span class="k">elif</span> <span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xc000006d</span> <span class="c1"># STATUS_LOGON_FAILURE</span> | |
359 | <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xc0000064</span> <span class="c1"># STATUS_NO_SUCH_USER</span> | |
360 | <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xc000006a</span><span class="p">):</span><span class="c1"># STATUS_WRONG_PASSWORD</span> | |
335 | 361 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">False</span> |
336 | 362 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (on SMB2) failed. Please check username and password.'</span><span class="p">)</span> |
337 | 363 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthFailed</span><span class="p">()</span> |
364 | <span class="k">elif</span> <span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xc0000193</span> <span class="c1"># STATUS_ACCOUNT_EXPIRED</span> | |
365 | <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xC0000071</span><span class="p">):</span> <span class="c1"># STATUS_PASSWORD_EXPIRED</span> | |
366 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">False</span> | |
367 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (on SMB2) failed. Account or password has expired.'</span><span class="p">)</span> | |
368 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthFailed</span><span class="p">()</span> | |
369 | <span class="k">elif</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xc0000234</span><span class="p">:</span> <span class="c1"># STATUS_ACCOUNT_LOCKED_OUT</span> | |
370 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">False</span> | |
371 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (on SMB2) failed. Account has been locked due to too many invalid logon attempts.'</span><span class="p">)</span> | |
372 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthFailed</span><span class="p">()</span> | |
373 | <span class="k">elif</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xc0000072</span><span class="p">:</span> <span class="c1"># STATUS_ACCOUNT_DISABLED</span> | |
374 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">False</span> | |
375 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (on SMB2) failed. Account has been disabled.'</span><span class="p">)</span> | |
376 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthFailed</span><span class="p">()</span> | |
377 | <span class="k">elif</span> <span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xc000006f</span> <span class="c1"># STATUS_INVALID_LOGON_HOURS</span> | |
378 | <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xc000015b</span> <span class="c1"># STATUS_LOGON_TYPE_NOT_GRANTED</span> | |
379 | <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xc0000070</span><span class="p">):</span> <span class="c1"># STATUS_INVALID_WORKSTATION</span> | |
380 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">False</span> | |
381 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (on SMB2) failed. Not allowed.'</span><span class="p">)</span> | |
382 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthFailed</span><span class="p">()</span> | |
383 | <span class="k">elif</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xc000018c</span><span class="p">:</span> <span class="c1"># STATUS_TRUSTED_DOMAIN_FAILURE</span> | |
384 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">False</span> | |
385 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (on SMB2) failed. Domain not trusted.'</span><span class="p">)</span> | |
386 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthFailed</span><span class="p">()</span> | |
387 | <span class="k">elif</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xc000018d</span><span class="p">:</span> <span class="c1"># STATUS_TRUSTED_RELATIONSHIP_FAILURE</span> | |
388 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">False</span> | |
389 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (on SMB2) failed. Workstation not trusted.'</span><span class="p">)</span> | |
390 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthFailed</span><span class="p">()</span> | |
338 | 391 | <span class="k">else</span><span class="p">:</span> |
339 | 392 | <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">'Unknown status value (0x</span><span class="si">%08X</span><span class="s1">) in SMB_COM_SESSION_SETUP_ANDX (with extended security)'</span> <span class="o">%</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="p">,</span> |
340 | 393 | <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span> |
341 | 394 | |
342 | <span class="n">req</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span> | |
343 | <span class="k">if</span> <span class="n">req</span><span class="p">:</span> | |
344 | <span class="n">req</span><span class="o">.</span><span class="n">callback</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="o">**</span><span class="n">req</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span> | |
345 | <span class="k">return</span> <span class="bp">True</span> | |
395 | <span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">isAsync</span><span class="p">:</span> | |
396 | <span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0x00000103</span><span class="p">:</span> <span class="c1"># STATUS_PENDING</span> | |
397 | <span class="n">req</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span> | |
398 | <span class="k">if</span> <span class="n">req</span><span class="p">:</span> | |
399 | <span class="bp">self</span><span class="o">.</span><span class="n">async_requests</span><span class="p">[</span><span class="n">message</span><span class="o">.</span><span class="n">async_id</span><span class="p">]</span> <span class="o">=</span> <span class="n">req</span> | |
400 | <span class="k">else</span><span class="p">:</span> <span class="c1"># All other status including SUCCESS</span> | |
401 | <span class="n">req</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">async_requests</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">async_id</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span> | |
402 | <span class="k">if</span> <span class="n">req</span><span class="p">:</span> | |
403 | <span class="n">req</span><span class="o">.</span><span class="n">callback</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="o">**</span><span class="n">req</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span> | |
404 | <span class="k">return</span> <span class="bp">True</span> | |
405 | <span class="k">else</span><span class="p">:</span> | |
406 | <span class="n">req</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span> | |
407 | <span class="k">if</span> <span class="n">req</span><span class="p">:</span> | |
408 | <span class="n">req</span><span class="o">.</span><span class="n">callback</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="o">**</span><span class="n">req</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span> | |
409 | <span class="k">return</span> <span class="bp">True</span> | |
346 | 410 | |
347 | 411 | |
348 | 412 | <span class="k">def</span> <span class="nf">_updateServerInfo_SMB2</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">payload</span><span class="p">):</span> |
382 | 446 | <span class="n">lm_challenge_response</span><span class="p">,</span> |
383 | 447 | <span class="n">session_key</span><span class="p">,</span> |
384 | 448 | <span class="bp">self</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> |
385 | <span class="bp">self</span><span class="o">.</span><span class="n">domain</span><span class="p">)</span> | |
449 | <span class="bp">self</span><span class="o">.</span><span class="n">domain</span><span class="p">,</span> | |
450 | <span class="bp">self</span><span class="o">.</span><span class="n">my_name</span><span class="p">)</span> | |
386 | 451 | |
387 | 452 | <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">isEnabledFor</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">):</span> |
388 | 453 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">'NT challenge response is "</span><span class="si">%s</span><span class="s1">" (</span><span class="si">%d</span><span class="s1"> bytes)'</span><span class="p">,</span> <span class="n">binascii</span><span class="o">.</span><span class="n">hexlify</span><span class="p">(</span><span class="n">nt_challenge_response</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="n">nt_challenge_response</span><span class="p">))</span> |
431 | 496 | |
432 | 497 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> |
433 | 498 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
434 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">connectSrvSvcCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">)</span> | |
499 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">connectSrvSvcCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span><span class="p">)</span> | |
435 | 500 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
436 | 501 | |
437 | 502 | <span class="k">def</span> <span class="nf">connectSrvSvcCB</span><span class="p">(</span><span class="n">create_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
453 | 518 | <span class="s2">01 00 00 00</span> |
454 | 519 | <span class="s2">"""</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">' '</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">,</span> <span class="s1">''</span><span class="p">))</span> |
455 | 520 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2WriteRequest</span><span class="p">(</span><span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> <span class="n">data_bytes</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> |
456 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">create_message</span><span class="o">.</span><span class="n">tid</span> | |
521 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">]</span> | |
457 | 522 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
458 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">rpcBindCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">)</span> | |
523 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">rpcBindCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">)</span> | |
459 | 524 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
460 | 525 | <span class="k">else</span><span class="p">:</span> |
461 | 526 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to list shares: Unable to locate Server Service RPC endpoint'</span><span class="p">,</span> <span class="n">messages_history</span><span class="p">))</span> |
464 | 529 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">trans_message</span><span class="p">)</span> |
465 | 530 | <span class="k">if</span> <span class="n">trans_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
466 | 531 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2ReadRequest</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">read_len</span> <span class="o">=</span> <span class="mi">1024</span><span class="p">,</span> <span class="n">read_offset</span> <span class="o">=</span> <span class="mi">0</span><span class="p">))</span> |
467 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">trans_message</span><span class="o">.</span><span class="n">tid</span> | |
532 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">]</span> | |
468 | 533 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
469 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">rpcReadCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">])</span> | |
534 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">rpcReadCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">])</span> | |
470 | 535 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
471 | 536 | <span class="k">else</span><span class="p">:</span> |
472 | <span class="n">closeFid</span><span class="p">(</span><span class="n">trans_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">error</span> <span class="o">=</span> <span class="s1">'Failed to list shares: Unable to read from Server Service RPC endpoint'</span><span class="p">)</span> | |
537 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">error</span> <span class="o">=</span> <span class="s1">'Failed to list shares: Unable to read from Server Service RPC endpoint'</span><span class="p">)</span> | |
473 | 538 | |
474 | 539 | <span class="k">def</span> <span class="nf">rpcReadCB</span><span class="p">(</span><span class="n">read_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
475 | 540 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">read_message</span><span class="p">)</span> |
497 | 562 | <span class="s2">00 00 00 00 ff ff ff ff 08 00 02 00 00 00 00 00</span> |
498 | 563 | <span class="s2">"""</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">' '</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">,</span> <span class="s1">''</span><span class="p">))</span> |
499 | 564 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2IoctlRequest</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="mh">0x0011C017</span><span class="p">,</span> <span class="n">flags</span> <span class="o">=</span> <span class="mh">0x01</span><span class="p">,</span> <span class="n">max_out_size</span> <span class="o">=</span> <span class="mi">8196</span><span class="p">,</span> <span class="n">in_data</span> <span class="o">=</span> <span class="n">data_bytes</span><span class="p">))</span> |
500 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">read_message</span><span class="o">.</span><span class="n">tid</span> | |
565 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">]</span> | |
501 | 566 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
502 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">listShareResultsCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">])</span> | |
567 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">listShareResultsCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">])</span> | |
503 | 568 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
504 | 569 | <span class="k">else</span><span class="p">:</span> |
505 | <span class="n">closeFid</span><span class="p">(</span><span class="n">read_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">error</span> <span class="o">=</span> <span class="s1">'Failed to list shares: Unable to bind to Server Service RPC endpoint'</span><span class="p">)</span> | |
570 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">error</span> <span class="o">=</span> <span class="s1">'Failed to list shares: Unable to bind to Server Service RPC endpoint'</span><span class="p">)</span> | |
506 | 571 | |
507 | 572 | <span class="k">def</span> <span class="nf">listShareResultsCB</span><span class="p">(</span><span class="n">result_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
508 | 573 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">result_message</span><span class="p">)</span> |
511 | 576 | <span class="n">data_bytes</span> <span class="o">=</span> <span class="n">result_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">out_data</span> |
512 | 577 | |
513 | 578 | <span class="k">if</span> <span class="nb">ord</span><span class="p">(</span><span class="n">data_bytes</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span> <span class="o">&</span> <span class="mh">0x02</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
514 | <span class="n">sendReadRequest</span><span class="p">(</span><span class="n">result_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">data_bytes</span><span class="p">)</span> | |
515 | <span class="k">else</span><span class="p">:</span> | |
516 | <span class="n">decodeResults</span><span class="p">(</span><span class="n">result_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">data_bytes</span><span class="p">)</span> | |
517 | <span class="k">elif</span> <span class="n">result_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0x0103</span><span class="p">:</span> <span class="c1"># STATUS_PENDING</span> | |
518 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">result_message</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">result_message</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">listShareResultsCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">])</span> | |
519 | <span class="k">else</span><span class="p">:</span> | |
520 | <span class="n">closeFid</span><span class="p">(</span><span class="n">result_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">])</span> | |
579 | <span class="n">sendReadRequest</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">data_bytes</span><span class="p">)</span> | |
580 | <span class="k">else</span><span class="p">:</span> | |
581 | <span class="n">decodeResults</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">data_bytes</span><span class="p">)</span> | |
582 | <span class="k">else</span><span class="p">:</span> | |
583 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">])</span> | |
521 | 584 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to list shares: Unable to retrieve shared device list'</span><span class="p">,</span> <span class="n">messages_history</span><span class="p">))</span> |
522 | 585 | |
523 | 586 | <span class="k">def</span> <span class="nf">decodeResults</span><span class="p">(</span><span class="n">tid</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">data_bytes</span><span class="p">):</span> |
556 | 619 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> |
557 | 620 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
558 | 621 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">readCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> |
559 | <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">,</span> <span class="n">data_bytes</span> <span class="o">=</span> <span class="n">data_bytes</span><span class="p">)</span> | |
622 | <span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">,</span> <span class="n">data_bytes</span> <span class="o">=</span> <span class="n">data_bytes</span><span class="p">)</span> | |
560 | 623 | |
561 | 624 | <span class="k">def</span> <span class="nf">readCB</span><span class="p">(</span><span class="n">read_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
562 | 625 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">read_message</span><span class="p">)</span> |
563 | 626 | <span class="k">if</span> <span class="n">read_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
564 | <span class="n">data_len</span> <span class="o">=</span> <span class="n">read_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">data_length</span> | |
565 | 627 | <span class="n">data_bytes</span> <span class="o">=</span> <span class="n">read_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">data</span> |
566 | 628 | |
567 | 629 | <span class="k">if</span> <span class="nb">ord</span><span class="p">(</span><span class="n">data_bytes</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span> <span class="o">&</span> <span class="mh">0x02</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
568 | <span class="n">sendReadRequest</span><span class="p">(</span><span class="n">read_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'data_bytes'</span><span class="p">]</span> <span class="o">+</span> <span class="n">data_bytes</span><span class="p">[</span><span class="mi">24</span><span class="p">:</span><span class="n">data_len</span><span class="o">-</span><span class="mi">24</span><span class="p">])</span> | |
569 | <span class="k">else</span><span class="p">:</span> | |
570 | <span class="n">decodeResults</span><span class="p">(</span><span class="n">read_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'data_bytes'</span><span class="p">]</span> <span class="o">+</span> <span class="n">data_bytes</span><span class="p">[</span><span class="mi">24</span><span class="p">:</span><span class="n">data_len</span><span class="o">-</span><span class="mi">24</span><span class="p">])</span> | |
571 | <span class="k">else</span><span class="p">:</span> | |
572 | <span class="n">closeFid</span><span class="p">(</span><span class="n">read_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">])</span> | |
630 | <span class="n">sendReadRequest</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'data_bytes'</span><span class="p">]</span> <span class="o">+</span> <span class="n">data_bytes</span><span class="p">[</span><span class="mi">24</span><span class="p">:])</span> | |
631 | <span class="k">else</span><span class="p">:</span> | |
632 | <span class="n">decodeResults</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'data_bytes'</span><span class="p">]</span> <span class="o">+</span> <span class="n">data_bytes</span><span class="p">[</span><span class="mi">24</span><span class="p">:])</span> | |
633 | <span class="k">else</span><span class="p">:</span> | |
634 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">])</span> | |
573 | 635 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to list shares: Unable to retrieve shared device list'</span><span class="p">,</span> <span class="n">messages_history</span><span class="p">))</span> |
574 | 636 | |
575 | 637 | <span class="k">def</span> <span class="nf">closeFid</span><span class="p">(</span><span class="n">tid</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">results</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span> <span class="n">error</span> <span class="o">=</span> <span class="bp">None</span><span class="p">):</span> |
634 | 696 | <span class="n">create_context_data</span> <span class="o">=</span> <span class="n">create_context_data</span><span class="p">))</span> |
635 | 697 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> |
636 | 698 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
637 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">createCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">)</span> | |
699 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">createCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span><span class="p">)</span> | |
638 | 700 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
639 | 701 | |
640 | 702 | <span class="k">def</span> <span class="nf">createCB</span><span class="p">(</span><span class="n">create_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
641 | 703 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">create_message</span><span class="p">)</span> |
642 | 704 | <span class="k">if</span> <span class="n">create_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
643 | <span class="n">sendQuery</span><span class="p">(</span><span class="n">create_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span> | |
705 | <span class="n">sendQuery</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span> | |
706 | <span class="k">elif</span> <span class="n">create_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xC0000034</span><span class="n">L</span><span class="p">:</span> <span class="c1"># [MS-ERREF]: STATUS_OBJECT_NAME_INVALID</span> | |
707 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to list </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Path not found'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
644 | 708 | <span class="k">else</span><span class="p">:</span> |
645 | 709 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to list </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to open directory'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> |
646 | 710 | |
647 | 711 | <span class="k">def</span> <span class="nf">sendQuery</span><span class="p">(</span><span class="n">tid</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">data_buf</span><span class="p">):</span> |
648 | 712 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2QueryDirectoryRequest</span><span class="p">(</span><span class="n">fid</span><span class="p">,</span> <span class="n">pattern</span><span class="p">,</span> |
649 | <span class="n">info_class</span> <span class="o">=</span> <span class="mh">0x03</span><span class="p">,</span> <span class="c1"># FileBothDirectoryInformation</span> | |
713 | <span class="n">info_class</span> <span class="o">=</span> <span class="mh">0x25</span><span class="p">,</span> <span class="c1"># FileIdBothDirectoryInformation</span> | |
650 | 714 | <span class="n">flags</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> |
651 | 715 | <span class="n">output_buf_len</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_transact_size</span><span class="p">))</span> |
652 | 716 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> |
653 | 717 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
654 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">queryCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">,</span> <span class="n">data_buf</span> <span class="o">=</span> <span class="n">data_buf</span><span class="p">)</span> | |
718 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">queryCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">,</span> <span class="n">data_buf</span> <span class="o">=</span> <span class="n">data_buf</span><span class="p">)</span> | |
655 | 719 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
656 | 720 | |
657 | 721 | <span class="k">def</span> <span class="nf">queryCB</span><span class="p">(</span><span class="n">query_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
658 | 722 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">query_message</span><span class="p">)</span> |
659 | 723 | <span class="k">if</span> <span class="n">query_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
660 | 724 | <span class="n">data_buf</span> <span class="o">=</span> <span class="n">decodeQueryStruct</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'data_buf'</span><span class="p">]</span> <span class="o">+</span> <span class="n">query_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">data</span><span class="p">)</span> |
661 | <span class="n">sendQuery</span><span class="p">(</span><span class="n">query_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">data_buf</span><span class="p">)</span> | |
725 | <span class="n">sendQuery</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">data_buf</span><span class="p">)</span> | |
726 | <span class="k">elif</span> <span class="n">query_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xC000000F</span><span class="n">L</span><span class="p">:</span> <span class="c1"># [MS-ERREF]: STATUS_NO_SUCH_FILE</span> | |
727 | <span class="c1"># If there are no matching files, we just treat as success instead of failing</span> | |
728 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">results</span> <span class="o">=</span> <span class="n">results</span><span class="p">)</span> | |
662 | 729 | <span class="k">elif</span> <span class="n">query_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0x80000006</span><span class="n">L</span><span class="p">:</span> <span class="c1"># STATUS_NO_MORE_FILES</span> |
663 | <span class="n">closeFid</span><span class="p">(</span><span class="n">query_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">results</span> <span class="o">=</span> <span class="n">results</span><span class="p">)</span> | |
664 | <span class="k">else</span><span class="p">:</span> | |
665 | <span class="n">closeFid</span><span class="p">(</span><span class="n">query_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">error</span> <span class="o">=</span> <span class="n">query_message</span><span class="o">.</span><span class="n">status</span><span class="p">)</span> | |
730 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">results</span> <span class="o">=</span> <span class="n">results</span><span class="p">)</span> | |
731 | <span class="k">else</span><span class="p">:</span> | |
732 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">error</span> <span class="o">=</span> <span class="n">query_message</span><span class="o">.</span><span class="n">status</span><span class="p">)</span> | |
666 | 733 | |
667 | 734 | <span class="k">def</span> <span class="nf">decodeQueryStruct</span><span class="p">(</span><span class="n">data_bytes</span><span class="p">):</span> |
668 | <span class="c1"># SMB_FIND_FILE_BOTH_DIRECTORY_INFO structure. See [MS-CIFS]: 2.2.8.1.7 and [MS-SMB]: 2.2.8.1.1</span> | |
669 | <span class="n">info_format</span> <span class="o">=</span> <span class="s1">'<IIQQQQQQIIIBB24s'</span> | |
735 | <span class="c1"># FileIdBothDirectoryInformation structure. See [MS-SMB]: 2.2.8.1.3 and [MS-FSCC]: 2.4.17</span> | |
736 | <span class="n">info_format</span> <span class="o">=</span> <span class="s1">'<IIQQQQQQIIIBB24sHQ'</span> | |
670 | 737 | <span class="n">info_size</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">info_format</span><span class="p">)</span> |
671 | 738 | |
672 | 739 | <span class="n">data_length</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data_bytes</span><span class="p">)</span> |
678 | 745 | <span class="n">next_offset</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> \ |
679 | 746 | <span class="n">create_time</span><span class="p">,</span> <span class="n">last_access_time</span><span class="p">,</span> <span class="n">last_write_time</span><span class="p">,</span> <span class="n">last_attr_change_time</span><span class="p">,</span> \ |
680 | 747 | <span class="n">file_size</span><span class="p">,</span> <span class="n">alloc_size</span><span class="p">,</span> <span class="n">file_attributes</span><span class="p">,</span> <span class="n">filename_length</span><span class="p">,</span> <span class="n">ea_size</span><span class="p">,</span> \ |
681 | <span class="n">short_name_length</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">short_name</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="n">info_format</span><span class="p">,</span> <span class="n">data_bytes</span><span class="p">[</span><span class="n">offset</span><span class="p">:</span><span class="n">offset</span><span class="o">+</span><span class="n">info_size</span><span class="p">])</span> | |
748 | <span class="n">short_name_length</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">short_name</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">file_id</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="n">info_format</span><span class="p">,</span> <span class="n">data_bytes</span><span class="p">[</span><span class="n">offset</span><span class="p">:</span><span class="n">offset</span><span class="o">+</span><span class="n">info_size</span><span class="p">])</span> | |
682 | 749 | |
683 | 750 | <span class="n">offset2</span> <span class="o">=</span> <span class="n">offset</span> <span class="o">+</span> <span class="n">info_size</span> |
684 | 751 | <span class="k">if</span> <span class="n">offset2</span> <span class="o">+</span> <span class="n">filename_length</span> <span class="o">></span> <span class="n">data_length</span><span class="p">:</span> |
685 | 752 | <span class="k">return</span> <span class="n">data_bytes</span><span class="p">[</span><span class="n">offset</span><span class="p">:]</span> |
686 | 753 | |
687 | 754 | <span class="n">filename</span> <span class="o">=</span> <span class="n">data_bytes</span><span class="p">[</span><span class="n">offset2</span><span class="p">:</span><span class="n">offset2</span><span class="o">+</span><span class="n">filename_length</span><span class="p">]</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">'UTF-16LE'</span><span class="p">)</span> |
688 | <span class="n">short_name</span> <span class="o">=</span> <span class="n">short_name</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">'UTF-16LE'</span><span class="p">)</span> | |
689 | <span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">SharedFile</span><span class="p">(</span><span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">create_time</span><span class="p">),</span> <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_access_time</span><span class="p">),</span> | |
690 | <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_write_time</span><span class="p">),</span> <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_attr_change_time</span><span class="p">),</span> | |
691 | <span class="n">file_size</span><span class="p">,</span> <span class="n">alloc_size</span><span class="p">,</span> <span class="n">file_attributes</span><span class="p">,</span> <span class="n">short_name</span><span class="p">,</span> <span class="n">filename</span><span class="p">))</span> | |
755 | <span class="n">short_name</span> <span class="o">=</span> <span class="n">short_name</span><span class="p">[:</span><span class="n">short_name_length</span><span class="p">]</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">'UTF-16LE'</span><span class="p">)</span> | |
756 | ||
757 | <span class="n">accept_result</span> <span class="o">=</span> <span class="bp">False</span> | |
758 | <span class="k">if</span> <span class="p">(</span><span class="n">file_attributes</span> <span class="o">&</span> <span class="mh">0xff</span><span class="p">)</span> <span class="ow">in</span> <span class="p">(</span> <span class="mh">0x00</span><span class="p">,</span> <span class="n">ATTR_NORMAL</span> <span class="p">):</span> <span class="c1"># Only the first 8-bits are compared. We ignore other bits like temp, compressed, encryption, sparse, indexed, etc</span> | |
759 | <span class="n">accept_result</span> <span class="o">=</span> <span class="p">(</span><span class="n">search</span> <span class="o">==</span> <span class="n">SMB_FILE_ATTRIBUTE_NORMAL</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">search</span> <span class="o">&</span> <span class="n">SMB_FILE_ATTRIBUTE_INCL_NORMAL</span><span class="p">)</span> | |
760 | <span class="k">else</span><span class="p">:</span> | |
761 | <span class="n">accept_result</span> <span class="o">=</span> <span class="p">(</span><span class="n">file_attributes</span> <span class="o">&</span> <span class="n">search</span><span class="p">)</span> <span class="o">></span> <span class="mi">0</span> | |
762 | <span class="k">if</span> <span class="n">accept_result</span><span class="p">:</span> | |
763 | <span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">SharedFile</span><span class="p">(</span><span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">create_time</span><span class="p">),</span> <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_access_time</span><span class="p">),</span> | |
764 | <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_write_time</span><span class="p">),</span> <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_attr_change_time</span><span class="p">),</span> | |
765 | <span class="n">file_size</span><span class="p">,</span> <span class="n">alloc_size</span><span class="p">,</span> <span class="n">file_attributes</span><span class="p">,</span> <span class="n">short_name</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">file_id</span><span class="p">))</span> | |
692 | 766 | |
693 | 767 | <span class="k">if</span> <span class="n">next_offset</span><span class="p">:</span> |
694 | 768 | <span class="n">offset</span> <span class="o">+=</span> <span class="n">next_offset</span> |
707 | 781 | <span class="k">if</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'results'</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> |
708 | 782 | <span class="n">callback</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'results'</span><span class="p">])</span> |
709 | 783 | <span class="k">elif</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'error'</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> |
710 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to list </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Query failed with errorcode 0x</span><span class="si">%08x</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'error'</span><span class="p">]</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
784 | <span class="k">if</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'error'</span><span class="p">]</span> <span class="o">==</span> <span class="mh">0xC000000F</span><span class="p">:</span> <span class="c1"># [MS-ERREF]: STATUS_NO_SUCH_FILE</span> | |
785 | <span class="c1"># Remote server returns STATUS_NO_SUCH_FILE error so we assume that the search returns no matching files</span> | |
786 | <span class="n">callback</span><span class="p">([</span> <span class="p">])</span> | |
787 | <span class="k">else</span><span class="p">:</span> | |
788 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to list </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Query failed with errorcode 0x</span><span class="si">%08x</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'error'</span><span class="p">]</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
711 | 789 | |
712 | 790 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">service_name</span><span class="p">):</span> |
713 | 791 | <span class="k">def</span> <span class="nf">connectCB</span><span class="p">(</span><span class="n">connect_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
757 | 835 | <span class="n">create_context_data</span> <span class="o">=</span> <span class="n">create_context_data</span><span class="p">))</span> |
758 | 836 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> |
759 | 837 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
760 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">createCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">)</span> | |
838 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">createCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span><span class="p">)</span> | |
761 | 839 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
762 | 840 | |
763 | 841 | <span class="k">def</span> <span class="nf">createCB</span><span class="p">(</span><span class="n">create_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
764 | 842 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">create_message</span><span class="p">)</span> |
765 | 843 | <span class="k">if</span> <span class="n">create_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
766 | 844 | <span class="n">p</span> <span class="o">=</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span> |
845 | <span class="n">filename</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_extractLastPathComponent</span><span class="p">(</span><span class="nb">unicode</span><span class="p">(</span><span class="n">path</span><span class="p">))</span> | |
767 | 846 | <span class="n">info</span> <span class="o">=</span> <span class="n">SharedFile</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">create_time</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">lastaccess_time</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">lastwrite_time</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">change_time</span><span class="p">,</span> |
768 | 847 | <span class="n">p</span><span class="o">.</span><span class="n">file_size</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">allocation_size</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">file_attributes</span><span class="p">,</span> |
769 | <span class="nb">unicode</span><span class="p">(</span><span class="n">path</span><span class="p">),</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">path</span><span class="p">))</span> | |
770 | <span class="n">closeFid</span><span class="p">(</span><span class="n">create_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> <span class="n">info</span> <span class="o">=</span> <span class="n">info</span><span class="p">)</span> | |
848 | <span class="n">filename</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span> | |
849 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">p</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> <span class="n">info</span> <span class="o">=</span> <span class="n">info</span><span class="p">)</span> | |
771 | 850 | <span class="k">else</span><span class="p">:</span> |
772 | 851 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to get attributes for </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to open remote file object'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> |
773 | 852 | |
792 | 871 | <span class="n">sendCreate</span><span class="p">(</span><span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span><span class="p">)</span> |
793 | 872 | <span class="k">else</span><span class="p">:</span> |
794 | 873 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to get attributes for </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to connect to shared device'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> |
874 | ||
875 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2TreeConnectRequest</span><span class="p">(</span><span class="s1">r'</span><span class="se">\\</span><span class="si">%s</span><span class="s1">\</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_name</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="n">service_name</span> <span class="p">)))</span> | |
876 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
877 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">connectCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">path</span> <span class="o">=</span> <span class="n">service_name</span><span class="p">)</span> | |
878 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
879 | <span class="k">else</span><span class="p">:</span> | |
880 | <span class="n">sendCreate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">])</span> | |
881 | ||
882 | <span class="k">def</span> <span class="nf">_getSecurity_SMB2</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
883 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span><span class="p">:</span> | |
884 | <span class="k">raise</span> <span class="n">NotReadyError</span><span class="p">(</span><span class="s1">'SMB connection not authenticated'</span><span class="p">)</span> | |
885 | ||
886 | <span class="n">expiry_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">+</span> <span class="n">timeout</span> | |
887 | <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">)</span> | |
888 | <span class="k">if</span> <span class="n">path</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">):</span> | |
889 | <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span> | |
890 | <span class="k">if</span> <span class="n">path</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">):</span> | |
891 | <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> | |
892 | <span class="n">messages_history</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> | |
893 | <span class="n">results</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> | |
894 | ||
895 | <span class="k">def</span> <span class="nf">sendCreate</span><span class="p">(</span><span class="n">tid</span><span class="p">):</span> | |
896 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2CreateRequest</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> | |
897 | <span class="n">file_attributes</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> | |
898 | <span class="n">access_mask</span> <span class="o">=</span> <span class="n">FILE_READ_DATA</span> <span class="o">|</span> <span class="n">FILE_READ_EA</span> <span class="o">|</span> <span class="n">FILE_READ_ATTRIBUTES</span> <span class="o">|</span> <span class="n">READ_CONTROL</span> <span class="o">|</span> <span class="n">SYNCHRONIZE</span><span class="p">,</span> | |
899 | <span class="n">share_access</span> <span class="o">=</span> <span class="n">FILE_SHARE_READ</span> <span class="o">|</span> <span class="n">FILE_SHARE_WRITE</span> <span class="o">|</span> <span class="n">FILE_SHARE_DELETE</span><span class="p">,</span> | |
900 | <span class="n">oplock</span> <span class="o">=</span> <span class="n">SMB2_OPLOCK_LEVEL_NONE</span><span class="p">,</span> | |
901 | <span class="n">impersonation</span> <span class="o">=</span> <span class="n">SEC_IMPERSONATE</span><span class="p">,</span> | |
902 | <span class="n">create_options</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> | |
903 | <span class="n">create_disp</span> <span class="o">=</span> <span class="n">FILE_OPEN</span><span class="p">))</span> | |
904 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> | |
905 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
906 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">createCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span><span class="p">)</span> | |
907 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
908 | ||
909 | <span class="k">def</span> <span class="nf">createCB</span><span class="p">(</span><span class="n">create_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |
910 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">create_message</span><span class="p">)</span> | |
911 | <span class="k">if</span> <span class="n">create_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> | |
912 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2QueryInfoRequest</span><span class="p">(</span><span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> | |
913 | <span class="n">flags</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> | |
914 | <span class="n">additional_info</span> <span class="o">=</span> <span class="n">OWNER_SECURITY_INFORMATION</span> <span class="o">|</span> <span class="n">GROUP_SECURITY_INFORMATION</span> <span class="o">|</span> <span class="n">DACL_SECURITY_INFORMATION</span><span class="p">,</span> | |
915 | <span class="n">info_type</span> <span class="o">=</span> <span class="n">SMB2_INFO_SECURITY</span><span class="p">,</span> | |
916 | <span class="n">file_info_class</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="c1"># [MS-SMB2] 2.2.37, 3.2.4.12</span> | |
917 | <span class="n">input_buf</span> <span class="o">=</span> <span class="s1">''</span><span class="p">,</span> | |
918 | <span class="n">output_buf_len</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_transact_size</span><span class="p">))</span> | |
919 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">]</span> | |
920 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
921 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">queryCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">)</span> | |
922 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
923 | <span class="k">else</span><span class="p">:</span> | |
924 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to get the security descriptor of </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to open file or directory'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
925 | ||
926 | <span class="k">def</span> <span class="nf">queryCB</span><span class="p">(</span><span class="n">query_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |
927 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">query_message</span><span class="p">)</span> | |
928 | <span class="k">if</span> <span class="n">query_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> | |
929 | <span class="n">security</span> <span class="o">=</span> <span class="n">SecurityDescriptor</span><span class="o">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">query_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">data</span><span class="p">)</span> | |
930 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">result</span> <span class="o">=</span> <span class="n">security</span><span class="p">)</span> | |
931 | <span class="k">else</span><span class="p">:</span> | |
932 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">error</span> <span class="o">=</span> <span class="n">query_message</span><span class="o">.</span><span class="n">status</span><span class="p">)</span> | |
933 | ||
934 | <span class="k">def</span> <span class="nf">closeFid</span><span class="p">(</span><span class="n">tid</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">result</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span> <span class="n">error</span> <span class="o">=</span> <span class="bp">None</span><span class="p">):</span> | |
935 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2CloseRequest</span><span class="p">(</span><span class="n">fid</span><span class="p">))</span> | |
936 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> | |
937 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
938 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">closeCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">result</span> <span class="o">=</span> <span class="n">result</span><span class="p">,</span> <span class="n">error</span> <span class="o">=</span> <span class="n">error</span><span class="p">)</span> | |
939 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
940 | ||
941 | <span class="k">def</span> <span class="nf">closeCB</span><span class="p">(</span><span class="n">close_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |
942 | <span class="k">if</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'result'</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> | |
943 | <span class="n">callback</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'result'</span><span class="p">])</span> | |
944 | <span class="k">elif</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'error'</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> | |
945 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to get the security descriptor of </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Query failed with errorcode 0x</span><span class="si">%08x</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'error'</span><span class="p">]</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
946 | ||
947 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">service_name</span><span class="p">):</span> | |
948 | <span class="k">def</span> <span class="nf">connectCB</span><span class="p">(</span><span class="n">connect_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |
949 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">connect_message</span><span class="p">)</span> | |
950 | <span class="k">if</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> | |
951 | <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span> | |
952 | <span class="n">sendCreate</span><span class="p">(</span><span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span><span class="p">)</span> | |
953 | <span class="k">else</span><span class="p">:</span> | |
954 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to get the security descriptor of </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to connect to shared device'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
795 | 955 | |
796 | 956 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2TreeConnectRequest</span><span class="p">(</span><span class="s1">r'</span><span class="se">\\</span><span class="si">%s</span><span class="s1">\</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_name</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="n">service_name</span> <span class="p">)))</span> |
797 | 957 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
828 | 988 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2CreateRequest</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> |
829 | 989 | <span class="n">file_attributes</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> |
830 | 990 | <span class="n">access_mask</span> <span class="o">=</span> <span class="n">FILE_READ_DATA</span> <span class="o">|</span> <span class="n">FILE_READ_EA</span> <span class="o">|</span> <span class="n">FILE_READ_ATTRIBUTES</span> <span class="o">|</span> <span class="n">READ_CONTROL</span> <span class="o">|</span> <span class="n">SYNCHRONIZE</span><span class="p">,</span> |
831 | <span class="n">share_access</span> <span class="o">=</span> <span class="n">FILE_SHARE_READ</span><span class="p">,</span> | |
991 | <span class="n">share_access</span> <span class="o">=</span> <span class="n">FILE_SHARE_READ</span> <span class="o">|</span> <span class="n">FILE_SHARE_WRITE</span><span class="p">,</span> | |
832 | 992 | <span class="n">oplock</span> <span class="o">=</span> <span class="n">SMB2_OPLOCK_LEVEL_NONE</span><span class="p">,</span> |
833 | 993 | <span class="n">impersonation</span> <span class="o">=</span> <span class="n">SEC_IMPERSONATE</span><span class="p">,</span> |
834 | 994 | <span class="n">create_options</span> <span class="o">=</span> <span class="n">FILE_SEQUENTIAL_ONLY</span> <span class="o">|</span> <span class="n">FILE_NON_DIRECTORY_FILE</span><span class="p">,</span> |
849 | 1009 | <span class="n">file_info_class</span> <span class="o">=</span> <span class="mh">0x16</span><span class="p">,</span> <span class="c1"># FileStreamInformation [MS-FSCC] 2.4</span> |
850 | 1010 | <span class="n">input_buf</span> <span class="o">=</span> <span class="s1">''</span><span class="p">,</span> |
851 | 1011 | <span class="n">output_buf_len</span> <span class="o">=</span> <span class="mi">4096</span><span class="p">))</span> |
852 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">create_message</span><span class="o">.</span><span class="n">tid</span> | |
1012 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">]</span> | |
853 | 1013 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
854 | 1014 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">infoCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> |
855 | <span class="n">fid</span> <span class="o">=</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> <span class="n">file_attributes</span> <span class="o">=</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">file_attributes</span><span class="p">)</span> | |
1015 | <span class="n">tid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> | |
1016 | <span class="n">fid</span> <span class="o">=</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> | |
1017 | <span class="n">file_attributes</span> <span class="o">=</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">file_attributes</span><span class="p">)</span> | |
856 | 1018 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
857 | 1019 | <span class="k">else</span><span class="p">:</span> |
858 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to list </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to open file'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
1020 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to retrieve </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to open file'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
859 | 1021 | |
860 | 1022 | <span class="k">def</span> <span class="nf">infoCB</span><span class="p">(</span><span class="n">info_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
861 | 1023 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">info_message</span><span class="p">)</span> |
870 | 1032 | <span class="n">remaining_len</span> <span class="o">=</span> <span class="n">file_len</span> |
871 | 1033 | <span class="k">if</span> <span class="n">starting_offset</span> <span class="o">+</span> <span class="n">remaining_len</span> <span class="o">></span> <span class="n">file_len</span><span class="p">:</span> |
872 | 1034 | <span class="n">remaining_len</span> <span class="o">=</span> <span class="n">file_len</span> <span class="o">-</span> <span class="n">starting_offset</span> |
873 | <span class="n">sendRead</span><span class="p">(</span><span class="n">info_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">starting_offset</span><span class="p">,</span> <span class="n">remaining_len</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'file_attributes'</span><span class="p">])</span> | |
874 | <span class="k">else</span><span class="p">:</span> | |
875 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to list </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to retrieve information on file'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
1035 | <span class="n">sendRead</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">starting_offset</span><span class="p">,</span> <span class="n">remaining_len</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'file_attributes'</span><span class="p">])</span> | |
1036 | <span class="k">else</span><span class="p">:</span> | |
1037 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to retrieve </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to retrieve information on file'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
876 | 1038 | |
877 | 1039 | <span class="k">def</span> <span class="nf">sendRead</span><span class="p">(</span><span class="n">tid</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">remaining_len</span><span class="p">,</span> <span class="n">read_len</span><span class="p">,</span> <span class="n">file_attributes</span><span class="p">):</span> |
878 | 1040 | <span class="n">read_count</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">max_read_size</span><span class="p">,</span> <span class="n">remaining_len</span><span class="p">)</span> |
880 | 1042 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> |
881 | 1043 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
882 | 1044 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">readCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> |
883 | <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">,</span> <span class="n">offset</span> <span class="o">=</span> <span class="n">offset</span><span class="p">,</span> | |
1045 | <span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">,</span> <span class="n">offset</span> <span class="o">=</span> <span class="n">offset</span><span class="p">,</span> | |
884 | 1046 | <span class="n">remaining_len</span> <span class="o">=</span> <span class="n">remaining_len</span><span class="p">,</span> |
885 | 1047 | <span class="n">read_len</span> <span class="o">=</span> <span class="n">read_len</span><span class="p">,</span> |
886 | 1048 | <span class="n">file_attributes</span> <span class="o">=</span> <span class="n">file_attributes</span><span class="p">)</span> |
894 | 1056 | <span class="n">remaining_len</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'remaining_len'</span><span class="p">]</span> <span class="o">-</span> <span class="n">data_len</span> |
895 | 1057 | |
896 | 1058 | <span class="k">if</span> <span class="n">remaining_len</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span> |
897 | <span class="n">sendRead</span><span class="p">(</span><span class="n">read_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'offset'</span><span class="p">]</span> <span class="o">+</span> <span class="n">data_len</span><span class="p">,</span> <span class="n">remaining_len</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'read_len'</span><span class="p">]</span> <span class="o">+</span> <span class="n">data_len</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'file_attributes'</span><span class="p">])</span> | |
898 | <span class="k">else</span><span class="p">:</span> | |
899 | <span class="n">closeFid</span><span class="p">(</span><span class="n">read_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">ret</span> <span class="o">=</span> <span class="p">(</span> <span class="n">file_obj</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'file_attributes'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'read_len'</span><span class="p">]</span> <span class="o">+</span> <span class="n">data_len</span> <span class="p">))</span> | |
1059 | <span class="n">sendRead</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'offset'</span><span class="p">]</span> <span class="o">+</span> <span class="n">data_len</span><span class="p">,</span> <span class="n">remaining_len</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'read_len'</span><span class="p">]</span> <span class="o">+</span> <span class="n">data_len</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'file_attributes'</span><span class="p">])</span> | |
1060 | <span class="k">else</span><span class="p">:</span> | |
1061 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">ret</span> <span class="o">=</span> <span class="p">(</span> <span class="n">file_obj</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'file_attributes'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'read_len'</span><span class="p">]</span> <span class="o">+</span> <span class="n">data_len</span> <span class="p">))</span> | |
900 | 1062 | <span class="k">else</span><span class="p">:</span> |
901 | 1063 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">read_message</span><span class="p">)</span> |
902 | <span class="n">closeFid</span><span class="p">(</span><span class="n">read_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">error</span> <span class="o">=</span> <span class="n">read_message</span><span class="o">.</span><span class="n">status</span><span class="p">)</span> | |
1064 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">error</span> <span class="o">=</span> <span class="n">read_message</span><span class="o">.</span><span class="n">status</span><span class="p">)</span> | |
903 | 1065 | |
904 | 1066 | <span class="k">def</span> <span class="nf">closeFid</span><span class="p">(</span><span class="n">tid</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">ret</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span> <span class="n">error</span> <span class="o">=</span> <span class="bp">None</span><span class="p">):</span> |
905 | 1067 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2CloseRequest</span><span class="p">(</span><span class="n">fid</span><span class="p">))</span> |
937 | 1099 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span><span class="p">:</span> |
938 | 1100 | <span class="k">raise</span> <span class="n">NotReadyError</span><span class="p">(</span><span class="s1">'SMB connection not authenticated'</span><span class="p">)</span> |
939 | 1101 | |
1102 | <span class="n">expiry_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">+</span> <span class="n">timeout</span> | |
940 | 1103 | <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">)</span> |
941 | 1104 | <span class="k">if</span> <span class="n">path</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">):</span> |
942 | 1105 | <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span> |
970 | 1133 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
971 | 1134 | |
972 | 1135 | <span class="k">def</span> <span class="nf">createCB</span><span class="p">(</span><span class="n">create_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
1136 | <span class="n">create_message</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">]</span> | |
973 | 1137 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">create_message</span><span class="p">)</span> |
974 | 1138 | <span class="k">if</span> <span class="n">create_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
975 | 1139 | <span class="n">sendWrite</span><span class="p">(</span><span class="n">create_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> <span class="n">starting_offset</span><span class="p">)</span> |
984 | 1148 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2WriteRequest</span><span class="p">(</span><span class="n">fid</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">offset</span><span class="p">))</span> |
985 | 1149 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> |
986 | 1150 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
987 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">writeCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">,</span> <span class="n">offset</span> <span class="o">=</span> <span class="n">offset</span><span class="o">+</span><span class="n">data_len</span><span class="p">)</span> | |
1151 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">writeCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">,</span> <span class="n">offset</span> <span class="o">=</span> <span class="n">offset</span><span class="o">+</span><span class="n">data_len</span><span class="p">)</span> | |
988 | 1152 | <span class="k">else</span><span class="p">:</span> |
989 | 1153 | <span class="n">closeFid</span><span class="p">(</span><span class="n">tid</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">offset</span> <span class="o">=</span> <span class="n">offset</span><span class="p">)</span> |
990 | 1154 | |
991 | 1155 | <span class="k">def</span> <span class="nf">writeCB</span><span class="p">(</span><span class="n">write_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
992 | 1156 | <span class="c1"># To avoid crazy memory usage when saving large files, we do not save every write_message in messages_history.</span> |
993 | 1157 | <span class="k">if</span> <span class="n">write_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
994 | <span class="n">sendWrite</span><span class="p">(</span><span class="n">write_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'offset'</span><span class="p">])</span> | |
1158 | <span class="n">sendWrite</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'offset'</span><span class="p">])</span> | |
995 | 1159 | <span class="k">else</span><span class="p">:</span> |
996 | 1160 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">write_message</span><span class="p">)</span> |
997 | <span class="n">closeFid</span><span class="p">(</span><span class="n">write_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">])</span> | |
1161 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">])</span> | |
998 | 1162 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to store </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Write failed'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> |
999 | 1163 | |
1000 | 1164 | <span class="k">def</span> <span class="nf">closeFid</span><span class="p">(</span><span class="n">tid</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">error</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span> <span class="n">offset</span> <span class="o">=</span> <span class="bp">None</span><span class="p">):</span> |
1027 | 1191 | <span class="n">sendCreate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">])</span> |
1028 | 1192 | |
1029 | 1193 | |
1030 | <span class="k">def</span> <span class="nf">_deleteFiles_SMB2</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path_file_pattern</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
1194 | <span class="k">def</span> <span class="nf">_deleteFiles_SMB2</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path_file_pattern</span><span class="p">,</span> <span class="n">delete_matching_folders</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
1031 | 1195 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span><span class="p">:</span> |
1032 | 1196 | <span class="k">raise</span> <span class="n">NotReadyError</span><span class="p">(</span><span class="s1">'SMB connection not authenticated'</span><span class="p">)</span> |
1033 | 1197 | |
1034 | 1198 | <span class="n">expiry_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">+</span> <span class="n">timeout</span> |
1199 | <span class="n">pattern</span> <span class="o">=</span> <span class="bp">None</span> | |
1035 | 1200 | <span class="n">path</span> <span class="o">=</span> <span class="n">path_file_pattern</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">)</span> |
1036 | 1201 | <span class="k">if</span> <span class="n">path</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">):</span> |
1037 | 1202 | <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span> |
1038 | 1203 | <span class="k">if</span> <span class="n">path</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">):</span> |
1039 | 1204 | <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> |
1205 | <span class="k">else</span><span class="p">:</span> | |
1206 | <span class="n">path_components</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">)</span> | |
1207 | <span class="k">if</span> <span class="n">path_components</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">'*'</span><span class="p">)</span> <span class="o">></span> <span class="o">-</span><span class="mi">1</span> <span class="ow">or</span> <span class="n">path_components</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">'?'</span><span class="p">)</span> <span class="o">></span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span> | |
1208 | <span class="n">path</span> <span class="o">=</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_components</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span> | |
1209 | <span class="n">pattern</span> <span class="o">=</span> <span class="n">path_components</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> | |
1210 | <span class="n">messages_history</span><span class="p">,</span> <span class="n">files_queue</span> <span class="o">=</span> <span class="p">[</span> <span class="p">],</span> <span class="p">[</span> <span class="p">]</span> | |
1211 | ||
1212 | <span class="k">if</span> <span class="n">pattern</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span> | |
1213 | <span class="n">path_components</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">)</span> | |
1214 | <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">path_components</span><span class="p">)</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> | |
1215 | <span class="n">files_queue</span><span class="o">.</span><span class="n">append</span><span class="p">((</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_components</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]),</span> <span class="n">path_components</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="p">))</span> | |
1216 | <span class="k">else</span><span class="p">:</span> | |
1217 | <span class="n">files_queue</span><span class="o">.</span><span class="n">append</span><span class="p">((</span> <span class="s1">''</span><span class="p">,</span> <span class="n">path</span> <span class="p">))</span> | |
1218 | ||
1219 | <span class="k">def</span> <span class="nf">deleteCB</span><span class="p">(</span><span class="n">path</span><span class="p">):</span> | |
1220 | <span class="k">if</span> <span class="n">files_queue</span><span class="p">:</span> | |
1221 | <span class="n">p</span><span class="p">,</span> <span class="n">filename</span> <span class="o">=</span> <span class="n">files_queue</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> | |
1222 | <span class="k">if</span> <span class="n">filename</span><span class="p">:</span> | |
1223 | <span class="k">if</span> <span class="n">p</span><span class="p">:</span> | |
1224 | <span class="n">filename</span> <span class="o">=</span> <span class="n">p</span> <span class="o">+</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">'</span> <span class="o">+</span> <span class="n">filename</span> | |
1225 | <span class="bp">self</span><span class="o">.</span><span class="n">_deleteFiles_SMB2__del</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">],</span> <span class="n">filename</span><span class="p">,</span> <span class="n">deleteCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span> | |
1226 | <span class="k">else</span><span class="p">:</span> | |
1227 | <span class="bp">self</span><span class="o">.</span><span class="n">_deleteDirectory_SMB2</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">deleteCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span> | |
1228 | <span class="k">else</span><span class="p">:</span> | |
1229 | <span class="n">callback</span><span class="p">(</span><span class="n">path_file_pattern</span><span class="p">)</span> | |
1230 | ||
1231 | <span class="k">def</span> <span class="nf">listCB</span><span class="p">(</span><span class="n">files_list</span><span class="p">):</span> | |
1232 | <span class="n">files_queue</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">files_list</span><span class="p">)</span> | |
1233 | <span class="n">deleteCB</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span> | |
1234 | ||
1235 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">service_name</span><span class="p">):</span> | |
1236 | <span class="k">def</span> <span class="nf">connectCB</span><span class="p">(</span><span class="n">connect_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |
1237 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">connect_message</span><span class="p">)</span> | |
1238 | <span class="k">if</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> | |
1239 | <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span> | |
1240 | <span class="k">if</span> <span class="n">files_queue</span><span class="p">:</span> | |
1241 | <span class="n">deleteCB</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span> | |
1242 | <span class="k">else</span><span class="p">:</span> | |
1243 | <span class="bp">self</span><span class="o">.</span><span class="n">_deleteFiles_SMB2__list</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">pattern</span><span class="p">,</span> <span class="n">delete_matching_folders</span><span class="p">,</span> <span class="n">listCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span> | |
1244 | <span class="k">else</span><span class="p">:</span> | |
1245 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to connect to shared device'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
1246 | ||
1247 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2TreeConnectRequest</span><span class="p">(</span><span class="s1">r'</span><span class="se">\\</span><span class="si">%s</span><span class="s1">\</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_name</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="n">service_name</span> <span class="p">)))</span> | |
1248 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
1249 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">connectCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">path</span> <span class="o">=</span> <span class="n">service_name</span><span class="p">)</span> | |
1250 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
1251 | <span class="k">else</span><span class="p">:</span> | |
1252 | <span class="k">if</span> <span class="n">files_queue</span><span class="p">:</span> | |
1253 | <span class="n">deleteCB</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span> | |
1254 | <span class="k">else</span><span class="p">:</span> | |
1255 | <span class="bp">self</span><span class="o">.</span><span class="n">_deleteFiles_SMB2__list</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">pattern</span><span class="p">,</span> <span class="n">delete_matching_folders</span><span class="p">,</span> <span class="n">listCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span> | |
1256 | ||
1257 | <span class="k">def</span> <span class="nf">_deleteFiles_SMB2__list</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">pattern</span><span class="p">,</span> <span class="n">delete_matching_folders</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
1258 | <span class="n">folder_queue</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> | |
1259 | <span class="n">files_list</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> | |
1260 | <span class="n">current_path</span> <span class="o">=</span> <span class="p">[</span> <span class="n">path</span> <span class="p">]</span> | |
1261 | <span class="n">search</span> <span class="o">=</span> <span class="n">SMB_FILE_ATTRIBUTE_READONLY</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_HIDDEN</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_SYSTEM</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_DIRECTORY</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_ARCHIVE</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_INCL_NORMAL</span> | |
1262 | ||
1263 | <span class="k">def</span> <span class="nf">listCB</span><span class="p">(</span><span class="n">results</span><span class="p">):</span> | |
1264 | <span class="n">files</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> | |
1265 | <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="nb">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">filename</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span> <span class="s1">'.'</span><span class="p">,</span> <span class="s1">'..'</span> <span class="p">],</span> <span class="n">results</span><span class="p">):</span> | |
1266 | <span class="k">if</span> <span class="n">f</span><span class="o">.</span><span class="n">isDirectory</span><span class="p">:</span> | |
1267 | <span class="k">if</span> <span class="n">delete_matching_folders</span><span class="p">:</span> | |
1268 | <span class="n">folder_queue</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">current_path</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="o">+</span><span class="n">f</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span> | |
1269 | <span class="k">else</span><span class="p">:</span> | |
1270 | <span class="n">files</span><span class="o">.</span><span class="n">append</span><span class="p">((</span> <span class="n">current_path</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">f</span><span class="o">.</span><span class="n">filename</span> <span class="p">))</span> | |
1271 | <span class="k">if</span> <span class="n">current_path</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">!=</span><span class="n">path</span> <span class="ow">and</span> <span class="n">delete_matching_folders</span><span class="p">:</span> | |
1272 | <span class="n">files</span><span class="o">.</span><span class="n">append</span><span class="p">((</span> <span class="n">current_path</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="bp">None</span> <span class="p">))</span> | |
1273 | ||
1274 | <span class="k">if</span> <span class="n">files</span><span class="p">:</span> | |
1275 | <span class="n">files_list</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">files</span> | |
1276 | ||
1277 | <span class="k">if</span> <span class="n">folder_queue</span><span class="p">:</span> | |
1278 | <span class="n">p</span> <span class="o">=</span> <span class="n">folder_queue</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span> | |
1279 | <span class="n">current_path</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">p</span> | |
1280 | <span class="bp">self</span><span class="o">.</span><span class="n">_listPath_SMB2</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">current_path</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">listCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">search</span> <span class="o">=</span> <span class="n">search</span><span class="p">,</span> <span class="n">pattern</span> <span class="o">=</span> <span class="s1">'*'</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">)</span> | |
1281 | <span class="k">else</span><span class="p">:</span> | |
1282 | <span class="n">callback</span><span class="p">(</span><span class="n">files_list</span><span class="p">)</span> | |
1283 | ||
1284 | <span class="bp">self</span><span class="o">.</span><span class="n">_listPath_SMB2</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">listCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">search</span> <span class="o">=</span> <span class="n">search</span><span class="p">,</span> <span class="n">pattern</span> <span class="o">=</span> <span class="n">pattern</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="n">timeout</span><span class="p">)</span> | |
1285 | ||
1286 | <span class="k">def</span> <span class="nf">_deleteFiles_SMB2__del</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">tid</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
1040 | 1287 | <span class="n">messages_history</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> |
1041 | 1288 | |
1042 | 1289 | <span class="k">def</span> <span class="nf">sendCreate</span><span class="p">(</span><span class="n">tid</span><span class="p">):</span> |
1063 | 1310 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
1064 | 1311 | |
1065 | 1312 | <span class="k">def</span> <span class="nf">createCB</span><span class="p">(</span><span class="n">open_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
1313 | <span class="n">open_message</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">]</span> | |
1066 | 1314 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">open_message</span><span class="p">)</span> |
1067 | 1315 | <span class="k">if</span> <span class="n">open_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
1068 | 1316 | <span class="n">sendDelete</span><span class="p">(</span><span class="n">open_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">open_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">)</span> |
1317 | <span class="k">elif</span> <span class="n">open_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xC0000034</span><span class="n">L</span><span class="p">:</span> <span class="c1"># [MS-ERREF]: STATUS_OBJECT_NAME_NOT_FOUND</span> | |
1318 | <span class="n">callback</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> | |
1319 | <span class="k">elif</span> <span class="n">open_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mh">0xC00000BA</span><span class="n">L</span><span class="p">:</span> <span class="c1"># [MS-ERREF]: STATUS_FILE_IS_A_DIRECTORY</span> | |
1320 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Cannot delete a folder. Please use deleteDirectory() method or append "/*" to your path if you wish to delete all files in the folder.'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
1069 | 1321 | <span class="k">else</span><span class="p">:</span> |
1070 | 1322 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to open file'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> |
1071 | 1323 | |
1075 | 1327 | <span class="n">info_type</span> <span class="o">=</span> <span class="n">SMB2_INFO_FILE</span><span class="p">,</span> |
1076 | 1328 | <span class="n">file_info_class</span> <span class="o">=</span> <span class="mh">0x0d</span><span class="p">,</span> <span class="c1"># SMB2_FILE_DISPOSITION_INFO</span> |
1077 | 1329 | <span class="n">data</span> <span class="o">=</span> <span class="s1">'</span><span class="se">\x01</span><span class="s1">'</span><span class="p">))</span> |
1078 | <span class="sd">'''</span> | |
1079 | <span class="sd"> Resources:</span> | |
1080 | <span class="sd"> https://msdn.microsoft.com/en-us/library/cc246560.aspx</span> | |
1081 | <span class="sd"> https://msdn.microsoft.com/en-us/library/cc232098.aspx</span> | |
1082 | <span class="sd"> '''</span> | |
1083 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> | |
1084 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
1085 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">deleteCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">)</span> | |
1330 | <span class="c1"># [MS-SMB2]: 2.2.39, [MS-FSCC]: 2.4.11</span> | |
1331 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> | |
1332 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
1333 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">deleteCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">)</span> | |
1086 | 1334 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
1087 | 1335 | |
1088 | 1336 | <span class="k">def</span> <span class="nf">deleteCB</span><span class="p">(</span><span class="n">delete_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
1089 | 1337 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">delete_message</span><span class="p">)</span> |
1090 | 1338 | <span class="k">if</span> <span class="n">delete_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
1091 | <span class="n">closeFid</span><span class="p">(</span><span class="n">delete_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span> | |
1092 | <span class="k">else</span><span class="p">:</span> | |
1093 | <span class="n">closeFid</span><span class="p">(</span><span class="n">delete_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="n">delete_message</span><span class="o">.</span><span class="n">status</span><span class="p">)</span> | |
1339 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span> | |
1340 | <span class="k">else</span><span class="p">:</span> | |
1341 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="n">delete_message</span><span class="o">.</span><span class="n">status</span><span class="p">)</span> | |
1094 | 1342 | |
1095 | 1343 | <span class="k">def</span> <span class="nf">closeFid</span><span class="p">(</span><span class="n">tid</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">status</span> <span class="o">=</span> <span class="bp">None</span><span class="p">):</span> |
1096 | 1344 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2CloseRequest</span><span class="p">(</span><span class="n">fid</span><span class="p">))</span> |
1101 | 1349 | |
1102 | 1350 | <span class="k">def</span> <span class="nf">closeCB</span><span class="p">(</span><span class="n">close_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
1103 | 1351 | <span class="k">if</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'status'</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
1104 | <span class="n">callback</span><span class="p">(</span><span class="n">path_file_pattern</span><span class="p">)</span> | |
1352 | <span class="n">callback</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> | |
1105 | 1353 | <span class="k">else</span><span class="p">:</span> |
1106 | 1354 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Delete failed'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> |
1107 | 1355 | |
1108 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">service_name</span><span class="p">):</span> | |
1109 | <span class="k">def</span> <span class="nf">connectCB</span><span class="p">(</span><span class="n">connect_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |
1110 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">connect_message</span><span class="p">)</span> | |
1111 | <span class="k">if</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> | |
1112 | <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span> | |
1113 | <span class="n">sendCreate</span><span class="p">(</span><span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span><span class="p">)</span> | |
1114 | <span class="k">else</span><span class="p">:</span> | |
1115 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to connect to shared device'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
1116 | ||
1117 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2TreeConnectRequest</span><span class="p">(</span><span class="s1">r'</span><span class="se">\\</span><span class="si">%s</span><span class="s1">\</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_name</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="n">service_name</span> <span class="p">)))</span> | |
1118 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
1119 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">connectCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">path</span> <span class="o">=</span> <span class="n">service_name</span><span class="p">)</span> | |
1120 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
1121 | <span class="k">else</span><span class="p">:</span> | |
1122 | <span class="n">sendCreate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">])</span> | |
1356 | <span class="n">sendCreate</span><span class="p">(</span><span class="n">tid</span><span class="p">)</span> | |
1123 | 1357 | |
1124 | 1358 | <span class="k">def</span> <span class="nf">_resetFileAttributes_SMB2</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path_file_pattern</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> |
1125 | 1359 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span><span class="p">:</span> |
1160 | 1394 | <span class="k">def</span> <span class="nf">createCB</span><span class="p">(</span><span class="n">open_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
1161 | 1395 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">open_message</span><span class="p">)</span> |
1162 | 1396 | <span class="k">if</span> <span class="n">open_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
1163 | <span class="n">sendReset</span><span class="p">(</span><span class="n">open_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">open_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">)</span> | |
1397 | <span class="n">sendReset</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">open_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">)</span> | |
1164 | 1398 | <span class="k">else</span><span class="p">:</span> |
1165 | 1399 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to reset attributes of </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to open file'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> |
1166 | 1400 | |
1170 | 1404 | <span class="n">info_type</span> <span class="o">=</span> <span class="n">SMB2_INFO_FILE</span><span class="p">,</span> |
1171 | 1405 | <span class="n">file_info_class</span> <span class="o">=</span> <span class="mi">4</span><span class="p">,</span> <span class="c1"># FileBasicInformation</span> |
1172 | 1406 | <span class="n">data</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="s1">'qqqqii'</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mh">0x80</span><span class="p">,</span><span class="mi">0</span><span class="p">)))</span> <span class="c1"># FILE_ATTRIBUTE_NORMAL</span> |
1173 | <span class="sd">'''</span> | |
1174 | <span class="sd"> Resources:</span> | |
1175 | <span class="sd"> https://msdn.microsoft.com/en-us/library/cc246560.aspx</span> | |
1176 | <span class="sd"> https://msdn.microsoft.com/en-us/library/cc232064.aspx</span> | |
1177 | <span class="sd"> https://msdn.microsoft.com/en-us/library/cc232094.aspx</span> | |
1178 | <span class="sd"> https://msdn.microsoft.com/en-us/library/cc232110.aspx</span> | |
1179 | <span class="sd"> '''</span> | |
1180 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> | |
1181 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
1182 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">resetCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">)</span> | |
1407 | <span class="c1"># [MS-SMB2]: 2.2.39, [MS-FSCC]: 2.4, [MS-FSCC]: 2.4.7, [MS-FSCC]: 2.6</span> | |
1408 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> | |
1409 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
1410 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">resetCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">)</span> | |
1183 | 1411 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
1184 | 1412 | |
1185 | 1413 | <span class="k">def</span> <span class="nf">resetCB</span><span class="p">(</span><span class="n">reset_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
1186 | 1414 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">reset_message</span><span class="p">)</span> |
1187 | 1415 | <span class="k">if</span> <span class="n">reset_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
1188 | <span class="n">closeFid</span><span class="p">(</span><span class="n">reset_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span> | |
1189 | <span class="k">else</span><span class="p">:</span> | |
1190 | <span class="n">closeFid</span><span class="p">(</span><span class="n">reset_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="n">reset_message</span><span class="o">.</span><span class="n">status</span><span class="p">)</span> | |
1416 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span> | |
1417 | <span class="k">else</span><span class="p">:</span> | |
1418 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="n">reset_message</span><span class="o">.</span><span class="n">status</span><span class="p">)</span> | |
1191 | 1419 | |
1192 | 1420 | <span class="k">def</span> <span class="nf">closeFid</span><span class="p">(</span><span class="n">tid</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">status</span> <span class="o">=</span> <span class="bp">None</span><span class="p">):</span> |
1193 | 1421 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2CloseRequest</span><span class="p">(</span><span class="n">fid</span><span class="p">))</span> |
1250 | 1478 | <span class="n">create_context_data</span> <span class="o">=</span> <span class="n">create_context_data</span><span class="p">))</span> |
1251 | 1479 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> |
1252 | 1480 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
1253 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">createCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">)</span> | |
1481 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">createCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span><span class="p">)</span> | |
1254 | 1482 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
1255 | 1483 | |
1256 | 1484 | <span class="k">def</span> <span class="nf">createCB</span><span class="p">(</span><span class="n">create_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
1257 | 1485 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">create_message</span><span class="p">)</span> |
1258 | 1486 | <span class="k">if</span> <span class="n">create_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
1259 | <span class="n">closeFid</span><span class="p">(</span><span class="n">create_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">)</span> | |
1487 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">)</span> | |
1260 | 1488 | <span class="k">else</span><span class="p">:</span> |
1261 | 1489 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to create directory </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Create failed'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> |
1262 | 1490 | |
1324 | 1552 | <span class="k">def</span> <span class="nf">createCB</span><span class="p">(</span><span class="n">open_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
1325 | 1553 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">open_message</span><span class="p">)</span> |
1326 | 1554 | <span class="k">if</span> <span class="n">open_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
1327 | <span class="n">sendDelete</span><span class="p">(</span><span class="n">open_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">open_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">)</span> | |
1555 | <span class="n">sendDelete</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">open_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">)</span> | |
1328 | 1556 | <span class="k">else</span><span class="p">:</span> |
1329 | 1557 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to open directory'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> |
1330 | 1558 | |
1336 | 1564 | <span class="n">data</span> <span class="o">=</span> <span class="s1">'</span><span class="se">\x01</span><span class="s1">'</span><span class="p">))</span> |
1337 | 1565 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> |
1338 | 1566 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
1339 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">deleteCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">)</span> | |
1567 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">deleteCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">)</span> | |
1340 | 1568 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
1341 | 1569 | |
1342 | 1570 | <span class="k">def</span> <span class="nf">deleteCB</span><span class="p">(</span><span class="n">delete_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
1343 | 1571 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">delete_message</span><span class="p">)</span> |
1344 | 1572 | <span class="k">if</span> <span class="n">delete_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
1345 | <span class="n">closeFid</span><span class="p">(</span><span class="n">delete_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span> | |
1346 | <span class="k">else</span><span class="p">:</span> | |
1347 | <span class="n">closeFid</span><span class="p">(</span><span class="n">delete_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="n">delete_message</span><span class="o">.</span><span class="n">status</span><span class="p">)</span> | |
1573 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span> | |
1574 | <span class="k">else</span><span class="p">:</span> | |
1575 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="n">delete_message</span><span class="o">.</span><span class="n">status</span><span class="p">)</span> | |
1348 | 1576 | |
1349 | 1577 | <span class="k">def</span> <span class="nf">closeFid</span><span class="p">(</span><span class="n">tid</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">status</span> <span class="o">=</span> <span class="bp">None</span><span class="p">):</span> |
1350 | 1578 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2CloseRequest</span><span class="p">(</span><span class="n">fid</span><span class="p">))</span> |
1420 | 1648 | <span class="k">def</span> <span class="nf">createCB</span><span class="p">(</span><span class="n">create_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
1421 | 1649 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">create_message</span><span class="p">)</span> |
1422 | 1650 | <span class="k">if</span> <span class="n">create_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
1423 | <span class="n">sendRename</span><span class="p">(</span><span class="n">create_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">)</span> | |
1651 | <span class="n">sendRename</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">)</span> | |
1424 | 1652 | <span class="k">else</span><span class="p">:</span> |
1425 | 1653 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to rename </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to open file/directory'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">old_path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> |
1426 | 1654 | |
1433 | 1661 | <span class="n">data</span> <span class="o">=</span> <span class="n">data</span><span class="p">))</span> |
1434 | 1662 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> |
1435 | 1663 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
1436 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">renameCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">)</span> | |
1664 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">renameCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span><span class="p">,</span> <span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span><span class="p">)</span> | |
1437 | 1665 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
1438 | 1666 | |
1439 | 1667 | <span class="k">def</span> <span class="nf">renameCB</span><span class="p">(</span><span class="n">rename_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
1440 | 1668 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">rename_message</span><span class="p">)</span> |
1441 | 1669 | <span class="k">if</span> <span class="n">rename_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
1442 | <span class="n">closeFid</span><span class="p">(</span><span class="n">rename_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span> | |
1443 | <span class="k">else</span><span class="p">:</span> | |
1444 | <span class="n">closeFid</span><span class="p">(</span><span class="n">rename_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="n">rename_message</span><span class="o">.</span><span class="n">status</span><span class="p">)</span> | |
1670 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span> | |
1671 | <span class="k">else</span><span class="p">:</span> | |
1672 | <span class="n">closeFid</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">status</span> <span class="o">=</span> <span class="n">rename_message</span><span class="o">.</span><span class="n">status</span><span class="p">)</span> | |
1445 | 1673 | |
1446 | 1674 | <span class="k">def</span> <span class="nf">closeFid</span><span class="p">(</span><span class="n">tid</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">status</span> <span class="o">=</span> <span class="bp">None</span><span class="p">):</span> |
1447 | 1675 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMB2Message</span><span class="p">(</span><span class="n">SMB2CloseRequest</span><span class="p">(</span><span class="n">fid</span><span class="p">))</span> |
1508 | 1736 | <span class="k">def</span> <span class="nf">createCB</span><span class="p">(</span><span class="n">create_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
1509 | 1737 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">create_message</span><span class="p">)</span> |
1510 | 1738 | <span class="k">if</span> <span class="n">create_message</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
1511 | <span class="n">sendEnumSnapshots</span><span class="p">(</span><span class="n">create_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">)</span> | |
1739 | <span class="n">sendEnumSnapshots</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">'tid'</span><span class="p">],</span> <span class="n">create_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">fid</span><span class="p">)</span> | |
1512 | 1740 | <span class="k">else</span><span class="p">:</span> |
1513 | 1741 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to list snapshots </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to open file/directory'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">old_path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> |
1514 | 1742 | |
1649 | 1877 | <span class="bp">self</span><span class="o">.</span><span class="n">_handleSessionChallenge</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="n">ntlm_token</span><span class="p">)</span> |
1650 | 1878 | <span class="k">except</span> <span class="p">(</span> <span class="n">securityblob</span><span class="o">.</span><span class="n">BadSecurityBlobError</span><span class="p">,</span> <span class="n">securityblob</span><span class="o">.</span><span class="n">UnsupportedSecurityProvider</span> <span class="p">),</span> <span class="n">ex</span><span class="p">:</span> |
1651 | 1879 | <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">),</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span> |
1652 | <span class="k">elif</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xc000006d</span><span class="p">:</span> <span class="c1"># STATUS_LOGON_FAILURE</span> | |
1880 | <span class="k">elif</span> <span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xc000006d</span> <span class="c1"># STATUS_LOGON_FAILURE</span> | |
1881 | <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xc0000064</span> <span class="c1"># STATUS_NO_SUCH_USER</span> | |
1882 | <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xc000006a</span><span class="p">):</span> <span class="c1"># STATUS_WRONG_PASSWORD</span> | |
1653 | 1883 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">False</span> |
1654 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (with extended security) failed. Please check username and password. You may need to enable/disable NTLMv2 authentication.'</span><span class="p">)</span> | |
1884 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (with extended security) failed. Please check username and password.'</span><span class="p">)</span> | |
1885 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthFailed</span><span class="p">()</span> | |
1886 | <span class="k">elif</span> <span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xc0000193</span> <span class="c1"># STATUS_ACCOUNT_EXPIRED</span> | |
1887 | <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xC0000071</span><span class="p">):</span> <span class="c1"># STATUS_PASSWORD_EXPIRED</span> | |
1888 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">False</span> | |
1889 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (with extended security) failed. Account or password has expired.'</span><span class="p">)</span> | |
1890 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthFailed</span><span class="p">()</span> | |
1891 | <span class="k">elif</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xc0000234</span><span class="p">:</span> <span class="c1"># STATUS_ACCOUNT_LOCKED_OUT</span> | |
1892 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">False</span> | |
1893 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (with extended security) failed. Account has been locked due to too many invalid logon attempts.'</span><span class="p">)</span> | |
1894 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthFailed</span><span class="p">()</span> | |
1895 | <span class="k">elif</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xc0000072</span><span class="p">:</span> <span class="c1"># STATUS_ACCOUNT_DISABLED</span> | |
1896 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">False</span> | |
1897 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (with extended security) failed. Account has been disabled.'</span><span class="p">)</span> | |
1898 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthFailed</span><span class="p">()</span> | |
1899 | <span class="k">elif</span> <span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xc000006f</span> <span class="c1"># STATUS_INVALID_LOGON_HOURS</span> | |
1900 | <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xc000015b</span> <span class="c1"># STATUS_LOGON_TYPE_NOT_GRANTED</span> | |
1901 | <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xc0000070</span><span class="p">):</span> <span class="c1"># STATUS_INVALID_WORKSTATION</span> | |
1902 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">False</span> | |
1903 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (with extended security) failed. Not allowed.'</span><span class="p">)</span> | |
1904 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthFailed</span><span class="p">()</span> | |
1905 | <span class="k">elif</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xc000018c</span><span class="p">:</span> <span class="c1"># STATUS_TRUSTED_DOMAIN_FAILURE</span> | |
1906 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">False</span> | |
1907 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (with extended security) failed. Domain not trusted.'</span><span class="p">)</span> | |
1908 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthFailed</span><span class="p">()</span> | |
1909 | <span class="k">elif</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xc000018d</span><span class="p">:</span> <span class="c1"># STATUS_TRUSTED_RELATIONSHIP_FAILURE</span> | |
1910 | <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span> <span class="o">=</span> <span class="bp">False</span> | |
1911 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Authentication (with extended security) failed. Workstation not trusted.'</span><span class="p">)</span> | |
1655 | 1912 | <span class="bp">self</span><span class="o">.</span><span class="n">onAuthFailed</span><span class="p">()</span> |
1656 | 1913 | <span class="k">else</span><span class="p">:</span> |
1657 | 1914 | <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">'Unknown status value (0x</span><span class="si">%08X</span><span class="s1">) in SMB_COM_SESSION_SETUP_ANDX (with extended security)'</span> <span class="o">%</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span><span class="p">,</span> |
1718 | 1975 | <span class="n">lm_challenge_response</span><span class="p">,</span> |
1719 | 1976 | <span class="n">session_key</span><span class="p">,</span> |
1720 | 1977 | <span class="bp">self</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> |
1721 | <span class="bp">self</span><span class="o">.</span><span class="n">domain</span><span class="p">)</span> | |
1978 | <span class="bp">self</span><span class="o">.</span><span class="n">domain</span><span class="p">,</span> | |
1979 | <span class="bp">self</span><span class="o">.</span><span class="n">my_name</span><span class="p">)</span> | |
1722 | 1980 | |
1723 | 1981 | <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">isEnabledFor</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">):</span> |
1724 | 1982 | <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">'NT challenge response is "</span><span class="si">%s</span><span class="s1">" (</span><span class="si">%d</span><span class="s1"> bytes)'</span><span class="p">,</span> <span class="n">binascii</span><span class="o">.</span><span class="n">hexlify</span><span class="p">(</span><span class="n">nt_challenge_response</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="n">nt_challenge_response</span><span class="p">))</span> |
1912 | 2170 | <span class="k">def</span> <span class="nf">readCB</span><span class="p">(</span><span class="n">read_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
1913 | 2171 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">read_message</span><span class="p">)</span> |
1914 | 2172 | <span class="k">if</span> <span class="ow">not</span> <span class="n">read_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span> |
1915 | <span class="n">data_len</span> <span class="o">=</span> <span class="n">read_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">data_length</span> | |
1916 | 2173 | <span class="n">data_bytes</span> <span class="o">=</span> <span class="n">read_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">data</span> |
1917 | 2174 | |
1918 | 2175 | <span class="k">if</span> <span class="nb">ord</span><span class="p">(</span><span class="n">data_bytes</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span> <span class="o">&</span> <span class="mh">0x02</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> |
1919 | <span class="n">sendReadRequest</span><span class="p">(</span><span class="n">read_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'data_bytes'</span><span class="p">]</span> <span class="o">+</span> <span class="n">data_bytes</span><span class="p">[</span><span class="mi">24</span><span class="p">:</span><span class="n">data_len</span><span class="o">-</span><span class="mi">24</span><span class="p">])</span> | |
1920 | <span class="k">else</span><span class="p">:</span> | |
1921 | <span class="n">decodeResults</span><span class="p">(</span><span class="n">read_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'data_bytes'</span><span class="p">]</span> <span class="o">+</span> <span class="n">data_bytes</span><span class="p">[</span><span class="mi">24</span><span class="p">:</span><span class="n">data_len</span><span class="o">-</span><span class="mi">24</span><span class="p">])</span> | |
2176 | <span class="n">sendReadRequest</span><span class="p">(</span><span class="n">read_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'data_bytes'</span><span class="p">]</span> <span class="o">+</span> <span class="n">data_bytes</span><span class="p">[</span><span class="mi">24</span><span class="p">:])</span> | |
2177 | <span class="k">else</span><span class="p">:</span> | |
2178 | <span class="n">decodeResults</span><span class="p">(</span><span class="n">read_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">],</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'data_bytes'</span><span class="p">]</span> <span class="o">+</span> <span class="n">data_bytes</span><span class="p">[</span><span class="mi">24</span><span class="p">:])</span> | |
1922 | 2179 | <span class="k">else</span><span class="p">:</span> |
1923 | 2180 | <span class="n">closeFid</span><span class="p">(</span><span class="n">read_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'fid'</span><span class="p">])</span> |
1924 | 2181 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to list shares: Unable to retrieve shared device list'</span><span class="p">,</span> <span class="n">messages_history</span><span class="p">))</span> |
1957 | 2214 | <span class="n">setup_bytes</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="s1">'<H'</span><span class="p">,</span> <span class="mh">0x0001</span><span class="p">)</span> <span class="c1"># TRANS2_FIND_FIRST2 sub-command. See [MS-CIFS]: 2.2.6.2.1</span> |
1958 | 2215 | <span class="n">params_bytes</span> <span class="o">=</span> \ |
1959 | 2216 | <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="s1">'<HHHHI'</span><span class="p">,</span> |
1960 | <span class="n">search</span><span class="p">,</span> <span class="c1"># SearchAttributes</span> | |
2217 | <span class="n">search</span> <span class="o">&</span> <span class="mh">0xFFFF</span><span class="p">,</span> <span class="c1"># SearchAttributes (need to restrict the values due to introduction of SMB_FILE_ATTRIBUTE_INCL_NORMAL)</span> | |
1961 | 2218 | <span class="mi">100</span><span class="p">,</span> <span class="c1"># SearchCount</span> |
1962 | 2219 | <span class="mh">0x0006</span><span class="p">,</span> <span class="c1"># Flags: SMB_FIND_CLOSE_AT_EOS | SMB_FIND_RETURN_RESUME_KEYS</span> |
1963 | 2220 | <span class="mh">0x0104</span><span class="p">,</span> <span class="c1"># InfoLevel: SMB_FIND_FILE_BOTH_DIRECTORY_INFO</span> |
1964 | <span class="mh">0x0000</span><span class="p">)</span> <span class="c1"># SearchStorageType</span> | |
2221 | <span class="mh">0x0000</span><span class="p">)</span> <span class="c1"># SearchStorageType (seems to be ignored by Windows)</span> | |
1965 | 2222 | <span class="k">if</span> <span class="n">support_dfs</span><span class="p">:</span> |
1966 | 2223 | <span class="n">params_bytes</span> <span class="o">+=</span> <span class="p">(</span><span class="s2">"</span><span class="se">\\</span><span class="s2">"</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_name</span> <span class="o">+</span> <span class="s2">"</span><span class="se">\\</span><span class="s2">"</span> <span class="o">+</span> <span class="n">service_name</span> <span class="o">+</span> <span class="n">path</span> <span class="o">+</span> <span class="n">pattern</span> <span class="o">+</span> <span class="s1">'</span><span class="se">\0</span><span class="s1">'</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">'UTF-16LE'</span><span class="p">)</span> |
1967 | 2224 | <span class="k">else</span><span class="p">:</span> |
1968 | <span class="n">params_bytes</span> <span class="o">+=</span> <span class="p">(</span><span class="n">path</span> <span class="o">+</span> <span class="n">pattern</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">'UTF-16LE'</span><span class="p">)</span> | |
2225 | <span class="n">params_bytes</span> <span class="o">+=</span> <span class="p">(</span><span class="n">path</span> <span class="o">+</span> <span class="n">pattern</span> <span class="o">+</span> <span class="s1">'</span><span class="se">\0</span><span class="s1">'</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">'UTF-16LE'</span><span class="p">)</span> | |
1969 | 2226 | |
1970 | 2227 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMBMessage</span><span class="p">(</span><span class="n">ComTransaction2Request</span><span class="p">(</span><span class="n">max_params_count</span> <span class="o">=</span> <span class="mi">10</span><span class="p">,</span> |
1971 | 2228 | <span class="n">max_data_count</span> <span class="o">=</span> <span class="mi">16644</span><span class="p">,</span> |
2001 | 2258 | |
2002 | 2259 | <span class="n">filename</span> <span class="o">=</span> <span class="n">data_bytes</span><span class="p">[</span><span class="n">offset2</span><span class="p">:</span><span class="n">offset2</span><span class="o">+</span><span class="n">filename_length</span><span class="p">]</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">'UTF-16LE'</span><span class="p">)</span> |
2003 | 2260 | <span class="n">short_name</span> <span class="o">=</span> <span class="n">short_name</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">'UTF-16LE'</span><span class="p">)</span> |
2004 | <span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">SharedFile</span><span class="p">(</span><span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">create_time</span><span class="p">),</span> <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_access_time</span><span class="p">),</span> | |
2005 | <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_write_time</span><span class="p">),</span> <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_attr_change_time</span><span class="p">),</span> | |
2006 | <span class="n">file_size</span><span class="p">,</span> <span class="n">alloc_size</span><span class="p">,</span> <span class="n">file_attributes</span><span class="p">,</span> <span class="n">short_name</span><span class="p">,</span> <span class="n">filename</span><span class="p">))</span> | |
2261 | ||
2262 | <span class="n">accept_result</span> <span class="o">=</span> <span class="bp">False</span> | |
2263 | <span class="k">if</span> <span class="p">(</span><span class="n">file_attributes</span> <span class="o">&</span> <span class="mh">0xff</span><span class="p">)</span> <span class="ow">in</span> <span class="p">(</span> <span class="mh">0x00</span><span class="p">,</span> <span class="n">ATTR_NORMAL</span> <span class="p">):</span> <span class="c1"># Only the first 8-bits are compared. We ignore other bits like temp, compressed, encryption, sparse, indexed, etc</span> | |
2264 | <span class="n">accept_result</span> <span class="o">=</span> <span class="p">(</span><span class="n">search</span> <span class="o">==</span> <span class="n">SMB_FILE_ATTRIBUTE_NORMAL</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">search</span> <span class="o">&</span> <span class="n">SMB_FILE_ATTRIBUTE_INCL_NORMAL</span><span class="p">)</span> | |
2265 | <span class="k">else</span><span class="p">:</span> | |
2266 | <span class="n">accept_result</span> <span class="o">=</span> <span class="p">(</span><span class="n">file_attributes</span> <span class="o">&</span> <span class="n">search</span><span class="p">)</span> <span class="o">></span> <span class="mi">0</span> | |
2267 | <span class="k">if</span> <span class="n">accept_result</span><span class="p">:</span> | |
2268 | <span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">SharedFile</span><span class="p">(</span><span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">create_time</span><span class="p">),</span> <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_access_time</span><span class="p">),</span> | |
2269 | <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_write_time</span><span class="p">),</span> <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_attr_change_time</span><span class="p">),</span> | |
2270 | <span class="n">file_size</span><span class="p">,</span> <span class="n">alloc_size</span><span class="p">,</span> <span class="n">file_attributes</span><span class="p">,</span> <span class="n">short_name</span><span class="p">,</span> <span class="n">filename</span><span class="p">))</span> | |
2007 | 2271 | |
2008 | 2272 | <span class="k">if</span> <span class="n">next_offset</span><span class="p">:</span> |
2009 | 2273 | <span class="n">offset</span> <span class="o">+=</span> <span class="n">next_offset</span> |
2043 | 2307 | <span class="k">elif</span> <span class="n">end_of_search</span><span class="p">:</span> |
2044 | 2308 | <span class="n">callback</span><span class="p">(</span><span class="n">results</span><span class="p">)</span> |
2045 | 2309 | <span class="k">else</span><span class="p">:</span> |
2046 | <span class="n">sendFindNext</span><span class="p">(</span><span class="n">find_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">sid</span><span class="p">,</span> <span class="n">last_name_offset</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'support_dfs'</span><span class="p">,</span> <span class="bp">False</span><span class="p">))</span> | |
2047 | <span class="k">else</span><span class="p">:</span> | |
2048 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to list </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to retrieve file list'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2049 | ||
2050 | <span class="k">def</span> <span class="nf">sendFindNext</span><span class="p">(</span><span class="n">tid</span><span class="p">,</span> <span class="n">sid</span><span class="p">,</span> <span class="n">resume_key</span><span class="p">,</span> <span class="n">support_dfs</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span> | |
2310 | <span class="n">sendFindNext</span><span class="p">(</span><span class="n">find_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">sid</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">results</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'support_dfs'</span><span class="p">,</span> <span class="bp">False</span><span class="p">))</span> | |
2311 | <span class="k">else</span><span class="p">:</span> | |
2312 | <span class="k">if</span> <span class="n">find_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xC000000F</span><span class="p">:</span> <span class="c1"># [MS-ERREF]: STATUS_NO_SUCH_FILE</span> | |
2313 | <span class="c1"># Remote server returns STATUS_NO_SUCH_FILE error so we assume that the search returns no matching files</span> | |
2314 | <span class="n">callback</span><span class="p">([</span> <span class="p">])</span> | |
2315 | <span class="k">else</span><span class="p">:</span> | |
2316 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to list </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to retrieve file list'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2317 | ||
2318 | <span class="k">def</span> <span class="nf">sendFindNext</span><span class="p">(</span><span class="n">tid</span><span class="p">,</span> <span class="n">sid</span><span class="p">,</span> <span class="n">resume_key</span><span class="p">,</span> <span class="n">resume_file</span><span class="p">,</span> <span class="n">support_dfs</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span> | |
2051 | 2319 | <span class="n">setup_bytes</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="s1">'<H'</span><span class="p">,</span> <span class="mh">0x0002</span><span class="p">)</span> <span class="c1"># TRANS2_FIND_NEXT2 sub-command. See [MS-CIFS]: 2.2.6.3.1</span> |
2052 | 2320 | <span class="n">params_bytes</span> <span class="o">=</span> \ |
2053 | 2321 | <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="s1">'<HHHIH'</span><span class="p">,</span> |
2055 | 2323 | <span class="mi">100</span><span class="p">,</span> <span class="c1"># SearchCount</span> |
2056 | 2324 | <span class="mh">0x0104</span><span class="p">,</span> <span class="c1"># InfoLevel: SMB_FIND_FILE_BOTH_DIRECTORY_INFO</span> |
2057 | 2325 | <span class="n">resume_key</span><span class="p">,</span> <span class="c1"># ResumeKey</span> |
2058 | <span class="mh">0x000a</span><span class="p">)</span> <span class="c1"># Flags: SMB_FIND_RETURN_RESUME_KEYS | SMB_FIND_CLOSE_AT_EOS | SMB_FIND_RETURN_RESUME_KEYS</span> | |
2059 | <span class="k">if</span> <span class="n">support_dfs</span><span class="p">:</span> | |
2060 | <span class="n">params_bytes</span> <span class="o">+=</span> <span class="p">(</span><span class="s2">"</span><span class="se">\\</span><span class="s2">"</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_name</span> <span class="o">+</span> <span class="s2">"</span><span class="se">\\</span><span class="s2">"</span> <span class="o">+</span> <span class="n">service_name</span> <span class="o">+</span> <span class="n">path</span> <span class="o">+</span> <span class="n">pattern</span> <span class="o">+</span> <span class="s1">'</span><span class="se">\0</span><span class="s1">'</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">'UTF-16LE'</span><span class="p">)</span> | |
2061 | <span class="k">else</span><span class="p">:</span> | |
2062 | <span class="n">params_bytes</span> <span class="o">+=</span> <span class="p">(</span><span class="n">path</span> <span class="o">+</span> <span class="n">pattern</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">'UTF-16LE'</span><span class="p">)</span> | |
2326 | <span class="mh">0x0006</span><span class="p">)</span> <span class="c1"># Flags: SMB_FIND_RETURN_RESUME_KEYS | SMB_FIND_CLOSE_AT_EOS</span> | |
2327 | <span class="n">params_bytes</span> <span class="o">+=</span> <span class="p">(</span><span class="n">resume_file</span><span class="o">+</span><span class="s1">'</span><span class="se">\0</span><span class="s1">'</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">'UTF-16LE'</span><span class="p">)</span> | |
2063 | 2328 | |
2064 | 2329 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMBMessage</span><span class="p">(</span><span class="n">ComTransaction2Request</span><span class="p">(</span><span class="n">max_params_count</span> <span class="o">=</span> <span class="mi">10</span><span class="p">,</span> |
2065 | 2330 | <span class="n">max_data_count</span> <span class="o">=</span> <span class="mi">16644</span><span class="p">,</span> |
2105 | 2370 | <span class="k">elif</span> <span class="n">end_of_search</span><span class="p">:</span> |
2106 | 2371 | <span class="n">callback</span><span class="p">(</span><span class="n">results</span><span class="p">)</span> |
2107 | 2372 | <span class="k">else</span><span class="p">:</span> |
2108 | <span class="n">sendFindNext</span><span class="p">(</span><span class="n">find_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'sid'</span><span class="p">],</span> <span class="n">last_name_offset</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'support_dfs'</span><span class="p">,</span> <span class="bp">False</span><span class="p">))</span> | |
2373 | <span class="n">sendFindNext</span><span class="p">(</span><span class="n">find_message</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">'sid'</span><span class="p">],</span> <span class="mi">0</span><span class="p">,</span> <span class="n">results</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'support_dfs'</span><span class="p">,</span> <span class="bp">False</span><span class="p">))</span> | |
2109 | 2374 | <span class="k">else</span><span class="p">:</span> |
2110 | 2375 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to list </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to retrieve file list'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> |
2111 | 2376 | |
2183 | 2448 | <span class="n">info_size</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">info_format</span><span class="p">)</span> |
2184 | 2449 | <span class="n">create_time</span><span class="p">,</span> <span class="n">last_access_time</span><span class="p">,</span> <span class="n">last_write_time</span><span class="p">,</span> <span class="n">last_attr_change_time</span><span class="p">,</span> \ |
2185 | 2450 | <span class="n">file_attributes</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">alloc_size</span><span class="p">,</span> <span class="n">file_size</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="n">info_format</span><span class="p">,</span> <span class="n">query_message</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">data_bytes</span><span class="p">[:</span><span class="n">info_size</span><span class="p">])</span> |
2186 | ||
2187 | <span class="n">info</span> <span class="o">=</span> <span class="n">SharedFile</span><span class="p">(</span><span class="n">create_time</span><span class="p">,</span> <span class="n">last_access_time</span><span class="p">,</span> <span class="n">last_write_time</span><span class="p">,</span> <span class="n">last_attr_change_time</span><span class="p">,</span> | |
2188 | <span class="n">file_size</span><span class="p">,</span> <span class="n">alloc_size</span><span class="p">,</span> <span class="n">file_attributes</span><span class="p">,</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">path</span><span class="p">),</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">path</span><span class="p">))</span> | |
2451 | <span class="n">filename</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_extractLastPathComponent</span><span class="p">(</span><span class="nb">unicode</span><span class="p">(</span><span class="n">path</span><span class="p">))</span> | |
2452 | ||
2453 | <span class="n">info</span> <span class="o">=</span> <span class="n">SharedFile</span><span class="p">(</span><span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">create_time</span><span class="p">),</span> <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_access_time</span><span class="p">),</span> <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_write_time</span><span class="p">),</span> <span class="n">convertFILETIMEtoEpoch</span><span class="p">(</span><span class="n">last_attr_change_time</span><span class="p">),</span> | |
2454 | <span class="n">file_size</span><span class="p">,</span> <span class="n">alloc_size</span><span class="p">,</span> <span class="n">file_attributes</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span> | |
2189 | 2455 | <span class="n">callback</span><span class="p">(</span><span class="n">info</span><span class="p">)</span> |
2190 | 2456 | <span class="k">else</span><span class="p">:</span> |
2191 | 2457 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to get attributes for </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Read failed'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> |
2205 | 2471 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
2206 | 2472 | <span class="k">else</span><span class="p">:</span> |
2207 | 2473 | <span class="n">sendQuery</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">])</span> |
2474 | ||
2475 | <span class="k">def</span> <span class="nf">_getSecurity_SMB1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path_file_pattern</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
2476 | <span class="k">raise</span> <span class="n">NotReadyError</span><span class="p">(</span><span class="s1">'getSecurity is not yet implemented for SMB1'</span><span class="p">)</span> | |
2208 | 2477 | |
2209 | 2478 | <span class="k">def</span> <span class="nf">_retrieveFile_SMB1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">file_obj</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> |
2210 | 2479 | <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_retrieveFileFromOffset</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">file_obj</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="il">0L</span><span class="p">,</span> <span class="o">-</span><span class="il">1L</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span> |
2373 | 2642 | <span class="k">else</span><span class="p">:</span> |
2374 | 2643 | <span class="n">sendOpen</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">])</span> |
2375 | 2644 | |
2376 | <span class="k">def</span> <span class="nf">_deleteFiles_SMB1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path_file_pattern</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
2645 | <span class="k">def</span> <span class="nf">_deleteFiles_SMB1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path_file_pattern</span><span class="p">,</span> <span class="n">delete_matching_folders</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
2377 | 2646 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span><span class="p">:</span> |
2378 | 2647 | <span class="k">raise</span> <span class="n">NotReadyError</span><span class="p">(</span><span class="s1">'SMB connection not authenticated'</span><span class="p">)</span> |
2379 | 2648 | |
2649 | <span class="n">expiry_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">+</span> <span class="n">timeout</span> | |
2650 | <span class="n">pattern</span> <span class="o">=</span> <span class="bp">None</span> | |
2380 | 2651 | <span class="n">path</span> <span class="o">=</span> <span class="n">path_file_pattern</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">)</span> |
2652 | <span class="k">if</span> <span class="n">path</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">):</span> | |
2653 | <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span> | |
2654 | <span class="k">if</span> <span class="n">path</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">):</span> | |
2655 | <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> | |
2656 | <span class="k">else</span><span class="p">:</span> | |
2657 | <span class="n">path_components</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">)</span> | |
2658 | <span class="k">if</span> <span class="n">path_components</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">'*'</span><span class="p">)</span> <span class="o">></span> <span class="o">-</span><span class="mi">1</span> <span class="ow">or</span> <span class="n">path_components</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">'?'</span><span class="p">)</span> <span class="o">></span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span> | |
2659 | <span class="n">path</span> <span class="o">=</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_components</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span> | |
2660 | <span class="n">pattern</span> <span class="o">=</span> <span class="n">path_components</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> | |
2661 | <span class="n">messages_history</span><span class="p">,</span> <span class="n">files_queue</span> <span class="o">=</span> <span class="p">[</span> <span class="p">],</span> <span class="p">[</span> <span class="p">]</span> | |
2662 | ||
2663 | <span class="k">if</span> <span class="n">pattern</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span> | |
2664 | <span class="n">path_components</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">)</span> | |
2665 | <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">path_components</span><span class="p">)</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> | |
2666 | <span class="n">files_queue</span><span class="o">.</span><span class="n">append</span><span class="p">((</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_components</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]),</span> <span class="n">path_components</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="p">))</span> | |
2667 | <span class="k">else</span><span class="p">:</span> | |
2668 | <span class="n">files_queue</span><span class="o">.</span><span class="n">append</span><span class="p">((</span> <span class="s1">''</span><span class="p">,</span> <span class="n">path</span> <span class="p">))</span> | |
2669 | ||
2670 | <span class="k">def</span> <span class="nf">deleteCB</span><span class="p">(</span><span class="n">path</span><span class="p">):</span> | |
2671 | <span class="k">if</span> <span class="n">files_queue</span><span class="p">:</span> | |
2672 | <span class="n">p</span><span class="p">,</span> <span class="n">filename</span> <span class="o">=</span> <span class="n">files_queue</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> | |
2673 | <span class="k">if</span> <span class="n">filename</span><span class="p">:</span> | |
2674 | <span class="k">if</span> <span class="n">p</span><span class="p">:</span> | |
2675 | <span class="n">filename</span> <span class="o">=</span> <span class="n">p</span> <span class="o">+</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">'</span> <span class="o">+</span> <span class="n">filename</span> | |
2676 | <span class="bp">self</span><span class="o">.</span><span class="n">_deleteFiles_SMB1__del</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">],</span> <span class="n">filename</span><span class="p">,</span> <span class="n">deleteCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span> | |
2677 | <span class="k">else</span><span class="p">:</span> | |
2678 | <span class="bp">self</span><span class="o">.</span><span class="n">_deleteDirectory_SMB1</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">deleteCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">)</span> | |
2679 | <span class="k">else</span><span class="p">:</span> | |
2680 | <span class="n">callback</span><span class="p">(</span><span class="n">path_file_pattern</span><span class="p">)</span> | |
2681 | ||
2682 | <span class="k">def</span> <span class="nf">listCB</span><span class="p">(</span><span class="n">files_list</span><span class="p">):</span> | |
2683 | <span class="n">files_queue</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">files_list</span><span class="p">)</span> | |
2684 | <span class="n">deleteCB</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span> | |
2685 | ||
2686 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">service_name</span><span class="p">):</span> | |
2687 | <span class="k">def</span> <span class="nf">connectCB</span><span class="p">(</span><span class="n">connect_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |
2688 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">connect_message</span><span class="p">)</span> | |
2689 | <span class="k">if</span> <span class="ow">not</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span> | |
2690 | <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span> | |
2691 | <span class="k">if</span> <span class="n">files_queue</span><span class="p">:</span> | |
2692 | <span class="n">deleteCB</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span> | |
2693 | <span class="k">else</span><span class="p">:</span> | |
2694 | <span class="bp">self</span><span class="o">.</span><span class="n">_deleteFiles_SMB1__list</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">pattern</span><span class="p">,</span> <span class="n">delete_matching_folders</span><span class="p">,</span> <span class="n">listCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span> | |
2695 | <span class="k">else</span><span class="p">:</span> | |
2696 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to connect to shared device'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2697 | ||
2698 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMBMessage</span><span class="p">(</span><span class="n">ComTreeConnectAndxRequest</span><span class="p">(</span><span class="s1">r'</span><span class="se">\\</span><span class="si">%s</span><span class="s1">\</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_name</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">SERVICE_ANY</span><span class="p">,</span> <span class="s1">''</span><span class="p">))</span> | |
2699 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2700 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">expiry_time</span><span class="p">,</span> <span class="n">connectCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">path</span> <span class="o">=</span> <span class="n">service_name</span><span class="p">)</span> | |
2701 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2702 | <span class="k">else</span><span class="p">:</span> | |
2703 | <span class="k">if</span> <span class="n">files_queue</span><span class="p">:</span> | |
2704 | <span class="n">deleteCB</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span> | |
2705 | <span class="k">else</span><span class="p">:</span> | |
2706 | <span class="bp">self</span><span class="o">.</span><span class="n">_deleteFiles_SMB1__list</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">pattern</span><span class="p">,</span> <span class="n">delete_matching_folders</span><span class="p">,</span> <span class="n">listCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span> | |
2707 | ||
2708 | <span class="k">def</span> <span class="nf">_deleteFiles_SMB1__list</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">pattern</span><span class="p">,</span> <span class="n">delete_matching_folders</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
2709 | <span class="n">folder_queue</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> | |
2710 | <span class="n">files_list</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> | |
2711 | <span class="n">current_path</span> <span class="o">=</span> <span class="p">[</span> <span class="n">path</span> <span class="p">]</span> | |
2712 | <span class="n">search</span> <span class="o">=</span> <span class="n">SMB_FILE_ATTRIBUTE_READONLY</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_HIDDEN</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_SYSTEM</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_DIRECTORY</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_ARCHIVE</span> <span class="o">|</span> <span class="n">SMB_FILE_ATTRIBUTE_INCL_NORMAL</span> | |
2713 | ||
2714 | <span class="k">def</span> <span class="nf">listCB</span><span class="p">(</span><span class="n">results</span><span class="p">):</span> | |
2715 | <span class="n">files</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> | |
2716 | <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="nb">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">filename</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span> <span class="s1">'.'</span><span class="p">,</span> <span class="s1">'..'</span> <span class="p">],</span> <span class="n">results</span><span class="p">):</span> | |
2717 | <span class="k">if</span> <span class="n">f</span><span class="o">.</span><span class="n">isDirectory</span><span class="p">:</span> | |
2718 | <span class="k">if</span> <span class="n">delete_matching_folders</span><span class="p">:</span> | |
2719 | <span class="n">folder_queue</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">current_path</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="o">+</span><span class="n">f</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span> | |
2720 | <span class="k">else</span><span class="p">:</span> | |
2721 | <span class="n">files</span><span class="o">.</span><span class="n">append</span><span class="p">((</span> <span class="n">current_path</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">f</span><span class="o">.</span><span class="n">filename</span> <span class="p">))</span> | |
2722 | <span class="k">if</span> <span class="n">current_path</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">!=</span><span class="n">path</span> <span class="ow">and</span> <span class="n">delete_matching_folders</span><span class="p">:</span> | |
2723 | <span class="n">files</span><span class="o">.</span><span class="n">append</span><span class="p">((</span> <span class="n">current_path</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="bp">None</span> <span class="p">))</span> | |
2724 | ||
2725 | <span class="k">if</span> <span class="n">files</span><span class="p">:</span> | |
2726 | <span class="n">files_list</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">files</span> | |
2727 | ||
2728 | <span class="k">if</span> <span class="n">folder_queue</span><span class="p">:</span> | |
2729 | <span class="n">p</span> <span class="o">=</span> <span class="n">folder_queue</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span> | |
2730 | <span class="n">current_path</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">p</span> | |
2731 | <span class="bp">self</span><span class="o">.</span><span class="n">_listPath_SMB1</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">current_path</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">listCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">search</span> <span class="o">=</span> <span class="n">search</span><span class="p">,</span> <span class="n">pattern</span> <span class="o">=</span> <span class="s1">'*'</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">)</span> | |
2732 | <span class="k">else</span><span class="p">:</span> | |
2733 | <span class="n">callback</span><span class="p">(</span><span class="n">files_list</span><span class="p">)</span> | |
2734 | ||
2735 | <span class="bp">self</span><span class="o">.</span><span class="n">_listPath_SMB1</span><span class="p">(</span><span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">listCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">search</span> <span class="o">=</span> <span class="n">search</span><span class="p">,</span> <span class="n">pattern</span> <span class="o">=</span> <span class="n">pattern</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="n">timeout</span><span class="p">)</span> | |
2736 | ||
2737 | ||
2738 | <span class="k">def</span> <span class="nf">_deleteFiles_SMB1__del</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">tid</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
2381 | 2739 | <span class="n">messages_history</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> |
2382 | 2740 | |
2383 | 2741 | <span class="k">def</span> <span class="nf">sendDelete</span><span class="p">(</span><span class="n">tid</span><span class="p">):</span> |
2391 | 2749 | <span class="k">def</span> <span class="nf">deleteCB</span><span class="p">(</span><span class="n">delete_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
2392 | 2750 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">delete_message</span><span class="p">)</span> |
2393 | 2751 | <span class="k">if</span> <span class="ow">not</span> <span class="n">delete_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span> |
2752 | <span class="n">callback</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> | |
2753 | <span class="k">elif</span> <span class="n">delete_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xC000000F</span><span class="n">L</span><span class="p">:</span> <span class="c1"># [MS-ERREF]: STATUS_NO_SUCH_FILE</span> | |
2754 | <span class="c1"># If there are no matching files, we just treat as success instead of failing</span> | |
2394 | 2755 | <span class="n">callback</span><span class="p">(</span><span class="n">path_file_pattern</span><span class="p">)</span> |
2395 | <span class="k">else</span><span class="p">:</span> | |
2396 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to store </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Delete failed'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2756 | <span class="k">elif</span> <span class="n">delete_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xC00000BA</span><span class="n">L</span><span class="p">:</span> <span class="c1"># [MS-ERREF]: STATUS_FILE_IS_A_DIRECTORY</span> | |
2757 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Cannot delete a folder. Please use deleteDirectory() method or append "/*" to your path if you wish to delete all files in the folder.'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2758 | <span class="k">elif</span> <span class="n">delete_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xC0000034</span><span class="n">L</span><span class="p">:</span> <span class="c1"># [MS-ERREF]: STATUS_OBJECT_NAME_INVALID</span> | |
2759 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Path not found'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2760 | <span class="k">else</span><span class="p">:</span> | |
2761 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Delete failed'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2762 | ||
2763 | <span class="n">sendDelete</span><span class="p">(</span><span class="n">tid</span><span class="p">)</span> | |
2764 | ||
2765 | <span class="k">def</span> <span class="nf">_resetFileAttributes_SMB1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path_file_pattern</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
2766 | <span class="k">raise</span> <span class="n">NotReadyError</span><span class="p">(</span><span class="s1">'resetFileAttributes is not yet implemented for SMB1'</span><span class="p">)</span> | |
2767 | ||
2768 | <span class="k">def</span> <span class="nf">_createDirectory_SMB1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
2769 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span><span class="p">:</span> | |
2770 | <span class="k">raise</span> <span class="n">NotReadyError</span><span class="p">(</span><span class="s1">'SMB connection not authenticated'</span><span class="p">)</span> | |
2771 | ||
2772 | <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">)</span> | |
2773 | <span class="n">messages_history</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> | |
2774 | ||
2775 | <span class="k">def</span> <span class="nf">sendCreate</span><span class="p">(</span><span class="n">tid</span><span class="p">):</span> | |
2776 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMBMessage</span><span class="p">(</span><span class="n">ComCreateDirectoryRequest</span><span class="p">(</span><span class="n">path</span><span class="p">))</span> | |
2777 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> | |
2778 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2779 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">createCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">)</span> | |
2780 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2781 | ||
2782 | <span class="k">def</span> <span class="nf">createCB</span><span class="p">(</span><span class="n">create_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |
2783 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">create_message</span><span class="p">)</span> | |
2784 | <span class="k">if</span> <span class="ow">not</span> <span class="n">create_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span> | |
2785 | <span class="n">callback</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> | |
2786 | <span class="k">else</span><span class="p">:</span> | |
2787 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to create directory </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Create failed'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2788 | ||
2789 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">service_name</span><span class="p">):</span> | |
2790 | <span class="k">def</span> <span class="nf">connectCB</span><span class="p">(</span><span class="n">connect_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |
2791 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">connect_message</span><span class="p">)</span> | |
2792 | <span class="k">if</span> <span class="ow">not</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span> | |
2793 | <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span> | |
2794 | <span class="n">sendCreate</span><span class="p">(</span><span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span><span class="p">)</span> | |
2795 | <span class="k">else</span><span class="p">:</span> | |
2796 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to create directory </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to connect to shared device'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2797 | ||
2798 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMBMessage</span><span class="p">(</span><span class="n">ComTreeConnectAndxRequest</span><span class="p">(</span><span class="s1">r'</span><span class="se">\\</span><span class="si">%s</span><span class="s1">\</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_name</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">SERVICE_ANY</span><span class="p">,</span> <span class="s1">''</span><span class="p">))</span> | |
2799 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2800 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">connectCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">path</span> <span class="o">=</span> <span class="n">service_name</span><span class="p">)</span> | |
2801 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2802 | <span class="k">else</span><span class="p">:</span> | |
2803 | <span class="n">sendCreate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">])</span> | |
2804 | ||
2805 | <span class="k">def</span> <span class="nf">_deleteDirectory_SMB1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
2806 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span><span class="p">:</span> | |
2807 | <span class="k">raise</span> <span class="n">NotReadyError</span><span class="p">(</span><span class="s1">'SMB connection not authenticated'</span><span class="p">)</span> | |
2808 | ||
2809 | <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">)</span> | |
2810 | <span class="n">messages_history</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> | |
2811 | ||
2812 | <span class="k">def</span> <span class="nf">sendDelete</span><span class="p">(</span><span class="n">tid</span><span class="p">):</span> | |
2813 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMBMessage</span><span class="p">(</span><span class="n">ComDeleteDirectoryRequest</span><span class="p">(</span><span class="n">path</span><span class="p">))</span> | |
2814 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> | |
2815 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2816 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">deleteCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">)</span> | |
2817 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2818 | ||
2819 | <span class="k">def</span> <span class="nf">deleteCB</span><span class="p">(</span><span class="n">delete_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |
2820 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">delete_message</span><span class="p">)</span> | |
2821 | <span class="k">if</span> <span class="ow">not</span> <span class="n">delete_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span> | |
2822 | <span class="n">callback</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> | |
2823 | <span class="k">else</span><span class="p">:</span> | |
2824 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete directory </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Delete failed'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2397 | 2825 | |
2398 | 2826 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">service_name</span><span class="p">):</span> |
2399 | 2827 | <span class="k">def</span> <span class="nf">connectCB</span><span class="p">(</span><span class="n">connect_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
2402 | 2830 | <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span> |
2403 | 2831 | <span class="n">sendDelete</span><span class="p">(</span><span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span><span class="p">)</span> |
2404 | 2832 | <span class="k">else</span><span class="p">:</span> |
2405 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to connect to shared device'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2406 | ||
2407 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMBMessage</span><span class="p">(</span><span class="n">ComTreeConnectAndxRequest</span><span class="p">(</span><span class="s1">r'</span><span class="se">\\</span><span class="si">%s</span><span class="s1">\</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_name</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">SERVICE_ANY</span><span class="p">,</span> <span class="s1">''</span><span class="p">))</span> | |
2408 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2409 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">connectCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">path</span> <span class="o">=</span> <span class="n">service_name</span><span class="p">)</span> | |
2410 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2411 | <span class="k">else</span><span class="p">:</span> | |
2412 | <span class="n">sendDelete</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">])</span> | |
2413 | ||
2414 | <span class="k">def</span> <span class="nf">_resetFileAttributes_SMB1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path_file_pattern</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
2415 | <span class="k">raise</span> <span class="n">NotReadyError</span><span class="p">(</span><span class="s1">'resetFileAttributes is not yet implemented for SMB1'</span><span class="p">)</span> | |
2416 | ||
2417 | <span class="k">def</span> <span class="nf">_createDirectory_SMB1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
2418 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span><span class="p">:</span> | |
2419 | <span class="k">raise</span> <span class="n">NotReadyError</span><span class="p">(</span><span class="s1">'SMB connection not authenticated'</span><span class="p">)</span> | |
2420 | ||
2421 | <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">)</span> | |
2422 | <span class="n">messages_history</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> | |
2423 | ||
2424 | <span class="k">def</span> <span class="nf">sendCreate</span><span class="p">(</span><span class="n">tid</span><span class="p">):</span> | |
2425 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMBMessage</span><span class="p">(</span><span class="n">ComCreateDirectoryRequest</span><span class="p">(</span><span class="n">path</span><span class="p">))</span> | |
2426 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> | |
2427 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2428 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">createCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">)</span> | |
2429 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2430 | ||
2431 | <span class="k">def</span> <span class="nf">createCB</span><span class="p">(</span><span class="n">create_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |
2432 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">create_message</span><span class="p">)</span> | |
2433 | <span class="k">if</span> <span class="ow">not</span> <span class="n">create_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span> | |
2434 | <span class="n">callback</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> | |
2435 | <span class="k">else</span><span class="p">:</span> | |
2436 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to create directory </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Create failed'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2437 | ||
2438 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">service_name</span><span class="p">):</span> | |
2439 | <span class="k">def</span> <span class="nf">connectCB</span><span class="p">(</span><span class="n">connect_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |
2440 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">connect_message</span><span class="p">)</span> | |
2441 | <span class="k">if</span> <span class="ow">not</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span> | |
2442 | <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span> | |
2443 | <span class="n">sendCreate</span><span class="p">(</span><span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span><span class="p">)</span> | |
2444 | <span class="k">else</span><span class="p">:</span> | |
2445 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to create directory </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to connect to shared device'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2446 | ||
2447 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMBMessage</span><span class="p">(</span><span class="n">ComTreeConnectAndxRequest</span><span class="p">(</span><span class="s1">r'</span><span class="se">\\</span><span class="si">%s</span><span class="s1">\</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_name</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">SERVICE_ANY</span><span class="p">,</span> <span class="s1">''</span><span class="p">))</span> | |
2448 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2449 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">connectCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">path</span> <span class="o">=</span> <span class="n">service_name</span><span class="p">)</span> | |
2450 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2451 | <span class="k">else</span><span class="p">:</span> | |
2452 | <span class="n">sendCreate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">])</span> | |
2453 | ||
2454 | <span class="k">def</span> <span class="nf">_deleteDirectory_SMB1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service_name</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> | |
2455 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_authenticated</span><span class="p">:</span> | |
2456 | <span class="k">raise</span> <span class="n">NotReadyError</span><span class="p">(</span><span class="s1">'SMB connection not authenticated'</span><span class="p">)</span> | |
2457 | ||
2458 | <span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">)</span> | |
2459 | <span class="n">messages_history</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> | |
2460 | ||
2461 | <span class="k">def</span> <span class="nf">sendDelete</span><span class="p">(</span><span class="n">tid</span><span class="p">):</span> | |
2462 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMBMessage</span><span class="p">(</span><span class="n">ComDeleteDirectoryRequest</span><span class="p">(</span><span class="n">path</span><span class="p">))</span> | |
2463 | <span class="n">m</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="n">tid</span> | |
2464 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2465 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">deleteCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">)</span> | |
2466 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> | |
2467 | ||
2468 | <span class="k">def</span> <span class="nf">deleteCB</span><span class="p">(</span><span class="n">delete_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |
2469 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">delete_message</span><span class="p">)</span> | |
2470 | <span class="k">if</span> <span class="ow">not</span> <span class="n">delete_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span> | |
2471 | <span class="n">callback</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> | |
2472 | <span class="k">else</span><span class="p">:</span> | |
2473 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete directory </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Delete failed'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2474 | ||
2475 | <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">service_name</span><span class="p">):</span> | |
2476 | <span class="k">def</span> <span class="nf">connectCB</span><span class="p">(</span><span class="n">connect_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |
2477 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">connect_message</span><span class="p">)</span> | |
2478 | <span class="k">if</span> <span class="ow">not</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span> | |
2479 | <span class="bp">self</span><span class="o">.</span><span class="n">connected_trees</span><span class="p">[</span><span class="n">service_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span> | |
2480 | <span class="n">sendDelete</span><span class="p">(</span><span class="n">connect_message</span><span class="o">.</span><span class="n">tid</span><span class="p">)</span> | |
2481 | <span class="k">else</span><span class="p">:</span> | |
2482 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to connect to shared device'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2833 | <span class="n">errback</span><span class="p">(</span><span class="n">OperationFailure</span><span class="p">(</span><span class="s1">'Failed to delete directory </span><span class="si">%s</span><span class="s1"> on </span><span class="si">%s</span><span class="s1">: Unable to connect to shared device'</span> <span class="o">%</span> <span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">messages_history</span><span class="p">))</span> | |
2483 | 2834 | |
2484 | 2835 | <span class="n">m</span> <span class="o">=</span> <span class="n">SMBMessage</span><span class="p">(</span><span class="n">ComTreeConnectAndxRequest</span><span class="p">(</span><span class="s1">r'</span><span class="se">\\</span><span class="si">%s</span><span class="s1">\</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_name</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="n">service_name</span> <span class="p">),</span> <span class="n">SERVICE_ANY</span><span class="p">,</span> <span class="s1">''</span><span class="p">))</span> |
2485 | 2836 | <span class="bp">self</span><span class="o">.</span><span class="n">_sendSMBMessage</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
2614 | 2965 | <span class="k">def</span> <span class="nf">_echo_SMB1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">errback</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span> |
2615 | 2966 | <span class="n">messages_history</span> <span class="o">=</span> <span class="p">[</span> <span class="p">]</span> |
2616 | 2967 | |
2968 | <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="nb">type</span><span class="p">(</span><span class="n">b</span><span class="s1">''</span><span class="p">)):</span> | |
2969 | <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'Echo data must be </span><span class="si">%s</span><span class="s1"> not </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="n">b</span><span class="s1">''</span><span class="p">)</span><span class="o">.</span><span class="n">__name__</span><span class="p">,</span> <span class="nb">type</span><span class="p">(</span><span class="n">data</span><span class="p">)</span><span class="o">.</span><span class="n">__name__</span><span class="p">))</span> | |
2970 | ||
2617 | 2971 | <span class="k">def</span> <span class="nf">echoCB</span><span class="p">(</span><span class="n">echo_message</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
2618 | 2972 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">echo_message</span><span class="p">)</span> |
2619 | 2973 | <span class="k">if</span> <span class="ow">not</span> <span class="n">echo_message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span> |
2626 | 2980 | <span class="bp">self</span><span class="o">.</span><span class="n">pending_requests</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">]</span> <span class="o">=</span> <span class="n">_PendingRequest</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span> <span class="o">+</span> <span class="n">timeout</span><span class="p">,</span> <span class="n">echoCB</span><span class="p">,</span> <span class="n">errback</span><span class="p">)</span> |
2627 | 2981 | <span class="n">messages_history</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> |
2628 | 2982 | |
2983 | <span class="k">def</span> <span class="nf">_extractLastPathComponent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">):</span> | |
2984 | <span class="k">return</span> <span class="n">path</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'</span><span class="se">\\</span><span class="s1">'</span><span class="p">,</span> <span class="s1">'/'</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'/'</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> | |
2985 | ||
2629 | 2986 | |
2630 | 2987 | <div class="viewcode-block" id="SharedDevice"><a class="viewcode-back" href="../../api/smb_SharedDevice.html#smb.base.SharedDevice">[docs]</a><span class="k">class</span> <span class="nc">SharedDevice</span><span class="p">:</span> |
2631 | 2988 | <span class="sd">"""</span> |
2632 | 2989 | <span class="sd"> Contains information about a single shared device on the remote server.</span> |
2990 | ||
2991 | <span class="sd"> The following attributes are available:</span> | |
2992 | ||
2993 | <span class="sd"> * name : An unicode string containing the name of the shared device</span> | |
2994 | <span class="sd"> * comments : An unicode string containing the user description of the shared device</span> | |
2633 | 2995 | <span class="sd"> """</span> |
2634 | 2996 | |
2635 | 2997 | <span class="c1"># The following constants are taken from [MS-SRVS]: 2.2.2.4</span> |
2685 | 3047 | <span class="sd"> If you encounter *SharedFile* instance where its short_name attribute is empty but the filename attribute contains a short name which does not correspond</span> |
2686 | 3048 | <span class="sd"> to any files/folders on your remote shared device, it could be that the original filename on the file/folder entry on the shared device contains</span> |
2687 | 3049 | <span class="sd"> one of these prohibited characters: "\/[]:+|<>=;?,* (see [MS-CIFS]: 2.2.1.1.1 for more details).</span> |
3050 | ||
3051 | <span class="sd"> The following attributes are available:</span> | |
3052 | ||
3053 | <span class="sd"> * create_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of creation of this file resource on the remote server</span> | |
3054 | <span class="sd"> * last_access_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last access of this file resource on the remote server</span> | |
3055 | <span class="sd"> * last_write_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last modification of this file resource on the remote server</span> | |
3056 | <span class="sd"> * last_attr_change_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last attribute change of this file resource on the remote server</span> | |
3057 | <span class="sd"> * file_size : File size in number of bytes</span> | |
3058 | <span class="sd"> * alloc_size : Total number of bytes allocated to store this file</span> | |
3059 | <span class="sd"> * file_attributes : A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3. You can perform bit-wise tests to determine the status of the file using the ATTR_xxx constants in smb_constants.py.</span> | |
3060 | <span class="sd"> * short_name : Unicode string containing the short name of this file (usually in 8.3 notation)</span> | |
3061 | <span class="sd"> * filename : Unicode string containing the long filename of this file. Each OS has a limit to the length of this file name. On Windows, it is 256 characters.</span> | |
3062 | <span class="sd"> * file_id : Long value representing the file reference number for the file. If the remote system does not support this field, this field will be None or 0. See [MS-FSCC]: 2.4.17</span> | |
2688 | 3063 | <span class="sd"> """</span> |
2689 | 3064 | |
2690 | <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">create_time</span><span class="p">,</span> <span class="n">last_access_time</span><span class="p">,</span> <span class="n">last_write_time</span><span class="p">,</span> <span class="n">last_attr_change_time</span><span class="p">,</span> <span class="n">file_size</span><span class="p">,</span> <span class="n">alloc_size</span><span class="p">,</span> <span class="n">file_attributes</span><span class="p">,</span> <span class="n">short_name</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span> | |
3065 | <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">create_time</span><span class="p">,</span> <span class="n">last_access_time</span><span class="p">,</span> <span class="n">last_write_time</span><span class="p">,</span> <span class="n">last_attr_change_time</span><span class="p">,</span> <span class="n">file_size</span><span class="p">,</span> <span class="n">alloc_size</span><span class="p">,</span> <span class="n">file_attributes</span><span class="p">,</span> <span class="n">short_name</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">file_id</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span> | |
2691 | 3066 | <span class="bp">self</span><span class="o">.</span><span class="n">create_time</span> <span class="o">=</span> <span class="n">create_time</span> <span class="c1">#: Float value in number of seconds since 1970-01-01 00:00:00 to the time of creation of this file resource on the remote server</span> |
2692 | 3067 | <span class="bp">self</span><span class="o">.</span><span class="n">last_access_time</span> <span class="o">=</span> <span class="n">last_access_time</span> <span class="c1">#: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last access of this file resource on the remote server</span> |
2693 | 3068 | <span class="bp">self</span><span class="o">.</span><span class="n">last_write_time</span> <span class="o">=</span> <span class="n">last_write_time</span> <span class="c1">#: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last modification of this file resource on the remote server</span> |
2694 | 3069 | <span class="bp">self</span><span class="o">.</span><span class="n">last_attr_change_time</span> <span class="o">=</span> <span class="n">last_attr_change_time</span> <span class="c1">#: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last attribute change of this file resource on the remote server</span> |
2695 | 3070 | <span class="bp">self</span><span class="o">.</span><span class="n">file_size</span> <span class="o">=</span> <span class="n">file_size</span> <span class="c1">#: File size in number of bytes</span> |
2696 | 3071 | <span class="bp">self</span><span class="o">.</span><span class="n">alloc_size</span> <span class="o">=</span> <span class="n">alloc_size</span> <span class="c1">#: Total number of bytes allocated to store this file</span> |
2697 | <span class="bp">self</span><span class="o">.</span><span class="n">file_attributes</span> <span class="o">=</span> <span class="n">file_attributes</span> <span class="c1">#: A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3</span> | |
3072 | <span class="bp">self</span><span class="o">.</span><span class="n">file_attributes</span> <span class="o">=</span> <span class="n">file_attributes</span> <span class="c1">#: A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3. You can perform bit-wise tests to determine the status of the file using the ATTR_xxx constants in smb_constants.py.</span> | |
2698 | 3073 | <span class="bp">self</span><span class="o">.</span><span class="n">short_name</span> <span class="o">=</span> <span class="n">short_name</span> <span class="c1">#: Unicode string containing the short name of this file (usually in 8.3 notation)</span> |
2699 | 3074 | <span class="bp">self</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">filename</span> <span class="c1">#: Unicode string containing the long filename of this file. Each OS has a limit to the length of this file name. On Windows, it is 256 characters.</span> |
3075 | <span class="bp">self</span><span class="o">.</span><span class="n">file_id</span> <span class="o">=</span> <span class="n">file_id</span> <span class="c1">#: Long value representing the file reference number for the file. If the remote system does not support this field, this field will be None or 0. See [MS-FSCC]: 2.4.17</span> | |
2700 | 3076 | |
2701 | 3077 | <span class="nd">@property</span> |
2702 | 3078 | <span class="k">def</span> <span class="nf">isDirectory</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> |
2707 | 3083 | <span class="k">def</span> <span class="nf">isReadOnly</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> |
2708 | 3084 | <span class="sd">"""A convenient property to return True if this file resource is read-only on the remote server"""</span> |
2709 | 3085 | <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">file_attributes</span> <span class="o">&</span> <span class="n">ATTR_READONLY</span><span class="p">)</span> |
3086 | ||
3087 | <span class="nd">@property</span> | |
3088 | <span class="k">def</span> <span class="nf">isNormal</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |
3089 | <span class="sd">"""</span> | |
3090 | <span class="sd"> A convenient property to return True if this is a normal file.</span> | |
3091 | ||
3092 | <span class="sd"> Note that pysmb defines a normal file as a file entry that is not read-only, not hidden, not system, not archive and not a directory.</span> | |
3093 | <span class="sd"> It ignores other attributes like compression, indexed, sparse, temporary and encryption.</span> | |
3094 | <span class="sd"> """</span> | |
3095 | <span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">file_attributes</span><span class="o">==</span><span class="n">ATTR_NORMAL</span><span class="p">)</span> <span class="ow">or</span> <span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">file_attributes</span> <span class="o">&</span> <span class="mh">0xff</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span> | |
2710 | 3096 | |
2711 | 3097 | <span class="k">def</span> <span class="nf">__unicode__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> |
2712 | 3098 | <span class="k">return</span> <span class="s1">u'Shared file: </span><span class="si">%s</span><span class="s1"> (FileSize:</span><span class="si">%d</span><span class="s1"> bytes, isDirectory:</span><span class="si">%s</span><span class="s1">)'</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">file_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">isDirectory</span> <span class="p">)</span></div> |
2733 | 3119 | <li class="right" style="margin-right: 10px"> |
2734 | 3120 | <a href="../../genindex.html" title="General Index" |
2735 | 3121 | >index</a></li> |
2736 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.18 documentation</a> »</li> | |
3122 | <li class="right" > | |
3123 | <a href="../../py-modindex.html" title="Python Module Index" | |
3124 | >modules</a> |</li> | |
3125 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.2.1 documentation</a> »</li> | |
2737 | 3126 | <li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> »</li> |
2738 | 3127 | </ul> |
2739 | 3128 | </div> |
2740 | 3129 | <div class="footer" role="contentinfo"> |
2741 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
3130 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
2742 | 3131 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
2743 | 3132 | </div> |
2744 | 3133 | </body> |
0 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
1 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
2 | ||
3 | ||
4 | <html xmlns="http://www.w3.org/1999/xhtml"> | |
5 | <head> | |
6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
7 | ||
8 | <title>smb.security_descriptors — pysmb 1.2.1 documentation</title> | |
9 | ||
10 | <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" /> | |
11 | <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> | |
12 | ||
13 | <script type="text/javascript"> | |
14 | var DOCUMENTATION_OPTIONS = { | |
15 | URL_ROOT: '../../', | |
16 | VERSION: '1.2.1', | |
17 | COLLAPSE_INDEX: false, | |
18 | FILE_SUFFIX: '.html', | |
19 | HAS_SOURCE: true | |
20 | }; | |
21 | </script> | |
22 | <script type="text/javascript" src="../../_static/jquery.js"></script> | |
23 | <script type="text/javascript" src="../../_static/underscore.js"></script> | |
24 | <script type="text/javascript" src="../../_static/doctools.js"></script> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../../index.html" /> | |
26 | <link rel="up" title="Module code" href="../index.html" /> | |
27 | </head> | |
28 | <body role="document"> | |
29 | <div class="related" role="navigation" aria-label="related navigation"> | |
30 | <h3>Navigation</h3> | |
31 | <ul> | |
32 | <li class="right" style="margin-right: 10px"> | |
33 | <a href="../../genindex.html" title="General Index" | |
34 | accesskey="I">index</a></li> | |
35 | <li class="right" > | |
36 | <a href="../../py-modindex.html" title="Python Module Index" | |
37 | >modules</a> |</li> | |
38 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.2.1 documentation</a> »</li> | |
39 | <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> »</li> | |
40 | </ul> | |
41 | </div> | |
42 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> | |
43 | <div class="sphinxsidebarwrapper"> | |
44 | <div id="searchbox" style="display: none" role="search"> | |
45 | <h3>Quick search</h3> | |
46 | <form class="search" action="../../search.html" method="get"> | |
47 | <input type="text" name="q" /> | |
48 | <input type="submit" value="Go" /> | |
49 | <input type="hidden" name="check_keywords" value="yes" /> | |
50 | <input type="hidden" name="area" value="default" /> | |
51 | </form> | |
52 | <p class="searchtip" style="font-size: 90%"> | |
53 | Enter search terms or a module, class or function name. | |
54 | </p> | |
55 | </div> | |
56 | <script type="text/javascript">$('#searchbox').show(0);</script> | |
57 | </div> | |
58 | </div> | |
59 | ||
60 | <div class="document"> | |
61 | <div class="documentwrapper"> | |
62 | <div class="bodywrapper"> | |
63 | <div class="body" role="main"> | |
64 | ||
65 | <h1>Source code for smb.security_descriptors</h1><div class="highlight"><pre> | |
66 | <span class="sd">"""</span> | |
67 | <span class="sd">This module implements security descriptors, and the partial structures</span> | |
68 | <span class="sd">used in them, as specified in [MS-DTYP].</span> | |
69 | <span class="sd">"""</span> | |
70 | ||
71 | <span class="kn">import</span> <span class="nn">struct</span> | |
72 | ||
73 | ||
74 | <span class="c1"># Security descriptor control flags</span> | |
75 | <span class="c1"># [MS-DTYP]: 2.4.6</span> | |
76 | <span class="n">SECURITY_DESCRIPTOR_OWNER_DEFAULTED</span> <span class="o">=</span> <span class="mh">0x0001</span> | |
77 | <span class="n">SECURITY_DESCRIPTOR_GROUP_DEFAULTED</span> <span class="o">=</span> <span class="mh">0x0002</span> | |
78 | <span class="n">SECURITY_DESCRIPTOR_DACL_PRESENT</span> <span class="o">=</span> <span class="mh">0x0004</span> | |
79 | <span class="n">SECURITY_DESCRIPTOR_DACL_DEFAULTED</span> <span class="o">=</span> <span class="mh">0x0008</span> | |
80 | <span class="n">SECURITY_DESCRIPTOR_SACL_PRESENT</span> <span class="o">=</span> <span class="mh">0x0010</span> | |
81 | <span class="n">SECURITY_DESCRIPTOR_SACL_DEFAULTED</span> <span class="o">=</span> <span class="mh">0x0020</span> | |
82 | <span class="n">SECURITY_DESCRIPTOR_SERVER_SECURITY</span> <span class="o">=</span> <span class="mh">0x0040</span> | |
83 | <span class="n">SECURITY_DESCRIPTOR_DACL_TRUSTED</span> <span class="o">=</span> <span class="mh">0x0080</span> | |
84 | <span class="n">SECURITY_DESCRIPTOR_DACL_COMPUTED_INHERITANCE_REQUIRED</span> <span class="o">=</span> <span class="mh">0x0100</span> | |
85 | <span class="n">SECURITY_DESCRIPTOR_SACL_COMPUTED_INHERITANCE_REQUIRED</span> <span class="o">=</span> <span class="mh">0x0200</span> | |
86 | <span class="n">SECURITY_DESCRIPTOR_DACL_AUTO_INHERITED</span> <span class="o">=</span> <span class="mh">0x0400</span> | |
87 | <span class="n">SECURITY_DESCRIPTOR_SACL_AUTO_INHERITED</span> <span class="o">=</span> <span class="mh">0x0800</span> | |
88 | <span class="n">SECURITY_DESCRIPTOR_DACL_PROTECTED</span> <span class="o">=</span> <span class="mh">0x1000</span> | |
89 | <span class="n">SECURITY_DESCRIPTOR_SACL_PROTECTED</span> <span class="o">=</span> <span class="mh">0x2000</span> | |
90 | <span class="n">SECURITY_DESCRIPTOR_RM_CONTROL_VALID</span> <span class="o">=</span> <span class="mh">0x4000</span> | |
91 | <span class="n">SECURITY_DESCRIPTOR_SELF_RELATIVE</span> <span class="o">=</span> <span class="mh">0x8000</span> | |
92 | ||
93 | <span class="c1"># ACE types</span> | |
94 | <span class="c1"># [MS-DTYP]: 2.4.4.1</span> | |
95 | <span class="n">ACE_TYPE_ACCESS_ALLOWED</span> <span class="o">=</span> <span class="mh">0x00</span> | |
96 | <span class="n">ACE_TYPE_ACCESS_DENIED</span> <span class="o">=</span> <span class="mh">0x01</span> | |
97 | <span class="n">ACE_TYPE_SYSTEM_AUDIT</span> <span class="o">=</span> <span class="mh">0x02</span> | |
98 | <span class="n">ACE_TYPE_SYSTEM_ALARM</span> <span class="o">=</span> <span class="mh">0x03</span> | |
99 | <span class="n">ACE_TYPE_ACCESS_ALLOWED_COMPOUND</span> <span class="o">=</span> <span class="mh">0x04</span> | |
100 | <span class="n">ACE_TYPE_ACCESS_ALLOWED_OBJECT</span> <span class="o">=</span> <span class="mh">0x05</span> | |
101 | <span class="n">ACE_TYPE_ACCESS_DENIED_OBJECT</span> <span class="o">=</span> <span class="mh">0x06</span> | |
102 | <span class="n">ACE_TYPE_SYSTEM_AUDIT_OBJECT</span> <span class="o">=</span> <span class="mh">0x07</span> | |
103 | <span class="n">ACE_TYPE_SYSTEM_ALARM_OBJECT</span> <span class="o">=</span> <span class="mh">0x08</span> | |
104 | <span class="n">ACE_TYPE_ACCESS_ALLOWED_CALLBACK</span> <span class="o">=</span> <span class="mh">0x09</span> | |
105 | <span class="n">ACE_TYPE_ACCESS_DENIED_CALLBACK</span> <span class="o">=</span> <span class="mh">0x0A</span> | |
106 | <span class="n">ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT</span> <span class="o">=</span> <span class="mh">0x0B</span> | |
107 | <span class="n">ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT</span> <span class="o">=</span> <span class="mh">0x0C</span> | |
108 | <span class="n">ACE_TYPE_SYSTEM_AUDIT_CALLBACK</span> <span class="o">=</span> <span class="mh">0x0D</span> | |
109 | <span class="n">ACE_TYPE_SYSTEM_ALARM_CALLBACK</span> <span class="o">=</span> <span class="mh">0x0E</span> | |
110 | <span class="n">ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT</span> <span class="o">=</span> <span class="mh">0x0F</span> | |
111 | <span class="n">ACE_TYPE_SYSTEM_ALARM_CALLBACK_OBJECT</span> <span class="o">=</span> <span class="mh">0x10</span> | |
112 | <span class="n">ACE_TYPE_SYSTEM_MANDATORY_LABEL</span> <span class="o">=</span> <span class="mh">0x11</span> | |
113 | <span class="n">ACE_TYPE_SYSTEM_RESOURCE_ATTRIBUTE</span> <span class="o">=</span> <span class="mh">0x12</span> | |
114 | <span class="n">ACE_TYPE_SYSTEM_SCOPED_POLICY_ID</span> <span class="o">=</span> <span class="mh">0x13</span> | |
115 | ||
116 | <span class="c1"># ACE flags</span> | |
117 | <span class="c1"># [MS-DTYP]: 2.4.4.1</span> | |
118 | <span class="n">ACE_FLAG_OBJECT_INHERIT</span> <span class="o">=</span> <span class="mh">0x01</span> | |
119 | <span class="n">ACE_FLAG_CONTAINER_INHERIT</span> <span class="o">=</span> <span class="mh">0x02</span> | |
120 | <span class="n">ACE_FLAG_NO_PROPAGATE_INHERIT</span> <span class="o">=</span> <span class="mh">0x04</span> | |
121 | <span class="n">ACE_FLAG_INHERIT_ONLY</span> <span class="o">=</span> <span class="mh">0x08</span> | |
122 | <span class="n">ACE_FLAG_INHERITED</span> <span class="o">=</span> <span class="mh">0x10</span> | |
123 | <span class="n">ACE_FLAG_SUCCESSFUL_ACCESS</span> <span class="o">=</span> <span class="mh">0x40</span> | |
124 | <span class="n">ACE_FLAG_FAILED_ACCESS</span> <span class="o">=</span> <span class="mh">0x80</span> | |
125 | ||
126 | <span class="c1"># Pre-defined well-known SIDs</span> | |
127 | <span class="c1"># [MS-DTYP]: 2.4.2.4</span> | |
128 | <span class="n">SID_NULL</span> <span class="o">=</span> <span class="s2">"S-1-0-0"</span> | |
129 | <span class="n">SID_EVERYONE</span> <span class="o">=</span> <span class="s2">"S-1-1-0"</span> | |
130 | <span class="n">SID_LOCAL</span> <span class="o">=</span> <span class="s2">"S-1-2-0"</span> | |
131 | <span class="n">SID_CONSOLE_LOGON</span> <span class="o">=</span> <span class="s2">"S-1-2-1"</span> | |
132 | <span class="n">SID_CREATOR_OWNER</span> <span class="o">=</span> <span class="s2">"S-1-3-0"</span> | |
133 | <span class="n">SID_CREATOR_GROUP</span> <span class="o">=</span> <span class="s2">"S-1-3-1"</span> | |
134 | <span class="n">SID_OWNER_SERVER</span> <span class="o">=</span> <span class="s2">"S-1-3-2"</span> | |
135 | <span class="n">SID_GROUP_SERVER</span> <span class="o">=</span> <span class="s2">"S-1-3-3"</span> | |
136 | <span class="n">SID_OWNER_RIGHTS</span> <span class="o">=</span> <span class="s2">"S-1-3-4"</span> | |
137 | <span class="n">SID_NT_AUTHORITY</span> <span class="o">=</span> <span class="s2">"S-1-5"</span> | |
138 | <span class="n">SID_DIALUP</span> <span class="o">=</span> <span class="s2">"S-1-5-1"</span> | |
139 | <span class="n">SID_NETWORK</span> <span class="o">=</span> <span class="s2">"S-1-5-2"</span> | |
140 | <span class="n">SID_BATCH</span> <span class="o">=</span> <span class="s2">"S-1-5-3"</span> | |
141 | <span class="n">SID_INTERACTIVE</span> <span class="o">=</span> <span class="s2">"S-1-5-4"</span> | |
142 | <span class="n">SID_SERVICE</span> <span class="o">=</span> <span class="s2">"S-1-5-6"</span> | |
143 | <span class="n">SID_ANONYMOUS</span> <span class="o">=</span> <span class="s2">"S-1-5-7"</span> | |
144 | <span class="n">SID_PROXY</span> <span class="o">=</span> <span class="s2">"S-1-5-8"</span> | |
145 | <span class="n">SID_ENTERPRISE_DOMAIN_CONTROLLERS</span> <span class="o">=</span> <span class="s2">"S-1-5-9"</span> | |
146 | <span class="n">SID_PRINCIPAL_SELF</span> <span class="o">=</span> <span class="s2">"S-1-5-10"</span> | |
147 | <span class="n">SID_AUTHENTICATED_USERS</span> <span class="o">=</span> <span class="s2">"S-1-5-11"</span> | |
148 | <span class="n">SID_RESTRICTED_CODE</span> <span class="o">=</span> <span class="s2">"S-1-5-12"</span> | |
149 | <span class="n">SID_TERMINAL_SERVER_USER</span> <span class="o">=</span> <span class="s2">"S-1-5-13"</span> | |
150 | <span class="n">SID_REMOTE_INTERACTIVE_LOGON</span> <span class="o">=</span> <span class="s2">"S-1-5-14"</span> | |
151 | <span class="n">SID_THIS_ORGANIZATION</span> <span class="o">=</span> <span class="s2">"S-1-5-15"</span> | |
152 | <span class="n">SID_IUSR</span> <span class="o">=</span> <span class="s2">"S-1-5-17"</span> | |
153 | <span class="n">SID_LOCAL_SYSTEM</span> <span class="o">=</span> <span class="s2">"S-1-5-18"</span> | |
154 | <span class="n">SID_LOCAL_SERVICE</span> <span class="o">=</span> <span class="s2">"S-1-5-19"</span> | |
155 | <span class="n">SID_NETWORK_SERVICE</span> <span class="o">=</span> <span class="s2">"S-1-5-20"</span> | |
156 | <span class="n">SID_COMPOUNDED_AUTHENTICATION</span> <span class="o">=</span> <span class="s2">"S-1-5-21-0-0-0-496"</span> | |
157 | <span class="n">SID_CLAIMS_VALID</span> <span class="o">=</span> <span class="s2">"S-1-5-21-0-0-0-497"</span> | |
158 | <span class="n">SID_BUILTIN_ADMINISTRATORS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-544"</span> | |
159 | <span class="n">SID_BUILTIN_USERS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-545"</span> | |
160 | <span class="n">SID_BUILTIN_GUESTS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-546"</span> | |
161 | <span class="n">SID_POWER_USERS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-547"</span> | |
162 | <span class="n">SID_ACCOUNT_OPERATORS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-548"</span> | |
163 | <span class="n">SID_SERVER_OPERATORS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-549"</span> | |
164 | <span class="n">SID_PRINTER_OPERATORS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-550"</span> | |
165 | <span class="n">SID_BACKUP_OPERATORS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-551"</span> | |
166 | <span class="n">SID_REPLICATOR</span> <span class="o">=</span> <span class="s2">"S-1-5-32-552"</span> | |
167 | <span class="n">SID_ALIAS_PREW2KCOMPACC</span> <span class="o">=</span> <span class="s2">"S-1-5-32-554"</span> | |
168 | <span class="n">SID_REMOTE_DESKTOP</span> <span class="o">=</span> <span class="s2">"S-1-5-32-555"</span> | |
169 | <span class="n">SID_NETWORK_CONFIGURATION_OPS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-556"</span> | |
170 | <span class="n">SID_INCOMING_FOREST_TRUST_BUILDERS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-557"</span> | |
171 | <span class="n">SID_PERFMON_USERS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-558"</span> | |
172 | <span class="n">SID_PERFLOG_USERS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-559"</span> | |
173 | <span class="n">SID_WINDOWS_AUTHORIZATION_ACCESS_GROUP</span> <span class="o">=</span> <span class="s2">"S-1-5-32-560"</span> | |
174 | <span class="n">SID_TERMINAL_SERVER_LICENSE_SERVERS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-561"</span> | |
175 | <span class="n">SID_DISTRIBUTED_COM_USERS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-562"</span> | |
176 | <span class="n">SID_IIS_IUSRS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-568"</span> | |
177 | <span class="n">SID_CRYPTOGRAPHIC_OPERATORS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-569"</span> | |
178 | <span class="n">SID_EVENT_LOG_READERS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-573"</span> | |
179 | <span class="n">SID_CERTIFICATE_SERVICE_DCOM_ACCESS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-574"</span> | |
180 | <span class="n">SID_RDS_REMOTE_ACCESS_SERVERS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-575"</span> | |
181 | <span class="n">SID_RDS_ENDPOINT_SERVERS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-576"</span> | |
182 | <span class="n">SID_RDS_MANAGEMENT_SERVERS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-577"</span> | |
183 | <span class="n">SID_HYPER_V_ADMINS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-578"</span> | |
184 | <span class="n">SID_ACCESS_CONTROL_ASSISTANCE_OPS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-579"</span> | |
185 | <span class="n">SID_REMOTE_MANAGEMENT_USERS</span> <span class="o">=</span> <span class="s2">"S-1-5-32-580"</span> | |
186 | <span class="n">SID_WRITE_RESTRICTED_CODE</span> <span class="o">=</span> <span class="s2">"S-1-5-33"</span> | |
187 | <span class="n">SID_NTLM_AUTHENTICATION</span> <span class="o">=</span> <span class="s2">"S-1-5-64-10"</span> | |
188 | <span class="n">SID_SCHANNEL_AUTHENTICATION</span> <span class="o">=</span> <span class="s2">"S-1-5-64-14"</span> | |
189 | <span class="n">SID_DIGEST_AUTHENTICATION</span> <span class="o">=</span> <span class="s2">"S-1-5-64-21"</span> | |
190 | <span class="n">SID_THIS_ORGANIZATION_CERTIFICATE</span> <span class="o">=</span> <span class="s2">"S-1-5-65-1"</span> | |
191 | <span class="n">SID_NT_SERVICE</span> <span class="o">=</span> <span class="s2">"S-1-5-80"</span> | |
192 | <span class="n">SID_USER_MODE_DRIVERS</span> <span class="o">=</span> <span class="s2">"S-1-5-84-0-0-0-0-0"</span> | |
193 | <span class="n">SID_LOCAL_ACCOUNT</span> <span class="o">=</span> <span class="s2">"S-1-5-113"</span> | |
194 | <span class="n">SID_LOCAL_ACCOUNT_AND_MEMBER_OF_ADMINISTRATORS_GROUP</span> <span class="o">=</span> <span class="s2">"S-1-5-114"</span> | |
195 | <span class="n">SID_OTHER_ORGANIZATION</span> <span class="o">=</span> <span class="s2">"S-1-5-1000"</span> | |
196 | <span class="n">SID_ALL_APP_PACKAGES</span> <span class="o">=</span> <span class="s2">"S-1-15-2-1"</span> | |
197 | <span class="n">SID_ML_UNTRUSTED</span> <span class="o">=</span> <span class="s2">"S-1-16-0"</span> | |
198 | <span class="n">SID_ML_LOW</span> <span class="o">=</span> <span class="s2">"S-1-16-4096"</span> | |
199 | <span class="n">SID_ML_MEDIUM</span> <span class="o">=</span> <span class="s2">"S-1-16-8192"</span> | |
200 | <span class="n">SID_ML_MEDIUM_PLUS</span> <span class="o">=</span> <span class="s2">"S-1-16-8448"</span> | |
201 | <span class="n">SID_ML_HIGH</span> <span class="o">=</span> <span class="s2">"S-1-16-12288"</span> | |
202 | <span class="n">SID_ML_SYSTEM</span> <span class="o">=</span> <span class="s2">"S-1-16-16384"</span> | |
203 | <span class="n">SID_ML_PROTECTED_PROCESS</span> <span class="o">=</span> <span class="s2">"S-1-16-20480"</span> | |
204 | <span class="n">SID_AUTHENTICATION_AUTHORITY_ASSERTED_IDENTITY</span> <span class="o">=</span> <span class="s2">"S-1-18-1"</span> | |
205 | <span class="n">SID_SERVICE_ASSERTED_IDENTITY</span> <span class="o">=</span> <span class="s2">"S-1-18-2"</span> | |
206 | <span class="n">SID_FRESH_PUBLIC_KEY_IDENTITY</span> <span class="o">=</span> <span class="s2">"S-1-18-3"</span> | |
207 | <span class="n">SID_KEY_TRUST_IDENTITY</span> <span class="o">=</span> <span class="s2">"S-1-18-4"</span> | |
208 | <span class="n">SID_KEY_PROPERTY_MFA</span> <span class="o">=</span> <span class="s2">"S-1-18-5"</span> | |
209 | <span class="n">SID_KEY_PROPERTY_ATTESTATION</span> <span class="o">=</span> <span class="s2">"S-1-18-6"</span> | |
210 | ||
211 | ||
212 | <div class="viewcode-block" id="SID"><a class="viewcode-back" href="../../api/smb_security_descriptors.html#smb.security_descriptors.SID">[docs]</a><span class="k">class</span> <span class="nc">SID</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> | |
213 | <span class="sd">"""</span> | |
214 | <span class="sd"> A Windows security identifier. Represents a single principal, such a</span> | |
215 | <span class="sd"> user or a group, as a sequence of numbers consisting of the revision,</span> | |
216 | <span class="sd"> identifier authority, and a variable-length list of subauthorities.</span> | |
217 | ||
218 | <span class="sd"> See [MS-DTYP]: 2.4.2</span> | |
219 | <span class="sd"> """</span> | |
220 | <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">revision</span><span class="p">,</span> <span class="n">identifier_authority</span><span class="p">,</span> <span class="n">subauthorities</span><span class="p">):</span> | |
221 | <span class="c1">#: Revision, should always be 1.</span> | |
222 | <span class="bp">self</span><span class="o">.</span><span class="n">revision</span> <span class="o">=</span> <span class="n">revision</span> | |
223 | <span class="c1">#: An integer representing the identifier authority.</span> | |
224 | <span class="bp">self</span><span class="o">.</span><span class="n">identifier_authority</span> <span class="o">=</span> <span class="n">identifier_authority</span> | |
225 | <span class="c1">#: A list of integers representing all subauthorities.</span> | |
226 | <span class="bp">self</span><span class="o">.</span><span class="n">subauthorities</span> <span class="o">=</span> <span class="n">subauthorities</span> | |
227 | ||
228 | <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |
229 | <span class="sd">"""</span> | |
230 | <span class="sd"> String representation, as specified in [MS-DTYP]: 2.4.2.1</span> | |
231 | <span class="sd"> """</span> | |
232 | <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">identifier_authority</span> <span class="o">>=</span> <span class="mi">2</span><span class="o">**</span><span class="mi">32</span><span class="p">:</span> | |
233 | <span class="n">id_auth</span> <span class="o">=</span> <span class="s1">'</span><span class="si">%#x</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">identifier_authority</span><span class="p">,)</span> | |
234 | <span class="k">else</span><span class="p">:</span> | |
235 | <span class="n">id_auth</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">identifier_authority</span> | |
236 | <span class="n">auths</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">revision</span><span class="p">,</span> <span class="n">id_auth</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">subauthorities</span> | |
237 | <span class="k">return</span> <span class="s1">'S-'</span> <span class="o">+</span> <span class="s1">'-'</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">subauth</span><span class="p">)</span> <span class="k">for</span> <span class="n">subauth</span> <span class="ow">in</span> <span class="n">auths</span><span class="p">)</span> | |
238 | ||
239 | <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |
240 | <span class="k">return</span> <span class="s1">'SID(</span><span class="si">%r</span><span class="s1">)'</span> <span class="o">%</span> <span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="p">),)</span> | |
241 | ||
242 | <span class="nd">@classmethod</span> | |
243 | <span class="k">def</span> <span class="nf">from_bytes</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">return_tail</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span> | |
244 | <span class="n">revision</span><span class="p">,</span> <span class="n">subauth_count</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">'<BB'</span><span class="p">,</span> <span class="n">data</span><span class="p">[:</span><span class="mi">2</span><span class="p">])</span> | |
245 | <span class="n">identifier_authority</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">'>Q'</span><span class="p">,</span> <span class="s1">'</span><span class="se">\x00\x00</span><span class="s1">'</span> <span class="o">+</span> <span class="n">data</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">8</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span> | |
246 | <span class="n">subauth_data</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="mi">8</span><span class="p">:]</span> | |
247 | <span class="n">subauthorities</span> <span class="o">=</span> <span class="p">[</span><span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">'<L'</span><span class="p">,</span> <span class="n">subauth_data</span><span class="p">[</span><span class="mi">4</span> <span class="o">*</span> <span class="n">i</span> <span class="p">:</span> <span class="mi">4</span> <span class="o">*</span> <span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">)])[</span><span class="mi">0</span><span class="p">]</span> | |
248 | <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">subauth_count</span><span class="p">)]</span> | |
249 | <span class="n">sid</span> <span class="o">=</span> <span class="n">cls</span><span class="p">(</span><span class="n">revision</span><span class="p">,</span> <span class="n">identifier_authority</span><span class="p">,</span> <span class="n">subauthorities</span><span class="p">)</span> | |
250 | <span class="k">if</span> <span class="n">return_tail</span><span class="p">:</span> | |
251 | <span class="k">return</span> <span class="n">sid</span><span class="p">,</span> <span class="n">subauth_data</span><span class="p">[</span><span class="mi">4</span> <span class="o">*</span> <span class="n">subauth_count</span> <span class="p">:]</span> | |
252 | <span class="k">return</span> <span class="n">sid</span></div> | |
253 | ||
254 | ||
255 | <div class="viewcode-block" id="ACE"><a class="viewcode-back" href="../../api/smb_security_descriptors.html#smb.security_descriptors.ACE">[docs]</a><span class="k">class</span> <span class="nc">ACE</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> | |
256 | <span class="sd">"""</span> | |
257 | <span class="sd"> Represents a single access control entry.</span> | |
258 | ||
259 | <span class="sd"> See [MS-DTYP]: 2.4.4</span> | |
260 | <span class="sd"> """</span> | |
261 | <span class="n">HEADER_FORMAT</span> <span class="o">=</span> <span class="s1">'<BBH'</span> | |
262 | ||
263 | <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">type_</span><span class="p">,</span> <span class="n">flags</span><span class="p">,</span> <span class="n">mask</span><span class="p">,</span> <span class="n">sid</span><span class="p">,</span> <span class="n">additional_data</span><span class="p">):</span> | |
264 | <span class="c1">#: An integer representing the type of the ACE. One of the</span> | |
265 | <span class="c1">#: ``ACE_TYPE_*`` constants. Corresponds to the ``AceType`` field</span> | |
266 | <span class="c1">#: from [MS-DTYP] 2.4.4.1.</span> | |
267 | <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">type_</span> | |
268 | <span class="c1">#: An integer bitmask with ACE flags, corresponds to the</span> | |
269 | <span class="c1">#: ``AceFlags`` field.</span> | |
270 | <span class="bp">self</span><span class="o">.</span><span class="n">flags</span> <span class="o">=</span> <span class="n">flags</span> | |
271 | <span class="c1">#: An integer representing the ``ACCESS_MASK`` as specified in</span> | |
272 | <span class="c1">#: [MS-DTYP] 2.4.3.</span> | |
273 | <span class="bp">self</span><span class="o">.</span><span class="n">mask</span> <span class="o">=</span> <span class="n">mask</span> | |
274 | <span class="c1">#: The :class:`SID` of a trustee.</span> | |
275 | <span class="bp">self</span><span class="o">.</span><span class="n">sid</span> <span class="o">=</span> <span class="n">sid</span> | |
276 | <span class="c1">#: A dictionary of additional fields present in the ACE, depending</span> | |
277 | <span class="c1">#: on the type. The following fields can be present:</span> | |
278 | <span class="c1">#:</span> | |
279 | <span class="c1">#: * ``flags``</span> | |
280 | <span class="c1">#: * ``object_type``</span> | |
281 | <span class="c1">#: * ``inherited_object_type``</span> | |
282 | <span class="c1">#: * ``application_data``</span> | |
283 | <span class="c1">#: * ``attribute_data``</span> | |
284 | <span class="bp">self</span><span class="o">.</span><span class="n">additional_data</span> <span class="o">=</span> <span class="n">additional_data</span> | |
285 | ||
286 | <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |
287 | <span class="k">return</span> <span class="s2">"ACE(type=</span><span class="si">%#04x</span><span class="s2">, flags=</span><span class="si">%#04x</span><span class="s2">, mask=</span><span class="si">%#010x</span><span class="s2">, sid=</span><span class="si">%s</span><span class="s2">)"</span> <span class="o">%</span> <span class="p">(</span> | |
288 | <span class="bp">self</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mask</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sid</span><span class="p">,</span> | |
289 | <span class="p">)</span> | |
290 | ||
291 | <span class="nd">@property</span> | |
292 | <span class="k">def</span> <span class="nf">isInheritOnly</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |
293 | <span class="sd">"""Convenience property which indicates if this ACE is inherit</span> | |
294 | <span class="sd"> only, meaning that it doesn't apply to the object itself."""</span> | |
295 | <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span> <span class="o">&</span> <span class="n">ACE_FLAG_INHERIT_ONLY</span><span class="p">)</span> | |
296 | ||
297 | <span class="nd">@classmethod</span> | |
298 | <span class="k">def</span> <span class="nf">from_bytes</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span> | |
299 | <span class="n">header_size</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">HEADER_FORMAT</span><span class="p">)</span> | |
300 | <span class="n">header</span> <span class="o">=</span> <span class="n">data</span><span class="p">[:</span><span class="n">header_size</span><span class="p">]</span> | |
301 | <span class="n">type_</span><span class="p">,</span> <span class="n">flags</span><span class="p">,</span> <span class="n">size</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">HEADER_FORMAT</span><span class="p">,</span> <span class="n">header</span><span class="p">)</span> | |
302 | ||
303 | <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">>=</span> <span class="n">size</span> | |
304 | ||
305 | <span class="n">body</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">header_size</span><span class="p">:</span><span class="n">size</span><span class="p">]</span> | |
306 | <span class="n">additional_data</span> <span class="o">=</span> <span class="p">{}</span> | |
307 | ||
308 | <span class="c1"># In all ACE types, the mask immediately follows the header.</span> | |
309 | <span class="n">mask</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">'<I'</span><span class="p">,</span> <span class="n">body</span><span class="p">[:</span><span class="mi">4</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span> | |
310 | <span class="n">body</span> <span class="o">=</span> <span class="n">body</span><span class="p">[</span><span class="mi">4</span><span class="p">:]</span> | |
311 | ||
312 | <span class="c1"># All OBJECT-type ACEs contain additional flags, and two GUIDs as</span> | |
313 | <span class="c1"># the following fields.</span> | |
314 | <span class="k">if</span> <span class="n">type_</span> <span class="ow">in</span> <span class="p">(</span><span class="n">ACE_TYPE_ACCESS_ALLOWED_OBJECT</span><span class="p">,</span> | |
315 | <span class="n">ACE_TYPE_ACCESS_DENIED_OBJECT</span><span class="p">,</span> | |
316 | <span class="n">ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT</span><span class="p">,</span> | |
317 | <span class="n">ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT</span><span class="p">,</span> | |
318 | <span class="n">ACE_TYPE_SYSTEM_AUDIT_OBJECT</span><span class="p">,</span> | |
319 | <span class="n">ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT</span><span class="p">):</span> | |
320 | <span class="n">additional_data</span><span class="p">[</span><span class="s1">'flags'</span><span class="p">]</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">'<I'</span><span class="p">,</span> <span class="n">body</span><span class="p">[:</span><span class="mi">4</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span> | |
321 | <span class="n">additional_data</span><span class="p">[</span><span class="s1">'object_type'</span><span class="p">]</span> <span class="o">=</span> <span class="n">body</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">20</span><span class="p">]</span> | |
322 | <span class="n">additional_data</span><span class="p">[</span><span class="s1">'inherited_object_type'</span><span class="p">]</span> <span class="o">=</span> <span class="n">body</span><span class="p">[</span><span class="mi">20</span><span class="p">:</span><span class="mi">36</span><span class="p">]</span> | |
323 | <span class="n">body</span> <span class="o">=</span> <span class="n">body</span><span class="p">[</span><span class="mi">36</span><span class="p">:]</span> | |
324 | ||
325 | <span class="c1"># Then the SID in all types.</span> | |
326 | <span class="n">sid</span><span class="p">,</span> <span class="n">body</span> <span class="o">=</span> <span class="n">SID</span><span class="o">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="n">return_tail</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> | |
327 | ||
328 | <span class="c1"># CALLBACK-type ACEs (and for some obscure reason,</span> | |
329 | <span class="c1"># SYSTEM_AUDIT_OBJECT) have a final tail of application data.</span> | |
330 | <span class="k">if</span> <span class="n">type_</span> <span class="ow">in</span> <span class="p">(</span><span class="n">ACE_TYPE_ACCESS_ALLOWED_CALLBACK</span><span class="p">,</span> | |
331 | <span class="n">ACE_TYPE_ACCESS_DENIED_CALLBACK</span><span class="p">,</span> | |
332 | <span class="n">ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT</span><span class="p">,</span> | |
333 | <span class="n">ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT</span><span class="p">,</span> | |
334 | <span class="n">ACE_TYPE_SYSTEM_AUDIT_OBJECT</span><span class="p">,</span> | |
335 | <span class="n">ACE_TYPE_SYSTEM_AUDIT_CALLBACK</span><span class="p">,</span> | |
336 | <span class="n">ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT</span><span class="p">):</span> | |
337 | <span class="n">additional_data</span><span class="p">[</span><span class="s1">'application_data'</span><span class="p">]</span> <span class="o">=</span> <span class="n">body</span> | |
338 | ||
339 | <span class="c1"># SYSTEM_RESOURCE_ATTRIBUTE ACEs have a tail of attribute data.</span> | |
340 | <span class="k">if</span> <span class="n">type_</span> <span class="o">==</span> <span class="n">ACE_TYPE_SYSTEM_RESOURCE_ATTRIBUTE</span><span class="p">:</span> | |
341 | <span class="n">additional_data</span><span class="p">[</span><span class="s1">'attribute_data'</span><span class="p">]</span> <span class="o">=</span> <span class="n">body</span> | |
342 | ||
343 | <span class="k">return</span> <span class="n">cls</span><span class="p">(</span><span class="n">type_</span><span class="p">,</span> <span class="n">flags</span><span class="p">,</span> <span class="n">mask</span><span class="p">,</span> <span class="n">sid</span><span class="p">,</span> <span class="n">additional_data</span><span class="p">)</span></div> | |
344 | ||
345 | ||
346 | <div class="viewcode-block" id="ACL"><a class="viewcode-back" href="../../api/smb_security_descriptors.html#smb.security_descriptors.ACL">[docs]</a><span class="k">class</span> <span class="nc">ACL</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> | |
347 | <span class="sd">"""</span> | |
348 | <span class="sd"> Access control list, encapsulating a sequence of access control</span> | |
349 | <span class="sd"> entries.</span> | |
350 | ||
351 | <span class="sd"> See [MS-DTYP]: 2.4.5</span> | |
352 | <span class="sd"> """</span> | |
353 | <span class="n">HEADER_FORMAT</span> <span class="o">=</span> <span class="s1">'<BBHHH'</span> | |
354 | ||
355 | <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">revision</span><span class="p">,</span> <span class="n">aces</span><span class="p">):</span> | |
356 | <span class="c1">#: Integer value of the revision.</span> | |
357 | <span class="bp">self</span><span class="o">.</span><span class="n">revision</span> <span class="o">=</span> <span class="n">revision</span> | |
358 | <span class="c1">#: List of :class:`ACE` instances.</span> | |
359 | <span class="bp">self</span><span class="o">.</span><span class="n">aces</span> <span class="o">=</span> <span class="n">aces</span> | |
360 | ||
361 | <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |
362 | <span class="k">return</span> <span class="s2">"ACL(</span><span class="si">%r</span><span class="s2">)"</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">aces</span><span class="p">,)</span> | |
363 | ||
364 | <span class="nd">@classmethod</span> | |
365 | <span class="k">def</span> <span class="nf">from_bytes</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span> | |
366 | <span class="n">revision</span> <span class="o">=</span> <span class="bp">None</span> | |
367 | <span class="n">aces</span> <span class="o">=</span> <span class="p">[]</span> | |
368 | ||
369 | <span class="n">header_size</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">HEADER_FORMAT</span><span class="p">)</span> | |
370 | <span class="n">header</span><span class="p">,</span> <span class="n">remaining</span> <span class="o">=</span> <span class="n">data</span><span class="p">[:</span><span class="n">header_size</span><span class="p">],</span> <span class="n">data</span><span class="p">[</span><span class="n">header_size</span><span class="p">:]</span> | |
371 | <span class="n">revision</span><span class="p">,</span> <span class="n">sbz1</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="n">sbz2</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">HEADER_FORMAT</span><span class="p">,</span> <span class="n">header</span><span class="p">)</span> | |
372 | ||
373 | <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">>=</span> <span class="n">size</span> | |
374 | ||
375 | <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">count</span><span class="p">):</span> | |
376 | <span class="n">ace_size</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">'<H'</span><span class="p">,</span> <span class="n">remaining</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">4</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span> | |
377 | <span class="n">ace_data</span><span class="p">,</span> <span class="n">remaining</span> <span class="o">=</span> <span class="n">remaining</span><span class="p">[:</span><span class="n">ace_size</span><span class="p">],</span> <span class="n">remaining</span><span class="p">[</span><span class="n">ace_size</span><span class="p">:]</span> | |
378 | <span class="n">aces</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ACE</span><span class="o">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">ace_data</span><span class="p">))</span> | |
379 | ||
380 | <span class="k">return</span> <span class="n">cls</span><span class="p">(</span><span class="n">revision</span><span class="p">,</span> <span class="n">aces</span><span class="p">)</span></div> | |
381 | ||
382 | ||
383 | <div class="viewcode-block" id="SecurityDescriptor"><a class="viewcode-back" href="../../api/smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor">[docs]</a><span class="k">class</span> <span class="nc">SecurityDescriptor</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> | |
384 | <span class="sd">"""</span> | |
385 | <span class="sd"> Represents a security descriptor.</span> | |
386 | ||
387 | <span class="sd"> See [MS-DTYP]: 2.4.6</span> | |
388 | <span class="sd"> """</span> | |
389 | ||
390 | <span class="n">HEADER_FORMAT</span> <span class="o">=</span> <span class="s1">'<BBHIIII'</span> | |
391 | ||
392 | <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flags</span><span class="p">,</span> <span class="n">owner</span><span class="p">,</span> <span class="n">group</span><span class="p">,</span> <span class="n">dacl</span><span class="p">,</span> <span class="n">sacl</span><span class="p">):</span> | |
393 | <span class="c1">#: Integer bitmask of control flags. Corresponds to the</span> | |
394 | <span class="c1">#: ``Control`` field in [MS-DTYP] 2.4.6.</span> | |
395 | <span class="bp">self</span><span class="o">.</span><span class="n">flags</span> <span class="o">=</span> <span class="n">flags</span> | |
396 | <span class="c1">#: Instance of :class:`SID` representing the owner user.</span> | |
397 | <span class="bp">self</span><span class="o">.</span><span class="n">owner</span> <span class="o">=</span> <span class="n">owner</span> | |
398 | <span class="c1">#: Instance of :class:`SID` representing the owner group.</span> | |
399 | <span class="bp">self</span><span class="o">.</span><span class="n">group</span> <span class="o">=</span> <span class="n">group</span> | |
400 | <span class="c1">#: Instance of :class:`ACL` representing the discretionary access</span> | |
401 | <span class="c1">#: control list, which specifies access restrictions of an object.</span> | |
402 | <span class="bp">self</span><span class="o">.</span><span class="n">dacl</span> <span class="o">=</span> <span class="n">dacl</span> | |
403 | <span class="c1">#: Instance of :class:`ACL` representing the system access control</span> | |
404 | <span class="c1">#: list, which specifies audit logging of an object.</span> | |
405 | <span class="bp">self</span><span class="o">.</span><span class="n">sacl</span> <span class="o">=</span> <span class="n">sacl</span> | |
406 | ||
407 | <span class="nd">@classmethod</span> | |
408 | <span class="k">def</span> <span class="nf">from_bytes</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span> | |
409 | <span class="n">owner</span> <span class="o">=</span> <span class="bp">None</span> | |
410 | <span class="n">group</span> <span class="o">=</span> <span class="bp">None</span> | |
411 | <span class="n">dacl</span> <span class="o">=</span> <span class="bp">None</span> | |
412 | <span class="n">sacl</span> <span class="o">=</span> <span class="bp">None</span> | |
413 | ||
414 | <span class="n">header</span> <span class="o">=</span> <span class="n">data</span><span class="p">[:</span><span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">HEADER_FORMAT</span><span class="p">)]</span> | |
415 | <span class="p">(</span><span class="n">revision</span><span class="p">,</span> <span class="n">sbz1</span><span class="p">,</span> <span class="n">flags</span><span class="p">,</span> <span class="n">owner_offset</span><span class="p">,</span> <span class="n">group_offset</span><span class="p">,</span> <span class="n">sacl_offset</span><span class="p">,</span> | |
416 | <span class="n">dacl_offset</span><span class="p">)</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">HEADER_FORMAT</span><span class="p">,</span> <span class="n">header</span><span class="p">)</span> | |
417 | ||
418 | <span class="k">assert</span> <span class="n">revision</span> <span class="o">==</span> <span class="mi">1</span> | |
419 | <span class="k">assert</span> <span class="n">flags</span> <span class="o">&</span> <span class="n">SECURITY_DESCRIPTOR_SELF_RELATIVE</span> | |
420 | <span class="k">for</span> <span class="n">offset</span> <span class="ow">in</span> <span class="p">(</span><span class="n">owner_offset</span><span class="p">,</span> <span class="n">group_offset</span><span class="p">,</span> <span class="n">sacl_offset</span><span class="p">,</span> <span class="n">dacl_offset</span><span class="p">):</span> | |
421 | <span class="k">assert</span> <span class="mi">0</span> <span class="o"><=</span> <span class="n">offset</span> <span class="o"><</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> | |
422 | ||
423 | <span class="k">if</span> <span class="n">owner_offset</span><span class="p">:</span> | |
424 | <span class="n">owner</span> <span class="o">=</span> <span class="n">SID</span><span class="o">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">owner_offset</span><span class="p">:])</span> | |
425 | <span class="k">if</span> <span class="n">group_offset</span><span class="p">:</span> | |
426 | <span class="n">group</span> <span class="o">=</span> <span class="n">SID</span><span class="o">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">group_offset</span><span class="p">:])</span> | |
427 | <span class="k">if</span> <span class="n">dacl_offset</span><span class="p">:</span> | |
428 | <span class="n">dacl</span> <span class="o">=</span> <span class="n">ACL</span><span class="o">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">dacl_offset</span><span class="p">:])</span> | |
429 | <span class="k">if</span> <span class="n">sacl_offset</span><span class="p">:</span> | |
430 | <span class="n">sacl</span> <span class="o">=</span> <span class="n">ACL</span><span class="o">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">sacl_offset</span><span class="p">:])</span> | |
431 | ||
432 | <span class="k">return</span> <span class="n">cls</span><span class="p">(</span><span class="n">flags</span><span class="p">,</span> <span class="n">owner</span><span class="p">,</span> <span class="n">group</span><span class="p">,</span> <span class="n">dacl</span><span class="p">,</span> <span class="n">sacl</span><span class="p">)</span></div> | |
433 | </pre></div> | |
434 | ||
435 | </div> | |
436 | </div> | |
437 | </div> | |
438 | <div class="clearer"></div> | |
439 | </div> | |
440 | <div class="related" role="navigation" aria-label="related navigation"> | |
441 | <h3>Navigation</h3> | |
442 | <ul> | |
443 | <li class="right" style="margin-right: 10px"> | |
444 | <a href="../../genindex.html" title="General Index" | |
445 | >index</a></li> | |
446 | <li class="right" > | |
447 | <a href="../../py-modindex.html" title="Python Module Index" | |
448 | >modules</a> |</li> | |
449 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.2.1 documentation</a> »</li> | |
450 | <li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> »</li> | |
451 | </ul> | |
452 | </div> | |
453 | <div class="footer" role="contentinfo"> | |
454 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
455 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. | |
456 | </div> | |
457 | </body> | |
458 | </html>⏎ |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>smb.smb_structs — pysmb 1.1.18 documentation</title> | |
8 | <title>smb.smb_structs — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../../index.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../../index.html" /> | |
26 | 26 | <link rel="up" title="Module code" href="../index.html" /> |
27 | 27 | </head> |
28 | 28 | <body role="document"> |
32 | 32 | <li class="right" style="margin-right: 10px"> |
33 | 33 | <a href="../../genindex.html" title="General Index" |
34 | 34 | accesskey="I">index</a></li> |
35 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.18 documentation</a> »</li> | |
35 | <li class="right" > | |
36 | <a href="../../py-modindex.html" title="Python Module Index" | |
37 | >modules</a> |</li> | |
38 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.2.1 documentation</a> »</li> | |
36 | 39 | <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> »</li> |
37 | 40 | </ul> |
38 | 41 | </div> |
1342 | 1345 | <span class="sd"> - [MS-CIFS]: 2.2.4.39.1</span> |
1343 | 1346 | <span class="sd"> """</span> |
1344 | 1347 | |
1345 | <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">echo_data</span> <span class="o">=</span> <span class="s1">''</span><span class="p">,</span> <span class="n">echo_count</span> <span class="o">=</span> <span class="mi">1</span><span class="p">):</span> | |
1348 | <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">echo_data</span> <span class="o">=</span> <span class="n">b</span><span class="s1">''</span><span class="p">,</span> <span class="n">echo_count</span> <span class="o">=</span> <span class="mi">1</span><span class="p">):</span> | |
1346 | 1349 | <span class="bp">self</span><span class="o">.</span><span class="n">echo_count</span> <span class="o">=</span> <span class="n">echo_count</span> |
1347 | 1350 | <span class="bp">self</span><span class="o">.</span><span class="n">echo_data</span> <span class="o">=</span> <span class="n">echo_data</span> |
1348 | 1351 | |
1493 | 1496 | <li class="right" style="margin-right: 10px"> |
1494 | 1497 | <a href="../../genindex.html" title="General Index" |
1495 | 1498 | >index</a></li> |
1496 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.18 documentation</a> »</li> | |
1499 | <li class="right" > | |
1500 | <a href="../../py-modindex.html" title="Python Module Index" | |
1501 | >modules</a> |</li> | |
1502 | <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.2.1 documentation</a> »</li> | |
1497 | 1503 | <li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> »</li> |
1498 | 1504 | </ul> |
1499 | 1505 | </div> |
1500 | 1506 | <div class="footer" role="contentinfo"> |
1501 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
1507 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
1502 | 1508 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
1503 | 1509 | </div> |
1504 | 1510 | </body> |
5 | 5 | |
6 | 6 | Notes |
7 | 7 | ----- |
8 | * Note that you need to pass in a valid hostname or IP address for the host component of the URL. | |
9 | Do not use the Windows/NetBIOS machine name for the host component. | |
8 | * The host component of the URL must be one of the following: | |
9 | ||
10 | * A fully-qualified hostname that can be resolved by your local DNS service. Example: myserver.test.com | |
11 | * An IP address. Example: 192.168.1.1 | |
12 | * A comma-separated string "<NBName>,<IP>" where *<NBName>* is the Windows/NetBIOS machine name for remote SMB service, and *<IP>* is the service's IP address. Example: MYSERVER,192.168.1.1 | |
13 | ||
10 | 14 | * The first component of the path in the URL points to the name of the shared folder. |
11 | 15 | Subsequent path components will point to the directory/folder of the file. |
12 | 16 | * You can retrieve and upload files, but you cannot delete files/folders or create folders. |
15 | 19 | Example |
16 | 20 | ------- |
17 | 21 | |
18 | The following code snippet illustrates file retrieval.:: | |
22 | The following code snippet illustrates file retrieval with Python 2.:: | |
19 | 23 | |
20 | 24 | # -*- coding: utf-8 -*- |
21 | 25 | import urllib2 |
33 | 37 | # Process fh2 like a file-like object and then close it. |
34 | 38 | fh2.close() |
35 | 39 | |
36 | The following code snippet illustrates file upload. You need to provide a file-like object for the *data* parameter in the *open()* method:: | |
40 | The following code snippet illustrates file upload with Python 2. You need to provide a file-like object for the *data* parameter in the *open()* method:: | |
37 | 41 | |
38 | 42 | import urllib2 |
39 | 43 | from smb.SMBHandler import SMBHandler |
45 | 49 | |
46 | 50 | # Reading from fh will only return an empty string |
47 | 51 | fh.close() |
52 | ||
53 | ||
54 | The following code snippet illustrates file retrieval with Python 3.:: | |
55 | ||
56 | import urllib | |
57 | from smb.SMBHandler import SMBHandler | |
58 | ||
59 | director = urllib.request.build_opener(SMBHandler) | |
60 | fh = director.open('smb://myuserID:[email protected]/sharedfolder/rfc1001.txt') | |
61 | ||
62 | # Process fh like a file-like object and then close it. | |
63 | fh.close() | |
64 | ||
65 | # For paths/files with unicode characters, simply pass in the URL as an unicode string | |
66 | fh2 = director.open(u'smb://myuserID:[email protected]/sharedfolder/测试文件夹/垃圾文件.dat') | |
67 | ||
68 | # Process fh2 like a file-like object and then close it. | |
69 | fh2.close() | |
70 | ||
71 | The following code snippet illustrates file upload with Python 3. You need to provide a file-like object for the *data* parameter in the *open()* method:: | |
72 | ||
73 | import urllib | |
74 | from smb.SMBHandler import SMBHandler | |
75 | ||
76 | file_fh = open('local_file.dat', 'rb') | |
77 | ||
78 | director = urllib.request.build_opener(SMBHandler) | |
79 | fh = director.open('smb://myuserID:[email protected]/sharedfolder/upload_file.dat', data = file_fh) | |
80 | ||
81 | # Reading from fh will only return an empty string | |
82 | fh.close() |
0 | ||
1 | Security Descriptors | |
2 | ==================== | |
3 | ||
4 | .. module:: smb.security_descriptors | |
5 | :synopsis: Data structures used in Windows security descriptors. | |
6 | ||
7 | This module implements security descriptors, and associated data | |
8 | structures, as specified in `[MS-DTYP]`_. | |
9 | ||
10 | .. autoclass:: SID | |
11 | :members: | |
12 | ||
13 | .. autoclass:: ACE | |
14 | :members: | |
15 | ||
16 | .. autoclass:: ACL | |
17 | :members: | |
18 | ||
19 | .. autoclass:: SecurityDescriptor | |
20 | :members: | |
21 | ||
22 | .. _[MS-DTYP]: https://msdn.microsoft.com/en-us/library/cc230273.aspx |
7 | 7 | |
8 | 8 | pysmb is a pure Python implementation of the client-side SMB/CIFS protocol (SMB1 and SMB2) which is the underlying protocol |
9 | 9 | that facilitates file sharing and printing between Windows machines, as well as with Linux machines via the Samba server application. |
10 | pysmb is developed in Python 2.4.6, Python 2.7.1 and Python 3.2.3 and has been tested against shared folders on Windows XP SP3, Windows Vista, Windows 7 and Samba 3.x. | |
10 | pysmb is developed in Python 2.7.x and Python 3.5.x and has been tested against shared folders on Windows XP SP3, Windows Vista, Windows 7 and Samba 3.x. | |
11 | 11 | |
12 | The latest version of pysmb is always available at the pysmb project page at `miketeo.net <http://miketeo.net/wp/index.php/projects/pysmb>`_. | |
12 | The latest version of pysmb is always available at the pysmb project page at `miketeo.net <http://miketeo.net/projects/pysmb>`_. | |
13 | 13 | |
14 | 14 | License |
15 | 15 | ------- |
89 | 89 | As a software developer who is looking to modify pysmb so that you can integrate it to other network frameworks: |
90 | 90 | * Read :doc:`extending` |
91 | 91 | |
92 | If you are upgrading from older pysmb versions: | |
93 | * Read :doc:`upgrading` | |
92 | 94 | |
93 | 95 | |
94 | 96 | Indices and tables |
100 | 102 | |
101 | 103 | api/* |
102 | 104 | extending |
105 | upgrading | |
103 | 106 | |
104 | 107 | * :ref:`genindex` |
105 | 108 | * :ref:`search` |
0 | Upgrading from older pysmb versions | |
1 | ==================================== | |
2 | ||
3 | This page documents the improvements and changes to the API that could be incompatible with previous releases. | |
4 | ||
5 | pysmb 1.2.0 | |
6 | ----------- | |
7 | - Add new `delete_matching_folders` parameter to `deleteFiles()` method in SMBProtocolFactory and SMBConnection | |
8 | class to support deletion of sub-folders. If you are passing timeout parameter to the `deleteFiles()` method | |
9 | in your application, please switch to using named parameter for timeout. | |
10 | ||
11 | pysmb 1.1.28 | |
12 | ------------ | |
13 | - SharedFile instances returned from the `listPath()` method now has a new property | |
14 | `file_id` attribute which represents the file reference number given by the remote SMB server. | |
15 | ||
16 | pysmb 1.1.26 | |
17 | ------------ | |
18 | - SMBConnection class can now be used as a context manager | |
19 | ||
20 | pysmb 1.1.25 | |
21 | ------------ | |
22 | - SharedFile class has a new property `isNormal` which will be True if the file is a | |
23 | 'normal' file. pysmb defines a 'normal' file as a file entry that is not | |
24 | read-only, not hidden, not system, not archive and not a directory; | |
25 | it ignores other attributes like compression, indexed, sparse, temporary and encryption. | |
26 | - `listPath()` method in SMBProtocolFactory and SMBConnection class will now include | |
27 | 'normal' files by default if you do not specify the `search` parameter. | |
28 | ||
29 | pysmb 1.1.20 | |
30 | ------------ | |
31 | - A new method `getSecurity()` was added to SMBConnection and SMBProtocolFactory class. | |
32 | ||
33 | pysmb 1.1.15 | |
34 | ------------ | |
35 | - Add new `truncate` parameter to `storeFileFromOffset()` in SMBProtocolFactory and SMBConnection | |
36 | class to support truncation of the file before writing. If you are passing timeout parameter | |
37 | to the `storeFileFromOffset()` method in your application, please switch to using named parameter for timeout. | |
38 | ||
39 | pysmb 1.1.11 | |
40 | ------------ | |
41 | - A new method `storeFileFromOffset()` was added to SMBConnection and SMBProtocolFactory class. | |
42 | ||
43 | pysmb 1.1.10 | |
44 | ------------ | |
45 | - A new method `getAttributes()` was added to SMBConnection and SMBProtocolFactory class | |
46 | - SharedFile class has a new property `isReadOnly` to indicate the file is read-only on the remote filesystem. | |
47 | ||
48 | pysmb 1.1.2 | |
49 | ----------- | |
50 | - `queryIPForName()` method in nmb.NetBIOS and nmb.NBNSProtocol class will now return only the server machine name and ignore workgroup names. | |
51 | ||
52 | pysmb 1.0.3 | |
53 | ----------- | |
54 | - Two new methods were added to NBNSProtocol class: `queryIPForName()` and `NetBIOS.queryIPForName()` | |
55 | to support querying for a machine's NetBIOS name at the given IP address. | |
56 | - A new method `retrieveFileFromOffset()` was added to SMBProtocolFactory and SMBConnection | |
57 | to support finer control of file retrieval operation. | |
58 | ||
59 | pysmb 1.0.0 | |
60 | ----------- | |
61 | pysmb was completely rewritten in version 1.0.0. | |
62 | If you are upgrading from pysmb 0.x, you most likely have to rewrite your application for the new 1.x API. |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>NBNSProtocol Class — pysmb 1.1.18 documentation</title> | |
8 | <title>NBNSProtocol Class — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../index.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../index.html" /> | |
26 | 26 | <link rel="next" title="NetBIOS class" href="nmb_NetBIOS.html" /> |
27 | 27 | <link rel="prev" title="Welcome to pysmb’s documentation!" href="../index.html" /> |
28 | 28 | </head> |
34 | 34 | <a href="../genindex.html" title="General Index" |
35 | 35 | accesskey="I">index</a></li> |
36 | 36 | <li class="right" > |
37 | <a href="../py-modindex.html" title="Python Module Index" | |
38 | >modules</a> |</li> | |
39 | <li class="right" > | |
37 | 40 | <a href="nmb_NetBIOS.html" title="NetBIOS class" |
38 | 41 | accesskey="N">next</a> |</li> |
39 | 42 | <li class="right" > |
40 | 43 | <a href="../index.html" title="Welcome to pysmb’s documentation!" |
41 | 44 | accesskey="P">previous</a> |</li> |
42 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
45 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
43 | 46 | </ul> |
44 | 47 | </div> |
45 | 48 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
185 | 188 | <a href="../genindex.html" title="General Index" |
186 | 189 | >index</a></li> |
187 | 190 | <li class="right" > |
191 | <a href="../py-modindex.html" title="Python Module Index" | |
192 | >modules</a> |</li> | |
193 | <li class="right" > | |
188 | 194 | <a href="nmb_NetBIOS.html" title="NetBIOS class" |
189 | 195 | >next</a> |</li> |
190 | 196 | <li class="right" > |
191 | 197 | <a href="../index.html" title="Welcome to pysmb’s documentation!" |
192 | 198 | >previous</a> |</li> |
193 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
199 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
194 | 200 | </ul> |
195 | 201 | </div> |
196 | 202 | <div class="footer" role="contentinfo"> |
197 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
203 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
198 | 204 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
199 | 205 | </div> |
200 | 206 | </body> |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>NetBIOS class — pysmb 1.1.18 documentation</title> | |
8 | <title>NetBIOS class — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../index.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../index.html" /> | |
26 | 26 | <link rel="next" title="SMBConnection Class" href="smb_SMBConnection.html" /> |
27 | 27 | <link rel="prev" title="NBNSProtocol Class" href="nmb_NBNSProtocol.html" /> |
28 | 28 | </head> |
34 | 34 | <a href="../genindex.html" title="General Index" |
35 | 35 | accesskey="I">index</a></li> |
36 | 36 | <li class="right" > |
37 | <a href="../py-modindex.html" title="Python Module Index" | |
38 | >modules</a> |</li> | |
39 | <li class="right" > | |
37 | 40 | <a href="smb_SMBConnection.html" title="SMBConnection Class" |
38 | 41 | accesskey="N">next</a> |</li> |
39 | 42 | <li class="right" > |
40 | 43 | <a href="nmb_NBNSProtocol.html" title="NBNSProtocol Class" |
41 | 44 | accesskey="P">previous</a> |</li> |
42 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
45 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
43 | 46 | </ul> |
44 | 47 | </div> |
45 | 48 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
189 | 192 | <a href="../genindex.html" title="General Index" |
190 | 193 | >index</a></li> |
191 | 194 | <li class="right" > |
195 | <a href="../py-modindex.html" title="Python Module Index" | |
196 | >modules</a> |</li> | |
197 | <li class="right" > | |
192 | 198 | <a href="smb_SMBConnection.html" title="SMBConnection Class" |
193 | 199 | >next</a> |</li> |
194 | 200 | <li class="right" > |
195 | 201 | <a href="nmb_NBNSProtocol.html" title="NBNSProtocol Class" |
196 | 202 | >previous</a> |</li> |
197 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
203 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
198 | 204 | </ul> |
199 | 205 | </div> |
200 | 206 | <div class="footer" role="contentinfo"> |
201 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
207 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
202 | 208 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
203 | 209 | </div> |
204 | 210 | </body> |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>SMBConnection Class — pysmb 1.1.18 documentation</title> | |
8 | <title>SMBConnection Class — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../index.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../index.html" /> | |
26 | 26 | <link rel="next" title="SMbHandler Class" href="smb_SMBHandler.html" /> |
27 | 27 | <link rel="prev" title="NetBIOS class" href="nmb_NetBIOS.html" /> |
28 | 28 | </head> |
34 | 34 | <a href="../genindex.html" title="General Index" |
35 | 35 | accesskey="I">index</a></li> |
36 | 36 | <li class="right" > |
37 | <a href="../py-modindex.html" title="Python Module Index" | |
38 | >modules</a> |</li> | |
39 | <li class="right" > | |
37 | 40 | <a href="smb_SMBHandler.html" title="SMbHandler Class" |
38 | 41 | accesskey="N">next</a> |</li> |
39 | 42 | <li class="right" > |
40 | 43 | <a href="nmb_NetBIOS.html" title="NetBIOS class" |
41 | 44 | accesskey="P">previous</a> |</li> |
42 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
45 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
43 | 46 | </ul> |
44 | 47 | </div> |
45 | 48 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
143 | 146 | <code class="descname">__init__</code><span class="sig-paren">(</span><em>username</em>, <em>password</em>, <em>my_name</em>, <em>remote_name</em>, <em>domain=''</em>, <em>use_ntlm_v2=True</em>, <em>sign_options=2</em>, <em>is_direct_tcp=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/SMBConnection.html#SMBConnection.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.SMBConnection.SMBConnection.__init__" title="Permalink to this definition">¶</a></dt> |
144 | 147 | <dd><p>Create a new SMBConnection instance.</p> |
145 | 148 | <p><em>username</em> and <em>password</em> are the user credentials required to authenticate the underlying SMB connection with the remote server. |
149 | <em>password</em> can be a string or a callable returning a string. | |
146 | 150 | File operations can only be proceeded after the connection has been authenticated successfully.</p> |
147 | 151 | <p>Note that you need to call <em>connect</em> method to actually establish the SMB connection to the remote server and perform authentication.</p> |
148 | 152 | <p>The default TCP port for most SMB/CIFS servers using NetBIOS over TCP/IP is 139. |
243 | 247 | |
244 | 248 | <dl class="method"> |
245 | 249 | <dt id="smb.SMBConnection.SMBConnection.deleteFiles"> |
246 | <code class="descname">deleteFiles</code><span class="sig-paren">(</span><em>service_name</em>, <em>path_file_pattern</em>, <em>timeout=30</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/SMBConnection.html#SMBConnection.deleteFiles"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.SMBConnection.SMBConnection.deleteFiles" title="Permalink to this definition">¶</a></dt> | |
250 | <code class="descname">deleteFiles</code><span class="sig-paren">(</span><em>service_name</em>, <em>path_file_pattern</em>, <em>delete_matching_folders=False</em>, <em>timeout=30</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/SMBConnection.html#SMBConnection.deleteFiles"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.SMBConnection.SMBConnection.deleteFiles" title="Permalink to this definition">¶</a></dt> | |
247 | 251 | <dd><p>Delete one or more regular files. It supports the use of wildcards in file names, allowing for deletion of multiple files in a single request.</p> |
252 | <p>If delete_matching_folders is True, immediate sub-folders that match the path_file_pattern will be deleted recursively.</p> | |
248 | 253 | <table class="docutils field-list" frame="void" rules="none"> |
249 | 254 | <col class="field-name" /> |
250 | 255 | <col class="field-body" /> |
272 | 277 | <col class="field-name" /> |
273 | 278 | <col class="field-body" /> |
274 | 279 | <tbody valign="top"> |
275 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>data</strong> (<em>string</em>) – Data to send to the remote server.</td> | |
280 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>data</strong> (<em>bytes</em>) – Data to send to the remote server. Must be a bytes object.</td> | |
276 | 281 | </tr> |
277 | 282 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The <em>data</em> parameter</td> |
278 | 283 | </tr> |
302 | 307 | </dd></dl> |
303 | 308 | |
304 | 309 | <dl class="method"> |
310 | <dt id="smb.SMBConnection.SMBConnection.getSecurity"> | |
311 | <code class="descname">getSecurity</code><span class="sig-paren">(</span><em>service_name</em>, <em>path</em>, <em>timeout=30</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/SMBConnection.html#SMBConnection.getSecurity"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.SMBConnection.SMBConnection.getSecurity" title="Permalink to this definition">¶</a></dt> | |
312 | <dd><p>Retrieve the security descriptor of the file at <em>path</em> on the <em>service_name</em>.</p> | |
313 | <table class="docutils field-list" frame="void" rules="none"> | |
314 | <col class="field-name" /> | |
315 | <col class="field-body" /> | |
316 | <tbody valign="top"> | |
317 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> | |
318 | <li><strong>service_name</strong> (<em>string/unicode</em>) – the name of the shared folder for the <em>path</em></li> | |
319 | <li><strong>path</strong> (<em>string/unicode</em>) – Path of the file on the remote server. If the file cannot be opened for reading, an <a class="reference internal" href="smb_exceptions.html"><em>OperationFailure</em></a> will be raised.</li> | |
320 | </ul> | |
321 | </td> | |
322 | </tr> | |
323 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A <a class="reference internal" href="smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor" title="smb.security_descriptors.SecurityDescriptor"><code class="xref py py-class docutils literal"><span class="pre">smb.security_descriptors.SecurityDescriptor</span></code></a> instance containing the security information of the file.</p> | |
324 | </td> | |
325 | </tr> | |
326 | </tbody> | |
327 | </table> | |
328 | </dd></dl> | |
329 | ||
330 | <dl class="method"> | |
305 | 331 | <dt id="smb.SMBConnection.SMBConnection.listPath"> |
306 | <code class="descname">listPath</code><span class="sig-paren">(</span><em>service_name</em>, <em>path</em>, <em>search=55</em>, <em>pattern='*'</em>, <em>timeout=30</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/SMBConnection.html#SMBConnection.listPath"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.SMBConnection.SMBConnection.listPath" title="Permalink to this definition">¶</a></dt> | |
332 | <code class="descname">listPath</code><span class="sig-paren">(</span><em>service_name</em>, <em>path</em>, <em>search=65591</em>, <em>pattern='*'</em>, <em>timeout=30</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/SMBConnection.html#SMBConnection.listPath"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.SMBConnection.SMBConnection.listPath" title="Permalink to this definition">¶</a></dt> | |
307 | 333 | <dd><p>Retrieve a directory listing of files/folders at <em>path</em></p> |
334 | <p>For simplicity, pysmb defines a “normal” file as a file entry that is not read-only, not hidden, not system, not archive and not a directory. | |
335 | It ignores other attributes like compression, indexed, sparse, temporary and encryption.</p> | |
336 | <p>Note that the default search parameter will query for all read-only (SMB_FILE_ATTRIBUTE_READONLY), hidden (SMB_FILE_ATTRIBUTE_HIDDEN), | |
337 | system (SMB_FILE_ATTRIBUTE_SYSTEM), archive (SMB_FILE_ATTRIBUTE_ARCHIVE), normal (SMB_FILE_ATTRIBUTE_INCL_NORMAL) files | |
338 | and directories (SMB_FILE_ATTRIBUTE_DIRECTORY). | |
339 | If you do not need to include “normal” files in the result, define your own search parameter without the SMB_FILE_ATTRIBUTE_INCL_NORMAL constant. | |
340 | SMB_FILE_ATTRIBUTE_NORMAL should be used by itself and not be used with other bit constants.</p> | |
308 | 341 | <table class="docutils field-list" frame="void" rules="none"> |
309 | 342 | <col class="field-name" /> |
310 | 343 | <col class="field-body" /> |
312 | 345 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
313 | 346 | <li><strong>service_name</strong> (<em>string/unicode</em>) – the name of the shared folder for the <em>path</em></li> |
314 | 347 | <li><strong>path</strong> (<em>string/unicode</em>) – path relative to the <em>service_name</em> where we are interested to learn about its files/sub-folders.</li> |
315 | <li><strong>search</strong> (<em>integer</em>) – integer value made up from a bitwise-OR of <em>SMB_FILE_ATTRIBUTE_xxx</em> bits (see smb_constants.py). | |
316 | The default <em>search</em> value will query for all read-only, hidden, system, archive files and directories.</li> | |
348 | <li><strong>search</strong> (<em>integer</em>) – integer value made up from a bitwise-OR of <em>SMB_FILE_ATTRIBUTE_xxx</em> bits (see smb_constants.py).</li> | |
317 | 349 | <li><strong>pattern</strong> (<em>string/unicode</em>) – the filter to apply to the results before returning to the client.</li> |
318 | 350 | </ul> |
319 | 351 | </td> |
546 | 578 | <a href="../genindex.html" title="General Index" |
547 | 579 | >index</a></li> |
548 | 580 | <li class="right" > |
581 | <a href="../py-modindex.html" title="Python Module Index" | |
582 | >modules</a> |</li> | |
583 | <li class="right" > | |
549 | 584 | <a href="smb_SMBHandler.html" title="SMbHandler Class" |
550 | 585 | >next</a> |</li> |
551 | 586 | <li class="right" > |
552 | 587 | <a href="nmb_NetBIOS.html" title="NetBIOS class" |
553 | 588 | >previous</a> |</li> |
554 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
589 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
555 | 590 | </ul> |
556 | 591 | </div> |
557 | 592 | <div class="footer" role="contentinfo"> |
558 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
593 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
559 | 594 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
560 | 595 | </div> |
561 | 596 | </body> |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>SMbHandler Class — pysmb 1.1.18 documentation</title> | |
8 | <title>SMbHandler Class — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../index.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../index.html" /> | |
26 | 26 | <link rel="next" title="SMBProtocolFactory Class" href="smb_SMBProtocolFactory.html" /> |
27 | 27 | <link rel="prev" title="SMBConnection Class" href="smb_SMBConnection.html" /> |
28 | 28 | </head> |
34 | 34 | <a href="../genindex.html" title="General Index" |
35 | 35 | accesskey="I">index</a></li> |
36 | 36 | <li class="right" > |
37 | <a href="../py-modindex.html" title="Python Module Index" | |
38 | >modules</a> |</li> | |
39 | <li class="right" > | |
37 | 40 | <a href="smb_SMBProtocolFactory.html" title="SMBProtocolFactory Class" |
38 | 41 | accesskey="N">next</a> |</li> |
39 | 42 | <li class="right" > |
40 | 43 | <a href="smb_SMBConnection.html" title="SMBConnection Class" |
41 | 44 | accesskey="P">previous</a> |</li> |
42 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
45 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
43 | 46 | </ul> |
44 | 47 | </div> |
45 | 48 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
93 | 96 | <div class="section" id="notes"> |
94 | 97 | <h2>Notes<a class="headerlink" href="#notes" title="Permalink to this headline">¶</a></h2> |
95 | 98 | <ul class="simple"> |
96 | <li>Note that you need to pass in a valid hostname or IP address for the host component of the URL. | |
97 | Do not use the Windows/NetBIOS machine name for the host component.</li> | |
99 | <li>The host component of the URL must be one of the following:<ul> | |
100 | <li>A fully-qualified hostname that can be resolved by your local DNS service. Example: myserver.test.com</li> | |
101 | <li>An IP address. Example: 192.168.1.1</li> | |
102 | <li>A comma-separated string “<NBName>,<IP>” where <em><NBName></em> is the Windows/NetBIOS machine name for remote SMB service, and <em><IP></em> is the service’s IP address. Example: MYSERVER,192.168.1.1</li> | |
103 | </ul> | |
104 | </li> | |
98 | 105 | <li>The first component of the path in the URL points to the name of the shared folder. |
99 | 106 | Subsequent path components will point to the directory/folder of the file.</li> |
100 | 107 | <li>You can retrieve and upload files, but you cannot delete files/folders or create folders. |
103 | 110 | </div> |
104 | 111 | <div class="section" id="example"> |
105 | 112 | <h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2> |
106 | <p>The following code snippet illustrates file retrieval.:</p> | |
113 | <p>The following code snippet illustrates file retrieval with Python 2.:</p> | |
107 | 114 | <div class="highlight-python"><div class="highlight"><pre><span class="c1"># -*- coding: utf-8 -*-</span> |
108 | 115 | <span class="kn">import</span> <span class="nn">urllib2</span> |
109 | 116 | <span class="kn">from</span> <span class="nn">smb.SMBHandler</span> <span class="kn">import</span> <span class="n">SMBHandler</span> |
121 | 128 | <span class="n">fh2</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> |
122 | 129 | </pre></div> |
123 | 130 | </div> |
124 | <p>The following code snippet illustrates file upload. You need to provide a file-like object for the <em>data</em> parameter in the <em>open()</em> method:</p> | |
131 | <p>The following code snippet illustrates file upload with Python 2. You need to provide a file-like object for the <em>data</em> parameter in the <em>open()</em> method:</p> | |
125 | 132 | <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">urllib2</span> |
126 | 133 | <span class="kn">from</span> <span class="nn">smb.SMBHandler</span> <span class="kn">import</span> <span class="n">SMBHandler</span> |
127 | 134 | |
128 | 135 | <span class="n">file_fh</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s1">'local_file.dat'</span><span class="p">,</span> <span class="s1">'rb'</span><span class="p">)</span> |
129 | 136 | |
130 | 137 | <span class="n">director</span> <span class="o">=</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">build_opener</span><span class="p">(</span><span class="n">SMBHandler</span><span class="p">)</span> |
138 | <span class="n">fh</span> <span class="o">=</span> <span class="n">director</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">'smb://myuserID:[email protected]/sharedfolder/upload_file.dat'</span><span class="p">,</span> <span class="n">data</span> <span class="o">=</span> <span class="n">file_fh</span><span class="p">)</span> | |
139 | ||
140 | <span class="c1"># Reading from fh will only return an empty string</span> | |
141 | <span class="n">fh</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> | |
142 | </pre></div> | |
143 | </div> | |
144 | <p>The following code snippet illustrates file retrieval with Python 3.:</p> | |
145 | <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">urllib</span> | |
146 | <span class="kn">from</span> <span class="nn">smb.SMBHandler</span> <span class="kn">import</span> <span class="n">SMBHandler</span> | |
147 | ||
148 | <span class="n">director</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">build_opener</span><span class="p">(</span><span class="n">SMBHandler</span><span class="p">)</span> | |
149 | <span class="n">fh</span> <span class="o">=</span> <span class="n">director</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">'smb://myuserID:[email protected]/sharedfolder/rfc1001.txt'</span><span class="p">)</span> | |
150 | ||
151 | <span class="c1"># Process fh like a file-like object and then close it.</span> | |
152 | <span class="n">fh</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> | |
153 | ||
154 | <span class="c1"># For paths/files with unicode characters, simply pass in the URL as an unicode string</span> | |
155 | <span class="n">fh2</span> <span class="o">=</span> <span class="n">director</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">u'smb://myuserID:[email protected]/sharedfolder/测试文件夹/垃圾文件.dat'</span><span class="p">)</span> | |
156 | ||
157 | <span class="c1"># Process fh2 like a file-like object and then close it.</span> | |
158 | <span class="n">fh2</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> | |
159 | </pre></div> | |
160 | </div> | |
161 | <p>The following code snippet illustrates file upload with Python 3. You need to provide a file-like object for the <em>data</em> parameter in the <em>open()</em> method:</p> | |
162 | <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">urllib</span> | |
163 | <span class="kn">from</span> <span class="nn">smb.SMBHandler</span> <span class="kn">import</span> <span class="n">SMBHandler</span> | |
164 | ||
165 | <span class="n">file_fh</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s1">'local_file.dat'</span><span class="p">,</span> <span class="s1">'rb'</span><span class="p">)</span> | |
166 | ||
167 | <span class="n">director</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">build_opener</span><span class="p">(</span><span class="n">SMBHandler</span><span class="p">)</span> | |
131 | 168 | <span class="n">fh</span> <span class="o">=</span> <span class="n">director</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">'smb://myuserID:[email protected]/sharedfolder/upload_file.dat'</span><span class="p">,</span> <span class="n">data</span> <span class="o">=</span> <span class="n">file_fh</span><span class="p">)</span> |
132 | 169 | |
133 | 170 | <span class="c1"># Reading from fh will only return an empty string</span> |
150 | 187 | <a href="../genindex.html" title="General Index" |
151 | 188 | >index</a></li> |
152 | 189 | <li class="right" > |
190 | <a href="../py-modindex.html" title="Python Module Index" | |
191 | >modules</a> |</li> | |
192 | <li class="right" > | |
153 | 193 | <a href="smb_SMBProtocolFactory.html" title="SMBProtocolFactory Class" |
154 | 194 | >next</a> |</li> |
155 | 195 | <li class="right" > |
156 | 196 | <a href="smb_SMBConnection.html" title="SMBConnection Class" |
157 | 197 | >previous</a> |</li> |
158 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
198 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
159 | 199 | </ul> |
160 | 200 | </div> |
161 | 201 | <div class="footer" role="contentinfo"> |
162 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
202 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
163 | 203 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
164 | 204 | </div> |
165 | 205 | </body> |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>SMBProtocolFactory Class — pysmb 1.1.18 documentation</title> | |
8 | <title>SMBProtocolFactory Class — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../index.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../index.html" /> | |
26 | 26 | <link rel="next" title="SharedDevice Class" href="smb_SharedDevice.html" /> |
27 | 27 | <link rel="prev" title="SMbHandler Class" href="smb_SMBHandler.html" /> |
28 | 28 | </head> |
34 | 34 | <a href="../genindex.html" title="General Index" |
35 | 35 | accesskey="I">index</a></li> |
36 | 36 | <li class="right" > |
37 | <a href="../py-modindex.html" title="Python Module Index" | |
38 | >modules</a> |</li> | |
39 | <li class="right" > | |
37 | 40 | <a href="smb_SharedDevice.html" title="SharedDevice Class" |
38 | 41 | accesskey="N">next</a> |</li> |
39 | 42 | <li class="right" > |
40 | 43 | <a href="smb_SMBHandler.html" title="SMbHandler Class" |
41 | 44 | accesskey="P">previous</a> |</li> |
42 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
45 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
43 | 46 | </ul> |
44 | 47 | </div> |
45 | 48 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
304 | 307 | <col class="field-body" /> |
305 | 308 | <tbody valign="top"> |
306 | 309 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
307 | <li><strong>data</strong> (<em>string</em>) – Data to send to the remote server.</li> | |
310 | <li><strong>data</strong> (<em>bytes</em>) – Data to send to the remote server. Must be a bytes object.</li> | |
308 | 311 | <li><strong>timeout</strong> (<em>integer/float</em>) – Number of seconds that pysmb will wait before raising <em>SMBTimeout</em> via the returned <em>Deferred</em> instance’s <em>errback</em> method.</li> |
309 | 312 | </ul> |
310 | 313 | </td> |
339 | 342 | |
340 | 343 | <dl class="method"> |
341 | 344 | <dt id="smb.SMBProtocol.SMBProtocolFactory.listPath"> |
342 | <code class="descname">listPath</code><span class="sig-paren">(</span><em>service_name</em>, <em>path</em>, <em>search=55</em>, <em>pattern='*'</em>, <em>timeout=30</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/SMBProtocol.html#SMBProtocolFactory.listPath"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.SMBProtocol.SMBProtocolFactory.listPath" title="Permalink to this definition">¶</a></dt> | |
345 | <code class="descname">listPath</code><span class="sig-paren">(</span><em>service_name</em>, <em>path</em>, <em>search=65591</em>, <em>pattern='*'</em>, <em>timeout=30</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/SMBProtocol.html#SMBProtocolFactory.listPath"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.SMBProtocol.SMBProtocolFactory.listPath" title="Permalink to this definition">¶</a></dt> | |
343 | 346 | <dd><p>Retrieve a directory listing of files/folders at <em>path</em></p> |
347 | <p>For simplicity, pysmb defines a “normal” file as a file entry that is not read-only, not hidden, not system, not archive and not a directory. | |
348 | It ignores other attributes like compression, indexed, sparse, temporary and encryption.</p> | |
349 | <p>Note that the default search parameter will query for all read-only (SMB_FILE_ATTRIBUTE_READONLY), hidden (SMB_FILE_ATTRIBUTE_HIDDEN), | |
350 | system (SMB_FILE_ATTRIBUTE_SYSTEM), archive (SMB_FILE_ATTRIBUTE_ARCHIVE), normal (SMB_FILE_ATTRIBUTE_INCL_NORMAL) files | |
351 | and directories (SMB_FILE_ATTRIBUTE_DIRECTORY). | |
352 | If you do not need to include “normal” files in the result, define your own search parameter without the SMB_FILE_ATTRIBUTE_INCL_NORMAL constant. | |
353 | SMB_FILE_ATTRIBUTE_NORMAL should be used by itself and not be used with other bit constants.</p> | |
344 | 354 | <table class="docutils field-list" frame="void" rules="none"> |
345 | 355 | <col class="field-name" /> |
346 | 356 | <col class="field-body" /> |
348 | 358 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
349 | 359 | <li><strong>service_name</strong> (<em>string/unicode</em>) – the name of the shared folder for the <em>path</em></li> |
350 | 360 | <li><strong>path</strong> (<em>string/unicode</em>) – path relative to the <em>service_name</em> where we are interested to learn about its files/sub-folders.</li> |
351 | <li><strong>search</strong> (<em>integer</em>) – integer value made up from a bitwise-OR of <em>SMB_FILE_ATTRIBUTE_xxx</em> bits (see smb_constants.py). | |
352 | The default <em>search</em> value will query for all read-only, hidden, system, archive files and directories.</li> | |
361 | <li><strong>search</strong> (<em>integer</em>) – integer value made up from a bitwise-OR of <em>SMB_FILE_ATTRIBUTE_xxx</em> bits (see smb_constants.py).</li> | |
353 | 362 | <li><strong>pattern</strong> (<em>string/unicode</em>) – the filter to apply to the results before returning to the client.</li> |
354 | 363 | <li><strong>timeout</strong> (<em>integer/float</em>) – Number of seconds that pysmb will wait before raising <em>SMBTimeout</em> via the returned <em>Deferred</em> instance’s <em>errback</em> method.</li> |
355 | 364 | </ul> |
585 | 594 | <a href="../genindex.html" title="General Index" |
586 | 595 | >index</a></li> |
587 | 596 | <li class="right" > |
597 | <a href="../py-modindex.html" title="Python Module Index" | |
598 | >modules</a> |</li> | |
599 | <li class="right" > | |
588 | 600 | <a href="smb_SharedDevice.html" title="SharedDevice Class" |
589 | 601 | >next</a> |</li> |
590 | 602 | <li class="right" > |
591 | 603 | <a href="smb_SMBHandler.html" title="SMbHandler Class" |
592 | 604 | >previous</a> |</li> |
593 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
605 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
594 | 606 | </ul> |
595 | 607 | </div> |
596 | 608 | <div class="footer" role="contentinfo"> |
597 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
609 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
598 | 610 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
599 | 611 | </div> |
600 | 612 | </body> |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>SharedDevice Class — pysmb 1.1.18 documentation</title> | |
8 | <title>SharedDevice Class — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../index.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../index.html" /> | |
26 | 26 | <link rel="next" title="SharedFile Class" href="smb_SharedFile.html" /> |
27 | 27 | <link rel="prev" title="SMBProtocolFactory Class" href="smb_SMBProtocolFactory.html" /> |
28 | 28 | </head> |
34 | 34 | <a href="../genindex.html" title="General Index" |
35 | 35 | accesskey="I">index</a></li> |
36 | 36 | <li class="right" > |
37 | <a href="../py-modindex.html" title="Python Module Index" | |
38 | >modules</a> |</li> | |
39 | <li class="right" > | |
37 | 40 | <a href="smb_SharedFile.html" title="SharedFile Class" |
38 | 41 | accesskey="N">next</a> |</li> |
39 | 42 | <li class="right" > |
40 | 43 | <a href="smb_SMBProtocolFactory.html" title="SMBProtocolFactory Class" |
41 | 44 | accesskey="P">previous</a> |</li> |
42 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
45 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
43 | 46 | </ul> |
44 | 47 | </div> |
45 | 48 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
84 | 87 | <dt id="smb.base.SharedDevice"> |
85 | 88 | <em class="property">class </em><code class="descclassname">smb.base.</code><code class="descname">SharedDevice</code><span class="sig-paren">(</span><em>type</em>, <em>name</em>, <em>comments</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/base.html#SharedDevice"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.base.SharedDevice" title="Permalink to this definition">¶</a></dt> |
86 | 89 | <dd><p>Contains information about a single shared device on the remote server.</p> |
90 | <p>The following attributes are available:</p> | |
91 | <ul class="simple"> | |
92 | <li>name : An unicode string containing the name of the shared device</li> | |
93 | <li>comments : An unicode string containing the user description of the shared device</li> | |
94 | </ul> | |
87 | 95 | <dl class="attribute"> |
88 | 96 | <dt id="smb.base.SharedDevice.comments"> |
89 | 97 | <code class="descname">comments</code><em class="property"> = None</em><a class="headerlink" href="#smb.base.SharedDevice.comments" title="Permalink to this definition">¶</a></dt> |
142 | 150 | <a href="../genindex.html" title="General Index" |
143 | 151 | >index</a></li> |
144 | 152 | <li class="right" > |
153 | <a href="../py-modindex.html" title="Python Module Index" | |
154 | >modules</a> |</li> | |
155 | <li class="right" > | |
145 | 156 | <a href="smb_SharedFile.html" title="SharedFile Class" |
146 | 157 | >next</a> |</li> |
147 | 158 | <li class="right" > |
148 | 159 | <a href="smb_SMBProtocolFactory.html" title="SMBProtocolFactory Class" |
149 | 160 | >previous</a> |</li> |
150 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
161 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
151 | 162 | </ul> |
152 | 163 | </div> |
153 | 164 | <div class="footer" role="contentinfo"> |
154 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
165 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
155 | 166 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
156 | 167 | </div> |
157 | 168 | </body> |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>SharedFile Class — pysmb 1.1.18 documentation</title> | |
8 | <title>SharedFile Class — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../index.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../index.html" /> | |
26 | 26 | <link rel="next" title="SMB Exceptions" href="smb_exceptions.html" /> |
27 | 27 | <link rel="prev" title="SharedDevice Class" href="smb_SharedDevice.html" /> |
28 | 28 | </head> |
34 | 34 | <a href="../genindex.html" title="General Index" |
35 | 35 | accesskey="I">index</a></li> |
36 | 36 | <li class="right" > |
37 | <a href="../py-modindex.html" title="Python Module Index" | |
38 | >modules</a> |</li> | |
39 | <li class="right" > | |
37 | 40 | <a href="smb_exceptions.html" title="SMB Exceptions" |
38 | 41 | accesskey="N">next</a> |</li> |
39 | 42 | <li class="right" > |
40 | 43 | <a href="smb_SharedDevice.html" title="SharedDevice Class" |
41 | 44 | accesskey="P">previous</a> |</li> |
42 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
45 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
43 | 46 | </ul> |
44 | 47 | </div> |
45 | 48 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
82 | 85 | <h1>SharedFile Class<a class="headerlink" href="#sharedfile-class" title="Permalink to this headline">¶</a></h1> |
83 | 86 | <dl class="class"> |
84 | 87 | <dt id="smb.base.SharedFile"> |
85 | <em class="property">class </em><code class="descclassname">smb.base.</code><code class="descname">SharedFile</code><span class="sig-paren">(</span><em>create_time</em>, <em>last_access_time</em>, <em>last_write_time</em>, <em>last_attr_change_time</em>, <em>file_size</em>, <em>alloc_size</em>, <em>file_attributes</em>, <em>short_name</em>, <em>filename</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/base.html#SharedFile"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.base.SharedFile" title="Permalink to this definition">¶</a></dt> | |
88 | <em class="property">class </em><code class="descclassname">smb.base.</code><code class="descname">SharedFile</code><span class="sig-paren">(</span><em>create_time</em>, <em>last_access_time</em>, <em>last_write_time</em>, <em>last_attr_change_time</em>, <em>file_size</em>, <em>alloc_size</em>, <em>file_attributes</em>, <em>short_name</em>, <em>filename</em>, <em>file_id=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/base.html#SharedFile"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.base.SharedFile" title="Permalink to this definition">¶</a></dt> | |
86 | 89 | <dd><p>Contain information about a file/folder entry that is shared on the shared device.</p> |
87 | 90 | <p>As an application developer, you should not need to instantiate a <em>SharedFile</em> instance directly in your application. |
88 | 91 | These <em>SharedFile</em> instances are usually returned via a call to <em>listPath</em> method in <a class="reference internal" href="smb_SMBProtocolFactory.html"><em>smb.SMBProtocol.SMBProtocolFactory</em></a>.</p> |
89 | 92 | <p>If you encounter <em>SharedFile</em> instance where its short_name attribute is empty but the filename attribute contains a short name which does not correspond |
90 | 93 | to any files/folders on your remote shared device, it could be that the original filename on the file/folder entry on the shared device contains |
91 | 94 | one of these prohibited characters: “/[]:+|<>=;?,* (see [MS-CIFS]: 2.2.1.1.1 for more details).</p> |
95 | <p>The following attributes are available:</p> | |
96 | <ul class="simple"> | |
97 | <li>create_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of creation of this file resource on the remote server</li> | |
98 | <li>last_access_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last access of this file resource on the remote server</li> | |
99 | <li>last_write_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last modification of this file resource on the remote server</li> | |
100 | <li>last_attr_change_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last attribute change of this file resource on the remote server</li> | |
101 | <li>file_size : File size in number of bytes</li> | |
102 | <li>alloc_size : Total number of bytes allocated to store this file</li> | |
103 | <li>file_attributes : A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3. You can perform bit-wise tests to determine the status of the file using the ATTR_xxx constants in smb_constants.py.</li> | |
104 | <li>short_name : Unicode string containing the short name of this file (usually in 8.3 notation)</li> | |
105 | <li>filename : Unicode string containing the long filename of this file. Each OS has a limit to the length of this file name. On Windows, it is 256 characters.</li> | |
106 | <li>file_id : Long value representing the file reference number for the file. If the remote system does not support this field, this field will be None or 0. See [MS-FSCC]: 2.4.17</li> | |
107 | </ul> | |
92 | 108 | <dl class="attribute"> |
93 | 109 | <dt id="smb.base.SharedFile.alloc_size"> |
94 | 110 | <code class="descname">alloc_size</code><em class="property"> = None</em><a class="headerlink" href="#smb.base.SharedFile.alloc_size" title="Permalink to this definition">¶</a></dt> |
104 | 120 | <dl class="attribute"> |
105 | 121 | <dt id="smb.base.SharedFile.file_attributes"> |
106 | 122 | <code class="descname">file_attributes</code><em class="property"> = None</em><a class="headerlink" href="#smb.base.SharedFile.file_attributes" title="Permalink to this definition">¶</a></dt> |
107 | <dd><p>A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3</p> | |
123 | <dd><p>A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3. You can perform bit-wise tests to determine the status of the file using the ATTR_xxx constants in smb_constants.py.</p> | |
124 | </dd></dl> | |
125 | ||
126 | <dl class="attribute"> | |
127 | <dt id="smb.base.SharedFile.file_id"> | |
128 | <code class="descname">file_id</code><em class="property"> = None</em><a class="headerlink" href="#smb.base.SharedFile.file_id" title="Permalink to this definition">¶</a></dt> | |
129 | <dd><p>Long value representing the file reference number for the file. If the remote system does not support this field, this field will be None or 0. See [MS-FSCC]: 2.4.17</p> | |
108 | 130 | </dd></dl> |
109 | 131 | |
110 | 132 | <dl class="attribute"> |
123 | 145 | <dt id="smb.base.SharedFile.isDirectory"> |
124 | 146 | <code class="descname">isDirectory</code><a class="headerlink" href="#smb.base.SharedFile.isDirectory" title="Permalink to this definition">¶</a></dt> |
125 | 147 | <dd><p>A convenient property to return True if this file resource is a directory on the remote server</p> |
148 | </dd></dl> | |
149 | ||
150 | <dl class="attribute"> | |
151 | <dt id="smb.base.SharedFile.isNormal"> | |
152 | <code class="descname">isNormal</code><a class="headerlink" href="#smb.base.SharedFile.isNormal" title="Permalink to this definition">¶</a></dt> | |
153 | <dd><p>A convenient property to return True if this is a normal file.</p> | |
154 | <p>Note that pysmb defines a normal file as a file entry that is not read-only, not hidden, not system, not archive and not a directory. | |
155 | It ignores other attributes like compression, indexed, sparse, temporary and encryption.</p> | |
126 | 156 | </dd></dl> |
127 | 157 | |
128 | 158 | <dl class="attribute"> |
172 | 202 | <a href="../genindex.html" title="General Index" |
173 | 203 | >index</a></li> |
174 | 204 | <li class="right" > |
205 | <a href="../py-modindex.html" title="Python Module Index" | |
206 | >modules</a> |</li> | |
207 | <li class="right" > | |
175 | 208 | <a href="smb_exceptions.html" title="SMB Exceptions" |
176 | 209 | >next</a> |</li> |
177 | 210 | <li class="right" > |
178 | 211 | <a href="smb_SharedDevice.html" title="SharedDevice Class" |
179 | 212 | >previous</a> |</li> |
180 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
213 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
181 | 214 | </ul> |
182 | 215 | </div> |
183 | 216 | <div class="footer" role="contentinfo"> |
184 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
217 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
185 | 218 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
186 | 219 | </div> |
187 | 220 | </body> |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>SMB Exceptions — pysmb 1.1.18 documentation</title> | |
8 | <title>SMB Exceptions — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: '../', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="../_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="../_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="../_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="../index.html" /> | |
26 | <link rel="next" title="Extending pysmb For Other Frameworks" href="../extending.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../index.html" /> | |
26 | <link rel="next" title="Security Descriptors" href="smb_security_descriptors.html" /> | |
27 | 27 | <link rel="prev" title="SharedFile Class" href="smb_SharedFile.html" /> |
28 | 28 | </head> |
29 | 29 | <body role="document"> |
34 | 34 | <a href="../genindex.html" title="General Index" |
35 | 35 | accesskey="I">index</a></li> |
36 | 36 | <li class="right" > |
37 | <a href="../extending.html" title="Extending pysmb For Other Frameworks" | |
37 | <a href="../py-modindex.html" title="Python Module Index" | |
38 | >modules</a> |</li> | |
39 | <li class="right" > | |
40 | <a href="smb_security_descriptors.html" title="Security Descriptors" | |
38 | 41 | accesskey="N">next</a> |</li> |
39 | 42 | <li class="right" > |
40 | 43 | <a href="smb_SharedFile.html" title="SharedFile Class" |
41 | 44 | accesskey="P">previous</a> |</li> |
42 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
45 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
43 | 46 | </ul> |
44 | 47 | </div> |
45 | 48 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
48 | 51 | <p class="topless"><a href="smb_SharedFile.html" |
49 | 52 | title="previous chapter">SharedFile Class</a></p> |
50 | 53 | <h4>Next topic</h4> |
51 | <p class="topless"><a href="../extending.html" | |
52 | title="next chapter">Extending pysmb For Other Frameworks</a></p> | |
54 | <p class="topless"><a href="smb_security_descriptors.html" | |
55 | title="next chapter">Security Descriptors</a></p> | |
53 | 56 | <div role="note" aria-label="source link"> |
54 | 57 | <h3>This Page</h3> |
55 | 58 | <ul class="this-page-menu"> |
130 | 133 | <a href="../genindex.html" title="General Index" |
131 | 134 | >index</a></li> |
132 | 135 | <li class="right" > |
133 | <a href="../extending.html" title="Extending pysmb For Other Frameworks" | |
136 | <a href="../py-modindex.html" title="Python Module Index" | |
137 | >modules</a> |</li> | |
138 | <li class="right" > | |
139 | <a href="smb_security_descriptors.html" title="Security Descriptors" | |
134 | 140 | >next</a> |</li> |
135 | 141 | <li class="right" > |
136 | 142 | <a href="smb_SharedFile.html" title="SharedFile Class" |
137 | 143 | >previous</a> |</li> |
138 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.18 documentation</a> »</li> | |
144 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
139 | 145 | </ul> |
140 | 146 | </div> |
141 | 147 | <div class="footer" role="contentinfo"> |
142 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
148 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
143 | 149 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
144 | 150 | </div> |
145 | 151 | </body> |
0 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
1 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
2 | ||
3 | ||
4 | <html xmlns="http://www.w3.org/1999/xhtml"> | |
5 | <head> | |
6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
7 | ||
8 | <title>Security Descriptors — pysmb 1.2.1 documentation</title> | |
9 | ||
10 | <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" /> | |
11 | <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> | |
12 | ||
13 | <script type="text/javascript"> | |
14 | var DOCUMENTATION_OPTIONS = { | |
15 | URL_ROOT: '../', | |
16 | VERSION: '1.2.1', | |
17 | COLLAPSE_INDEX: false, | |
18 | FILE_SUFFIX: '.html', | |
19 | HAS_SOURCE: true | |
20 | }; | |
21 | </script> | |
22 | <script type="text/javascript" src="../_static/jquery.js"></script> | |
23 | <script type="text/javascript" src="../_static/underscore.js"></script> | |
24 | <script type="text/javascript" src="../_static/doctools.js"></script> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="../index.html" /> | |
26 | <link rel="next" title="Extending pysmb For Other Frameworks" href="../extending.html" /> | |
27 | <link rel="prev" title="SMB Exceptions" href="smb_exceptions.html" /> | |
28 | </head> | |
29 | <body role="document"> | |
30 | <div class="related" role="navigation" aria-label="related navigation"> | |
31 | <h3>Navigation</h3> | |
32 | <ul> | |
33 | <li class="right" style="margin-right: 10px"> | |
34 | <a href="../genindex.html" title="General Index" | |
35 | accesskey="I">index</a></li> | |
36 | <li class="right" > | |
37 | <a href="../py-modindex.html" title="Python Module Index" | |
38 | >modules</a> |</li> | |
39 | <li class="right" > | |
40 | <a href="../extending.html" title="Extending pysmb For Other Frameworks" | |
41 | accesskey="N">next</a> |</li> | |
42 | <li class="right" > | |
43 | <a href="smb_exceptions.html" title="SMB Exceptions" | |
44 | accesskey="P">previous</a> |</li> | |
45 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
46 | </ul> | |
47 | </div> | |
48 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> | |
49 | <div class="sphinxsidebarwrapper"> | |
50 | <h4>Previous topic</h4> | |
51 | <p class="topless"><a href="smb_exceptions.html" | |
52 | title="previous chapter">SMB Exceptions</a></p> | |
53 | <h4>Next topic</h4> | |
54 | <p class="topless"><a href="../extending.html" | |
55 | title="next chapter">Extending pysmb For Other Frameworks</a></p> | |
56 | <div role="note" aria-label="source link"> | |
57 | <h3>This Page</h3> | |
58 | <ul class="this-page-menu"> | |
59 | <li><a href="../_sources/api/smb_security_descriptors.txt" | |
60 | rel="nofollow">Show Source</a></li> | |
61 | </ul> | |
62 | </div> | |
63 | <div id="searchbox" style="display: none" role="search"> | |
64 | <h3>Quick search</h3> | |
65 | <form class="search" action="../search.html" method="get"> | |
66 | <input type="text" name="q" /> | |
67 | <input type="submit" value="Go" /> | |
68 | <input type="hidden" name="check_keywords" value="yes" /> | |
69 | <input type="hidden" name="area" value="default" /> | |
70 | </form> | |
71 | <p class="searchtip" style="font-size: 90%"> | |
72 | Enter search terms or a module, class or function name. | |
73 | </p> | |
74 | </div> | |
75 | <script type="text/javascript">$('#searchbox').show(0);</script> | |
76 | </div> | |
77 | </div> | |
78 | ||
79 | <div class="document"> | |
80 | <div class="documentwrapper"> | |
81 | <div class="bodywrapper"> | |
82 | <div class="body" role="main"> | |
83 | ||
84 | <div class="section" id="module-smb.security_descriptors"> | |
85 | <span id="security-descriptors"></span><h1>Security Descriptors<a class="headerlink" href="#module-smb.security_descriptors" title="Permalink to this headline">¶</a></h1> | |
86 | <p>This module implements security descriptors, and associated data | |
87 | structures, as specified in <a class="reference external" href="https://msdn.microsoft.com/en-us/library/cc230273.aspx">[MS-DTYP]</a>.</p> | |
88 | <dl class="class"> | |
89 | <dt id="smb.security_descriptors.SID"> | |
90 | <em class="property">class </em><code class="descclassname">smb.security_descriptors.</code><code class="descname">SID</code><span class="sig-paren">(</span><em>revision</em>, <em>identifier_authority</em>, <em>subauthorities</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/security_descriptors.html#SID"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.security_descriptors.SID" title="Permalink to this definition">¶</a></dt> | |
91 | <dd><p>A Windows security identifier. Represents a single principal, such a | |
92 | user or a group, as a sequence of numbers consisting of the revision, | |
93 | identifier authority, and a variable-length list of subauthorities.</p> | |
94 | <p>See [MS-DTYP]: 2.4.2</p> | |
95 | <dl class="attribute"> | |
96 | <dt id="smb.security_descriptors.SID.identifier_authority"> | |
97 | <code class="descname">identifier_authority</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SID.identifier_authority" title="Permalink to this definition">¶</a></dt> | |
98 | <dd><p>An integer representing the identifier authority.</p> | |
99 | </dd></dl> | |
100 | ||
101 | <dl class="attribute"> | |
102 | <dt id="smb.security_descriptors.SID.revision"> | |
103 | <code class="descname">revision</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SID.revision" title="Permalink to this definition">¶</a></dt> | |
104 | <dd><p>Revision, should always be 1.</p> | |
105 | </dd></dl> | |
106 | ||
107 | <dl class="attribute"> | |
108 | <dt id="smb.security_descriptors.SID.subauthorities"> | |
109 | <code class="descname">subauthorities</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SID.subauthorities" title="Permalink to this definition">¶</a></dt> | |
110 | <dd><p>A list of integers representing all subauthorities.</p> | |
111 | </dd></dl> | |
112 | ||
113 | </dd></dl> | |
114 | ||
115 | <dl class="class"> | |
116 | <dt id="smb.security_descriptors.ACE"> | |
117 | <em class="property">class </em><code class="descclassname">smb.security_descriptors.</code><code class="descname">ACE</code><span class="sig-paren">(</span><em>type_</em>, <em>flags</em>, <em>mask</em>, <em>sid</em>, <em>additional_data</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/security_descriptors.html#ACE"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.security_descriptors.ACE" title="Permalink to this definition">¶</a></dt> | |
118 | <dd><p>Represents a single access control entry.</p> | |
119 | <p>See [MS-DTYP]: 2.4.4</p> | |
120 | <dl class="attribute"> | |
121 | <dt id="smb.security_descriptors.ACE.additional_data"> | |
122 | <code class="descname">additional_data</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.ACE.additional_data" title="Permalink to this definition">¶</a></dt> | |
123 | <dd><p>A dictionary of additional fields present in the ACE, depending | |
124 | on the type. The following fields can be present:</p> | |
125 | <ul class="simple"> | |
126 | <li><code class="docutils literal"><span class="pre">flags</span></code></li> | |
127 | <li><code class="docutils literal"><span class="pre">object_type</span></code></li> | |
128 | <li><code class="docutils literal"><span class="pre">inherited_object_type</span></code></li> | |
129 | <li><code class="docutils literal"><span class="pre">application_data</span></code></li> | |
130 | <li><code class="docutils literal"><span class="pre">attribute_data</span></code></li> | |
131 | </ul> | |
132 | </dd></dl> | |
133 | ||
134 | <dl class="attribute"> | |
135 | <dt id="smb.security_descriptors.ACE.flags"> | |
136 | <code class="descname">flags</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.ACE.flags" title="Permalink to this definition">¶</a></dt> | |
137 | <dd><p>An integer bitmask with ACE flags, corresponds to the | |
138 | <code class="docutils literal"><span class="pre">AceFlags</span></code> field.</p> | |
139 | </dd></dl> | |
140 | ||
141 | <dl class="attribute"> | |
142 | <dt id="smb.security_descriptors.ACE.isInheritOnly"> | |
143 | <code class="descname">isInheritOnly</code><a class="headerlink" href="#smb.security_descriptors.ACE.isInheritOnly" title="Permalink to this definition">¶</a></dt> | |
144 | <dd><p>Convenience property which indicates if this ACE is inherit | |
145 | only, meaning that it doesn’t apply to the object itself.</p> | |
146 | </dd></dl> | |
147 | ||
148 | <dl class="attribute"> | |
149 | <dt id="smb.security_descriptors.ACE.mask"> | |
150 | <code class="descname">mask</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.ACE.mask" title="Permalink to this definition">¶</a></dt> | |
151 | <dd><p>An integer representing the <code class="docutils literal"><span class="pre">ACCESS_MASK</span></code> as specified in | |
152 | [MS-DTYP] 2.4.3.</p> | |
153 | </dd></dl> | |
154 | ||
155 | <dl class="attribute"> | |
156 | <dt id="smb.security_descriptors.ACE.sid"> | |
157 | <code class="descname">sid</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.ACE.sid" title="Permalink to this definition">¶</a></dt> | |
158 | <dd><p>The <a class="reference internal" href="#smb.security_descriptors.SID" title="smb.security_descriptors.SID"><code class="xref py py-class docutils literal"><span class="pre">SID</span></code></a> of a trustee.</p> | |
159 | </dd></dl> | |
160 | ||
161 | <dl class="attribute"> | |
162 | <dt id="smb.security_descriptors.ACE.type"> | |
163 | <code class="descname">type</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.ACE.type" title="Permalink to this definition">¶</a></dt> | |
164 | <dd><p>An integer representing the type of the ACE. One of the | |
165 | <code class="docutils literal"><span class="pre">ACE_TYPE_*</span></code> constants. Corresponds to the <code class="docutils literal"><span class="pre">AceType</span></code> field | |
166 | from [MS-DTYP] 2.4.4.1.</p> | |
167 | </dd></dl> | |
168 | ||
169 | </dd></dl> | |
170 | ||
171 | <dl class="class"> | |
172 | <dt id="smb.security_descriptors.ACL"> | |
173 | <em class="property">class </em><code class="descclassname">smb.security_descriptors.</code><code class="descname">ACL</code><span class="sig-paren">(</span><em>revision</em>, <em>aces</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/security_descriptors.html#ACL"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.security_descriptors.ACL" title="Permalink to this definition">¶</a></dt> | |
174 | <dd><p>Access control list, encapsulating a sequence of access control | |
175 | entries.</p> | |
176 | <p>See [MS-DTYP]: 2.4.5</p> | |
177 | <dl class="attribute"> | |
178 | <dt id="smb.security_descriptors.ACL.aces"> | |
179 | <code class="descname">aces</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.ACL.aces" title="Permalink to this definition">¶</a></dt> | |
180 | <dd><p>List of <a class="reference internal" href="#smb.security_descriptors.ACE" title="smb.security_descriptors.ACE"><code class="xref py py-class docutils literal"><span class="pre">ACE</span></code></a> instances.</p> | |
181 | </dd></dl> | |
182 | ||
183 | <dl class="attribute"> | |
184 | <dt id="smb.security_descriptors.ACL.revision"> | |
185 | <code class="descname">revision</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.ACL.revision" title="Permalink to this definition">¶</a></dt> | |
186 | <dd><p>Integer value of the revision.</p> | |
187 | </dd></dl> | |
188 | ||
189 | </dd></dl> | |
190 | ||
191 | <dl class="class"> | |
192 | <dt id="smb.security_descriptors.SecurityDescriptor"> | |
193 | <em class="property">class </em><code class="descclassname">smb.security_descriptors.</code><code class="descname">SecurityDescriptor</code><span class="sig-paren">(</span><em>flags</em>, <em>owner</em>, <em>group</em>, <em>dacl</em>, <em>sacl</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/security_descriptors.html#SecurityDescriptor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.security_descriptors.SecurityDescriptor" title="Permalink to this definition">¶</a></dt> | |
194 | <dd><p>Represents a security descriptor.</p> | |
195 | <p>See [MS-DTYP]: 2.4.6</p> | |
196 | <dl class="attribute"> | |
197 | <dt id="smb.security_descriptors.SecurityDescriptor.dacl"> | |
198 | <code class="descname">dacl</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SecurityDescriptor.dacl" title="Permalink to this definition">¶</a></dt> | |
199 | <dd><p>Instance of <a class="reference internal" href="#smb.security_descriptors.ACL" title="smb.security_descriptors.ACL"><code class="xref py py-class docutils literal"><span class="pre">ACL</span></code></a> representing the discretionary access | |
200 | control list, which specifies access restrictions of an object.</p> | |
201 | </dd></dl> | |
202 | ||
203 | <dl class="attribute"> | |
204 | <dt id="smb.security_descriptors.SecurityDescriptor.flags"> | |
205 | <code class="descname">flags</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SecurityDescriptor.flags" title="Permalink to this definition">¶</a></dt> | |
206 | <dd><p>Integer bitmask of control flags. Corresponds to the | |
207 | <code class="docutils literal"><span class="pre">Control</span></code> field in [MS-DTYP] 2.4.6.</p> | |
208 | </dd></dl> | |
209 | ||
210 | <dl class="attribute"> | |
211 | <dt id="smb.security_descriptors.SecurityDescriptor.group"> | |
212 | <code class="descname">group</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SecurityDescriptor.group" title="Permalink to this definition">¶</a></dt> | |
213 | <dd><p>Instance of <a class="reference internal" href="#smb.security_descriptors.SID" title="smb.security_descriptors.SID"><code class="xref py py-class docutils literal"><span class="pre">SID</span></code></a> representing the owner group.</p> | |
214 | </dd></dl> | |
215 | ||
216 | <dl class="attribute"> | |
217 | <dt id="smb.security_descriptors.SecurityDescriptor.owner"> | |
218 | <code class="descname">owner</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SecurityDescriptor.owner" title="Permalink to this definition">¶</a></dt> | |
219 | <dd><p>Instance of <a class="reference internal" href="#smb.security_descriptors.SID" title="smb.security_descriptors.SID"><code class="xref py py-class docutils literal"><span class="pre">SID</span></code></a> representing the owner user.</p> | |
220 | </dd></dl> | |
221 | ||
222 | <dl class="attribute"> | |
223 | <dt id="smb.security_descriptors.SecurityDescriptor.sacl"> | |
224 | <code class="descname">sacl</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SecurityDescriptor.sacl" title="Permalink to this definition">¶</a></dt> | |
225 | <dd><p>Instance of <a class="reference internal" href="#smb.security_descriptors.ACL" title="smb.security_descriptors.ACL"><code class="xref py py-class docutils literal"><span class="pre">ACL</span></code></a> representing the system access control | |
226 | list, which specifies audit logging of an object.</p> | |
227 | </dd></dl> | |
228 | ||
229 | </dd></dl> | |
230 | ||
231 | </div> | |
232 | ||
233 | ||
234 | </div> | |
235 | </div> | |
236 | </div> | |
237 | <div class="clearer"></div> | |
238 | </div> | |
239 | <div class="related" role="navigation" aria-label="related navigation"> | |
240 | <h3>Navigation</h3> | |
241 | <ul> | |
242 | <li class="right" style="margin-right: 10px"> | |
243 | <a href="../genindex.html" title="General Index" | |
244 | >index</a></li> | |
245 | <li class="right" > | |
246 | <a href="../py-modindex.html" title="Python Module Index" | |
247 | >modules</a> |</li> | |
248 | <li class="right" > | |
249 | <a href="../extending.html" title="Extending pysmb For Other Frameworks" | |
250 | >next</a> |</li> | |
251 | <li class="right" > | |
252 | <a href="smb_exceptions.html" title="SMB Exceptions" | |
253 | >previous</a> |</li> | |
254 | <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.1 documentation</a> »</li> | |
255 | </ul> | |
256 | </div> | |
257 | <div class="footer" role="contentinfo"> | |
258 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
259 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. | |
260 | </div> | |
261 | </body> | |
262 | </html>⏎ |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>Extending pysmb For Other Frameworks — pysmb 1.1.18 documentation</title> | |
8 | <title>Extending pysmb For Other Frameworks — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: './', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="index.html" /> | |
26 | <link rel="prev" title="SMB Exceptions" href="api/smb_exceptions.html" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="index.html" /> | |
26 | <link rel="next" title="Upgrading from older pysmb versions" href="upgrading.html" /> | |
27 | <link rel="prev" title="Security Descriptors" href="api/smb_security_descriptors.html" /> | |
27 | 28 | </head> |
28 | 29 | <body role="document"> |
29 | 30 | <div class="related" role="navigation" aria-label="related navigation"> |
33 | 34 | <a href="genindex.html" title="General Index" |
34 | 35 | accesskey="I">index</a></li> |
35 | 36 | <li class="right" > |
36 | <a href="api/smb_exceptions.html" title="SMB Exceptions" | |
37 | <a href="py-modindex.html" title="Python Module Index" | |
38 | >modules</a> |</li> | |
39 | <li class="right" > | |
40 | <a href="upgrading.html" title="Upgrading from older pysmb versions" | |
41 | accesskey="N">next</a> |</li> | |
42 | <li class="right" > | |
43 | <a href="api/smb_security_descriptors.html" title="Security Descriptors" | |
37 | 44 | accesskey="P">previous</a> |</li> |
38 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.1.18 documentation</a> »</li> | |
45 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.2.1 documentation</a> »</li> | |
39 | 46 | </ul> |
40 | 47 | </div> |
41 | 48 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
42 | 49 | <div class="sphinxsidebarwrapper"> |
43 | 50 | <h4>Previous topic</h4> |
44 | <p class="topless"><a href="api/smb_exceptions.html" | |
45 | title="previous chapter">SMB Exceptions</a></p> | |
51 | <p class="topless"><a href="api/smb_security_descriptors.html" | |
52 | title="previous chapter">Security Descriptors</a></p> | |
53 | <h4>Next topic</h4> | |
54 | <p class="topless"><a href="upgrading.html" | |
55 | title="next chapter">Upgrading from older pysmb versions</a></p> | |
46 | 56 | <div role="note" aria-label="source link"> |
47 | 57 | <h3>This Page</h3> |
48 | 58 | <ul class="this-page-menu"> |
110 | 120 | <a href="genindex.html" title="General Index" |
111 | 121 | >index</a></li> |
112 | 122 | <li class="right" > |
113 | <a href="api/smb_exceptions.html" title="SMB Exceptions" | |
123 | <a href="py-modindex.html" title="Python Module Index" | |
124 | >modules</a> |</li> | |
125 | <li class="right" > | |
126 | <a href="upgrading.html" title="Upgrading from older pysmb versions" | |
127 | >next</a> |</li> | |
128 | <li class="right" > | |
129 | <a href="api/smb_security_descriptors.html" title="Security Descriptors" | |
114 | 130 | >previous</a> |</li> |
115 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.1.18 documentation</a> »</li> | |
131 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.2.1 documentation</a> »</li> | |
116 | 132 | </ul> |
117 | 133 | </div> |
118 | 134 | <div class="footer" role="contentinfo"> |
119 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
135 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
120 | 136 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
121 | 137 | </div> |
122 | 138 | </body> |
6 | 6 | <head> |
7 | 7 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
8 | 8 | |
9 | <title>Index — pysmb 1.1.18 documentation</title> | |
9 | <title>Index — pysmb 1.2.1 documentation</title> | |
10 | 10 | |
11 | 11 | <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" /> |
12 | 12 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
14 | 14 | <script type="text/javascript"> |
15 | 15 | var DOCUMENTATION_OPTIONS = { |
16 | 16 | URL_ROOT: './', |
17 | VERSION: '1.1.18', | |
17 | VERSION: '1.2.1', | |
18 | 18 | COLLAPSE_INDEX: false, |
19 | 19 | FILE_SUFFIX: '.html', |
20 | 20 | HAS_SOURCE: true |
23 | 23 | <script type="text/javascript" src="_static/jquery.js"></script> |
24 | 24 | <script type="text/javascript" src="_static/underscore.js"></script> |
25 | 25 | <script type="text/javascript" src="_static/doctools.js"></script> |
26 | <link rel="top" title="pysmb 1.1.18 documentation" href="index.html" /> | |
26 | <link rel="top" title="pysmb 1.2.1 documentation" href="index.html" /> | |
27 | 27 | </head> |
28 | 28 | <body role="document"> |
29 | 29 | <div class="related" role="navigation" aria-label="related navigation"> |
32 | 32 | <li class="right" style="margin-right: 10px"> |
33 | 33 | <a href="#" title="General Index" |
34 | 34 | accesskey="I">index</a></li> |
35 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.1.18 documentation</a> »</li> | |
35 | <li class="right" > | |
36 | <a href="py-modindex.html" title="Python Module Index" | |
37 | >modules</a> |</li> | |
38 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.2.1 documentation</a> »</li> | |
36 | 39 | </ul> |
37 | 40 | </div> |
38 | 41 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
74 | 77 | | <a href="#G"><strong>G</strong></a> |
75 | 78 | | <a href="#I"><strong>I</strong></a> |
76 | 79 | | <a href="#L"><strong>L</strong></a> |
80 | | <a href="#M"><strong>M</strong></a> | |
77 | 81 | | <a href="#N"><strong>N</strong></a> |
78 | 82 | | <a href="#O"><strong>O</strong></a> |
79 | 83 | | <a href="#P"><strong>P</strong></a> |
112 | 116 | <table style="width: 100%" class="indextable genindextable"><tr> |
113 | 117 | <td style="width: 33%" valign="top"><dl> |
114 | 118 | |
119 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACE">ACE (class in smb.security_descriptors)</a> | |
120 | </dt> | |
121 | ||
122 | ||
123 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACL.aces">aces (smb.security_descriptors.ACL attribute)</a> | |
124 | </dt> | |
125 | ||
126 | ||
127 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACL">ACL (class in smb.security_descriptors)</a> | |
128 | </dt> | |
129 | ||
130 | </dl></td> | |
131 | <td style="width: 33%" valign="top"><dl> | |
132 | ||
133 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACE.additional_data">additional_data (smb.security_descriptors.ACE attribute)</a> | |
134 | </dt> | |
135 | ||
136 | ||
115 | 137 | <dt><a href="api/smb_SharedFile.html#smb.base.SharedFile.alloc_size">alloc_size (smb.base.SharedFile attribute)</a> |
116 | 138 | </dt> |
117 | 139 | |
166 | 188 | <table style="width: 100%" class="indextable genindextable"><tr> |
167 | 189 | <td style="width: 33%" valign="top"><dl> |
168 | 190 | |
191 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor.dacl">dacl (smb.security_descriptors.SecurityDescriptor attribute)</a> | |
192 | </dt> | |
193 | ||
194 | ||
169 | 195 | <dt><a href="api/smb_SMBConnection.html#smb.SMBConnection.SMBConnection.deleteDirectory">deleteDirectory() (smb.SMBConnection.SMBConnection method)</a> |
170 | 196 | </dt> |
171 | 197 | |
214 | 240 | </dt> |
215 | 241 | |
216 | 242 | |
243 | <dt><a href="api/smb_SharedFile.html#smb.base.SharedFile.file_id">file_id (smb.base.SharedFile attribute)</a> | |
244 | </dt> | |
245 | ||
246 | ||
217 | 247 | <dt><a href="api/smb_SharedFile.html#smb.base.SharedFile.file_size">file_size (smb.base.SharedFile attribute)</a> |
218 | 248 | </dt> |
219 | 249 | |
223 | 253 | <dt><a href="api/smb_SharedFile.html#smb.base.SharedFile.filename">filename (smb.base.SharedFile attribute)</a> |
224 | 254 | </dt> |
225 | 255 | |
256 | ||
257 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACE.flags">flags (smb.security_descriptors.ACE attribute)</a> | |
258 | </dt> | |
259 | ||
260 | <dd><dl> | |
261 | ||
262 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor.flags">(smb.security_descriptors.SecurityDescriptor attribute)</a> | |
263 | </dt> | |
264 | ||
265 | </dl></dd> | |
226 | 266 | </dl></td> |
227 | 267 | </tr></table> |
228 | 268 | |
239 | 279 | </dt> |
240 | 280 | |
241 | 281 | </dl></dd> |
282 | ||
283 | <dt><a href="api/smb_SMBConnection.html#smb.SMBConnection.SMBConnection.getSecurity">getSecurity() (smb.SMBConnection.SMBConnection method)</a> | |
284 | </dt> | |
285 | ||
286 | </dl></td> | |
287 | <td style="width: 33%" valign="top"><dl> | |
288 | ||
289 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor.group">group (smb.security_descriptors.SecurityDescriptor attribute)</a> | |
290 | </dt> | |
291 | ||
242 | 292 | </dl></td> |
243 | 293 | </tr></table> |
244 | 294 | |
246 | 296 | <table style="width: 100%" class="indextable genindextable"><tr> |
247 | 297 | <td style="width: 33%" valign="top"><dl> |
248 | 298 | |
299 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SID.identifier_authority">identifier_authority (smb.security_descriptors.SID attribute)</a> | |
300 | </dt> | |
301 | ||
302 | ||
249 | 303 | <dt><a href="api/smb_SMBProtocolFactory.html#smb.SMBProtocol.SMBProtocolFactory.instance">instance (smb.SMBProtocol.SMBProtocolFactory attribute)</a> |
250 | 304 | </dt> |
251 | 305 | |
254 | 308 | </dt> |
255 | 309 | |
256 | 310 | |
311 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACE.isInheritOnly">isInheritOnly (smb.security_descriptors.ACE attribute)</a> | |
312 | </dt> | |
313 | ||
314 | ||
315 | <dt><a href="api/smb_SharedFile.html#smb.base.SharedFile.isNormal">isNormal (smb.base.SharedFile attribute)</a> | |
316 | </dt> | |
317 | ||
318 | </dl></td> | |
319 | <td style="width: 33%" valign="top"><dl> | |
320 | ||
257 | 321 | <dt><a href="api/smb_SharedFile.html#smb.base.SharedFile.isReadOnly">isReadOnly (smb.base.SharedFile attribute)</a> |
258 | 322 | </dt> |
259 | 323 | |
261 | 325 | <dt><a href="api/smb_SMBProtocolFactory.html#smb.SMBProtocol.SMBProtocolFactory.isReady">isReady (smb.SMBProtocol.SMBProtocolFactory attribute)</a> |
262 | 326 | </dt> |
263 | 327 | |
264 | </dl></td> | |
265 | <td style="width: 33%" valign="top"><dl> | |
266 | 328 | |
267 | 329 | <dt><a href="api/smb_SharedDevice.html#smb.base.SharedDevice.isSpecial">isSpecial (smb.base.SharedDevice attribute)</a> |
268 | 330 | </dt> |
334 | 396 | </dl></td> |
335 | 397 | </tr></table> |
336 | 398 | |
399 | <h2 id="M">M</h2> | |
400 | <table style="width: 100%" class="indextable genindextable"><tr> | |
401 | <td style="width: 33%" valign="top"><dl> | |
402 | ||
403 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACE.mask">mask (smb.security_descriptors.ACE attribute)</a> | |
404 | </dt> | |
405 | ||
406 | </dl></td> | |
407 | </tr></table> | |
408 | ||
337 | 409 | <h2 id="N">N</h2> |
338 | 410 | <table style="width: 100%" class="indextable genindextable"><tr> |
339 | 411 | <td style="width: 33%" valign="top"><dl> |
383 | 455 | <dt><a href="api/smb_exceptions.html#smb.smb_structs.OperationFailure">OperationFailure (class in smb.smb_structs)</a> |
384 | 456 | </dt> |
385 | 457 | |
458 | ||
459 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor.owner">owner (smb.security_descriptors.SecurityDescriptor attribute)</a> | |
460 | </dt> | |
461 | ||
386 | 462 | </dl></td> |
387 | 463 | </tr></table> |
388 | 464 | |
441 | 517 | <dt><a href="api/smb_SMBConnection.html#smb.SMBConnection.SMBConnection.resetFileAttributes">resetFileAttributes() (smb.SMBConnection.SMBConnection method)</a> |
442 | 518 | </dt> |
443 | 519 | |
444 | </dl></td> | |
445 | <td style="width: 33%" valign="top"><dl> | |
446 | 520 | |
447 | 521 | <dt><a href="api/smb_SMBConnection.html#smb.SMBConnection.SMBConnection.retrieveFile">retrieveFile() (smb.SMBConnection.SMBConnection method)</a> |
448 | 522 | </dt> |
453 | 527 | </dt> |
454 | 528 | |
455 | 529 | </dl></dd> |
530 | </dl></td> | |
531 | <td style="width: 33%" valign="top"><dl> | |
456 | 532 | |
457 | 533 | <dt><a href="api/smb_SMBConnection.html#smb.SMBConnection.SMBConnection.retrieveFileFromOffset">retrieveFileFromOffset() (smb.SMBConnection.SMBConnection method)</a> |
458 | 534 | </dt> |
463 | 539 | </dt> |
464 | 540 | |
465 | 541 | </dl></dd> |
542 | ||
543 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACL.revision">revision (smb.security_descriptors.ACL attribute)</a> | |
544 | </dt> | |
545 | ||
546 | <dd><dl> | |
547 | ||
548 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SID.revision">(smb.security_descriptors.SID attribute)</a> | |
549 | </dt> | |
550 | ||
551 | </dl></dd> | |
466 | 552 | </dl></td> |
467 | 553 | </tr></table> |
468 | 554 | |
470 | 556 | <table style="width: 100%" class="indextable genindextable"><tr> |
471 | 557 | <td style="width: 33%" valign="top"><dl> |
472 | 558 | |
559 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor.sacl">sacl (smb.security_descriptors.SecurityDescriptor attribute)</a> | |
560 | </dt> | |
561 | ||
562 | ||
563 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor">SecurityDescriptor (class in smb.security_descriptors)</a> | |
564 | </dt> | |
565 | ||
566 | ||
473 | 567 | <dt><a href="api/smb_SharedDevice.html#smb.base.SharedDevice">SharedDevice (class in smb.base)</a> |
474 | 568 | </dt> |
475 | 569 | |
482 | 576 | </dt> |
483 | 577 | |
484 | 578 | |
579 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SID">SID (class in smb.security_descriptors)</a> | |
580 | </dt> | |
581 | ||
582 | ||
583 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACE.sid">sid (smb.security_descriptors.ACE attribute)</a> | |
584 | </dt> | |
585 | ||
586 | ||
485 | 587 | <dt><a href="api/smb_SMBConnection.html#smb.SMBConnection.SMBConnection.SIGN_NEVER">SIGN_NEVER (smb.SMBConnection.SMBConnection attribute)</a> |
486 | 588 | </dt> |
487 | 589 | |
501 | 603 | </dt> |
502 | 604 | |
503 | 605 | </dl></dd> |
606 | </dl></td> | |
607 | <td style="width: 33%" valign="top"><dl> | |
504 | 608 | |
505 | 609 | <dt><a href="api/smb_SMBConnection.html#smb.SMBConnection.SMBConnection.SIGN_WHEN_SUPPORTED">SIGN_WHEN_SUPPORTED (smb.SMBConnection.SMBConnection attribute)</a> |
506 | 610 | </dt> |
511 | 615 | </dt> |
512 | 616 | |
513 | 617 | </dl></dd> |
514 | </dl></td> | |
515 | <td style="width: 33%" valign="top"><dl> | |
618 | ||
619 | <dt><a href="api/smb_security_descriptors.html#module-smb.security_descriptors">smb.security_descriptors (module)</a> | |
620 | </dt> | |
621 | ||
516 | 622 | |
517 | 623 | <dt><a href="api/smb_SMBConnection.html#smb.SMBConnection.SMBConnection">SMBConnection (class in smb.SMBConnection)</a> |
518 | 624 | </dt> |
539 | 645 | <dt><a href="api/smb_SMBConnection.html#smb.SMBConnection.SMBConnection.storeFileFromOffset">storeFileFromOffset() (smb.SMBConnection.SMBConnection method)</a> |
540 | 646 | </dt> |
541 | 647 | |
648 | ||
649 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SID.subauthorities">subauthorities (smb.security_descriptors.SID attribute)</a> | |
650 | </dt> | |
651 | ||
542 | 652 | </dl></td> |
543 | 653 | </tr></table> |
544 | 654 | |
549 | 659 | <dt><a href="api/smb_SharedDevice.html#smb.base.SharedDevice.type">type (smb.base.SharedDevice attribute)</a> |
550 | 660 | </dt> |
551 | 661 | |
662 | <dd><dl> | |
663 | ||
664 | <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACE.type">(smb.security_descriptors.ACE attribute)</a> | |
665 | </dt> | |
666 | ||
667 | </dl></dd> | |
552 | 668 | </dl></td> |
553 | 669 | </tr></table> |
554 | 670 | |
575 | 691 | <li class="right" style="margin-right: 10px"> |
576 | 692 | <a href="#" title="General Index" |
577 | 693 | >index</a></li> |
578 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.1.18 documentation</a> »</li> | |
694 | <li class="right" > | |
695 | <a href="py-modindex.html" title="Python Module Index" | |
696 | >modules</a> |</li> | |
697 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.2.1 documentation</a> »</li> | |
579 | 698 | </ul> |
580 | 699 | </div> |
581 | 700 | <div class="footer" role="contentinfo"> |
582 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
701 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
583 | 702 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
584 | 703 | </div> |
585 | 704 | </body> |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>Welcome to pysmb’s documentation! — pysmb 1.1.18 documentation</title> | |
8 | <title>Welcome to pysmb’s documentation! — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: './', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
22 | 22 | <script type="text/javascript" src="_static/jquery.js"></script> |
23 | 23 | <script type="text/javascript" src="_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="_static/doctools.js"></script> |
25 | <link rel="top" title="pysmb 1.1.18 documentation" href="#" /> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="#" /> | |
26 | 26 | <link rel="next" title="NBNSProtocol Class" href="api/nmb_NBNSProtocol.html" /> |
27 | 27 | </head> |
28 | 28 | <body role="document"> |
33 | 33 | <a href="genindex.html" title="General Index" |
34 | 34 | accesskey="I">index</a></li> |
35 | 35 | <li class="right" > |
36 | <a href="py-modindex.html" title="Python Module Index" | |
37 | >modules</a> |</li> | |
38 | <li class="right" > | |
36 | 39 | <a href="api/nmb_NBNSProtocol.html" title="NBNSProtocol Class" |
37 | 40 | accesskey="N">next</a> |</li> |
38 | <li class="nav-item nav-item-0"><a href="#">pysmb 1.1.18 documentation</a> »</li> | |
41 | <li class="nav-item nav-item-0"><a href="#">pysmb 1.2.1 documentation</a> »</li> | |
39 | 42 | </ul> |
40 | 43 | </div> |
41 | 44 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
87 | 90 | <h1>Welcome to pysmb’s documentation!<a class="headerlink" href="#welcome-to-pysmb-s-documentation" title="Permalink to this headline">¶</a></h1> |
88 | 91 | <p>pysmb is a pure Python implementation of the client-side SMB/CIFS protocol (SMB1 and SMB2) which is the underlying protocol |
89 | 92 | that facilitates file sharing and printing between Windows machines, as well as with Linux machines via the Samba server application. |
90 | pysmb is developed in Python 2.4.6, Python 2.7.1 and Python 3.2.3 and has been tested against shared folders on Windows XP SP3, Windows Vista, Windows 7 and Samba 3.x.</p> | |
91 | <p>The latest version of pysmb is always available at the pysmb project page at <a class="reference external" href="http://miketeo.net/wp/index.php/projects/pysmb">miketeo.net</a>.</p> | |
93 | pysmb is developed in Python 2.7.x and Python 3.5.x and has been tested against shared folders on Windows XP SP3, Windows Vista, Windows 7 and Samba 3.x.</p> | |
94 | <p>The latest version of pysmb is always available at the pysmb project page at <a class="reference external" href="http://miketeo.net/projects/pysmb">miketeo.net</a>.</p> | |
92 | 95 | <div class="section" id="license"> |
93 | 96 | <h2>License<a class="headerlink" href="#license" title="Permalink to this headline">¶</a></h2> |
94 | 97 | <p>pysmb itself is licensed under an opensource license. |
172 | 175 | <li>Read <a class="reference internal" href="extending.html"><em>Extending pysmb For Other Frameworks</em></a></li> |
173 | 176 | </ul> |
174 | 177 | </dd> |
178 | <dt>If you are upgrading from older pysmb versions:</dt> | |
179 | <dd><ul class="first last simple"> | |
180 | <li>Read <a class="reference internal" href="upgrading.html"><em>Upgrading from older pysmb versions</em></a></li> | |
181 | </ul> | |
182 | </dd> | |
175 | 183 | </dl> |
176 | 184 | </div> |
177 | 185 | <div class="section" id="indices-and-tables"> |
186 | 194 | <li class="toctree-l1"><a class="reference internal" href="api/smb_SharedDevice.html">SharedDevice Class</a></li> |
187 | 195 | <li class="toctree-l1"><a class="reference internal" href="api/smb_SharedFile.html">SharedFile Class</a></li> |
188 | 196 | <li class="toctree-l1"><a class="reference internal" href="api/smb_exceptions.html">SMB Exceptions</a></li> |
197 | <li class="toctree-l1"><a class="reference internal" href="api/smb_security_descriptors.html">Security Descriptors</a></li> | |
189 | 198 | <li class="toctree-l1"><a class="reference internal" href="extending.html">Extending pysmb For Other Frameworks</a></li> |
199 | <li class="toctree-l1"><a class="reference internal" href="upgrading.html">Upgrading from older pysmb versions</a></li> | |
190 | 200 | </ul> |
191 | 201 | </div> |
192 | 202 | <ul class="simple"> |
208 | 218 | <a href="genindex.html" title="General Index" |
209 | 219 | >index</a></li> |
210 | 220 | <li class="right" > |
221 | <a href="py-modindex.html" title="Python Module Index" | |
222 | >modules</a> |</li> | |
223 | <li class="right" > | |
211 | 224 | <a href="api/nmb_NBNSProtocol.html" title="NBNSProtocol Class" |
212 | 225 | >next</a> |</li> |
213 | <li class="nav-item nav-item-0"><a href="#">pysmb 1.1.18 documentation</a> »</li> | |
226 | <li class="nav-item nav-item-0"><a href="#">pysmb 1.2.1 documentation</a> »</li> | |
214 | 227 | </ul> |
215 | 228 | </div> |
216 | 229 | <div class="footer" role="contentinfo"> |
217 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
230 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
218 | 231 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
219 | 232 | </div> |
220 | 233 | </body> |
Binary diff not shown
0 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
1 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
2 | ||
3 | ||
4 | <html xmlns="http://www.w3.org/1999/xhtml"> | |
5 | <head> | |
6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
7 | ||
8 | <title>Python Module Index — pysmb 1.2.1 documentation</title> | |
9 | ||
10 | <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" /> | |
11 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> | |
12 | ||
13 | <script type="text/javascript"> | |
14 | var DOCUMENTATION_OPTIONS = { | |
15 | URL_ROOT: './', | |
16 | VERSION: '1.2.1', | |
17 | COLLAPSE_INDEX: false, | |
18 | FILE_SUFFIX: '.html', | |
19 | HAS_SOURCE: true | |
20 | }; | |
21 | </script> | |
22 | <script type="text/javascript" src="_static/jquery.js"></script> | |
23 | <script type="text/javascript" src="_static/underscore.js"></script> | |
24 | <script type="text/javascript" src="_static/doctools.js"></script> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="index.html" /> | |
26 | ||
27 | ||
28 | ||
29 | </head> | |
30 | <body role="document"> | |
31 | <div class="related" role="navigation" aria-label="related navigation"> | |
32 | <h3>Navigation</h3> | |
33 | <ul> | |
34 | <li class="right" style="margin-right: 10px"> | |
35 | <a href="genindex.html" title="General Index" | |
36 | accesskey="I">index</a></li> | |
37 | <li class="right" > | |
38 | <a href="#" title="Python Module Index" | |
39 | >modules</a> |</li> | |
40 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.2.1 documentation</a> »</li> | |
41 | </ul> | |
42 | </div> | |
43 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> | |
44 | <div class="sphinxsidebarwrapper"> | |
45 | <div id="searchbox" style="display: none" role="search"> | |
46 | <h3>Quick search</h3> | |
47 | <form class="search" action="search.html" method="get"> | |
48 | <input type="text" name="q" /> | |
49 | <input type="submit" value="Go" /> | |
50 | <input type="hidden" name="check_keywords" value="yes" /> | |
51 | <input type="hidden" name="area" value="default" /> | |
52 | </form> | |
53 | <p class="searchtip" style="font-size: 90%"> | |
54 | Enter search terms or a module, class or function name. | |
55 | </p> | |
56 | </div> | |
57 | <script type="text/javascript">$('#searchbox').show(0);</script> | |
58 | </div> | |
59 | </div> | |
60 | ||
61 | <div class="document"> | |
62 | <div class="documentwrapper"> | |
63 | <div class="bodywrapper"> | |
64 | <div class="body" role="main"> | |
65 | ||
66 | ||
67 | <h1>Python Module Index</h1> | |
68 | ||
69 | <div class="modindex-jumpbox"> | |
70 | <a href="#cap-s"><strong>s</strong></a> | |
71 | </div> | |
72 | ||
73 | <table class="indextable modindextable" cellspacing="0" cellpadding="2"> | |
74 | <tr class="pcap"><td></td><td> </td><td></td></tr> | |
75 | <tr class="cap" id="cap-s"><td></td><td> | |
76 | <strong>s</strong></td><td></td></tr> | |
77 | <tr> | |
78 | <td><img src="_static/minus.png" class="toggler" | |
79 | id="toggle-1" style="display: none" alt="-" /></td> | |
80 | <td> | |
81 | <code class="xref">smb</code></td><td> | |
82 | <em></em></td></tr> | |
83 | <tr class="cg-1"> | |
84 | <td></td> | |
85 | <td> | |
86 | <a href="api/smb_security_descriptors.html#module-smb.security_descriptors"><code class="xref">smb.security_descriptors</code></a></td><td> | |
87 | <em>Data structures used in Windows security descriptors.</em></td></tr> | |
88 | </table> | |
89 | ||
90 | ||
91 | </div> | |
92 | </div> | |
93 | </div> | |
94 | <div class="clearer"></div> | |
95 | </div> | |
96 | <div class="related" role="navigation" aria-label="related navigation"> | |
97 | <h3>Navigation</h3> | |
98 | <ul> | |
99 | <li class="right" style="margin-right: 10px"> | |
100 | <a href="genindex.html" title="General Index" | |
101 | >index</a></li> | |
102 | <li class="right" > | |
103 | <a href="#" title="Python Module Index" | |
104 | >modules</a> |</li> | |
105 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.2.1 documentation</a> »</li> | |
106 | </ul> | |
107 | </div> | |
108 | <div class="footer" role="contentinfo"> | |
109 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
110 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. | |
111 | </div> | |
112 | </body> | |
113 | </html>⏎ |
5 | 5 | <head> |
6 | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
7 | 7 | |
8 | <title>Search — pysmb 1.1.18 documentation</title> | |
8 | <title>Search — pysmb 1.2.1 documentation</title> | |
9 | 9 | |
10 | 10 | <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" /> |
11 | 11 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
13 | 13 | <script type="text/javascript"> |
14 | 14 | var DOCUMENTATION_OPTIONS = { |
15 | 15 | URL_ROOT: './', |
16 | VERSION: '1.1.18', | |
16 | VERSION: '1.2.1', | |
17 | 17 | COLLAPSE_INDEX: false, |
18 | 18 | FILE_SUFFIX: '.html', |
19 | 19 | HAS_SOURCE: true |
23 | 23 | <script type="text/javascript" src="_static/underscore.js"></script> |
24 | 24 | <script type="text/javascript" src="_static/doctools.js"></script> |
25 | 25 | <script type="text/javascript" src="_static/searchtools.js"></script> |
26 | <link rel="top" title="pysmb 1.1.18 documentation" href="index.html" /> | |
26 | <link rel="top" title="pysmb 1.2.1 documentation" href="index.html" /> | |
27 | 27 | <script type="text/javascript"> |
28 | 28 | jQuery(function() { Search.loadIndex("searchindex.js"); }); |
29 | 29 | </script> |
39 | 39 | <li class="right" style="margin-right: 10px"> |
40 | 40 | <a href="genindex.html" title="General Index" |
41 | 41 | accesskey="I">index</a></li> |
42 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.1.18 documentation</a> »</li> | |
42 | <li class="right" > | |
43 | <a href="py-modindex.html" title="Python Module Index" | |
44 | >modules</a> |</li> | |
45 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.2.1 documentation</a> »</li> | |
43 | 46 | </ul> |
44 | 47 | </div> |
45 | 48 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
87 | 90 | <li class="right" style="margin-right: 10px"> |
88 | 91 | <a href="genindex.html" title="General Index" |
89 | 92 | >index</a></li> |
90 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.1.18 documentation</a> »</li> | |
93 | <li class="right" > | |
94 | <a href="py-modindex.html" title="Python Module Index" | |
95 | >modules</a> |</li> | |
96 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.2.1 documentation</a> »</li> | |
91 | 97 | </ul> |
92 | 98 | </div> |
93 | 99 | <div class="footer" role="contentinfo"> |
94 | © Copyright 2001-2015, Michael Teo http://miketeo.net/. | |
100 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
95 | 101 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. |
96 | 102 | </div> |
97 | 103 | </body> |
0 | Search.setIndex({envversion:46,filenames:["api/nmb_NBNSProtocol","api/nmb_NetBIOS","api/smb_SMBConnection","api/smb_SMBHandler","api/smb_SMBProtocolFactory","api/smb_SharedDevice","api/smb_SharedFile","api/smb_exceptions","extending","index"],objects:{"nmb.NetBIOS":{NetBIOS:[1,0,1,""]},"nmb.NetBIOS.NetBIOS":{"__init__":[1,1,1,""],close:[1,1,1,""],queryIPForName:[1,1,1,""],queryName:[1,1,1,""]},"nmb.NetBIOSProtocol":{NBNSProtocol:[0,0,1,""],NetBIOSTimeout:[0,0,1,""]},"nmb.NetBIOSProtocol.NBNSProtocol":{"__init__":[0,1,1,""],queryIPForName:[0,1,1,""],queryName:[0,1,1,""]},"smb.SMBConnection":{SMBConnection:[2,0,1,""]},"smb.SMBConnection.SMBConnection":{"__init__":[2,1,1,""],SIGN_NEVER:[2,2,1,""],SIGN_WHEN_REQUIRED:[2,2,1,""],SIGN_WHEN_SUPPORTED:[2,2,1,""],close:[2,1,1,""],connect:[2,1,1,""],createDirectory:[2,1,1,""],deleteDirectory:[2,1,1,""],deleteFiles:[2,1,1,""],echo:[2,1,1,""],getAttributes:[2,1,1,""],isUsingSMB2:[2,2,1,""],listPath:[2,1,1,""],listShares:[2,1,1,""],listSnapshots:[2,1,1,""],rename:[2,1,1,""],resetFileAttributes:[2,1,1,""],retrieveFile:[2,1,1,""],retrieveFileFromOffset:[2,1,1,""],storeFile:[2,1,1,""],storeFileFromOffset:[2,1,1,""]},"smb.SMBProtocol":{SMBProtocolFactory:[4,0,1,""]},"smb.SMBProtocol.SMBProtocolFactory":{"__init__":[4,1,1,""],SIGN_NEVER:[4,2,1,""],SIGN_WHEN_REQUIRED:[4,2,1,""],SIGN_WHEN_SUPPORTED:[4,2,1,""],closeConnection:[4,1,1,""],createDirectory:[4,1,1,""],deleteDirectory:[4,1,1,""],deleteFiles:[4,1,1,""],echo:[4,1,1,""],getAttributes:[4,1,1,""],instance:[4,2,1,""],isReady:[4,2,1,""],isUsingSMB2:[4,2,1,""],listPath:[4,1,1,""],listShares:[4,1,1,""],listSnapshots:[4,1,1,""],onAuthFailed:[4,1,1,""],onAuthOK:[4,1,1,""],rename:[4,1,1,""],retrieveFile:[4,1,1,""],retrieveFileFromOffset:[4,1,1,""],storeFile:[4,1,1,""]},"smb.base":{NotConnectedError:[7,0,1,""],NotReadyError:[7,0,1,""],SMBTimeout:[7,0,1,""],SharedDevice:[5,0,1,""],SharedFile:[6,0,1,""]},"smb.base.SharedDevice":{comments:[5,2,1,""],isSpecial:[5,2,1,""],isTemporary:[5,2,1,""],name:[5,2,1,""],type:[5,2,1,""]},"smb.base.SharedFile":{alloc_size:[6,2,1,""],create_time:[6,2,1,""],file_attributes:[6,2,1,""],file_size:[6,2,1,""],filename:[6,2,1,""],isDirectory:[6,2,1,""],isReadOnly:[6,2,1,""],last_access_time:[6,2,1,""],last_attr_change_time:[6,2,1,""],last_write_time:[6,2,1,""],short_name:[6,2,1,""]},"smb.smb_structs":{OperationFailure:[7,0,1,""],ProtocolError:[7,0,1,""],UnsupportedFeature:[7,0,1,""]}},objnames:{"0":["py","class","Python class"],"1":["py","method","Python method"],"2":["py","attribute","Python attribute"]},objtypes:{"0":"py:class","1":"py:method","2":"py:attribute"},terms:{"3rd":9,"60kbyte":4,"\u5783\u573e\u6587\u4ef6":3,"\u6d4b\u8bd5\u6587\u4ef6\u5939":3,"__init__":[0,1,2,4,8],"abstract":9,"boolean":[0,1,2,4],"byte":[2,4,6],"case":4,"default":[2,4],"float":[0,1,4,6],"function":[0,1,2,4,9],"import":[2,3,4,9],"int":[2,4],"long":[2,4,6],"new":[1,2,4,8],"public":4,"return":[0,1,2,3,4,5,6,9],"short":6,"true":[0,1,2,4,5,6],"try":[2,4,8],"while":7,aaa:[0,1],about:[2,4,5,6],abov:8,accept:[4,8],access:[2,4,6],accur:4,acknowledg:4,across:[2,4],actual:2,add:[0,4],addcallback:[0,4],adderrback:4,address:[0,1,3,8,9],admin:5,administr:5,after:[0,1,2,4,9],again:0,against:9,algorithm:[2,4,8,9],all:[2,4,9],alloc:6,alloc_s:6,allow:[0,2,4],alon:9,alphanumer:[2,4],alreadi:2,also:[2,4,5],alwai:9,anderson:[0,1],ani:[1,2,4,6,9],appli:[2,4],applic:[0,1,4,6,9],appropri:[0,1],arbitari:[2,4],archiv:[2,4],arg:4,around:0,ascii:[2,4],asn:9,aspx:2,assert:2,asynchron:[0,2,8],attempt:2,attribut:[2,4,6],atttempt:2,auth:4,authent:[2,4,7,8,9],authenthent:4,auto:[2,4],automat:[0,1,2,4],avail:[2,4,9],avoid:4,back:[0,1,2,4],base:[2,4,5,6,7,8,9],batch:4,bbb:[0,1],been:[2,4,7,8,9],befor:[2,4],begin:[2,4],between:9,bind:[0,1],bit:[2,4,9],bitwis:[2,4],blob:9,block:[0,1,2,9],both:[2,4],briefli:8,broadcast:[0,1],buffer:8,build_open:3,busi:[2,4],call:[0,1,2,4,6,8],callback:[0,4,8],can:[0,1,2,3,4,5,8,9],cannot:[2,3,4],captur:[2,4],care:8,cc232110:2,ccc:[0,1],chang:6,charact:[2,3,4,6],choic:[2,4],choos:[2,4],cif:[1,2,4,6,7,8,9],clear:2,click:[2,4],client:[2,4,9],client_machine_nam:[2,4],close:[1,2,3,4],closeconnect:4,code:3,com:2,come:9,comm_devic:5,command:[2,4],comment:5,commerci:9,commun:[2,4,5,9],compat:[2,4],complet:[2,4,7,9],compon:[2,3,4],comput:[2,4],concurr:[2,4],configur:[2,4],conflict:9,conn:2,connect:[2,4,7,8],connecttcp:4,constant:[5,9],constructor:8,contain:[1,2,4,5,6,9],content:[2,4],continu:[2,4],contribut:[0,1],control:[2,4],conveni:[2,4,6],copi:[2,4,9],correspond:6,could:[6,9],cover:9,creat:[0,1,2,3,4,8],create_tim:6,createdirectori:[2,4],creation:[5,6],credenti:[2,4],credienti:4,current:[2,7],dat:3,data:[2,3,4,8,9],data_buf:7,datetim:[2,4],ddd:[0,1],decod:9,def:4,defer:[0,4],defin:[0,1],delet:[2,3,4],deletedirectori:[2,4],deletefil:[2,4],depend:9,describ:[2,8],descript:5,detail:[6,8,9],detect:[2,4],determin:[0,1,2,4,9],develop:[2,6,9],devic:[5,6],dialect:9,differ:[2,4,8,9],digest:9,direct:[2,4],directli:[4,6],director:3,directori:[2,3,4,6],disabl:[2,4],disconnect:[2,4,7],discret:9,disk_tre:5,dixon:9,dmitri:9,doe:[2,4,6,9],domain:[2,4,9],done:[0,1],dot:[0,1],download:[4,9],due:8,each:[1,2,4,5,6],earliest:4,echo:[2,4],edit:[2,4],either:[2,4],element:[2,4],els:[2,4],empti:[0,1,2,3,4,6],enabl:[2,4],encod:9,encount:[2,6],encrypt:9,end:[2,4],english:[2,4],enterpris:[2,4],entir:4,entri:6,eof:[2,4],errback:[0,4],error:[2,4,8],establish:[2,4],etc:4,excee:4,except:[0,4],exercis:9,exist:[2,3,4],expos:4,facilit:9,factori:4,fail:[2,4,7,8],failur:0,fallback:[2,4],fals:[0,1,2,4],familiar:9,featur:[2,4,7],feeddata:8,fh2:3,file:[2,3,4,5,6,8,9],file_attribut:[2,4,6],file_attribute_norm:2,file_fh:3,file_obj:[2,4],file_s:[4,6],filenam:[2,4,6],fileretriev:4,files:2,filter:[2,4],find:[2,4,8],first:[2,3,4],flag:[0,1,2,4],folder:[2,3,4,6,9],follow:[2,3,4,5,9],forth:5,framework:[0,4],free:[0,1,9],freeli:[2,4],from:[0,1,2,3,4,8,9],functionl:4,further:2,gener:8,getattribut:[2,4],gmt:[2,4],googl:9,guess:[2,4],handl:[4,8],hash:9,have:[0,2,8,9],held:2,help:2,henc:[2,4,9],hidden:[2,4],hope:[0,1],host:[2,3,4],hostnam:3,http:2,iana:[0,1],identifi:[2,4],idl:2,illustr:[2,3,4],immedi:[2,4],implement:[0,1,2,4,8,9],impos:[2,4],includ:[8,9],incom:0,incomplet:8,index:9,indic:[0,1,2,4],individu:4,inform:[2,4,5,6],initi:[5,8],insid:[2,4],instal:[2,4,9],instanc:[0,1,2,4,6],instanti:[0,1,4,6],instiant:[0,1],integ:[0,1,2,4,6,9],integr:[5,9],interest:[2,4],intern:[4,8,9],internet:[0,4],interprocess:5,interv:4,invok:[2,4],involv:8,ipc:5,ipv4:1,is_direct_tcp:[2,4],isdirectori:6,isreadi:4,isreadonli:6,isspeci:5,istemporari:5,isusingsmb2:[2,4],itself:[4,9],jason:[0,1],just:[0,4],keep:2,keepal:2,know:[0,1,4],known:[2,4],kwarg:4,last:6,last_access_tim:6,last_attr_change_tim:6,last_write_tim:6,latest:9,learn:[2,4],least:2,leav:[0,1,2,4],length:6,lgpl:9,librari:[2,9],like:[2,3,4],limit:[2,4,6],linux:9,list:[0,1,2,4,9],listen:[0,1],listen_port:[0,1],listenudp:0,listpath:[2,4,6],listshar:[2,4],listsnapshot:[2,4],local:[2,4],local_fil:3,look:9,loop:8,loseconnect:4,machin:[0,1,2,3,4,9],made:[2,4,9],mai:[2,4],main:9,match:[0,1,2,4],max_length:[2,4],maximum:[2,4],md4:9,mean:4,meant:2,mechan:[2,4],messag:[2,4,7,9],method:[0,1,2,3,4,6,8],microsoft:[2,9],might:[2,4],miketeo:9,mit:9,mode:[0,1],modif:6,modifi:9,modul:[2,4,9],more:[2,4,6,8,9],most:[2,4,8,9],msdn:2,multipl:[2,4],must:[0,2,4],my_nam:[2,4],mypassword:3,myuserid:3,name:[0,1,2,3,4,5,6,9],namedtemporaryfil:[2,4],nbn:[1,9],need:[2,3,4,6,8,9],neg:[2,4],net:9,netbio:0,netbiosprotocol:[0,9],netbiossess:9,netbiostimeout:0,network:[0,1,2,4,9],never:[2,4],new_path:[2,4],newer:[2,4],next:2,nmb:[0,1,9],non:[2,4],none:[0,1,2,4,5,6,7],notat:[0,1,6],notconnectederror:[4,7],note:2,notreadyerror:[4,7],now:8,ntlm:[4,8,9],ntlmssp:9,ntlmv1:[2,4,9],ntlmv2:[2,4,9],number:[0,1,2,4,6],obj:[2,4],object:[2,3,4],occur:[2,4,7],offset:[2,4],often:8,old:[2,4],old_path:[2,4],onauthfail:[4,8],onauthok:[4,8],onc:[4,8],onli:[2,3,4,6,9],onnmbsessionfail:8,open:[2,3,4,9],opensourc:9,oper:[1,2,4,7,8,9],operationfailur:[2,4,7],opportun:4,organ:9,origin:[2,4,6],other:[2,4],otherwis:[2,4],out:[2,4],over:[2,4,9],overrid:[4,8],overwritten:[2,4],own:[4,8,9],packag:3,packet:[0,1,4,8],page:[8,9],paramet:[0,1,2,3,4,8,9],parent:3,pars:9,part:8,parti:9,pass:[2,3,4],password:[2,4],path:[2,3,4],path_file_pattern:[2,4],pathnam:[2,4],pattern:[2,4],perform:[0,1,2,4,8],period:4,persist:5,place:9,pleas:9,point:3,port:[0,1,2,4],posit:[2,4],possibl:9,post:[4,8],precis:4,present:7,print:[4,9],print_queu:5,proce:4,proceed:[2,4],process:[3,8],prohibit:6,project:[0,4,9],promis:9,properti:[2,4,6],protocol:[2,4,7,9],protocolerror:7,provid:[0,1,2,3,4,8,9],pure:9,purpos:9,pyasn1:9,pyde:9,pymsb:4,pysmb:[0,2,4,7],python:[2,3,4,9],queri:[0,1,2,4,9],queryipfornam:[0,1],querynam:[0,1],queue:4,rais:[0,2,3,4,7],reactor:[0,4],read:[2,3,4,6,8,9],readi:[4,7],receiv:[0,1,2,4],refer:[2,4,5,9],referenc:9,regardless:[2,4],regular:[2,4],reject:[2,4],rel:[2,4],relat:9,releas:[1,2],remot:[1,2,4,5,6,8],remote_nam:[2,4,8],remov:0,renam:[2,4],repli:[0,1,2,4],report:8,request:[2,4],requir:[2,4,7],reserv:5,reset:2,resetfileattribut:2,resourc:[1,2,4,6],respond:2,respons:7,result:[0,2,4],retri:4,retriev:[2,3,4],retrievefil:[2,4],retrievefilefactori:4,retrievefilefromoffset:[2,4],reus:4,rfc1001:[2,3,4],right:[2,4],routin:9,rozmanov:9,safe:[2,4],samba:9,sambda:[2,4],same:[2,4],search:[2,4,9],sec:4,second:[0,1,4,6],section:9,secur:9,securityblob:9,see:[2,4,6],seek:[2,4],select:[0,1,2,4],self:[4,8],send:[0,1,2,4],separ:9,sequenti:2,seri:4,server:[2,4,5,6,8,9],server_ip:[2,4],server_nam:[2,4],servic:[1,2,4,8,9],service_nam:[2,4],session:[8,9],set:[2,4],setup:[0,1,4,8],sha256:9,sha:9,shadow:[2,4],share:[2,3,4,5,6,9],shareddevic:[2,4],sharedfil:[2,4],sharedfold:3,short_nam:6,should:[0,1,2,4,6],side:9,sign:[2,4],sign_nev:[2,4],sign_opt:[2,4],sign_when_requir:[2,4],sign_when_support:[2,4],simpl:[2,4],simpli:3,sinc:6,singl:[2,4,5],site:9,size:[4,6],smb1:[2,4,9],smb2_constant:9,smb2_struct:9,smb:[1,2,3,4,5,6],smb_constant:[2,4,9],smb_ext_file_attr:6,smb_file_attribute_xxx:[2,4],smb_messag:7,smb_struct:[2,4,7,9],smbprotocol:[4,6,9],smbtest:[2,4],smbtimeout:[4,7],snapshot:[2,4],snippet:3,sock_famili:2,socket:[1,2,8],softwar:9,some:[2,4,9],sort:2,sourc:[0,1,2,4,5,6,7,9],sp3:9,space:[2,4],special:5,specif:9,specifi:[0,1,2,4],standard:[0,1,9],start:[0,2,4],step:8,stoplisten:0,store:[2,4,6],storefil:[2,4],storefilefromoffset:2,string:[0,1,2,3,4,5,6],style:9,sub:[2,4],subclass:[4,8],subsequ:3,success:[2,8],successfulli:[2,4],suitabl:[2,9],support_smb2:[2,4],synchron:[8,9],system:[2,4],take:[8,9],target:[0,1],tcp:[2,4,8],technic:[2,8],tempfil:[2,4],temporari:5,term:9,termin:[2,4],test:9,than:[2,4],thei:9,therefor:2,thi:[0,1,2,4,5,6,8,9],thoma:9,those:4,thousand:4,through:4,time:[2,4,5,6,9],timeout:[0,1,2,4,7],todd:9,togeth:9,too:2,total:6,touch:[0,1,4],transfer:[4,9],translat:9,transmit:4,transport:[0,4,9],truncat:2,tupl:[2,4],twist:[0,4,9],txt:[2,3,4],type:5,u32:9,udp:[0,1],ultim:[2,4],under:9,underli:[1,2,4,7,9],unicod:[2,3,4,5,6],unless:[0,1],unlock:2,unsign:9,unsupportedfeatur:7,until:[1,2,4],upload:[2,3,4],upload_fil:3,url:[3,9],urlerror:3,urllib2:[3,9],use_ntlm_v2:[2,4,8],user:[2,4,5],userid:[2,4],usernam:[2,4],usual:[2,4,6,8,9],utc:[2,4],utf:3,util:[2,4],valid:3,valu:[2,4,6],variou:9,veri:2,version:9,via:[0,4,6,9],vista:[2,4,9],wait:[0,1,4,7],want:[4,9],web:9,well:9,what:[0,1,2,4,8],when:[0,1,2,4,7,8,9],where:[2,4,6,9],whether:[2,4],which:[0,1,2,4,6,8,9],whiteman:9,who:[2,4,9],whose:9,wider:[2,4],wildcard:[2,4],window:[2,3,4,6,9],wish:[1,2],within:[2,4,9],without:[0,9],workgroup:[2,4],wrap:0,write:[2,4,8],write_result:4,written:[2,4],wrong:8,yet:7,you:[0,1,2,3,4,6,8,9],your:[0,1,2,4,6,8,9],yourself:9,zero:[0,1,2,4],zone:[2,4]},titles:["NBNSProtocol Class","NetBIOS class","SMBConnection Class","SMbHandler Class","SMBProtocolFactory Class","SharedDevice Class","SharedFile Class","SMB Exceptions","Extending pysmb For Other Frameworks","Welcome to pysmb’s documentation!"],titleterms:{"class":[0,1,2,3,4,5,6],caveat:[2,4],content:9,credit:9,descript:9,document:9,exampl:[2,3,4],except:7,extend:8,framework:8,indic:9,licens:9,nbnsprotocol:0,netbio:1,note:3,other:8,packag:9,pysmb:[8,9],shareddevic:5,sharedfil:6,smb2:[2,4],smb:7,smbconnect:2,smbhandler:3,smbprotocolfactori:4,support:[2,4],tabl:9,welcom:9}})⏎ | |
0 | Search.setIndex({envversion:46,filenames:["api/nmb_NBNSProtocol","api/nmb_NetBIOS","api/smb_SMBConnection","api/smb_SMBHandler","api/smb_SMBProtocolFactory","api/smb_SharedDevice","api/smb_SharedFile","api/smb_exceptions","api/smb_security_descriptors","extending","index","upgrading"],objects:{"nmb.NetBIOS":{NetBIOS:[1,0,1,""]},"nmb.NetBIOS.NetBIOS":{"__init__":[1,1,1,""],close:[1,1,1,""],queryIPForName:[1,1,1,""],queryName:[1,1,1,""]},"nmb.NetBIOSProtocol":{NBNSProtocol:[0,0,1,""],NetBIOSTimeout:[0,0,1,""]},"nmb.NetBIOSProtocol.NBNSProtocol":{"__init__":[0,1,1,""],queryIPForName:[0,1,1,""],queryName:[0,1,1,""]},"smb.SMBConnection":{SMBConnection:[2,0,1,""]},"smb.SMBConnection.SMBConnection":{"__init__":[2,1,1,""],SIGN_NEVER:[2,2,1,""],SIGN_WHEN_REQUIRED:[2,2,1,""],SIGN_WHEN_SUPPORTED:[2,2,1,""],close:[2,1,1,""],connect:[2,1,1,""],createDirectory:[2,1,1,""],deleteDirectory:[2,1,1,""],deleteFiles:[2,1,1,""],echo:[2,1,1,""],getAttributes:[2,1,1,""],getSecurity:[2,1,1,""],isUsingSMB2:[2,2,1,""],listPath:[2,1,1,""],listShares:[2,1,1,""],listSnapshots:[2,1,1,""],rename:[2,1,1,""],resetFileAttributes:[2,1,1,""],retrieveFile:[2,1,1,""],retrieveFileFromOffset:[2,1,1,""],storeFile:[2,1,1,""],storeFileFromOffset:[2,1,1,""]},"smb.SMBProtocol":{SMBProtocolFactory:[4,0,1,""]},"smb.SMBProtocol.SMBProtocolFactory":{"__init__":[4,1,1,""],SIGN_NEVER:[4,2,1,""],SIGN_WHEN_REQUIRED:[4,2,1,""],SIGN_WHEN_SUPPORTED:[4,2,1,""],closeConnection:[4,1,1,""],createDirectory:[4,1,1,""],deleteDirectory:[4,1,1,""],deleteFiles:[4,1,1,""],echo:[4,1,1,""],getAttributes:[4,1,1,""],instance:[4,2,1,""],isReady:[4,2,1,""],isUsingSMB2:[4,2,1,""],listPath:[4,1,1,""],listShares:[4,1,1,""],listSnapshots:[4,1,1,""],onAuthFailed:[4,1,1,""],onAuthOK:[4,1,1,""],rename:[4,1,1,""],retrieveFile:[4,1,1,""],retrieveFileFromOffset:[4,1,1,""],storeFile:[4,1,1,""]},"smb.base":{NotConnectedError:[7,0,1,""],NotReadyError:[7,0,1,""],SMBTimeout:[7,0,1,""],SharedDevice:[5,0,1,""],SharedFile:[6,0,1,""]},"smb.base.SharedDevice":{comments:[5,2,1,""],isSpecial:[5,2,1,""],isTemporary:[5,2,1,""],name:[5,2,1,""],type:[5,2,1,""]},"smb.base.SharedFile":{alloc_size:[6,2,1,""],create_time:[6,2,1,""],file_attributes:[6,2,1,""],file_id:[6,2,1,""],file_size:[6,2,1,""],filename:[6,2,1,""],isDirectory:[6,2,1,""],isNormal:[6,2,1,""],isReadOnly:[6,2,1,""],last_access_time:[6,2,1,""],last_attr_change_time:[6,2,1,""],last_write_time:[6,2,1,""],short_name:[6,2,1,""]},"smb.security_descriptors":{ACE:[8,0,1,""],ACL:[8,0,1,""],SID:[8,0,1,""],SecurityDescriptor:[8,0,1,""]},"smb.security_descriptors.ACE":{additional_data:[8,2,1,""],flags:[8,2,1,""],isInheritOnly:[8,2,1,""],mask:[8,2,1,""],sid:[8,2,1,""],type:[8,2,1,""]},"smb.security_descriptors.ACL":{aces:[8,2,1,""],revision:[8,2,1,""]},"smb.security_descriptors.SID":{identifier_authority:[8,2,1,""],revision:[8,2,1,""],subauthorities:[8,2,1,""]},"smb.security_descriptors.SecurityDescriptor":{dacl:[8,2,1,""],flags:[8,2,1,""],group:[8,2,1,""],owner:[8,2,1,""],sacl:[8,2,1,""]},"smb.smb_structs":{OperationFailure:[7,0,1,""],ProtocolError:[7,0,1,""],UnsupportedFeature:[7,0,1,""]},smb:{security_descriptors:[8,3,0,"-"]}},objnames:{"0":["py","class","Python class"],"1":["py","method","Python method"],"2":["py","attribute","Python attribute"],"3":["py","module","Python module"]},objtypes:{"0":"py:class","1":"py:method","2":"py:attribute","3":"py:module"},terms:{"3rd":10,"60kbyte":4,"\u5783\u573e\u6587\u4ef6":3,"\u6d4b\u8bd5\u6587\u4ef6\u5939":3,"__init__":[0,1,2,4,9],"abstract":10,"boolean":[0,1,2,4],"byte":[2,4,6],"case":4,"default":[2,4,11],"float":[0,1,4,6],"function":[0,1,2,4,10],"import":[2,3,4,10],"int":[2,4],"long":[2,4,6],"new":[1,2,4,9,11],"public":4,"return":[0,1,2,3,4,5,6,10,11],"short":6,"switch":11,"true":[0,1,2,4,5,6,11],"try":[2,4,9],"while":7,aaa:[0,1],about:[2,4,5,6],abov:9,accept:[4,9],access:[2,4,6,8],access_mask:8,accord:[],accur:4,ace_type_:8,aceflag:8,acetyp:8,acknowledg:4,acl:8,across:[2,4],actual:2,add:[0,4,11],addcallback:[0,4],adderrback:4,addit:8,additional_data:8,address:[0,1,3,9,10,11],admin:5,administr:5,after:[0,1,2,4,10],again:0,against:10,algorithm:[2,4,9,10],all:[2,4,8,10],alloc:6,alloc_s:6,allow:[0,2,4],alon:10,alphanumer:[2,4],alreadi:2,also:[2,4,5],alwai:[8,10],anderson:[0,1],ani:[1,2,4,6,10],api:11,appli:[2,4,8],applic:[0,1,4,6,10,11],application_data:8,appropri:[0,1],arbitari:[2,4],archiv:[2,4,6,11],arg:4,around:0,ascii:[2,4],asn:10,aspx:2,assert:2,associ:8,asynchron:[0,2,9],attempt:2,attr_xxx:6,attribut:[2,4,5,6,11],attribute_data:8,atttempt:2,audit:8,auth:4,authent:[2,4,7,9,10],authenthent:4,author:8,auto:[2,4],automat:[0,1,2,4],avail:[2,4,5,6,10],avoid:4,back:[0,1,2,4],base:[2,4,5,6,7,9,10],batch:4,bbb:[0,1],been:[2,4,7,9,10],befor:[2,4,11],begin:[2,4],between:10,bind:[0,1],bit:[2,4,6,10],bitmask:8,bitwis:[2,4],blob:10,block:[0,1,2,10],both:[2,4],briefli:9,broadcast:[0,1],buffer:9,build_open:3,busi:[2,4],call:[0,1,2,4,6,9],callabl:2,callback:[0,4,9],can:[0,1,2,3,4,5,6,8,9,10,11],cannot:[2,3,4],captur:[2,4],care:9,cc232110:2,ccc:[0,1],chang:[6,11],charact:[2,3,4,6],choic:[2,4],choos:[2,4],cif:[1,2,4,6,7,9,10],clear:2,click:[2,4],client:[2,4,10],client_machine_nam:[2,4],close:[1,2,3,4],closeconnect:4,code:3,com:[2,3],come:10,comm_devic:5,comma:3,command:[2,4],comment:5,commerci:10,commun:[2,4,5,10],compat:[2,4],complet:[2,4,7,10,11],compon:[2,3,4],compress:[2,4,6,11],comput:[2,4],concurr:[2,4],configur:[2,4],conflict:10,conn:2,connect:[2,4,7,9],connecttcp:4,consist:8,constant:[2,4,5,6,8,10],constructor:9,contain:[1,2,4,5,6,10],content:[],context:11,continu:[2,4],contribut:[0,1],control:[2,4,8,11],conveni:[2,4,6,8],copi:[2,4,10],correspond:[6,8],could:[6,10,11],cover:10,creat:[0,1,2,3,4,9],create_tim:6,createdirectori:[2,4],creation:[5,6],credenti:[2,4],credienti:4,current:[2,7],dacl:8,dat:3,data:[2,3,4,8,9,10],data_buf:7,datetim:[2,4],ddd:[0,1],decod:10,def:4,defer:[0,4],defin:[0,1,2,4,6,11],definit:[],delet:[2,3,4,11],delete_matching_fold:[2,11],deletedirectori:[2,4],deletefil:[2,4,11],depend:[8,10],describ:[2,9],descript:[],descriptor:[],detail:[6,9,10],detect:[2,4],determin:[0,1,2,4,6,10],develop:[2,6,10],devic:[5,6],dialect:10,dictionari:8,differ:[2,4,9,10],digest:10,direct:[2,4],directli:[4,6],director:3,directori:[2,3,4,6,11],disabl:[2,4],disconnect:[2,4,7],discret:10,discretionari:8,disk_tre:5,dixon:10,dmitri:10,doe:[2,4,6,10],doesn:8,domain:[2,4,10],done:[0,1],dot:[0,1],download:[4,10],dtyp:8,due:9,each:[1,2,4,5,6],earliest:4,echo:[2,4],edit:[2,4],either:[2,4],element:[2,4],els:[2,4],empti:[0,1,2,3,4,6],enabl:[2,4],encapsul:8,encod:10,encount:[2,6],encrypt:[2,4,6,10,11],end:[2,4],english:[2,4],enterpris:[2,4],entir:4,entri:[2,4,6,8,11],eof:[2,4],errback:[0,4],error:[2,4,9],establish:[2,4],etc:4,excee:4,except:[],exercis:10,exist:[2,3,4],expos:4,facilit:10,factori:4,fail:[2,4,7,9],failur:0,fallback:[2,4],fals:[0,1,2,4],familiar:10,featur:[2,4,7],feeddata:9,fh2:3,field:[6,8],file:[2,3,4,5,6,9,10,11],file_attribut:[2,4,6],file_attribute_norm:2,file_fh:3,file_id:[6,11],file_obj:[2,4],file_s:[4,6],filenam:[2,4,6],fileretriev:4,files:2,filesystem:11,filter:[2,4],find:[2,4,9],finer:11,first:[2,3,4],flag:[0,1,2,4,8],folder:[2,3,4,6,10,11],follow:[2,3,4,5,6,8,10],format:[],forth:5,framework:[],free:[0,1,10],freeli:[2,4],from:[],fscc:6,fulli:3,functionl:4,further:2,gener:9,getattribut:[2,4,11],getsecur:[2,11],given:11,gmt:[2,4],googl:10,group:8,guess:[2,4],handl:[4,9],hash:10,have:[0,2,9,10,11],held:2,help:2,henc:[2,4,10],hidden:[2,4,6,11],hope:[0,1],host:[2,3,4],hostnam:3,http:2,iana:[0,1],identifi:[2,4,8],identifier_author:8,idl:2,ignor:[2,4,6,11],illustr:[2,3,4],immedi:[2,4],implement:[0,1,2,4,8,9,10],impos:[2,4],improv:11,includ:[2,4,9,10,11],incom:0,incompat:11,incomplet:9,index:[2,4,6,10,11],indic:[],individu:4,inform:[2,4,5,6],inherit:8,inherited_object_typ:8,initi:[5,9],insid:[2,4],instal:[2,4,10],instanc:[0,1,2,4,6,8,11],instanti:[0,1,4,6],instiant:[0,1],integ:[0,1,2,4,6,8,10],integr:[5,10],interest:[2,4],intern:[4,9,10],internet:[0,4],interprocess:5,interv:4,invok:[2,4],involv:9,ipc:5,ipv4:1,is_direct_tcp:[2,4],isdirectori:6,isinheritonli:8,isnorm:[6,11],isreadi:4,isreadonli:[6,11],isspeci:5,istemporari:5,isusingsmb2:[2,4],itself:[2,4,8,10],jason:[0,1],join:[],just:[0,4],keep:2,keepal:2,know:[0,1,4],known:[2,4],kwarg:4,last:6,last_access_tim:6,last_attr_change_tim:6,last_write_tim:6,latest:10,learn:[2,4],least:2,leav:[0,1,2,4],length:[6,8],lgpl:10,librari:[2,10],like:[2,3,4,6,11],limit:[2,4,6],linux:10,list:[0,1,2,4,8,10],listen:[0,1],listen_port:[0,1],listenudp:0,listpath:[2,4,6,11],listshar:[2,4],listsnapshot:[2,4],local:[2,3,4],local_fil:3,log:8,look:10,loop:9,loseconnect:4,machin:[0,1,2,3,4,10,11],made:[2,4,10],mai:[2,4],main:10,manag:11,mask:8,match:[0,1,2,4],max_length:[2,4],maximum:[2,4],md4:10,mean:[4,8],meant:2,mechan:[2,4],messag:[2,4,7,10],method:[0,1,2,3,4,6,9,11],microsoft:[2,10],might:[2,4],miketeo:10,mit:10,mode:[0,1],modif:6,modifi:10,modul:[2,4,8,10],more:[2,4,6,9,10],most:[2,4,9,10,11],msdn:2,multipl:[2,4],must:[0,2,3,4],my_nam:[2,4],mypassword:3,myserv:3,myuserid:3,name:[0,1,2,3,4,5,6,10,11],namedtemporaryfil:[2,4],nbn:[1,10],nbname:3,need:[2,3,4,6,9,10],neg:[2,4],net:10,netbio:[],netbiosprotocol:[0,10],netbiossess:10,netbiostimeout:0,network:[0,1,2,4,10],never:[2,4],new_path:[2,4],newer:[2,4],next:2,nmb:[0,1,10,11],non:[2,4],none:[0,1,2,4,5,6,7,8],normal:[2,4,6,11],notat:[0,1,6],notconnectederror:[4,7],note:[],notreadyerror:[4,7],now:[9,11],ntlm:[4,9,10],ntlmssp:10,ntlmv1:[2,4,10],ntlmv2:[2,4,10],number:[0,1,2,4,6,8,11],obj:[2,4],object:[2,3,4,8],object_typ:8,occur:[2,4,7],offset:[2,4],often:9,old:[2,4],old_path:[2,4],older:[],onauthfail:[4,9],onauthok:[4,9],onc:[4,9],onli:[2,3,4,6,8,10,11],onnmbsessionfail:9,open:[2,3,4,10],opensourc:10,oper:[1,2,4,7,9,10,11],operationfailur:[2,4,7],opportun:4,organ:10,origin:[2,4,6],other:[],otherwis:[2,4],out:[2,4],over:[2,4,10],overrid:[4,9],overwritten:[2,4],own:[2,4,9,10],owner:8,packag:[],packet:[0,1,4,9],page:[9,10,11],paramet:[0,1,2,3,4,9,10,11],parent:3,pars:10,part:9,parti:10,pass:[2,3,4,11],password:[2,4],path:[2,3,4],path_file_pattern:[2,4],pathnam:[2,4],pattern:[2,4],perform:[0,1,2,4,6,9],period:4,persist:5,place:10,pleas:[10,11],point:3,port:[0,1,2,4],posit:[2,4],possibl:10,post:[4,9],pre:[],precis:4,present:[7,8],previou:11,princip:8,print:[4,10],print_queu:5,proce:4,proceed:[2,4],process:[3,9],prohibit:6,project:[0,4,10],promis:10,properti:[2,4,6,8,11],protocol:[2,4,7,10],protocolerror:7,provid:[0,1,2,3,4,9,10],pure:10,purpos:10,pyasn1:10,pyde:10,pymsb:4,pysmb:[],python:[2,3,4,10],qualifi:3,queri:[0,1,2,4,10,11],queryipfornam:[0,1,11],querynam:[0,1],queue:4,rais:[0,2,3,4,7],reactor:[0,4],read:[2,3,4,6,9,10,11],readi:[4,7],receiv:[0,1,2,4],recurs:2,refer:[2,4,5,6,10,11],referenc:10,regardless:[2,4],regular:[2,4],reject:[2,4],rel:[2,4],relat:10,releas:[1,2,11],remot:[1,2,3,4,5,6,9,11],remote_nam:[2,4,9],remov:0,renam:[2,4],repli:[0,1,2,4],report:9,repres:[6,8,11],request:[2,3,4],requir:[2,4,7],reserv:5,reset:2,resetfileattribut:2,resolv:3,resourc:[1,2,4,6],respond:2,respons:7,restrict:8,result:[0,2,4],retri:4,retriev:[2,3,4,11],retrievefil:[2,4],retrievefilefactori:4,retrievefilefromoffset:[2,4,11],reus:4,revis:8,rewrit:11,rewritten:11,rfc1001:[2,3,4],right:[2,4],routin:10,rozmanov:10,sacl:8,safe:[2,4],samba:10,sambda:[2,4],same:[2,4],search:[2,4,10,11],sec:4,second:[0,1,4,6],section:10,secur:[],security_descriptor:[2,8],securityblob:10,securitydescriptor:[2,8],see:[2,4,6,8],seek:[2,4],select:[0,1,2,4],self:[4,9],send:[0,1,2,4],separ:[3,10],sequenc:8,sequenti:2,seri:4,server:[2,4,5,6,9,10,11],server_ip:[2,4],server_nam:[2,4],servic:[1,2,3,4,9,10],service_nam:[2,4],session:[9,10],set:[2,4],setup:[0,1,4,9],sha256:10,sha:10,shadow:[2,4],share:[2,3,4,5,6,10],shareddevic:[],sharedfil:[],sharedfold:3,short_nam:6,should:[0,1,2,4,6,8],sid:8,side:10,sign:[2,4],sign_nev:[2,4],sign_opt:[2,4],sign_when_requir:[2,4],sign_when_support:[2,4],simpl:[2,4],simpli:3,simplic:[2,4],sinc:6,singl:[2,4,5,8],site:10,size:[4,6],smb1:[2,4,10],smb2_constant:10,smb2_struct:10,smb:[],smb_constant:[2,4,6,10],smb_ext_file_attr:6,smb_file_attribute_arch:[2,4],smb_file_attribute_directori:[2,4],smb_file_attribute_hidden:[2,4],smb_file_attribute_incl_norm:[2,4],smb_file_attribute_norm:[2,4],smb_file_attribute_readonli:[2,4],smb_file_attribute_system:[2,4],smb_file_attribute_xxx:[2,4],smb_messag:7,smb_struct:[2,4,7,10],smbprotocol:[4,6,10],smbtest:[2,4],smbtimeout:[4,7],snapshot:[2,4],snippet:3,sock_famili:2,socket:[1,2,9],softwar:10,some:[2,4,10],sort:2,sourc:[0,1,2,4,5,6,7,8,10],sp3:10,space:[2,4],spars:[2,4,6,11],special:5,specif:10,specifi:[0,1,2,4,8,11],standard:[0,1,10],start:[0,2,4],statu:6,step:9,stoplisten:0,store:[2,4,6],storefil:[2,4],storefilefromoffset:[2,11],string:[0,1,2,3,4,5,6],structur:8,style:10,sub:[2,4,11],subauthor:8,subclass:[4,9],subsequ:3,success:[2,9],successfulli:[2,4],suitabl:[2,10],support_smb2:[2,4],synchron:[9,10],system:[2,4,6,8,11],take:[9,10],target:[0,1],tcp:[2,4,9],technic:[2,9],tempfil:[2,4],temporari:[2,4,5,6,11],term:10,termin:[2,4],test:[3,6,10],than:[2,4],thei:10,therefor:2,thi:[0,1,2,4,5,6,8,9,10,11],thoma:10,those:4,thousand:4,through:4,time:[2,4,5,6,10],timeout:[0,1,2,4,7,11],todd:10,togeth:10,too:2,total:6,touch:[0,1,4],transfer:[4,10],translat:10,transmit:4,transport:[0,4,10],truncat:[2,11],truste:8,tupl:[2,4],twist:[0,4,10],two:11,txt:[2,3,4],type:[5,8],type_:8,u32:10,udp:[0,1],ultim:[2,4],under:10,underli:[1,2,4,7,10],unicod:[2,3,4,5,6],unless:[0,1],unlock:2,unsign:10,unsupportedfeatur:7,until:[1,2,4],upgrad:[],upload:[2,3,4],upload_fil:3,url:[3,10],urlerror:3,urllib2:[3,10],urllib:3,use_ntlm_v2:[2,4,9],user:[2,4,5,8],userid:[2,4],usernam:[2,4],usual:[2,4,6,9,10],utc:[2,4],utf:3,util:[2,4],valid:[],valu:[2,4,6,8],variabl:8,variou:10,veri:2,version:[],via:[0,4,6,10],vista:[2,4,10],wait:[0,1,4,7],want:[4,10],web:10,well:10,were:11,what:[0,1,2,4,9],when:[0,1,2,4,7,9,10],where:[2,3,4,6,10],whether:[2,4],which:[0,1,2,4,6,8,9,10,11],whiteman:10,who:[2,4,10],whose:10,wider:[2,4],wildcard:[2,4],window:[2,3,4,6,8,10],wise:6,wish:[1,2],within:[2,4,10],without:[0,2,4,10],workgroup:[2,4,11],wrap:0,write:[2,4,9,11],write_result:4,written:[2,4],wrong:9,yet:7,you:[0,1,2,3,4,6,9,10,11],your:[0,1,2,3,4,6,9,10,11],yourself:10,zero:[0,1,2,4],zone:[2,4]},titles:["NBNSProtocol Class","NetBIOS class","SMBConnection Class","SMbHandler Class","SMBProtocolFactory Class","SharedDevice Class","SharedFile Class","SMB Exceptions","Security Descriptors","Extending pysmb For Other Frameworks","Welcome to pysmb’s documentation!","Upgrading from older pysmb versions"],titleterms:{"class":[0,1,2,3,4,5,6],caveat:[2,4],content:10,credit:10,descript:10,descriptor:8,document:10,exampl:[2,3,4],except:7,extend:9,framework:9,from:11,indic:10,licens:10,nbnsprotocol:0,netbio:1,note:3,older:11,other:9,packag:10,pysmb:[9,10,11],secur:8,shareddevic:5,sharedfil:6,smb2:[2,4],smb:7,smbconnect:2,smbhandler:3,smbprotocolfactori:4,support:[2,4],tabl:10,upgrad:11,version:11,welcom:10}})⏎ |
0 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
1 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
2 | ||
3 | ||
4 | <html xmlns="http://www.w3.org/1999/xhtml"> | |
5 | <head> | |
6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
7 | ||
8 | <title>Upgrading from older pysmb versions — pysmb 1.2.1 documentation</title> | |
9 | ||
10 | <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" /> | |
11 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> | |
12 | ||
13 | <script type="text/javascript"> | |
14 | var DOCUMENTATION_OPTIONS = { | |
15 | URL_ROOT: './', | |
16 | VERSION: '1.2.1', | |
17 | COLLAPSE_INDEX: false, | |
18 | FILE_SUFFIX: '.html', | |
19 | HAS_SOURCE: true | |
20 | }; | |
21 | </script> | |
22 | <script type="text/javascript" src="_static/jquery.js"></script> | |
23 | <script type="text/javascript" src="_static/underscore.js"></script> | |
24 | <script type="text/javascript" src="_static/doctools.js"></script> | |
25 | <link rel="top" title="pysmb 1.2.1 documentation" href="index.html" /> | |
26 | <link rel="prev" title="Extending pysmb For Other Frameworks" href="extending.html" /> | |
27 | </head> | |
28 | <body role="document"> | |
29 | <div class="related" role="navigation" aria-label="related navigation"> | |
30 | <h3>Navigation</h3> | |
31 | <ul> | |
32 | <li class="right" style="margin-right: 10px"> | |
33 | <a href="genindex.html" title="General Index" | |
34 | accesskey="I">index</a></li> | |
35 | <li class="right" > | |
36 | <a href="py-modindex.html" title="Python Module Index" | |
37 | >modules</a> |</li> | |
38 | <li class="right" > | |
39 | <a href="extending.html" title="Extending pysmb For Other Frameworks" | |
40 | accesskey="P">previous</a> |</li> | |
41 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.2.1 documentation</a> »</li> | |
42 | </ul> | |
43 | </div> | |
44 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> | |
45 | <div class="sphinxsidebarwrapper"> | |
46 | <h3><a href="index.html">Table Of Contents</a></h3> | |
47 | <ul> | |
48 | <li><a class="reference internal" href="#">Upgrading from older pysmb versions</a><ul> | |
49 | <li><a class="reference internal" href="#pysmb-1-2-0">pysmb 1.2.0</a></li> | |
50 | <li><a class="reference internal" href="#pysmb-1-1-28">pysmb 1.1.28</a></li> | |
51 | <li><a class="reference internal" href="#pysmb-1-1-26">pysmb 1.1.26</a></li> | |
52 | <li><a class="reference internal" href="#pysmb-1-1-25">pysmb 1.1.25</a></li> | |
53 | <li><a class="reference internal" href="#pysmb-1-1-20">pysmb 1.1.20</a></li> | |
54 | <li><a class="reference internal" href="#pysmb-1-1-15">pysmb 1.1.15</a></li> | |
55 | <li><a class="reference internal" href="#pysmb-1-1-11">pysmb 1.1.11</a></li> | |
56 | <li><a class="reference internal" href="#pysmb-1-1-10">pysmb 1.1.10</a></li> | |
57 | <li><a class="reference internal" href="#pysmb-1-1-2">pysmb 1.1.2</a></li> | |
58 | <li><a class="reference internal" href="#pysmb-1-0-3">pysmb 1.0.3</a></li> | |
59 | <li><a class="reference internal" href="#pysmb-1-0-0">pysmb 1.0.0</a></li> | |
60 | </ul> | |
61 | </li> | |
62 | </ul> | |
63 | ||
64 | <h4>Previous topic</h4> | |
65 | <p class="topless"><a href="extending.html" | |
66 | title="previous chapter">Extending pysmb For Other Frameworks</a></p> | |
67 | <div role="note" aria-label="source link"> | |
68 | <h3>This Page</h3> | |
69 | <ul class="this-page-menu"> | |
70 | <li><a href="_sources/upgrading.txt" | |
71 | rel="nofollow">Show Source</a></li> | |
72 | </ul> | |
73 | </div> | |
74 | <div id="searchbox" style="display: none" role="search"> | |
75 | <h3>Quick search</h3> | |
76 | <form class="search" action="search.html" method="get"> | |
77 | <input type="text" name="q" /> | |
78 | <input type="submit" value="Go" /> | |
79 | <input type="hidden" name="check_keywords" value="yes" /> | |
80 | <input type="hidden" name="area" value="default" /> | |
81 | </form> | |
82 | <p class="searchtip" style="font-size: 90%"> | |
83 | Enter search terms or a module, class or function name. | |
84 | </p> | |
85 | </div> | |
86 | <script type="text/javascript">$('#searchbox').show(0);</script> | |
87 | </div> | |
88 | </div> | |
89 | ||
90 | <div class="document"> | |
91 | <div class="documentwrapper"> | |
92 | <div class="bodywrapper"> | |
93 | <div class="body" role="main"> | |
94 | ||
95 | <div class="section" id="upgrading-from-older-pysmb-versions"> | |
96 | <h1>Upgrading from older pysmb versions<a class="headerlink" href="#upgrading-from-older-pysmb-versions" title="Permalink to this headline">¶</a></h1> | |
97 | <p>This page documents the improvements and changes to the API that could be incompatible with previous releases.</p> | |
98 | <div class="section" id="pysmb-1-2-0"> | |
99 | <h2>pysmb 1.2.0<a class="headerlink" href="#pysmb-1-2-0" title="Permalink to this headline">¶</a></h2> | |
100 | <ul class="simple"> | |
101 | <li>Add new <cite>delete_matching_folders</cite> parameter to <cite>deleteFiles()</cite> method in SMBProtocolFactory and SMBConnection | |
102 | class to support deletion of sub-folders. If you are passing timeout parameter to the <cite>deleteFiles()</cite> method | |
103 | in your application, please switch to using named parameter for timeout.</li> | |
104 | </ul> | |
105 | </div> | |
106 | <div class="section" id="pysmb-1-1-28"> | |
107 | <h2>pysmb 1.1.28<a class="headerlink" href="#pysmb-1-1-28" title="Permalink to this headline">¶</a></h2> | |
108 | <ul class="simple"> | |
109 | <li>SharedFile instances returned from the <cite>listPath()</cite> method now has a new property | |
110 | <cite>file_id</cite> attribute which represents the file reference number given by the remote SMB server.</li> | |
111 | </ul> | |
112 | </div> | |
113 | <div class="section" id="pysmb-1-1-26"> | |
114 | <h2>pysmb 1.1.26<a class="headerlink" href="#pysmb-1-1-26" title="Permalink to this headline">¶</a></h2> | |
115 | <ul class="simple"> | |
116 | <li>SMBConnection class can now be used as a context manager</li> | |
117 | </ul> | |
118 | </div> | |
119 | <div class="section" id="pysmb-1-1-25"> | |
120 | <h2>pysmb 1.1.25<a class="headerlink" href="#pysmb-1-1-25" title="Permalink to this headline">¶</a></h2> | |
121 | <ul class="simple"> | |
122 | <li>SharedFile class has a new property <cite>isNormal</cite> which will be True if the file is a | |
123 | ‘normal’ file. pysmb defines a ‘normal’ file as a file entry that is not | |
124 | read-only, not hidden, not system, not archive and not a directory; | |
125 | it ignores other attributes like compression, indexed, sparse, temporary and encryption.</li> | |
126 | <li><cite>listPath()</cite> method in SMBProtocolFactory and SMBConnection class will now include | |
127 | ‘normal’ files by default if you do not specify the <cite>search</cite> parameter.</li> | |
128 | </ul> | |
129 | </div> | |
130 | <div class="section" id="pysmb-1-1-20"> | |
131 | <h2>pysmb 1.1.20<a class="headerlink" href="#pysmb-1-1-20" title="Permalink to this headline">¶</a></h2> | |
132 | <ul class="simple"> | |
133 | <li>A new method <cite>getSecurity()</cite> was added to SMBConnection and SMBProtocolFactory class.</li> | |
134 | </ul> | |
135 | </div> | |
136 | <div class="section" id="pysmb-1-1-15"> | |
137 | <h2>pysmb 1.1.15<a class="headerlink" href="#pysmb-1-1-15" title="Permalink to this headline">¶</a></h2> | |
138 | <ul class="simple"> | |
139 | <li>Add new <cite>truncate</cite> parameter to <cite>storeFileFromOffset()</cite> in SMBProtocolFactory and SMBConnection | |
140 | class to support truncation of the file before writing. If you are passing timeout parameter | |
141 | to the <cite>storeFileFromOffset()</cite> method in your application, please switch to using named parameter for timeout.</li> | |
142 | </ul> | |
143 | </div> | |
144 | <div class="section" id="pysmb-1-1-11"> | |
145 | <h2>pysmb 1.1.11<a class="headerlink" href="#pysmb-1-1-11" title="Permalink to this headline">¶</a></h2> | |
146 | <ul class="simple"> | |
147 | <li>A new method <cite>storeFileFromOffset()</cite> was added to SMBConnection and SMBProtocolFactory class.</li> | |
148 | </ul> | |
149 | </div> | |
150 | <div class="section" id="pysmb-1-1-10"> | |
151 | <h2>pysmb 1.1.10<a class="headerlink" href="#pysmb-1-1-10" title="Permalink to this headline">¶</a></h2> | |
152 | <ul class="simple"> | |
153 | <li>A new method <cite>getAttributes()</cite> was added to SMBConnection and SMBProtocolFactory class</li> | |
154 | <li>SharedFile class has a new property <cite>isReadOnly</cite> to indicate the file is read-only on the remote filesystem.</li> | |
155 | </ul> | |
156 | </div> | |
157 | <div class="section" id="pysmb-1-1-2"> | |
158 | <h2>pysmb 1.1.2<a class="headerlink" href="#pysmb-1-1-2" title="Permalink to this headline">¶</a></h2> | |
159 | <ul class="simple"> | |
160 | <li><cite>queryIPForName()</cite> method in nmb.NetBIOS and nmb.NBNSProtocol class will now return only the server machine name and ignore workgroup names.</li> | |
161 | </ul> | |
162 | </div> | |
163 | <div class="section" id="pysmb-1-0-3"> | |
164 | <h2>pysmb 1.0.3<a class="headerlink" href="#pysmb-1-0-3" title="Permalink to this headline">¶</a></h2> | |
165 | <ul class="simple"> | |
166 | <li>Two new methods were added to NBNSProtocol class: <cite>queryIPForName()</cite> and <cite>NetBIOS.queryIPForName()</cite> | |
167 | to support querying for a machine’s NetBIOS name at the given IP address.</li> | |
168 | <li>A new method <cite>retrieveFileFromOffset()</cite> was added to SMBProtocolFactory and SMBConnection | |
169 | to support finer control of file retrieval operation.</li> | |
170 | </ul> | |
171 | </div> | |
172 | <div class="section" id="pysmb-1-0-0"> | |
173 | <h2>pysmb 1.0.0<a class="headerlink" href="#pysmb-1-0-0" title="Permalink to this headline">¶</a></h2> | |
174 | <p>pysmb was completely rewritten in version 1.0.0. | |
175 | If you are upgrading from pysmb 0.x, you most likely have to rewrite your application for the new 1.x API.</p> | |
176 | </div> | |
177 | </div> | |
178 | ||
179 | ||
180 | </div> | |
181 | </div> | |
182 | </div> | |
183 | <div class="clearer"></div> | |
184 | </div> | |
185 | <div class="related" role="navigation" aria-label="related navigation"> | |
186 | <h3>Navigation</h3> | |
187 | <ul> | |
188 | <li class="right" style="margin-right: 10px"> | |
189 | <a href="genindex.html" title="General Index" | |
190 | >index</a></li> | |
191 | <li class="right" > | |
192 | <a href="py-modindex.html" title="Python Module Index" | |
193 | >modules</a> |</li> | |
194 | <li class="right" > | |
195 | <a href="extending.html" title="Extending pysmb For Other Frameworks" | |
196 | >previous</a> |</li> | |
197 | <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.2.1 documentation</a> »</li> | |
198 | </ul> | |
199 | </div> | |
200 | <div class="footer" role="contentinfo"> | |
201 | © Copyright 2001-2020, Michael Teo https://miketeo.net/. | |
202 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6. | |
203 | </div> | |
204 | </body> | |
205 | </html>⏎ |
76 | 76 | self.onNMBSessionOK() |
77 | 77 | elif packet.type == NEGATIVE_SESSION_RESPONSE: |
78 | 78 | self.onNMBSessionFailed() |
79 | elif packet.type == SESSION_KEEPALIVE: | |
80 | # Discard keepalive packets - [RFC1002]: 5.2.2.1 | |
81 | pass | |
79 | 82 | else: |
80 | 83 | self.log.warning('Unrecognized NMB session type: 0x%02x', packet.type) |
81 | 84 | |
150 | 153 | opcode = (code >> 11) & 0x0F |
151 | 154 | flags = (code >> 4) & 0x7F |
152 | 155 | rcode = code & 0x0F |
153 | numnames = struct.unpack('B', data[self.HEADER_STRUCT_SIZE + 44])[0] | |
154 | 156 | |
155 | if numnames > 0: | |
156 | ret = [ ] | |
157 | offset = self.HEADER_STRUCT_SIZE + 45 | |
157 | try: | |
158 | numnames = struct.unpack('B', data[self.HEADER_STRUCT_SIZE + 44])[0] | |
158 | 159 | |
159 | for i in range(0, numnames): | |
160 | mynme = data[offset:offset + 15] | |
161 | mynme = mynme.strip() | |
162 | ret.append(( mynme, ord(data[offset+15]) )) | |
163 | offset += 18 | |
160 | if numnames > 0: | |
161 | ret = [ ] | |
162 | offset = self.HEADER_STRUCT_SIZE + 45 | |
164 | 163 | |
165 | return trn_id, ret | |
166 | else: | |
167 | return trn_id, None | |
164 | for i in range(0, numnames): | |
165 | mynme = data[offset:offset + 15] | |
166 | mynme = mynme.strip() | |
167 | ret.append(( mynme, ord(data[offset+15]) )) | |
168 | offset += 18 | |
169 | ||
170 | return trn_id, ret | |
171 | except IndexError: | |
172 | pass | |
173 | ||
174 | return trn_id, None | |
168 | 175 | |
169 | 176 | # |
170 | 177 | # Contributed by Jason Anderson |
20 | 20 | Create a new SMBConnection instance. |
21 | 21 | |
22 | 22 | *username* and *password* are the user credentials required to authenticate the underlying SMB connection with the remote server. |
23 | *password* can be a string or a callable returning a string. | |
23 | 24 | File operations can only be proceeded after the connection has been authenticated successfully. |
24 | 25 | |
25 | 26 | Note that you need to call *connect* method to actually establish the SMB connection to the remote server and perform authentication. |
28 | 29 | Some newer server installations might also support Direct hosting of SMB over TCP/IP; for these servers, the default TCP port is 445. |
29 | 30 | |
30 | 31 | :param string my_name: The local NetBIOS machine name that will identify where this connection is originating from. |
31 | You can freely choose a name as long as it contains a maximum of 15 alphanumeric characters and does not contain spaces and any of ``\/:*?";|+`` | |
32 | You can freely choose a name as long as it contains a maximum of 15 alphanumeric characters and does not contain spaces and any of ``\\/:*?";|+`` | |
32 | 33 | :param string remote_name: The NetBIOS machine name of the remote server. |
33 | 34 | On windows, you can find out the machine name by right-clicking on the "My Computer" and selecting "Properties". |
34 | 35 | This parameter must be the same as what has been configured on the remote server, or else the connection will be rejected. |
71 | 72 | total_sent = total_sent + sent |
72 | 73 | |
73 | 74 | # |
75 | # Support for "with" context | |
76 | # | |
77 | def __enter__(self): | |
78 | return self | |
79 | ||
80 | def __exit__(self, *args): | |
81 | self.close() | |
82 | ||
83 | # | |
74 | 84 | # Misc Properties |
75 | 85 | # |
76 | 86 | |
152 | 162 | return results |
153 | 163 | |
154 | 164 | def listPath(self, service_name, path, |
155 | search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE, | |
165 | search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL, | |
156 | 166 | pattern = '*', timeout = 30): |
157 | 167 | """ |
158 | 168 | Retrieve a directory listing of files/folders at *path* |
169 | ||
170 | For simplicity, pysmb defines a "normal" file as a file entry that is not read-only, not hidden, not system, not archive and not a directory. | |
171 | It ignores other attributes like compression, indexed, sparse, temporary and encryption. | |
172 | ||
173 | Note that the default search parameter will query for all read-only (SMB_FILE_ATTRIBUTE_READONLY), hidden (SMB_FILE_ATTRIBUTE_HIDDEN), | |
174 | system (SMB_FILE_ATTRIBUTE_SYSTEM), archive (SMB_FILE_ATTRIBUTE_ARCHIVE), normal (SMB_FILE_ATTRIBUTE_INCL_NORMAL) files | |
175 | and directories (SMB_FILE_ATTRIBUTE_DIRECTORY). | |
176 | If you do not need to include "normal" files in the result, define your own search parameter without the SMB_FILE_ATTRIBUTE_INCL_NORMAL constant. | |
177 | SMB_FILE_ATTRIBUTE_NORMAL should be used by itself and not be used with other bit constants. | |
159 | 178 | |
160 | 179 | :param string/unicode service_name: the name of the shared folder for the *path* |
161 | 180 | :param string/unicode path: path relative to the *service_name* where we are interested to learn about its files/sub-folders. |
162 | 181 | :param integer search: integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py). |
163 | The default *search* value will query for all read-only, hidden, system, archive files and directories. | |
164 | 182 | :param string/unicode pattern: the filter to apply to the results before returning to the client. |
165 | 183 | :return: A list of :doc:`smb.base.SharedFile<smb_SharedFile>` instances. |
166 | 184 | """ |
244 | 262 | self.is_busy = True |
245 | 263 | try: |
246 | 264 | self._getAttributes(service_name, path, cb, eb, timeout) |
265 | while self.is_busy: | |
266 | self._pollForNetBIOSPacket(timeout) | |
267 | finally: | |
268 | self.is_busy = False | |
269 | ||
270 | return results[0] | |
271 | ||
272 | def getSecurity(self, service_name, path, timeout = 30): | |
273 | """ | |
274 | Retrieve the security descriptor of the file at *path* on the *service_name*. | |
275 | ||
276 | :param string/unicode service_name: the name of the shared folder for the *path* | |
277 | :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be raised. | |
278 | :return: A :class:`smb.security_descriptors.SecurityDescriptor` instance containing the security information of the file. | |
279 | """ | |
280 | if not self.sock: | |
281 | raise NotConnectedError('Not connected to server') | |
282 | ||
283 | results = [ ] | |
284 | ||
285 | def cb(info): | |
286 | self.is_busy = False | |
287 | results.append(info) | |
288 | ||
289 | def eb(failure): | |
290 | self.is_busy = False | |
291 | raise failure | |
292 | ||
293 | self.is_busy = True | |
294 | try: | |
295 | self._getSecurity(service_name, path, cb, eb, timeout) | |
247 | 296 | while self.is_busy: |
248 | 297 | self._pollForNetBIOSPacket(timeout) |
249 | 298 | finally: |
349 | 398 | |
350 | 399 | return results[0] |
351 | 400 | |
352 | def deleteFiles(self, service_name, path_file_pattern, timeout = 30): | |
401 | def deleteFiles(self, service_name, path_file_pattern, delete_matching_folders = False, timeout = 30): | |
353 | 402 | """ |
354 | 403 | Delete one or more regular files. It supports the use of wildcards in file names, allowing for deletion of multiple files in a single request. |
404 | ||
405 | If delete_matching_folders is True, immediate sub-folders that match the path_file_pattern will be deleted recursively. | |
355 | 406 | |
356 | 407 | :param string/unicode service_name: Contains the name of the shared folder. |
357 | 408 | :param string/unicode path_file_pattern: The pathname of the file(s) to be deleted, relative to the service_name. |
371 | 422 | |
372 | 423 | self.is_busy = True |
373 | 424 | try: |
374 | self._deleteFiles(service_name, path_file_pattern, cb, eb, timeout = timeout) | |
375 | while self.is_busy: | |
376 | self._pollForNetBIOSPacket(timeout) | |
377 | finally: | |
378 | self.is_busy = False | |
379 | ||
380 | def resetFileAttributes(self, service_name, path_file_pattern, timeout = 30): | |
425 | self._deleteFiles(service_name, path_file_pattern, delete_matching_folders, cb, eb, timeout = timeout) | |
426 | while self.is_busy: | |
427 | self._pollForNetBIOSPacket(timeout) | |
428 | finally: | |
429 | self.is_busy = False | |
430 | ||
431 | def resetFileAttributes(self, service_name, path_file_pattern, file_attributes = ATTR_NORMAL, timeout = 30): | |
381 | 432 | """ |
382 | 433 | Reset file attributes of one or more regular files or folders. |
383 | 434 | It supports the use of wildcards in file names, allowing for unlocking of multiple files/folders in a single request. |
384 | 435 | This function is very helpful when deleting files/folders that are read-only. |
385 | Note: this function is currently only implemented for SMB2! Technically, it sets the FILE_ATTRIBUTE_NORMAL flag, therefore clearing all other flags. (See https://msdn.microsoft.com/en-us/library/cc232110.aspx for further information) | |
386 | ||
436 | By default, it sets the ATTR_NORMAL flag, therefore clearing all other flags. | |
437 | (See https://msdn.microsoft.com/en-us/library/cc232110.aspx for further information) | |
438 | ||
439 | Note: this function is currently only implemented for SMB2! | |
440 | ||
387 | 441 | :param string/unicode service_name: Contains the name of the shared folder. |
388 | 442 | :param string/unicode path_file_pattern: The pathname of the file(s) to be deleted, relative to the service_name. |
389 | 443 | Wildcards may be used in the filename component of the path. |
390 | 444 | If your path/filename contains non-English characters, you must pass in an unicode string. |
445 | :param int file_attributes: The desired file attributes to set. Defaults to `ATTR_NORMAL`. | |
391 | 446 | :return: None |
392 | 447 | """ |
393 | 448 | if not self.sock: |
402 | 457 | |
403 | 458 | self.is_busy = True |
404 | 459 | try: |
405 | self._resetFileAttributes(service_name, path_file_pattern, cb, eb, timeout = timeout) | |
460 | self._resetFileAttributes(service_name, path_file_pattern, cb, eb, file_attributes, timeout = timeout) | |
406 | 461 | while self.is_busy: |
407 | 462 | self._pollForNetBIOSPacket(timeout) |
408 | 463 | finally: |
494 | 549 | """ |
495 | 550 | Send an echo command containing *data* to the remote SMB/CIFS server. The remote SMB/CIFS will reply with the same *data*. |
496 | 551 | |
497 | :param string data: Data to send to the remote server. | |
552 | :param bytes data: Data to send to the remote server. Must be a bytes object. | |
498 | 553 | :return: The *data* parameter |
499 | 554 | """ |
500 | 555 | if not self.sock: |
43 | 43 | passwd = passwd or '' |
44 | 44 | myname = MACHINE_NAME or self.generateClientMachineName() |
45 | 45 | |
46 | n = NetBIOS() | |
47 | names = n.queryIPForName(host) | |
48 | if names: | |
49 | server_name = names[0] | |
50 | else: | |
51 | raise urllib2.URLError('SMB error: Hostname does not reply back with its machine name') | |
46 | server_name,host = host.split(',') if ',' in host else [None,host] | |
47 | ||
48 | if server_name is None: | |
49 | n = NetBIOS() | |
50 | names = n.queryIPForName(host) | |
51 | if names: | |
52 | server_name = names[0] | |
53 | else: | |
54 | raise urllib2.URLError('SMB error: Hostname does not reply back with its machine name') | |
52 | 55 | |
53 | 56 | path, attrs = splitattr(req.get_selector()) |
54 | 57 | if path.startswith('/'): |
176 | 176 | return d |
177 | 177 | |
178 | 178 | def listPath(self, service_name, path, |
179 | search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE, | |
179 | search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL, | |
180 | 180 | pattern = '*', timeout = 30): |
181 | 181 | """ |
182 | 182 | Retrieve a directory listing of files/folders at *path* |
183 | ||
184 | For simplicity, pysmb defines a "normal" file as a file entry that is not read-only, not hidden, not system, not archive and not a directory. | |
185 | It ignores other attributes like compression, indexed, sparse, temporary and encryption. | |
186 | ||
187 | Note that the default search parameter will query for all read-only (SMB_FILE_ATTRIBUTE_READONLY), hidden (SMB_FILE_ATTRIBUTE_HIDDEN), | |
188 | system (SMB_FILE_ATTRIBUTE_SYSTEM), archive (SMB_FILE_ATTRIBUTE_ARCHIVE), normal (SMB_FILE_ATTRIBUTE_INCL_NORMAL) files | |
189 | and directories (SMB_FILE_ATTRIBUTE_DIRECTORY). | |
190 | If you do not need to include "normal" files in the result, define your own search parameter without the SMB_FILE_ATTRIBUTE_INCL_NORMAL constant. | |
191 | SMB_FILE_ATTRIBUTE_NORMAL should be used by itself and not be used with other bit constants. | |
183 | 192 | |
184 | 193 | :param string/unicode service_name: the name of the shared folder for the *path* |
185 | 194 | :param string/unicode path: path relative to the *service_name* where we are interested to learn about its files/sub-folders. |
186 | 195 | :param integer search: integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py). |
187 | The default *search* value will query for all read-only, hidden, system, archive files and directories. | |
188 | 196 | :param string/unicode pattern: the filter to apply to the results before returning to the client. |
189 | 197 | :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method. |
190 | 198 | :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of :doc:`smb.base.SharedFile<smb_SharedFile>` instances. |
367 | 375 | """ |
368 | 376 | Send an echo command containing *data* to the remote SMB/CIFS server. The remote SMB/CIFS will reply with the same *data*. |
369 | 377 | |
370 | :param string data: Data to send to the remote server. | |
378 | :param bytes data: Data to send to the remote server. Must be a bytes object. | |
371 | 379 | :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method. |
372 | 380 | :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with the *data* parameter. |
373 | 381 | """ |
4 | 4 | from smb2_constants import * |
5 | 5 | from smb_structs import * |
6 | 6 | from smb2_structs import * |
7 | from .security_descriptors import SecurityDescriptor | |
7 | 8 | from nmb.base import NMBSession |
8 | 9 | from utils import convertFILETIMEtoEpoch |
9 | 10 | import ntlm, securityblob |
58 | 59 | def __init__(self, username, password, my_name, remote_name, domain = '', use_ntlm_v2 = True, sign_options = SIGN_WHEN_REQUIRED, is_direct_tcp = False): |
59 | 60 | NMBSession.__init__(self, my_name, remote_name, is_direct_tcp = is_direct_tcp) |
60 | 61 | self.username = _convert_to_unicode(username) |
61 | self.password = _convert_to_unicode(password) | |
62 | self._password = password | |
62 | 63 | self.domain = _convert_to_unicode(domain) |
63 | 64 | self.sign_options = sign_options |
64 | 65 | self.is_direct_tcp = is_direct_tcp |
65 | 66 | self.use_ntlm_v2 = use_ntlm_v2 #: Similar to LMAuthenticationPolicy and NTAuthenticationPolicy as described in [MS-CIFS] 3.2.1.1 |
66 | 67 | self.smb_message = SMBMessage() |
67 | 68 | self.is_using_smb2 = False #: Are we communicating using SMB2 protocol? self.smb_message will be a SMB2Message instance if this flag is True |
69 | self.async_requests = { } #: AsyncID mapped to _PendingRequest instance | |
68 | 70 | self.pending_requests = { } #: MID mapped to _PendingRequest instance |
69 | 71 | self.connected_trees = { } #: Share name mapped to TID |
70 | 72 | self.next_rpc_call_id = 1 #: Next RPC callID value. Not used directly in SMB message. Usually encapsulated in sub-commands under SMB_COM_TRANSACTION or SMB_COM_TRANSACTION2 messages |
103 | 105 | (self.use_ntlm_v2 and 'v2') or 'v1', |
104 | 106 | (SUPPORT_EXTENDED_SECURITY and 'with') or 'without') |
105 | 107 | |
108 | @property | |
109 | def password(self): | |
110 | password = self._password() if callable(self._password) else self._password | |
111 | return _convert_to_unicode(password) | |
106 | 112 | |
107 | 113 | # |
108 | 114 | # NMBSession Methods |
172 | 178 | self._listShares = self._listShares_SMB1 |
173 | 179 | self._listPath = self._listPath_SMB1 |
174 | 180 | self._listSnapshots = self._listSnapshots_SMB1 |
181 | self._getSecurity = self._getSecurity_SMB1 | |
175 | 182 | self._getAttributes = self._getAttributes_SMB1 |
176 | 183 | self._retrieveFile = self._retrieveFile_SMB1 |
177 | 184 | self._retrieveFileFromOffset = self._retrieveFileFromOffset_SMB1 |
195 | 202 | self._listPath = self._listPath_SMB2 |
196 | 203 | self._listSnapshots = self._listSnapshots_SMB2 |
197 | 204 | self._getAttributes = self._getAttributes_SMB2 |
205 | self._getSecurity = self._getSecurity_SMB2 | |
198 | 206 | self._retrieveFile = self._retrieveFile_SMB2 |
199 | 207 | self._retrieveFileFromOffset = self._retrieveFileFromOffset_SMB2 |
200 | 208 | self._storeFile = self._storeFile_SMB2 |
218 | 226 | if smb_message.mid == 0: |
219 | 227 | smb_message.mid = self._getNextMID_SMB2() |
220 | 228 | |
221 | if smb_message.command != SMB2_COM_NEGOTIATE and smb_message.command != SMB2_COM_ECHO: | |
229 | if smb_message.command != SMB2_COM_NEGOTIATE: | |
222 | 230 | smb_message.session_id = self.session_id |
223 | 231 | |
224 | 232 | if self.is_signing_active: |
255 | 263 | if result == securityblob.RESULT_ACCEPT_COMPLETED: |
256 | 264 | self.has_authenticated = True |
257 | 265 | self.log.info('Authentication (on SMB2) successful!') |
266 | ||
267 | # [MS-SMB2]: 3.2.5.3.1 | |
268 | # If the security subsystem indicates that the session was established by an anonymous user, | |
269 | # Session.SigningRequired MUST be set to FALSE. | |
270 | # If the SMB2_SESSION_FLAG_IS_GUEST bit is set in the SessionFlags field of the | |
271 | # SMB2 SESSION_SETUP Response and if Session.SigningRequired is TRUE, this indicates a SESSION_SETUP | |
272 | # failure and the connection MUST be terminated. If the SMB2_SESSION_FLAG_IS_GUEST bit is set in the SessionFlags | |
273 | # field of the SMB2 SESSION_SETUP Response and if RequireMessageSigning is FALSE, Session.SigningRequired | |
274 | # MUST be set to FALSE. | |
275 | if message.payload.isGuestSession or message.payload.isAnonymousSession: | |
276 | self.is_signing_active = False | |
277 | self.log.info('Signing disabled because session is guest/anonymous') | |
278 | ||
258 | 279 | self.onAuthOK() |
259 | 280 | else: |
260 | 281 | raise ProtocolError('SMB2_COM_SESSION_SETUP status is 0 but security blob negResult value is %d' % result, message.raw_data, message) |
268 | 289 | self._handleSessionChallenge(message, ntlm_token) |
269 | 290 | except ( securityblob.BadSecurityBlobError, securityblob.UnsupportedSecurityProvider ), ex: |
270 | 291 | raise ProtocolError(str(ex), message.raw_data, message) |
271 | elif message.status == 0xc000006d: # STATUS_LOGON_FAILURE | |
292 | elif (message.status == 0xc000006d # STATUS_LOGON_FAILURE | |
293 | or message.status == 0xc0000064 # STATUS_NO_SUCH_USER | |
294 | or message.status == 0xc000006a):# STATUS_WRONG_PASSWORD | |
272 | 295 | self.has_authenticated = False |
273 | 296 | self.log.info('Authentication (on SMB2) failed. Please check username and password.') |
274 | 297 | self.onAuthFailed() |
298 | elif (message.status == 0xc0000193 # STATUS_ACCOUNT_EXPIRED | |
299 | or message.status == 0xC0000071): # STATUS_PASSWORD_EXPIRED | |
300 | self.has_authenticated = False | |
301 | self.log.info('Authentication (on SMB2) failed. Account or password has expired.') | |
302 | self.onAuthFailed() | |
303 | elif message.status == 0xc0000234: # STATUS_ACCOUNT_LOCKED_OUT | |
304 | self.has_authenticated = False | |
305 | self.log.info('Authentication (on SMB2) failed. Account has been locked due to too many invalid logon attempts.') | |
306 | self.onAuthFailed() | |
307 | elif message.status == 0xc0000072: # STATUS_ACCOUNT_DISABLED | |
308 | self.has_authenticated = False | |
309 | self.log.info('Authentication (on SMB2) failed. Account has been disabled.') | |
310 | self.onAuthFailed() | |
311 | elif (message.status == 0xc000006f # STATUS_INVALID_LOGON_HOURS | |
312 | or message.status == 0xc000015b # STATUS_LOGON_TYPE_NOT_GRANTED | |
313 | or message.status == 0xc0000070): # STATUS_INVALID_WORKSTATION | |
314 | self.has_authenticated = False | |
315 | self.log.info('Authentication (on SMB2) failed. Not allowed.') | |
316 | self.onAuthFailed() | |
317 | elif message.status == 0xc000018c: # STATUS_TRUSTED_DOMAIN_FAILURE | |
318 | self.has_authenticated = False | |
319 | self.log.info('Authentication (on SMB2) failed. Domain not trusted.') | |
320 | self.onAuthFailed() | |
321 | elif message.status == 0xc000018d: # STATUS_TRUSTED_RELATIONSHIP_FAILURE | |
322 | self.has_authenticated = False | |
323 | self.log.info('Authentication (on SMB2) failed. Workstation not trusted.') | |
324 | self.onAuthFailed() | |
275 | 325 | else: |
276 | 326 | raise ProtocolError('Unknown status value (0x%08X) in SMB_COM_SESSION_SETUP_ANDX (with extended security)' % message.status, |
277 | 327 | message.raw_data, message) |
278 | 328 | |
279 | req = self.pending_requests.pop(message.mid, None) | |
280 | if req: | |
281 | req.callback(message, **req.kwargs) | |
282 | return True | |
329 | if message.isAsync: | |
330 | if message.status == 0x00000103: # STATUS_PENDING | |
331 | req = self.pending_requests.pop(message.mid, None) | |
332 | if req: | |
333 | self.async_requests[message.async_id] = req | |
334 | else: # All other status including SUCCESS | |
335 | req = self.async_requests.pop(message.async_id, None) | |
336 | if req: | |
337 | req.callback(message, **req.kwargs) | |
338 | return True | |
339 | else: | |
340 | req = self.pending_requests.pop(message.mid, None) | |
341 | if req: | |
342 | req.callback(message, **req.kwargs) | |
343 | return True | |
283 | 344 | |
284 | 345 | |
285 | 346 | def _updateServerInfo_SMB2(self, payload): |
314 | 375 | self.log.info('Performing NTLMv1 authentication (on SMB2) with server challenge "%s"', binascii.hexlify(server_challenge)) |
315 | 376 | nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV1(self.password, server_challenge, True) |
316 | 377 | |
317 | ntlm_data = ntlm.generateAuthenticateMessage(server_flags, | |
318 | nt_challenge_response, | |
319 | lm_challenge_response, | |
320 | session_key, | |
321 | self.username, | |
322 | self.domain) | |
378 | ntlm_data, session_signing_key = ntlm.generateAuthenticateMessage(server_flags, | |
379 | nt_challenge_response, | |
380 | lm_challenge_response, | |
381 | session_key, | |
382 | self.username, | |
383 | self.domain, | |
384 | self.my_name) | |
323 | 385 | |
324 | 386 | if self.log.isEnabledFor(logging.DEBUG): |
325 | 387 | self.log.debug('NT challenge response is "%s" (%d bytes)', binascii.hexlify(nt_challenge_response), len(nt_challenge_response)) |
339 | 401 | |
340 | 402 | if self.is_signing_active: |
341 | 403 | self.log.info("SMB signing activated. All SMB messages will be signed.") |
342 | self.signing_session_key = (session_key + '\0'*16)[:16] | |
404 | self.signing_session_key = session_signing_key | |
405 | if self.log.isEnabledFor(logging.DEBUG): | |
406 | self.log.info("SMB signing key is %s", binascii.hexlify(self.signing_session_key)) | |
407 | ||
343 | 408 | if self.capabilities & CAP_EXTENDED_SECURITY: |
344 | 409 | self.signing_challenge_response = None |
345 | 410 | else: |
368 | 433 | |
369 | 434 | m.tid = tid |
370 | 435 | self._sendSMBMessage(m) |
371 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectSrvSvcCB, errback) | |
436 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectSrvSvcCB, errback, tid = tid) | |
372 | 437 | messages_history.append(m) |
373 | 438 | |
374 | 439 | def connectSrvSvcCB(create_message, **kwargs): |
390 | 455 | 01 00 00 00 |
391 | 456 | """.replace(' ', '').replace('\n', '')) |
392 | 457 | m = SMB2Message(SMB2WriteRequest(create_message.payload.fid, data_bytes, 0)) |
393 | m.tid = create_message.tid | |
458 | m.tid = kwargs['tid'] | |
394 | 459 | self._sendSMBMessage(m) |
395 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcBindCB, errback, fid = create_message.payload.fid) | |
460 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcBindCB, errback, tid = kwargs['tid'], fid = create_message.payload.fid) | |
396 | 461 | messages_history.append(m) |
397 | 462 | else: |
398 | 463 | errback(OperationFailure('Failed to list shares: Unable to locate Server Service RPC endpoint', messages_history)) |
401 | 466 | messages_history.append(trans_message) |
402 | 467 | if trans_message.status == 0: |
403 | 468 | m = SMB2Message(SMB2ReadRequest(kwargs['fid'], read_len = 1024, read_offset = 0)) |
404 | m.tid = trans_message.tid | |
469 | m.tid = kwargs['tid'] | |
405 | 470 | self._sendSMBMessage(m) |
406 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcReadCB, errback, fid = kwargs['fid']) | |
471 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcReadCB, errback, tid = kwargs['tid'], fid = kwargs['fid']) | |
407 | 472 | messages_history.append(m) |
408 | 473 | else: |
409 | closeFid(trans_message.tid, kwargs['fid'], error = 'Failed to list shares: Unable to read from Server Service RPC endpoint') | |
474 | closeFid(kwargs['tid'], kwargs['fid'], error = 'Failed to list shares: Unable to read from Server Service RPC endpoint') | |
410 | 475 | |
411 | 476 | def rpcReadCB(read_message, **kwargs): |
412 | 477 | messages_history.append(read_message) |
434 | 499 | 00 00 00 00 ff ff ff ff 08 00 02 00 00 00 00 00 |
435 | 500 | """.replace(' ', '').replace('\n', '')) |
436 | 501 | m = SMB2Message(SMB2IoctlRequest(kwargs['fid'], 0x0011C017, flags = 0x01, max_out_size = 8196, in_data = data_bytes)) |
437 | m.tid = read_message.tid | |
502 | m.tid = kwargs['tid'] | |
438 | 503 | self._sendSMBMessage(m) |
439 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, listShareResultsCB, errback, fid = kwargs['fid']) | |
504 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, listShareResultsCB, errback, tid = kwargs['tid'], fid = kwargs['fid']) | |
440 | 505 | messages_history.append(m) |
441 | 506 | else: |
442 | closeFid(read_message.tid, kwargs['fid'], error = 'Failed to list shares: Unable to bind to Server Service RPC endpoint') | |
507 | closeFid(kwargs['tid'], kwargs['fid'], error = 'Failed to list shares: Unable to bind to Server Service RPC endpoint') | |
443 | 508 | |
444 | 509 | def listShareResultsCB(result_message, **kwargs): |
445 | 510 | messages_history.append(result_message) |
448 | 513 | data_bytes = result_message.payload.out_data |
449 | 514 | |
450 | 515 | if ord(data_bytes[3]) & 0x02 == 0: |
451 | sendReadRequest(result_message.tid, kwargs['fid'], data_bytes) | |
452 | else: | |
453 | decodeResults(result_message.tid, kwargs['fid'], data_bytes) | |
454 | elif result_message.status == 0x0103: # STATUS_PENDING | |
455 | self.pending_requests[result_message.mid] = _PendingRequest(result_message.mid, expiry_time, listShareResultsCB, errback, fid = kwargs['fid']) | |
456 | else: | |
457 | closeFid(result_message.tid, kwargs['fid']) | |
516 | sendReadRequest(kwargs['tid'], kwargs['fid'], data_bytes) | |
517 | else: | |
518 | decodeResults(kwargs['tid'], kwargs['fid'], data_bytes) | |
519 | else: | |
520 | closeFid(kwargs['tid'], kwargs['fid']) | |
458 | 521 | errback(OperationFailure('Failed to list shares: Unable to retrieve shared device list', messages_history)) |
459 | 522 | |
460 | 523 | def decodeResults(tid, fid, data_bytes): |
493 | 556 | m.tid = tid |
494 | 557 | self._sendSMBMessage(m) |
495 | 558 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, readCB, errback, |
496 | fid = fid, data_bytes = data_bytes) | |
559 | tid = tid, fid = fid, data_bytes = data_bytes) | |
497 | 560 | |
498 | 561 | def readCB(read_message, **kwargs): |
499 | 562 | messages_history.append(read_message) |
500 | 563 | if read_message.status == 0: |
501 | data_len = read_message.payload.data_length | |
502 | 564 | data_bytes = read_message.payload.data |
503 | 565 | |
504 | 566 | if ord(data_bytes[3]) & 0x02 == 0: |
505 | sendReadRequest(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:data_len-24]) | |
506 | else: | |
507 | decodeResults(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:data_len-24]) | |
508 | else: | |
509 | closeFid(read_message.tid, kwargs['fid']) | |
567 | sendReadRequest(kwargs['tid'], kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:]) | |
568 | else: | |
569 | decodeResults(kwargs['tid'], kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:]) | |
570 | else: | |
571 | closeFid(kwargs['tid'], kwargs['fid']) | |
510 | 572 | errback(OperationFailure('Failed to list shares: Unable to retrieve shared device list', messages_history)) |
511 | 573 | |
512 | 574 | def closeFid(tid, fid, results = None, error = None): |
571 | 633 | create_context_data = create_context_data)) |
572 | 634 | m.tid = tid |
573 | 635 | self._sendSMBMessage(m) |
574 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback) | |
636 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid) | |
575 | 637 | messages_history.append(m) |
576 | 638 | |
577 | 639 | def createCB(create_message, **kwargs): |
578 | 640 | messages_history.append(create_message) |
579 | 641 | if create_message.status == 0: |
580 | sendQuery(create_message.tid, create_message.payload.fid, '') | |
642 | sendQuery(kwargs['tid'], create_message.payload.fid, '') | |
643 | elif create_message.status == 0xC0000034L: # [MS-ERREF]: STATUS_OBJECT_NAME_INVALID | |
644 | errback(OperationFailure('Failed to list %s on %s: Path not found' % ( path, service_name ), messages_history)) | |
581 | 645 | else: |
582 | 646 | errback(OperationFailure('Failed to list %s on %s: Unable to open directory' % ( path, service_name ), messages_history)) |
583 | 647 | |
584 | 648 | def sendQuery(tid, fid, data_buf): |
585 | 649 | m = SMB2Message(SMB2QueryDirectoryRequest(fid, pattern, |
586 | info_class = 0x03, # FileBothDirectoryInformation | |
650 | info_class = 0x25, # FileIdBothDirectoryInformation | |
587 | 651 | flags = 0, |
588 | 652 | output_buf_len = self.max_transact_size)) |
589 | 653 | m.tid = tid |
590 | 654 | self._sendSMBMessage(m) |
591 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, queryCB, errback, fid = fid, data_buf = data_buf) | |
655 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, queryCB, errback, tid = tid, fid = fid, data_buf = data_buf) | |
592 | 656 | messages_history.append(m) |
593 | 657 | |
594 | 658 | def queryCB(query_message, **kwargs): |
595 | 659 | messages_history.append(query_message) |
596 | 660 | if query_message.status == 0: |
597 | 661 | data_buf = decodeQueryStruct(kwargs['data_buf'] + query_message.payload.data) |
598 | sendQuery(query_message.tid, kwargs['fid'], data_buf) | |
662 | sendQuery(kwargs['tid'], kwargs['fid'], data_buf) | |
663 | elif query_message.status == 0xC000000FL: # [MS-ERREF]: STATUS_NO_SUCH_FILE | |
664 | # If there are no matching files, we just treat as success instead of failing | |
665 | closeFid(kwargs['tid'], kwargs['fid'], results = results) | |
599 | 666 | elif query_message.status == 0x80000006L: # STATUS_NO_MORE_FILES |
600 | closeFid(query_message.tid, kwargs['fid'], results = results) | |
601 | else: | |
602 | closeFid(query_message.tid, kwargs['fid'], error = query_message.status) | |
667 | closeFid(kwargs['tid'], kwargs['fid'], results = results) | |
668 | else: | |
669 | closeFid(kwargs['tid'], kwargs['fid'], error = query_message.status) | |
603 | 670 | |
604 | 671 | def decodeQueryStruct(data_bytes): |
605 | # SMB_FIND_FILE_BOTH_DIRECTORY_INFO structure. See [MS-CIFS]: 2.2.8.1.7 and [MS-SMB]: 2.2.8.1.1 | |
606 | info_format = '<IIQQQQQQIIIBB24s' | |
672 | # FileIdBothDirectoryInformation structure. See [MS-SMB]: 2.2.8.1.3 and [MS-FSCC]: 2.4.17 | |
673 | info_format = '<IIQQQQQQIIIBB24sHQ' | |
607 | 674 | info_size = struct.calcsize(info_format) |
608 | 675 | |
609 | 676 | data_length = len(data_bytes) |
615 | 682 | next_offset, _, \ |
616 | 683 | create_time, last_access_time, last_write_time, last_attr_change_time, \ |
617 | 684 | file_size, alloc_size, file_attributes, filename_length, ea_size, \ |
618 | short_name_length, _, short_name = struct.unpack(info_format, data_bytes[offset:offset+info_size]) | |
685 | short_name_length, _, short_name, _, file_id = struct.unpack(info_format, data_bytes[offset:offset+info_size]) | |
619 | 686 | |
620 | 687 | offset2 = offset + info_size |
621 | 688 | if offset2 + filename_length > data_length: |
622 | 689 | return data_bytes[offset:] |
623 | 690 | |
624 | 691 | filename = data_bytes[offset2:offset2+filename_length].decode('UTF-16LE') |
625 | short_name = short_name.decode('UTF-16LE') | |
626 | results.append(SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time), | |
627 | convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time), | |
628 | file_size, alloc_size, file_attributes, short_name, filename)) | |
692 | short_name = short_name[:short_name_length].decode('UTF-16LE') | |
693 | ||
694 | accept_result = False | |
695 | if (file_attributes & 0xff) in ( 0x00, ATTR_NORMAL ): # Only the first 8-bits are compared. We ignore other bits like temp, compressed, encryption, sparse, indexed, etc | |
696 | accept_result = (search == SMB_FILE_ATTRIBUTE_NORMAL) or (search & SMB_FILE_ATTRIBUTE_INCL_NORMAL) | |
697 | else: | |
698 | accept_result = (file_attributes & search) > 0 | |
699 | if accept_result: | |
700 | results.append(SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time), | |
701 | convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time), | |
702 | file_size, alloc_size, file_attributes, short_name, filename, file_id)) | |
629 | 703 | |
630 | 704 | if next_offset: |
631 | 705 | offset += next_offset |
644 | 718 | if kwargs['results'] is not None: |
645 | 719 | callback(kwargs['results']) |
646 | 720 | elif kwargs['error'] is not None: |
647 | errback(OperationFailure('Failed to list %s on %s: Query failed with errorcode 0x%08x' % ( path, service_name, kwargs['error'] ), messages_history)) | |
721 | if kwargs['error'] == 0xC000000F: # [MS-ERREF]: STATUS_NO_SUCH_FILE | |
722 | # Remote server returns STATUS_NO_SUCH_FILE error so we assume that the search returns no matching files | |
723 | callback([ ]) | |
724 | else: | |
725 | errback(OperationFailure('Failed to list %s on %s: Query failed with errorcode 0x%08x' % ( path, service_name, kwargs['error'] ), messages_history)) | |
648 | 726 | |
649 | 727 | if not self.connected_trees.has_key(service_name): |
650 | 728 | def connectCB(connect_message, **kwargs): |
694 | 772 | create_context_data = create_context_data)) |
695 | 773 | m.tid = tid |
696 | 774 | self._sendSMBMessage(m) |
697 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback) | |
775 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid) | |
698 | 776 | messages_history.append(m) |
699 | 777 | |
700 | 778 | def createCB(create_message, **kwargs): |
701 | 779 | messages_history.append(create_message) |
702 | 780 | if create_message.status == 0: |
703 | 781 | p = create_message.payload |
782 | filename = self._extractLastPathComponent(unicode(path)) | |
704 | 783 | info = SharedFile(p.create_time, p.lastaccess_time, p.lastwrite_time, p.change_time, |
705 | 784 | p.file_size, p.allocation_size, p.file_attributes, |
706 | unicode(path), unicode(path)) | |
707 | closeFid(create_message.tid, p.fid, info = info) | |
785 | filename, filename) | |
786 | closeFid(kwargs['tid'], p.fid, info = info) | |
708 | 787 | else: |
709 | 788 | errback(OperationFailure('Failed to get attributes for %s on %s: Unable to open remote file object' % ( path, service_name ), messages_history)) |
710 | 789 | |
729 | 808 | sendCreate(connect_message.tid) |
730 | 809 | else: |
731 | 810 | errback(OperationFailure('Failed to get attributes for %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) |
811 | ||
812 | m = SMB2Message(SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ))) | |
813 | self._sendSMBMessage(m) | |
814 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name) | |
815 | messages_history.append(m) | |
816 | else: | |
817 | sendCreate(self.connected_trees[service_name]) | |
818 | ||
819 | def _getSecurity_SMB2(self, service_name, path, callback, errback, timeout = 30): | |
820 | if not self.has_authenticated: | |
821 | raise NotReadyError('SMB connection not authenticated') | |
822 | ||
823 | expiry_time = time.time() + timeout | |
824 | path = path.replace('/', '\\') | |
825 | if path.startswith('\\'): | |
826 | path = path[1:] | |
827 | if path.endswith('\\'): | |
828 | path = path[:-1] | |
829 | messages_history = [ ] | |
830 | results = [ ] | |
831 | ||
832 | def sendCreate(tid): | |
833 | m = SMB2Message(SMB2CreateRequest(path, | |
834 | file_attributes = 0, | |
835 | access_mask = FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | READ_CONTROL | SYNCHRONIZE, | |
836 | share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | |
837 | oplock = SMB2_OPLOCK_LEVEL_NONE, | |
838 | impersonation = SEC_IMPERSONATE, | |
839 | create_options = 0, | |
840 | create_disp = FILE_OPEN)) | |
841 | m.tid = tid | |
842 | self._sendSMBMessage(m) | |
843 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid) | |
844 | messages_history.append(m) | |
845 | ||
846 | def createCB(create_message, **kwargs): | |
847 | messages_history.append(create_message) | |
848 | if create_message.status == 0: | |
849 | m = SMB2Message(SMB2QueryInfoRequest(create_message.payload.fid, | |
850 | flags = 0, | |
851 | additional_info = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, | |
852 | info_type = SMB2_INFO_SECURITY, | |
853 | file_info_class = 0, # [MS-SMB2] 2.2.37, 3.2.4.12 | |
854 | input_buf = '', | |
855 | output_buf_len = self.max_transact_size)) | |
856 | m.tid = kwargs['tid'] | |
857 | self._sendSMBMessage(m) | |
858 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, queryCB, errback, tid = kwargs['tid'], fid = create_message.payload.fid) | |
859 | messages_history.append(m) | |
860 | else: | |
861 | errback(OperationFailure('Failed to get the security descriptor of %s on %s: Unable to open file or directory' % ( path, service_name ), messages_history)) | |
862 | ||
863 | def queryCB(query_message, **kwargs): | |
864 | messages_history.append(query_message) | |
865 | if query_message.status == 0: | |
866 | security = SecurityDescriptor.from_bytes(query_message.payload.data) | |
867 | closeFid(kwargs['tid'], kwargs['fid'], result = security) | |
868 | else: | |
869 | closeFid(kwargs['tid'], kwargs['fid'], error = query_message.status) | |
870 | ||
871 | def closeFid(tid, fid, result = None, error = None): | |
872 | m = SMB2Message(SMB2CloseRequest(fid)) | |
873 | m.tid = tid | |
874 | self._sendSMBMessage(m) | |
875 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, result = result, error = error) | |
876 | messages_history.append(m) | |
877 | ||
878 | def closeCB(close_message, **kwargs): | |
879 | if kwargs['result'] is not None: | |
880 | callback(kwargs['result']) | |
881 | elif kwargs['error'] is not None: | |
882 | errback(OperationFailure('Failed to get the security descriptor of %s on %s: Query failed with errorcode 0x%08x' % ( path, service_name, kwargs['error'] ), messages_history)) | |
883 | ||
884 | if not self.connected_trees.has_key(service_name): | |
885 | def connectCB(connect_message, **kwargs): | |
886 | messages_history.append(connect_message) | |
887 | if connect_message.status == 0: | |
888 | self.connected_trees[service_name] = connect_message.tid | |
889 | sendCreate(connect_message.tid) | |
890 | else: | |
891 | errback(OperationFailure('Failed to get the security descriptor of %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
732 | 892 | |
733 | 893 | m = SMB2Message(SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ))) |
734 | 894 | self._sendSMBMessage(m) |
765 | 925 | m = SMB2Message(SMB2CreateRequest(path, |
766 | 926 | file_attributes = 0, |
767 | 927 | access_mask = FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | READ_CONTROL | SYNCHRONIZE, |
768 | share_access = FILE_SHARE_READ, | |
928 | share_access = FILE_SHARE_READ | FILE_SHARE_WRITE, | |
769 | 929 | oplock = SMB2_OPLOCK_LEVEL_NONE, |
770 | 930 | impersonation = SEC_IMPERSONATE, |
771 | 931 | create_options = FILE_SEQUENTIAL_ONLY | FILE_NON_DIRECTORY_FILE, |
786 | 946 | file_info_class = 0x16, # FileStreamInformation [MS-FSCC] 2.4 |
787 | 947 | input_buf = '', |
788 | 948 | output_buf_len = 4096)) |
789 | m.tid = create_message.tid | |
949 | m.tid = kwargs['tid'] | |
790 | 950 | self._sendSMBMessage(m) |
791 | 951 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, infoCB, errback, |
792 | fid = create_message.payload.fid, file_attributes = create_message.payload.file_attributes) | |
952 | tid = kwargs['tid'], | |
953 | fid = create_message.payload.fid, | |
954 | file_attributes = create_message.payload.file_attributes) | |
793 | 955 | messages_history.append(m) |
794 | 956 | else: |
795 | errback(OperationFailure('Failed to list %s on %s: Unable to open file' % ( path, service_name ), messages_history)) | |
957 | errback(OperationFailure('Failed to retrieve %s on %s: Unable to open file' % ( path, service_name ), messages_history)) | |
796 | 958 | |
797 | 959 | def infoCB(info_message, **kwargs): |
798 | 960 | messages_history.append(info_message) |
807 | 969 | remaining_len = file_len |
808 | 970 | if starting_offset + remaining_len > file_len: |
809 | 971 | remaining_len = file_len - starting_offset |
810 | sendRead(info_message.tid, kwargs['fid'], starting_offset, remaining_len, 0, kwargs['file_attributes']) | |
811 | else: | |
812 | errback(OperationFailure('Failed to list %s on %s: Unable to retrieve information on file' % ( path, service_name ), messages_history)) | |
972 | sendRead(kwargs['tid'], kwargs['fid'], starting_offset, remaining_len, 0, kwargs['file_attributes']) | |
973 | else: | |
974 | errback(OperationFailure('Failed to retrieve %s on %s: Unable to retrieve information on file' % ( path, service_name ), messages_history)) | |
813 | 975 | |
814 | 976 | def sendRead(tid, fid, offset, remaining_len, read_len, file_attributes): |
815 | 977 | read_count = min(self.max_read_size, remaining_len) |
817 | 979 | m.tid = tid |
818 | 980 | self._sendSMBMessage(m) |
819 | 981 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, readCB, errback, |
820 | fid = fid, offset = offset, | |
982 | tid = tid, fid = fid, offset = offset, | |
821 | 983 | remaining_len = remaining_len, |
822 | 984 | read_len = read_len, |
823 | 985 | file_attributes = file_attributes) |
831 | 993 | remaining_len = kwargs['remaining_len'] - data_len |
832 | 994 | |
833 | 995 | if remaining_len > 0: |
834 | sendRead(read_message.tid, kwargs['fid'], kwargs['offset'] + data_len, remaining_len, kwargs['read_len'] + data_len, kwargs['file_attributes']) | |
835 | else: | |
836 | closeFid(read_message.tid, kwargs['fid'], ret = ( file_obj, kwargs['file_attributes'], kwargs['read_len'] + data_len )) | |
996 | sendRead(kwargs['tid'], kwargs['fid'], kwargs['offset'] + data_len, remaining_len, kwargs['read_len'] + data_len, kwargs['file_attributes']) | |
997 | else: | |
998 | closeFid(kwargs['tid'], kwargs['fid'], ret = ( file_obj, kwargs['file_attributes'], kwargs['read_len'] + data_len )) | |
837 | 999 | else: |
838 | 1000 | messages_history.append(read_message) |
839 | closeFid(read_message.tid, kwargs['fid'], error = read_message.status) | |
1001 | closeFid(kwargs['tid'], kwargs['fid'], error = read_message.status) | |
840 | 1002 | |
841 | 1003 | def closeFid(tid, fid, ret = None, error = None): |
842 | 1004 | m = SMB2Message(SMB2CloseRequest(fid)) |
912 | 1074 | messages_history.append(create_message) |
913 | 1075 | if create_message.status == 0: |
914 | 1076 | sendWrite(create_message.tid, create_message.payload.fid, starting_offset) |
915 | elif create_message.status == 0x0103: # STATUS_PENDING | |
916 | self.pending_requests[create_message.mid] = _PendingRequest(create_message.mid, expiry_time, | |
917 | createCB, errback, | |
918 | tid=kwargs['tid']) | |
919 | 1077 | else: |
920 | 1078 | errback(OperationFailure('Failed to store %s on %s: Unable to open file' % ( path, service_name ), messages_history)) |
921 | 1079 | |
927 | 1085 | m = SMB2Message(SMB2WriteRequest(fid, data, offset)) |
928 | 1086 | m.tid = tid |
929 | 1087 | self._sendSMBMessage(m) |
930 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, writeCB, errback, fid = fid, offset = offset+data_len) | |
1088 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, writeCB, errback, tid = tid, fid = fid, offset = offset+data_len) | |
931 | 1089 | else: |
932 | 1090 | closeFid(tid, fid, offset = offset) |
933 | 1091 | |
934 | 1092 | def writeCB(write_message, **kwargs): |
935 | 1093 | # To avoid crazy memory usage when saving large files, we do not save every write_message in messages_history. |
936 | 1094 | if write_message.status == 0: |
937 | sendWrite(write_message.tid, kwargs['fid'], kwargs['offset']) | |
1095 | sendWrite(kwargs['tid'], kwargs['fid'], kwargs['offset']) | |
938 | 1096 | else: |
939 | 1097 | messages_history.append(write_message) |
940 | closeFid(write_message.tid, kwargs['fid']) | |
1098 | closeFid(kwargs['tid'], kwargs['fid']) | |
941 | 1099 | errback(OperationFailure('Failed to store %s on %s: Write failed' % ( path, service_name ), messages_history)) |
942 | 1100 | |
943 | 1101 | def closeFid(tid, fid, error = None, offset = None): |
970 | 1128 | sendCreate(self.connected_trees[service_name]) |
971 | 1129 | |
972 | 1130 | |
973 | def _deleteFiles_SMB2(self, service_name, path_file_pattern, callback, errback, timeout = 30): | |
1131 | def _deleteFiles_SMB2(self, service_name, path_file_pattern, delete_matching_folders, callback, errback, timeout = 30): | |
974 | 1132 | if not self.has_authenticated: |
975 | 1133 | raise NotReadyError('SMB connection not authenticated') |
976 | 1134 | |
977 | 1135 | expiry_time = time.time() + timeout |
1136 | pattern = None | |
978 | 1137 | path = path_file_pattern.replace('/', '\\') |
979 | 1138 | if path.startswith('\\'): |
980 | 1139 | path = path[1:] |
981 | 1140 | if path.endswith('\\'): |
982 | 1141 | path = path[:-1] |
1142 | else: | |
1143 | path_components = path.split('\\') | |
1144 | if path_components[-1].find('*') > -1 or path_components[-1].find('?') > -1: | |
1145 | path = '\\'.join(path_components[:-1]) | |
1146 | pattern = path_components[-1] | |
1147 | messages_history, files_queue = [ ], [ ] | |
1148 | ||
1149 | if pattern is None: | |
1150 | path_components = path.split('\\') | |
1151 | if len(path_components) > 1: | |
1152 | files_queue.append(( '\\'.join(path_components[:-1]), path_components[-1] )) | |
1153 | else: | |
1154 | files_queue.append(( '', path )) | |
1155 | ||
1156 | def deleteCB(path): | |
1157 | if files_queue: | |
1158 | p, filename = files_queue.pop(0) | |
1159 | if filename: | |
1160 | if p: | |
1161 | filename = p + '\\' + filename | |
1162 | self._deleteFiles_SMB2__del(service_name, self.connected_trees[service_name], filename, deleteCB, errback, timeout) | |
1163 | else: | |
1164 | self._deleteDirectory_SMB2(service_name, p, deleteCB, errback, timeout) | |
1165 | else: | |
1166 | callback(path_file_pattern) | |
1167 | ||
1168 | def listCB(files_list): | |
1169 | files_queue.extend(files_list) | |
1170 | deleteCB(None) | |
1171 | ||
1172 | if not self.connected_trees.has_key(service_name): | |
1173 | def connectCB(connect_message, **kwargs): | |
1174 | messages_history.append(connect_message) | |
1175 | if connect_message.status == 0: | |
1176 | self.connected_trees[service_name] = connect_message.tid | |
1177 | if files_queue: | |
1178 | deleteCB(None) | |
1179 | else: | |
1180 | self._deleteFiles_SMB2__list(service_name, path, pattern, delete_matching_folders, listCB, errback, timeout) | |
1181 | else: | |
1182 | errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
1183 | ||
1184 | m = SMB2Message(SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ))) | |
1185 | self._sendSMBMessage(m) | |
1186 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name) | |
1187 | messages_history.append(m) | |
1188 | else: | |
1189 | if files_queue: | |
1190 | deleteCB(None) | |
1191 | else: | |
1192 | self._deleteFiles_SMB2__list(service_name, path, pattern, delete_matching_folders, listCB, errback, timeout) | |
1193 | ||
1194 | def _deleteFiles_SMB2__list(self, service_name, path, pattern, delete_matching_folders, callback, errback, timeout = 30): | |
1195 | folder_queue = [ ] | |
1196 | files_list = [ ] | |
1197 | current_path = [ path ] | |
1198 | search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL | |
1199 | ||
1200 | def listCB(results): | |
1201 | files = [ ] | |
1202 | for f in filter(lambda x: x.filename not in [ '.', '..' ], results): | |
1203 | if f.isDirectory: | |
1204 | if delete_matching_folders: | |
1205 | folder_queue.append(current_path[0]+'\\'+f.filename) | |
1206 | else: | |
1207 | files.append(( current_path[0], f.filename )) | |
1208 | if current_path[0]!=path and delete_matching_folders: | |
1209 | files.append(( current_path[0], None )) | |
1210 | ||
1211 | if files: | |
1212 | files_list[0:0] = files | |
1213 | ||
1214 | if folder_queue: | |
1215 | p = folder_queue.pop() | |
1216 | current_path[0] = p | |
1217 | self._listPath_SMB2(service_name, current_path[0], listCB, errback, search = search, pattern = '*', timeout = 30) | |
1218 | else: | |
1219 | callback(files_list) | |
1220 | ||
1221 | self._listPath_SMB2(service_name, path, listCB, errback, search = search, pattern = pattern, timeout = timeout) | |
1222 | ||
1223 | def _deleteFiles_SMB2__del(self, service_name, tid, path, callback, errback, timeout = 30): | |
983 | 1224 | messages_history = [ ] |
984 | 1225 | |
985 | 1226 | def sendCreate(tid): |
1010 | 1251 | messages_history.append(open_message) |
1011 | 1252 | if open_message.status == 0: |
1012 | 1253 | sendDelete(open_message.tid, open_message.payload.fid) |
1013 | elif open_message.status == 0x0103: # STATUS_PENDING | |
1014 | self.pending_requests[open_message.mid] = _PendingRequest(open_message.mid, expiry_time, | |
1015 | createCB, errback, | |
1016 | tid=kwargs['tid']) | |
1254 | elif open_message.status == 0xC0000034L: # [MS-ERREF]: STATUS_OBJECT_NAME_NOT_FOUND | |
1255 | callback(path) | |
1256 | elif open_message.status == 0xC00000BAL: # [MS-ERREF]: STATUS_FILE_IS_A_DIRECTORY | |
1257 | errback(OperationFailure('Failed to delete %s on %s: Cannot delete a folder. Please use deleteDirectory() method or append "/*" to your path if you wish to delete all files in the folder.' % ( path, service_name ), messages_history)) | |
1017 | 1258 | else: |
1018 | 1259 | errback(OperationFailure('Failed to delete %s on %s: Unable to open file' % ( path, service_name ), messages_history)) |
1019 | 1260 | |
1023 | 1264 | info_type = SMB2_INFO_FILE, |
1024 | 1265 | file_info_class = 0x0d, # SMB2_FILE_DISPOSITION_INFO |
1025 | 1266 | data = '\x01')) |
1026 | ''' | |
1027 | Resources: | |
1028 | https://msdn.microsoft.com/en-us/library/cc246560.aspx | |
1029 | https://msdn.microsoft.com/en-us/library/cc232098.aspx | |
1030 | ''' | |
1031 | m.tid = tid | |
1032 | self._sendSMBMessage(m) | |
1033 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback, fid = fid) | |
1267 | # [MS-SMB2]: 2.2.39, [MS-FSCC]: 2.4.11 | |
1268 | m.tid = tid | |
1269 | self._sendSMBMessage(m) | |
1270 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback, tid = tid, fid = fid) | |
1034 | 1271 | messages_history.append(m) |
1035 | 1272 | |
1036 | 1273 | def deleteCB(delete_message, **kwargs): |
1037 | 1274 | messages_history.append(delete_message) |
1038 | 1275 | if delete_message.status == 0: |
1039 | closeFid(delete_message.tid, kwargs['fid'], status = 0) | |
1040 | else: | |
1041 | closeFid(delete_message.tid, kwargs['fid'], status = delete_message.status) | |
1276 | closeFid(kwargs['tid'], kwargs['fid'], status = 0) | |
1277 | else: | |
1278 | closeFid(kwargs['tid'], kwargs['fid'], status = delete_message.status) | |
1042 | 1279 | |
1043 | 1280 | def closeFid(tid, fid, status = None): |
1044 | 1281 | m = SMB2Message(SMB2CloseRequest(fid)) |
1049 | 1286 | |
1050 | 1287 | def closeCB(close_message, **kwargs): |
1051 | 1288 | if kwargs['status'] == 0: |
1052 | callback(path_file_pattern) | |
1289 | callback(path) | |
1053 | 1290 | else: |
1054 | 1291 | errback(OperationFailure('Failed to delete %s on %s: Delete failed' % ( path, service_name ), messages_history)) |
1055 | 1292 | |
1056 | if not self.connected_trees.has_key(service_name): | |
1057 | def connectCB(connect_message, **kwargs): | |
1058 | messages_history.append(connect_message) | |
1059 | if connect_message.status == 0: | |
1060 | self.connected_trees[service_name] = connect_message.tid | |
1061 | sendCreate(connect_message.tid) | |
1062 | else: | |
1063 | errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
1064 | ||
1065 | m = SMB2Message(SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ))) | |
1066 | self._sendSMBMessage(m) | |
1067 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name) | |
1068 | messages_history.append(m) | |
1069 | else: | |
1070 | sendCreate(self.connected_trees[service_name]) | |
1071 | ||
1072 | def _resetFileAttributes_SMB2(self, service_name, path_file_pattern, callback, errback, timeout = 30): | |
1293 | sendCreate(tid) | |
1294 | ||
1295 | def _resetFileAttributes_SMB2(self, service_name, path_file_pattern, callback, errback, file_attributes = ATTR_NORMAL, timeout = 30): | |
1073 | 1296 | if not self.has_authenticated: |
1074 | 1297 | raise NotReadyError('SMB connection not authenticated') |
1075 | 1298 | |
1108 | 1331 | def createCB(open_message, **kwargs): |
1109 | 1332 | messages_history.append(open_message) |
1110 | 1333 | if open_message.status == 0: |
1111 | sendReset(open_message.tid, open_message.payload.fid) | |
1334 | sendReset(kwargs['tid'], open_message.payload.fid) | |
1112 | 1335 | else: |
1113 | 1336 | errback(OperationFailure('Failed to reset attributes of %s on %s: Unable to open file' % ( path, service_name ), messages_history)) |
1114 | 1337 | |
1117 | 1340 | additional_info = 0, |
1118 | 1341 | info_type = SMB2_INFO_FILE, |
1119 | 1342 | file_info_class = 4, # FileBasicInformation |
1120 | data = struct.pack('qqqqii',0,0,0,0,0x80,0))) # FILE_ATTRIBUTE_NORMAL | |
1121 | ''' | |
1122 | Resources: | |
1123 | https://msdn.microsoft.com/en-us/library/cc246560.aspx | |
1124 | https://msdn.microsoft.com/en-us/library/cc232064.aspx | |
1125 | https://msdn.microsoft.com/en-us/library/cc232094.aspx | |
1126 | https://msdn.microsoft.com/en-us/library/cc232110.aspx | |
1127 | ''' | |
1128 | m.tid = tid | |
1129 | self._sendSMBMessage(m) | |
1130 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, resetCB, errback, fid = fid) | |
1343 | data = struct.pack('qqqqii',0,0,0,0,file_attributes,0))) | |
1344 | # [MS-SMB2]: 2.2.39, [MS-FSCC]: 2.4, [MS-FSCC]: 2.4.7, [MS-FSCC]: 2.6 | |
1345 | m.tid = tid | |
1346 | self._sendSMBMessage(m) | |
1347 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, resetCB, errback, tid = tid, fid = fid) | |
1131 | 1348 | messages_history.append(m) |
1132 | 1349 | |
1133 | 1350 | def resetCB(reset_message, **kwargs): |
1134 | 1351 | messages_history.append(reset_message) |
1135 | 1352 | if reset_message.status == 0: |
1136 | closeFid(reset_message.tid, kwargs['fid'], status = 0) | |
1137 | else: | |
1138 | closeFid(reset_message.tid, kwargs['fid'], status = reset_message.status) | |
1353 | closeFid(kwargs['tid'], kwargs['fid'], status = 0) | |
1354 | else: | |
1355 | closeFid(kwargs['tid'], kwargs['fid'], status = reset_message.status) | |
1139 | 1356 | |
1140 | 1357 | def closeFid(tid, fid, status = None): |
1141 | 1358 | m = SMB2Message(SMB2CloseRequest(fid)) |
1198 | 1415 | create_context_data = create_context_data)) |
1199 | 1416 | m.tid = tid |
1200 | 1417 | self._sendSMBMessage(m) |
1201 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback) | |
1418 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid) | |
1202 | 1419 | messages_history.append(m) |
1203 | 1420 | |
1204 | 1421 | def createCB(create_message, **kwargs): |
1205 | 1422 | messages_history.append(create_message) |
1206 | 1423 | if create_message.status == 0: |
1207 | closeFid(create_message.tid, create_message.payload.fid) | |
1424 | closeFid(kwargs['tid'], create_message.payload.fid) | |
1208 | 1425 | else: |
1209 | 1426 | errback(OperationFailure('Failed to create directory %s on %s: Create failed' % ( path, service_name ), messages_history)) |
1210 | 1427 | |
1272 | 1489 | def createCB(open_message, **kwargs): |
1273 | 1490 | messages_history.append(open_message) |
1274 | 1491 | if open_message.status == 0: |
1275 | sendDelete(open_message.tid, open_message.payload.fid) | |
1492 | sendDelete(kwargs['tid'], open_message.payload.fid) | |
1276 | 1493 | else: |
1277 | 1494 | errback(OperationFailure('Failed to delete %s on %s: Unable to open directory' % ( path, service_name ), messages_history)) |
1278 | 1495 | |
1284 | 1501 | data = '\x01')) |
1285 | 1502 | m.tid = tid |
1286 | 1503 | self._sendSMBMessage(m) |
1287 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback, fid = fid) | |
1504 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback, tid = tid, fid = fid) | |
1288 | 1505 | messages_history.append(m) |
1289 | 1506 | |
1290 | 1507 | def deleteCB(delete_message, **kwargs): |
1291 | 1508 | messages_history.append(delete_message) |
1292 | 1509 | if delete_message.status == 0: |
1293 | closeFid(delete_message.tid, kwargs['fid'], status = 0) | |
1294 | else: | |
1295 | closeFid(delete_message.tid, kwargs['fid'], status = delete_message.status) | |
1510 | closeFid(kwargs['tid'], kwargs['fid'], status = 0) | |
1511 | else: | |
1512 | closeFid(kwargs['tid'], kwargs['fid'], status = delete_message.status) | |
1296 | 1513 | |
1297 | 1514 | def closeFid(tid, fid, status = None): |
1298 | 1515 | m = SMB2Message(SMB2CloseRequest(fid)) |
1368 | 1585 | def createCB(create_message, **kwargs): |
1369 | 1586 | messages_history.append(create_message) |
1370 | 1587 | if create_message.status == 0: |
1371 | sendRename(create_message.tid, create_message.payload.fid) | |
1588 | sendRename(kwargs['tid'], create_message.payload.fid) | |
1372 | 1589 | else: |
1373 | 1590 | errback(OperationFailure('Failed to rename %s on %s: Unable to open file/directory' % ( old_path, service_name ), messages_history)) |
1374 | 1591 | |
1381 | 1598 | data = data)) |
1382 | 1599 | m.tid = tid |
1383 | 1600 | self._sendSMBMessage(m) |
1384 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, renameCB, errback, fid = fid) | |
1601 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, renameCB, errback, tid = tid, fid = fid) | |
1385 | 1602 | messages_history.append(m) |
1386 | 1603 | |
1387 | 1604 | def renameCB(rename_message, **kwargs): |
1388 | 1605 | messages_history.append(rename_message) |
1389 | 1606 | if rename_message.status == 0: |
1390 | closeFid(rename_message.tid, kwargs['fid'], status = 0) | |
1391 | else: | |
1392 | closeFid(rename_message.tid, kwargs['fid'], status = rename_message.status) | |
1607 | closeFid(kwargs['tid'], kwargs['fid'], status = 0) | |
1608 | else: | |
1609 | closeFid(kwargs['tid'], kwargs['fid'], status = rename_message.status) | |
1393 | 1610 | |
1394 | 1611 | def closeFid(tid, fid, status = None): |
1395 | 1612 | m = SMB2Message(SMB2CloseRequest(fid)) |
1456 | 1673 | def createCB(create_message, **kwargs): |
1457 | 1674 | messages_history.append(create_message) |
1458 | 1675 | if create_message.status == 0: |
1459 | sendEnumSnapshots(create_message.tid, create_message.payload.fid) | |
1676 | sendEnumSnapshots(kwargs['tid'], create_message.payload.fid) | |
1460 | 1677 | else: |
1461 | 1678 | errback(OperationFailure('Failed to list snapshots %s on %s: Unable to open file/directory' % ( old_path, service_name ), messages_history)) |
1462 | 1679 | |
1597 | 1814 | self._handleSessionChallenge(message, ntlm_token) |
1598 | 1815 | except ( securityblob.BadSecurityBlobError, securityblob.UnsupportedSecurityProvider ), ex: |
1599 | 1816 | raise ProtocolError(str(ex), message.raw_data, message) |
1600 | elif message.status.internal_value == 0xc000006d: # STATUS_LOGON_FAILURE | |
1817 | elif (message.status.internal_value == 0xc000006d # STATUS_LOGON_FAILURE | |
1818 | or message.status.internal_value == 0xc0000064 # STATUS_NO_SUCH_USER | |
1819 | or message.status.internal_value == 0xc000006a): # STATUS_WRONG_PASSWORD | |
1601 | 1820 | self.has_authenticated = False |
1602 | self.log.info('Authentication (with extended security) failed. Please check username and password. You may need to enable/disable NTLMv2 authentication.') | |
1821 | self.log.info('Authentication (with extended security) failed. Please check username and password.') | |
1822 | self.onAuthFailed() | |
1823 | elif (message.status.internal_value == 0xc0000193 # STATUS_ACCOUNT_EXPIRED | |
1824 | or message.status.internal_value == 0xC0000071): # STATUS_PASSWORD_EXPIRED | |
1825 | self.has_authenticated = False | |
1826 | self.log.info('Authentication (with extended security) failed. Account or password has expired.') | |
1827 | self.onAuthFailed() | |
1828 | elif message.status.internal_value == 0xc0000234: # STATUS_ACCOUNT_LOCKED_OUT | |
1829 | self.has_authenticated = False | |
1830 | self.log.info('Authentication (with extended security) failed. Account has been locked due to too many invalid logon attempts.') | |
1831 | self.onAuthFailed() | |
1832 | elif message.status.internal_value == 0xc0000072: # STATUS_ACCOUNT_DISABLED | |
1833 | self.has_authenticated = False | |
1834 | self.log.info('Authentication (with extended security) failed. Account has been disabled.') | |
1835 | self.onAuthFailed() | |
1836 | elif (message.status.internal_value == 0xc000006f # STATUS_INVALID_LOGON_HOURS | |
1837 | or message.status.internal_value == 0xc000015b # STATUS_LOGON_TYPE_NOT_GRANTED | |
1838 | or message.status.internal_value == 0xc0000070): # STATUS_INVALID_WORKSTATION | |
1839 | self.has_authenticated = False | |
1840 | self.log.info('Authentication (with extended security) failed. Not allowed.') | |
1841 | self.onAuthFailed() | |
1842 | elif message.status.internal_value == 0xc000018c: # STATUS_TRUSTED_DOMAIN_FAILURE | |
1843 | self.has_authenticated = False | |
1844 | self.log.info('Authentication (with extended security) failed. Domain not trusted.') | |
1845 | self.onAuthFailed() | |
1846 | elif message.status.internal_value == 0xc000018d: # STATUS_TRUSTED_RELATIONSHIP_FAILURE | |
1847 | self.has_authenticated = False | |
1848 | self.log.info('Authentication (with extended security) failed. Workstation not trusted.') | |
1603 | 1849 | self.onAuthFailed() |
1604 | 1850 | else: |
1605 | 1851 | raise ProtocolError('Unknown status value (0x%08X) in SMB_COM_SESSION_SETUP_ANDX (with extended security)' % message.status.internal_value, |
1661 | 1907 | self.log.info('Performing NTLMv1 authentication (with extended security) with server challenge "%s"', binascii.hexlify(server_challenge)) |
1662 | 1908 | nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV1(self.password, server_challenge, True) |
1663 | 1909 | |
1664 | ntlm_data = ntlm.generateAuthenticateMessage(server_flags, | |
1665 | nt_challenge_response, | |
1666 | lm_challenge_response, | |
1667 | session_key, | |
1668 | self.username, | |
1669 | self.domain) | |
1910 | ntlm_data, session_signing_key = ntlm.generateAuthenticateMessage(server_flags, | |
1911 | nt_challenge_response, | |
1912 | lm_challenge_response, | |
1913 | session_key, | |
1914 | self.username, | |
1915 | self.domain, | |
1916 | self.my_name) | |
1670 | 1917 | |
1671 | 1918 | if self.log.isEnabledFor(logging.DEBUG): |
1672 | 1919 | self.log.debug('NT challenge response is "%s" (%d bytes)', binascii.hexlify(nt_challenge_response), len(nt_challenge_response)) |
1686 | 1933 | |
1687 | 1934 | if self.is_signing_active: |
1688 | 1935 | self.log.info("SMB signing activated. All SMB messages will be signed.") |
1689 | self.signing_session_key = session_key | |
1936 | self.signing_session_key = session_signing_key | |
1690 | 1937 | if self.capabilities & CAP_EXTENDED_SECURITY: |
1691 | 1938 | self.signing_challenge_response = None |
1692 | 1939 | else: |
1860 | 2107 | def readCB(read_message, **kwargs): |
1861 | 2108 | messages_history.append(read_message) |
1862 | 2109 | if not read_message.status.hasError: |
1863 | data_len = read_message.payload.data_length | |
1864 | 2110 | data_bytes = read_message.payload.data |
1865 | 2111 | |
1866 | 2112 | if ord(data_bytes[3]) & 0x02 == 0: |
1867 | sendReadRequest(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:data_len-24]) | |
1868 | else: | |
1869 | decodeResults(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:data_len-24]) | |
2113 | sendReadRequest(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:]) | |
2114 | else: | |
2115 | decodeResults(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:]) | |
1870 | 2116 | else: |
1871 | 2117 | closeFid(read_message.tid, kwargs['fid']) |
1872 | 2118 | errback(OperationFailure('Failed to list shares: Unable to retrieve shared device list', messages_history)) |
1905 | 2151 | setup_bytes = struct.pack('<H', 0x0001) # TRANS2_FIND_FIRST2 sub-command. See [MS-CIFS]: 2.2.6.2.1 |
1906 | 2152 | params_bytes = \ |
1907 | 2153 | struct.pack('<HHHHI', |
1908 | search, # SearchAttributes | |
2154 | search & 0xFFFF, # SearchAttributes (need to restrict the values due to introduction of SMB_FILE_ATTRIBUTE_INCL_NORMAL) | |
1909 | 2155 | 100, # SearchCount |
1910 | 2156 | 0x0006, # Flags: SMB_FIND_CLOSE_AT_EOS | SMB_FIND_RETURN_RESUME_KEYS |
1911 | 2157 | 0x0104, # InfoLevel: SMB_FIND_FILE_BOTH_DIRECTORY_INFO |
1912 | 0x0000) # SearchStorageType | |
2158 | 0x0000) # SearchStorageType (seems to be ignored by Windows) | |
1913 | 2159 | if support_dfs: |
1914 | 2160 | params_bytes += ("\\" + self.remote_name + "\\" + service_name + path + pattern + '\0').encode('UTF-16LE') |
1915 | 2161 | else: |
1916 | params_bytes += (path + pattern).encode('UTF-16LE') | |
2162 | params_bytes += (path + pattern + '\0').encode('UTF-16LE') | |
1917 | 2163 | |
1918 | 2164 | m = SMBMessage(ComTransaction2Request(max_params_count = 10, |
1919 | 2165 | max_data_count = 16644, |
1949 | 2195 | |
1950 | 2196 | filename = data_bytes[offset2:offset2+filename_length].decode('UTF-16LE') |
1951 | 2197 | short_name = short_name.decode('UTF-16LE') |
1952 | results.append(SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time), | |
1953 | convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time), | |
1954 | file_size, alloc_size, file_attributes, short_name, filename)) | |
2198 | ||
2199 | accept_result = False | |
2200 | if (file_attributes & 0xff) in ( 0x00, ATTR_NORMAL ): # Only the first 8-bits are compared. We ignore other bits like temp, compressed, encryption, sparse, indexed, etc | |
2201 | accept_result = (search == SMB_FILE_ATTRIBUTE_NORMAL) or (search & SMB_FILE_ATTRIBUTE_INCL_NORMAL) | |
2202 | else: | |
2203 | accept_result = (file_attributes & search) > 0 | |
2204 | if accept_result: | |
2205 | results.append(SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time), | |
2206 | convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time), | |
2207 | file_size, alloc_size, file_attributes, short_name, filename)) | |
1955 | 2208 | |
1956 | 2209 | if next_offset: |
1957 | 2210 | offset += next_offset |
1991 | 2244 | elif end_of_search: |
1992 | 2245 | callback(results) |
1993 | 2246 | else: |
1994 | sendFindNext(find_message.tid, sid, last_name_offset, kwargs.get('support_dfs', False)) | |
1995 | else: | |
1996 | errback(OperationFailure('Failed to list %s on %s: Unable to retrieve file list' % ( path, service_name ), messages_history)) | |
1997 | ||
1998 | def sendFindNext(tid, sid, resume_key, support_dfs=False): | |
2247 | sendFindNext(find_message.tid, sid, 0, results[-1].filename, kwargs.get('support_dfs', False)) | |
2248 | else: | |
2249 | if find_message.status.internal_value == 0xC000000F: # [MS-ERREF]: STATUS_NO_SUCH_FILE | |
2250 | # Remote server returns STATUS_NO_SUCH_FILE error so we assume that the search returns no matching files | |
2251 | callback([ ]) | |
2252 | else: | |
2253 | errback(OperationFailure('Failed to list %s on %s: Unable to retrieve file list' % ( path, service_name ), messages_history)) | |
2254 | ||
2255 | def sendFindNext(tid, sid, resume_key, resume_file, support_dfs=False): | |
1999 | 2256 | setup_bytes = struct.pack('<H', 0x0002) # TRANS2_FIND_NEXT2 sub-command. See [MS-CIFS]: 2.2.6.3.1 |
2000 | 2257 | params_bytes = \ |
2001 | 2258 | struct.pack('<HHHIH', |
2003 | 2260 | 100, # SearchCount |
2004 | 2261 | 0x0104, # InfoLevel: SMB_FIND_FILE_BOTH_DIRECTORY_INFO |
2005 | 2262 | resume_key, # ResumeKey |
2006 | 0x000a) # Flags: SMB_FIND_RETURN_RESUME_KEYS | SMB_FIND_CLOSE_AT_EOS | SMB_FIND_RETURN_RESUME_KEYS | |
2007 | if support_dfs: | |
2008 | params_bytes += ("\\" + self.remote_name + "\\" + service_name + path + pattern + '\0').encode('UTF-16LE') | |
2009 | else: | |
2010 | params_bytes += (path + pattern).encode('UTF-16LE') | |
2263 | 0x0006) # Flags: SMB_FIND_RETURN_RESUME_KEYS | SMB_FIND_CLOSE_AT_EOS | |
2264 | params_bytes += (resume_file+'\0').encode('UTF-16LE') | |
2011 | 2265 | |
2012 | 2266 | m = SMBMessage(ComTransaction2Request(max_params_count = 10, |
2013 | 2267 | max_data_count = 16644, |
2053 | 2307 | elif end_of_search: |
2054 | 2308 | callback(results) |
2055 | 2309 | else: |
2056 | sendFindNext(find_message.tid, kwargs['sid'], last_name_offset, kwargs.get('support_dfs', False)) | |
2310 | sendFindNext(find_message.tid, kwargs['sid'], 0, results[-1].filename, kwargs.get('support_dfs', False)) | |
2057 | 2311 | else: |
2058 | 2312 | errback(OperationFailure('Failed to list %s on %s: Unable to retrieve file list' % ( path, service_name ), messages_history)) |
2059 | 2313 | |
2131 | 2385 | info_size = struct.calcsize(info_format) |
2132 | 2386 | create_time, last_access_time, last_write_time, last_attr_change_time, \ |
2133 | 2387 | file_attributes, _, alloc_size, file_size = struct.unpack(info_format, query_message.payload.data_bytes[:info_size]) |
2134 | ||
2135 | info = SharedFile(create_time, last_access_time, last_write_time, last_attr_change_time, | |
2136 | file_size, alloc_size, file_attributes, unicode(path), unicode(path)) | |
2388 | filename = self._extractLastPathComponent(unicode(path)) | |
2389 | ||
2390 | info = SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time), convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time), | |
2391 | file_size, alloc_size, file_attributes, filename, filename) | |
2137 | 2392 | callback(info) |
2138 | 2393 | else: |
2139 | 2394 | errback(OperationFailure('Failed to get attributes for %s on %s: Read failed' % ( path, service_name ), messages_history)) |
2153 | 2408 | messages_history.append(m) |
2154 | 2409 | else: |
2155 | 2410 | sendQuery(self.connected_trees[service_name]) |
2411 | ||
2412 | def _getSecurity_SMB1(self, service_name, path_file_pattern, callback, errback, timeout = 30): | |
2413 | raise NotReadyError('getSecurity is not yet implemented for SMB1') | |
2156 | 2414 | |
2157 | 2415 | def _retrieveFile_SMB1(self, service_name, path, file_obj, callback, errback, timeout = 30): |
2158 | 2416 | return self._retrieveFileFromOffset(service_name, path, file_obj, callback, errback, 0L, -1L, timeout) |
2277 | 2535 | errback(OperationFailure('Failed to store %s on %s: Unable to open file' % ( path, service_name ), messages_history)) |
2278 | 2536 | |
2279 | 2537 | def sendWrite(tid, fid, offset): |
2280 | # For message signing, the total SMB message size must be not exceed the max_buffer_size. Non-message signing does not have this limitation | |
2281 | write_count = min((self.is_signing_active and (self.max_buffer_size-64)) or self.max_raw_size, 0xFFFF-1) # Need to minus 1 byte from 0xFFFF because of the first NULL byte in the ComWriteAndxRequest message data | |
2538 | # [MS-SMB] 2.2.4.5.2.2: The total SMB message size (inclusive of SMB header) must be not exceed the max_buffer_size. | |
2539 | write_count = min(self.max_buffer_size-64, 0xFFFF-64) # SMB header is 32-bytes. We factor in another 32-bytes for the message parameter block | |
2282 | 2540 | data_bytes = file_obj.read(write_count) |
2283 | 2541 | data_len = len(data_bytes) |
2284 | 2542 | if data_len > 0: |
2321 | 2579 | else: |
2322 | 2580 | sendOpen(self.connected_trees[service_name]) |
2323 | 2581 | |
2324 | def _deleteFiles_SMB1(self, service_name, path_file_pattern, callback, errback, timeout = 30): | |
2582 | def _deleteFiles_SMB1(self, service_name, path_file_pattern, delete_matching_folders, callback, errback, timeout = 30): | |
2325 | 2583 | if not self.has_authenticated: |
2326 | 2584 | raise NotReadyError('SMB connection not authenticated') |
2327 | 2585 | |
2586 | expiry_time = time.time() + timeout | |
2587 | pattern = None | |
2328 | 2588 | path = path_file_pattern.replace('/', '\\') |
2589 | if path.startswith('\\'): | |
2590 | path = path[1:] | |
2591 | if path.endswith('\\'): | |
2592 | path = path[:-1] | |
2593 | else: | |
2594 | path_components = path.split('\\') | |
2595 | if path_components[-1].find('*') > -1 or path_components[-1].find('?') > -1: | |
2596 | path = '\\'.join(path_components[:-1]) | |
2597 | pattern = path_components[-1] | |
2598 | messages_history, files_queue = [ ], [ ] | |
2599 | ||
2600 | if pattern is None: | |
2601 | path_components = path.split('\\') | |
2602 | if len(path_components) > 1: | |
2603 | files_queue.append(( '\\'.join(path_components[:-1]), path_components[-1] )) | |
2604 | else: | |
2605 | files_queue.append(( '', path )) | |
2606 | ||
2607 | def deleteCB(path): | |
2608 | if files_queue: | |
2609 | p, filename = files_queue.pop(0) | |
2610 | if filename: | |
2611 | if p: | |
2612 | filename = p + '\\' + filename | |
2613 | self._deleteFiles_SMB1__del(service_name, self.connected_trees[service_name], filename, deleteCB, errback, timeout) | |
2614 | else: | |
2615 | self._deleteDirectory_SMB1(service_name, p, deleteCB, errback, timeout = 30) | |
2616 | else: | |
2617 | callback(path_file_pattern) | |
2618 | ||
2619 | def listCB(files_list): | |
2620 | files_queue.extend(files_list) | |
2621 | deleteCB(None) | |
2622 | ||
2623 | if not self.connected_trees.has_key(service_name): | |
2624 | def connectCB(connect_message, **kwargs): | |
2625 | messages_history.append(connect_message) | |
2626 | if not connect_message.status.hasError: | |
2627 | self.connected_trees[service_name] = connect_message.tid | |
2628 | if files_queue: | |
2629 | deleteCB(None) | |
2630 | else: | |
2631 | self._deleteFiles_SMB1__list(service_name, path, pattern, delete_matching_folders, listCB, errback, timeout) | |
2632 | else: | |
2633 | errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
2634 | ||
2635 | m = SMBMessage(ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, '')) | |
2636 | self._sendSMBMessage(m) | |
2637 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name) | |
2638 | messages_history.append(m) | |
2639 | else: | |
2640 | if files_queue: | |
2641 | deleteCB(None) | |
2642 | else: | |
2643 | self._deleteFiles_SMB1__list(service_name, path, pattern, delete_matching_folders, listCB, errback, timeout) | |
2644 | ||
2645 | def _deleteFiles_SMB1__list(self, service_name, path, pattern, delete_matching_folders, callback, errback, timeout = 30): | |
2646 | folder_queue = [ ] | |
2647 | files_list = [ ] | |
2648 | current_path = [ path ] | |
2649 | search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL | |
2650 | ||
2651 | def listCB(results): | |
2652 | files = [ ] | |
2653 | for f in filter(lambda x: x.filename not in [ '.', '..' ], results): | |
2654 | if f.isDirectory: | |
2655 | if delete_matching_folders: | |
2656 | folder_queue.append(current_path[0]+'\\'+f.filename) | |
2657 | else: | |
2658 | files.append(( current_path[0], f.filename )) | |
2659 | if current_path[0]!=path and delete_matching_folders: | |
2660 | files.append(( current_path[0], None )) | |
2661 | ||
2662 | if files: | |
2663 | files_list[0:0] = files | |
2664 | ||
2665 | if folder_queue: | |
2666 | p = folder_queue.pop() | |
2667 | current_path[0] = p | |
2668 | self._listPath_SMB1(service_name, current_path[0], listCB, errback, search = search, pattern = '*', timeout = 30) | |
2669 | else: | |
2670 | callback(files_list) | |
2671 | ||
2672 | self._listPath_SMB1(service_name, path, listCB, errback, search = search, pattern = pattern, timeout = timeout) | |
2673 | ||
2674 | ||
2675 | def _deleteFiles_SMB1__del(self, service_name, tid, path, callback, errback, timeout = 30): | |
2329 | 2676 | messages_history = [ ] |
2330 | 2677 | |
2331 | 2678 | def sendDelete(tid): |
2339 | 2686 | def deleteCB(delete_message, **kwargs): |
2340 | 2687 | messages_history.append(delete_message) |
2341 | 2688 | if not delete_message.status.hasError: |
2689 | callback(path) | |
2690 | elif delete_message.status.internal_value == 0xC000000FL: # [MS-ERREF]: STATUS_NO_SUCH_FILE | |
2691 | # If there are no matching files, we just treat as success instead of failing | |
2342 | 2692 | callback(path_file_pattern) |
2343 | else: | |
2344 | errback(OperationFailure('Failed to store %s on %s: Delete failed' % ( path, service_name ), messages_history)) | |
2693 | elif delete_message.status.internal_value == 0xC00000BAL: # [MS-ERREF]: STATUS_FILE_IS_A_DIRECTORY | |
2694 | errback(OperationFailure('Failed to delete %s on %s: Cannot delete a folder. Please use deleteDirectory() method or append "/*" to your path if you wish to delete all files in the folder.' % ( path, service_name ), messages_history)) | |
2695 | elif delete_message.status.internal_value == 0xC0000034L: # [MS-ERREF]: STATUS_OBJECT_NAME_INVALID | |
2696 | errback(OperationFailure('Failed to delete %s on %s: Path not found' % ( path, service_name ), messages_history)) | |
2697 | else: | |
2698 | errback(OperationFailure('Failed to delete %s on %s: Delete failed' % ( path, service_name ), messages_history)) | |
2699 | ||
2700 | sendDelete(tid) | |
2701 | ||
2702 | def _resetFileAttributes_SMB1(self, service_name, path_file_pattern, callback, errback, file_attributes=ATTR_NORMAL, timeout = 30): | |
2703 | raise NotReadyError('resetFileAttributes is not yet implemented for SMB1') | |
2704 | ||
2705 | def _createDirectory_SMB1(self, service_name, path, callback, errback, timeout = 30): | |
2706 | if not self.has_authenticated: | |
2707 | raise NotReadyError('SMB connection not authenticated') | |
2708 | ||
2709 | path = path.replace('/', '\\') | |
2710 | messages_history = [ ] | |
2711 | ||
2712 | def sendCreate(tid): | |
2713 | m = SMBMessage(ComCreateDirectoryRequest(path)) | |
2714 | m.tid = tid | |
2715 | self._sendSMBMessage(m) | |
2716 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback) | |
2717 | messages_history.append(m) | |
2718 | ||
2719 | def createCB(create_message, **kwargs): | |
2720 | messages_history.append(create_message) | |
2721 | if not create_message.status.hasError: | |
2722 | callback(path) | |
2723 | else: | |
2724 | errback(OperationFailure('Failed to create directory %s on %s: Create failed' % ( path, service_name ), messages_history)) | |
2725 | ||
2726 | if not self.connected_trees.has_key(service_name): | |
2727 | def connectCB(connect_message, **kwargs): | |
2728 | messages_history.append(connect_message) | |
2729 | if not connect_message.status.hasError: | |
2730 | self.connected_trees[service_name] = connect_message.tid | |
2731 | sendCreate(connect_message.tid) | |
2732 | else: | |
2733 | errback(OperationFailure('Failed to create directory %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
2734 | ||
2735 | m = SMBMessage(ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, '')) | |
2736 | self._sendSMBMessage(m) | |
2737 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name) | |
2738 | messages_history.append(m) | |
2739 | else: | |
2740 | sendCreate(self.connected_trees[service_name]) | |
2741 | ||
2742 | def _deleteDirectory_SMB1(self, service_name, path, callback, errback, timeout = 30): | |
2743 | if not self.has_authenticated: | |
2744 | raise NotReadyError('SMB connection not authenticated') | |
2745 | ||
2746 | path = path.replace('/', '\\') | |
2747 | messages_history = [ ] | |
2748 | ||
2749 | def sendDelete(tid): | |
2750 | m = SMBMessage(ComDeleteDirectoryRequest(path)) | |
2751 | m.tid = tid | |
2752 | self._sendSMBMessage(m) | |
2753 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback) | |
2754 | messages_history.append(m) | |
2755 | ||
2756 | def deleteCB(delete_message, **kwargs): | |
2757 | messages_history.append(delete_message) | |
2758 | if not delete_message.status.hasError: | |
2759 | callback(path) | |
2760 | else: | |
2761 | errback(OperationFailure('Failed to delete directory %s on %s: Delete failed' % ( path, service_name ), messages_history)) | |
2345 | 2762 | |
2346 | 2763 | if not self.connected_trees.has_key(service_name): |
2347 | 2764 | def connectCB(connect_message, **kwargs): |
2350 | 2767 | self.connected_trees[service_name] = connect_message.tid |
2351 | 2768 | sendDelete(connect_message.tid) |
2352 | 2769 | else: |
2353 | errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
2354 | ||
2355 | m = SMBMessage(ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, '')) | |
2356 | self._sendSMBMessage(m) | |
2357 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name) | |
2358 | messages_history.append(m) | |
2359 | else: | |
2360 | sendDelete(self.connected_trees[service_name]) | |
2361 | ||
2362 | def _resetFileAttributes_SMB1(self, service_name, path_file_pattern, callback, errback, timeout = 30): | |
2363 | raise NotReadyError('resetFileAttributes is not yet implemented for SMB1') | |
2364 | ||
2365 | def _createDirectory_SMB1(self, service_name, path, callback, errback, timeout = 30): | |
2366 | if not self.has_authenticated: | |
2367 | raise NotReadyError('SMB connection not authenticated') | |
2368 | ||
2369 | path = path.replace('/', '\\') | |
2370 | messages_history = [ ] | |
2371 | ||
2372 | def sendCreate(tid): | |
2373 | m = SMBMessage(ComCreateDirectoryRequest(path)) | |
2374 | m.tid = tid | |
2375 | self._sendSMBMessage(m) | |
2376 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback) | |
2377 | messages_history.append(m) | |
2378 | ||
2379 | def createCB(create_message, **kwargs): | |
2380 | messages_history.append(create_message) | |
2381 | if not create_message.status.hasError: | |
2382 | callback(path) | |
2383 | else: | |
2384 | errback(OperationFailure('Failed to create directory %s on %s: Create failed' % ( path, service_name ), messages_history)) | |
2385 | ||
2386 | if not self.connected_trees.has_key(service_name): | |
2387 | def connectCB(connect_message, **kwargs): | |
2388 | messages_history.append(connect_message) | |
2389 | if not connect_message.status.hasError: | |
2390 | self.connected_trees[service_name] = connect_message.tid | |
2391 | sendCreate(connect_message.tid) | |
2392 | else: | |
2393 | errback(OperationFailure('Failed to create directory %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
2394 | ||
2395 | m = SMBMessage(ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, '')) | |
2396 | self._sendSMBMessage(m) | |
2397 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name) | |
2398 | messages_history.append(m) | |
2399 | else: | |
2400 | sendCreate(self.connected_trees[service_name]) | |
2401 | ||
2402 | def _deleteDirectory_SMB1(self, service_name, path, callback, errback, timeout = 30): | |
2403 | if not self.has_authenticated: | |
2404 | raise NotReadyError('SMB connection not authenticated') | |
2405 | ||
2406 | path = path.replace('/', '\\') | |
2407 | messages_history = [ ] | |
2408 | ||
2409 | def sendDelete(tid): | |
2410 | m = SMBMessage(ComDeleteDirectoryRequest(path)) | |
2411 | m.tid = tid | |
2412 | self._sendSMBMessage(m) | |
2413 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback) | |
2414 | messages_history.append(m) | |
2415 | ||
2416 | def deleteCB(delete_message, **kwargs): | |
2417 | messages_history.append(delete_message) | |
2418 | if not delete_message.status.hasError: | |
2419 | callback(path) | |
2420 | else: | |
2421 | errback(OperationFailure('Failed to delete directory %s on %s: Delete failed' % ( path, service_name ), messages_history)) | |
2422 | ||
2423 | if not self.connected_trees.has_key(service_name): | |
2424 | def connectCB(connect_message, **kwargs): | |
2425 | messages_history.append(connect_message) | |
2426 | if not connect_message.status.hasError: | |
2427 | self.connected_trees[service_name] = connect_message.tid | |
2428 | sendDelete(connect_message.tid) | |
2429 | else: | |
2430 | errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
2770 | errback(OperationFailure('Failed to delete directory %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
2431 | 2771 | |
2432 | 2772 | m = SMBMessage(ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, '')) |
2433 | 2773 | self._sendSMBMessage(m) |
2562 | 2902 | def _echo_SMB1(self, data, callback, errback, timeout = 30): |
2563 | 2903 | messages_history = [ ] |
2564 | 2904 | |
2905 | if not isinstance(data, type(b'')): | |
2906 | raise TypeError('Echo data must be %s not %s' % (type(b'').__name__, type(data).__name__)) | |
2907 | ||
2565 | 2908 | def echoCB(echo_message, **kwargs): |
2566 | 2909 | messages_history.append(echo_message) |
2567 | 2910 | if not echo_message.status.hasError: |
2574 | 2917 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, echoCB, errback) |
2575 | 2918 | messages_history.append(m) |
2576 | 2919 | |
2920 | def _extractLastPathComponent(self, path): | |
2921 | return path.replace('\\', '/').split('/')[-1] | |
2922 | ||
2577 | 2923 | |
2578 | 2924 | class SharedDevice: |
2579 | 2925 | """ |
2580 | 2926 | Contains information about a single shared device on the remote server. |
2927 | ||
2928 | The following attributes are available: | |
2929 | ||
2930 | * name : An unicode string containing the name of the shared device | |
2931 | * comments : An unicode string containing the user description of the shared device | |
2581 | 2932 | """ |
2582 | 2933 | |
2583 | 2934 | # The following constants are taken from [MS-SRVS]: 2.2.2.4 |
2632 | 2983 | |
2633 | 2984 | If you encounter *SharedFile* instance where its short_name attribute is empty but the filename attribute contains a short name which does not correspond |
2634 | 2985 | to any files/folders on your remote shared device, it could be that the original filename on the file/folder entry on the shared device contains |
2635 | one of these prohibited characters: "\/[]:+|<>=;?,* (see [MS-CIFS]: 2.2.1.1.1 for more details). | |
2986 | one of these prohibited characters: "\\/[]:+|<>=;?,* (see [MS-CIFS]: 2.2.1.1.1 for more details). | |
2987 | ||
2988 | The following attributes are available: | |
2989 | ||
2990 | * create_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of creation of this file resource on the remote server | |
2991 | * last_access_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last access of this file resource on the remote server | |
2992 | * last_write_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last modification of this file resource on the remote server | |
2993 | * last_attr_change_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last attribute change of this file resource on the remote server | |
2994 | * file_size : File size in number of bytes | |
2995 | * alloc_size : Total number of bytes allocated to store this file | |
2996 | * file_attributes : A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3. You can perform bit-wise tests to determine the status of the file using the ATTR_xxx constants in smb_constants.py. | |
2997 | * short_name : Unicode string containing the short name of this file (usually in 8.3 notation) | |
2998 | * filename : Unicode string containing the long filename of this file. Each OS has a limit to the length of this file name. On Windows, it is 256 characters. | |
2999 | * file_id : Long value representing the file reference number for the file. If the remote system does not support this field, this field will be None or 0. See [MS-FSCC]: 2.4.17 | |
2636 | 3000 | """ |
2637 | 3001 | |
2638 | def __init__(self, create_time, last_access_time, last_write_time, last_attr_change_time, file_size, alloc_size, file_attributes, short_name, filename): | |
3002 | def __init__(self, create_time, last_access_time, last_write_time, last_attr_change_time, file_size, alloc_size, file_attributes, short_name, filename, file_id=None): | |
2639 | 3003 | self.create_time = create_time #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of creation of this file resource on the remote server |
2640 | 3004 | self.last_access_time = last_access_time #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last access of this file resource on the remote server |
2641 | 3005 | self.last_write_time = last_write_time #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last modification of this file resource on the remote server |
2642 | 3006 | self.last_attr_change_time = last_attr_change_time #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last attribute change of this file resource on the remote server |
2643 | 3007 | self.file_size = file_size #: File size in number of bytes |
2644 | 3008 | self.alloc_size = alloc_size #: Total number of bytes allocated to store this file |
2645 | self.file_attributes = file_attributes #: A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3 | |
3009 | self.file_attributes = file_attributes #: A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3. You can perform bit-wise tests to determine the status of the file using the ATTR_xxx constants in smb_constants.py. | |
2646 | 3010 | self.short_name = short_name #: Unicode string containing the short name of this file (usually in 8.3 notation) |
2647 | 3011 | self.filename = filename #: Unicode string containing the long filename of this file. Each OS has a limit to the length of this file name. On Windows, it is 256 characters. |
3012 | self.file_id = file_id #: Long value representing the file reference number for the file. If the remote system does not support this field, this field will be None or 0. See [MS-FSCC]: 2.4.17 | |
2648 | 3013 | |
2649 | 3014 | @property |
2650 | 3015 | def isDirectory(self): |
2655 | 3020 | def isReadOnly(self): |
2656 | 3021 | """A convenient property to return True if this file resource is read-only on the remote server""" |
2657 | 3022 | return bool(self.file_attributes & ATTR_READONLY) |
3023 | ||
3024 | @property | |
3025 | def isNormal(self): | |
3026 | """ | |
3027 | A convenient property to return True if this is a normal file. | |
3028 | ||
3029 | Note that pysmb defines a normal file as a file entry that is not read-only, not hidden, not system, not archive and not a directory. | |
3030 | It ignores other attributes like compression, indexed, sparse, temporary and encryption. | |
3031 | """ | |
3032 | return (self.file_attributes==ATTR_NORMAL) or ((self.file_attributes & 0xff)==0) | |
2658 | 3033 | |
2659 | 3034 | def __unicode__(self): |
2660 | 3035 | return u'Shared file: %s (FileSize:%d bytes, isDirectory:%s)' % ( self.filename, self.file_size, self.isDirectory ) |
0 | 0 | |
1 | import types, hmac, binascii, struct, random | |
1 | import types, hmac, binascii, struct, random, string | |
2 | from .utils.rc4 import RC4_encrypt | |
2 | 3 | from utils.pyDes import des |
3 | 4 | |
4 | 5 | try: |
57 | 58 | |
58 | 59 | NTLM_FLAGS = NTLM_NegotiateUnicode | \ |
59 | 60 | NTLM_RequestTarget | \ |
61 | NTLM_NegotiateSign | \ | |
60 | 62 | NTLM_NegotiateNTLM | \ |
61 | 63 | NTLM_NegotiateAlwaysSign | \ |
62 | 64 | NTLM_NegotiateExtendedSecurity | \ |
63 | 65 | NTLM_NegotiateTargetInfo | \ |
64 | 66 | NTLM_NegotiateVersion | \ |
65 | 67 | NTLM_Negotiate128 | \ |
66 | NTLM_NegotiateKeyExchange | \ | |
67 | NTLM_Negotiate56 | |
68 | NTLM_NegotiateKeyExchange | |
68 | 69 | |
69 | 70 | def generateNegotiateMessage(): |
70 | 71 | """ |
80 | 81 | return s |
81 | 82 | |
82 | 83 | |
83 | def generateAuthenticateMessage(challenge_flags, nt_response, lm_response, session_key, user, domain = 'WORKGROUP', workstation = 'LOCALHOST'): | |
84 | def generateAuthenticateMessage(challenge_flags, nt_response, lm_response, request_session_key, user, domain = 'WORKGROUP', workstation = 'LOCALHOST'): | |
84 | 85 | """ |
85 | 86 | References: |
86 | 87 | =========== |
88 | 89 | """ |
89 | 90 | FORMAT = '<8sIHHIHHIHHIHHIHHIHHII' |
90 | 91 | FORMAT_SIZE = struct.calcsize(FORMAT) |
92 | ||
93 | # [MS-NLMP]: 3.1.5.1.2 | |
94 | # http://grutz.jingojango.net/exploits/davenport-ntlm.html | |
95 | session_key = session_signing_key = request_session_key | |
96 | if challenge_flags & NTLM_NegotiateKeyExchange: | |
97 | session_signing_key = "".join([ random.choice(string.digits+string.ascii_letters) for _ in range(16) ]).encode('ascii') | |
98 | session_key = RC4_encrypt(request_session_key, session_signing_key) | |
91 | 99 | |
92 | 100 | lm_response_length = len(lm_response) |
93 | 101 | lm_response_offset = FORMAT_SIZE |
124 | 132 | session_key_length, session_key_length, session_key_offset, |
125 | 133 | auth_flags) |
126 | 134 | |
127 | return s + lm_response + nt_response + padding + domain_unicode + user_unicode + workstation_unicode + session_key | |
135 | return s + lm_response + nt_response + padding + domain_unicode + user_unicode + workstation_unicode + session_key, session_signing_key | |
128 | 136 | |
129 | 137 | |
130 | 138 | def decodeChallengeMessage(ntlm_data): |
0 | """ | |
1 | This module implements security descriptors, and the partial structures | |
2 | used in them, as specified in [MS-DTYP]. | |
3 | """ | |
4 | ||
5 | import struct | |
6 | ||
7 | ||
8 | # Security descriptor control flags | |
9 | # [MS-DTYP]: 2.4.6 | |
10 | SECURITY_DESCRIPTOR_OWNER_DEFAULTED = 0x0001 | |
11 | SECURITY_DESCRIPTOR_GROUP_DEFAULTED = 0x0002 | |
12 | SECURITY_DESCRIPTOR_DACL_PRESENT = 0x0004 | |
13 | SECURITY_DESCRIPTOR_DACL_DEFAULTED = 0x0008 | |
14 | SECURITY_DESCRIPTOR_SACL_PRESENT = 0x0010 | |
15 | SECURITY_DESCRIPTOR_SACL_DEFAULTED = 0x0020 | |
16 | SECURITY_DESCRIPTOR_SERVER_SECURITY = 0x0040 | |
17 | SECURITY_DESCRIPTOR_DACL_TRUSTED = 0x0080 | |
18 | SECURITY_DESCRIPTOR_DACL_COMPUTED_INHERITANCE_REQUIRED = 0x0100 | |
19 | SECURITY_DESCRIPTOR_SACL_COMPUTED_INHERITANCE_REQUIRED = 0x0200 | |
20 | SECURITY_DESCRIPTOR_DACL_AUTO_INHERITED = 0x0400 | |
21 | SECURITY_DESCRIPTOR_SACL_AUTO_INHERITED = 0x0800 | |
22 | SECURITY_DESCRIPTOR_DACL_PROTECTED = 0x1000 | |
23 | SECURITY_DESCRIPTOR_SACL_PROTECTED = 0x2000 | |
24 | SECURITY_DESCRIPTOR_RM_CONTROL_VALID = 0x4000 | |
25 | SECURITY_DESCRIPTOR_SELF_RELATIVE = 0x8000 | |
26 | ||
27 | # ACE types | |
28 | # [MS-DTYP]: 2.4.4.1 | |
29 | ACE_TYPE_ACCESS_ALLOWED = 0x00 | |
30 | ACE_TYPE_ACCESS_DENIED = 0x01 | |
31 | ACE_TYPE_SYSTEM_AUDIT = 0x02 | |
32 | ACE_TYPE_SYSTEM_ALARM = 0x03 | |
33 | ACE_TYPE_ACCESS_ALLOWED_COMPOUND = 0x04 | |
34 | ACE_TYPE_ACCESS_ALLOWED_OBJECT = 0x05 | |
35 | ACE_TYPE_ACCESS_DENIED_OBJECT = 0x06 | |
36 | ACE_TYPE_SYSTEM_AUDIT_OBJECT = 0x07 | |
37 | ACE_TYPE_SYSTEM_ALARM_OBJECT = 0x08 | |
38 | ACE_TYPE_ACCESS_ALLOWED_CALLBACK = 0x09 | |
39 | ACE_TYPE_ACCESS_DENIED_CALLBACK = 0x0A | |
40 | ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT = 0x0B | |
41 | ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT = 0x0C | |
42 | ACE_TYPE_SYSTEM_AUDIT_CALLBACK = 0x0D | |
43 | ACE_TYPE_SYSTEM_ALARM_CALLBACK = 0x0E | |
44 | ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT = 0x0F | |
45 | ACE_TYPE_SYSTEM_ALARM_CALLBACK_OBJECT = 0x10 | |
46 | ACE_TYPE_SYSTEM_MANDATORY_LABEL = 0x11 | |
47 | ACE_TYPE_SYSTEM_RESOURCE_ATTRIBUTE = 0x12 | |
48 | ACE_TYPE_SYSTEM_SCOPED_POLICY_ID = 0x13 | |
49 | ||
50 | # ACE flags | |
51 | # [MS-DTYP]: 2.4.4.1 | |
52 | ACE_FLAG_OBJECT_INHERIT = 0x01 | |
53 | ACE_FLAG_CONTAINER_INHERIT = 0x02 | |
54 | ACE_FLAG_NO_PROPAGATE_INHERIT = 0x04 | |
55 | ACE_FLAG_INHERIT_ONLY = 0x08 | |
56 | ACE_FLAG_INHERITED = 0x10 | |
57 | ACE_FLAG_SUCCESSFUL_ACCESS = 0x40 | |
58 | ACE_FLAG_FAILED_ACCESS = 0x80 | |
59 | ||
60 | # Pre-defined well-known SIDs | |
61 | # [MS-DTYP]: 2.4.2.4 | |
62 | SID_NULL = "S-1-0-0" | |
63 | SID_EVERYONE = "S-1-1-0" | |
64 | SID_LOCAL = "S-1-2-0" | |
65 | SID_CONSOLE_LOGON = "S-1-2-1" | |
66 | SID_CREATOR_OWNER = "S-1-3-0" | |
67 | SID_CREATOR_GROUP = "S-1-3-1" | |
68 | SID_OWNER_SERVER = "S-1-3-2" | |
69 | SID_GROUP_SERVER = "S-1-3-3" | |
70 | SID_OWNER_RIGHTS = "S-1-3-4" | |
71 | SID_NT_AUTHORITY = "S-1-5" | |
72 | SID_DIALUP = "S-1-5-1" | |
73 | SID_NETWORK = "S-1-5-2" | |
74 | SID_BATCH = "S-1-5-3" | |
75 | SID_INTERACTIVE = "S-1-5-4" | |
76 | SID_SERVICE = "S-1-5-6" | |
77 | SID_ANONYMOUS = "S-1-5-7" | |
78 | SID_PROXY = "S-1-5-8" | |
79 | SID_ENTERPRISE_DOMAIN_CONTROLLERS = "S-1-5-9" | |
80 | SID_PRINCIPAL_SELF = "S-1-5-10" | |
81 | SID_AUTHENTICATED_USERS = "S-1-5-11" | |
82 | SID_RESTRICTED_CODE = "S-1-5-12" | |
83 | SID_TERMINAL_SERVER_USER = "S-1-5-13" | |
84 | SID_REMOTE_INTERACTIVE_LOGON = "S-1-5-14" | |
85 | SID_THIS_ORGANIZATION = "S-1-5-15" | |
86 | SID_IUSR = "S-1-5-17" | |
87 | SID_LOCAL_SYSTEM = "S-1-5-18" | |
88 | SID_LOCAL_SERVICE = "S-1-5-19" | |
89 | SID_NETWORK_SERVICE = "S-1-5-20" | |
90 | SID_COMPOUNDED_AUTHENTICATION = "S-1-5-21-0-0-0-496" | |
91 | SID_CLAIMS_VALID = "S-1-5-21-0-0-0-497" | |
92 | SID_BUILTIN_ADMINISTRATORS = "S-1-5-32-544" | |
93 | SID_BUILTIN_USERS = "S-1-5-32-545" | |
94 | SID_BUILTIN_GUESTS = "S-1-5-32-546" | |
95 | SID_POWER_USERS = "S-1-5-32-547" | |
96 | SID_ACCOUNT_OPERATORS = "S-1-5-32-548" | |
97 | SID_SERVER_OPERATORS = "S-1-5-32-549" | |
98 | SID_PRINTER_OPERATORS = "S-1-5-32-550" | |
99 | SID_BACKUP_OPERATORS = "S-1-5-32-551" | |
100 | SID_REPLICATOR = "S-1-5-32-552" | |
101 | SID_ALIAS_PREW2KCOMPACC = "S-1-5-32-554" | |
102 | SID_REMOTE_DESKTOP = "S-1-5-32-555" | |
103 | SID_NETWORK_CONFIGURATION_OPS = "S-1-5-32-556" | |
104 | SID_INCOMING_FOREST_TRUST_BUILDERS = "S-1-5-32-557" | |
105 | SID_PERFMON_USERS = "S-1-5-32-558" | |
106 | SID_PERFLOG_USERS = "S-1-5-32-559" | |
107 | SID_WINDOWS_AUTHORIZATION_ACCESS_GROUP = "S-1-5-32-560" | |
108 | SID_TERMINAL_SERVER_LICENSE_SERVERS = "S-1-5-32-561" | |
109 | SID_DISTRIBUTED_COM_USERS = "S-1-5-32-562" | |
110 | SID_IIS_IUSRS = "S-1-5-32-568" | |
111 | SID_CRYPTOGRAPHIC_OPERATORS = "S-1-5-32-569" | |
112 | SID_EVENT_LOG_READERS = "S-1-5-32-573" | |
113 | SID_CERTIFICATE_SERVICE_DCOM_ACCESS = "S-1-5-32-574" | |
114 | SID_RDS_REMOTE_ACCESS_SERVERS = "S-1-5-32-575" | |
115 | SID_RDS_ENDPOINT_SERVERS = "S-1-5-32-576" | |
116 | SID_RDS_MANAGEMENT_SERVERS = "S-1-5-32-577" | |
117 | SID_HYPER_V_ADMINS = "S-1-5-32-578" | |
118 | SID_ACCESS_CONTROL_ASSISTANCE_OPS = "S-1-5-32-579" | |
119 | SID_REMOTE_MANAGEMENT_USERS = "S-1-5-32-580" | |
120 | SID_WRITE_RESTRICTED_CODE = "S-1-5-33" | |
121 | SID_NTLM_AUTHENTICATION = "S-1-5-64-10" | |
122 | SID_SCHANNEL_AUTHENTICATION = "S-1-5-64-14" | |
123 | SID_DIGEST_AUTHENTICATION = "S-1-5-64-21" | |
124 | SID_THIS_ORGANIZATION_CERTIFICATE = "S-1-5-65-1" | |
125 | SID_NT_SERVICE = "S-1-5-80" | |
126 | SID_USER_MODE_DRIVERS = "S-1-5-84-0-0-0-0-0" | |
127 | SID_LOCAL_ACCOUNT = "S-1-5-113" | |
128 | SID_LOCAL_ACCOUNT_AND_MEMBER_OF_ADMINISTRATORS_GROUP = "S-1-5-114" | |
129 | SID_OTHER_ORGANIZATION = "S-1-5-1000" | |
130 | SID_ALL_APP_PACKAGES = "S-1-15-2-1" | |
131 | SID_ML_UNTRUSTED = "S-1-16-0" | |
132 | SID_ML_LOW = "S-1-16-4096" | |
133 | SID_ML_MEDIUM = "S-1-16-8192" | |
134 | SID_ML_MEDIUM_PLUS = "S-1-16-8448" | |
135 | SID_ML_HIGH = "S-1-16-12288" | |
136 | SID_ML_SYSTEM = "S-1-16-16384" | |
137 | SID_ML_PROTECTED_PROCESS = "S-1-16-20480" | |
138 | SID_AUTHENTICATION_AUTHORITY_ASSERTED_IDENTITY = "S-1-18-1" | |
139 | SID_SERVICE_ASSERTED_IDENTITY = "S-1-18-2" | |
140 | SID_FRESH_PUBLIC_KEY_IDENTITY = "S-1-18-3" | |
141 | SID_KEY_TRUST_IDENTITY = "S-1-18-4" | |
142 | SID_KEY_PROPERTY_MFA = "S-1-18-5" | |
143 | SID_KEY_PROPERTY_ATTESTATION = "S-1-18-6" | |
144 | ||
145 | ||
146 | class SID(object): | |
147 | """ | |
148 | A Windows security identifier. Represents a single principal, such a | |
149 | user or a group, as a sequence of numbers consisting of the revision, | |
150 | identifier authority, and a variable-length list of subauthorities. | |
151 | ||
152 | See [MS-DTYP]: 2.4.2 | |
153 | """ | |
154 | def __init__(self, revision, identifier_authority, subauthorities): | |
155 | #: Revision, should always be 1. | |
156 | self.revision = revision | |
157 | #: An integer representing the identifier authority. | |
158 | self.identifier_authority = identifier_authority | |
159 | #: A list of integers representing all subauthorities. | |
160 | self.subauthorities = subauthorities | |
161 | ||
162 | def __str__(self): | |
163 | """ | |
164 | String representation, as specified in [MS-DTYP]: 2.4.2.1 | |
165 | """ | |
166 | if self.identifier_authority >= 2**32: | |
167 | id_auth = '%#x' % (self.identifier_authority,) | |
168 | else: | |
169 | id_auth = self.identifier_authority | |
170 | auths = [self.revision, id_auth] + self.subauthorities | |
171 | return 'S-' + '-'.join(str(subauth) for subauth in auths) | |
172 | ||
173 | def __repr__(self): | |
174 | return 'SID(%r)' % (str(self),) | |
175 | ||
176 | @classmethod | |
177 | def from_bytes(cls, data, return_tail=False): | |
178 | revision, subauth_count = struct.unpack('<BB', data[:2]) | |
179 | identifier_authority = struct.unpack('>Q', '\x00\x00' + data[2:8])[0] | |
180 | subauth_data = data[8:] | |
181 | subauthorities = [struct.unpack('<L', subauth_data[4 * i : 4 * (i+1)])[0] | |
182 | for i in range(subauth_count)] | |
183 | sid = cls(revision, identifier_authority, subauthorities) | |
184 | if return_tail: | |
185 | return sid, subauth_data[4 * subauth_count :] | |
186 | return sid | |
187 | ||
188 | ||
189 | class ACE(object): | |
190 | """ | |
191 | Represents a single access control entry. | |
192 | ||
193 | See [MS-DTYP]: 2.4.4 | |
194 | """ | |
195 | HEADER_FORMAT = '<BBH' | |
196 | ||
197 | def __init__(self, type_, flags, mask, sid, additional_data): | |
198 | #: An integer representing the type of the ACE. One of the | |
199 | #: ``ACE_TYPE_*`` constants. Corresponds to the ``AceType`` field | |
200 | #: from [MS-DTYP] 2.4.4.1. | |
201 | self.type = type_ | |
202 | #: An integer bitmask with ACE flags, corresponds to the | |
203 | #: ``AceFlags`` field. | |
204 | self.flags = flags | |
205 | #: An integer representing the ``ACCESS_MASK`` as specified in | |
206 | #: [MS-DTYP] 2.4.3. | |
207 | self.mask = mask | |
208 | #: The :class:`SID` of a trustee. | |
209 | self.sid = sid | |
210 | #: A dictionary of additional fields present in the ACE, depending | |
211 | #: on the type. The following fields can be present: | |
212 | #: | |
213 | #: * ``flags`` | |
214 | #: * ``object_type`` | |
215 | #: * ``inherited_object_type`` | |
216 | #: * ``application_data`` | |
217 | #: * ``attribute_data`` | |
218 | self.additional_data = additional_data | |
219 | ||
220 | def __repr__(self): | |
221 | return "ACE(type=%#04x, flags=%#04x, mask=%#010x, sid=%s)" % ( | |
222 | self.type, self.flags, self.mask, self.sid, | |
223 | ) | |
224 | ||
225 | @property | |
226 | def isInheritOnly(self): | |
227 | """Convenience property which indicates if this ACE is inherit | |
228 | only, meaning that it doesn't apply to the object itself.""" | |
229 | return bool(self.flags & ACE_FLAG_INHERIT_ONLY) | |
230 | ||
231 | @classmethod | |
232 | def from_bytes(cls, data): | |
233 | header_size = struct.calcsize(cls.HEADER_FORMAT) | |
234 | header = data[:header_size] | |
235 | type_, flags, size = struct.unpack(cls.HEADER_FORMAT, header) | |
236 | ||
237 | assert len(data) >= size | |
238 | ||
239 | body = data[header_size:size] | |
240 | additional_data = {} | |
241 | ||
242 | # In all ACE types, the mask immediately follows the header. | |
243 | mask = struct.unpack('<I', body[:4])[0] | |
244 | body = body[4:] | |
245 | ||
246 | # All OBJECT-type ACEs contain additional flags, and two GUIDs as | |
247 | # the following fields. | |
248 | if type_ in (ACE_TYPE_ACCESS_ALLOWED_OBJECT, | |
249 | ACE_TYPE_ACCESS_DENIED_OBJECT, | |
250 | ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT, | |
251 | ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT, | |
252 | ACE_TYPE_SYSTEM_AUDIT_OBJECT, | |
253 | ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT): | |
254 | additional_data['flags'] = struct.unpack('<I', body[:4])[0] | |
255 | additional_data['object_type'] = body[4:20] | |
256 | additional_data['inherited_object_type'] = body[20:36] | |
257 | body = body[36:] | |
258 | ||
259 | # Then the SID in all types. | |
260 | sid, body = SID.from_bytes(body, return_tail=True) | |
261 | ||
262 | # CALLBACK-type ACEs (and for some obscure reason, | |
263 | # SYSTEM_AUDIT_OBJECT) have a final tail of application data. | |
264 | if type_ in (ACE_TYPE_ACCESS_ALLOWED_CALLBACK, | |
265 | ACE_TYPE_ACCESS_DENIED_CALLBACK, | |
266 | ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT, | |
267 | ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT, | |
268 | ACE_TYPE_SYSTEM_AUDIT_OBJECT, | |
269 | ACE_TYPE_SYSTEM_AUDIT_CALLBACK, | |
270 | ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT): | |
271 | additional_data['application_data'] = body | |
272 | ||
273 | # SYSTEM_RESOURCE_ATTRIBUTE ACEs have a tail of attribute data. | |
274 | if type_ == ACE_TYPE_SYSTEM_RESOURCE_ATTRIBUTE: | |
275 | additional_data['attribute_data'] = body | |
276 | ||
277 | return cls(type_, flags, mask, sid, additional_data) | |
278 | ||
279 | ||
280 | class ACL(object): | |
281 | """ | |
282 | Access control list, encapsulating a sequence of access control | |
283 | entries. | |
284 | ||
285 | See [MS-DTYP]: 2.4.5 | |
286 | """ | |
287 | HEADER_FORMAT = '<BBHHH' | |
288 | ||
289 | def __init__(self, revision, aces): | |
290 | #: Integer value of the revision. | |
291 | self.revision = revision | |
292 | #: List of :class:`ACE` instances. | |
293 | self.aces = aces | |
294 | ||
295 | def __repr__(self): | |
296 | return "ACL(%r)" % (self.aces,) | |
297 | ||
298 | @classmethod | |
299 | def from_bytes(cls, data): | |
300 | revision = None | |
301 | aces = [] | |
302 | ||
303 | header_size = struct.calcsize(cls.HEADER_FORMAT) | |
304 | header, remaining = data[:header_size], data[header_size:] | |
305 | revision, sbz1, size, count, sbz2 = struct.unpack(cls.HEADER_FORMAT, header) | |
306 | ||
307 | assert len(data) >= size | |
308 | ||
309 | for i in range(count): | |
310 | ace_size = struct.unpack('<H', remaining[2:4])[0] | |
311 | ace_data, remaining = remaining[:ace_size], remaining[ace_size:] | |
312 | aces.append(ACE.from_bytes(ace_data)) | |
313 | ||
314 | return cls(revision, aces) | |
315 | ||
316 | ||
317 | class SecurityDescriptor(object): | |
318 | """ | |
319 | Represents a security descriptor. | |
320 | ||
321 | See [MS-DTYP]: 2.4.6 | |
322 | """ | |
323 | ||
324 | HEADER_FORMAT = '<BBHIIII' | |
325 | ||
326 | def __init__(self, flags, owner, group, dacl, sacl): | |
327 | #: Integer bitmask of control flags. Corresponds to the | |
328 | #: ``Control`` field in [MS-DTYP] 2.4.6. | |
329 | self.flags = flags | |
330 | #: Instance of :class:`SID` representing the owner user. | |
331 | self.owner = owner | |
332 | #: Instance of :class:`SID` representing the owner group. | |
333 | self.group = group | |
334 | #: Instance of :class:`ACL` representing the discretionary access | |
335 | #: control list, which specifies access restrictions of an object. | |
336 | self.dacl = dacl | |
337 | #: Instance of :class:`ACL` representing the system access control | |
338 | #: list, which specifies audit logging of an object. | |
339 | self.sacl = sacl | |
340 | ||
341 | @classmethod | |
342 | def from_bytes(cls, data): | |
343 | owner = None | |
344 | group = None | |
345 | dacl = None | |
346 | sacl = None | |
347 | ||
348 | header = data[:struct.calcsize(cls.HEADER_FORMAT)] | |
349 | (revision, sbz1, flags, owner_offset, group_offset, sacl_offset, | |
350 | dacl_offset) = struct.unpack(cls.HEADER_FORMAT, header) | |
351 | ||
352 | assert revision == 1 | |
353 | assert flags & SECURITY_DESCRIPTOR_SELF_RELATIVE | |
354 | for offset in (owner_offset, group_offset, sacl_offset, dacl_offset): | |
355 | assert 0 <= offset < len(data) | |
356 | ||
357 | if owner_offset: | |
358 | owner = SID.from_bytes(data[owner_offset:]) | |
359 | if group_offset: | |
360 | group = SID.from_bytes(data[group_offset:]) | |
361 | if dacl_offset: | |
362 | dacl = ACL.from_bytes(data[dacl_offset:]) | |
363 | if sacl_offset: | |
364 | sacl = ACL.from_bytes(data[sacl_offset:]) | |
365 | ||
366 | return cls(flags, owner, group, dacl, sacl) |
269 | 269 | STRUCTURE_FORMAT = "<HHHH" |
270 | 270 | STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT) |
271 | 271 | |
272 | @property | |
273 | def isGuestSession(self): | |
274 | return (self.session_flags & 0x0001) > 0 # SMB2_SESSION_FLAG_IS_GUEST | |
275 | ||
276 | @property | |
277 | def isAnonymousSession(self): | |
278 | return (self.session_flags & 0x0002) > 0 # SMB2_SESSION_FLAG_IS_NULL | |
279 | ||
272 | 280 | def decode(self, message): |
273 | 281 | assert message.command == SMB2_COM_SESSION_SETUP |
274 | 282 | |
361 | 369 | |
362 | 370 | def prepare(self, message): |
363 | 371 | buf = self.filename.encode('UTF-16LE') |
372 | filename_len = len(buf) | |
364 | 373 | if self.create_context_data: |
365 | 374 | n = SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE + len(buf) |
366 | 375 | if n % 8 != 0: |
388 | 397 | self.create_disp, |
389 | 398 | self.create_options, |
390 | 399 | SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE, # NameOffset |
391 | len(self.filename)*2, # NameLength in bytes | |
400 | filename_len, # Length of encoded filename in bytes | |
392 | 401 | create_context_offset, # CreateContextOffset |
393 | 402 | len(self.create_context_data) # CreateContextLength |
394 | 403 | ) + buf |
114 | 114 | FILE_READ_EA = 0x08 |
115 | 115 | FILE_WRITE_EA = 0x10 |
116 | 116 | FILE_EXECUTE = 0x20 |
117 | FILE_DELETE_CHILD = 0x40 | |
117 | 118 | FILE_READ_ATTRIBUTES = 0x80 |
118 | 119 | FILE_WRITE_ATTRIBUTES = 0x0100 |
119 | 120 | DELETE = 0x010000 |
224 | 225 | SMB_FILE_ATTRIBUTE_READONLY = 0x01 |
225 | 226 | SMB_FILE_ATTRIBUTE_HIDDEN = 0x02 |
226 | 227 | SMB_FILE_ATTRIBUTE_SYSTEM = 0x04 |
227 | SMB_FILE_ATTRIBUTE_VOLUME = 0x08 | |
228 | SMB_FILE_ATTRIBUTE_VOLUME = 0x08 # Unsupported for listPath() operations | |
228 | 229 | SMB_FILE_ATTRIBUTE_DIRECTORY = 0x10 |
229 | 230 | SMB_FILE_ATTRIBUTE_ARCHIVE = 0x20 |
231 | # SMB_FILE_ATTRIBUTE_INCL_NORMAL is a special placeholder to include normal files for | |
232 | # with other search attributes for listPath() operations. It is not defined in the MS-CIFS specs. | |
233 | SMB_FILE_ATTRIBUTE_INCL_NORMAL = 0x10000 | |
234 | # Do not use the following values for listPath() operations as they are not supported for SMB2 | |
230 | 235 | SMB_SEARCH_ATTRIBUTE_READONLY = 0x0100 |
231 | 236 | SMB_SEARCH_ATTRIBUTE_HIDDEN = 0x0200 |
232 | 237 | SMB_SEARCH_ATTRIBUTE_SYSTEM = 0x0400 |
236 | 241 | # Bitmask for OptionalSupport field in SMB_COM_TREE_CONNECT_ANDX response |
237 | 242 | SMB_TREE_CONNECTX_SUPPORT_SEARCH = 0x0001 |
238 | 243 | SMB_TREE_CONNECTX_SUPPORT_DFS = 0x0002 |
244 | ||
245 | # Bitmask for security information fields, specified as | |
246 | # AdditionalInformation in SMB2 | |
247 | # [MS-SMB]: 2.2.7.4 | |
248 | # [MS-SMB2]: 2.2.37 | |
249 | OWNER_SECURITY_INFORMATION = 0x00000001 | |
250 | GROUP_SECURITY_INFORMATION = 0x00000002 | |
251 | DACL_SECURITY_INFORMATION = 0x00000004 | |
252 | SACL_SECURITY_INFORMATION = 0x00000008 | |
253 | LABEL_SECURITY_INFORMATION = 0x00000010 | |
254 | ATTRIBUTE_SECURITY_INFORMATION = 0x00000020 | |
255 | SCOPE_SECURITY_INFORMATION = 0x00000040 | |
256 | BACKUP_SECURITY_INFORMATION = 0x00010000 |
1279 | 1279 | - [MS-CIFS]: 2.2.4.39.1 |
1280 | 1280 | """ |
1281 | 1281 | |
1282 | def __init__(self, echo_data = '', echo_count = 1): | |
1282 | def __init__(self, echo_data = b'', echo_count = 1): | |
1283 | 1283 | self.echo_count = echo_count |
1284 | 1284 | self.echo_data = echo_data |
1285 | 1285 |
0 | ||
1 | def RC4_encrypt(key, data): | |
2 | S = list(range(256)) | |
3 | j = 0 | |
4 | ||
5 | key_len = len(key) | |
6 | for i in list(range(256)): | |
7 | j = (j + S[i] + ord(key[i % key_len])) % 256 | |
8 | S[i], S[j] = S[j], S[i] | |
9 | ||
10 | j = 0 | |
11 | y = 0 | |
12 | out = [] | |
13 | ||
14 | for char in data: | |
15 | j = (j + 1) % 256 | |
16 | y = (y + S[j]) % 256 | |
17 | S[j], S[y] = S[y], S[j] | |
18 | ||
19 | out.append(chr(ord(char) ^ S[(S[j] + S[y]) % 256])) | |
20 | ||
21 | return ''.join(out) |
3 | 3 | from nose.tools import with_setup |
4 | 4 | from smb import smb_structs |
5 | 5 | |
6 | conn = None | |
6 | conn, conn2, conn3 = None, None, None | |
7 | 7 | |
8 | 8 | def teardown_func(): |
9 | global conn | |
10 | conn.close() | |
9 | global conn, conn2, conn3 | |
10 | if conn: | |
11 | conn.close() | |
12 | if conn2: | |
13 | conn2.close() | |
14 | if conn3: | |
15 | conn3.close(); | |
11 | 16 | |
12 | 17 | @with_setup(teardown = teardown_func) |
13 | 18 | def test_NTLMv1_auth_SMB1(): |
14 | global conn | |
19 | global conn, conn2, conn3 | |
15 | 20 | smb_structs.SUPPORT_SMB2 = False |
16 | 21 | info = getConnectionInfo() |
17 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False) | |
22 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
18 | 23 | assert conn.connect(info['server_ip'], info['server_port']) |
24 | ||
25 | conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
26 | assert not conn2.connect(info['server_ip'], info['server_port']) | |
27 | ||
28 | conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
29 | assert not conn3.connect(info['server_ip'], info['server_port']) | |
30 | ||
31 | @with_setup(teardown = teardown_func) | |
32 | def test_NTLMv1_auth_SMB1_callable_password(): | |
33 | global conn, conn2, conn3 | |
34 | smb_structs.SUPPORT_SMB2 = False | |
35 | info = getConnectionInfo() | |
36 | conn = SMBConnection(info['user'], lambda: info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
37 | assert conn.connect(info['server_ip'], info['server_port']) | |
38 | ||
39 | conn2 = SMBConnection(info['user'], lambda: 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
40 | assert not conn2.connect(info['server_ip'], info['server_port']) | |
41 | ||
42 | conn3 = SMBConnection('INVALIDUSER', lambda: 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
43 | assert not conn3.connect(info['server_ip'], info['server_port']) | |
19 | 44 | |
20 | 45 | @with_setup(teardown = teardown_func) |
21 | 46 | def test_NTLMv2_auth_SMB1(): |
22 | global conn | |
47 | global conn, conn2, conn3 | |
23 | 48 | smb_structs.SUPPORT_SMB2 = False |
24 | 49 | info = getConnectionInfo() |
25 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
50 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
26 | 51 | assert conn.connect(info['server_ip'], info['server_port']) |
52 | ||
53 | conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
54 | assert not conn2.connect(info['server_ip'], info['server_port']) | |
55 | ||
56 | conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
57 | assert not conn3.connect(info['server_ip'], info['server_port']) | |
27 | 58 | |
28 | 59 | @with_setup(teardown = teardown_func) |
29 | 60 | def test_NTLMv1_auth_SMB2(): |
30 | global conn | |
61 | global conn, conn2, conn3 | |
31 | 62 | smb_structs.SUPPORT_SMB2 = True |
32 | 63 | info = getConnectionInfo() |
33 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False) | |
64 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
34 | 65 | assert conn.connect(info['server_ip'], info['server_port']) |
66 | ||
67 | conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
68 | assert not conn2.connect(info['server_ip'], info['server_port']) | |
69 | ||
70 | conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
71 | assert not conn3.connect(info['server_ip'], info['server_port']) | |
35 | 72 | |
36 | 73 | @with_setup(teardown = teardown_func) |
37 | 74 | def test_NTLMv2_auth_SMB2(): |
38 | global conn | |
75 | global conn, conn2, conn3 | |
39 | 76 | smb_structs.SUPPORT_SMB2 = True |
40 | 77 | info = getConnectionInfo() |
41 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
78 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
42 | 79 | assert conn.connect(info['server_ip'], info['server_port']) |
80 | ||
81 | conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
82 | assert not conn2.connect(info['server_ip'], info['server_port']) | |
83 | ||
84 | conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
85 | assert not conn3.connect(info['server_ip'], info['server_port']) |
12 | 12 | smb_structs.SUPPORT_SMB2 = False |
13 | 13 | |
14 | 14 | info = getConnectionInfo() |
15 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
15 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
16 | 16 | assert conn.connect(info['server_ip'], info['server_port']) |
17 | 17 | |
18 | 18 | def setup_func_SMB2(): |
20 | 20 | smb_structs.SUPPORT_SMB2 = True |
21 | 21 | |
22 | 22 | info = getConnectionInfo() |
23 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
23 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
24 | 24 | assert conn.connect(info['server_ip'], info['server_port']) |
25 | 25 | |
26 | 26 | def teardown_func(): |
8 | 8 | def setup_func(): |
9 | 9 | global conn |
10 | 10 | info = getConnectionInfo() |
11 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
11 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
12 | 12 | assert conn.connect(info['server_ip'], info['server_port']) |
13 | 13 | |
14 | 14 | def teardown_func(): |
21 | 21 | |
22 | 22 | data = '%d' % random.randint(1000, 9999) |
23 | 23 | assert conn.echo(data) == data |
24 |
0 | 0 | # -*- coding: utf-8 -*- |
1 | 1 | |
2 | 2 | from smb.SMBConnection import SMBConnection |
3 | from smb.smb_constants import * | |
3 | 4 | from util import getConnectionInfo |
4 | 5 | from nose.tools import with_setup |
5 | 6 | from smb import smb_structs |
10 | 11 | global conn |
11 | 12 | smb_structs.SUPPORT_SMB2 = False |
12 | 13 | info = getConnectionInfo() |
13 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
14 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
14 | 15 | assert conn.connect(info['server_ip'], info['server_port']) |
15 | 16 | |
16 | 17 | def setup_func_SMB2(): |
17 | 18 | global conn |
18 | 19 | smb_structs.SUPPORT_SMB2 = True |
19 | 20 | info = getConnectionInfo() |
20 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
21 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
21 | 22 | assert conn.connect(info['server_ip'], info['server_port']) |
22 | 23 | |
23 | 24 | def teardown_func(): |
44 | 45 | assert ( u'Test Folder', True ) in filenames |
45 | 46 | assert ( u'子文件夹', True ) in filenames |
46 | 47 | |
48 | @with_setup(setup_func_SMB1, teardown_func) | |
49 | def test_listPathWithManyFiles_SMB1(): | |
50 | global conn | |
51 | results = conn.listPath('smbtest', '/RFC Archive/') | |
52 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
53 | assert len(filenames)==999 | |
54 | ||
47 | 55 | @with_setup(setup_func_SMB2, teardown_func) |
48 | 56 | def test_listPath_SMB2(): |
49 | 57 | global conn |
63 | 71 | assert ( u'Test File.txt', False ) in filenames |
64 | 72 | assert ( u'Test Folder', True ) in filenames |
65 | 73 | assert ( u'子文件夹', True ) in filenames |
74 | ||
75 | @with_setup(setup_func_SMB2, teardown_func) | |
76 | def test_listPathWithManyFiles_SMB2(): | |
77 | global conn | |
78 | results = conn.listPath('smbtest', '/RFC Archive/') | |
79 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
80 | assert len(filenames)==999 | |
81 | ||
82 | @with_setup(setup_func_SMB1, teardown_func) | |
83 | def test_listPathFilterForDirectory_SMB1(): | |
84 | global conn | |
85 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY) | |
86 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
87 | assert len(filenames) > 0 | |
88 | for f, isDirectory in filenames: | |
89 | assert isDirectory | |
90 | ||
91 | @with_setup(setup_func_SMB2, teardown_func) | |
92 | def test_listPathFilterForDirectory_SMB2(): | |
93 | global conn | |
94 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY) | |
95 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
96 | assert len(filenames) > 0 | |
97 | for f, isDirectory in filenames: | |
98 | assert isDirectory | |
99 | ||
100 | @with_setup(setup_func_SMB1, teardown_func) | |
101 | def test_listPathFilterForFiles_SMB1(): | |
102 | global conn | |
103 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL) | |
104 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
105 | assert len(filenames) > 0 | |
106 | for f, isDirectory in filenames: | |
107 | assert not isDirectory | |
108 | ||
109 | @with_setup(setup_func_SMB2, teardown_func) | |
110 | def test_listPathFilterForFiles_SMB2(): | |
111 | global conn | |
112 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL) | |
113 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
114 | assert len(filenames) > 0 | |
115 | for f, isDirectory in filenames: | |
116 | assert not isDirectory | |
117 | ||
118 | @with_setup(setup_func_SMB1, teardown_func) | |
119 | def test_listPathFilterPattern_SMB1(): | |
120 | global conn | |
121 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*') | |
122 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
123 | assert len(filenames) == 2 | |
124 | assert ( u'Test File.txt', False ) in filenames | |
125 | assert ( u'Test Folder', True ) in filenames | |
126 | assert ( u'子文件夹', True ) not in filenames | |
127 | ||
128 | @with_setup(setup_func_SMB2, teardown_func) | |
129 | def test_listPathFilterPattern_SMB2(): | |
130 | global conn | |
131 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*') | |
132 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
133 | assert len(filenames) == 2 | |
134 | assert ( u'Test File.txt', False ) in filenames | |
135 | assert ( u'Test Folder', True ) in filenames | |
136 | assert ( u'子文件夹', True ) not in filenames | |
137 | ||
138 | @with_setup(setup_func_SMB1, teardown_func) | |
139 | def test_listPathFilterUnicodePattern_SMB1(): | |
140 | global conn | |
141 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹') | |
142 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
143 | assert len(filenames) == 1 | |
144 | assert ( u'Test File.txt', False ) not in filenames | |
145 | assert ( u'Test Folder', True ) not in filenames | |
146 | assert ( u'子文件夹', True ) in filenames | |
147 | ||
148 | @with_setup(setup_func_SMB2, teardown_func) | |
149 | def test_listPathFilterUnicodePattern_SMB2(): | |
150 | global conn | |
151 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹') | |
152 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
153 | assert len(filenames) == 1 | |
154 | assert ( u'Test File.txt', False ) not in filenames | |
155 | assert ( u'Test Folder', True ) not in filenames | |
156 | assert ( u'子文件夹', True ) in filenames |
9 | 9 | global conn |
10 | 10 | smb_structs.SUPPORT_SMB2 = False |
11 | 11 | info = getConnectionInfo() |
12 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
12 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
13 | 13 | assert conn.connect(info['server_ip'], info['server_port']) |
14 | 14 | |
15 | 15 | def setup_func_SMB2(): |
16 | 16 | global conn |
17 | 17 | smb_structs.SUPPORT_SMB2 = True |
18 | 18 | info = getConnectionInfo() |
19 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
19 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
20 | 20 | assert conn.connect(info['server_ip'], info['server_port']) |
21 | 21 | |
22 | 22 | def teardown_func(): |
9 | 9 | global conn |
10 | 10 | smb_structs.SUPPORT_SMB2 = False |
11 | 11 | info = getConnectionInfo() |
12 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
12 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
13 | 13 | assert conn.connect(info['server_ip'], info['server_port']) |
14 | 14 | |
15 | 15 | def setup_func_SMB2(): |
16 | 16 | global conn |
17 | 17 | smb_structs.SUPPORT_SMB2 = True |
18 | 18 | info = getConnectionInfo() |
19 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
19 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
20 | 20 | assert conn.connect(info['server_ip'], info['server_port']) |
21 | 21 | |
22 | 22 | def teardown_func(): |
12 | 12 | global conn |
13 | 13 | smb_structs.SUPPORT_SMB2 = False |
14 | 14 | info = getConnectionInfo() |
15 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
15 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
16 | 16 | assert conn.connect(info['server_ip'], info['server_port']) |
17 | 17 | |
18 | 18 | def setup_func_SMB2(): |
19 | 19 | global conn |
20 | 20 | smb_structs.SUPPORT_SMB2 = True |
21 | 21 | info = getConnectionInfo() |
22 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
22 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
23 | 23 | assert conn.connect(info['server_ip'], info['server_port']) |
24 | 24 | |
25 | 25 | def teardown_func(): |
19 | 19 | global conn |
20 | 20 | smb_structs.SUPPORT_SMB2 = False |
21 | 21 | info = getConnectionInfo() |
22 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
22 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
23 | 23 | assert conn.connect(info['server_ip'], info['server_port']) |
24 | 24 | |
25 | 25 | def setup_func_SMB2(): |
26 | 26 | global conn |
27 | 27 | smb_structs.SUPPORT_SMB2 = True |
28 | 28 | info = getConnectionInfo() |
29 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
29 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
30 | 30 | assert conn.connect(info['server_ip'], info['server_port']) |
31 | 31 | |
32 | 32 | def teardown_func(): |
24 | 24 | smb_structs.SUPPORT_SMB2 = False |
25 | 25 | |
26 | 26 | info = getConnectionInfo() |
27 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
27 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
28 | 28 | assert conn.connect(info['server_ip'], info['server_port']) |
29 | 29 | |
30 | 30 | def setup_func_SMB2(): |
32 | 32 | smb_structs.SUPPORT_SMB2 = True |
33 | 33 | |
34 | 34 | info = getConnectionInfo() |
35 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
35 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
36 | 36 | assert conn.connect(info['server_ip'], info['server_port']) |
37 | 37 | |
38 | 38 | def teardown_func(): |
9 | 9 | info = { |
10 | 10 | 'server_name': cp.get('server', 'name'), |
11 | 11 | 'server_ip': cp.get('server', 'ip'), |
12 | 'server_port': cp.getint('server', 'port'), | |
12 | 'server_port': cp.getint('server', 'direct_port'), | |
13 | 13 | 'client_name': cp.get('client', 'name'), |
14 | 14 | 'user': cp.get('user', 'name'), |
15 | 15 | 'password': cp.get('user', 'password'), |
0 | ||
1 | Steps to Follow to Run the Unit Tests | |
2 | ===================================== | |
3 | ||
4 | ## Step 1: Install system dependencies ## | |
5 | ||
6 | If you are using Ubuntu 20.04 LTS, you can install the system dependencies with the following command | |
7 | ``` | |
8 | $> apt-get install virtualenv python-dev gcc g++ make automake autoconf | |
9 | ``` | |
10 | For other distributions, you can use their package managers and install the system dependencies (although the package names might differ slightly). | |
11 | ||
12 | ## Step 2: Setup python virtualenv ## | |
13 | ||
14 | We will create a python2 virtualenv and install the python dependencies for testing in the "venv2" folder. | |
15 | ||
16 | ``` | |
17 | $> cd <pysmb-home>/python2 | |
18 | $> virtualenv -p /usr/bin/python2 venv2 | |
19 | $> source venv2/bin/activate | |
20 | $venv2> pip install nose pyasn1 twisted | |
21 | ``` | |
22 | ||
23 | ## Step 3: Setup shared folder on your remote SMB server ## | |
24 | ||
25 | Prepare a shared folder called "smbtest" on your remote SMB server (Windows or Samba). | |
26 | ||
27 | Then, download [smbtest.zip](https://miketeo.net/files/Projects/pysmb/smbtest.zip) and unzip the contents of this zip file in the shared folder. | |
28 | ||
29 | You should also configure a user on the SMB server with read-write access to the "smbtest" folder. | |
30 | ||
31 | ## Step 4: Update connection details in connection.ini ## | |
32 | ||
33 | In the same folder where you are viewing this readme file, there should be an ini file called "connection.ini". Edit this file's connection details to match the shared folder's access information. | |
34 | ||
35 | ## Step 5: Run the unit tests in the python2 folder ## | |
36 | ||
37 | Before running the tests, the venv2 virtualenv must be activated. | |
38 | ``` | |
39 | $> cd <pysmb-home>/python2 | |
40 | $> source venv2/bin/activate | |
41 | ``` | |
42 | ||
43 | To run all the tests: | |
44 | ``` | |
45 | $venv2> nosetests -v tests | |
46 | ``` | |
47 | ||
48 | To selectively run some tests: | |
49 | ``` | |
50 | $venv2> nosetests -v tests/SMBConnectionTests | |
51 | $venv2> nosetests -v tests/SMBConnectionTests/test_rename.py | |
52 | $venv2> nosetests -v tests/SMBConnectionTests/test_rename.py:test_rename_english_file_SMB1 | |
53 | ``` | |
54 | ||
55 | For more information, please consult the [documentation for nose](https://nose.readthedocs.io/). | |
56 | ||
57 |
0 | ||
1 | Steps to Follow to Run the Unit Tests | |
2 | ===================================== | |
3 | ||
4 | 1a. Install Nose Testing Framework | |
5 | All the unit tests here are designed to be conducted with the nose testing framework. | |
6 | You can install the latest nose testing framework by running: easy_install nose | |
7 | For more information on nose testing, please visit http://readthedocs.org/docs/nose/en/latest/ | |
8 | ||
9 | 1b. Install the Twisted framework | |
10 | If you need to test the SMB/NetBIOS protocol implementations for Twisted framework, | |
11 | you should install the Twisted framework from http://twistedmatrix.com/ | |
12 | or by running: easy_install Twisted | |
13 | Without the Twisted framework, the Twisted tests will fail. | |
14 | ||
15 | 2. Prepare a Shared Folder "smbtest" on a Remote Server | |
16 | To run the unit tests here, besides installing the nose testing framework, you will | |
17 | also need to prepare a shared folder on a remote server. | |
18 | pysmb has been tested against Samba 3.x, Windows XP SP3 and Windows Vista. | |
19 | The shared folder must be named "smbtest". | |
20 | ||
21 | 3. Unzip smbtest.zip in the Shared Folder | |
22 | In the same folder where you are viewing this readme file, there should be a zip file | |
23 | called "smbtest.zip". Unzip the contents of this zip file in the shared folder. | |
24 | ||
25 | 4. Update Connection Details in connection.ini | |
26 | In the same folder where you are viewing this readme file, there should be an ini file | |
27 | called "connection.ini". Edit this file's connection details to match the shared folder's | |
28 | access information. | |
29 | ||
30 | 5. Run the Unit Tests | |
31 | Just run: nosetests |
3 | 3 | from nose.tools import with_setup |
4 | 4 | from smb import smb_structs |
5 | 5 | |
6 | conn = None | |
6 | conn, conn2, conn3 = None, None, None | |
7 | 7 | |
8 | 8 | def teardown_func(): |
9 | global conn | |
10 | conn.close() | |
9 | global conn, conn2, conn3 | |
10 | if conn: | |
11 | conn.close() | |
12 | if conn2: | |
13 | conn2.close() | |
14 | if conn3: | |
15 | conn3.close(); | |
11 | 16 | |
12 | 17 | @with_setup(teardown = teardown_func) |
13 | 18 | def test_NTLMv1_auth_SMB1(): |
17 | 22 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = False) |
18 | 23 | assert conn.connect(info['server_ip'], info['server_port']) |
19 | 24 | |
25 | conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False) | |
26 | assert not conn2.connect(info['server_ip'], info['server_port']) | |
27 | ||
28 | conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False) | |
29 | assert not conn3.connect(info['server_ip'], info['server_port']) | |
30 | ||
20 | 31 | @with_setup(teardown = teardown_func) |
21 | 32 | def test_NTLMv2_auth_SMB1(): |
22 | 33 | global conn |
24 | 35 | info = getConnectionInfo() |
25 | 36 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = True) |
26 | 37 | assert conn.connect(info['server_ip'], info['server_port']) |
38 | ||
39 | conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
40 | assert not conn2.connect(info['server_ip'], info['server_port']) | |
41 | ||
42 | conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
43 | assert not conn3.connect(info['server_ip'], info['server_port']) | |
27 | 44 | |
28 | 45 | @with_setup(teardown = teardown_func) |
29 | 46 | def test_NTLMv1_auth_SMB2(): |
33 | 50 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = False) |
34 | 51 | assert conn.connect(info['server_ip'], info['server_port']) |
35 | 52 | |
53 | conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False) | |
54 | assert not conn2.connect(info['server_ip'], info['server_port']) | |
55 | ||
56 | conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False) | |
57 | assert not conn3.connect(info['server_ip'], info['server_port']) | |
58 | ||
36 | 59 | @with_setup(teardown = teardown_func) |
37 | 60 | def test_NTLMv2_auth_SMB2(): |
38 | 61 | global conn |
40 | 63 | info = getConnectionInfo() |
41 | 64 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = True) |
42 | 65 | assert conn.connect(info['server_ip'], info['server_port']) |
66 | ||
67 | conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
68 | assert not conn2.connect(info['server_ip'], info['server_port']) | |
69 | ||
70 | conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
71 | assert not conn3.connect(info['server_ip'], info['server_port']) |
29 | 29 | conn.close() |
30 | 30 | |
31 | 31 | @with_setup(setup_func_SMB1, teardown_func) |
32 | def test_delete_SMB1(): | |
33 | global conn | |
34 | ||
35 | path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
36 | conn.createDirectory('smbtest', path) | |
37 | ||
38 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
39 | conn.storeFile('smbtest', path+"/"+filename, StringIO("0123456789")) | |
40 | ||
41 | results = conn.listPath('smbtest', path) | |
42 | filenames = map(lambda r: r.filename, results) | |
32 | def test_delete_without_subfolder_SMB1(): | |
33 | global conn | |
34 | ||
35 | path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
36 | conn.createDirectory('smbtest', path) | |
37 | ||
38 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
39 | conn.storeFile('smbtest', path+"/"+filename, StringIO("0123456789")) | |
40 | ||
41 | for p in [ 'aaTest.Folder', 'aaTest.Folder/xyz', 'bbTest.Folder' ]: | |
42 | conn.createDirectory('smbtest', path+"/"+p) | |
43 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
44 | conn.storeFile('smbtest', path+"/"+p+"/"+filename, StringIO("0123456789")) | |
45 | ||
46 | results = conn.listPath('smbtest', path) | |
47 | filenames = map(lambda r: r.filename, results) | |
48 | assert 'aaTest.Folder' in filenames | |
49 | assert 'bbTest.Folder' in filenames | |
43 | 50 | assert 'aaTest.txt' in filenames |
44 | 51 | assert 'aaBest.txt' in filenames |
45 | 52 | assert 'aaTest.bin' in filenames |
50 | 57 | |
51 | 58 | results = conn.listPath('smbtest', path) |
52 | 59 | filenames = map(lambda r: r.filename, results) |
60 | assert 'aaTest.Folder' in filenames | |
61 | assert 'bbTest.Folder' in filenames | |
53 | 62 | assert 'aaTest.txt' not in filenames |
54 | 63 | assert 'aaBest.txt' not in filenames |
55 | 64 | assert 'aaTest.bin' in filenames |
60 | 69 | |
61 | 70 | results = conn.listPath('smbtest', path) |
62 | 71 | filenames = map(lambda r: r.filename, results) |
63 | assert 'aaTest.bin' not in filenames | |
64 | assert 'aaBest.bin' in filenames | |
65 | assert 'random.txt' in filenames | |
66 | ||
67 | conn.deleteFiles('smbtest', path+'/*') | |
68 | conn.deleteDirectory('smbtest', path) | |
72 | assert 'aaTest.Folder' in filenames | |
73 | assert 'bbTest.Folder' in filenames | |
74 | assert 'aaTest.bin' not in filenames | |
75 | assert 'aaBest.bin' in filenames | |
76 | assert 'random.txt' in filenames | |
77 | ||
78 | ||
79 | @with_setup(setup_func_SMB1, teardown_func) | |
80 | def test_delete_with_subfolder_SMB1(): | |
81 | global conn | |
82 | ||
83 | path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
84 | conn.createDirectory('smbtest', path) | |
85 | ||
86 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
87 | conn.storeFile('smbtest', path+"/"+filename, StringIO("0123456789")) | |
88 | ||
89 | for p in [ 'aaTest.Folder', 'aaTest.Folder/xyz', 'bbTest.Folder' ]: | |
90 | conn.createDirectory('smbtest', path+"/"+p) | |
91 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
92 | conn.storeFile('smbtest', path+"/"+p+"/"+filename, StringIO("0123456789")) | |
93 | ||
94 | results = conn.listPath('smbtest', path) | |
95 | filenames = map(lambda r: r.filename, results) | |
96 | assert 'aaTest.Folder' in filenames | |
97 | assert 'bbTest.Folder' in filenames | |
98 | assert 'aaTest.txt' in filenames | |
99 | assert 'aaBest.txt' in filenames | |
100 | assert 'aaTest.bin' in filenames | |
101 | assert 'aaBest.bin' in filenames | |
102 | assert 'random.txt' in filenames | |
103 | ||
104 | conn.deleteFiles('smbtest', path+'/aa*.txt', delete_matching_folders=True) | |
105 | ||
106 | results = conn.listPath('smbtest', path) | |
107 | filenames = map(lambda r: r.filename, results) | |
108 | assert 'aaTest.Folder' in filenames | |
109 | assert 'bbTest.Folder' in filenames | |
110 | assert 'aaTest.txt' not in filenames | |
111 | assert 'aaBest.txt' not in filenames | |
112 | assert 'aaTest.bin' in filenames | |
113 | assert 'aaBest.bin' in filenames | |
114 | assert 'random.txt' in filenames | |
115 | ||
116 | conn.deleteFiles('smbtest', path+'/aaTest.*', delete_matching_folders=True) | |
117 | ||
118 | results = conn.listPath('smbtest', path) | |
119 | filenames = map(lambda r: r.filename, results) | |
120 | assert 'aaTest.Folder' not in filenames | |
121 | assert 'bbTest.Folder' in filenames | |
122 | assert 'aaTest.bin' not in filenames | |
123 | assert 'aaBest.bin' in filenames | |
124 | assert 'random.txt' in filenames | |
125 | ||
69 | 126 | |
70 | 127 | @with_setup(setup_func_SMB2, teardown_func) |
71 | def test_delete_SMB2(): | |
72 | global conn | |
73 | ||
74 | path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
75 | conn.createDirectory('smbtest', path) | |
76 | ||
77 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
78 | conn.storeFile('smbtest', path+"/"+filename, StringIO("0123456789")) | |
79 | ||
80 | results = conn.listPath('smbtest', path) | |
81 | filenames = map(lambda r: r.filename, results) | |
128 | def test_delete_without_subfolder_SMB2(): | |
129 | global conn | |
130 | ||
131 | path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
132 | conn.createDirectory('smbtest', path) | |
133 | ||
134 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
135 | conn.storeFile('smbtest', path+"/"+filename, StringIO("0123456789")) | |
136 | ||
137 | for p in [ 'aaTest.Folder', 'aaTest.Folder/xyz', 'bbTest.Folder' ]: | |
138 | conn.createDirectory('smbtest', path+"/"+p) | |
139 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
140 | conn.storeFile('smbtest', path+"/"+p+"/"+filename, StringIO("0123456789")) | |
141 | ||
142 | results = conn.listPath('smbtest', path) | |
143 | filenames = map(lambda r: r.filename, results) | |
144 | assert 'aaTest.Folder' in filenames | |
145 | assert 'bbTest.Folder' in filenames | |
82 | 146 | assert 'aaTest.txt' in filenames |
83 | 147 | assert 'aaBest.txt' in filenames |
84 | 148 | assert 'aaTest.bin' in filenames |
89 | 153 | |
90 | 154 | results = conn.listPath('smbtest', path) |
91 | 155 | filenames = map(lambda r: r.filename, results) |
156 | assert 'aaTest.Folder' in filenames | |
157 | assert 'bbTest.Folder' in filenames | |
92 | 158 | assert 'aaTest.txt' not in filenames |
93 | 159 | assert 'aaBest.txt' not in filenames |
94 | 160 | assert 'aaTest.bin' in filenames |
99 | 165 | |
100 | 166 | results = conn.listPath('smbtest', path) |
101 | 167 | filenames = map(lambda r: r.filename, results) |
102 | assert 'aaTest.bin' not in filenames | |
103 | assert 'aaBest.bin' in filenames | |
104 | assert 'random.txt' in filenames | |
168 | assert 'aaTest.Folder' in filenames | |
169 | assert 'bbTest.Folder' in filenames | |
170 | assert 'aaTest.bin' not in filenames | |
171 | assert 'aaBest.bin' in filenames | |
172 | assert 'random.txt' in filenames | |
173 | ||
174 | @with_setup(setup_func_SMB2, teardown_func) | |
175 | def test_delete_with_subfolder_SMB2(): | |
176 | global conn | |
177 | ||
178 | path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
179 | conn.createDirectory('smbtest', path) | |
180 | ||
181 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
182 | conn.storeFile('smbtest', path+"/"+filename, StringIO("0123456789")) | |
183 | ||
184 | for p in [ 'aaTest.Folder', 'aaTest.Folder/xyz', 'bbTest.Folder' ]: | |
185 | conn.createDirectory('smbtest', path+"/"+p) | |
186 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
187 | conn.storeFile('smbtest', path+"/"+p+"/"+filename, StringIO("0123456789")) | |
188 | ||
189 | results = conn.listPath('smbtest', path) | |
190 | filenames = map(lambda r: r.filename, results) | |
191 | assert 'aaTest.Folder' in filenames | |
192 | assert 'bbTest.Folder' in filenames | |
193 | assert 'aaTest.txt' in filenames | |
194 | assert 'aaBest.txt' in filenames | |
195 | assert 'aaTest.bin' in filenames | |
196 | assert 'aaBest.bin' in filenames | |
197 | assert 'random.txt' in filenames | |
198 | ||
199 | conn.deleteFiles('smbtest', path+'/aa*.txt', delete_matching_folders=True) | |
200 | ||
201 | results = conn.listPath('smbtest', path) | |
202 | filenames = map(lambda r: r.filename, results) | |
203 | assert 'aaTest.Folder' in filenames | |
204 | assert 'bbTest.Folder' in filenames | |
205 | assert 'aaTest.txt' not in filenames | |
206 | assert 'aaBest.txt' not in filenames | |
207 | assert 'aaTest.bin' in filenames | |
208 | assert 'aaBest.bin' in filenames | |
209 | assert 'random.txt' in filenames | |
210 | ||
211 | conn.deleteFiles('smbtest', path+'/aaTest.*', delete_matching_folders=True) | |
212 | ||
213 | results = conn.listPath('smbtest', path) | |
214 | filenames = map(lambda r: r.filename, results) | |
215 | assert 'aaTest.Folder' not in filenames | |
216 | assert 'bbTest.Folder' in filenames | |
217 | assert 'aaTest.bin' not in filenames | |
218 | assert 'aaBest.bin' in filenames | |
219 | assert 'random.txt' in filenames |
0 | 0 | # -*- coding: utf-8 -*- |
1 | 1 | |
2 | 2 | from smb.SMBConnection import SMBConnection |
3 | from smb.smb_constants import * | |
3 | 4 | from util import getConnectionInfo |
4 | 5 | from nose.tools import with_setup |
5 | 6 | from smb import smb_structs |
44 | 45 | assert ( u'Test Folder', True ) in filenames |
45 | 46 | assert ( u'子文件夹', True ) in filenames |
46 | 47 | |
48 | @with_setup(setup_func_SMB1, teardown_func) | |
49 | def test_listPathWithManyFiles_SMB1(): | |
50 | global conn | |
51 | results = conn.listPath('smbtest', '/RFC Archive/') | |
52 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
53 | assert len(filenames)==999 | |
54 | ||
47 | 55 | @with_setup(setup_func_SMB2, teardown_func) |
48 | 56 | def test_listPath_SMB2(): |
49 | 57 | global conn |
63 | 71 | assert ( u'Test File.txt', False ) in filenames |
64 | 72 | assert ( u'Test Folder', True ) in filenames |
65 | 73 | assert ( u'子文件夹', True ) in filenames |
74 | ||
75 | @with_setup(setup_func_SMB2, teardown_func) | |
76 | def test_listPathWithManyFiles_SMB2(): | |
77 | global conn | |
78 | results = conn.listPath('smbtest', '/RFC Archive/') | |
79 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
80 | assert len(filenames)==999 | |
81 | ||
82 | @with_setup(setup_func_SMB1, teardown_func) | |
83 | def test_listPathFilterForDirectory_SMB1(): | |
84 | global conn | |
85 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY) | |
86 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
87 | assert len(filenames) > 0 | |
88 | for f, isDirectory in filenames: | |
89 | assert isDirectory | |
90 | ||
91 | @with_setup(setup_func_SMB2, teardown_func) | |
92 | def test_listPathFilterForDirectory_SMB2(): | |
93 | global conn | |
94 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY) | |
95 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
96 | assert len(filenames) > 0 | |
97 | for f, isDirectory in filenames: | |
98 | assert isDirectory | |
99 | ||
100 | @with_setup(setup_func_SMB1, teardown_func) | |
101 | def test_listPathFilterForFiles_SMB1(): | |
102 | global conn | |
103 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL) | |
104 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
105 | assert len(filenames) > 0 | |
106 | for f, isDirectory in filenames: | |
107 | assert not isDirectory | |
108 | ||
109 | @with_setup(setup_func_SMB2, teardown_func) | |
110 | def test_listPathFilterForFiles_SMB2(): | |
111 | global conn | |
112 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL) | |
113 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
114 | assert len(filenames) > 0 | |
115 | for f, isDirectory in filenames: | |
116 | assert not isDirectory | |
117 | ||
118 | @with_setup(setup_func_SMB1, teardown_func) | |
119 | def test_listPathFilterPattern_SMB1(): | |
120 | global conn | |
121 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*') | |
122 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
123 | assert len(filenames) == 2 | |
124 | assert ( u'Test File.txt', False ) in filenames | |
125 | assert ( u'Test Folder', True ) in filenames | |
126 | assert ( u'子文件夹', True ) not in filenames | |
127 | ||
128 | @with_setup(setup_func_SMB2, teardown_func) | |
129 | def test_listPathFilterPattern_SMB2(): | |
130 | global conn | |
131 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*') | |
132 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
133 | assert len(filenames) == 2 | |
134 | assert ( u'Test File.txt', False ) in filenames | |
135 | assert ( u'Test Folder', True ) in filenames | |
136 | assert ( u'子文件夹', True ) not in filenames | |
137 | ||
138 | @with_setup(setup_func_SMB1, teardown_func) | |
139 | def test_listPathFilterUnicodePattern_SMB1(): | |
140 | global conn | |
141 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹') | |
142 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
143 | assert len(filenames) == 1 | |
144 | assert ( u'Test File.txt', False ) not in filenames | |
145 | assert ( u'Test Folder', True ) not in filenames | |
146 | assert ( u'子文件夹', True ) in filenames | |
147 | ||
148 | @with_setup(setup_func_SMB2, teardown_func) | |
149 | def test_listPathFilterUnicodePattern_SMB2(): | |
150 | global conn | |
151 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹') | |
152 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
153 | assert len(filenames) == 1 | |
154 | assert ( u'Test File.txt', False ) not in filenames | |
155 | assert ( u'Test Folder', True ) not in filenames | |
156 | assert ( u'子文件夹', True ) in filenames | |
157 | ||
158 | @with_setup(setup_func_SMB1, teardown_func) | |
159 | def test_listPathFilterEmptyList_SMB1(): | |
160 | global conn | |
161 | results = conn.listPath('smbtest', '/RFC Archive', pattern = '*.abc') | |
162 | filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results)) | |
163 | ||
164 | @with_setup(setup_func_SMB2, teardown_func) | |
165 | def test_listPathFilterEmptyList_SMB2(): | |
166 | global conn | |
167 | results = conn.listPath('smbtest', '/RFC Archive', pattern = '*.abc') | |
168 | filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results)) |
0 | # -*- coding: utf-8 -*- | |
1 | ||
2 | import os, tempfile | |
3 | from StringIO import StringIO | |
4 | from smb.SMBConnection import SMBConnection | |
5 | from util import getConnectionInfo | |
6 | from nose.tools import with_setup | |
7 | from smb import smb_structs | |
8 | ||
9 | try: | |
10 | import hashlib | |
11 | def MD5(): return hashlib.md5() | |
12 | except ImportError: | |
13 | import md5 | |
14 | def MD5(): return md5.new() | |
15 | ||
16 | conn = None | |
17 | ||
18 | def setup_func_SMB2(): | |
19 | global conn | |
20 | smb_structs.SUPPORT_SMB2 = True | |
21 | info = getConnectionInfo() | |
22 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
23 | assert conn.connect(info['server_ip'], info['server_port']) | |
24 | ||
25 | def teardown_func(): | |
26 | global conn | |
27 | conn.close() | |
28 | ||
29 | @with_setup(setup_func_SMB2, teardown_func) | |
30 | def test_security_SMB2(): | |
31 | global conn | |
32 | # TODO: Need a way to setup the environment on the remote server and perform some verification on the returned results. | |
33 | attributes = conn.getSecurity('smbtest', '/rfc1001.txt') |
0 | # -*- coding: utf-8 -*- | |
1 | ||
2 | from smb.SMBConnection import SMBConnection | |
3 | from .util import getConnectionInfo | |
4 | ||
5 | def test_context(): | |
6 | info = getConnectionInfo() | |
7 | with SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) as conn: | |
8 | assert conn.connect(info['server_ip'], info['server_port']) | |
9 | ||
10 | assert conn.sock is None |
2 | 2 | name = SERVER |
3 | 3 | ip = 192.168.1.1 |
4 | 4 | port = 139 |
5 | direct_port = 445 | |
5 | 6 | |
6 | 7 | [client] |
7 | 8 | name = TESTCLIENT |
0 | import binascii | |
1 | ||
2 | from smb import security_descriptors as sd | |
3 | from smb import smb_constants as sc | |
4 | ||
5 | ||
6 | def test_sid_string_representation(): | |
7 | sid = sd.SID(1, 5, [2, 3, 4]) | |
8 | assert str(sid) == "S-1-5-2-3-4" | |
9 | sid = sd.SID(1, 2**32 + 3, []) | |
10 | assert str(sid) == "S-1-0x100000003" | |
11 | sid = sd.SID(1, 2**32, [3, 2, 1]) | |
12 | assert str(sid) == "S-1-0x100000000-3-2-1" | |
13 | ||
14 | ||
15 | def test_sid_binary_parsing(): | |
16 | raw_sid = binascii.unhexlify(""" | |
17 | 01 05 00 00 00 00 00 05 15 00 00 00 de 53 c1 2a | |
18 | 2a 4f da ca c1 79 a6 32 b1 04 00 00 | |
19 | """.translate(None, ' \n')) | |
20 | assert str(sd.SID.from_bytes(raw_sid)) == "S-1-5-21-717312990-3403304746-849770945-1201" | |
21 | raw_sid += "garbage" | |
22 | assert str(sd.SID.from_bytes(raw_sid)) == "S-1-5-21-717312990-3403304746-849770945-1201" | |
23 | sid, tail = sd.SID.from_bytes(raw_sid, return_tail=True) | |
24 | assert str(sid) == "S-1-5-21-717312990-3403304746-849770945-1201" | |
25 | assert tail == "garbage" | |
26 | ||
27 | ||
28 | def test_ace_binary_parsing(): | |
29 | raw_ace = binascii.unhexlify(""" | |
30 | 00 10 24 00 ff 01 1f 00 01 05 00 00 00 00 00 05 | |
31 | 15 00 00 00 de 53 c1 2a 2a 4f da ca c1 79 a6 32 | |
32 | 6e 04 00 00 | |
33 | """.translate(None, ' \n')) | |
34 | ace = sd.ACE.from_bytes(raw_ace) | |
35 | assert str(ace.sid) == "S-1-5-21-717312990-3403304746-849770945-1134" | |
36 | assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED | |
37 | assert ace.flags == sd.ACE_FLAG_INHERITED | |
38 | assert ace.mask == (sc.SYNCHRONIZE | sc.WRITE_OWNER | sc.WRITE_DAC | |
39 | | sc.READ_CONTROL | sc.DELETE | sc.FILE_READ_DATA | |
40 | | sc.FILE_WRITE_DATA | sc.FILE_APPEND_DATA | |
41 | | sc.FILE_READ_EA | sc.FILE_WRITE_EA | sc.FILE_EXECUTE | |
42 | | sc.FILE_DELETE_CHILD | sc.FILE_READ_ATTRIBUTES | |
43 | | sc.FILE_WRITE_ATTRIBUTES) | |
44 | assert not ace.additional_data | |
45 | ||
46 | raw_ace = binascii.unhexlify(""" | |
47 | 00 13 18 00 a9 00 12 00 01 02 00 00 00 00 00 05 | |
48 | 20 00 00 00 21 02 00 00 | |
49 | """.translate(None, ' \n')) | |
50 | ace = sd.ACE.from_bytes(raw_ace) | |
51 | assert str(ace.sid) == "S-1-5-32-545" | |
52 | assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED | |
53 | assert ace.flags == (sd.ACE_FLAG_INHERITED | sd.ACE_FLAG_CONTAINER_INHERIT | |
54 | | sd.ACE_FLAG_OBJECT_INHERIT) | |
55 | assert ace.mask == (sc.SYNCHRONIZE | sc.READ_CONTROL | sc.FILE_READ_DATA | |
56 | | sc.FILE_READ_EA | sc.FILE_EXECUTE | |
57 | | sc.FILE_READ_ATTRIBUTES) | |
58 | assert not ace.additional_data | |
59 | ||
60 | raw_ace = binascii.unhexlify(""" | |
61 | 01 03 24 00 a9 00 02 00 01 05 00 00 00 00 00 05 | |
62 | 15 00 00 00 de 53 c1 2a 2a 4f da ca c1 79 a6 32 | |
63 | 6c 04 00 00 | |
64 | """.translate(None, ' \n')) | |
65 | ace = sd.ACE.from_bytes(raw_ace) | |
66 | assert str(ace.sid) == "S-1-5-21-717312990-3403304746-849770945-1132" | |
67 | assert ace.type == sd.ACE_TYPE_ACCESS_DENIED | |
68 | assert ace.flags == (sd.ACE_FLAG_CONTAINER_INHERIT | |
69 | | sd.ACE_FLAG_OBJECT_INHERIT) | |
70 | assert ace.mask == (sc.READ_CONTROL | sc.FILE_READ_DATA | sc.FILE_READ_EA | |
71 | | sc.FILE_EXECUTE | sc.FILE_READ_ATTRIBUTES) | |
72 | assert not ace.additional_data | |
73 | ||
74 | ||
75 | def test_acl_binary_parsing(): | |
76 | raw_acl = binascii.unhexlify(""" | |
77 | 02 00 70 00 04 00 00 00 00 10 18 00 89 00 10 00 | |
78 | 01 02 00 00 00 00 00 05 20 00 00 00 21 02 00 00 | |
79 | 00 10 14 00 ff 01 1f 00 01 01 00 00 00 00 00 05 | |
80 | 12 00 00 00 00 10 18 00 ff 01 1f 00 01 02 00 00 | |
81 | 00 00 00 05 20 00 00 00 20 02 00 00 00 10 24 00 | |
82 | ff 01 1f 00 01 05 00 00 00 00 00 05 15 00 00 00 | |
83 | de 53 c1 2a 2a 4f da ca c1 79 a6 32 b1 04 00 00 | |
84 | """.translate(None, ' \n')) | |
85 | acl = sd.ACL.from_bytes(raw_acl) | |
86 | assert acl.revision == 2 | |
87 | assert len(acl.aces) == 4 | |
88 | ||
89 | ace = acl.aces[0] | |
90 | assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED | |
91 | assert str(ace.sid) == "S-1-5-32-545" | |
92 | assert ace.flags == sd.ACE_FLAG_INHERITED | |
93 | assert ace.mask == (sc.SYNCHRONIZE | sc.FILE_READ_DATA | sc.FILE_READ_EA | |
94 | | sc.FILE_READ_ATTRIBUTES) | |
95 | ||
96 | ace = acl.aces[3] | |
97 | assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED | |
98 | assert str(ace.sid) == "S-1-5-21-717312990-3403304746-849770945-1201" | |
99 | assert ace.flags == sd.ACE_FLAG_INHERITED | |
100 | assert ace.mask == (sc.SYNCHRONIZE | sc.WRITE_OWNER | sc.WRITE_DAC | |
101 | | sc.READ_CONTROL | sc.DELETE | sc.FILE_READ_DATA | |
102 | | sc.FILE_WRITE_DATA | sc.FILE_APPEND_DATA | |
103 | | sc.FILE_READ_EA | sc.FILE_WRITE_EA | sc.FILE_EXECUTE | |
104 | | sc.FILE_DELETE_CHILD | sc.FILE_READ_ATTRIBUTES | |
105 | | sc.FILE_WRITE_ATTRIBUTES) | |
106 | ||
107 | ||
108 | def test_descriptor_binary_parsing(): | |
109 | raw_descriptor = binascii.unhexlify(""" | |
110 | 01 00 04 84 14 00 00 00 30 00 00 00 00 00 00 00 | |
111 | 4c 00 00 00 01 05 00 00 00 00 00 05 15 00 00 00 | |
112 | de 53 c1 2a 2a 4f da ca c1 79 a6 32 b1 04 00 00 | |
113 | 01 05 00 00 00 00 00 05 15 00 00 00 de 53 c1 2a | |
114 | 2a 4f da ca c1 79 a6 32 01 02 00 00 02 00 70 00 | |
115 | 04 00 00 00 00 10 18 00 89 00 10 00 01 02 00 00 | |
116 | 00 00 00 05 20 00 00 00 21 02 00 00 00 10 14 00 | |
117 | ff 01 1f 00 01 01 00 00 00 00 00 05 12 00 00 00 | |
118 | 00 10 18 00 ff 01 1f 00 01 02 00 00 00 00 00 05 | |
119 | 20 00 00 00 20 02 00 00 00 10 24 00 ff 01 1f 00 | |
120 | 01 05 00 00 00 00 00 05 15 00 00 00 de 53 c1 2a | |
121 | 2a 4f da ca c1 79 a6 32 b1 04 00 00 | |
122 | """.translate(None, ' \n')) | |
123 | descriptor = sd.SecurityDescriptor.from_bytes(raw_descriptor) | |
124 | assert descriptor.flags == (sd.SECURITY_DESCRIPTOR_SELF_RELATIVE | |
125 | | sd.SECURITY_DESCRIPTOR_DACL_PRESENT | |
126 | | sd.SECURITY_DESCRIPTOR_DACL_AUTO_INHERITED) | |
127 | assert descriptor.dacl is not None | |
128 | assert descriptor.sacl is None | |
129 | assert str(descriptor.owner) == "S-1-5-21-717312990-3403304746-849770945-1201" | |
130 | assert str(descriptor.group) == "S-1-5-21-717312990-3403304746-849770945-513" | |
131 | ||
132 | acl = descriptor.dacl | |
133 | assert acl.revision == 2 | |
134 | assert len(acl.aces) == 4 | |
135 | assert str(acl.aces[0].sid) == sd.SID_BUILTIN_USERS | |
136 | assert str(acl.aces[1].sid) == sd.SID_LOCAL_SYSTEM | |
137 | assert str(acl.aces[2].sid) == sd.SID_BUILTIN_ADMINISTRATORS | |
138 | assert str(acl.aces[3].sid) == "S-1-5-21-717312990-3403304746-849770945-1201" |
76 | 76 | self.onNMBSessionOK() |
77 | 77 | elif packet.type == NEGATIVE_SESSION_RESPONSE: |
78 | 78 | self.onNMBSessionFailed() |
79 | elif packet.type == SESSION_KEEPALIVE: | |
80 | # Discard keepalive packets - [RFC1002]: 5.2.2.1 | |
81 | pass | |
79 | 82 | else: |
80 | 83 | self.log.warning('Unrecognized NMB session type: 0x%02x', packet.type) |
81 | 84 | |
152 | 155 | opcode = (code >> 11) & 0x0F |
153 | 156 | flags = (code >> 4) & 0x7F |
154 | 157 | rcode = code & 0x0F |
155 | numnames = data[self.HEADER_STRUCT_SIZE + 44] | |
156 | 158 | |
157 | if numnames > 0: | |
158 | ret = [ ] | |
159 | offset = self.HEADER_STRUCT_SIZE + 45 | |
159 | try: | |
160 | numnames = data[self.HEADER_STRUCT_SIZE + 44] | |
160 | 161 | |
161 | for i in range(0, numnames): | |
162 | mynme = data[offset:offset + 15] | |
163 | mynme = mynme.strip() | |
164 | ret.append(( str(mynme, 'ascii'), data[offset+15] )) | |
165 | offset += 18 | |
162 | if numnames > 0: | |
163 | ret = [ ] | |
164 | offset = self.HEADER_STRUCT_SIZE + 45 | |
166 | 165 | |
167 | return trn_id, ret | |
168 | else: | |
169 | return trn_id, None | |
166 | for i in range(0, numnames): | |
167 | mynme = data[offset:offset + 15] | |
168 | mynme = mynme.strip() | |
169 | ret.append(( str(mynme, 'ascii'), data[offset+15] )) | |
170 | offset += 18 | |
171 | ||
172 | return trn_id, ret | |
173 | except IndexError: | |
174 | pass | |
175 | ||
176 | return trn_id, None | |
170 | 177 | |
171 | 178 | # |
172 | 179 | # Contributed by Jason Anderson |
0 | Metadata-Version: 1.1 | |
1 | Name: pysmb | |
2 | Version: 1.2.6 | |
3 | Summary: pysmb is an experimental SMB/CIFS library written in Python to support file sharing between Windows and Linux machines | |
4 | Home-page: https://miketeo.net/projects/pysmb | |
5 | Author: Michael Teo | |
6 | Author-email: [email protected] | |
7 | License: zlib/libpng | |
8 | Description: pysmb is an experimental SMB/CIFS library written in Python. It implements the client-side SMB/CIFS protocol which allows your Python application to access and transfer files to/from SMB/CIFS shared folders like your Windows file sharing and Samba folders. | |
9 | Keywords: windows samba cifs sharing ftp smb linux | |
10 | Platform: UNKNOWN | |
11 | Classifier: Development Status :: 5 - Production/Stable | |
12 | Classifier: Environment :: Win32 (MS Windows) | |
13 | Classifier: Environment :: Console | |
14 | Classifier: License :: OSI Approved :: zlib/libpng License | |
15 | Classifier: Operating System :: Microsoft :: Windows | |
16 | Classifier: Operating System :: POSIX | |
17 | Classifier: Programming Language :: Python | |
18 | Classifier: Programming Language :: Python :: 2.4 | |
19 | Classifier: Programming Language :: Python :: 2.5 | |
20 | Classifier: Programming Language :: Python :: 2.6 | |
21 | Classifier: Programming Language :: Python :: 2.7 | |
22 | Classifier: Programming Language :: Python :: 3 | |
23 | Classifier: Topic :: Communications :: File Sharing | |
24 | Classifier: Topic :: Software Development :: Libraries :: Python Modules | |
25 | Classifier: Topic :: System :: Networking |
0 | CHANGELOG | |
1 | LICENSE | |
2 | MANIFEST.in | |
3 | README.txt | |
4 | setup.py | |
5 | docs/doctrees/environment.pickle | |
6 | docs/doctrees/extending.doctree | |
7 | docs/doctrees/index.doctree | |
8 | docs/doctrees/upgrading.doctree | |
9 | docs/doctrees/api/nmb_NBNSProtocol.doctree | |
10 | docs/doctrees/api/nmb_NetBIOS.doctree | |
11 | docs/doctrees/api/smb_SMBConnection.doctree | |
12 | docs/doctrees/api/smb_SMBHandler.doctree | |
13 | docs/doctrees/api/smb_SMBProtocolFactory.doctree | |
14 | docs/doctrees/api/smb_SharedDevice.doctree | |
15 | docs/doctrees/api/smb_SharedFile.doctree | |
16 | docs/doctrees/api/smb_exceptions.doctree | |
17 | docs/doctrees/api/smb_security_descriptors.doctree | |
18 | docs/html/.buildinfo | |
19 | docs/html/extending.html | |
20 | docs/html/genindex.html | |
21 | docs/html/index.html | |
22 | docs/html/objects.inv | |
23 | docs/html/py-modindex.html | |
24 | docs/html/search.html | |
25 | docs/html/searchindex.js | |
26 | docs/html/upgrading.html | |
27 | docs/html/_modules/index.html | |
28 | docs/html/_modules/nmb/NetBIOS.html | |
29 | docs/html/_modules/nmb/NetBIOSProtocol.html | |
30 | docs/html/_modules/smb/SMBConnection.html | |
31 | docs/html/_modules/smb/SMBProtocol.html | |
32 | docs/html/_modules/smb/base.html | |
33 | docs/html/_modules/smb/security_descriptors.html | |
34 | docs/html/_modules/smb/smb_structs.html | |
35 | docs/html/_sources/extending.txt | |
36 | docs/html/_sources/index.txt | |
37 | docs/html/_sources/upgrading.txt | |
38 | docs/html/_sources/api/nmb_NBNSProtocol.txt | |
39 | docs/html/_sources/api/nmb_NetBIOS.txt | |
40 | docs/html/_sources/api/smb_SMBConnection.txt | |
41 | docs/html/_sources/api/smb_SMBHandler.txt | |
42 | docs/html/_sources/api/smb_SMBProtocolFactory.txt | |
43 | docs/html/_sources/api/smb_SharedDevice.txt | |
44 | docs/html/_sources/api/smb_SharedFile.txt | |
45 | docs/html/_sources/api/smb_exceptions.txt | |
46 | docs/html/_sources/api/smb_security_descriptors.txt | |
47 | docs/html/_static/ajax-loader.gif | |
48 | docs/html/_static/basic.css | |
49 | docs/html/_static/comment-bright.png | |
50 | docs/html/_static/comment-close.png | |
51 | docs/html/_static/comment.png | |
52 | docs/html/_static/contents.png | |
53 | docs/html/_static/doctools.js | |
54 | docs/html/_static/down-pressed.png | |
55 | docs/html/_static/down.png | |
56 | docs/html/_static/file.png | |
57 | docs/html/_static/jquery.js | |
58 | docs/html/_static/minus.png | |
59 | docs/html/_static/navigation.png | |
60 | docs/html/_static/plus.png | |
61 | docs/html/_static/pygments.css | |
62 | docs/html/_static/searchtools.js | |
63 | docs/html/_static/sphinxdoc.css | |
64 | docs/html/_static/underscore.js | |
65 | docs/html/_static/up-pressed.png | |
66 | docs/html/_static/up.png | |
67 | docs/html/_static/websupport.js | |
68 | docs/html/api/nmb_NBNSProtocol.html | |
69 | docs/html/api/nmb_NetBIOS.html | |
70 | docs/html/api/smb_SMBConnection.html | |
71 | docs/html/api/smb_SMBHandler.html | |
72 | docs/html/api/smb_SMBProtocolFactory.html | |
73 | docs/html/api/smb_SharedDevice.html | |
74 | docs/html/api/smb_SharedFile.html | |
75 | docs/html/api/smb_exceptions.html | |
76 | docs/html/api/smb_security_descriptors.html | |
77 | python2/nmb/NetBIOS.py | |
78 | python2/nmb/NetBIOSProtocol.py | |
79 | python2/nmb/__init__.py | |
80 | python2/nmb/base.py | |
81 | python2/nmb/nmb_constants.py | |
82 | python2/nmb/nmb_structs.py | |
83 | python2/nmb/utils.py | |
84 | python2/smb/SMBConnection.py | |
85 | python2/smb/SMBHandler.py | |
86 | python2/smb/SMBProtocol.py | |
87 | python2/smb/__init__.py | |
88 | python2/smb/base.py | |
89 | python2/smb/ntlm.py | |
90 | python2/smb/security_descriptors.py | |
91 | python2/smb/securityblob.py | |
92 | python2/smb/smb2_constants.py | |
93 | python2/smb/smb2_structs.py | |
94 | python2/smb/smb_constants.py | |
95 | python2/smb/smb_structs.py | |
96 | python2/smb/utils/README.txt | |
97 | python2/smb/utils/U32.py | |
98 | python2/smb/utils/__init__.py | |
99 | python2/smb/utils/md4.py | |
100 | python2/smb/utils/pyDes.py | |
101 | python2/smb/utils/rc4.py | |
102 | python2/smb/utils/sha256.py | |
103 | python2/tests/README.md | |
104 | python2/tests/__init__.py | |
105 | python2/tests/connection.ini | |
106 | python2/tests/test_ntlm.py | |
107 | python2/tests/test_security_descriptors.py | |
108 | python2/tests/test_securityblob.py | |
109 | python2/tests/DirectSMBConnectionTests/__init__.py | |
110 | python2/tests/DirectSMBConnectionTests/test_SMBHandler.py | |
111 | python2/tests/DirectSMBConnectionTests/test_auth.py | |
112 | python2/tests/DirectSMBConnectionTests/test_createdeletedirectory.py | |
113 | python2/tests/DirectSMBConnectionTests/test_echo.py | |
114 | python2/tests/DirectSMBConnectionTests/test_listpath.py | |
115 | python2/tests/DirectSMBConnectionTests/test_listshares.py | |
116 | python2/tests/DirectSMBConnectionTests/test_listsnapshots.py | |
117 | python2/tests/DirectSMBConnectionTests/test_rename.py | |
118 | python2/tests/DirectSMBConnectionTests/test_retrievefile.py | |
119 | python2/tests/DirectSMBConnectionTests/test_storefile.py | |
120 | python2/tests/DirectSMBConnectionTests/util.py | |
121 | python2/tests/DirectSMBTwistedTests/test_auth.py | |
122 | python2/tests/DirectSMBTwistedTests/test_createdeletedirectory.py | |
123 | python2/tests/DirectSMBTwistedTests/test_echo.py | |
124 | python2/tests/DirectSMBTwistedTests/test_listpath.py | |
125 | python2/tests/DirectSMBTwistedTests/test_listshares.py | |
126 | python2/tests/DirectSMBTwistedTests/test_listsnapshots.py | |
127 | python2/tests/DirectSMBTwistedTests/test_rename.py | |
128 | python2/tests/DirectSMBTwistedTests/test_retrievefile.py | |
129 | python2/tests/DirectSMBTwistedTests/test_storefile.py | |
130 | python2/tests/DirectSMBTwistedTests/util.py | |
131 | python2/tests/NetBIOSTests/__init__.py | |
132 | python2/tests/NetBIOSTests/test_queryname.py | |
133 | python2/tests/NetBIOSTwistedTests/__init__.py | |
134 | python2/tests/NetBIOSTwistedTests/test_queryname.py | |
135 | python2/tests/SMBConnectionTests/__init__.py | |
136 | python2/tests/SMBConnectionTests/test_SMBHandler.py | |
137 | python2/tests/SMBConnectionTests/test_auth.py | |
138 | python2/tests/SMBConnectionTests/test_createdeletedirectory.py | |
139 | python2/tests/SMBConnectionTests/test_deletepattern.py | |
140 | python2/tests/SMBConnectionTests/test_echo.py | |
141 | python2/tests/SMBConnectionTests/test_getattributes.py | |
142 | python2/tests/SMBConnectionTests/test_listpath.py | |
143 | python2/tests/SMBConnectionTests/test_listshares.py | |
144 | python2/tests/SMBConnectionTests/test_listsnapshots.py | |
145 | python2/tests/SMBConnectionTests/test_rename.py | |
146 | python2/tests/SMBConnectionTests/test_retrievefile.py | |
147 | python2/tests/SMBConnectionTests/test_security.py | |
148 | python2/tests/SMBConnectionTests/test_storefile.py | |
149 | python2/tests/SMBConnectionTests/test_with_context.py | |
150 | python2/tests/SMBConnectionTests/util.py | |
151 | python2/tests/SMBTwistedTests/__init__.py | |
152 | python2/tests/SMBTwistedTests/test_auth.py | |
153 | python2/tests/SMBTwistedTests/test_createdeletedirectory.py | |
154 | python2/tests/SMBTwistedTests/test_echo.py | |
155 | python2/tests/SMBTwistedTests/test_getattributes.py | |
156 | python2/tests/SMBTwistedTests/test_listpath.py | |
157 | python2/tests/SMBTwistedTests/test_listshares.py | |
158 | python2/tests/SMBTwistedTests/test_listsnapshots.py | |
159 | python2/tests/SMBTwistedTests/test_rename.py | |
160 | python2/tests/SMBTwistedTests/test_retrievefile.py | |
161 | python2/tests/SMBTwistedTests/test_storefile.py | |
162 | python2/tests/SMBTwistedTests/util.py | |
163 | python2/tests/SupportFiles/binary.dat | |
164 | python3/nmb/NetBIOS.py | |
165 | python3/nmb/NetBIOSProtocol.py | |
166 | python3/nmb/__init__.py | |
167 | python3/nmb/base.py | |
168 | python3/nmb/nmb_constants.py | |
169 | python3/nmb/nmb_structs.py | |
170 | python3/nmb/utils.py | |
171 | python3/pysmb.egg-info/PKG-INFO | |
172 | python3/pysmb.egg-info/SOURCES.txt | |
173 | python3/pysmb.egg-info/dependency_links.txt | |
174 | python3/pysmb.egg-info/requires.txt | |
175 | python3/pysmb.egg-info/top_level.txt | |
176 | python3/smb/SMBConnection.py | |
177 | python3/smb/SMBHandler.py | |
178 | python3/smb/SMBProtocol.py | |
179 | python3/smb/__init__.py | |
180 | python3/smb/base.py | |
181 | python3/smb/ntlm.py | |
182 | python3/smb/security_descriptors.py | |
183 | python3/smb/securityblob.py | |
184 | python3/smb/smb2_constants.py | |
185 | python3/smb/smb2_structs.py | |
186 | python3/smb/smb_constants.py | |
187 | python3/smb/smb_structs.py | |
188 | python3/smb/utils/U32.py | |
189 | python3/smb/utils/__init__.py | |
190 | python3/smb/utils/md4.py | |
191 | python3/smb/utils/pyDes.py | |
192 | python3/smb/utils/rc4.py | |
193 | python3/smb/utils/sha256.py | |
194 | python3/tests/README.md | |
195 | python3/tests/__init__.py | |
196 | python3/tests/connection.ini | |
197 | python3/tests/test_ntlm.py | |
198 | python3/tests/test_security_descriptors.py | |
199 | python3/tests/test_securityblob.py | |
200 | python3/tests/DirectSMBConnectionTests/__init__.py | |
201 | python3/tests/DirectSMBConnectionTests/test_auth.py | |
202 | python3/tests/DirectSMBConnectionTests/test_createdeletedirectory.py | |
203 | python3/tests/DirectSMBConnectionTests/test_echo.py | |
204 | python3/tests/DirectSMBConnectionTests/test_listpath.py | |
205 | python3/tests/DirectSMBConnectionTests/test_listshares.py | |
206 | python3/tests/DirectSMBConnectionTests/test_listsnapshots.py | |
207 | python3/tests/DirectSMBConnectionTests/test_rename.py | |
208 | python3/tests/DirectSMBConnectionTests/test_retrievefile.py | |
209 | python3/tests/DirectSMBConnectionTests/test_storefile.py | |
210 | python3/tests/DirectSMBConnectionTests/util.py | |
211 | python3/tests/NetBIOSTests/__init__.py | |
212 | python3/tests/NetBIOSTests/test_queryname.py | |
213 | python3/tests/SMBConnectionTests/__init__.py | |
214 | python3/tests/SMBConnectionTests/test_SMBHandler.py | |
215 | python3/tests/SMBConnectionTests/test_auth.py | |
216 | python3/tests/SMBConnectionTests/test_createdeletedirectory.py | |
217 | python3/tests/SMBConnectionTests/test_deletepattern.py | |
218 | python3/tests/SMBConnectionTests/test_echo.py | |
219 | python3/tests/SMBConnectionTests/test_getattributes.py | |
220 | python3/tests/SMBConnectionTests/test_listpath.py | |
221 | python3/tests/SMBConnectionTests/test_listshares.py | |
222 | python3/tests/SMBConnectionTests/test_listsnapshots.py | |
223 | python3/tests/SMBConnectionTests/test_rename.py | |
224 | python3/tests/SMBConnectionTests/test_retrievefile.py | |
225 | python3/tests/SMBConnectionTests/test_storefile.py | |
226 | python3/tests/SMBConnectionTests/test_with_context.py | |
227 | python3/tests/SMBConnectionTests/util.py | |
228 | python3/tests/SupportFiles/binary.dat | |
229 | sphinx/Makefile | |
230 | sphinx/make.bat | |
231 | sphinx/requirements.txt | |
232 | sphinx/source/conf.py | |
233 | sphinx/source/extending.rst | |
234 | sphinx/source/index.rst | |
235 | sphinx/source/upgrading.rst | |
236 | sphinx/source/api/nmb_NBNSProtocol.rst | |
237 | sphinx/source/api/nmb_NetBIOS.rst | |
238 | sphinx/source/api/smb_SMBConnection.rst | |
239 | sphinx/source/api/smb_SMBHandler.rst | |
240 | sphinx/source/api/smb_SMBProtocolFactory.rst | |
241 | sphinx/source/api/smb_SharedDevice.rst | |
242 | sphinx/source/api/smb_SharedFile.rst | |
243 | sphinx/source/api/smb_exceptions.rst | |
244 | sphinx/source/api/smb_security_descriptors.rst⏎ |
0 | pyasn1 |
20 | 20 | Create a new SMBConnection instance. |
21 | 21 | |
22 | 22 | *username* and *password* are the user credentials required to authenticate the underlying SMB connection with the remote server. |
23 | *password* can be a string or a callable returning a string. | |
23 | 24 | File operations can only be proceeded after the connection has been authenticated successfully. |
24 | 25 | |
25 | 26 | Note that you need to call *connect* method to actually establish the SMB connection to the remote server and perform authentication. |
28 | 29 | Some newer server installations might also support Direct hosting of SMB over TCP/IP; for these servers, the default TCP port is 445. |
29 | 30 | |
30 | 31 | :param string my_name: The local NetBIOS machine name that will identify where this connection is originating from. |
31 | You can freely choose a name as long as it contains a maximum of 15 alphanumeric characters and does not contain spaces and any of ``\/:*?";|+`` | |
32 | You can freely choose a name as long as it contains a maximum of 15 alphanumeric characters and does not contain spaces and any of ``\\/:*?";|+`` | |
32 | 33 | :param string remote_name: The NetBIOS machine name of the remote server. |
33 | 34 | On windows, you can find out the machine name by right-clicking on the "My Computer" and selecting "Properties". |
34 | 35 | This parameter must be the same as what has been configured on the remote server, or else the connection will be rejected. |
71 | 72 | total_sent = total_sent + sent |
72 | 73 | |
73 | 74 | # |
75 | # Support for "with" context | |
76 | # | |
77 | def __enter__(self): | |
78 | return self | |
79 | ||
80 | def __exit__(self, *args): | |
81 | self.close() | |
82 | ||
83 | # | |
74 | 84 | # Misc Properties |
75 | 85 | # |
76 | 86 | |
152 | 162 | return results |
153 | 163 | |
154 | 164 | def listPath(self, service_name, path, |
155 | search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE, | |
165 | search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL, | |
156 | 166 | pattern = '*', timeout = 30): |
157 | 167 | """ |
158 | 168 | Retrieve a directory listing of files/folders at *path* |
169 | ||
170 | For simplicity, pysmb defines a "normal" file as a file entry that is not read-only, not hidden, not system, not archive and not a directory. | |
171 | It ignores other attributes like compression, indexed, sparse, temporary and encryption. | |
172 | ||
173 | Note that the default search parameter will query for all read-only (SMB_FILE_ATTRIBUTE_READONLY), hidden (SMB_FILE_ATTRIBUTE_HIDDEN), | |
174 | system (SMB_FILE_ATTRIBUTE_SYSTEM), archive (SMB_FILE_ATTRIBUTE_ARCHIVE), normal (SMB_FILE_ATTRIBUTE_INCL_NORMAL) files | |
175 | and directories (SMB_FILE_ATTRIBUTE_DIRECTORY). | |
176 | If you do not need to include "normal" files in the result, define your own search parameter without the SMB_FILE_ATTRIBUTE_INCL_NORMAL constant. | |
177 | SMB_FILE_ATTRIBUTE_NORMAL should be used by itself and not be used with other bit constants. | |
159 | 178 | |
160 | 179 | :param string/unicode service_name: the name of the shared folder for the *path* |
161 | 180 | :param string/unicode path: path relative to the *service_name* where we are interested to learn about its files/sub-folders. |
162 | 181 | :param integer search: integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py). |
163 | The default *search* value will query for all read-only, hidden, system, archive files and directories. | |
164 | 182 | :param string/unicode pattern: the filter to apply to the results before returning to the client. |
165 | 183 | :return: A list of :doc:`smb.base.SharedFile<smb_SharedFile>` instances. |
166 | 184 | """ |
244 | 262 | self.is_busy = True |
245 | 263 | try: |
246 | 264 | self._getAttributes(service_name, path, cb, eb, timeout) |
265 | while self.is_busy: | |
266 | self._pollForNetBIOSPacket(timeout) | |
267 | finally: | |
268 | self.is_busy = False | |
269 | ||
270 | return results[0] | |
271 | ||
272 | def getSecurity(self, service_name, path, timeout = 30): | |
273 | """ | |
274 | Retrieve the security descriptor of the file at *path* on the *service_name*. | |
275 | ||
276 | :param string/unicode service_name: the name of the shared folder for the *path* | |
277 | :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be raised. | |
278 | :return: A :class:`smb.security_descriptors.SecurityDescriptor` instance containing the security information of the file. | |
279 | """ | |
280 | if not self.sock: | |
281 | raise NotConnectedError('Not connected to server') | |
282 | ||
283 | results = [ ] | |
284 | ||
285 | def cb(info): | |
286 | self.is_busy = False | |
287 | results.append(info) | |
288 | ||
289 | def eb(failure): | |
290 | self.is_busy = False | |
291 | raise failure | |
292 | ||
293 | self.is_busy = True | |
294 | try: | |
295 | self._getSecurity(service_name, path, cb, eb, timeout) | |
247 | 296 | while self.is_busy: |
248 | 297 | self._pollForNetBIOSPacket(timeout) |
249 | 298 | finally: |
349 | 398 | |
350 | 399 | return results[0] |
351 | 400 | |
352 | def deleteFiles(self, service_name, path_file_pattern, timeout = 30): | |
401 | def deleteFiles(self, service_name, path_file_pattern, delete_matching_folders = False, timeout = 30): | |
353 | 402 | """ |
354 | 403 | Delete one or more regular files. It supports the use of wildcards in file names, allowing for deletion of multiple files in a single request. |
404 | ||
405 | If delete_matching_folders is True, immediate sub-folders that match the path_file_pattern will be deleted recursively. | |
355 | 406 | |
356 | 407 | :param string/unicode service_name: Contains the name of the shared folder. |
357 | 408 | :param string/unicode path_file_pattern: The pathname of the file(s) to be deleted, relative to the service_name. |
371 | 422 | |
372 | 423 | self.is_busy = True |
373 | 424 | try: |
374 | self._deleteFiles(service_name, path_file_pattern, cb, eb, timeout = timeout) | |
375 | while self.is_busy: | |
376 | self._pollForNetBIOSPacket(timeout) | |
377 | finally: | |
378 | self.is_busy = False | |
379 | ||
380 | def resetFileAttributes(self, service_name, path_file_pattern, timeout = 30): | |
425 | self._deleteFiles(service_name, path_file_pattern, delete_matching_folders, cb, eb, timeout = timeout) | |
426 | while self.is_busy: | |
427 | self._pollForNetBIOSPacket(timeout) | |
428 | finally: | |
429 | self.is_busy = False | |
430 | ||
431 | def resetFileAttributes(self, service_name, path_file_pattern, file_attributes = ATTR_NORMAL, timeout = 30): | |
381 | 432 | """ |
382 | 433 | Reset file attributes of one or more regular files or folders. |
383 | 434 | It supports the use of wildcards in file names, allowing for unlocking of multiple files/folders in a single request. |
384 | 435 | This function is very helpful when deleting files/folders that are read-only. |
385 | Note: this function is currently only implemented for SMB2! Technically, it sets the FILE_ATTRIBUTE_NORMAL flag, therefore clearing all other flags. (See https://msdn.microsoft.com/en-us/library/cc232110.aspx for further information) | |
386 | ||
436 | By default, it sets the ATTR_NORMAL flag, therefore clearing all other flags. | |
437 | (See https://msdn.microsoft.com/en-us/library/cc232110.aspx for further information) | |
438 | ||
439 | Note: this function is currently only implemented for SMB2! | |
440 | ||
387 | 441 | :param string/unicode service_name: Contains the name of the shared folder. |
388 | 442 | :param string/unicode path_file_pattern: The pathname of the file(s) to be deleted, relative to the service_name. |
389 | 443 | Wildcards may be used in the filename component of the path. |
390 | 444 | If your path/filename contains non-English characters, you must pass in an unicode string. |
445 | :param int file_attributes: The desired file attributes to set. Defaults to `ATTR_NORMAL`. | |
391 | 446 | :return: None |
392 | 447 | """ |
393 | 448 | if not self.sock: |
402 | 457 | |
403 | 458 | self.is_busy = True |
404 | 459 | try: |
405 | self._resetFileAttributes(service_name, path_file_pattern, cb, eb, timeout = timeout) | |
406 | while self.is_busy: | |
407 | self._pollForNetBIOSPacket(timeout) | |
408 | finally: | |
409 | self.is_busy = False | |
410 | ||
460 | self._resetFileAttributes(service_name, path_file_pattern, cb, eb, file_attributes, timeout) | |
461 | while self.is_busy: | |
462 | self._pollForNetBIOSPacket(timeout) | |
463 | finally: | |
464 | self.is_busy = False | |
411 | 465 | |
412 | 466 | def createDirectory(self, service_name, path, timeout = 30): |
413 | 467 | """ |
495 | 549 | """ |
496 | 550 | Send an echo command containing *data* to the remote SMB/CIFS server. The remote SMB/CIFS will reply with the same *data*. |
497 | 551 | |
498 | :param string data: Data to send to the remote server. | |
552 | :param bytes data: Data to send to the remote server. Must be a bytes object. | |
499 | 553 | :return: The *data* parameter |
500 | 554 | """ |
501 | 555 | if not self.sock: |
0 | ||
1 | 0 | import os, sys, socket, urllib.request, urllib.error, urllib.parse, mimetypes, email, tempfile |
2 | 1 | from urllib.parse import (unwrap, unquote, splittype, splithost, quote, |
3 | 2 | splitport, splittag, splitattr, splituser, splitpasswd, splitvalue) |
25 | 24 | port = int(port) |
26 | 25 | |
27 | 26 | # username/password handling |
27 | ||
28 | 28 | user, host = splituser(host) |
29 | ||
29 | 30 | if user: |
30 | 31 | user, passwd = splitpasswd(user) |
31 | 32 | else: |
32 | 33 | passwd = None |
34 | ||
33 | 35 | host = unquote(host) |
34 | 36 | user = user or '' |
35 | 37 | |
40 | 42 | passwd = passwd or '' |
41 | 43 | myname = MACHINE_NAME or self.generateClientMachineName() |
42 | 44 | |
43 | n = NetBIOS() | |
44 | names = n.queryIPForName(host) | |
45 | if names: | |
46 | server_name = names[0] | |
47 | else: | |
48 | raise urllib.error.URLError('SMB error: Hostname does not reply back with its machine name') | |
45 | server_name,host = host.split(',') if ',' in host else [None,host] | |
46 | ||
47 | if server_name is None: | |
48 | n = NetBIOS() | |
49 | ||
50 | names = n.queryIPForName(host) | |
51 | if names: | |
52 | server_name = names[0] | |
53 | else: | |
54 | raise urllib.error.URLError('SMB error: Hostname does not reply back with its machine name') | |
49 | 55 | |
50 | 56 | path, attrs = splitattr(req.selector) |
51 | 57 | if path.startswith('/'): |
177 | 177 | return d |
178 | 178 | |
179 | 179 | def listPath(self, service_name, path, |
180 | search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE, | |
180 | search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL, | |
181 | 181 | pattern = '*', timeout = 30): |
182 | 182 | """ |
183 | 183 | Retrieve a directory listing of files/folders at *path* |
184 | ||
185 | For simplicity, pysmb defines a "normal" file as a file entry that is not read-only, not hidden, not system, not archive and not a directory. | |
186 | It ignores other attributes like compression, indexed, sparse, temporary and encryption. | |
187 | ||
188 | Note that the default search parameter will query for all read-only (SMB_FILE_ATTRIBUTE_READONLY), hidden (SMB_FILE_ATTRIBUTE_HIDDEN), | |
189 | system (SMB_FILE_ATTRIBUTE_SYSTEM), archive (SMB_FILE_ATTRIBUTE_ARCHIVE), normal (SMB_FILE_ATTRIBUTE_INCL_NORMAL) files | |
190 | and directories (SMB_FILE_ATTRIBUTE_DIRECTORY). | |
191 | If you do not need to include "normal" files in the result, define your own search parameter without the SMB_FILE_ATTRIBUTE_INCL_NORMAL constant. | |
192 | SMB_FILE_ATTRIBUTE_NORMAL should be used by itself and not be used with other bit constants. | |
184 | 193 | |
185 | 194 | :param string/unicode service_name: the name of the shared folder for the *path* |
186 | 195 | :param string/unicode path: path relative to the *service_name* where we are interested to learn about its files/sub-folders. |
187 | 196 | :param integer search: integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py). |
188 | The default *search* value will query for all read-only, hidden, system, archive files and directories. | |
189 | 197 | :param string/unicode pattern: the filter to apply to the results before returning to the client. |
190 | 198 | :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method. |
191 | 199 | :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of :doc:`smb.base.SharedFile<smb_SharedFile>` instances. |
294 | 302 | self.instance._storeFile(service_name, path, file_obj, d.callback, d.errback, timeout = timeout) |
295 | 303 | return d |
296 | 304 | |
297 | def deleteFiles(self, service_name, path_file_pattern, timeout = 30): | |
305 | def deleteFiles(self, service_name, path_file_pattern, delete_matching_folders = False, timeout = 30): | |
298 | 306 | """ |
299 | 307 | Delete one or more regular files. It supports the use of wildcards in file names, allowing for deletion of multiple files in a single request. |
300 | 308 | |
309 | If delete_matching_folders is True, immediate sub-folders that match the path_file_pattern will be deleted recursively. | |
310 | ||
301 | 311 | :param string/unicode service_name: Contains the name of the shared folder. |
302 | 312 | :param string/unicode path_file_pattern: The pathname of the file(s) to be deleted, relative to the service_name. |
303 | 313 | Wildcards may be used in th filename component of the path. |
309 | 319 | raise NotConnectedError('Not connected to server') |
310 | 320 | |
311 | 321 | d = defer.Deferred() |
312 | self.instance._deleteFiles(service_name, path_file_pattern, d.callback, d.errback, timeout = timeout) | |
322 | self.instance._deleteFiles(service_name, path_file_pattern, delete_matching_folders, d.callback, d.errback, timeout = timeout) | |
313 | 323 | return d |
314 | 324 | |
315 | 325 | def createDirectory(self, service_name, path): |
368 | 378 | """ |
369 | 379 | Send an echo command containing *data* to the remote SMB/CIFS server. The remote SMB/CIFS will reply with the same *data*. |
370 | 380 | |
371 | :param string data: Data to send to the remote server. | |
381 | :param bytes data: Data to send to the remote server. Must be a bytes object. | |
372 | 382 | :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method. |
373 | 383 | :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with the *data* parameter. |
374 | 384 | """ |
4 | 4 | from .smb2_constants import * |
5 | 5 | from .smb_structs import * |
6 | 6 | from .smb2_structs import * |
7 | from .security_descriptors import SecurityDescriptor | |
7 | 8 | from nmb.base import NMBSession |
8 | 9 | from .utils import convertFILETIMEtoEpoch |
9 | 10 | from . import ntlm, securityblob |
52 | 53 | def __init__(self, username, password, my_name, remote_name, domain = '', use_ntlm_v2 = True, sign_options = SIGN_WHEN_REQUIRED, is_direct_tcp = False): |
53 | 54 | NMBSession.__init__(self, my_name, remote_name, is_direct_tcp = is_direct_tcp) |
54 | 55 | self.username = username |
55 | self.password = password | |
56 | self._password = password | |
56 | 57 | self.domain = domain |
57 | 58 | self.sign_options = sign_options |
58 | 59 | self.is_direct_tcp = is_direct_tcp |
59 | 60 | self.use_ntlm_v2 = use_ntlm_v2 #: Similar to LMAuthenticationPolicy and NTAuthenticationPolicy as described in [MS-CIFS] 3.2.1.1 |
60 | 61 | self.smb_message = SMBMessage() |
61 | 62 | self.is_using_smb2 = False #: Are we communicating using SMB2 protocol? self.smb_message will be a SMB2Message instance if this flag is True |
63 | self.async_requests = { } #: AsyncID mapped to _PendingRequest instance | |
62 | 64 | self.pending_requests = { } #: MID mapped to _PendingRequest instance |
63 | 65 | self.connected_trees = { } #: Share name mapped to TID |
64 | 66 | self.next_rpc_call_id = 1 #: Next RPC callID value. Not used directly in SMB message. Usually encapsulated in sub-commands under SMB_COM_TRANSACTION or SMB_COM_TRANSACTION2 messages |
97 | 99 | (self.use_ntlm_v2 and 'v2') or 'v1', |
98 | 100 | (SUPPORT_EXTENDED_SECURITY and 'with') or 'without') |
99 | 101 | |
102 | @property | |
103 | def password(self): | |
104 | if callable(self._password): | |
105 | return self._password() | |
106 | return self._password | |
100 | 107 | |
101 | 108 | # |
102 | 109 | # NMBSession Methods |
166 | 173 | self._listShares = self._listShares_SMB1 |
167 | 174 | self._listPath = self._listPath_SMB1 |
168 | 175 | self._listSnapshots = self._listSnapshots_SMB1 |
176 | self._getSecurity = self._getSecurity_SMB1 | |
169 | 177 | self._getAttributes = self._getAttributes_SMB1 |
170 | 178 | self._retrieveFile = self._retrieveFile_SMB1 |
171 | 179 | self._retrieveFileFromOffset = self._retrieveFileFromOffset_SMB1 |
188 | 196 | self._listShares = self._listShares_SMB2 |
189 | 197 | self._listPath = self._listPath_SMB2 |
190 | 198 | self._listSnapshots = self._listSnapshots_SMB2 |
199 | self._getSecurity = self._getSecurity_SMB2 | |
191 | 200 | self._getAttributes = self._getAttributes_SMB2 |
192 | 201 | self._retrieveFile = self._retrieveFile_SMB2 |
193 | 202 | self._retrieveFileFromOffset = self._retrieveFileFromOffset_SMB2 |
212 | 221 | if smb_message.mid == 0: |
213 | 222 | smb_message.mid = self._getNextMID_SMB2() |
214 | 223 | |
215 | if smb_message.command != SMB2_COM_NEGOTIATE and smb_message.command != SMB2_COM_ECHO: | |
224 | if smb_message.command != SMB2_COM_NEGOTIATE: | |
216 | 225 | smb_message.session_id = self.session_id |
217 | 226 | |
218 | 227 | if self.is_signing_active: |
249 | 258 | if result == securityblob.RESULT_ACCEPT_COMPLETED: |
250 | 259 | self.has_authenticated = True |
251 | 260 | self.log.info('Authentication (on SMB2) successful!') |
261 | ||
262 | # [MS-SMB2]: 3.2.5.3.1 | |
263 | # If the security subsystem indicates that the session was established by an anonymous user, | |
264 | # Session.SigningRequired MUST be set to FALSE. | |
265 | # If the SMB2_SESSION_FLAG_IS_GUEST bit is set in the SessionFlags field of the | |
266 | # SMB2 SESSION_SETUP Response and if Session.SigningRequired is TRUE, this indicates a SESSION_SETUP | |
267 | # failure and the connection MUST be terminated. If the SMB2_SESSION_FLAG_IS_GUEST bit is set in the SessionFlags | |
268 | # field of the SMB2 SESSION_SETUP Response and if RequireMessageSigning is FALSE, Session.SigningRequired | |
269 | # MUST be set to FALSE. | |
270 | if message.payload.isGuestSession or message.payload.isAnonymousSession: | |
271 | self.is_signing_active = False | |
272 | self.log.info('Signing disabled because session is guest/anonymous') | |
273 | ||
252 | 274 | self.onAuthOK() |
253 | 275 | else: |
254 | 276 | raise ProtocolError('SMB2_COM_SESSION_SETUP status is 0 but security blob negResult value is %d' % result, message.raw_data, message) |
262 | 284 | self._handleSessionChallenge(message, ntlm_token) |
263 | 285 | except ( securityblob.BadSecurityBlobError, securityblob.UnsupportedSecurityProvider ) as ex: |
264 | 286 | raise ProtocolError(str(ex), message.raw_data, message) |
265 | elif message.status == 0xc000006d: # STATUS_LOGON_FAILURE | |
287 | elif (message.status == 0xc000006d # STATUS_LOGON_FAILURE | |
288 | or message.status == 0xc0000064 # STATUS_NO_SUCH_USER | |
289 | or message.status == 0xc000006a):# STATUS_WRONG_PASSWORD | |
266 | 290 | self.has_authenticated = False |
267 | 291 | self.log.info('Authentication (on SMB2) failed. Please check username and password.') |
268 | 292 | self.onAuthFailed() |
293 | elif (message.status == 0xc0000193 # STATUS_ACCOUNT_EXPIRED | |
294 | or message.status == 0xC0000071): # STATUS_PASSWORD_EXPIRED | |
295 | self.has_authenticated = False | |
296 | self.log.info('Authentication (on SMB2) failed. Account or password has expired.') | |
297 | self.onAuthFailed() | |
298 | elif message.status == 0xc0000234: # STATUS_ACCOUNT_LOCKED_OUT | |
299 | self.has_authenticated = False | |
300 | self.log.info('Authentication (on SMB2) failed. Account has been locked due to too many invalid logon attempts.') | |
301 | self.onAuthFailed() | |
302 | elif message.status == 0xc0000072: # STATUS_ACCOUNT_DISABLED | |
303 | self.has_authenticated = False | |
304 | self.log.info('Authentication (on SMB2) failed. Account has been disabled.') | |
305 | self.onAuthFailed() | |
306 | elif (message.status == 0xc000006f # STATUS_INVALID_LOGON_HOURS | |
307 | or message.status == 0xc000015b # STATUS_LOGON_TYPE_NOT_GRANTED | |
308 | or message.status == 0xc0000070): # STATUS_INVALID_WORKSTATION | |
309 | self.has_authenticated = False | |
310 | self.log.info('Authentication (on SMB2) failed. Not allowed.') | |
311 | self.onAuthFailed() | |
312 | elif message.status == 0xc000018c: # STATUS_TRUSTED_DOMAIN_FAILURE | |
313 | self.has_authenticated = False | |
314 | self.log.info('Authentication (on SMB2) failed. Domain not trusted.') | |
315 | self.onAuthFailed() | |
316 | elif message.status == 0xc000018d: # STATUS_TRUSTED_RELATIONSHIP_FAILURE | |
317 | self.has_authenticated = False | |
318 | self.log.info('Authentication (on SMB2) failed. Workstation not trusted.') | |
319 | self.onAuthFailed() | |
269 | 320 | else: |
270 | 321 | raise ProtocolError('Unknown status value (0x%08X) in SMB_COM_SESSION_SETUP_ANDX (with extended security)' % message.status, |
271 | 322 | message.raw_data, message) |
272 | 323 | |
273 | req = self.pending_requests.pop(message.mid, None) | |
274 | if req: | |
275 | req.callback(message, **req.kwargs) | |
276 | return True | |
324 | if message.isAsync: | |
325 | if message.status == 0x00000103: # STATUS_PENDING | |
326 | req = self.pending_requests.pop(message.mid, None) | |
327 | if req: | |
328 | self.async_requests[message.async_id] = req | |
329 | else: # All other status including SUCCESS | |
330 | req = self.async_requests.pop(message.async_id, None) | |
331 | if req: | |
332 | req.callback(message, **req.kwargs) | |
333 | return True | |
334 | else: | |
335 | req = self.pending_requests.pop(message.mid, None) | |
336 | if req: | |
337 | req.callback(message, **req.kwargs) | |
338 | return True | |
277 | 339 | |
278 | 340 | |
279 | 341 | def _updateServerInfo_SMB2(self, payload): |
308 | 370 | self.log.info('Performing NTLMv1 authentication (on SMB2) with server challenge "%s"', binascii.hexlify(server_challenge)) |
309 | 371 | nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV1(self.password, server_challenge, True) |
310 | 372 | |
311 | ntlm_data = ntlm.generateAuthenticateMessage(server_flags, | |
312 | nt_challenge_response, | |
313 | lm_challenge_response, | |
314 | session_key, | |
315 | self.username, | |
316 | self.domain) | |
373 | ntlm_data, session_signing_key = ntlm.generateAuthenticateMessage(server_flags, | |
374 | nt_challenge_response, | |
375 | lm_challenge_response, | |
376 | session_key, | |
377 | self.username, | |
378 | self.domain, | |
379 | self.my_name) | |
317 | 380 | |
318 | 381 | if self.log.isEnabledFor(logging.DEBUG): |
319 | 382 | self.log.debug('NT challenge response is "%s" (%d bytes)', binascii.hexlify(nt_challenge_response), len(nt_challenge_response)) |
333 | 396 | |
334 | 397 | if self.is_signing_active: |
335 | 398 | self.log.info("SMB signing activated. All SMB messages will be signed.") |
336 | self.signing_session_key = (session_key + b'\0'*16)[:16] | |
399 | self.signing_session_key = session_signing_key | |
400 | if self.log.isEnabledFor(logging.DEBUG): | |
401 | self.log.info("SMB signing key is %s", binascii.hexlify(self.signing_session_key)) | |
402 | ||
337 | 403 | if self.capabilities & CAP_EXTENDED_SECURITY: |
338 | 404 | self.signing_challenge_response = None |
339 | 405 | else: |
362 | 428 | |
363 | 429 | m.tid = tid |
364 | 430 | self._sendSMBMessage(m) |
365 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectSrvSvcCB, errback) | |
431 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectSrvSvcCB, errback, tid = tid) | |
366 | 432 | messages_history.append(m) |
367 | 433 | |
368 | 434 | def connectSrvSvcCB(create_message, **kwargs): |
384 | 450 | 01 00 00 00 |
385 | 451 | """.replace(b' ', b'').replace(b'\n', b'')) |
386 | 452 | m = SMB2Message(SMB2WriteRequest(create_message.payload.fid, data_bytes, 0)) |
387 | m.tid = create_message.tid | |
453 | m.tid = kwargs['tid'] | |
388 | 454 | self._sendSMBMessage(m) |
389 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcBindCB, errback, fid = create_message.payload.fid) | |
455 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcBindCB, errback, tid = kwargs['tid'], fid = create_message.payload.fid) | |
390 | 456 | messages_history.append(m) |
391 | 457 | else: |
392 | 458 | errback(OperationFailure('Failed to list shares: Unable to locate Server Service RPC endpoint', messages_history)) |
395 | 461 | messages_history.append(trans_message) |
396 | 462 | if trans_message.status == 0: |
397 | 463 | m = SMB2Message(SMB2ReadRequest(kwargs['fid'], read_len = 1024, read_offset = 0)) |
398 | m.tid = trans_message.tid | |
464 | m.tid = kwargs['tid'] | |
399 | 465 | self._sendSMBMessage(m) |
400 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcReadCB, errback, fid = kwargs['fid']) | |
466 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcReadCB, errback, tid = kwargs['tid'], fid = kwargs['fid']) | |
401 | 467 | messages_history.append(m) |
402 | 468 | else: |
403 | closeFid(trans_message.tid, kwargs['fid'], error = 'Failed to list shares: Unable to read from Server Service RPC endpoint') | |
469 | closeFid(kwargs['tid'], kwargs['fid'], error = 'Failed to list shares: Unable to read from Server Service RPC endpoint') | |
404 | 470 | |
405 | 471 | def rpcReadCB(read_message, **kwargs): |
406 | 472 | messages_history.append(read_message) |
428 | 494 | 00 00 00 00 ff ff ff ff 08 00 02 00 00 00 00 00 |
429 | 495 | """.replace(b' ', b'').replace(b'\n', b'')) |
430 | 496 | m = SMB2Message(SMB2IoctlRequest(kwargs['fid'], 0x0011C017, flags = 0x01, max_out_size = 8196, in_data = data_bytes)) |
431 | m.tid = read_message.tid | |
497 | m.tid = kwargs['tid'] | |
432 | 498 | self._sendSMBMessage(m) |
433 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, listShareResultsCB, errback, fid = kwargs['fid']) | |
499 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, listShareResultsCB, errback, tid = kwargs['tid'], fid = kwargs['fid']) | |
434 | 500 | messages_history.append(m) |
435 | 501 | else: |
436 | closeFid(read_message.tid, kwargs['fid'], error = 'Failed to list shares: Unable to bind to Server Service RPC endpoint') | |
502 | closeFid(kwargs['tid'], kwargs['fid'], error = 'Failed to list shares: Unable to bind to Server Service RPC endpoint') | |
437 | 503 | |
438 | 504 | def listShareResultsCB(result_message, **kwargs): |
439 | 505 | messages_history.append(result_message) |
442 | 508 | data_bytes = result_message.payload.out_data |
443 | 509 | |
444 | 510 | if data_bytes[3] & 0x02 == 0: |
445 | sendReadRequest(result_message.tid, kwargs['fid'], data_bytes) | |
446 | else: | |
447 | decodeResults(result_message.tid, kwargs['fid'], data_bytes) | |
448 | elif result_message.status == 0x0103: # STATUS_PENDING | |
449 | self.pending_requests[result_message.mid] = _PendingRequest(result_message.mid, expiry_time, listShareResultsCB, errback, fid = kwargs['fid']) | |
450 | else: | |
451 | closeFid(result_message.tid, kwargs['fid']) | |
511 | sendReadRequest(kwargs['tid'], kwargs['fid'], data_bytes) | |
512 | else: | |
513 | decodeResults(kwargs['tid'], kwargs['fid'], data_bytes) | |
514 | else: | |
515 | closeFid(kwargs['tid'], kwargs['fid']) | |
452 | 516 | errback(OperationFailure('Failed to list shares: Unable to retrieve shared device list', messages_history)) |
453 | 517 | |
454 | 518 | def decodeResults(tid, fid, data_bytes): |
487 | 551 | m.tid = tid |
488 | 552 | self._sendSMBMessage(m) |
489 | 553 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, readCB, errback, |
490 | fid = fid, data_bytes = data_bytes) | |
554 | tid = tid, fid = fid, data_bytes = data_bytes) | |
491 | 555 | |
492 | 556 | def readCB(read_message, **kwargs): |
493 | 557 | messages_history.append(read_message) |
494 | 558 | if read_message.status == 0: |
495 | data_len = read_message.payload.data_length | |
496 | 559 | data_bytes = read_message.payload.data |
497 | 560 | |
498 | 561 | if data_bytes[3] & 0x02 == 0: |
499 | sendReadRequest(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:data_len-24]) | |
500 | else: | |
501 | decodeResults(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:data_len-24]) | |
502 | else: | |
503 | closeFid(read_message.tid, kwargs['fid']) | |
562 | sendReadRequest(kwargs['tid'], kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:]) | |
563 | else: | |
564 | decodeResults(kwargs['tid'], kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:]) | |
565 | else: | |
566 | closeFid(kwargs['tid'], kwargs['fid']) | |
504 | 567 | errback(OperationFailure('Failed to list shares: Unable to retrieve shared device list', messages_history)) |
505 | 568 | |
506 | 569 | def closeFid(tid, fid, results = None, error = None): |
565 | 628 | create_context_data = create_context_data)) |
566 | 629 | m.tid = tid |
567 | 630 | self._sendSMBMessage(m) |
568 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback) | |
631 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid) | |
569 | 632 | messages_history.append(m) |
570 | 633 | |
571 | 634 | def createCB(create_message, **kwargs): |
572 | 635 | messages_history.append(create_message) |
573 | 636 | if create_message.status == 0: |
574 | sendQuery(create_message.tid, create_message.payload.fid, b'') | |
637 | sendQuery(kwargs['tid'], create_message.payload.fid, b'') | |
638 | elif create_message.status == 0xC0000034: # [MS-ERREF]: STATUS_OBJECT_NAME_INVALID | |
639 | errback(OperationFailure('Failed to list %s on %s: Path not found' % ( path, service_name ), messages_history)) | |
575 | 640 | else: |
576 | 641 | errback(OperationFailure('Failed to list %s on %s: Unable to open directory' % ( path, service_name ), messages_history)) |
577 | 642 | |
578 | 643 | def sendQuery(tid, fid, data_buf): |
579 | 644 | m = SMB2Message(SMB2QueryDirectoryRequest(fid, pattern, |
580 | info_class = 0x03, # FileBothDirectoryInformation | |
645 | info_class = 0x25, # FileIdBothDirectoryInformation | |
581 | 646 | flags = 0, |
582 | 647 | output_buf_len = self.max_transact_size)) |
583 | 648 | m.tid = tid |
584 | 649 | self._sendSMBMessage(m) |
585 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, queryCB, errback, fid = fid, data_buf = data_buf) | |
650 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, queryCB, errback, tid = tid, fid = fid, data_buf = data_buf) | |
586 | 651 | messages_history.append(m) |
587 | 652 | |
588 | 653 | def queryCB(query_message, **kwargs): |
589 | 654 | messages_history.append(query_message) |
590 | 655 | if query_message.status == 0: |
591 | 656 | data_buf = decodeQueryStruct(kwargs['data_buf'] + query_message.payload.data) |
592 | sendQuery(query_message.tid, kwargs['fid'], data_buf) | |
657 | sendQuery(kwargs['tid'], kwargs['fid'], data_buf) | |
658 | elif query_message.status == 0xC000000F: # [MS-ERREF]: STATUS_NO_SUCH_FILE | |
659 | # If there are no matching files, we just treat as success instead of failing | |
660 | closeFid(kwargs['tid'], kwargs['fid'], results = results) | |
593 | 661 | elif query_message.status == 0x80000006: # STATUS_NO_MORE_FILES |
594 | closeFid(query_message.tid, kwargs['fid'], results = results) | |
595 | else: | |
596 | closeFid(query_message.tid, kwargs['fid'], error = query_message.status) | |
662 | closeFid(kwargs['tid'], kwargs['fid'], results = results) | |
663 | else: | |
664 | closeFid(kwargs['tid'], kwargs['fid'], error = query_message.status) | |
597 | 665 | |
598 | 666 | def decodeQueryStruct(data_bytes): |
599 | # SMB_FIND_FILE_BOTH_DIRECTORY_INFO structure. See [MS-CIFS]: 2.2.8.1.7 and [MS-SMB]: 2.2.8.1.1 | |
600 | info_format = '<IIQQQQQQIIIBB24s' | |
667 | # FileIdBothDirectoryInformation structure. See [MS-SMB]: 2.2.8.1.3 and [MS-FSCC]: 2.4.17 | |
668 | info_format = '<IIQQQQQQIIIBB24sHQ' | |
601 | 669 | info_size = struct.calcsize(info_format) |
602 | 670 | |
603 | 671 | data_length = len(data_bytes) |
609 | 677 | next_offset, _, \ |
610 | 678 | create_time, last_access_time, last_write_time, last_attr_change_time, \ |
611 | 679 | file_size, alloc_size, file_attributes, filename_length, ea_size, \ |
612 | short_name_length, _, short_name = struct.unpack(info_format, data_bytes[offset:offset+info_size]) | |
680 | short_name_length, _, short_name, _, file_id = struct.unpack(info_format, data_bytes[offset:offset+info_size]) | |
613 | 681 | |
614 | 682 | offset2 = offset + info_size |
615 | 683 | if offset2 + filename_length > data_length: |
616 | 684 | return data_bytes[offset:] |
617 | 685 | |
618 | 686 | filename = data_bytes[offset2:offset2+filename_length].decode('UTF-16LE') |
619 | short_name = short_name.decode('UTF-16LE') | |
620 | results.append(SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time), | |
621 | convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time), | |
622 | file_size, alloc_size, file_attributes, short_name, filename)) | |
687 | short_name = short_name[:short_name_length].decode('UTF-16LE') | |
688 | ||
689 | accept_result = False | |
690 | if (file_attributes & 0xff) in ( 0x00, ATTR_NORMAL ): # Only the first 8-bits are compared. We ignore other bits like temp, compressed, encryption, sparse, indexed, etc | |
691 | accept_result = (search == SMB_FILE_ATTRIBUTE_NORMAL) or (search & SMB_FILE_ATTRIBUTE_INCL_NORMAL) | |
692 | else: | |
693 | accept_result = (file_attributes & search) > 0 | |
694 | if accept_result: | |
695 | results.append(SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time), | |
696 | convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time), | |
697 | file_size, alloc_size, file_attributes, short_name, filename, file_id)) | |
623 | 698 | |
624 | 699 | if next_offset: |
625 | 700 | offset += next_offset |
638 | 713 | if kwargs['results'] is not None: |
639 | 714 | callback(kwargs['results']) |
640 | 715 | elif kwargs['error'] is not None: |
641 | errback(OperationFailure('Failed to list %s on %s: Query failed with errorcode 0x%08x' % ( path, service_name, kwargs['error'] ), messages_history)) | |
716 | if kwargs['error'] == 0xC000000F: # [MS-ERREF]: STATUS_NO_SUCH_FILE | |
717 | # Remote server returns STATUS_NO_SUCH_FILE error so we assume that the search returns no matching files | |
718 | callback([ ]) | |
719 | else: | |
720 | errback(OperationFailure('Failed to list %s on %s: Query failed with errorcode 0x%08x' % ( path, service_name, kwargs['error'] ), messages_history)) | |
642 | 721 | |
643 | 722 | if service_name not in self.connected_trees: |
644 | 723 | def connectCB(connect_message, **kwargs): |
688 | 767 | create_context_data = create_context_data)) |
689 | 768 | m.tid = tid |
690 | 769 | self._sendSMBMessage(m) |
691 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback) | |
770 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid) | |
692 | 771 | messages_history.append(m) |
693 | 772 | |
694 | 773 | def createCB(create_message, **kwargs): |
695 | 774 | messages_history.append(create_message) |
696 | 775 | if create_message.status == 0: |
697 | 776 | p = create_message.payload |
777 | filename = self._extractLastPathComponent(path) | |
698 | 778 | info = SharedFile(p.create_time, p.lastaccess_time, p.lastwrite_time, p.change_time, |
699 | 779 | p.file_size, p.allocation_size, p.file_attributes, |
700 | path, path) | |
701 | closeFid(create_message.tid, p.fid, info = info) | |
780 | filename, filename) | |
781 | closeFid(kwargs['tid'], p.fid, info = info) | |
702 | 782 | else: |
703 | 783 | errback(OperationFailure('Failed to get attributes for %s on %s: Unable to open remote file object' % ( path, service_name ), messages_history)) |
704 | 784 | |
723 | 803 | sendCreate(connect_message.tid) |
724 | 804 | else: |
725 | 805 | errback(OperationFailure('Failed to get attributes for %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) |
806 | ||
807 | m = SMB2Message(SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ))) | |
808 | self._sendSMBMessage(m) | |
809 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name) | |
810 | messages_history.append(m) | |
811 | else: | |
812 | sendCreate(self.connected_trees[service_name]) | |
813 | ||
814 | def _getSecurity_SMB2(self, service_name, path, callback, errback, timeout = 30): | |
815 | if not self.has_authenticated: | |
816 | raise NotReadyError('SMB connection not authenticated') | |
817 | ||
818 | expiry_time = time.time() + timeout | |
819 | path = path.replace('/', '\\') | |
820 | if path.startswith('\\'): | |
821 | path = path[1:] | |
822 | if path.endswith('\\'): | |
823 | path = path[:-1] | |
824 | messages_history = [ ] | |
825 | results = [ ] | |
826 | ||
827 | def sendCreate(tid): | |
828 | m = SMB2Message(SMB2CreateRequest(path, | |
829 | file_attributes = 0, | |
830 | access_mask = FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | READ_CONTROL | SYNCHRONIZE, | |
831 | share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | |
832 | oplock = SMB2_OPLOCK_LEVEL_NONE, | |
833 | impersonation = SEC_IMPERSONATE, | |
834 | create_options = 0, | |
835 | create_disp = FILE_OPEN)) | |
836 | m.tid = tid | |
837 | self._sendSMBMessage(m) | |
838 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid) | |
839 | messages_history.append(m) | |
840 | ||
841 | def createCB(create_message, **kwargs): | |
842 | messages_history.append(create_message) | |
843 | if create_message.status == 0: | |
844 | m = SMB2Message(SMB2QueryInfoRequest(create_message.payload.fid, | |
845 | flags = 0, | |
846 | additional_info = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, | |
847 | info_type = SMB2_INFO_SECURITY, | |
848 | file_info_class = 0, # [MS-SMB2] 2.2.37, 3.2.4.12 | |
849 | input_buf = '', | |
850 | output_buf_len = self.max_transact_size)) | |
851 | m.tid = kwargs['tid'] | |
852 | self._sendSMBMessage(m) | |
853 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, queryCB, errback, tid = kwargs['tid'], fid = create_message.payload.fid) | |
854 | messages_history.append(m) | |
855 | else: | |
856 | errback(OperationFailure('Failed to get the security descriptor of %s on %s: Unable to open file or directory' % ( path, service_name ), messages_history)) | |
857 | ||
858 | def queryCB(query_message, **kwargs): | |
859 | messages_history.append(query_message) | |
860 | if query_message.status == 0: | |
861 | security = SecurityDescriptor.from_bytes(query_message.payload.data) | |
862 | closeFid(kwargs['tid'], kwargs['fid'], result = security) | |
863 | else: | |
864 | closeFid(kwargs['tid'], kwargs['fid'], error = query_message.status) | |
865 | ||
866 | def closeFid(tid, fid, result = None, error = None): | |
867 | m = SMB2Message(SMB2CloseRequest(fid)) | |
868 | m.tid = tid | |
869 | self._sendSMBMessage(m) | |
870 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, result = result, error = error) | |
871 | messages_history.append(m) | |
872 | ||
873 | def closeCB(close_message, **kwargs): | |
874 | if kwargs['result'] is not None: | |
875 | callback(kwargs['result']) | |
876 | elif kwargs['error'] is not None: | |
877 | errback(OperationFailure('Failed to get the security descriptor of %s on %s: Query failed with errorcode 0x%08x' % ( path, service_name, kwargs['error'] ), messages_history)) | |
878 | ||
879 | if service_name not in self.connected_trees: | |
880 | def connectCB(connect_message, **kwargs): | |
881 | messages_history.append(connect_message) | |
882 | if connect_message.status == 0: | |
883 | self.connected_trees[service_name] = connect_message.tid | |
884 | sendCreate(connect_message.tid) | |
885 | else: | |
886 | errback(OperationFailure('Failed to get the security descriptor of %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
726 | 887 | |
727 | 888 | m = SMB2Message(SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ))) |
728 | 889 | self._sendSMBMessage(m) |
759 | 920 | m = SMB2Message(SMB2CreateRequest(path, |
760 | 921 | file_attributes = 0, |
761 | 922 | access_mask = FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | READ_CONTROL | SYNCHRONIZE, |
762 | share_access = FILE_SHARE_READ, | |
923 | share_access = FILE_SHARE_READ | FILE_SHARE_WRITE, | |
763 | 924 | oplock = SMB2_OPLOCK_LEVEL_NONE, |
764 | 925 | impersonation = SEC_IMPERSONATE, |
765 | 926 | create_options = FILE_SEQUENTIAL_ONLY | FILE_NON_DIRECTORY_FILE, |
780 | 941 | file_info_class = 0x16, # FileStreamInformation [MS-FSCC] 2.4 |
781 | 942 | input_buf = b'', |
782 | 943 | output_buf_len = 4096)) |
783 | m.tid = create_message.tid | |
944 | m.tid = kwargs['tid'] | |
784 | 945 | self._sendSMBMessage(m) |
785 | 946 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, infoCB, errback, |
786 | fid = create_message.payload.fid, file_attributes = create_message.payload.file_attributes) | |
947 | tid = kwargs['tid'], | |
948 | fid = create_message.payload.fid, | |
949 | file_attributes = create_message.payload.file_attributes) | |
787 | 950 | messages_history.append(m) |
788 | 951 | else: |
789 | errback(OperationFailure('Failed to list %s on %s: Unable to open file' % ( path, service_name ), messages_history)) | |
952 | errback(OperationFailure('Failed to retrieve %s on %s: Unable to open file' % ( path, service_name ), messages_history)) | |
790 | 953 | |
791 | 954 | def infoCB(info_message, **kwargs): |
792 | 955 | messages_history.append(info_message) |
801 | 964 | remaining_len = file_len |
802 | 965 | if starting_offset + remaining_len > file_len: |
803 | 966 | remaining_len = file_len - starting_offset |
804 | sendRead(info_message.tid, kwargs['fid'], starting_offset, remaining_len, 0, kwargs['file_attributes']) | |
805 | else: | |
806 | errback(OperationFailure('Failed to list %s on %s: Unable to retrieve information on file' % ( path, service_name ), messages_history)) | |
967 | sendRead(kwargs['tid'], kwargs['fid'], starting_offset, remaining_len, 0, kwargs['file_attributes']) | |
968 | else: | |
969 | errback(OperationFailure('Failed to retrieve %s on %s: Unable to retrieve information on file' % ( path, service_name ), messages_history)) | |
807 | 970 | |
808 | 971 | def sendRead(tid, fid, offset, remaining_len, read_len, file_attributes): |
809 | 972 | read_count = min(self.max_read_size, remaining_len) |
811 | 974 | m.tid = tid |
812 | 975 | self._sendSMBMessage(m) |
813 | 976 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, readCB, errback, |
814 | fid = fid, offset = offset, | |
977 | tid = tid, fid = fid, offset = offset, | |
815 | 978 | remaining_len = remaining_len, |
816 | 979 | read_len = read_len, |
817 | 980 | file_attributes = file_attributes) |
825 | 988 | remaining_len = kwargs['remaining_len'] - data_len |
826 | 989 | |
827 | 990 | if remaining_len > 0: |
828 | sendRead(read_message.tid, kwargs['fid'], kwargs['offset'] + data_len, remaining_len, kwargs['read_len'] + data_len, kwargs['file_attributes']) | |
829 | else: | |
830 | closeFid(read_message.tid, kwargs['fid'], ret = ( file_obj, kwargs['file_attributes'], kwargs['read_len'] + data_len )) | |
991 | sendRead(kwargs['tid'], kwargs['fid'], kwargs['offset'] + data_len, remaining_len, kwargs['read_len'] + data_len, kwargs['file_attributes']) | |
992 | else: | |
993 | closeFid(kwargs['tid'], kwargs['fid'], ret = ( file_obj, kwargs['file_attributes'], kwargs['read_len'] + data_len )) | |
831 | 994 | else: |
832 | 995 | messages_history.append(read_message) |
833 | closeFid(read_message.tid, kwargs['fid'], error = read_message.status) | |
996 | closeFid(kwargs['tid'], kwargs['fid'], error = read_message.status) | |
834 | 997 | |
835 | 998 | def closeFid(tid, fid, ret = None, error = None): |
836 | 999 | m = SMB2Message(SMB2CloseRequest(fid)) |
906 | 1069 | messages_history.append(create_message) |
907 | 1070 | if create_message.status == 0: |
908 | 1071 | sendWrite(create_message.tid, create_message.payload.fid, starting_offset) |
909 | elif create_message.status == 0x0103: # STATUS_PENDING | |
910 | self.pending_requests[create_message.mid] = _PendingRequest(create_message.mid, expiry_time, | |
911 | createCB, errback, | |
912 | tid=kwargs['tid']) | |
913 | 1072 | else: |
914 | 1073 | errback(OperationFailure('Failed to store %s on %s: Unable to open file' % ( path, service_name ), messages_history)) |
915 | 1074 | |
921 | 1080 | m = SMB2Message(SMB2WriteRequest(fid, data, offset)) |
922 | 1081 | m.tid = tid |
923 | 1082 | self._sendSMBMessage(m) |
924 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, writeCB, errback, fid = fid, offset = offset+data_len) | |
1083 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, writeCB, errback, tid = tid, fid = fid, offset = offset+data_len) | |
925 | 1084 | else: |
926 | 1085 | closeFid(tid, fid, offset = offset) |
927 | 1086 | |
928 | 1087 | def writeCB(write_message, **kwargs): |
929 | 1088 | # To avoid crazy memory usage when saving large files, we do not save every write_message in messages_history. |
930 | 1089 | if write_message.status == 0: |
931 | sendWrite(write_message.tid, kwargs['fid'], kwargs['offset']) | |
1090 | sendWrite(kwargs['tid'], kwargs['fid'], kwargs['offset']) | |
932 | 1091 | else: |
933 | 1092 | messages_history.append(write_message) |
934 | closeFid(write_message.tid, kwargs['fid']) | |
1093 | closeFid(kwargs['tid'], kwargs['fid']) | |
935 | 1094 | errback(OperationFailure('Failed to store %s on %s: Write failed' % ( path, service_name ), messages_history)) |
936 | 1095 | |
937 | 1096 | def closeFid(tid, fid, error = None, offset = None): |
964 | 1123 | sendCreate(self.connected_trees[service_name]) |
965 | 1124 | |
966 | 1125 | |
967 | def _deleteFiles_SMB2(self, service_name, path_file_pattern, callback, errback, timeout = 30): | |
1126 | def _deleteFiles_SMB2(self, service_name, path_file_pattern, delete_matching_folders, callback, errback, timeout = 30): | |
1127 | if not self.has_authenticated: | |
1128 | raise NotReadyError('SMB connection not authenticated') | |
1129 | ||
1130 | expiry_time = time.time() + timeout | |
1131 | pattern = None | |
1132 | path = path_file_pattern.replace('/', '\\') | |
1133 | if path.startswith('\\'): | |
1134 | path = path[1:] | |
1135 | if path.endswith('\\'): | |
1136 | path = path[:-1] | |
1137 | else: | |
1138 | path_components = path.split('\\') | |
1139 | if path_components[-1].find('*') > -1 or path_components[-1].find('?') > -1: | |
1140 | path = '\\'.join(path_components[:-1]) | |
1141 | pattern = path_components[-1] | |
1142 | messages_history, files_queue = [ ], [ ] | |
1143 | ||
1144 | if pattern is None: | |
1145 | path_components = path.split('\\') | |
1146 | if len(path_components) > 1: | |
1147 | files_queue.append(( '\\'.join(path_components[:-1]), path_components[-1] )) | |
1148 | else: | |
1149 | files_queue.append(( '', path )) | |
1150 | ||
1151 | def deleteCB(path): | |
1152 | if files_queue: | |
1153 | p, filename = files_queue.pop(0) | |
1154 | if filename: | |
1155 | if p: | |
1156 | filename = p + '\\' + filename | |
1157 | self._deleteFiles_SMB2__del(service_name, self.connected_trees[service_name], filename, deleteCB, errback, timeout) | |
1158 | else: | |
1159 | self._deleteDirectory_SMB2(service_name, p, deleteCB, errback, timeout) | |
1160 | else: | |
1161 | callback(path_file_pattern) | |
1162 | ||
1163 | def listCB(files_list): | |
1164 | files_queue.extend(files_list) | |
1165 | deleteCB(None) | |
1166 | ||
1167 | if service_name not in self.connected_trees: | |
1168 | def connectCB(connect_message, **kwargs): | |
1169 | messages_history.append(connect_message) | |
1170 | if connect_message.status == 0: | |
1171 | self.connected_trees[service_name] = connect_message.tid | |
1172 | if files_queue: | |
1173 | deleteCB(None) | |
1174 | else: | |
1175 | self._deleteFiles_SMB2__list(service_name, path, pattern, delete_matching_folders, listCB, errback, timeout) | |
1176 | else: | |
1177 | errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
1178 | ||
1179 | m = SMB2Message(SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ))) | |
1180 | self._sendSMBMessage(m) | |
1181 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name) | |
1182 | messages_history.append(m) | |
1183 | else: | |
1184 | if files_queue: | |
1185 | deleteCB(None) | |
1186 | else: | |
1187 | self._deleteFiles_SMB2__list(service_name, path, pattern, delete_matching_folders, listCB, errback, timeout) | |
1188 | ||
1189 | def _deleteFiles_SMB2__list(self, service_name, path, pattern, delete_matching_folders, callback, errback, timeout = 30): | |
1190 | folder_queue = [ ] | |
1191 | files_list = [ ] | |
1192 | current_path = [ path ] | |
1193 | search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL | |
1194 | ||
1195 | def listCB(results): | |
1196 | files = [ ] | |
1197 | for f in filter(lambda x: x.filename not in [ '.', '..' ], results): | |
1198 | if f.isDirectory: | |
1199 | if delete_matching_folders: | |
1200 | folder_queue.append(current_path[0]+'\\'+f.filename) | |
1201 | else: | |
1202 | files.append(( current_path[0], f.filename )) | |
1203 | if current_path[0]!=path and delete_matching_folders: | |
1204 | files.append(( current_path[0], None )) | |
1205 | ||
1206 | if files: | |
1207 | files_list[0:0] = files | |
1208 | ||
1209 | if folder_queue: | |
1210 | p = folder_queue.pop() | |
1211 | current_path[0] = p | |
1212 | self._listPath_SMB2(service_name, current_path[0], listCB, errback, search = search, pattern = '*', timeout = 30) | |
1213 | else: | |
1214 | callback(files_list) | |
1215 | ||
1216 | self._listPath_SMB2(service_name, path, listCB, errback, search = search, pattern = pattern, timeout = timeout) | |
1217 | ||
1218 | def _deleteFiles_SMB2__del(self, service_name, tid, path, callback, errback, timeout = 30): | |
1219 | messages_history = [ ] | |
1220 | ||
1221 | def sendCreate(tid): | |
1222 | create_context_data = binascii.unhexlify(b""" | |
1223 | 28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00 | |
1224 | 44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00 | |
1225 | 00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00 | |
1226 | 00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00 | |
1227 | 00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00 | |
1228 | 51 46 69 64 00 00 00 00 | |
1229 | """.replace(b' ', b'').replace(b'\n', b'')) | |
1230 | m = SMB2Message(SMB2CreateRequest(path, | |
1231 | file_attributes = 0, | |
1232 | access_mask = DELETE | FILE_READ_ATTRIBUTES, | |
1233 | share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | |
1234 | oplock = SMB2_OPLOCK_LEVEL_NONE, | |
1235 | impersonation = SEC_IMPERSONATE, | |
1236 | create_options = FILE_NON_DIRECTORY_FILE, | |
1237 | create_disp = FILE_OPEN, | |
1238 | create_context_data = create_context_data)) | |
1239 | m.tid = tid | |
1240 | self._sendSMBMessage(m) | |
1241 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid) | |
1242 | messages_history.append(m) | |
1243 | ||
1244 | def createCB(open_message, **kwargs): | |
1245 | open_message.tid = kwargs['tid'] | |
1246 | messages_history.append(open_message) | |
1247 | if open_message.status == 0: | |
1248 | sendDelete(open_message.tid, open_message.payload.fid) | |
1249 | elif open_message.status == 0xc0000034: # STATUS_OBJECT_NAME_NOT_FOUND | |
1250 | callback(path) | |
1251 | elif open_message.status == 0xC00000BA: # [MS-ERREF]: STATUS_FILE_IS_A_DIRECTORY | |
1252 | errback(OperationFailure('Failed to delete %s on %s: Cannot delete a folder. Please use deleteDirectory() method or append "/*" to your path if you wish to delete all files in the folder.' % ( path, service_name ), messages_history)) | |
1253 | else: | |
1254 | errback(OperationFailure('Failed to delete %s on %s: Unable to open file' % ( path, service_name ), messages_history)) | |
1255 | ||
1256 | def sendDelete(tid, fid): | |
1257 | m = SMB2Message(SMB2SetInfoRequest(fid, | |
1258 | additional_info = 0, | |
1259 | info_type = SMB2_INFO_FILE, | |
1260 | file_info_class = 0x0d, # SMB2_FILE_DISPOSITION_INFO | |
1261 | data = b'\x01')) | |
1262 | # [MS-SMB2]: 2.2.39, [MS-FSCC]: 2.4.11 | |
1263 | m.tid = tid | |
1264 | self._sendSMBMessage(m) | |
1265 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback, tid = tid, fid = fid) | |
1266 | messages_history.append(m) | |
1267 | ||
1268 | def deleteCB(delete_message, **kwargs): | |
1269 | messages_history.append(delete_message) | |
1270 | if delete_message.status == 0: | |
1271 | closeFid(kwargs['tid'], kwargs['fid'], status = 0) | |
1272 | else: | |
1273 | closeFid(kwargs['tid'], kwargs['fid'], status = delete_message.status) | |
1274 | ||
1275 | def closeFid(tid, fid, status = None): | |
1276 | m = SMB2Message(SMB2CloseRequest(fid)) | |
1277 | m.tid = tid | |
1278 | self._sendSMBMessage(m) | |
1279 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, closeCB, errback, status = status) | |
1280 | messages_history.append(m) | |
1281 | ||
1282 | def closeCB(close_message, **kwargs): | |
1283 | if kwargs['status'] == 0: | |
1284 | callback(path) | |
1285 | else: | |
1286 | errback(OperationFailure('Failed to delete %s on %s: Delete failed' % ( path, service_name ), messages_history)) | |
1287 | ||
1288 | sendCreate(tid) | |
1289 | ||
1290 | def _resetFileAttributes_SMB2(self, service_name, path_file_pattern, callback, errback, file_attributes = ATTR_NORMAL, timeout = 30): | |
968 | 1291 | if not self.has_authenticated: |
969 | 1292 | raise NotReadyError('SMB connection not authenticated') |
970 | 1293 | |
985 | 1308 | 00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00 |
986 | 1309 | 51 46 69 64 00 00 00 00 |
987 | 1310 | """.replace(b' ', b'').replace(b'\n', b'')) |
988 | m = SMB2Message(SMB2CreateRequest(path, | |
989 | file_attributes = 0, | |
990 | access_mask = DELETE | FILE_READ_ATTRIBUTES, | |
991 | share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | |
992 | oplock = SMB2_OPLOCK_LEVEL_NONE, | |
993 | impersonation = SEC_IMPERSONATE, | |
994 | create_options = FILE_NON_DIRECTORY_FILE, | |
995 | create_disp = FILE_OPEN, | |
996 | create_context_data = create_context_data)) | |
997 | m.tid = tid | |
998 | self._sendSMBMessage(m) | |
999 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid) | |
1000 | messages_history.append(m) | |
1001 | ||
1002 | def createCB(open_message, **kwargs): | |
1003 | open_message.tid = kwargs['tid'] | |
1004 | messages_history.append(open_message) | |
1005 | if open_message.status == 0: | |
1006 | sendDelete(open_message.tid, open_message.payload.fid) | |
1007 | elif open_message.status == 0x0103: # STATUS_PENDING | |
1008 | self.pending_requests[open_message.mid] = _PendingRequest(open_message.mid, expiry_time, | |
1009 | createCB, errback, | |
1010 | tid=kwargs['tid']) | |
1011 | else: | |
1012 | errback(OperationFailure('Failed to delete %s on %s: Unable to open file' % ( path, service_name ), messages_history)) | |
1013 | ||
1014 | def sendDelete(tid, fid): | |
1015 | m = SMB2Message(SMB2SetInfoRequest(fid, | |
1016 | additional_info = 0, | |
1017 | info_type = SMB2_INFO_FILE, | |
1018 | file_info_class = 0x0d, # SMB2_FILE_DISPOSITION_INFO | |
1019 | data = b'\x01')) | |
1020 | ''' | |
1021 | Resources: | |
1022 | https://msdn.microsoft.com/en-us/library/cc246560.aspx | |
1023 | https://msdn.microsoft.com/en-us/library/cc232098.aspx | |
1024 | ''' | |
1025 | m.tid = tid | |
1026 | self._sendSMBMessage(m) | |
1027 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback, fid = fid) | |
1028 | messages_history.append(m) | |
1029 | ||
1030 | def deleteCB(delete_message, **kwargs): | |
1031 | messages_history.append(delete_message) | |
1032 | if delete_message.status == 0: | |
1033 | closeFid(delete_message.tid, kwargs['fid'], status = 0) | |
1034 | else: | |
1035 | closeFid(delete_message.tid, kwargs['fid'], status = delete_message.status) | |
1036 | ||
1037 | def closeFid(tid, fid, status = None): | |
1038 | m = SMB2Message(SMB2CloseRequest(fid)) | |
1039 | m.tid = tid | |
1040 | self._sendSMBMessage(m) | |
1041 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, closeCB, errback, status = status) | |
1042 | messages_history.append(m) | |
1043 | ||
1044 | def closeCB(close_message, **kwargs): | |
1045 | if kwargs['status'] == 0: | |
1046 | callback(path_file_pattern) | |
1047 | else: | |
1048 | errback(OperationFailure('Failed to delete %s on %s: Delete failed' % ( path, service_name ), messages_history)) | |
1049 | ||
1050 | if service_name not in self.connected_trees: | |
1051 | def connectCB(connect_message, **kwargs): | |
1052 | messages_history.append(connect_message) | |
1053 | if connect_message.status == 0: | |
1054 | self.connected_trees[service_name] = connect_message.tid | |
1055 | sendCreate(connect_message.tid) | |
1056 | else: | |
1057 | errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
1058 | ||
1059 | m = SMB2Message(SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ))) | |
1060 | self._sendSMBMessage(m) | |
1061 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name) | |
1062 | messages_history.append(m) | |
1063 | else: | |
1064 | sendCreate(self.connected_trees[service_name]) | |
1065 | ||
1066 | def _resetFileAttributes_SMB2(self, service_name, path_file_pattern, callback, errback, timeout = 30): | |
1067 | if not self.has_authenticated: | |
1068 | raise NotReadyError('SMB connection not authenticated') | |
1069 | ||
1070 | expiry_time = time.time() + timeout | |
1071 | path = path_file_pattern.replace('/', '\\') | |
1072 | if path.startswith('\\'): | |
1073 | path = path[1:] | |
1074 | if path.endswith('\\'): | |
1075 | path = path[:-1] | |
1076 | messages_history = [ ] | |
1077 | ||
1078 | def sendCreate(tid): | |
1079 | create_context_data = binascii.unhexlify(""" | |
1080 | 28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00 | |
1081 | 44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00 | |
1082 | 00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00 | |
1083 | 00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00 | |
1084 | 00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00 | |
1085 | 51 46 69 64 00 00 00 00 | |
1086 | """.replace(' ', '').replace('\n', '')) | |
1087 | 1311 | |
1088 | 1312 | m = SMB2Message(SMB2CreateRequest(path, |
1089 | 1313 | file_attributes = 0, |
1102 | 1326 | def createCB(open_message, **kwargs): |
1103 | 1327 | messages_history.append(open_message) |
1104 | 1328 | if open_message.status == 0: |
1105 | sendReset(open_message.tid, open_message.payload.fid) | |
1329 | sendReset(kwargs['tid'], open_message.payload.fid) | |
1106 | 1330 | else: |
1107 | 1331 | errback(OperationFailure('Failed to reset attributes of %s on %s: Unable to open file' % ( path, service_name ), messages_history)) |
1108 | 1332 | |
1111 | 1335 | additional_info = 0, |
1112 | 1336 | info_type = SMB2_INFO_FILE, |
1113 | 1337 | file_info_class = 4, # FileBasicInformation |
1114 | data = struct.pack('qqqqii',0,0,0,0,0x80,0))) # FILE_ATTRIBUTE_NORMAL | |
1115 | ''' | |
1116 | Resources: | |
1117 | https://msdn.microsoft.com/en-us/library/cc246560.aspx | |
1118 | https://msdn.microsoft.com/en-us/library/cc232064.aspx | |
1119 | https://msdn.microsoft.com/en-us/library/cc232094.aspx | |
1120 | https://msdn.microsoft.com/en-us/library/cc232110.aspx | |
1121 | ''' | |
1122 | m.tid = tid | |
1123 | self._sendSMBMessage(m) | |
1124 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, resetCB, errback, fid = fid) | |
1338 | data = struct.pack('qqqqii', 0, 0, 0, 0, file_attributes, 0))) | |
1339 | # [MS-SMB2]: 2.2.39, [MS-FSCC]: 2.4, [MS-FSCC]: 2.4.7, [MS-FSCC]: 2.6 | |
1340 | m.tid = tid | |
1341 | self._sendSMBMessage(m) | |
1342 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, resetCB, errback, tid = tid, fid = fid) | |
1125 | 1343 | messages_history.append(m) |
1126 | 1344 | |
1127 | 1345 | def resetCB(reset_message, **kwargs): |
1128 | 1346 | messages_history.append(reset_message) |
1129 | 1347 | if reset_message.status == 0: |
1130 | closeFid(reset_message.tid, kwargs['fid'], status = 0) | |
1131 | else: | |
1132 | closeFid(reset_message.tid, kwargs['fid'], status = reset_message.status) | |
1348 | closeFid(kwargs['tid'], kwargs['fid'], status = 0) | |
1349 | else: | |
1350 | closeFid(kwargs['tid'], kwargs['fid'], status = reset_message.status) | |
1133 | 1351 | |
1134 | 1352 | def closeFid(tid, fid, status = None): |
1135 | 1353 | m = SMB2Message(SMB2CloseRequest(fid)) |
1159 | 1377 | messages_history.append(m) |
1160 | 1378 | else: |
1161 | 1379 | sendCreate(self.connected_trees[service_name]) |
1162 | ||
1163 | ||
1164 | 1380 | |
1165 | 1381 | def _createDirectory_SMB2(self, service_name, path, callback, errback, timeout = 30): |
1166 | 1382 | if not self.has_authenticated: |
1194 | 1410 | create_context_data = create_context_data)) |
1195 | 1411 | m.tid = tid |
1196 | 1412 | self._sendSMBMessage(m) |
1197 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback) | |
1413 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid) | |
1198 | 1414 | messages_history.append(m) |
1199 | 1415 | |
1200 | 1416 | def createCB(create_message, **kwargs): |
1201 | 1417 | messages_history.append(create_message) |
1202 | 1418 | if create_message.status == 0: |
1203 | closeFid(create_message.tid, create_message.payload.fid) | |
1419 | closeFid(kwargs['tid'], create_message.payload.fid) | |
1204 | 1420 | else: |
1205 | 1421 | errback(OperationFailure('Failed to create directory %s on %s: Create failed' % ( path, service_name ), messages_history)) |
1206 | 1422 | |
1268 | 1484 | def createCB(open_message, **kwargs): |
1269 | 1485 | messages_history.append(open_message) |
1270 | 1486 | if open_message.status == 0: |
1271 | sendDelete(open_message.tid, open_message.payload.fid) | |
1487 | sendDelete(kwargs['tid'], open_message.payload.fid) | |
1272 | 1488 | else: |
1273 | 1489 | errback(OperationFailure('Failed to delete %s on %s: Unable to open directory' % ( path, service_name ), messages_history)) |
1274 | 1490 | |
1280 | 1496 | data = b'\x01')) |
1281 | 1497 | m.tid = tid |
1282 | 1498 | self._sendSMBMessage(m) |
1283 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback, fid = fid) | |
1499 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback, tid = tid, fid = fid) | |
1284 | 1500 | messages_history.append(m) |
1285 | 1501 | |
1286 | 1502 | def deleteCB(delete_message, **kwargs): |
1287 | 1503 | messages_history.append(delete_message) |
1288 | 1504 | if delete_message.status == 0: |
1289 | closeFid(delete_message.tid, kwargs['fid'], status = 0) | |
1290 | else: | |
1291 | closeFid(delete_message.tid, kwargs['fid'], status = delete_message.status) | |
1505 | closeFid(kwargs['tid'], kwargs['fid'], status = 0) | |
1506 | else: | |
1507 | closeFid(kwargs['tid'], kwargs['fid'], status = delete_message.status) | |
1292 | 1508 | |
1293 | 1509 | def closeFid(tid, fid, status = None): |
1294 | 1510 | m = SMB2Message(SMB2CloseRequest(fid)) |
1364 | 1580 | def createCB(create_message, **kwargs): |
1365 | 1581 | messages_history.append(create_message) |
1366 | 1582 | if create_message.status == 0: |
1367 | sendRename(create_message.tid, create_message.payload.fid) | |
1583 | sendRename(kwargs['tid'], create_message.payload.fid) | |
1368 | 1584 | else: |
1369 | 1585 | errback(OperationFailure('Failed to rename %s on %s: Unable to open file/directory' % ( old_path, service_name ), messages_history)) |
1370 | 1586 | |
1377 | 1593 | data = data)) |
1378 | 1594 | m.tid = tid |
1379 | 1595 | self._sendSMBMessage(m) |
1380 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, renameCB, errback, fid = fid) | |
1596 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, renameCB, errback, tid = tid, fid = fid) | |
1381 | 1597 | messages_history.append(m) |
1382 | 1598 | |
1383 | 1599 | def renameCB(rename_message, **kwargs): |
1384 | 1600 | messages_history.append(rename_message) |
1385 | 1601 | if rename_message.status == 0: |
1386 | closeFid(rename_message.tid, kwargs['fid'], status = 0) | |
1387 | else: | |
1388 | closeFid(rename_message.tid, kwargs['fid'], status = rename_message.status) | |
1602 | closeFid(kwargs['tid'], kwargs['fid'], status = 0) | |
1603 | else: | |
1604 | closeFid(kwargs['tid'], kwargs['fid'], status = rename_message.status) | |
1389 | 1605 | |
1390 | 1606 | def closeFid(tid, fid, status = None): |
1391 | 1607 | m = SMB2Message(SMB2CloseRequest(fid)) |
1452 | 1668 | def createCB(create_message, **kwargs): |
1453 | 1669 | messages_history.append(create_message) |
1454 | 1670 | if create_message.status == 0: |
1455 | sendEnumSnapshots(create_message.tid, create_message.payload.fid) | |
1671 | sendEnumSnapshots(kwargs['tid'], create_message.payload.fid) | |
1456 | 1672 | else: |
1457 | 1673 | errback(OperationFailure('Failed to list snapshots %s on %s: Unable to open file/directory' % ( old_path, service_name ), messages_history)) |
1458 | 1674 | |
1593 | 1809 | self._handleSessionChallenge(message, ntlm_token) |
1594 | 1810 | except ( securityblob.BadSecurityBlobError, securityblob.UnsupportedSecurityProvider ) as ex: |
1595 | 1811 | raise ProtocolError(str(ex), message.raw_data, message) |
1596 | elif message.status.internal_value == 0xc000006d: # STATUS_LOGON_FAILURE | |
1812 | elif (message.status.internal_value == 0xc000006d # STATUS_LOGON_FAILURE | |
1813 | or message.status.internal_value == 0xc0000064 # STATUS_NO_SUCH_USER | |
1814 | or message.status.internal_value == 0xc000006a): # STATUS_WRONG_PASSWORD | |
1597 | 1815 | self.has_authenticated = False |
1598 | self.log.info('Authentication (with extended security) failed. Please check username and password. You may need to enable/disable NTLMv2 authentication.') | |
1816 | self.log.info('Authentication (with extended security) failed. Please check username and password.') | |
1817 | self.onAuthFailed() | |
1818 | elif (message.status.internal_value == 0xc0000193 # STATUS_ACCOUNT_EXPIRED | |
1819 | or message.status.internal_value == 0xC0000071): # STATUS_PASSWORD_EXPIRED | |
1820 | self.has_authenticated = False | |
1821 | self.log.info('Authentication (with extended security) failed. Account or password has expired.') | |
1822 | self.onAuthFailed() | |
1823 | elif message.status.internal_value == 0xc0000234: # STATUS_ACCOUNT_LOCKED_OUT | |
1824 | self.has_authenticated = False | |
1825 | self.log.info('Authentication (with extended security) failed. Account has been locked due to too many invalid logon attempts.') | |
1826 | self.onAuthFailed() | |
1827 | elif message.status.internal_value == 0xc0000072: # STATUS_ACCOUNT_DISABLED | |
1828 | self.has_authenticated = False | |
1829 | self.log.info('Authentication (with extended security) failed. Account has been disabled.') | |
1830 | self.onAuthFailed() | |
1831 | elif (message.status.internal_value == 0xc000006f # STATUS_INVALID_LOGON_HOURS | |
1832 | or message.status.internal_value == 0xc000015b # STATUS_LOGON_TYPE_NOT_GRANTED | |
1833 | or message.status.internal_value == 0xc0000070): # STATUS_INVALID_WORKSTATION | |
1834 | self.has_authenticated = False | |
1835 | self.log.info('Authentication (with extended security) failed. Not allowed.') | |
1836 | self.onAuthFailed() | |
1837 | elif message.status.internal_value == 0xc000018c: # STATUS_TRUSTED_DOMAIN_FAILURE | |
1838 | self.has_authenticated = False | |
1839 | self.log.info('Authentication (with extended security) failed. Domain not trusted.') | |
1840 | self.onAuthFailed() | |
1841 | elif message.status.internal_value == 0xc000018d: # STATUS_TRUSTED_RELATIONSHIP_FAILURE | |
1842 | self.has_authenticated = False | |
1843 | self.log.info('Authentication (with extended security) failed. Workstation not trusted.') | |
1599 | 1844 | self.onAuthFailed() |
1600 | 1845 | else: |
1601 | 1846 | raise ProtocolError('Unknown status value (0x%08X) in SMB_COM_SESSION_SETUP_ANDX (with extended security)' % message.status.internal_value, |
1657 | 1902 | self.log.info('Performing NTLMv1 authentication (with extended security) with server challenge "%s"', binascii.hexlify(server_challenge)) |
1658 | 1903 | nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV1(self.password, server_challenge, True) |
1659 | 1904 | |
1660 | ntlm_data = ntlm.generateAuthenticateMessage(server_flags, | |
1661 | nt_challenge_response, | |
1662 | lm_challenge_response, | |
1663 | session_key, | |
1664 | self.username, | |
1665 | self.domain) | |
1905 | ntlm_data, signing_session_key = ntlm.generateAuthenticateMessage(server_flags, | |
1906 | nt_challenge_response, | |
1907 | lm_challenge_response, | |
1908 | session_key, | |
1909 | self.username, | |
1910 | self.domain, | |
1911 | self.my_name) | |
1666 | 1912 | |
1667 | 1913 | if self.log.isEnabledFor(logging.DEBUG): |
1668 | 1914 | self.log.debug('NT challenge response is "%s" (%d bytes)', binascii.hexlify(nt_challenge_response), len(nt_challenge_response)) |
1682 | 1928 | |
1683 | 1929 | if self.is_signing_active: |
1684 | 1930 | self.log.info("SMB signing activated. All SMB messages will be signed.") |
1685 | self.signing_session_key = session_key | |
1931 | self.signing_session_key = signing_session_key | |
1686 | 1932 | if self.capabilities & CAP_EXTENDED_SECURITY: |
1687 | 1933 | self.signing_challenge_response = None |
1688 | 1934 | else: |
1856 | 2102 | def readCB(read_message, **kwargs): |
1857 | 2103 | messages_history.append(read_message) |
1858 | 2104 | if not read_message.status.hasError: |
1859 | data_len = read_message.payload.data_length | |
1860 | 2105 | data_bytes = read_message.payload.data |
1861 | 2106 | |
1862 | 2107 | if data_bytes[3] & 0x02 == 0: |
1863 | sendReadRequest(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:data_len-24]) | |
1864 | else: | |
1865 | decodeResults(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:data_len-24]) | |
2108 | sendReadRequest(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:]) | |
2109 | else: | |
2110 | decodeResults(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:]) | |
1866 | 2111 | else: |
1867 | 2112 | closeFid(read_message.tid, kwargs['fid']) |
1868 | 2113 | errback(OperationFailure('Failed to list shares: Unable to retrieve shared device list', messages_history)) |
1901 | 2146 | setup_bytes = struct.pack('<H', 0x0001) # TRANS2_FIND_FIRST2 sub-command. See [MS-CIFS]: 2.2.6.2.1 |
1902 | 2147 | params_bytes = \ |
1903 | 2148 | struct.pack('<HHHHI', |
1904 | search, # SearchAttributes | |
2149 | search & 0xFFFF, # SearchAttributes (need to restrict the values due to introduction of SMB_FILE_ATTRIBUTE_INCL_NORMAL) | |
1905 | 2150 | 100, # SearchCount |
1906 | 2151 | 0x0006, # Flags: SMB_FIND_CLOSE_AT_EOS | SMB_FIND_RETURN_RESUME_KEYS |
1907 | 2152 | 0x0104, # InfoLevel: SMB_FIND_FILE_BOTH_DIRECTORY_INFO |
1908 | 0x0000) # SearchStorageType | |
2153 | 0x0000) # SearchStorageType (seems to be ignored by Windows) | |
1909 | 2154 | if support_dfs: |
1910 | 2155 | params_bytes += ("\\" + self.remote_name + "\\" + service_name + path + pattern + '\0').encode('UTF-16LE') |
1911 | 2156 | else: |
1912 | params_bytes += (path + pattern).encode('UTF-16LE') | |
2157 | params_bytes += (path + pattern + '\0').encode('UTF-16LE') | |
1913 | 2158 | |
1914 | 2159 | m = SMBMessage(ComTransaction2Request(max_params_count = 10, |
1915 | 2160 | max_data_count = 16644, |
1945 | 2190 | |
1946 | 2191 | filename = data_bytes[offset2:offset2+filename_length].decode('UTF-16LE') |
1947 | 2192 | short_name = short_name.decode('UTF-16LE') |
1948 | results.append(SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time), | |
1949 | convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time), | |
1950 | file_size, alloc_size, file_attributes, short_name, filename)) | |
2193 | ||
2194 | accept_result = False | |
2195 | if (file_attributes & 0xff) in ( 0x00, ATTR_NORMAL ): # Only the first 8-bits are compared. We ignore other bits like temp, compressed, encryption, sparse, indexed, etc | |
2196 | accept_result = (search == SMB_FILE_ATTRIBUTE_NORMAL) or (search & SMB_FILE_ATTRIBUTE_INCL_NORMAL) | |
2197 | else: | |
2198 | accept_result = (file_attributes & search) > 0 | |
2199 | if accept_result: | |
2200 | results.append(SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time), | |
2201 | convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time), | |
2202 | file_size, alloc_size, file_attributes, short_name, filename)) | |
1951 | 2203 | |
1952 | 2204 | if next_offset: |
1953 | 2205 | offset += next_offset |
1987 | 2239 | elif end_of_search: |
1988 | 2240 | callback(results) |
1989 | 2241 | else: |
1990 | sendFindNext(find_message.tid, sid, last_name_offset, kwargs.get('support_dfs', False)) | |
1991 | else: | |
1992 | errback(OperationFailure('Failed to list %s on %s: Unable to retrieve file list' % ( path, service_name ), messages_history)) | |
1993 | ||
1994 | def sendFindNext(tid, sid, resume_key, support_dfs=False): | |
2242 | sendFindNext(find_message.tid, sid, 0, results[-1].filename, kwargs.get('support_dfs', False)) | |
2243 | else: | |
2244 | if find_message.status.internal_value == 0xC000000F: # [MS-ERREF]: STATUS_NO_SUCH_FILE | |
2245 | # Remote server returns STATUS_NO_SUCH_FILE error so we assume that the search returns no matching files | |
2246 | callback([ ]) | |
2247 | else: | |
2248 | errback(OperationFailure('Failed to list %s on %s: Unable to retrieve file list' % ( path, service_name ), messages_history)) | |
2249 | ||
2250 | def sendFindNext(tid, sid, resume_key, resume_file, support_dfs): | |
1995 | 2251 | setup_bytes = struct.pack('<H', 0x0002) # TRANS2_FIND_NEXT2 sub-command. See [MS-CIFS]: 2.2.6.3.1 |
1996 | 2252 | params_bytes = \ |
1997 | 2253 | struct.pack('<HHHIH', |
1999 | 2255 | 100, # SearchCount |
2000 | 2256 | 0x0104, # InfoLevel: SMB_FIND_FILE_BOTH_DIRECTORY_INFO |
2001 | 2257 | resume_key, # ResumeKey |
2002 | 0x000a) # Flags: SMB_FIND_RETURN_RESUME_KEYS | SMB_FIND_CLOSE_AT_EOS | SMB_FIND_RETURN_RESUME_KEYS | |
2003 | if support_dfs: | |
2004 | params_bytes += ("\\" + self.remote_name + "\\" + service_name + path + pattern + '\0').encode('UTF-16LE') | |
2005 | else: | |
2006 | params_bytes += (path + pattern).encode('UTF-16LE') | |
2258 | 0x0006) # Flags: SMB_FIND_RETURN_RESUME_KEYS | SMB_FIND_CLOSE_AT_EOS | |
2259 | params_bytes += (resume_file+'\0').encode('UTF-16LE') | |
2007 | 2260 | |
2008 | 2261 | m = SMBMessage(ComTransaction2Request(max_params_count = 10, |
2009 | 2262 | max_data_count = 16644, |
2049 | 2302 | elif end_of_search: |
2050 | 2303 | callback(results) |
2051 | 2304 | else: |
2052 | sendFindNext(find_message.tid, kwargs['sid'], last_name_offset, kwargs.get('support_dfs', False)) | |
2305 | sendFindNext(find_message.tid, kwargs['sid'], 0, results[-1].filename, kwargs.get('support_dfs', False)) | |
2053 | 2306 | else: |
2054 | 2307 | errback(OperationFailure('Failed to list %s on %s: Unable to retrieve file list' % ( path, service_name ), messages_history)) |
2055 | 2308 | |
2127 | 2380 | info_size = struct.calcsize(info_format) |
2128 | 2381 | create_time, last_access_time, last_write_time, last_attr_change_time, \ |
2129 | 2382 | file_attributes, _, alloc_size, file_size = struct.unpack(info_format, query_message.payload.data_bytes[:info_size]) |
2130 | ||
2131 | info = SharedFile(create_time, last_access_time, last_write_time, last_attr_change_time, | |
2132 | file_size, alloc_size, file_attributes, path, path) | |
2383 | filename = self._extractLastPathComponent(path) | |
2384 | ||
2385 | info = SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time), convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time), | |
2386 | file_size, alloc_size, file_attributes, filename, filename) | |
2133 | 2387 | callback(info) |
2134 | 2388 | else: |
2135 | 2389 | errback(OperationFailure('Failed to get attributes for %s on %s: Read failed' % ( path, service_name ), messages_history)) |
2149 | 2403 | messages_history.append(m) |
2150 | 2404 | else: |
2151 | 2405 | sendQuery(self.connected_trees[service_name]) |
2406 | ||
2407 | def _getSecurity_SMB1(self, service_name, path_file_pattern, callback, errback, timeout = 30): | |
2408 | raise NotReadyError('getSecurity is not yet implemented for SMB1') | |
2152 | 2409 | |
2153 | 2410 | def _retrieveFile_SMB1(self, service_name, path, file_obj, callback, errback, timeout = 30): |
2154 | 2411 | return self._retrieveFileFromOffset(service_name, path, file_obj, callback, errback, 0, -1, timeout) |
2273 | 2530 | errback(OperationFailure('Failed to store %s on %s: Unable to open file' % ( path, service_name ), messages_history)) |
2274 | 2531 | |
2275 | 2532 | def sendWrite(tid, fid, offset): |
2276 | # For message signing, the total SMB message size must be not exceed the max_buffer_size. Non-message signing does not have this limitation | |
2277 | write_count = min((self.is_signing_active and (self.max_buffer_size-64)) or self.max_raw_size, 0xFFFF-1) # Need to minus 1 byte from 0xFFFF because of the first NULL byte in the ComWriteAndxRequest message data | |
2533 | # [MS-SMB] 2.2.4.5.2.2: The total SMB message size (inclusive of SMB header) must be not exceed the max_buffer_size. | |
2534 | write_count = min(self.max_buffer_size-64, 0xFFFF-64) # SMB header is 32-bytes. We factor in another 32-bytes for the message parameter block | |
2278 | 2535 | data_bytes = file_obj.read(write_count) |
2279 | 2536 | data_len = len(data_bytes) |
2280 | 2537 | if data_len > 0: |
2317 | 2574 | else: |
2318 | 2575 | sendOpen(self.connected_trees[service_name]) |
2319 | 2576 | |
2320 | def _deleteFiles_SMB1(self, service_name, path_file_pattern, callback, errback, timeout = 30): | |
2577 | def _deleteFiles_SMB1(self, service_name, path_file_pattern, delete_matching_folders, callback, errback, timeout = 30): | |
2321 | 2578 | if not self.has_authenticated: |
2322 | 2579 | raise NotReadyError('SMB connection not authenticated') |
2323 | 2580 | |
2581 | expiry_time = time.time() + timeout | |
2582 | pattern = None | |
2324 | 2583 | path = path_file_pattern.replace('/', '\\') |
2584 | if path.startswith('\\'): | |
2585 | path = path[1:] | |
2586 | if path.endswith('\\'): | |
2587 | path = path[:-1] | |
2588 | else: | |
2589 | path_components = path.split('\\') | |
2590 | if path_components[-1].find('*') > -1 or path_components[-1].find('?') > -1: | |
2591 | path = '\\'.join(path_components[:-1]) | |
2592 | pattern = path_components[-1] | |
2593 | messages_history, files_queue = [ ], [ ] | |
2594 | ||
2595 | if pattern is None: | |
2596 | path_components = path.split('\\') | |
2597 | if len(path_components) > 1: | |
2598 | files_queue.append(( '\\'.join(path_components[:-1]), path_components[-1] )) | |
2599 | else: | |
2600 | files_queue.append(( '', path )) | |
2601 | ||
2602 | def deleteCB(path): | |
2603 | if files_queue: | |
2604 | p, filename = files_queue.pop(0) | |
2605 | if filename: | |
2606 | if p: | |
2607 | filename = p + '\\' + filename | |
2608 | self._deleteFiles_SMB1__del(service_name, self.connected_trees[service_name], filename, deleteCB, errback, timeout) | |
2609 | else: | |
2610 | self._deleteDirectory_SMB1(service_name, p, deleteCB, errback, timeout = 30) | |
2611 | else: | |
2612 | callback(path_file_pattern) | |
2613 | ||
2614 | def listCB(files_list): | |
2615 | files_queue.extend(files_list) | |
2616 | deleteCB(None) | |
2617 | ||
2618 | if service_name not in self.connected_trees: | |
2619 | def connectCB(connect_message, **kwargs): | |
2620 | messages_history.append(connect_message) | |
2621 | if not connect_message.status.hasError: | |
2622 | self.connected_trees[service_name] = connect_message.tid | |
2623 | if files_queue: | |
2624 | deleteCB(None) | |
2625 | else: | |
2626 | self._deleteFiles_SMB1__list(service_name, path, pattern, delete_matching_folders, listCB, errback, timeout) | |
2627 | else: | |
2628 | errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
2629 | ||
2630 | m = SMBMessage(ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, '')) | |
2631 | self._sendSMBMessage(m) | |
2632 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name) | |
2633 | messages_history.append(m) | |
2634 | else: | |
2635 | if files_queue: | |
2636 | deleteCB(None) | |
2637 | else: | |
2638 | self._deleteFiles_SMB1__list(service_name, path, pattern, delete_matching_folders, listCB, errback, timeout) | |
2639 | ||
2640 | def _deleteFiles_SMB1__list(self, service_name, path, pattern, delete_matching_folders, callback, errback, timeout = 30): | |
2641 | folder_queue = [ ] | |
2642 | files_list = [ ] | |
2643 | current_path = [ path ] | |
2644 | search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL | |
2645 | ||
2646 | def listCB(results): | |
2647 | files = [ ] | |
2648 | for f in filter(lambda x: x.filename not in [ '.', '..' ], results): | |
2649 | if f.isDirectory: | |
2650 | if delete_matching_folders: | |
2651 | folder_queue.append(current_path[0]+'\\'+f.filename) | |
2652 | else: | |
2653 | files.append(( current_path[0], f.filename )) | |
2654 | if current_path[0]!=path and delete_matching_folders: | |
2655 | files.append(( current_path[0], None )) | |
2656 | ||
2657 | if files: | |
2658 | files_list[0:0] = files | |
2659 | ||
2660 | if folder_queue: | |
2661 | p = folder_queue.pop() | |
2662 | current_path[0] = p | |
2663 | self._listPath_SMB1(service_name, current_path[0], listCB, errback, search = search, pattern = '*', timeout = 30) | |
2664 | else: | |
2665 | callback(files_list) | |
2666 | ||
2667 | self._listPath_SMB1(service_name, path, listCB, errback, search = search, pattern = pattern, timeout = timeout) | |
2668 | ||
2669 | def _deleteFiles_SMB1__del(self, service_name, tid, path, callback, errback, timeout = 30): | |
2325 | 2670 | messages_history = [ ] |
2326 | 2671 | |
2327 | 2672 | def sendDelete(tid): |
2335 | 2680 | def deleteCB(delete_message, **kwargs): |
2336 | 2681 | messages_history.append(delete_message) |
2337 | 2682 | if not delete_message.status.hasError: |
2683 | callback(path) | |
2684 | elif delete_message.status.internal_value == 0xC000000F: # [MS-ERREF]: STATUS_NO_SUCH_FILE | |
2685 | # If there are no matching files, we just treat as success instead of failing | |
2338 | 2686 | callback(path_file_pattern) |
2339 | else: | |
2340 | errback(OperationFailure('Failed to store %s on %s: Delete failed' % ( path, service_name ), messages_history)) | |
2687 | elif delete_message.status.internal_value == 0xC00000BA: # [MS-ERREF]: STATUS_FILE_IS_A_DIRECTORY | |
2688 | errback(OperationFailure('Failed to delete %s on %s: Cannot delete a folder. Please use deleteDirectory() method or append "/*" to your path if you wish to delete all files in the folder.' % ( path, service_name ), messages_history)) | |
2689 | elif delete_message.status.internal_value == 0xC0000034: # [MS-ERREF]: STATUS_OBJECT_NAME_INVALID | |
2690 | errback(OperationFailure('Failed to delete %s on %s: Path not found' % ( path, service_name ), messages_history)) | |
2691 | else: | |
2692 | errback(OperationFailure('Failed to delete %s on %s: Delete failed' % ( path, service_name ), messages_history)) | |
2693 | ||
2694 | sendDelete(tid) | |
2695 | ||
2696 | def _resetFileAttributes_SMB1(self, service_name, path_file_pattern, callback, errback, file_attributes=ATTR_NORMAL, timeout = 30): | |
2697 | raise NotReadyError('resetFileAttributes is not yet implemented for SMB1') | |
2698 | ||
2699 | def _createDirectory_SMB1(self, service_name, path, callback, errback, timeout = 30): | |
2700 | if not self.has_authenticated: | |
2701 | raise NotReadyError('SMB connection not authenticated') | |
2702 | ||
2703 | path = path.replace('/', '\\') | |
2704 | messages_history = [ ] | |
2705 | ||
2706 | def sendCreate(tid): | |
2707 | m = SMBMessage(ComCreateDirectoryRequest(path)) | |
2708 | m.tid = tid | |
2709 | self._sendSMBMessage(m) | |
2710 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback) | |
2711 | messages_history.append(m) | |
2712 | ||
2713 | def createCB(create_message, **kwargs): | |
2714 | messages_history.append(create_message) | |
2715 | if not create_message.status.hasError: | |
2716 | callback(path) | |
2717 | else: | |
2718 | errback(OperationFailure('Failed to create directory %s on %s: Create failed' % ( path, service_name ), messages_history)) | |
2719 | ||
2720 | if service_name not in self.connected_trees: | |
2721 | def connectCB(connect_message, **kwargs): | |
2722 | messages_history.append(connect_message) | |
2723 | if not connect_message.status.hasError: | |
2724 | self.connected_trees[service_name] = connect_message.tid | |
2725 | sendCreate(connect_message.tid) | |
2726 | else: | |
2727 | errback(OperationFailure('Failed to create directory %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
2728 | ||
2729 | m = SMBMessage(ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, '')) | |
2730 | self._sendSMBMessage(m) | |
2731 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name) | |
2732 | messages_history.append(m) | |
2733 | else: | |
2734 | sendCreate(self.connected_trees[service_name]) | |
2735 | ||
2736 | def _deleteDirectory_SMB1(self, service_name, path, callback, errback, timeout = 30): | |
2737 | if not self.has_authenticated: | |
2738 | raise NotReadyError('SMB connection not authenticated') | |
2739 | ||
2740 | path = path.replace('/', '\\') | |
2741 | messages_history = [ ] | |
2742 | ||
2743 | def sendDelete(tid): | |
2744 | m = SMBMessage(ComDeleteDirectoryRequest(path)) | |
2745 | m.tid = tid | |
2746 | self._sendSMBMessage(m) | |
2747 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback) | |
2748 | messages_history.append(m) | |
2749 | ||
2750 | def deleteCB(delete_message, **kwargs): | |
2751 | messages_history.append(delete_message) | |
2752 | if not delete_message.status.hasError: | |
2753 | callback(path) | |
2754 | else: | |
2755 | errback(OperationFailure('Failed to delete directory %s on %s: Delete failed' % ( path, service_name ), messages_history)) | |
2341 | 2756 | |
2342 | 2757 | if service_name not in self.connected_trees: |
2343 | 2758 | def connectCB(connect_message, **kwargs): |
2346 | 2761 | self.connected_trees[service_name] = connect_message.tid |
2347 | 2762 | sendDelete(connect_message.tid) |
2348 | 2763 | else: |
2349 | errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
2350 | ||
2351 | m = SMBMessage(ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, '')) | |
2352 | self._sendSMBMessage(m) | |
2353 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name) | |
2354 | messages_history.append(m) | |
2355 | else: | |
2356 | sendDelete(self.connected_trees[service_name]) | |
2357 | ||
2358 | def _resetFileAttributes_SMB1(self, service_name, path_file_pattern, callback, errback, timeout = 30): | |
2359 | raise NotReadyError('resetFileAttributes is not yet implemented for SMB1') | |
2360 | ||
2361 | def _createDirectory_SMB1(self, service_name, path, callback, errback, timeout = 30): | |
2362 | if not self.has_authenticated: | |
2363 | raise NotReadyError('SMB connection not authenticated') | |
2364 | ||
2365 | path = path.replace('/', '\\') | |
2366 | messages_history = [ ] | |
2367 | ||
2368 | def sendCreate(tid): | |
2369 | m = SMBMessage(ComCreateDirectoryRequest(path)) | |
2370 | m.tid = tid | |
2371 | self._sendSMBMessage(m) | |
2372 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback) | |
2373 | messages_history.append(m) | |
2374 | ||
2375 | def createCB(create_message, **kwargs): | |
2376 | messages_history.append(create_message) | |
2377 | if not create_message.status.hasError: | |
2378 | callback(path) | |
2379 | else: | |
2380 | errback(OperationFailure('Failed to create directory %s on %s: Create failed' % ( path, service_name ), messages_history)) | |
2381 | ||
2382 | if service_name not in self.connected_trees: | |
2383 | def connectCB(connect_message, **kwargs): | |
2384 | messages_history.append(connect_message) | |
2385 | if not connect_message.status.hasError: | |
2386 | self.connected_trees[service_name] = connect_message.tid | |
2387 | sendCreate(connect_message.tid) | |
2388 | else: | |
2389 | errback(OperationFailure('Failed to create directory %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
2390 | ||
2391 | m = SMBMessage(ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, '')) | |
2392 | self._sendSMBMessage(m) | |
2393 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name) | |
2394 | messages_history.append(m) | |
2395 | else: | |
2396 | sendCreate(self.connected_trees[service_name]) | |
2397 | ||
2398 | def _deleteDirectory_SMB1(self, service_name, path, callback, errback, timeout = 30): | |
2399 | if not self.has_authenticated: | |
2400 | raise NotReadyError('SMB connection not authenticated') | |
2401 | ||
2402 | path = path.replace('/', '\\') | |
2403 | messages_history = [ ] | |
2404 | ||
2405 | def sendDelete(tid): | |
2406 | m = SMBMessage(ComDeleteDirectoryRequest(path)) | |
2407 | m.tid = tid | |
2408 | self._sendSMBMessage(m) | |
2409 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback) | |
2410 | messages_history.append(m) | |
2411 | ||
2412 | def deleteCB(delete_message, **kwargs): | |
2413 | messages_history.append(delete_message) | |
2414 | if not delete_message.status.hasError: | |
2415 | callback(path) | |
2416 | else: | |
2417 | errback(OperationFailure('Failed to delete directory %s on %s: Delete failed' % ( path, service_name ), messages_history)) | |
2418 | ||
2419 | if service_name not in self.connected_trees: | |
2420 | def connectCB(connect_message, **kwargs): | |
2421 | messages_history.append(connect_message) | |
2422 | if not connect_message.status.hasError: | |
2423 | self.connected_trees[service_name] = connect_message.tid | |
2424 | sendDelete(connect_message.tid) | |
2425 | else: | |
2426 | errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
2764 | errback(OperationFailure('Failed to delete directory %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history)) | |
2427 | 2765 | |
2428 | 2766 | m = SMBMessage(ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, '')) |
2429 | 2767 | self._sendSMBMessage(m) |
2558 | 2896 | def _echo_SMB1(self, data, callback, errback, timeout = 30): |
2559 | 2897 | messages_history = [ ] |
2560 | 2898 | |
2899 | if not isinstance(data, type(b'')): | |
2900 | raise TypeError('Echo data must be %s not %s' % (type(b'').__name__, type(data).__name__)) | |
2901 | ||
2561 | 2902 | def echoCB(echo_message, **kwargs): |
2562 | 2903 | messages_history.append(echo_message) |
2563 | 2904 | if not echo_message.status.hasError: |
2570 | 2911 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, echoCB, errback) |
2571 | 2912 | messages_history.append(m) |
2572 | 2913 | |
2914 | def _extractLastPathComponent(self, path): | |
2915 | return path.replace('\\', '/').split('/')[-1] | |
2916 | ||
2573 | 2917 | |
2574 | 2918 | class SharedDevice: |
2575 | 2919 | """ |
2576 | 2920 | Contains information about a single shared device on the remote server. |
2921 | ||
2922 | The following attributes are available: | |
2923 | ||
2924 | * name : An unicode string containing the name of the shared device | |
2925 | * comments : An unicode string containing the user description of the shared device | |
2577 | 2926 | """ |
2578 | 2927 | |
2579 | 2928 | # The following constants are taken from [MS-SRVS]: 2.2.2.4 |
2628 | 2977 | |
2629 | 2978 | If you encounter *SharedFile* instance where its short_name attribute is empty but the filename attribute contains a short name which does not correspond |
2630 | 2979 | to any files/folders on your remote shared device, it could be that the original filename on the file/folder entry on the shared device contains |
2631 | one of these prohibited characters: "\/[]:+|<>=;?,* (see [MS-CIFS]: 2.2.1.1.1 for more details). | |
2980 | one of these prohibited characters: "\\/[]:+|<>=;?,* (see [MS-CIFS]: 2.2.1.1.1 for more details). | |
2981 | ||
2982 | The following attributes are available: | |
2983 | ||
2984 | * create_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of creation of this file resource on the remote server | |
2985 | * last_access_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last access of this file resource on the remote server | |
2986 | * last_write_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last modification of this file resource on the remote server | |
2987 | * last_attr_change_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last attribute change of this file resource on the remote server | |
2988 | * file_size : File size in number of bytes | |
2989 | * alloc_size : Total number of bytes allocated to store this file | |
2990 | * file_attributes : A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3. You can perform bit-wise tests to determine the status of the file using the ATTR_xxx constants in smb_constants.py. | |
2991 | * short_name : Unicode string containing the short name of this file (usually in 8.3 notation) | |
2992 | * filename : Unicode string containing the long filename of this file. Each OS has a limit to the length of this file name. On Windows, it is 256 characters. | |
2993 | * file_id : Long value representing the file reference number for the file. If the remote system does not support this field, this field will be None or 0. See [MS-FSCC]: 2.4.17 | |
2632 | 2994 | """ |
2633 | 2995 | |
2634 | def __init__(self, create_time, last_access_time, last_write_time, last_attr_change_time, file_size, alloc_size, file_attributes, short_name, filename): | |
2996 | def __init__(self, create_time, last_access_time, last_write_time, last_attr_change_time, file_size, alloc_size, file_attributes, short_name, filename, file_id=None): | |
2635 | 2997 | self.create_time = create_time #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of creation of this file resource on the remote server |
2636 | 2998 | self.last_access_time = last_access_time #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last access of this file resource on the remote server |
2637 | 2999 | self.last_write_time = last_write_time #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last modification of this file resource on the remote server |
2638 | 3000 | self.last_attr_change_time = last_attr_change_time #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last attribute change of this file resource on the remote server |
2639 | 3001 | self.file_size = file_size #: File size in number of bytes |
2640 | 3002 | self.alloc_size = alloc_size #: Total number of bytes allocated to store this file |
2641 | self.file_attributes = file_attributes #: A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3 | |
3003 | self.file_attributes = file_attributes #: A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3. You can perform bit-wise tests to determine the status of the file using the ATTR_xxx constants in smb_constants.py. | |
2642 | 3004 | self.short_name = short_name #: Unicode string containing the short name of this file (usually in 8.3 notation) |
2643 | 3005 | self.filename = filename #: Unicode string containing the long filename of this file. Each OS has a limit to the length of this file name. On Windows, it is 256 characters. |
3006 | self.file_id = file_id #: Long value representing the file reference number for the file. If the remote system does not support this field, this field will be None or 0. See [MS-FSCC]: 2.4.17 | |
2644 | 3007 | |
2645 | 3008 | @property |
2646 | 3009 | def isDirectory(self): |
2651 | 3014 | def isReadOnly(self): |
2652 | 3015 | """A convenient property to return True if this file resource is read-only on the remote server""" |
2653 | 3016 | return bool(self.file_attributes & ATTR_READONLY) |
3017 | ||
3018 | @property | |
3019 | def isNormal(self): | |
3020 | """ | |
3021 | A convenient property to return True if this is a normal file. | |
3022 | ||
3023 | Note that pysmb defines a normal file as a file entry that is not read-only, not hidden, not system, not archive and not a directory. | |
3024 | It ignores other attributes like compression, indexed, sparse, temporary and encryption. | |
3025 | """ | |
3026 | return (self.file_attributes==ATTR_NORMAL) or ((self.file_attributes & 0xff)==0) | |
2654 | 3027 | |
2655 | 3028 | def __unicode__(self): |
2656 | 3029 | return 'Shared file: %s (FileSize:%d bytes, isDirectory:%s)' % ( self.filename, self.file_size, self.isDirectory ) |
0 | 0 | |
1 | import types, hmac, binascii, struct, random | |
1 | import types, hmac, binascii, struct, random, string | |
2 | from .utils.rc4 import RC4_encrypt | |
2 | 3 | from .utils.pyDes import des |
3 | 4 | |
4 | 5 | try: |
57 | 58 | |
58 | 59 | NTLM_FLAGS = NTLM_NegotiateUnicode | \ |
59 | 60 | NTLM_RequestTarget | \ |
61 | NTLM_NegotiateSign | \ | |
60 | 62 | NTLM_NegotiateNTLM | \ |
61 | 63 | NTLM_NegotiateAlwaysSign | \ |
62 | 64 | NTLM_NegotiateExtendedSecurity | \ |
63 | 65 | NTLM_NegotiateTargetInfo | \ |
64 | 66 | NTLM_NegotiateVersion | \ |
65 | 67 | NTLM_Negotiate128 | \ |
66 | NTLM_NegotiateKeyExchange | \ | |
67 | NTLM_Negotiate56 | |
68 | NTLM_NegotiateKeyExchange | |
68 | 69 | |
69 | 70 | def generateNegotiateMessage(): |
70 | 71 | """ |
80 | 81 | return s |
81 | 82 | |
82 | 83 | |
83 | def generateAuthenticateMessage(challenge_flags, nt_response, lm_response, session_key, user, domain = 'WORKGROUP', workstation = 'LOCALHOST'): | |
84 | def generateAuthenticateMessage(challenge_flags, nt_response, lm_response, request_session_key, user, domain = 'WORKGROUP', workstation = 'LOCALHOST'): | |
84 | 85 | """ |
85 | 86 | References: |
86 | 87 | =========== |
88 | 89 | """ |
89 | 90 | FORMAT = '<8sIHHIHHIHHIHHIHHIHHII' |
90 | 91 | FORMAT_SIZE = struct.calcsize(FORMAT) |
92 | ||
93 | # [MS-NLMP]: 3.1.5.1.2 | |
94 | # http://grutz.jingojango.net/exploits/davenport-ntlm.html | |
95 | session_key = session_signing_key = request_session_key | |
96 | if challenge_flags & NTLM_NegotiateKeyExchange: | |
97 | session_signing_key = "".join([ random.choice(string.digits+string.ascii_letters) for _ in range(16) ]).encode('ascii') | |
98 | session_key = RC4_encrypt(request_session_key, session_signing_key) | |
91 | 99 | |
92 | 100 | lm_response_length = len(lm_response) |
93 | 101 | lm_response_offset = FORMAT_SIZE |
124 | 132 | session_key_length, session_key_length, session_key_offset, |
125 | 133 | auth_flags) |
126 | 134 | |
127 | return s + lm_response + nt_response + padding + domain_unicode + user_unicode + workstation_unicode + session_key | |
135 | return s + lm_response + nt_response + padding + domain_unicode + user_unicode + workstation_unicode + session_key, session_signing_key | |
128 | 136 | |
129 | 137 | |
130 | 138 | def decodeChallengeMessage(ntlm_data): |
160 | 168 | d = MD4() |
161 | 169 | d.update(password.encode('UTF-16LE')) |
162 | 170 | ntlm_hash = d.digest() # The NT password hash |
163 | response_key = hmac.new(ntlm_hash, (user.upper() + domain).encode('UTF-16LE')).digest() # The NTLMv2 password hash. In [MS-NLMP], this is the result of NTOWFv2 and LMOWFv2 functions | |
171 | response_key = hmac.new(ntlm_hash, (user.upper() + domain).encode('UTF-16LE'), 'md5').digest() # The NTLMv2 password hash. In [MS-NLMP], this is the result of NTOWFv2 and LMOWFv2 functions | |
164 | 172 | temp = b'\x01\x01' + b'\0'*6 + client_timestamp + client_challenge + b'\0'*4 + server_info |
165 | ntproofstr = hmac.new(response_key, server_challenge + temp).digest() | |
173 | ntproofstr = hmac.new(response_key, server_challenge + temp, 'md5').digest() | |
166 | 174 | |
167 | 175 | nt_challenge_response = ntproofstr + temp |
168 | lm_challenge_response = hmac.new(response_key, server_challenge + client_challenge).digest() + client_challenge | |
169 | session_key = hmac.new(response_key, ntproofstr).digest() | |
176 | lm_challenge_response = hmac.new(response_key, server_challenge + client_challenge, 'md5').digest() + client_challenge | |
177 | session_key = hmac.new(response_key, ntproofstr, 'md5').digest() | |
170 | 178 | |
171 | 179 | return nt_challenge_response, lm_challenge_response, session_key |
172 | 180 |
0 | """ | |
1 | This module implements security descriptors, and the partial structures | |
2 | used in them, as specified in [MS-DTYP]. | |
3 | """ | |
4 | ||
5 | import struct | |
6 | ||
7 | ||
8 | # Security descriptor control flags | |
9 | # [MS-DTYP]: 2.4.6 | |
10 | SECURITY_DESCRIPTOR_OWNER_DEFAULTED = 0x0001 | |
11 | SECURITY_DESCRIPTOR_GROUP_DEFAULTED = 0x0002 | |
12 | SECURITY_DESCRIPTOR_DACL_PRESENT = 0x0004 | |
13 | SECURITY_DESCRIPTOR_DACL_DEFAULTED = 0x0008 | |
14 | SECURITY_DESCRIPTOR_SACL_PRESENT = 0x0010 | |
15 | SECURITY_DESCRIPTOR_SACL_DEFAULTED = 0x0020 | |
16 | SECURITY_DESCRIPTOR_SERVER_SECURITY = 0x0040 | |
17 | SECURITY_DESCRIPTOR_DACL_TRUSTED = 0x0080 | |
18 | SECURITY_DESCRIPTOR_DACL_COMPUTED_INHERITANCE_REQUIRED = 0x0100 | |
19 | SECURITY_DESCRIPTOR_SACL_COMPUTED_INHERITANCE_REQUIRED = 0x0200 | |
20 | SECURITY_DESCRIPTOR_DACL_AUTO_INHERITED = 0x0400 | |
21 | SECURITY_DESCRIPTOR_SACL_AUTO_INHERITED = 0x0800 | |
22 | SECURITY_DESCRIPTOR_DACL_PROTECTED = 0x1000 | |
23 | SECURITY_DESCRIPTOR_SACL_PROTECTED = 0x2000 | |
24 | SECURITY_DESCRIPTOR_RM_CONTROL_VALID = 0x4000 | |
25 | SECURITY_DESCRIPTOR_SELF_RELATIVE = 0x8000 | |
26 | ||
27 | # ACE types | |
28 | # [MS-DTYP]: 2.4.4.1 | |
29 | ACE_TYPE_ACCESS_ALLOWED = 0x00 | |
30 | ACE_TYPE_ACCESS_DENIED = 0x01 | |
31 | ACE_TYPE_SYSTEM_AUDIT = 0x02 | |
32 | ACE_TYPE_SYSTEM_ALARM = 0x03 | |
33 | ACE_TYPE_ACCESS_ALLOWED_COMPOUND = 0x04 | |
34 | ACE_TYPE_ACCESS_ALLOWED_OBJECT = 0x05 | |
35 | ACE_TYPE_ACCESS_DENIED_OBJECT = 0x06 | |
36 | ACE_TYPE_SYSTEM_AUDIT_OBJECT = 0x07 | |
37 | ACE_TYPE_SYSTEM_ALARM_OBJECT = 0x08 | |
38 | ACE_TYPE_ACCESS_ALLOWED_CALLBACK = 0x09 | |
39 | ACE_TYPE_ACCESS_DENIED_CALLBACK = 0x0A | |
40 | ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT = 0x0B | |
41 | ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT = 0x0C | |
42 | ACE_TYPE_SYSTEM_AUDIT_CALLBACK = 0x0D | |
43 | ACE_TYPE_SYSTEM_ALARM_CALLBACK = 0x0E | |
44 | ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT = 0x0F | |
45 | ACE_TYPE_SYSTEM_ALARM_CALLBACK_OBJECT = 0x10 | |
46 | ACE_TYPE_SYSTEM_MANDATORY_LABEL = 0x11 | |
47 | ACE_TYPE_SYSTEM_RESOURCE_ATTRIBUTE = 0x12 | |
48 | ACE_TYPE_SYSTEM_SCOPED_POLICY_ID = 0x13 | |
49 | ||
50 | # ACE flags | |
51 | # [MS-DTYP]: 2.4.4.1 | |
52 | ACE_FLAG_OBJECT_INHERIT = 0x01 | |
53 | ACE_FLAG_CONTAINER_INHERIT = 0x02 | |
54 | ACE_FLAG_NO_PROPAGATE_INHERIT = 0x04 | |
55 | ACE_FLAG_INHERIT_ONLY = 0x08 | |
56 | ACE_FLAG_INHERITED = 0x10 | |
57 | ACE_FLAG_SUCCESSFUL_ACCESS = 0x40 | |
58 | ACE_FLAG_FAILED_ACCESS = 0x80 | |
59 | ||
60 | # Pre-defined well-known SIDs | |
61 | # [MS-DTYP]: 2.4.2.4 | |
62 | SID_NULL = "S-1-0-0" | |
63 | SID_EVERYONE = "S-1-1-0" | |
64 | SID_LOCAL = "S-1-2-0" | |
65 | SID_CONSOLE_LOGON = "S-1-2-1" | |
66 | SID_CREATOR_OWNER = "S-1-3-0" | |
67 | SID_CREATOR_GROUP = "S-1-3-1" | |
68 | SID_OWNER_SERVER = "S-1-3-2" | |
69 | SID_GROUP_SERVER = "S-1-3-3" | |
70 | SID_OWNER_RIGHTS = "S-1-3-4" | |
71 | SID_NT_AUTHORITY = "S-1-5" | |
72 | SID_DIALUP = "S-1-5-1" | |
73 | SID_NETWORK = "S-1-5-2" | |
74 | SID_BATCH = "S-1-5-3" | |
75 | SID_INTERACTIVE = "S-1-5-4" | |
76 | SID_SERVICE = "S-1-5-6" | |
77 | SID_ANONYMOUS = "S-1-5-7" | |
78 | SID_PROXY = "S-1-5-8" | |
79 | SID_ENTERPRISE_DOMAIN_CONTROLLERS = "S-1-5-9" | |
80 | SID_PRINCIPAL_SELF = "S-1-5-10" | |
81 | SID_AUTHENTICATED_USERS = "S-1-5-11" | |
82 | SID_RESTRICTED_CODE = "S-1-5-12" | |
83 | SID_TERMINAL_SERVER_USER = "S-1-5-13" | |
84 | SID_REMOTE_INTERACTIVE_LOGON = "S-1-5-14" | |
85 | SID_THIS_ORGANIZATION = "S-1-5-15" | |
86 | SID_IUSR = "S-1-5-17" | |
87 | SID_LOCAL_SYSTEM = "S-1-5-18" | |
88 | SID_LOCAL_SERVICE = "S-1-5-19" | |
89 | SID_NETWORK_SERVICE = "S-1-5-20" | |
90 | SID_COMPOUNDED_AUTHENTICATION = "S-1-5-21-0-0-0-496" | |
91 | SID_CLAIMS_VALID = "S-1-5-21-0-0-0-497" | |
92 | SID_BUILTIN_ADMINISTRATORS = "S-1-5-32-544" | |
93 | SID_BUILTIN_USERS = "S-1-5-32-545" | |
94 | SID_BUILTIN_GUESTS = "S-1-5-32-546" | |
95 | SID_POWER_USERS = "S-1-5-32-547" | |
96 | SID_ACCOUNT_OPERATORS = "S-1-5-32-548" | |
97 | SID_SERVER_OPERATORS = "S-1-5-32-549" | |
98 | SID_PRINTER_OPERATORS = "S-1-5-32-550" | |
99 | SID_BACKUP_OPERATORS = "S-1-5-32-551" | |
100 | SID_REPLICATOR = "S-1-5-32-552" | |
101 | SID_ALIAS_PREW2KCOMPACC = "S-1-5-32-554" | |
102 | SID_REMOTE_DESKTOP = "S-1-5-32-555" | |
103 | SID_NETWORK_CONFIGURATION_OPS = "S-1-5-32-556" | |
104 | SID_INCOMING_FOREST_TRUST_BUILDERS = "S-1-5-32-557" | |
105 | SID_PERFMON_USERS = "S-1-5-32-558" | |
106 | SID_PERFLOG_USERS = "S-1-5-32-559" | |
107 | SID_WINDOWS_AUTHORIZATION_ACCESS_GROUP = "S-1-5-32-560" | |
108 | SID_TERMINAL_SERVER_LICENSE_SERVERS = "S-1-5-32-561" | |
109 | SID_DISTRIBUTED_COM_USERS = "S-1-5-32-562" | |
110 | SID_IIS_IUSRS = "S-1-5-32-568" | |
111 | SID_CRYPTOGRAPHIC_OPERATORS = "S-1-5-32-569" | |
112 | SID_EVENT_LOG_READERS = "S-1-5-32-573" | |
113 | SID_CERTIFICATE_SERVICE_DCOM_ACCESS = "S-1-5-32-574" | |
114 | SID_RDS_REMOTE_ACCESS_SERVERS = "S-1-5-32-575" | |
115 | SID_RDS_ENDPOINT_SERVERS = "S-1-5-32-576" | |
116 | SID_RDS_MANAGEMENT_SERVERS = "S-1-5-32-577" | |
117 | SID_HYPER_V_ADMINS = "S-1-5-32-578" | |
118 | SID_ACCESS_CONTROL_ASSISTANCE_OPS = "S-1-5-32-579" | |
119 | SID_REMOTE_MANAGEMENT_USERS = "S-1-5-32-580" | |
120 | SID_WRITE_RESTRICTED_CODE = "S-1-5-33" | |
121 | SID_NTLM_AUTHENTICATION = "S-1-5-64-10" | |
122 | SID_SCHANNEL_AUTHENTICATION = "S-1-5-64-14" | |
123 | SID_DIGEST_AUTHENTICATION = "S-1-5-64-21" | |
124 | SID_THIS_ORGANIZATION_CERTIFICATE = "S-1-5-65-1" | |
125 | SID_NT_SERVICE = "S-1-5-80" | |
126 | SID_USER_MODE_DRIVERS = "S-1-5-84-0-0-0-0-0" | |
127 | SID_LOCAL_ACCOUNT = "S-1-5-113" | |
128 | SID_LOCAL_ACCOUNT_AND_MEMBER_OF_ADMINISTRATORS_GROUP = "S-1-5-114" | |
129 | SID_OTHER_ORGANIZATION = "S-1-5-1000" | |
130 | SID_ALL_APP_PACKAGES = "S-1-15-2-1" | |
131 | SID_ML_UNTRUSTED = "S-1-16-0" | |
132 | SID_ML_LOW = "S-1-16-4096" | |
133 | SID_ML_MEDIUM = "S-1-16-8192" | |
134 | SID_ML_MEDIUM_PLUS = "S-1-16-8448" | |
135 | SID_ML_HIGH = "S-1-16-12288" | |
136 | SID_ML_SYSTEM = "S-1-16-16384" | |
137 | SID_ML_PROTECTED_PROCESS = "S-1-16-20480" | |
138 | SID_AUTHENTICATION_AUTHORITY_ASSERTED_IDENTITY = "S-1-18-1" | |
139 | SID_SERVICE_ASSERTED_IDENTITY = "S-1-18-2" | |
140 | SID_FRESH_PUBLIC_KEY_IDENTITY = "S-1-18-3" | |
141 | SID_KEY_TRUST_IDENTITY = "S-1-18-4" | |
142 | SID_KEY_PROPERTY_MFA = "S-1-18-5" | |
143 | SID_KEY_PROPERTY_ATTESTATION = "S-1-18-6" | |
144 | ||
145 | ||
146 | class SID(object): | |
147 | """ | |
148 | A Windows security identifier. Represents a single principal, such a | |
149 | user or a group, as a sequence of numbers consisting of the revision, | |
150 | identifier authority, and a variable-length list of subauthorities. | |
151 | ||
152 | See [MS-DTYP]: 2.4.2 | |
153 | """ | |
154 | def __init__(self, revision, identifier_authority, subauthorities): | |
155 | #: Revision, should always be 1. | |
156 | self.revision = revision | |
157 | #: An integer representing the identifier authority. | |
158 | self.identifier_authority = identifier_authority | |
159 | #: A list of integers representing all subauthorities. | |
160 | self.subauthorities = subauthorities | |
161 | ||
162 | def __str__(self): | |
163 | """ | |
164 | String representation, as specified in [MS-DTYP]: 2.4.2.1 | |
165 | """ | |
166 | if self.identifier_authority >= 2**32: | |
167 | id_auth = '%#x' % (self.identifier_authority,) | |
168 | else: | |
169 | id_auth = self.identifier_authority | |
170 | auths = [self.revision, id_auth] + self.subauthorities | |
171 | return 'S-' + '-'.join(str(subauth) for subauth in auths) | |
172 | ||
173 | def __repr__(self): | |
174 | return 'SID(%r)' % (str(self),) | |
175 | ||
176 | @classmethod | |
177 | def from_bytes(cls, data, return_tail=False): | |
178 | revision, subauth_count = struct.unpack('<BB', data[:2]) | |
179 | identifier_authority = struct.unpack('>Q', b'\x00\x00' + data[2:8])[0] | |
180 | subauth_data = data[8:] | |
181 | subauthorities = [struct.unpack('<L', subauth_data[4 * i : 4 * (i+1)])[0] | |
182 | for i in range(subauth_count)] | |
183 | sid = cls(revision, identifier_authority, subauthorities) | |
184 | if return_tail: | |
185 | return sid, subauth_data[4 * subauth_count :] | |
186 | return sid | |
187 | ||
188 | ||
189 | class ACE(object): | |
190 | """ | |
191 | Represents a single access control entry. | |
192 | ||
193 | See [MS-DTYP]: 2.4.4 | |
194 | """ | |
195 | HEADER_FORMAT = '<BBH' | |
196 | ||
197 | def __init__(self, type_, flags, mask, sid, additional_data): | |
198 | #: An integer representing the type of the ACE. One of the | |
199 | #: ``ACE_TYPE_*`` constants. Corresponds to the ``AceType`` field | |
200 | #: from [MS-DTYP] 2.4.4.1. | |
201 | self.type = type_ | |
202 | #: An integer bitmask with ACE flags, corresponds to the | |
203 | #: ``AceFlags`` field. | |
204 | self.flags = flags | |
205 | #: An integer representing the ``ACCESS_MASK`` as specified in | |
206 | #: [MS-DTYP] 2.4.3. | |
207 | self.mask = mask | |
208 | #: The :class:`SID` of a trustee. | |
209 | self.sid = sid | |
210 | #: A dictionary of additional fields present in the ACE, depending | |
211 | #: on the type. The following fields can be present: | |
212 | #: | |
213 | #: * ``flags`` | |
214 | #: * ``object_type`` | |
215 | #: * ``inherited_object_type`` | |
216 | #: * ``application_data`` | |
217 | #: * ``attribute_data`` | |
218 | self.additional_data = additional_data | |
219 | ||
220 | def __repr__(self): | |
221 | return "ACE(type=%#04x, flags=%#04x, mask=%#010x, sid=%s)" % ( | |
222 | self.type, self.flags, self.mask, self.sid, | |
223 | ) | |
224 | ||
225 | @property | |
226 | def isInheritOnly(self): | |
227 | """Convenience property which indicates if this ACE is inherit | |
228 | only, meaning that it doesn't apply to the object itself.""" | |
229 | return bool(self.flags & ACE_FLAG_INHERIT_ONLY) | |
230 | ||
231 | @classmethod | |
232 | def from_bytes(cls, data): | |
233 | header_size = struct.calcsize(cls.HEADER_FORMAT) | |
234 | header = data[:header_size] | |
235 | type_, flags, size = struct.unpack(cls.HEADER_FORMAT, header) | |
236 | ||
237 | assert len(data) >= size | |
238 | ||
239 | body = data[header_size:size] | |
240 | additional_data = {} | |
241 | ||
242 | # In all ACE types, the mask immediately follows the header. | |
243 | mask = struct.unpack('<I', body[:4])[0] | |
244 | body = body[4:] | |
245 | ||
246 | # All OBJECT-type ACEs contain additional flags, and two GUIDs as | |
247 | # the following fields. | |
248 | if type_ in (ACE_TYPE_ACCESS_ALLOWED_OBJECT, | |
249 | ACE_TYPE_ACCESS_DENIED_OBJECT, | |
250 | ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT, | |
251 | ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT, | |
252 | ACE_TYPE_SYSTEM_AUDIT_OBJECT, | |
253 | ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT): | |
254 | additional_data['flags'] = struct.unpack('<I', body[:4])[0] | |
255 | additional_data['object_type'] = body[4:20] | |
256 | additional_data['inherited_object_type'] = body[20:36] | |
257 | body = body[36:] | |
258 | ||
259 | # Then the SID in all types. | |
260 | sid, body = SID.from_bytes(body, return_tail=True) | |
261 | ||
262 | # CALLBACK-type ACEs (and for some obscure reason, | |
263 | # SYSTEM_AUDIT_OBJECT) have a final tail of application data. | |
264 | if type_ in (ACE_TYPE_ACCESS_ALLOWED_CALLBACK, | |
265 | ACE_TYPE_ACCESS_DENIED_CALLBACK, | |
266 | ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT, | |
267 | ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT, | |
268 | ACE_TYPE_SYSTEM_AUDIT_OBJECT, | |
269 | ACE_TYPE_SYSTEM_AUDIT_CALLBACK, | |
270 | ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT): | |
271 | additional_data['application_data'] = body | |
272 | ||
273 | # SYSTEM_RESOURCE_ATTRIBUTE ACEs have a tail of attribute data. | |
274 | if type_ == ACE_TYPE_SYSTEM_RESOURCE_ATTRIBUTE: | |
275 | additional_data['attribute_data'] = body | |
276 | ||
277 | return cls(type_, flags, mask, sid, additional_data) | |
278 | ||
279 | ||
280 | class ACL(object): | |
281 | """ | |
282 | Access control list, encapsulating a sequence of access control | |
283 | entries. | |
284 | ||
285 | See [MS-DTYP]: 2.4.5 | |
286 | """ | |
287 | HEADER_FORMAT = '<BBHHH' | |
288 | ||
289 | def __init__(self, revision, aces): | |
290 | #: Integer value of the revision. | |
291 | self.revision = revision | |
292 | #: List of :class:`ACE` instances. | |
293 | self.aces = aces | |
294 | ||
295 | def __repr__(self): | |
296 | return "ACL(%r)" % (self.aces,) | |
297 | ||
298 | @classmethod | |
299 | def from_bytes(cls, data): | |
300 | revision = None | |
301 | aces = [] | |
302 | ||
303 | header_size = struct.calcsize(cls.HEADER_FORMAT) | |
304 | header, remaining = data[:header_size], data[header_size:] | |
305 | revision, sbz1, size, count, sbz2 = struct.unpack(cls.HEADER_FORMAT, header) | |
306 | ||
307 | assert len(data) >= size | |
308 | ||
309 | for i in range(count): | |
310 | ace_size = struct.unpack('<H', remaining[2:4])[0] | |
311 | ace_data, remaining = remaining[:ace_size], remaining[ace_size:] | |
312 | aces.append(ACE.from_bytes(ace_data)) | |
313 | ||
314 | return cls(revision, aces) | |
315 | ||
316 | ||
317 | class SecurityDescriptor(object): | |
318 | """ | |
319 | Represents a security descriptor. | |
320 | ||
321 | See [MS-DTYP]: 2.4.6 | |
322 | """ | |
323 | ||
324 | HEADER_FORMAT = '<BBHIIII' | |
325 | ||
326 | def __init__(self, flags, owner, group, dacl, sacl): | |
327 | #: Integer bitmask of control flags. Corresponds to the | |
328 | #: ``Control`` field in [MS-DTYP] 2.4.6. | |
329 | self.flags = flags | |
330 | #: Instance of :class:`SID` representing the owner user. | |
331 | self.owner = owner | |
332 | #: Instance of :class:`SID` representing the owner group. | |
333 | self.group = group | |
334 | #: Instance of :class:`ACL` representing the discretionary access | |
335 | #: control list, which specifies access restrictions of an object. | |
336 | self.dacl = dacl | |
337 | #: Instance of :class:`ACL` representing the system access control | |
338 | #: list, which specifies audit logging of an object. | |
339 | self.sacl = sacl | |
340 | ||
341 | @classmethod | |
342 | def from_bytes(cls, data): | |
343 | owner = None | |
344 | group = None | |
345 | dacl = None | |
346 | sacl = None | |
347 | ||
348 | header = data[:struct.calcsize(cls.HEADER_FORMAT)] | |
349 | (revision, sbz1, flags, owner_offset, group_offset, sacl_offset, | |
350 | dacl_offset) = struct.unpack(cls.HEADER_FORMAT, header) | |
351 | ||
352 | assert revision == 1 | |
353 | assert flags & SECURITY_DESCRIPTOR_SELF_RELATIVE | |
354 | for offset in (owner_offset, group_offset, sacl_offset, dacl_offset): | |
355 | assert 0 <= offset < len(data) | |
356 | ||
357 | if owner_offset: | |
358 | owner = SID.from_bytes(data[owner_offset:]) | |
359 | if group_offset: | |
360 | group = SID.from_bytes(data[group_offset:]) | |
361 | if dacl_offset: | |
362 | dacl = ACL.from_bytes(data[dacl_offset:]) | |
363 | if sacl_offset: | |
364 | sacl = ACL.from_bytes(data[sacl_offset:]) | |
365 | ||
366 | return cls(flags, owner, group, dacl, sacl) |
269 | 269 | STRUCTURE_FORMAT = "<HHHH" |
270 | 270 | STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT) |
271 | 271 | |
272 | @property | |
273 | def isGuestSession(self): | |
274 | return (self.session_flags & 0x0001) > 0 # SMB2_SESSION_FLAG_IS_GUEST | |
275 | ||
276 | @property | |
277 | def isAnonymousSession(self): | |
278 | return (self.session_flags & 0x0002) > 0 # SMB2_SESSION_FLAG_IS_NULL | |
279 | ||
272 | 280 | def decode(self, message): |
273 | 281 | assert message.command == SMB2_COM_SESSION_SETUP |
274 | 282 | |
361 | 369 | |
362 | 370 | def prepare(self, message): |
363 | 371 | buf = self.filename.encode('UTF-16LE') |
372 | filename_len = len(buf) | |
364 | 373 | if self.create_context_data: |
365 | 374 | n = SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE + len(buf) |
366 | 375 | if n % 8 != 0: |
388 | 397 | self.create_disp, |
389 | 398 | self.create_options, |
390 | 399 | SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE, # NameOffset |
391 | len(self.filename)*2, # NameLength in bytes | |
400 | filename_len, # Length of encoded filename in bytes | |
392 | 401 | create_context_offset, # CreateContextOffset |
393 | 402 | len(self.create_context_data) # CreateContextLength |
394 | 403 | ) + buf |
114 | 114 | FILE_READ_EA = 0x08 |
115 | 115 | FILE_WRITE_EA = 0x10 |
116 | 116 | FILE_EXECUTE = 0x20 |
117 | FILE_DELETE_CHILD = 0x40 | |
117 | 118 | FILE_READ_ATTRIBUTES = 0x80 |
118 | 119 | FILE_WRITE_ATTRIBUTES = 0x0100 |
119 | 120 | DELETE = 0x010000 |
224 | 225 | SMB_FILE_ATTRIBUTE_READONLY = 0x01 |
225 | 226 | SMB_FILE_ATTRIBUTE_HIDDEN = 0x02 |
226 | 227 | SMB_FILE_ATTRIBUTE_SYSTEM = 0x04 |
227 | SMB_FILE_ATTRIBUTE_VOLUME = 0x08 | |
228 | SMB_FILE_ATTRIBUTE_VOLUME = 0x08 # Unsupported for listPath() operations | |
228 | 229 | SMB_FILE_ATTRIBUTE_DIRECTORY = 0x10 |
229 | 230 | SMB_FILE_ATTRIBUTE_ARCHIVE = 0x20 |
231 | # SMB_FILE_ATTRIBUTE_INCL_NORMAL is a special placeholder to include normal files | |
232 | # with other search attributes for listPath() operations. It is not defined in the MS-CIFS specs. | |
233 | SMB_FILE_ATTRIBUTE_INCL_NORMAL = 0x10000 | |
234 | # Do not use the following values for listPath() operations as they are not supported for SMB2 | |
230 | 235 | SMB_SEARCH_ATTRIBUTE_READONLY = 0x0100 |
231 | 236 | SMB_SEARCH_ATTRIBUTE_HIDDEN = 0x0200 |
232 | 237 | SMB_SEARCH_ATTRIBUTE_SYSTEM = 0x0400 |
236 | 241 | # Bitmask for OptionalSupport field in SMB_COM_TREE_CONNECT_ANDX response |
237 | 242 | SMB_TREE_CONNECTX_SUPPORT_SEARCH = 0x0001 |
238 | 243 | SMB_TREE_CONNECTX_SUPPORT_DFS = 0x0002 |
244 | ||
245 | # Bitmask for security information fields, specified as | |
246 | # AdditionalInformation in SMB2 | |
247 | # [MS-SMB]: 2.2.7.4 | |
248 | # [MS-SMB2]: 2.2.37 | |
249 | OWNER_SECURITY_INFORMATION = 0x00000001 | |
250 | GROUP_SECURITY_INFORMATION = 0x00000002 | |
251 | DACL_SECURITY_INFORMATION = 0x00000004 | |
252 | SACL_SECURITY_INFORMATION = 0x00000008 | |
253 | LABEL_SECURITY_INFORMATION = 0x00000010 | |
254 | ATTRIBUTE_SECURITY_INFORMATION = 0x00000020 | |
255 | SCOPE_SECURITY_INFORMATION = 0x00000040 | |
256 | BACKUP_SECURITY_INFORMATION = 0x00010000 |
141 | 141 | self.parameters_data = b'' |
142 | 142 | self.data = b'' |
143 | 143 | self.payload = None |
144 | ||
145 | @property | |
146 | def isAsync(self): | |
147 | return bool(self.flags & SMB2_FLAGS_ASYNC_COMMAND) | |
144 | 148 | |
145 | 149 | @property |
146 | 150 | def isReply(self): |
1278 | 1282 | - [MS-CIFS]: 2.2.4.39.1 |
1279 | 1283 | """ |
1280 | 1284 | |
1281 | def __init__(self, echo_data = '', echo_count = 1): | |
1285 | def __init__(self, echo_data = b'', echo_count = 1): | |
1282 | 1286 | self.echo_count = echo_count |
1283 | 1287 | self.echo_data = echo_data |
1284 | 1288 |
81 | 81 | dest.C = self.C |
82 | 82 | dest.D = self.D |
83 | 83 | dest.count = self.count |
84 | for i in range(self.count): | |
84 | for i in range(int(self.count)): | |
85 | 85 | dest.buf[i] = self.buf[i] |
86 | 86 | |
87 | 87 | return dest |
88 | 88 | |
89 | 89 | #----------------------------------------------------- |
90 | 90 | def update(self, str): |
91 | ||
92 | buf = [] | |
93 | for i in str: buf.append(ord(i)) | |
91 | if isinstance(str, bytes): | |
92 | buf = list(str) | |
93 | else: | |
94 | buf = [ord(i) for i in str] | |
95 | ||
94 | 96 | ilen = U32(len(buf)) |
95 | 97 | |
96 | 98 | # check if the first length is out of range |
226 | 228 | res[14]=(temp.D >> 16) & U32(0xFF) |
227 | 229 | res[15]=(temp.D >> 24) & U32(0xFF) |
228 | 230 | |
229 | return int_array2str(res) | |
231 | return int_array2str(res).encode('UTF-16LE') | |
230 | 232 | |
231 | 233 | #==================================================================== |
232 | 234 | # helpers |
0 | ||
1 | def RC4_encrypt(key, data): | |
2 | S = list(range(256)) | |
3 | j = 0 | |
4 | ||
5 | key_len = len(key) | |
6 | for i in list(range(256)): | |
7 | j = (j + S[i] + key[i % key_len]) % 256 | |
8 | S[i], S[j] = S[j], S[i] | |
9 | ||
10 | j = 0 | |
11 | y = 0 | |
12 | out = [] | |
13 | ||
14 | for char in data: | |
15 | j = (j + 1) % 256 | |
16 | y = (y + S[j]) % 256 | |
17 | S[j], S[y] = S[y], S[j] | |
18 | ||
19 | out.append(char ^ S[(S[j] + S[y]) % 256]) | |
20 | ||
21 | return bytes(out) |
0 | 0 | |
1 | from nose2.tools.decorators import with_teardown | |
1 | 2 | from smb.SMBConnection import SMBConnection |
3 | from smb import smb_structs | |
2 | 4 | from .util import getConnectionInfo |
3 | from nose.tools import with_setup | |
4 | from smb import smb_structs | |
5 | 5 | |
6 | conn = None | |
6 | conn, conn2, conn3 = None, None, None | |
7 | 7 | |
8 | 8 | def teardown_func(): |
9 | global conn | |
10 | conn.close() | |
9 | global conn, conn2, conn3 | |
10 | if conn: | |
11 | conn.close() | |
12 | if conn2: | |
13 | conn2.close() | |
14 | if conn3: | |
15 | conn3.close(); | |
11 | 16 | |
12 | @with_setup(teardown = teardown_func) | |
17 | @with_teardown(teardown_func) | |
13 | 18 | def test_NTLMv1_auth_SMB1(): |
14 | global conn | |
19 | global conn, conn2, conn3 | |
15 | 20 | smb_structs.SUPPORT_SMB2 = False |
16 | 21 | info = getConnectionInfo() |
17 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False) | |
22 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
18 | 23 | assert conn.connect(info['server_ip'], info['server_port']) |
19 | 24 | |
20 | @with_setup(teardown = teardown_func) | |
21 | def test_NTLMv2_auth_SMB1(): | |
22 | global conn | |
25 | conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
26 | assert not conn2.connect(info['server_ip'], info['server_port']) | |
27 | ||
28 | conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
29 | assert not conn3.connect(info['server_ip'], info['server_port']) | |
30 | ||
31 | @with_teardown(teardown_func) | |
32 | def test_NTLMv1_auth_SMB1_callable_password(): | |
33 | global conn, conn2, conn3 | |
23 | 34 | smb_structs.SUPPORT_SMB2 = False |
24 | 35 | info = getConnectionInfo() |
25 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
36 | conn = SMBConnection(info['user'], lambda: info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
26 | 37 | assert conn.connect(info['server_ip'], info['server_port']) |
27 | 38 | |
28 | @with_setup(teardown = teardown_func) | |
39 | conn2 = SMBConnection(info['user'], lambda: 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
40 | assert not conn2.connect(info['server_ip'], info['server_port']) | |
41 | ||
42 | conn3 = SMBConnection('INVALIDUSER', lambda: 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
43 | assert not conn3.connect(info['server_ip'], info['server_port']) | |
44 | ||
45 | @with_teardown(teardown_func) | |
46 | def test_NTLMv2_auth_SMB1(): | |
47 | global conn, conn2, conn3 | |
48 | smb_structs.SUPPORT_SMB2 = False | |
49 | info = getConnectionInfo() | |
50 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
51 | assert conn.connect(info['server_ip'], info['server_port']) | |
52 | ||
53 | conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
54 | assert not conn2.connect(info['server_ip'], info['server_port']) | |
55 | ||
56 | conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
57 | assert not conn3.connect(info['server_ip'], info['server_port']) | |
58 | ||
59 | @with_teardown(teardown_func) | |
29 | 60 | def test_NTLMv1_auth_SMB2(): |
30 | global conn | |
61 | global conn, conn2, conn3 | |
31 | 62 | smb_structs.SUPPORT_SMB2 = True |
32 | 63 | info = getConnectionInfo() |
33 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False) | |
64 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
34 | 65 | assert conn.connect(info['server_ip'], info['server_port']) |
35 | 66 | |
36 | @with_setup(teardown = teardown_func) | |
67 | conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
68 | assert not conn2.connect(info['server_ip'], info['server_port']) | |
69 | ||
70 | conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True) | |
71 | assert not conn3.connect(info['server_ip'], info['server_port']) | |
72 | ||
73 | @with_teardown(teardown_func) | |
37 | 74 | def test_NTLMv2_auth_SMB2(): |
38 | global conn | |
75 | global conn, conn2, conn3 | |
39 | 76 | smb_structs.SUPPORT_SMB2 = True |
40 | 77 | info = getConnectionInfo() |
41 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
78 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
42 | 79 | assert conn.connect(info['server_ip'], info['server_port']) |
80 | ||
81 | conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
82 | assert not conn2.connect(info['server_ip'], info['server_port']) | |
83 | ||
84 | conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
85 | assert not conn3.connect(info['server_ip'], info['server_port']) |
0 | 0 | # -*- coding: utf-8 -*- |
1 | 1 | |
2 | 2 | import os, time, random |
3 | from nose2.tools.decorators import with_setup, with_teardown | |
3 | 4 | from smb.SMBConnection import SMBConnection |
5 | from smb import smb_structs | |
4 | 6 | from .util import getConnectionInfo |
5 | from nose.tools import with_setup | |
6 | from smb import smb_structs | |
7 | 7 | |
8 | 8 | conn = None |
9 | 9 | |
12 | 12 | smb_structs.SUPPORT_SMB2 = False |
13 | 13 | |
14 | 14 | info = getConnectionInfo() |
15 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
15 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
16 | 16 | assert conn.connect(info['server_ip'], info['server_port']) |
17 | 17 | |
18 | 18 | def setup_func_SMB2(): |
20 | 20 | smb_structs.SUPPORT_SMB2 = True |
21 | 21 | |
22 | 22 | info = getConnectionInfo() |
23 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
23 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
24 | 24 | assert conn.connect(info['server_ip'], info['server_port']) |
25 | 25 | |
26 | 26 | def teardown_func(): |
27 | 27 | global conn |
28 | 28 | conn.close() |
29 | 29 | |
30 | @with_setup(setup_func_SMB1, teardown_func) | |
30 | @with_setup(setup_func_SMB1) | |
31 | @with_teardown(teardown_func) | |
31 | 32 | def test_english_directory_SMB1(): |
32 | 33 | global conn |
33 | 34 | |
44 | 45 | names = [e.filename for e in entries] |
45 | 46 | assert os.path.basename(path.replace('/', os.sep)) not in names |
46 | 47 | |
47 | @with_setup(setup_func_SMB2, teardown_func) | |
48 | @with_setup(setup_func_SMB2) | |
49 | @with_teardown(teardown_func) | |
48 | 50 | def test_english_directory_SMB2(): |
49 | 51 | global conn |
50 | 52 | |
61 | 63 | names = [e.filename for e in entries] |
62 | 64 | assert os.path.basename(path.replace('/', os.sep)) not in names |
63 | 65 | |
64 | @with_setup(setup_func_SMB1, teardown_func) | |
66 | @with_setup(setup_func_SMB1) | |
67 | @with_teardown(teardown_func) | |
65 | 68 | def test_unicode_directory_SMB1(): |
66 | 69 | global conn |
67 | 70 | |
78 | 81 | names = [e.filename for e in entries] |
79 | 82 | assert os.path.basename(path.replace('/', os.sep)) not in names |
80 | 83 | |
81 | @with_setup(setup_func_SMB2, teardown_func) | |
84 | @with_setup(setup_func_SMB2) | |
85 | @with_teardown(teardown_func) | |
82 | 86 | def test_unicode_directory_SMB2(): |
83 | 87 | global conn |
84 | 88 |
0 | 0 | |
1 | 1 | import random |
2 | from nose2.tools.decorators import with_setup, with_teardown | |
2 | 3 | from smb.SMBConnection import SMBConnection |
3 | 4 | from .util import getConnectionInfo |
4 | from nose.tools import with_setup | |
5 | 5 | |
6 | 6 | conn = None |
7 | 7 | |
8 | 8 | def setup_func(): |
9 | 9 | global conn |
10 | 10 | info = getConnectionInfo() |
11 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
11 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
12 | 12 | assert conn.connect(info['server_ip'], info['server_port']) |
13 | 13 | |
14 | 14 | def teardown_func(): |
15 | 15 | global conn |
16 | 16 | conn.close() |
17 | 17 | |
18 | @with_setup(setup_func, teardown_func) | |
18 | @with_setup(setup_func) | |
19 | @with_teardown(teardown_func) | |
19 | 20 | def test_echo(): |
20 | 21 | global conn |
21 | 22 |
0 | 0 | # -*- coding: utf-8 -*- |
1 | 1 | |
2 | from nose2.tools.decorators import with_setup, with_teardown | |
2 | 3 | from smb.SMBConnection import SMBConnection |
4 | from smb.smb_constants import * | |
5 | from smb import smb_structs | |
3 | 6 | from .util import getConnectionInfo |
4 | from nose.tools import with_setup | |
5 | from smb import smb_structs | |
6 | 7 | |
7 | 8 | conn = None |
8 | 9 | |
10 | 11 | global conn |
11 | 12 | smb_structs.SUPPORT_SMB2 = False |
12 | 13 | info = getConnectionInfo() |
13 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
14 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
14 | 15 | assert conn.connect(info['server_ip'], info['server_port']) |
15 | 16 | |
16 | 17 | def setup_func_SMB2(): |
17 | 18 | global conn |
18 | 19 | smb_structs.SUPPORT_SMB2 = True |
19 | 20 | info = getConnectionInfo() |
20 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
21 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
21 | 22 | assert conn.connect(info['server_ip'], info['server_port']) |
22 | 23 | |
23 | 24 | def teardown_func(): |
24 | 25 | global conn |
25 | 26 | conn.close() |
26 | 27 | |
27 | @with_setup(setup_func_SMB1, teardown_func) | |
28 | @with_setup(setup_func_SMB1) | |
29 | @with_teardown(teardown_func) | |
28 | 30 | def test_listPath_SMB1(): |
29 | 31 | global conn |
30 | 32 | results = conn.listPath('smbtest', '/') |
35 | 37 | assert ( 'Implementing CIFS - SMB.html', False ) in filenames # Test long English file names |
36 | 38 | assert ( 'rfc1001.txt', False ) in filenames # Test short English file names |
37 | 39 | |
38 | @with_setup(setup_func_SMB1, teardown_func) | |
40 | @with_setup(setup_func_SMB1) | |
41 | @with_teardown(teardown_func) | |
39 | 42 | def test_listSubPath_SMB1(): |
40 | 43 | global conn |
41 | 44 | results = conn.listPath('smbtest', '/Test Folder with Long Name/') |
44 | 47 | assert ( 'Test Folder', True ) in filenames |
45 | 48 | assert ( '子文件夹', True ) in filenames |
46 | 49 | |
47 | @with_setup(setup_func_SMB2, teardown_func) | |
50 | @with_setup(setup_func_SMB1) | |
51 | @with_teardown(teardown_func) | |
52 | def test_listPathWithManyFiles_SMB1(): | |
53 | global conn | |
54 | results = conn.listPath('smbtest', '/RFC Archive/') | |
55 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
56 | assert len(list(filenames))==999 | |
57 | ||
58 | @with_setup(setup_func_SMB2) | |
59 | @with_teardown(teardown_func) | |
48 | 60 | def test_listPath_SMB2(): |
49 | 61 | global conn |
50 | 62 | results = conn.listPath('smbtest', '/') |
55 | 67 | assert ( 'Implementing CIFS - SMB.html', False ) in filenames # Test long English file names |
56 | 68 | assert ( 'rfc1001.txt', False ) in filenames # Test short English file names |
57 | 69 | |
58 | @with_setup(setup_func_SMB2, teardown_func) | |
70 | @with_setup(setup_func_SMB2) | |
71 | @with_teardown(teardown_func) | |
59 | 72 | def test_listSubPath_SMB2(): |
60 | 73 | global conn |
61 | 74 | results = conn.listPath('smbtest', '/Test Folder with Long Name/') |
63 | 76 | assert ( 'Test File.txt', False ) in filenames |
64 | 77 | assert ( 'Test Folder', True ) in filenames |
65 | 78 | assert ( '子文件夹', True ) in filenames |
79 | ||
80 | @with_setup(setup_func_SMB2) | |
81 | @with_teardown(teardown_func) | |
82 | def test_listPathWithManyFiles_SMB2(): | |
83 | global conn | |
84 | results = conn.listPath('smbtest', '/RFC Archive/') | |
85 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
86 | assert len(list(filenames))==999 | |
87 | ||
88 | @with_setup(setup_func_SMB1) | |
89 | @with_teardown(teardown_func) | |
90 | def test_listPathFilterForDirectory_SMB1(): | |
91 | global conn | |
92 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY) | |
93 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
94 | assert len(list(filenames)) > 0 | |
95 | for f, isDirectory in filenames: | |
96 | assert isDirectory | |
97 | ||
98 | @with_setup(setup_func_SMB2) | |
99 | @with_teardown(teardown_func) | |
100 | def test_listPathFilterForDirectory_SMB2(): | |
101 | global conn | |
102 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY) | |
103 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
104 | assert len(list(filenames)) > 0 | |
105 | for f, isDirectory in filenames: | |
106 | assert isDirectory | |
107 | ||
108 | @with_setup(setup_func_SMB1) | |
109 | @with_teardown(teardown_func) | |
110 | def test_listPathFilterForFiles_SMB1(): | |
111 | global conn | |
112 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL) | |
113 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
114 | assert len(list(filenames)) > 0 | |
115 | for f, isDirectory in filenames: | |
116 | assert not isDirectory | |
117 | ||
118 | @with_setup(setup_func_SMB2) | |
119 | @with_teardown(teardown_func) | |
120 | def test_listPathFilterForFiles_SMB2(): | |
121 | global conn | |
122 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL) | |
123 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
124 | assert len(list(filenames)) > 0 | |
125 | for f, isDirectory in filenames: | |
126 | assert not isDirectory | |
127 | ||
128 | ||
129 | @with_setup(setup_func_SMB1) | |
130 | @with_teardown(teardown_func) | |
131 | def test_listPathFilterPattern_SMB1(): | |
132 | global conn | |
133 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*') | |
134 | filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results)) | |
135 | assert len(filenames) == 2 | |
136 | assert ( u'Test File.txt', False ) in filenames | |
137 | assert ( u'Test Folder', True ) in filenames | |
138 | assert ( u'子文件夹', True ) not in filenames | |
139 | ||
140 | @with_setup(setup_func_SMB2) | |
141 | @with_teardown(teardown_func) | |
142 | def test_listPathFilterPattern_SMB2(): | |
143 | global conn | |
144 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*') | |
145 | filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results)) | |
146 | assert len(filenames) == 2 | |
147 | assert ( u'Test File.txt', False ) in filenames | |
148 | assert ( u'Test Folder', True ) in filenames | |
149 | assert ( u'子文件夹', True ) not in filenames | |
150 | ||
151 | @with_setup(setup_func_SMB1) | |
152 | @with_teardown(teardown_func) | |
153 | def test_listPathFilterUnicodePattern_SMB1(): | |
154 | global conn | |
155 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹') | |
156 | filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results)) | |
157 | assert len(filenames) == 1 | |
158 | assert ( u'Test File.txt', False ) not in filenames | |
159 | assert ( u'Test Folder', True ) not in filenames | |
160 | assert ( u'子文件夹', True ) in filenames | |
161 | ||
162 | @with_setup(setup_func_SMB2) | |
163 | @with_teardown(teardown_func) | |
164 | def test_listPathFilterUnicodePattern_SMB2(): | |
165 | global conn | |
166 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹') | |
167 | filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results)) | |
168 | assert len(filenames) == 1 | |
169 | assert ( u'Test File.txt', False ) not in filenames | |
170 | assert ( u'Test Folder', True ) not in filenames | |
171 | assert ( u'子文件夹', True ) in filenames |
0 | 0 | |
1 | from nose2.tools.decorators import with_setup, with_teardown | |
1 | 2 | from smb.SMBConnection import SMBConnection |
3 | from smb import smb_structs | |
2 | 4 | from .util import getConnectionInfo |
3 | from nose.tools import with_setup | |
4 | from smb import smb_structs | |
5 | 5 | |
6 | 6 | conn = None |
7 | 7 | |
9 | 9 | global conn |
10 | 10 | smb_structs.SUPPORT_SMB2 = False |
11 | 11 | info = getConnectionInfo() |
12 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
12 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
13 | 13 | assert conn.connect(info['server_ip'], info['server_port']) |
14 | 14 | |
15 | 15 | def setup_func_SMB2(): |
16 | 16 | global conn |
17 | 17 | smb_structs.SUPPORT_SMB2 = True |
18 | 18 | info = getConnectionInfo() |
19 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
19 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
20 | 20 | assert conn.connect(info['server_ip'], info['server_port']) |
21 | 21 | |
22 | 22 | def teardown_func(): |
23 | 23 | global conn |
24 | 24 | conn.close() |
25 | 25 | |
26 | @with_setup(setup_func_SMB1, teardown_func) | |
26 | @with_setup(setup_func_SMB1) | |
27 | @with_teardown(teardown_func) | |
27 | 28 | def test_listshares_SMB1(): |
28 | 29 | global conn |
29 | 30 | results = conn.listShares() |
30 | 31 | assert 'smbtest' in [r.name.lower() for r in results] |
31 | 32 | |
32 | @with_setup(setup_func_SMB2, teardown_func) | |
33 | @with_setup(setup_func_SMB2) | |
34 | @with_teardown(teardown_func) | |
33 | 35 | def test_listshares_SMB2(): |
34 | 36 | global conn |
35 | 37 | results = conn.listShares() |
0 | 0 | |
1 | from nose2.tools.decorators import with_setup, with_teardown | |
1 | 2 | from smb.SMBConnection import SMBConnection |
3 | from smb import smb_structs | |
2 | 4 | from .util import getConnectionInfo |
3 | from nose.tools import with_setup | |
4 | from smb import smb_structs | |
5 | 5 | |
6 | 6 | conn = None |
7 | 7 | |
9 | 9 | global conn |
10 | 10 | smb_structs.SUPPORT_SMB2 = False |
11 | 11 | info = getConnectionInfo() |
12 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
12 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
13 | 13 | assert conn.connect(info['server_ip'], info['server_port']) |
14 | 14 | |
15 | 15 | def setup_func_SMB2(): |
16 | 16 | global conn |
17 | 17 | smb_structs.SUPPORT_SMB2 = True |
18 | 18 | info = getConnectionInfo() |
19 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
19 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
20 | 20 | assert conn.connect(info['server_ip'], info['server_port']) |
21 | 21 | |
22 | 22 | def teardown_func(): |
23 | 23 | global conn |
24 | 24 | conn.close() |
25 | 25 | |
26 | @with_setup(setup_func_SMB1, teardown_func) | |
26 | @with_setup(setup_func_SMB1) | |
27 | @with_teardown(teardown_func) | |
27 | 28 | def test_listsnapshots_SMB1(): |
28 | 29 | global conn |
29 | 30 | results = conn.listSnapshots('smbtest', '/rfc1001.txt') |
30 | 31 | assert len(results) > 0 |
31 | 32 | |
32 | @with_setup(setup_func_SMB2, teardown_func) | |
33 | @with_setup(setup_func_SMB2) | |
34 | @with_teardown(teardown_func) | |
33 | 35 | def test_listsnapshots_SMB2(): |
34 | 36 | global conn |
35 | 37 | results = conn.listSnapshots('smbtest', '/rfc1001.txt') |
1 | 1 | |
2 | 2 | import os, time, random |
3 | 3 | from io import BytesIO |
4 | from nose2.tools.decorators import with_setup, with_teardown | |
4 | 5 | from smb.SMBConnection import SMBConnection |
6 | from smb import smb_structs | |
5 | 7 | from .util import getConnectionInfo |
6 | from nose.tools import with_setup | |
7 | from smb import smb_structs | |
8 | 8 | |
9 | 9 | conn = None |
10 | 10 | |
12 | 12 | global conn |
13 | 13 | smb_structs.SUPPORT_SMB2 = False |
14 | 14 | info = getConnectionInfo() |
15 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
15 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
16 | 16 | assert conn.connect(info['server_ip'], info['server_port']) |
17 | 17 | |
18 | 18 | def setup_func_SMB2(): |
19 | 19 | global conn |
20 | 20 | smb_structs.SUPPORT_SMB2 = True |
21 | 21 | info = getConnectionInfo() |
22 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
22 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
23 | 23 | assert conn.connect(info['server_ip'], info['server_port']) |
24 | 24 | |
25 | 25 | def teardown_func(): |
26 | 26 | global conn |
27 | 27 | conn.close() |
28 | 28 | |
29 | @with_setup(setup_func_SMB1, teardown_func) | |
29 | @with_setup(setup_func_SMB1) | |
30 | @with_teardown(teardown_func) | |
30 | 31 | def test_rename_english_file_SMB1(): |
31 | 32 | global conn |
32 | 33 | |
49 | 50 | |
50 | 51 | conn.deleteFiles('smbtest', new_path) |
51 | 52 | |
52 | @with_setup(setup_func_SMB2, teardown_func) | |
53 | @with_setup(setup_func_SMB2) | |
54 | @with_teardown(teardown_func) | |
53 | 55 | def test_rename_english_file_SMB2(): |
54 | 56 | global conn |
55 | 57 | |
72 | 74 | |
73 | 75 | conn.deleteFiles('smbtest', new_path) |
74 | 76 | |
75 | @with_setup(setup_func_SMB1, teardown_func) | |
77 | @with_setup(setup_func_SMB1) | |
78 | @with_teardown(teardown_func) | |
76 | 79 | def test_rename_unicode_file_SMB1(): |
77 | 80 | global conn |
78 | 81 | |
95 | 98 | |
96 | 99 | conn.deleteFiles('smbtest', new_path) |
97 | 100 | |
98 | @with_setup(setup_func_SMB2, teardown_func) | |
101 | @with_setup(setup_func_SMB2) | |
102 | @with_teardown(teardown_func) | |
99 | 103 | def test_rename_unicode_file_SMB2(): |
100 | 104 | global conn |
101 | 105 | |
118 | 122 | |
119 | 123 | conn.deleteFiles('smbtest', new_path) |
120 | 124 | |
121 | @with_setup(setup_func_SMB1, teardown_func) | |
125 | @with_setup(setup_func_SMB1) | |
126 | @with_teardown(teardown_func) | |
122 | 127 | def test_rename_english_directory_SMB1(): |
123 | 128 | global conn |
124 | 129 | |
141 | 146 | |
142 | 147 | conn.deleteDirectory('smbtest', new_path) |
143 | 148 | |
144 | @with_setup(setup_func_SMB2, teardown_func) | |
149 | @with_setup(setup_func_SMB2) | |
150 | @with_teardown(teardown_func) | |
145 | 151 | def test_rename_english_directory_SMB2(): |
146 | 152 | global conn |
147 | 153 | |
164 | 170 | |
165 | 171 | conn.deleteDirectory('smbtest', new_path) |
166 | 172 | |
167 | @with_setup(setup_func_SMB1, teardown_func) | |
173 | @with_setup(setup_func_SMB1) | |
174 | @with_teardown(teardown_func) | |
168 | 175 | def test_rename_unicode_directory_SMB1(): |
169 | 176 | global conn |
170 | 177 | |
187 | 194 | |
188 | 195 | conn.deleteDirectory('smbtest', new_path) |
189 | 196 | |
190 | @with_setup(setup_func_SMB2, teardown_func) | |
197 | @with_setup(setup_func_SMB2) | |
198 | @with_teardown(teardown_func) | |
191 | 199 | def test_rename_unicode_directory_SMB2(): |
192 | 200 | global conn |
193 | 201 |
1 | 1 | |
2 | 2 | import os, tempfile |
3 | 3 | from io import BytesIO |
4 | from nose2.tools.decorators import with_setup, with_teardown | |
4 | 5 | from smb.SMBConnection import SMBConnection |
6 | from smb import smb_structs | |
5 | 7 | from .util import getConnectionInfo |
6 | from nose.tools import with_setup | |
7 | from smb import smb_structs | |
8 | 8 | |
9 | 9 | try: |
10 | 10 | import hashlib |
19 | 19 | global conn |
20 | 20 | smb_structs.SUPPORT_SMB2 = False |
21 | 21 | info = getConnectionInfo() |
22 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
22 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
23 | 23 | assert conn.connect(info['server_ip'], info['server_port']) |
24 | 24 | |
25 | 25 | def setup_func_SMB2(): |
26 | 26 | global conn |
27 | 27 | smb_structs.SUPPORT_SMB2 = True |
28 | 28 | info = getConnectionInfo() |
29 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
29 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
30 | 30 | assert conn.connect(info['server_ip'], info['server_port']) |
31 | 31 | |
32 | 32 | def teardown_func(): |
33 | 33 | global conn |
34 | 34 | conn.close() |
35 | 35 | |
36 | @with_setup(setup_func_SMB1, teardown_func) | |
36 | @with_setup(setup_func_SMB1) | |
37 | @with_teardown(teardown_func) | |
37 | 38 | def test_retr_multiplereads_SMB1(): |
38 | 39 | # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes) |
39 | 40 | global conn |
47 | 48 | |
48 | 49 | temp_fh.close() |
49 | 50 | |
50 | @with_setup(setup_func_SMB2, teardown_func) | |
51 | @with_setup(setup_func_SMB2) | |
52 | @with_teardown(teardown_func) | |
51 | 53 | def test_retr_multiplereads_SMB2(): |
52 | 54 | # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes) |
53 | 55 | global conn |
61 | 63 | |
62 | 64 | temp_fh.close() |
63 | 65 | |
64 | @with_setup(setup_func_SMB1, teardown_func) | |
66 | @with_setup(setup_func_SMB1) | |
67 | @with_teardown(teardown_func) | |
65 | 68 | def test_retr_longfilename_SMB1(): |
66 | 69 | # Test file retrieval that has a long English filename |
67 | 70 | global conn |
75 | 78 | |
76 | 79 | temp_fh.close() |
77 | 80 | |
78 | @with_setup(setup_func_SMB2, teardown_func) | |
81 | @with_setup(setup_func_SMB2) | |
82 | @with_teardown(teardown_func) | |
79 | 83 | def test_retr_longfilename_SMB2(): |
80 | 84 | # Test file retrieval that has a long English filename |
81 | 85 | global conn |
89 | 93 | |
90 | 94 | temp_fh.close() |
91 | 95 | |
92 | @with_setup(setup_func_SMB1, teardown_func) | |
96 | @with_setup(setup_func_SMB1) | |
97 | @with_teardown(teardown_func) | |
93 | 98 | def test_retr_unicodefilename_SMB1(): |
94 | 99 | # Test file retrieval that has a long non-English filename inside a folder with a non-English name |
95 | 100 | global conn |
103 | 108 | |
104 | 109 | temp_fh.close() |
105 | 110 | |
106 | @with_setup(setup_func_SMB2, teardown_func) | |
111 | @with_setup(setup_func_SMB2) | |
112 | @with_teardown(teardown_func) | |
107 | 113 | def test_retr_unicodefilename_SMB2(): |
108 | 114 | # Test file retrieval that has a long non-English filename inside a folder with a non-English name |
109 | 115 | global conn |
117 | 123 | |
118 | 124 | temp_fh.close() |
119 | 125 | |
120 | @with_setup(setup_func_SMB1, teardown_func) | |
126 | @with_setup(setup_func_SMB1) | |
127 | @with_teardown(teardown_func) | |
121 | 128 | def test_retr_offset_SMB1(): |
122 | 129 | # Test file retrieval from offset to EOF |
123 | 130 | global conn |
131 | 138 | |
132 | 139 | temp_fh.close() |
133 | 140 | |
134 | @with_setup(setup_func_SMB2, teardown_func) | |
141 | @with_setup(setup_func_SMB2) | |
142 | @with_teardown(teardown_func) | |
135 | 143 | def test_retr_offset_SMB2(): |
136 | 144 | # Test file retrieval from offset to EOF |
137 | 145 | global conn |
145 | 153 | |
146 | 154 | temp_fh.close() |
147 | 155 | |
148 | @with_setup(setup_func_SMB1, teardown_func) | |
156 | @with_setup(setup_func_SMB1) | |
157 | @with_teardown(teardown_func) | |
149 | 158 | def test_retr_offset_and_biglimit_SMB1(): |
150 | 159 | # Test file retrieval from offset with a big max_length |
151 | 160 | global conn |
159 | 168 | |
160 | 169 | temp_fh.close() |
161 | 170 | |
162 | @with_setup(setup_func_SMB2, teardown_func) | |
171 | @with_setup(setup_func_SMB2) | |
172 | @with_teardown(teardown_func) | |
163 | 173 | def test_retr_offset_and_biglimit_SMB2(): |
164 | 174 | # Test file retrieval from offset with a big max_length |
165 | 175 | global conn |
173 | 183 | |
174 | 184 | temp_fh.close() |
175 | 185 | |
176 | @with_setup(setup_func_SMB1, teardown_func) | |
186 | @with_setup(setup_func_SMB1) | |
187 | @with_teardown(teardown_func) | |
177 | 188 | def test_retr_offset_and_smalllimit_SMB1(): |
178 | 189 | # Test file retrieval from offset with a small max_length |
179 | 190 | global conn |
187 | 198 | |
188 | 199 | temp_fh.close() |
189 | 200 | |
190 | @with_setup(setup_func_SMB2, teardown_func) | |
201 | @with_setup(setup_func_SMB2) | |
202 | @with_teardown(teardown_func) | |
191 | 203 | def test_retr_offset_and_smalllimit_SMB2(): |
192 | 204 | # Test file retrieval from offset with a small max_length |
193 | 205 | global conn |
201 | 213 | |
202 | 214 | temp_fh.close() |
203 | 215 | |
204 | @with_setup(setup_func_SMB1, teardown_func) | |
216 | @with_setup(setup_func_SMB1) | |
217 | @with_teardown(teardown_func) | |
205 | 218 | def test_retr_offset_and_zerolimit_SMB1(): |
206 | 219 | # Test file retrieval from offset to EOF with max_length=0 |
207 | 220 | global conn |
215 | 228 | |
216 | 229 | temp_fh.close() |
217 | 230 | |
218 | @with_setup(setup_func_SMB2, teardown_func) | |
231 | @with_setup(setup_func_SMB2) | |
232 | @with_teardown(teardown_func) | |
219 | 233 | def test_retr_offset_and_zerolimit_SMB2(): |
220 | 234 | # Test file retrieval from offset to EOF with max_length=0 |
221 | 235 | global conn |
1 | 1 | |
2 | 2 | import os, tempfile, random, time |
3 | 3 | from io import BytesIO |
4 | from nose2.tools.decorators import with_setup, with_teardown | |
4 | 5 | from smb.SMBConnection import SMBConnection |
6 | from smb import smb_structs | |
5 | 7 | from .util import getConnectionInfo |
6 | from nose.tools import with_setup | |
7 | from smb import smb_structs | |
8 | 8 | |
9 | 9 | try: |
10 | 10 | import hashlib |
24 | 24 | smb_structs.SUPPORT_SMB2 = False |
25 | 25 | |
26 | 26 | info = getConnectionInfo() |
27 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
27 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
28 | 28 | assert conn.connect(info['server_ip'], info['server_port']) |
29 | 29 | |
30 | 30 | def setup_func_SMB2(): |
32 | 32 | smb_structs.SUPPORT_SMB2 = True |
33 | 33 | |
34 | 34 | info = getConnectionInfo() |
35 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
35 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True) | |
36 | 36 | assert conn.connect(info['server_ip'], info['server_port']) |
37 | 37 | |
38 | 38 | def teardown_func(): |
40 | 40 | conn.close() |
41 | 41 | |
42 | 42 | |
43 | @with_setup(setup_func_SMB1, teardown_func) | |
43 | @with_setup(setup_func_SMB1) | |
44 | @with_teardown(teardown_func) | |
44 | 45 | def test_store_long_filename_SMB1(): |
45 | 46 | filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) |
46 | 47 | |
63 | 64 | conn.deleteFiles('smbtest', filename) |
64 | 65 | |
65 | 66 | |
66 | @with_setup(setup_func_SMB2, teardown_func) | |
67 | @with_setup(setup_func_SMB2) | |
68 | @with_teardown(teardown_func) | |
67 | 69 | def test_store_long_filename_SMB2(): |
68 | 70 | filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) |
69 | 71 | |
86 | 88 | conn.deleteFiles('smbtest', filename) |
87 | 89 | |
88 | 90 | |
89 | @with_setup(setup_func_SMB1, teardown_func) | |
91 | @with_setup(setup_func_SMB1) | |
92 | @with_teardown(teardown_func) | |
90 | 93 | def test_store_unicode_filename_SMB1(): |
91 | 94 | filename = os.sep + '上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) |
92 | 95 | |
109 | 112 | conn.deleteFiles('smbtest', filename) |
110 | 113 | |
111 | 114 | |
112 | @with_setup(setup_func_SMB2, teardown_func) | |
115 | @with_setup(setup_func_SMB2) | |
116 | @with_teardown(teardown_func) | |
113 | 117 | def test_store_unicode_filename_SMB2(): |
114 | 118 | filename = os.sep + '上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) |
115 | 119 |
0 | ||
1 | from nose.twistedtools import reactor, deferred | |
2 | from twisted.internet import defer | |
3 | from smb.SMBProtocol import SMBProtocolFactory | |
4 | from smb import smb_structs | |
5 | from .util import getConnectionInfo | |
6 | ||
7 | ||
8 | class AuthFactory(SMBProtocolFactory): | |
9 | ||
10 | def __init__(self, *args, **kwargs): | |
11 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
12 | self.d = defer.Deferred() | |
13 | self.d.addBoth(self.testDone) | |
14 | ||
15 | def testDone(self, r): | |
16 | if self.instance: | |
17 | self.instance.transport.loseConnection() | |
18 | return r | |
19 | ||
20 | def onAuthOK(self): | |
21 | self.d.callback(True) | |
22 | ||
23 | def onAuthFailed(self): | |
24 | self.d.callback(False) | |
25 | ||
26 | ||
27 | @deferred(timeout=5.0) | |
28 | def test_NTLMv1_auth_SMB1(): | |
29 | def result(auth_passed): | |
30 | assert auth_passed | |
31 | ||
32 | smb_structs.SUPPORT_SMB2 = False | |
33 | info = getConnectionInfo() | |
34 | factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False) | |
35 | factory.d.addCallback(result) | |
36 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
37 | return factory.d | |
38 | ||
39 | ||
40 | @deferred(timeout=5.0) | |
41 | def test_NTLMv2_auth_SMB1(): | |
42 | def result(auth_passed): | |
43 | assert auth_passed | |
44 | ||
45 | smb_structs.SUPPORT_SMB2 = False | |
46 | info = getConnectionInfo() | |
47 | factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
48 | factory.d.addCallback(result) | |
49 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
50 | return factory.d | |
51 | ||
52 | ||
53 | @deferred(timeout=5.0) | |
54 | def test_NTLMv1_auth_SMB2(): | |
55 | def result(auth_passed): | |
56 | assert auth_passed | |
57 | ||
58 | smb_structs.SUPPORT_SMB2 = True | |
59 | info = getConnectionInfo() | |
60 | factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False) | |
61 | factory.d.addCallback(result) | |
62 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
63 | return factory.d | |
64 | ||
65 | ||
66 | @deferred(timeout=5.0) | |
67 | def test_NTLMv2_auth_SMB2(): | |
68 | def result(auth_passed): | |
69 | assert auth_passed | |
70 | ||
71 | smb_structs.SUPPORT_SMB2 = True | |
72 | info = getConnectionInfo() | |
73 | factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
74 | factory.d.addCallback(result) | |
75 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
76 | return factory.d |
0 | # -*- coding: utf-8 -*- | |
1 | ||
2 | import os, random, time | |
3 | from nose.twistedtools import reactor, deferred | |
4 | from twisted.internet import defer | |
5 | from smb.SMBProtocol import SMBProtocolFactory | |
6 | from smb import smb_structs | |
7 | from .util import getConnectionInfo | |
8 | ||
9 | ||
10 | class DirectoryFactory(SMBProtocolFactory): | |
11 | ||
12 | def __init__(self, *args, **kwargs): | |
13 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
14 | self.d = defer.Deferred() | |
15 | self.d.addBoth(self.testDone) | |
16 | self.service_name = '' | |
17 | self.path = '' | |
18 | ||
19 | def testDone(self, r): | |
20 | if self.instance: | |
21 | self.instance.transport.loseConnection() | |
22 | return r | |
23 | ||
24 | def createDone(self, result): | |
25 | d = self.listPath(self.service_name, os.path.dirname(self.path.replace('/', os.sep))) | |
26 | d.addCallback(self.listComplete) | |
27 | d.addErrback(self.d.errback) | |
28 | ||
29 | def listComplete(self, entries): | |
30 | names = [e.filename for e in entries] | |
31 | assert os.path.basename(self.path.replace('/', os.sep)) in names | |
32 | ||
33 | d = self.deleteDirectory(self.service_name, self.path) | |
34 | d.addCallback(self.deleteDone) | |
35 | d.addErrback(self.d.errback) | |
36 | ||
37 | def deleteDone(self, result): | |
38 | d = self.listPath(self.service_name, os.path.dirname(self.path.replace('/', os.sep))) | |
39 | d.addCallback(self.list2Complete) | |
40 | d.addErrback(self.d.errback) | |
41 | ||
42 | def list2Complete(self, entries): | |
43 | names = [e.filename for e in entries] | |
44 | assert os.path.basename(self.path.replace('/', os.sep)) not in names | |
45 | self.d.callback(True) | |
46 | ||
47 | def onAuthOK(self): | |
48 | d = self.createDirectory(self.service_name, self.path) | |
49 | d.addCallback(self.createDone) | |
50 | d.addErrback(self.d.errback) | |
51 | ||
52 | def onAuthFailed(self): | |
53 | self.d.errback('Auth failed') | |
54 | ||
55 | ||
56 | @deferred(timeout=15.0) | |
57 | def test_english_directory_SMB1(): | |
58 | info = getConnectionInfo() | |
59 | smb_structs.SUPPORT_SMB2 = False | |
60 | ||
61 | factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
62 | factory.service_name = 'smbtest' | |
63 | factory.path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
64 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
65 | return factory.d | |
66 | ||
67 | @deferred(timeout=15.0) | |
68 | def test_english_directory_SMB2(): | |
69 | info = getConnectionInfo() | |
70 | smb_structs.SUPPORT_SMB2 = True | |
71 | ||
72 | factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
73 | factory.service_name = 'smbtest' | |
74 | factory.path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
75 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
76 | return factory.d | |
77 | ||
78 | @deferred(timeout=15.0) | |
79 | def test_unicode_directory_SMB1(): | |
80 | info = getConnectionInfo() | |
81 | smb_structs.SUPPORT_SMB2 = False | |
82 | ||
83 | factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
84 | factory.service_name = 'smbtest' | |
85 | factory.path = os.sep + '文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
86 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
87 | return factory.d | |
88 | ||
89 | @deferred(timeout=15.0) | |
90 | def test_unicode_directory_SMB2(): | |
91 | info = getConnectionInfo() | |
92 | smb_structs.SUPPORT_SMB2 = True | |
93 | ||
94 | factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
95 | factory.service_name = 'smbtest' | |
96 | factory.path = os.sep + '文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
97 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
98 | return factory.d |
0 | ||
1 | from nose.twistedtools import reactor, deferred | |
2 | from twisted.internet import defer | |
3 | from smb.SMBProtocol import SMBProtocolFactory | |
4 | from .util import getConnectionInfo | |
5 | ||
6 | ||
7 | class EchoFactory(SMBProtocolFactory): | |
8 | ||
9 | def __init__(self, *args, **kwargs): | |
10 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
11 | self.d = defer.Deferred() | |
12 | self.d.addBoth(self.testDone) | |
13 | self.echo_data = 'This is an echo test' | |
14 | ||
15 | def testDone(self, r): | |
16 | if self.instance: | |
17 | self.instance.transport.loseConnection() | |
18 | return r | |
19 | ||
20 | def onAuthOK(self): | |
21 | def cb(data): | |
22 | assert data == self.echo_data | |
23 | self.d.callback(True) | |
24 | ||
25 | d = self.echo(self.echo_data) | |
26 | d.addCallback(cb) | |
27 | d.addErrback(self.d.errback) | |
28 | ||
29 | def onAuthFailed(self): | |
30 | self.d.errback('Auth failed') | |
31 | ||
32 | ||
33 | @deferred(timeout=15.0) | |
34 | def test_echo(): | |
35 | info = getConnectionInfo() | |
36 | factory = EchoFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
37 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
38 | return factory.d |
0 | ||
1 | from nose.twistedtools import reactor, deferred | |
2 | from twisted.internet import defer | |
3 | from smb.SMBProtocol import SMBProtocolFactory | |
4 | from smb import smb_structs | |
5 | from .util import getConnectionInfo | |
6 | ||
7 | ||
8 | class ListPathFactory(SMBProtocolFactory): | |
9 | ||
10 | def __init__(self, *args, **kwargs): | |
11 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
12 | self.d = defer.Deferred() | |
13 | self.d.addBoth(self.testDone) | |
14 | ||
15 | def testDone(self, r): | |
16 | if self.instance: | |
17 | self.instance.transport.loseConnection() | |
18 | return r | |
19 | ||
20 | def onAuthOK(self): | |
21 | def cb(results): | |
22 | filenames = [( r.filename, r.isDirectory ) for r in results] | |
23 | assert ( '\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames # Test non-English folder names | |
24 | assert ( 'Test Folder with Long Name', True ) in filenames # Test long English folder names | |
25 | assert ( 'TestDir1', True ) in filenames # Test short English folder names | |
26 | assert ( 'Implementing CIFS - SMB.html', False ) in filenames # Test long English file names | |
27 | assert ( 'rfc1001.txt', False ) in filenames # Test short English file names | |
28 | ||
29 | self.d.callback(True) | |
30 | ||
31 | d = self.listPath('smbtest', '/', timeout = 15) | |
32 | d.addCallback(cb) | |
33 | d.addErrback(self.d.errback) | |
34 | ||
35 | def onAuthFailed(self): | |
36 | self.d.errback('Auth failed') | |
37 | ||
38 | ||
39 | @deferred(timeout=15.0) | |
40 | def test_listPath_SMB1(): | |
41 | info = getConnectionInfo() | |
42 | smb_structs.SUPPORT_SMB2 = False | |
43 | ||
44 | factory = ListPathFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
45 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
46 | return factory.d | |
47 | ||
48 | @deferred(timeout=15.0) | |
49 | def test_listPath_SMB2(): | |
50 | info = getConnectionInfo() | |
51 | smb_structs.SUPPORT_SMB2 = True | |
52 | ||
53 | factory = ListPathFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
54 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
55 | return factory.d |
0 | ||
1 | from nose.twistedtools import reactor, deferred | |
2 | from twisted.internet import defer | |
3 | from smb.SMBProtocol import SMBProtocolFactory | |
4 | from smb import smb_structs | |
5 | from .util import getConnectionInfo | |
6 | ||
7 | ||
8 | class ListSharesFactory(SMBProtocolFactory): | |
9 | ||
10 | def __init__(self, *args, **kwargs): | |
11 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
12 | self.d = defer.Deferred() | |
13 | self.d.addBoth(self.testDone) | |
14 | ||
15 | def testDone(self, r): | |
16 | if self.instance: | |
17 | self.instance.transport.loseConnection() | |
18 | return r | |
19 | ||
20 | def onAuthOK(self): | |
21 | def cb(results): | |
22 | assert 'smbtest' in [r.name.lower() for r in results] | |
23 | self.d.callback(True) | |
24 | self.instance.transport.loseConnection() | |
25 | ||
26 | d = self.listShares(timeout = 15) | |
27 | d.addCallback(cb) | |
28 | d.addErrback(self.d.errback) | |
29 | ||
30 | def onAuthFailed(self): | |
31 | self.d.errback('Auth failed') | |
32 | ||
33 | ||
34 | @deferred(timeout=15.0) | |
35 | def test_listshares_SMB1(): | |
36 | info = getConnectionInfo() | |
37 | smb_structs.SUPPORT_SMB2 = False | |
38 | ||
39 | factory = ListSharesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
40 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
41 | return factory.d | |
42 | ||
43 | @deferred(timeout=15.0) | |
44 | def test_listshares_SMB2(): | |
45 | info = getConnectionInfo() | |
46 | smb_structs.SUPPORT_SMB2 = True | |
47 | ||
48 | factory = ListSharesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
49 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
50 | return factory.d |
0 | ||
1 | from nose.twistedtools import reactor, deferred | |
2 | from twisted.internet import defer | |
3 | from smb.SMBProtocol import SMBProtocolFactory | |
4 | from smb import smb_structs | |
5 | from .util import getConnectionInfo | |
6 | ||
7 | ||
8 | class ListSnapshotsFactory(SMBProtocolFactory): | |
9 | ||
10 | def __init__(self, *args, **kwargs): | |
11 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
12 | self.d = defer.Deferred() | |
13 | self.d.addBoth(self.testDone) | |
14 | self.service_name = None | |
15 | self.path = None | |
16 | ||
17 | def testDone(self, r): | |
18 | if self.instance: | |
19 | self.instance.transport.loseConnection() | |
20 | return r | |
21 | ||
22 | def onAuthOK(self): | |
23 | def cb(results): | |
24 | assert len(results) > 0 | |
25 | self.d.callback(True) | |
26 | self.instance.transport.loseConnection() | |
27 | ||
28 | d = self.listSnapshots(self.service_name, self.path, timeout = 15) | |
29 | d.addCallback(cb) | |
30 | d.addErrback(self.d.errback) | |
31 | ||
32 | def onAuthFailed(self): | |
33 | self.d.errback('Auth failed') | |
34 | ||
35 | ||
36 | @deferred(timeout=15.0) | |
37 | def test_listshares_SMB1(): | |
38 | info = getConnectionInfo() | |
39 | smb_structs.SUPPORT_SMB2 = False | |
40 | ||
41 | factory = ListSnapshotsFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
42 | factory.service_name = 'smbtest' | |
43 | factory.path = '/rfc1001.txt' | |
44 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
45 | return factory.d | |
46 | ||
47 | @deferred(timeout=15.0) | |
48 | def test_listshares_SMB2(): | |
49 | info = getConnectionInfo() | |
50 | smb_structs.SUPPORT_SMB2 = True | |
51 | ||
52 | factory = ListSnapshotsFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
53 | factory.service_name = 'smbtest' | |
54 | factory.path = '/rfc1001.txt' | |
55 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
56 | return factory.d |
0 | # -*- coding: utf-8 -*- | |
1 | ||
2 | import os, random, time | |
3 | from io import StringIO | |
4 | from nose.twistedtools import reactor, deferred | |
5 | from twisted.internet import defer | |
6 | from smb.SMBProtocol import SMBProtocolFactory | |
7 | from smb import smb_structs | |
8 | from .util import getConnectionInfo | |
9 | ||
10 | ||
11 | class RenameFactory(SMBProtocolFactory): | |
12 | ||
13 | def __init__(self, *args, **kwargs): | |
14 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
15 | self.d = defer.Deferred() | |
16 | self.d.addBoth(self.testDone) | |
17 | self.service = '' | |
18 | self.new_path = '' | |
19 | self.old_path = '' | |
20 | ||
21 | def testDone(self, r): | |
22 | if self.instance: | |
23 | self.instance.transport.loseConnection() | |
24 | return r | |
25 | ||
26 | def pathCreated(self, result): | |
27 | d = self.listPath(self.service, os.path.dirname(self.old_path.replace('/', os.sep))) | |
28 | d.addCallback(self.listComplete) | |
29 | d.addErrback(self.d.errback) | |
30 | ||
31 | def listComplete(self, entries): | |
32 | filenames = [e.filename for e in entries] | |
33 | assert os.path.basename(self.old_path.replace('/', os.sep)) in filenames | |
34 | assert os.path.basename(self.new_path.replace('/', os.sep)) not in filenames | |
35 | ||
36 | d = self.rename(self.service, self.old_path, self.new_path) | |
37 | d.addCallback(self.renameComplete) | |
38 | d.addErrback(self.d.errback) | |
39 | ||
40 | def renameComplete(self, result): | |
41 | d = self.listPath(self.service, os.path.dirname(self.new_path.replace('/', os.sep))) | |
42 | d.addCallback(self.list2Complete) | |
43 | d.addErrback(self.d.errback) | |
44 | ||
45 | def list2Complete(self, entries): | |
46 | filenames = [e.filename for e in entries] | |
47 | assert os.path.basename(self.new_path.replace('/', os.sep)) in filenames | |
48 | assert os.path.basename(self.old_path.replace('/', os.sep)) not in filenames | |
49 | self.cleanup() | |
50 | ||
51 | def onAuthFailed(self): | |
52 | self.d.errback('Auth failed') | |
53 | ||
54 | ||
55 | class RenameFileFactory(RenameFactory): | |
56 | ||
57 | def onAuthOK(self): | |
58 | d = self.storeFile(self.service, self.old_path, StringIO('Rename file test')) | |
59 | d.addCallback(self.pathCreated) | |
60 | d.addErrback(self.d.errback) | |
61 | ||
62 | def cleanup(self): | |
63 | d = self.deleteFiles(self.service, self.new_path) | |
64 | d.chainDeferred(self.d) | |
65 | ||
66 | ||
67 | class RenameDirectoryFactory(RenameFactory): | |
68 | ||
69 | def onAuthOK(self): | |
70 | d = self.createDirectory(self.service, self.old_path) | |
71 | d.addCallback(self.pathCreated) | |
72 | d.addErrback(self.d.errback) | |
73 | ||
74 | def cleanup(self): | |
75 | d = self.deleteDirectory(self.service, self.new_path) | |
76 | d.chainDeferred(self.d) | |
77 | ||
78 | ||
79 | @deferred(timeout=30.0) | |
80 | def test_rename_english_file_SMB1(): | |
81 | info = getConnectionInfo() | |
82 | smb_structs.SUPPORT_SMB2 = False | |
83 | ||
84 | factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
85 | factory.service = 'smbtest' | |
86 | factory.old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
87 | factory.new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
88 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
89 | return factory.d | |
90 | ||
91 | @deferred(timeout=30.0) | |
92 | def test_rename_english_file_SMB2(): | |
93 | info = getConnectionInfo() | |
94 | smb_structs.SUPPORT_SMB2 = True | |
95 | ||
96 | factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
97 | factory.service = 'smbtest' | |
98 | factory.old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
99 | factory.new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
100 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
101 | return factory.d | |
102 | ||
103 | @deferred(timeout=30.0) | |
104 | def test_rename_unicode_file_SMB1(): | |
105 | info = getConnectionInfo() | |
106 | smb_structs.SUPPORT_SMB2 = False | |
107 | ||
108 | factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
109 | factory.service = 'smbtest' | |
110 | factory.old_path = '/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
111 | factory.new_path = '/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
112 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
113 | return factory.d | |
114 | ||
115 | @deferred(timeout=30.0) | |
116 | def test_rename_unicode_file_SMB2(): | |
117 | info = getConnectionInfo() | |
118 | smb_structs.SUPPORT_SMB2 = True | |
119 | ||
120 | factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
121 | factory.service = 'smbtest' | |
122 | factory.old_path = '/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
123 | factory.new_path = '/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
124 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
125 | return factory.d | |
126 | ||
127 | @deferred(timeout=30.0) | |
128 | def test_rename_english_directory_SMB1(): | |
129 | info = getConnectionInfo() | |
130 | smb_structs.SUPPORT_SMB2 = False | |
131 | ||
132 | factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
133 | factory.service = 'smbtest' | |
134 | factory.old_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
135 | factory.new_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
136 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
137 | return factory.d | |
138 | ||
139 | @deferred(timeout=30.0) | |
140 | def test_rename_english_directory_SMB2(): | |
141 | info = getConnectionInfo() | |
142 | smb_structs.SUPPORT_SMB2 = True | |
143 | ||
144 | factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
145 | factory.service = 'smbtest' | |
146 | factory.old_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
147 | factory.new_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
148 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
149 | return factory.d | |
150 | ||
151 | @deferred(timeout=30.0) | |
152 | def test_rename_unicode_directory_SMB1(): | |
153 | info = getConnectionInfo() | |
154 | smb_structs.SUPPORT_SMB2 = False | |
155 | ||
156 | factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
157 | factory.service = 'smbtest' | |
158 | factory.old_path = '/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
159 | factory.new_path = '/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
160 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
161 | return factory.d | |
162 | ||
163 | @deferred(timeout=30.0) | |
164 | def test_rename_unicode_directory_SMB2(): | |
165 | info = getConnectionInfo() | |
166 | smb_structs.SUPPORT_SMB2 = True | |
167 | ||
168 | factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
169 | factory.service = 'smbtest' | |
170 | factory.old_path = '/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
171 | factory.new_path = '/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
172 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
173 | return factory.d |
0 | # -*- coding: utf-8 -*- | |
1 | ||
2 | import os, tempfile | |
3 | from nose.twistedtools import reactor, deferred | |
4 | from twisted.internet import defer | |
5 | from smb.SMBProtocol import SMBProtocolFactory | |
6 | from smb import smb_structs | |
7 | from .util import getConnectionInfo | |
8 | ||
9 | try: | |
10 | import hashlib | |
11 | def MD5(): return hashlib.md5() | |
12 | except ImportError: | |
13 | import md5 | |
14 | def MD5(): return md5.new() | |
15 | ||
16 | ||
17 | class RetrieveFileFactory(SMBProtocolFactory): | |
18 | ||
19 | def __init__(self, *args, **kwargs): | |
20 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
21 | self.d = defer.Deferred() | |
22 | self.d.addBoth(self.testDone) | |
23 | self.temp_fh = tempfile.NamedTemporaryFile(prefix = 'pysmbtest-') | |
24 | self.service = '' | |
25 | self.path = '' | |
26 | self.digest = '' | |
27 | self.offset = 0 | |
28 | self.max_length = -1 | |
29 | self.filesize = 0 | |
30 | ||
31 | def testDone(self, r): | |
32 | if self.instance: | |
33 | self.instance.transport.loseConnection() | |
34 | return r | |
35 | ||
36 | def fileRetrieved(self, write_result): | |
37 | file_obj, file_attributes, file_size = write_result | |
38 | assert file_obj == self.temp_fh | |
39 | ||
40 | md = MD5() | |
41 | filesize = 0 | |
42 | self.temp_fh.seek(0) | |
43 | while True: | |
44 | s = self.temp_fh.read(8192) | |
45 | if not s: | |
46 | break | |
47 | md.update(s) | |
48 | filesize += len(s) | |
49 | ||
50 | assert self.filesize == filesize | |
51 | assert md.hexdigest() == self.digest | |
52 | ||
53 | self.temp_fh.close() | |
54 | self.d.callback(True) | |
55 | self.instance.transport.loseConnection() | |
56 | ||
57 | def onAuthOK(self): | |
58 | assert self.service | |
59 | assert self.path | |
60 | ||
61 | d = self.retrieveFileFromOffset(self.service, self.path, self.temp_fh, self.offset, self.max_length, timeout = 15) | |
62 | d.addCallback(self.fileRetrieved) | |
63 | d.addErrback(self.d.errback) | |
64 | ||
65 | def onAuthFailed(self): | |
66 | self.d.errback('Auth failed') | |
67 | ||
68 | ||
69 | @deferred(timeout=30.0) | |
70 | def test_retr_multiplereads_SMB1(): | |
71 | # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes) | |
72 | info = getConnectionInfo() | |
73 | smb_structs.SUPPORT_SMB2 = False | |
74 | ||
75 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
76 | factory.service = 'smbtest' | |
77 | factory.path = '/rfc1001.txt' | |
78 | factory.digest = '5367c2bbf97f521059c78eab65309ad3' | |
79 | factory.filesize = 158437 | |
80 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
81 | return factory.d | |
82 | ||
83 | @deferred(timeout=30.0) | |
84 | def test_retr_multiplereads_SMB2(): | |
85 | # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes) | |
86 | info = getConnectionInfo() | |
87 | smb_structs.SUPPORT_SMB2 = True | |
88 | ||
89 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
90 | factory.service = 'smbtest' | |
91 | factory.path = '/rfc1001.txt' | |
92 | factory.digest = '5367c2bbf97f521059c78eab65309ad3' | |
93 | factory.filesize = 158437 | |
94 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
95 | return factory.d | |
96 | ||
97 | @deferred(timeout=30.0) | |
98 | def test_retr_longfilename_SMB1(): | |
99 | # Test file retrieval that has a long English filename | |
100 | info = getConnectionInfo() | |
101 | smb_structs.SUPPORT_SMB2 = False | |
102 | ||
103 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
104 | factory.service = 'smbtest' | |
105 | factory.path = '/Implementing CIFS - SMB.html' | |
106 | factory.digest = '671c5700d279fcbbf958c1bba3c2639e' | |
107 | factory.filesize = 421269 | |
108 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
109 | return factory.d | |
110 | ||
111 | @deferred(timeout=30.0) | |
112 | def test_retr_longfilename_SMB2(): | |
113 | # Test file retrieval that has a long English filename | |
114 | info = getConnectionInfo() | |
115 | smb_structs.SUPPORT_SMB2 = True | |
116 | ||
117 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
118 | factory.service = 'smbtest' | |
119 | factory.path = '/Implementing CIFS - SMB.html' | |
120 | factory.digest = '671c5700d279fcbbf958c1bba3c2639e' | |
121 | factory.filesize = 421269 | |
122 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
123 | return factory.d | |
124 | ||
125 | @deferred(timeout=30.0) | |
126 | def test_retr_unicodefilename_SMB1(): | |
127 | # Test file retrieval that has a long non-English filename inside a folder with a non-English name | |
128 | info = getConnectionInfo() | |
129 | smb_structs.SUPPORT_SMB2 = False | |
130 | ||
131 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
132 | factory.service = 'smbtest' | |
133 | factory.path = '/测试文件夹/垃圾文件.dat' | |
134 | factory.digest = '8a44c1e80d55e91c92350955cdf83442' | |
135 | factory.filesize = 256000 | |
136 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
137 | return factory.d | |
138 | ||
139 | @deferred(timeout=30.0) | |
140 | def test_retr_unicodefilename_SMB2(): | |
141 | # Test file retrieval that has a long non-English filename inside a folder with a non-English name | |
142 | info = getConnectionInfo() | |
143 | smb_structs.SUPPORT_SMB2 = True | |
144 | ||
145 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
146 | factory.service = 'smbtest' | |
147 | factory.path = '/测试文件夹/垃圾文件.dat' | |
148 | factory.digest = '8a44c1e80d55e91c92350955cdf83442' | |
149 | factory.filesize = 256000 | |
150 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
151 | return factory.d | |
152 | ||
153 | @deferred(timeout=30.0) | |
154 | def test_retr_offset_SMB1(): | |
155 | # Test file retrieval from offset to EOF | |
156 | info = getConnectionInfo() | |
157 | smb_structs.SUPPORT_SMB2 = False | |
158 | ||
159 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
160 | factory.service = 'smbtest' | |
161 | factory.path = '/测试文件夹/垃圾文件.dat' | |
162 | factory.digest = 'a141bd8024571ce7cb5c67f2b0d8ea0b' | |
163 | factory.filesize = 156000 | |
164 | factory.offset = 100000 | |
165 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
166 | return factory.d | |
167 | ||
168 | @deferred(timeout=30.0) | |
169 | def test_retr_offset_SMB2(): | |
170 | # Test file retrieval from offset to EOF | |
171 | info = getConnectionInfo() | |
172 | smb_structs.SUPPORT_SMB2 = True | |
173 | ||
174 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
175 | factory.service = 'smbtest' | |
176 | factory.path = '/测试文件夹/垃圾文件.dat' | |
177 | factory.digest = 'a141bd8024571ce7cb5c67f2b0d8ea0b' | |
178 | factory.filesize = 156000 | |
179 | factory.offset = 100000 | |
180 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
181 | return factory.d | |
182 | ||
183 | @deferred(timeout=30.0) | |
184 | def test_retr_offset_and_biglimit_SMB1(): | |
185 | # Test file retrieval from offset with a big max_length | |
186 | info = getConnectionInfo() | |
187 | smb_structs.SUPPORT_SMB2 = False | |
188 | ||
189 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
190 | factory.service = 'smbtest' | |
191 | factory.path = '/测试文件夹/垃圾文件.dat' | |
192 | factory.digest = '83b7afd7c92cdece3975338b5ca0b1c5' | |
193 | factory.filesize = 100000 | |
194 | factory.offset = 100000 | |
195 | factory.max_length = 100000 | |
196 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
197 | return factory.d | |
198 | ||
199 | @deferred(timeout=30.0) | |
200 | def test_retr_offset_and_biglimit_SMB2(): | |
201 | # Test file retrieval from offset with a big max_length | |
202 | info = getConnectionInfo() | |
203 | smb_structs.SUPPORT_SMB2 = True | |
204 | ||
205 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
206 | factory.service = 'smbtest' | |
207 | factory.path = '/测试文件夹/垃圾文件.dat' | |
208 | factory.digest = '83b7afd7c92cdece3975338b5ca0b1c5' | |
209 | factory.filesize = 100000 | |
210 | factory.offset = 100000 | |
211 | factory.max_length = 100000 | |
212 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
213 | return factory.d | |
214 | ||
215 | @deferred(timeout=30.0) | |
216 | def test_retr_offset_and_smalllimit_SMB1(): | |
217 | # Test file retrieval from offset with a small max_length | |
218 | info = getConnectionInfo() | |
219 | smb_structs.SUPPORT_SMB2 = False | |
220 | ||
221 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
222 | factory.service = 'smbtest' | |
223 | factory.path = '/测试文件夹/垃圾文件.dat' | |
224 | factory.digest = '746f60a96b39b712a7b6e17ddde19986' | |
225 | factory.filesize = 10 | |
226 | factory.offset = 100000 | |
227 | factory.max_length = 10 | |
228 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
229 | return factory.d | |
230 | ||
231 | @deferred(timeout=30.0) | |
232 | def test_retr_offset_and_smalllimit_SMB2(): | |
233 | # Test file retrieval from offset with a small max_length | |
234 | info = getConnectionInfo() | |
235 | smb_structs.SUPPORT_SMB2 = True | |
236 | ||
237 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
238 | factory.service = 'smbtest' | |
239 | factory.path = '/测试文件夹/垃圾文件.dat' | |
240 | factory.digest = '746f60a96b39b712a7b6e17ddde19986' | |
241 | factory.filesize = 10 | |
242 | factory.offset = 100000 | |
243 | factory.max_length = 10 | |
244 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
245 | return factory.d | |
246 | ||
247 | @deferred(timeout=30.0) | |
248 | def test_retr_offset_and_zerolimit_SMB1(): | |
249 | # Test file retrieval from offset to EOF with max_length=0 | |
250 | info = getConnectionInfo() | |
251 | smb_structs.SUPPORT_SMB2 = False | |
252 | ||
253 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
254 | factory.service = 'smbtest' | |
255 | factory.path = '/测试文件夹/垃圾文件.dat' | |
256 | factory.digest = 'd41d8cd98f00b204e9800998ecf8427e' | |
257 | factory.filesize = 0 | |
258 | factory.offset = 100000 | |
259 | factory.max_length = 0 | |
260 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
261 | return factory.d | |
262 | ||
263 | @deferred(timeout=30.0) | |
264 | def test_retr_offset_and_zerolimit_SMB2(): | |
265 | # Test file retrieval from offset to EOF with max_length=0 | |
266 | info = getConnectionInfo() | |
267 | smb_structs.SUPPORT_SMB2 = True | |
268 | ||
269 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
270 | factory.service = 'smbtest' | |
271 | factory.path = '/测试文件夹/垃圾文件.dat' | |
272 | factory.digest = 'd41d8cd98f00b204e9800998ecf8427e' | |
273 | factory.filesize = 0 | |
274 | factory.offset = 100000 | |
275 | factory.max_length = 0 | |
276 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
277 | return factory.d |
0 | # -*- coding: utf-8 -*- | |
1 | ||
2 | import os, time, random | |
3 | from io import StringIO | |
4 | from nose.twistedtools import reactor, deferred | |
5 | from twisted.internet import defer | |
6 | from smb.SMBProtocol import SMBProtocolFactory | |
7 | from smb import smb_structs | |
8 | from .util import getConnectionInfo | |
9 | ||
10 | try: | |
11 | import hashlib | |
12 | def MD5(): return hashlib.md5() | |
13 | except ImportError: | |
14 | import md5 | |
15 | def MD5(): return md5.new() | |
16 | ||
17 | class StoreFilesFactory(SMBProtocolFactory): | |
18 | """ | |
19 | A super test factory that tests store file, list files, retrieve file and delete file functionlities in sequence. | |
20 | """ | |
21 | ||
22 | TEST_FILENAME = os.path.join(os.path.dirname(__file__), os.pardir, 'SupportFiles', 'binary.dat') | |
23 | TEST_FILESIZE = 256000 | |
24 | TEST_DIGEST = 'bb6303f76e29f354b6fdf6ef58587e48' | |
25 | ||
26 | def __init__(self, *args, **kwargs): | |
27 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
28 | self.d = defer.Deferred() | |
29 | self.d.addBoth(self.testDone) | |
30 | self.service_name = '' | |
31 | self.filename = '' | |
32 | ||
33 | def testDone(self, r): | |
34 | if self.instance: | |
35 | self.instance.transport.loseConnection() | |
36 | return r | |
37 | ||
38 | def storeComplete(self, result): | |
39 | file_obj, filesize = result | |
40 | file_obj.close() | |
41 | assert filesize == self.TEST_FILESIZE | |
42 | ||
43 | d = self.listPath(self.service_name, os.path.dirname(self.filename.replace('/', os.sep))) | |
44 | d.addCallback(self.listComplete) | |
45 | d.addErrback(self.d.errback) | |
46 | ||
47 | def listComplete(self, entries): | |
48 | filenames = [e.filename for e in entries] | |
49 | assert os.path.basename(self.filename.replace('/', os.sep)) in filenames | |
50 | ||
51 | for entry in entries: | |
52 | if os.path.basename(self.filename.replace('/', os.sep)) == entry.filename: | |
53 | # The following asserts will fail if the remote machine's time is not in sync with the test machine's time | |
54 | assert abs(entry.create_time - time.time()) < 3 | |
55 | assert abs(entry.last_access_time - time.time()) < 3 | |
56 | assert abs(entry.last_write_time - time.time()) < 3 | |
57 | assert abs(entry.last_attr_change_time - time.time()) < 3 | |
58 | break | |
59 | ||
60 | d = self.retrieveFile(self.service_name, self.filename, StringIO()) | |
61 | d.addCallback(self.retrieveComplete) | |
62 | d.addErrback(self.d.errback) | |
63 | ||
64 | def retrieveComplete(self, result): | |
65 | file_obj, file_attributes, file_size = result | |
66 | ||
67 | md = MD5() | |
68 | md.update(file_obj.getvalue()) | |
69 | file_obj.close() | |
70 | ||
71 | assert file_size == self.TEST_FILESIZE | |
72 | assert md.hexdigest() == self.TEST_DIGEST | |
73 | ||
74 | d = self.deleteFiles(self.service_name, self.filename) | |
75 | d.addCallback(self.deleteComplete) | |
76 | d.addErrback(self.d.errback) | |
77 | ||
78 | def deleteComplete(self, result): | |
79 | d = self.listPath(self.service_name, os.path.dirname(self.filename.replace('/', os.sep))) | |
80 | d.addCallback(self.list2Complete) | |
81 | d.addErrback(self.d.errback) | |
82 | ||
83 | def list2Complete(self, entries): | |
84 | filenames = [e.filename for e in entries] | |
85 | assert os.path.basename(self.filename.replace('/', os.sep)) not in filenames | |
86 | self.d.callback(True) | |
87 | self.instance.transport.loseConnection() | |
88 | ||
89 | def onAuthOK(self): | |
90 | d = self.storeFile(self.service_name, self.filename, open(self.TEST_FILENAME, 'rb')) | |
91 | d.addCallback(self.storeComplete) | |
92 | d.addErrback(self.d.errback) | |
93 | ||
94 | def onAuthFailed(self): | |
95 | self.d.errback('Auth failed') | |
96 | ||
97 | ||
98 | @deferred(timeout=30.0) | |
99 | def test_store_long_filename_SMB1(): | |
100 | info = getConnectionInfo() | |
101 | smb_structs.SUPPORT_SMB2 = False | |
102 | ||
103 | factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
104 | factory.service_name = 'smbtest' | |
105 | factory.filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) | |
106 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
107 | return factory.d | |
108 | ||
109 | @deferred(timeout=30.0) | |
110 | def test_store_long_filename_SMB2(): | |
111 | info = getConnectionInfo() | |
112 | smb_structs.SUPPORT_SMB2 = True | |
113 | ||
114 | factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
115 | factory.service_name = 'smbtest' | |
116 | factory.filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) | |
117 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
118 | return factory.d | |
119 | ||
120 | @deferred(timeout=30.0) | |
121 | def test_store_unicode_filename_SMB1(): | |
122 | info = getConnectionInfo() | |
123 | smb_structs.SUPPORT_SMB2 = False | |
124 | ||
125 | factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
126 | factory.service_name = 'smbtest' | |
127 | factory.filename = os.sep + '上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) | |
128 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
129 | return factory.d | |
130 | ||
131 | @deferred(timeout=30.0) | |
132 | def test_store_unicode_filename_SMB2(): | |
133 | info = getConnectionInfo() | |
134 | smb_structs.SUPPORT_SMB2 = True | |
135 | ||
136 | factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
137 | factory.service_name = 'smbtest' | |
138 | factory.filename = os.sep + '上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) | |
139 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
140 | return factory.d |
0 | ||
1 | import os | |
2 | from ConfigParser import SafeConfigParser | |
3 | ||
4 | def getConnectionInfo(): | |
5 | config_filename = os.path.join(os.path.dirname(__file__), os.path.pardir, 'connection.ini') | |
6 | cp = SafeConfigParser() | |
7 | cp.read(config_filename) | |
8 | ||
9 | info = { | |
10 | 'server_name': cp.get('server', 'name'), | |
11 | 'server_ip': cp.get('server', 'ip'), | |
12 | 'server_port': cp.getint('server', 'direct_port'), | |
13 | 'client_name': cp.get('client', 'name'), | |
14 | 'user': cp.get('user', 'name'), | |
15 | 'password': cp.get('user', 'password'), | |
16 | 'is_direct_tcp': True, | |
17 | } | |
18 | return info |
0 | 0 | |
1 | 1 | from nmb.NetBIOS import NetBIOS |
2 | from nose.tools import with_setup | |
2 | from nose2.tools.decorators import with_teardown | |
3 | 3 | |
4 | 4 | conn = None |
5 | 5 | |
7 | 7 | global conn |
8 | 8 | conn.close() |
9 | 9 | |
10 | @with_setup(teardown = teardown_func) | |
10 | @with_teardown(teardown_func) | |
11 | 11 | def test_broadcast(): |
12 | 12 | global conn |
13 | 13 | conn = NetBIOS() |
0 | ||
1 | from nose.twistedtools import reactor, deferred | |
2 | from twisted.internet import defer | |
3 | from nmb.NetBIOSProtocol import NBNSProtocol | |
4 | from nose.tools import with_setup | |
5 | ||
6 | ||
7 | @deferred(timeout=15.0) | |
8 | def test_broadcast(): | |
9 | def cb(results): | |
10 | assert results | |
11 | ||
12 | def cleanup(r): | |
13 | p.transport.stopListening() | |
14 | ||
15 | p = NBNSProtocol() | |
16 | d = p.queryName('MICHAEL-I5PC', timeout = 10) | |
17 | d.addCallback(cb) | |
18 | d.addBoth(cleanup) | |
19 | ||
20 | return d |
0 | ||
1 | Steps to Follow to Run the Unit Tests | |
2 | ===================================== | |
3 | ||
4 | ## Step 1: Install system dependencies ## | |
5 | ||
6 | If you are using Ubuntu 20.04 LTS, you can install the system dependencies with the following command | |
7 | ``` | |
8 | $> apt-get install python3-dev python3-venv gcc g++ make automake autoconf | |
9 | ``` | |
10 | For other distributions, you can use their package managers and install the system dependencies (although the package names might differ slightly). | |
11 | ||
12 | ## Step 2: Setup python virtualenv ## | |
13 | ||
14 | We will create a python3 virtualenv and install the python dependencies for testing in the "venv3" folder. | |
15 | ||
16 | ``` | |
17 | $> cd <pysmb-home>/python3 | |
18 | $> virtualenv -p /usr/bin/python3 venv3 | |
19 | $> source venv3/bin/activate | |
20 | $venv3> pip install nose2 pyasn1 twisted | |
21 | ``` | |
22 | ||
23 | ## Step 3: Setup shared folder on your remote SMB server ## | |
24 | ||
25 | Prepare a shared folder called "smbtest" on your remote SMB server (Windows or Samba). | |
26 | ||
27 | Then, download [smbtest.zip](https://miketeo.net/files/Projects/pysmb/smbtest.zip) and unzip the contents of this zip file in the shared folder. | |
28 | ||
29 | You should also configure a user on the SMB server with read-write access to the "smbtest" folder. | |
30 | ||
31 | ## Step 4: Update connection details in connection.ini ## | |
32 | ||
33 | In the same folder where you are viewing this readme file, there should be an ini file called "connection.ini". Edit this file's connection details to match the shared folder's access information. | |
34 | ||
35 | ## Step 5: Run the unit tests in the python3 folder ## | |
36 | ||
37 | Before running the tests, the venv3 virtualenv must be activated. | |
38 | ``` | |
39 | $> cd <pysmb-home>/python3 | |
40 | $> source venv3/bin/activate | |
41 | ``` | |
42 | ||
43 | To run all the tests: | |
44 | ``` | |
45 | $venv3> nose2 -v tests | |
46 | ``` | |
47 | ||
48 | To selectively run some tests: | |
49 | ``` | |
50 | $venv3> nose2 -v tests.SMBConnectionTests | |
51 | $venv3> nose2 -v tests.SMBConnectionTests.test_rename | |
52 | $venv3> nose2 -v tests.SMBConnectionTests.test_rename.test_rename_english_file_SMB1 | |
53 | ``` | |
54 | For more information, please consult the [documentation for nose2](https://docs.nose2.io/). | |
55 | ||
56 |
1 | 1 | |
2 | 2 | import os, urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse, time, random |
3 | 3 | from smb.SMBHandler import SMBHandler |
4 | from . import util | |
4 | import util | |
5 | 5 | |
6 | 6 | |
7 | 7 | try: |
0 | 0 | |
1 | from nose2.tools.decorators import with_teardown | |
1 | 2 | from smb.SMBConnection import SMBConnection |
3 | from smb import smb_structs | |
2 | 4 | from .util import getConnectionInfo |
3 | from nose.tools import with_setup | |
4 | from smb import smb_structs | |
5 | 5 | |
6 | 6 | conn = None |
7 | 7 | |
9 | 9 | global conn |
10 | 10 | conn.close() |
11 | 11 | |
12 | @with_setup(teardown = teardown_func) | |
12 | @with_teardown(teardown_func) | |
13 | 13 | def test_NTLMv1_auth_SMB1(): |
14 | 14 | global conn |
15 | 15 | smb_structs.SUPPORT_SMB2 = False |
17 | 17 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = False) |
18 | 18 | assert conn.connect(info['server_ip'], info['server_port']) |
19 | 19 | |
20 | @with_setup(teardown = teardown_func) | |
20 | @with_teardown(teardown_func) | |
21 | 21 | def test_NTLMv2_auth_SMB1(): |
22 | 22 | global conn |
23 | 23 | smb_structs.SUPPORT_SMB2 = False |
25 | 25 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = True) |
26 | 26 | assert conn.connect(info['server_ip'], info['server_port']) |
27 | 27 | |
28 | @with_setup(teardown = teardown_func) | |
28 | @with_teardown(teardown_func) | |
29 | 29 | def test_NTLMv1_auth_SMB2(): |
30 | 30 | global conn |
31 | 31 | smb_structs.SUPPORT_SMB2 = True |
33 | 33 | conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = False) |
34 | 34 | assert conn.connect(info['server_ip'], info['server_port']) |
35 | 35 | |
36 | @with_setup(teardown = teardown_func) | |
36 | @with_teardown(teardown_func) | |
37 | 37 | def test_NTLMv2_auth_SMB2(): |
38 | 38 | global conn |
39 | 39 | smb_structs.SUPPORT_SMB2 = True |
0 | 0 | # -*- coding: utf-8 -*- |
1 | 1 | |
2 | 2 | import os, time, random |
3 | from nose2.tools.decorators import with_setup, with_teardown | |
3 | 4 | from smb.SMBConnection import SMBConnection |
5 | from smb import smb_structs | |
4 | 6 | from .util import getConnectionInfo |
5 | from nose.tools import with_setup | |
6 | from smb import smb_structs | |
7 | 7 | |
8 | 8 | conn = None |
9 | 9 | |
27 | 27 | global conn |
28 | 28 | conn.close() |
29 | 29 | |
30 | @with_setup(setup_func_SMB1, teardown_func) | |
30 | @with_setup(setup_func_SMB1) | |
31 | @with_teardown(teardown_func) | |
31 | 32 | def test_english_directory_SMB1(): |
32 | 33 | global conn |
33 | 34 | |
44 | 45 | names = [e.filename for e in entries] |
45 | 46 | assert os.path.basename(path.replace('/', os.sep)) not in names |
46 | 47 | |
47 | @with_setup(setup_func_SMB2, teardown_func) | |
48 | @with_setup(setup_func_SMB2) | |
49 | @with_teardown(teardown_func) | |
48 | 50 | def test_english_directory_SMB2(): |
49 | 51 | global conn |
50 | 52 | |
61 | 63 | names = [e.filename for e in entries] |
62 | 64 | assert os.path.basename(path.replace('/', os.sep)) not in names |
63 | 65 | |
64 | @with_setup(setup_func_SMB1, teardown_func) | |
66 | @with_setup(setup_func_SMB1) | |
67 | @with_teardown(teardown_func) | |
65 | 68 | def test_unicode_directory_SMB1(): |
66 | 69 | global conn |
67 | 70 | |
78 | 81 | names = [e.filename for e in entries] |
79 | 82 | assert os.path.basename(path.replace('/', os.sep)) not in names |
80 | 83 | |
81 | @with_setup(setup_func_SMB2, teardown_func) | |
84 | @with_setup(setup_func_SMB2) | |
85 | @with_teardown(teardown_func) | |
82 | 86 | def test_unicode_directory_SMB2(): |
83 | 87 | global conn |
84 | 88 |
1 | 1 | |
2 | 2 | import os, time, random |
3 | 3 | from io import BytesIO |
4 | from nose2.tools.decorators import with_setup, with_teardown | |
4 | 5 | from smb.SMBConnection import SMBConnection |
6 | from smb import smb_structs | |
5 | 7 | from .util import getConnectionInfo |
6 | from nose.tools import with_setup | |
7 | from smb import smb_structs | |
8 | 8 | |
9 | 9 | conn = None |
10 | 10 | |
28 | 28 | global conn |
29 | 29 | conn.close() |
30 | 30 | |
31 | @with_setup(setup_func_SMB1, teardown_func) | |
32 | def test_delete_SMB1(): | |
33 | global conn | |
34 | ||
35 | path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
36 | conn.createDirectory('smbtest', path) | |
37 | ||
38 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
39 | conn.storeFile('smbtest', path+"/"+filename, BytesIO(b"0123456789")) | |
40 | ||
41 | results = conn.listPath('smbtest', path) | |
42 | filenames = list(map(lambda r: r.filename, results)) | |
31 | @with_setup(setup_func_SMB1) | |
32 | @with_teardown(teardown_func) | |
33 | def test_delete_without_subfolder_SMB1(): | |
34 | global conn | |
35 | ||
36 | path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
37 | conn.createDirectory('smbtest', path) | |
38 | ||
39 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
40 | conn.storeFile('smbtest', path+"/"+filename, BytesIO(b"0123456789")) | |
41 | ||
42 | for p in [ 'aaTest.Folder', 'aaTest.Folder/xyz', 'bbTest.Folder' ]: | |
43 | conn.createDirectory('smbtest', path+"/"+p) | |
44 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
45 | conn.storeFile('smbtest', path+"/"+p+"/"+filename, BytesIO(b"0123456789")) | |
46 | ||
47 | results = conn.listPath('smbtest', path) | |
48 | filenames = list(map(lambda r: r.filename, results)) | |
49 | assert 'aaTest.Folder' in filenames | |
50 | assert 'bbTest.Folder' in filenames | |
43 | 51 | assert 'aaTest.txt' in filenames |
44 | 52 | assert 'aaBest.txt' in filenames |
45 | 53 | assert 'aaTest.bin' in filenames |
50 | 58 | |
51 | 59 | results = conn.listPath('smbtest', path) |
52 | 60 | filenames = list(map(lambda r: r.filename, results)) |
61 | assert 'aaTest.Folder' in filenames | |
62 | assert 'bbTest.Folder' in filenames | |
53 | 63 | assert 'aaTest.txt' not in filenames |
54 | 64 | assert 'aaBest.txt' not in filenames |
55 | 65 | assert 'aaTest.bin' in filenames |
60 | 70 | |
61 | 71 | results = conn.listPath('smbtest', path) |
62 | 72 | filenames = list(map(lambda r: r.filename, results)) |
63 | assert 'aaTest.bin' not in filenames | |
64 | assert 'aaBest.bin' in filenames | |
65 | assert 'random.txt' in filenames | |
66 | ||
67 | conn.deleteFiles('smbtest', path+'/*') | |
68 | conn.deleteDirectory('smbtest', path) | |
69 | ||
70 | @with_setup(setup_func_SMB2, teardown_func) | |
71 | def test_delete_SMB2(): | |
72 | global conn | |
73 | ||
74 | path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
75 | conn.createDirectory('smbtest', path) | |
76 | ||
77 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
78 | conn.storeFile('smbtest', path+"/"+filename, BytesIO(b"0123456789")) | |
79 | ||
80 | results = conn.listPath('smbtest', path) | |
81 | filenames = list(map(lambda r: r.filename, results)) | |
73 | assert 'aaTest.Folder' in filenames | |
74 | assert 'bbTest.Folder' in filenames | |
75 | assert 'aaTest.bin' not in filenames | |
76 | assert 'aaBest.bin' in filenames | |
77 | assert 'random.txt' in filenames | |
78 | ||
79 | ||
80 | @with_setup(setup_func_SMB1) | |
81 | @with_teardown(teardown_func) | |
82 | def test_delete_with_subfolder_SMB1(): | |
83 | global conn | |
84 | ||
85 | path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
86 | conn.createDirectory('smbtest', path) | |
87 | ||
88 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
89 | conn.storeFile('smbtest', path+"/"+filename, BytesIO(b"0123456789")) | |
90 | ||
91 | for p in [ 'aaTest.Folder', 'aaTest.Folder/xyz', 'bbTest.Folder' ]: | |
92 | conn.createDirectory('smbtest', path+"/"+p) | |
93 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
94 | conn.storeFile('smbtest', path+"/"+p+"/"+filename, BytesIO(b"0123456789")) | |
95 | ||
96 | results = conn.listPath('smbtest', path) | |
97 | filenames = list(map(lambda r: r.filename, results)) | |
98 | assert 'aaTest.Folder' in filenames | |
99 | assert 'bbTest.Folder' in filenames | |
100 | assert 'aaTest.txt' in filenames | |
101 | assert 'aaBest.txt' in filenames | |
102 | assert 'aaTest.bin' in filenames | |
103 | assert 'aaBest.bin' in filenames | |
104 | assert 'random.txt' in filenames | |
105 | ||
106 | conn.deleteFiles('smbtest', path+'/aa*.txt', delete_matching_folders=True) | |
107 | ||
108 | results = conn.listPath('smbtest', path) | |
109 | filenames = list(map(lambda r: r.filename, results)) | |
110 | assert 'aaTest.Folder' in filenames | |
111 | assert 'bbTest.Folder' in filenames | |
112 | assert 'aaTest.txt' not in filenames | |
113 | assert 'aaBest.txt' not in filenames | |
114 | assert 'aaTest.bin' in filenames | |
115 | assert 'aaBest.bin' in filenames | |
116 | assert 'random.txt' in filenames | |
117 | ||
118 | conn.deleteFiles('smbtest', path+'/aaTest.*', delete_matching_folders=True) | |
119 | ||
120 | results = conn.listPath('smbtest', path) | |
121 | filenames = list(map(lambda r: r.filename, results)) | |
122 | assert 'aaTest.Folder' not in filenames | |
123 | assert 'bbTest.Folder' in filenames | |
124 | assert 'aaTest.bin' not in filenames | |
125 | assert 'aaBest.bin' in filenames | |
126 | assert 'random.txt' in filenames | |
127 | ||
128 | ||
129 | @with_setup(setup_func_SMB2) | |
130 | @with_teardown(teardown_func) | |
131 | def test_delete_without_subfolder_SMB2(): | |
132 | global conn | |
133 | ||
134 | path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
135 | conn.createDirectory('smbtest', path) | |
136 | ||
137 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
138 | conn.storeFile('smbtest', path+"/"+filename, BytesIO(b"0123456789")) | |
139 | ||
140 | for p in [ 'aaTest.Folder', 'aaTest.Folder/xyz', 'bbTest.Folder' ]: | |
141 | conn.createDirectory('smbtest', path+"/"+p) | |
142 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
143 | conn.storeFile('smbtest', path+"/"+p+"/"+filename, BytesIO(b"0123456789")) | |
144 | ||
145 | results = conn.listPath('smbtest', path) | |
146 | filenames = list(map(lambda r: r.filename, results)) | |
147 | assert 'aaTest.Folder' in filenames | |
148 | assert 'bbTest.Folder' in filenames | |
82 | 149 | assert 'aaTest.txt' in filenames |
83 | 150 | assert 'aaBest.txt' in filenames |
84 | 151 | assert 'aaTest.bin' in filenames |
89 | 156 | |
90 | 157 | results = conn.listPath('smbtest', path) |
91 | 158 | filenames = list(map(lambda r: r.filename, results)) |
159 | assert 'aaTest.Folder' in filenames | |
160 | assert 'bbTest.Folder' in filenames | |
92 | 161 | assert 'aaTest.txt' not in filenames |
93 | 162 | assert 'aaBest.txt' not in filenames |
94 | 163 | assert 'aaTest.bin' in filenames |
99 | 168 | |
100 | 169 | results = conn.listPath('smbtest', path) |
101 | 170 | filenames = list(map(lambda r: r.filename, results)) |
102 | assert 'aaTest.bin' not in filenames | |
103 | assert 'aaBest.bin' in filenames | |
104 | assert 'random.txt' in filenames | |
171 | assert 'aaTest.Folder' in filenames | |
172 | assert 'bbTest.Folder' in filenames | |
173 | assert 'aaTest.bin' not in filenames | |
174 | assert 'aaBest.bin' in filenames | |
175 | assert 'random.txt' in filenames | |
176 | ||
177 | @with_setup(setup_func_SMB2) | |
178 | @with_teardown(teardown_func) | |
179 | def test_delete_with_subfolder_SMB2(): | |
180 | global conn | |
181 | ||
182 | path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
183 | conn.createDirectory('smbtest', path) | |
184 | ||
185 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
186 | conn.storeFile('smbtest', path+"/"+filename, BytesIO(b"0123456789")) | |
187 | ||
188 | for p in [ 'aaTest.Folder', 'aaTest.Folder/xyz', 'bbTest.Folder' ]: | |
189 | conn.createDirectory('smbtest', path+"/"+p) | |
190 | for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]: | |
191 | conn.storeFile('smbtest', path+"/"+p+"/"+filename, BytesIO(b"0123456789")) | |
192 | ||
193 | results = conn.listPath('smbtest', path) | |
194 | filenames = list(map(lambda r: r.filename, results)) | |
195 | assert 'aaTest.Folder' in filenames | |
196 | assert 'bbTest.Folder' in filenames | |
197 | assert 'aaTest.txt' in filenames | |
198 | assert 'aaBest.txt' in filenames | |
199 | assert 'aaTest.bin' in filenames | |
200 | assert 'aaBest.bin' in filenames | |
201 | assert 'random.txt' in filenames | |
202 | ||
203 | conn.deleteFiles('smbtest', path+'/aa*.txt', delete_matching_folders=True) | |
204 | ||
205 | results = conn.listPath('smbtest', path) | |
206 | filenames = list(map(lambda r: r.filename, results)) | |
207 | assert 'aaTest.Folder' in filenames | |
208 | assert 'bbTest.Folder' in filenames | |
209 | assert 'aaTest.txt' not in filenames | |
210 | assert 'aaBest.txt' not in filenames | |
211 | assert 'aaTest.bin' in filenames | |
212 | assert 'aaBest.bin' in filenames | |
213 | assert 'random.txt' in filenames | |
214 | ||
215 | conn.deleteFiles('smbtest', path+'/aaTest.*', delete_matching_folders=True) | |
216 | ||
217 | results = conn.listPath('smbtest', path) | |
218 | filenames = list(map(lambda r: r.filename, results)) | |
219 | assert 'aaTest.Folder' not in filenames | |
220 | assert 'bbTest.Folder' in filenames | |
221 | assert 'aaTest.bin' not in filenames | |
222 | assert 'aaBest.bin' in filenames | |
223 | assert 'random.txt' in filenames |
0 | 0 | |
1 | 1 | import random |
2 | from nose2.tools.decorators import with_setup, with_teardown | |
2 | 3 | from smb.SMBConnection import SMBConnection |
3 | 4 | from .util import getConnectionInfo |
4 | from nose.tools import with_setup | |
5 | 5 | |
6 | 6 | conn = None |
7 | 7 | |
15 | 15 | global conn |
16 | 16 | conn.close() |
17 | 17 | |
18 | @with_setup(setup_func, teardown_func) | |
18 | @with_setup(setup_func) | |
19 | @with_teardown(teardown_func) | |
19 | 20 | def test_echo(): |
20 | 21 | global conn |
21 | 22 |
1 | 1 | |
2 | 2 | from smb.SMBConnection import SMBConnection |
3 | 3 | from .util import getConnectionInfo |
4 | from nose.tools import with_setup | |
4 | from nose2.tools.decorators import with_setup | |
5 | 5 | from smb import smb_structs |
6 | 6 | |
7 | 7 | conn = None |
0 | 0 | # -*- coding: utf-8 -*- |
1 | 1 | |
2 | from nose2.tools.decorators import with_setup, with_teardown | |
2 | 3 | from smb.SMBConnection import SMBConnection |
4 | from smb.smb_constants import * | |
5 | from smb import smb_structs | |
3 | 6 | from .util import getConnectionInfo |
4 | from nose.tools import with_setup | |
5 | from smb import smb_structs | |
6 | 7 | |
7 | 8 | conn = None |
8 | 9 | |
24 | 25 | global conn |
25 | 26 | conn.close() |
26 | 27 | |
27 | @with_setup(setup_func_SMB1, teardown_func) | |
28 | @with_setup(setup_func_SMB1) | |
29 | @with_teardown(teardown_func) | |
28 | 30 | def test_listPath_SMB1(): |
29 | 31 | global conn |
30 | 32 | results = conn.listPath('smbtest', '/') |
35 | 37 | assert ( 'Implementing CIFS - SMB.html', False ) in filenames # Test long English file names |
36 | 38 | assert ( 'rfc1001.txt', False ) in filenames # Test short English file names |
37 | 39 | |
38 | @with_setup(setup_func_SMB1, teardown_func) | |
40 | @with_setup(setup_func_SMB1) | |
41 | @with_teardown(teardown_func) | |
39 | 42 | def test_listSubPath_SMB1(): |
40 | 43 | global conn |
41 | 44 | results = conn.listPath('smbtest', '/Test Folder with Long Name/') |
44 | 47 | assert ( 'Test Folder', True ) in filenames |
45 | 48 | assert ( '子文件夹', True ) in filenames |
46 | 49 | |
47 | @with_setup(setup_func_SMB2, teardown_func) | |
50 | @with_setup(setup_func_SMB1) | |
51 | @with_teardown(teardown_func) | |
52 | def test_listPathWithManyFiles_SMB1(): | |
53 | global conn | |
54 | results = conn.listPath('smbtest', '/RFC Archive/') | |
55 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
56 | assert len(list(filenames))==999 | |
57 | ||
58 | @with_setup(setup_func_SMB2) | |
59 | @with_teardown(teardown_func) | |
48 | 60 | def test_listPath_SMB2(): |
49 | 61 | global conn |
50 | 62 | results = conn.listPath('smbtest', '/') |
55 | 67 | assert ( 'Implementing CIFS - SMB.html', False ) in filenames # Test long English file names |
56 | 68 | assert ( 'rfc1001.txt', False ) in filenames # Test short English file names |
57 | 69 | |
58 | @with_setup(setup_func_SMB2, teardown_func) | |
70 | @with_setup(setup_func_SMB2) | |
71 | @with_teardown(teardown_func) | |
59 | 72 | def test_listSubPath_SMB2(): |
60 | 73 | global conn |
61 | 74 | results = conn.listPath('smbtest', '/Test Folder with Long Name/') |
63 | 76 | assert ( 'Test File.txt', False ) in filenames |
64 | 77 | assert ( 'Test Folder', True ) in filenames |
65 | 78 | assert ( '子文件夹', True ) in filenames |
79 | ||
80 | @with_setup(setup_func_SMB2) | |
81 | @with_teardown(teardown_func) | |
82 | def test_listPathWithManyFiles_SMB2(): | |
83 | global conn | |
84 | results = conn.listPath('smbtest', '/RFC Archive/') | |
85 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
86 | assert len(list(filenames))==999 | |
87 | ||
88 | @with_setup(setup_func_SMB1) | |
89 | @with_teardown(teardown_func) | |
90 | def test_listPathFilterForDirectory_SMB1(): | |
91 | global conn | |
92 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY) | |
93 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
94 | assert len(list(filenames)) > 0 | |
95 | for f, isDirectory in filenames: | |
96 | assert isDirectory | |
97 | ||
98 | @with_setup(setup_func_SMB2) | |
99 | @with_teardown(teardown_func) | |
100 | def test_listPathFilterForDirectory_SMB2(): | |
101 | global conn | |
102 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY) | |
103 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
104 | assert len(list(filenames)) > 0 | |
105 | for f, isDirectory in filenames: | |
106 | assert isDirectory | |
107 | ||
108 | @with_setup(setup_func_SMB1) | |
109 | @with_teardown(teardown_func) | |
110 | def test_listPathFilterForFiles_SMB1(): | |
111 | global conn | |
112 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL) | |
113 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
114 | assert len(list(filenames)) > 0 | |
115 | for f, isDirectory in filenames: | |
116 | assert not isDirectory | |
117 | ||
118 | @with_setup(setup_func_SMB2) | |
119 | @with_teardown(teardown_func) | |
120 | def test_listPathFilterForFiles_SMB2(): | |
121 | global conn | |
122 | results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL) | |
123 | filenames = map(lambda r: ( r.filename, r.isDirectory ), results) | |
124 | assert len(list(filenames)) > 0 | |
125 | for f, isDirectory in filenames: | |
126 | assert not isDirectory | |
127 | ||
128 | @with_setup(setup_func_SMB1) | |
129 | @with_teardown(teardown_func) | |
130 | def test_listPathFilterPattern_SMB1(): | |
131 | global conn | |
132 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*') | |
133 | filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results)) | |
134 | assert len(filenames) == 2 | |
135 | assert ( u'Test File.txt', False ) in filenames | |
136 | assert ( u'Test Folder', True ) in filenames | |
137 | assert ( u'子文件夹', True ) not in filenames | |
138 | ||
139 | @with_setup(setup_func_SMB2) | |
140 | @with_teardown(teardown_func) | |
141 | def test_listPathFilterPattern_SMB2(): | |
142 | global conn | |
143 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*') | |
144 | filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results)) | |
145 | assert len(filenames) == 2 | |
146 | assert ( u'Test File.txt', False ) in filenames | |
147 | assert ( u'Test Folder', True ) in filenames | |
148 | assert ( u'子文件夹', True ) not in filenames | |
149 | ||
150 | @with_setup(setup_func_SMB1) | |
151 | @with_teardown(teardown_func) | |
152 | def test_listPathFilterUnicodePattern_SMB1(): | |
153 | global conn | |
154 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹') | |
155 | filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results)) | |
156 | assert len(filenames) == 1 | |
157 | assert ( u'Test File.txt', False ) not in filenames | |
158 | assert ( u'Test Folder', True ) not in filenames | |
159 | assert ( u'子文件夹', True ) in filenames | |
160 | ||
161 | @with_setup(setup_func_SMB2) | |
162 | @with_teardown(teardown_func) | |
163 | def test_listPathFilterUnicodePattern_SMB2(): | |
164 | global conn | |
165 | results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹') | |
166 | filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results)) | |
167 | assert len(filenames) == 1 | |
168 | assert ( u'Test File.txt', False ) not in filenames | |
169 | assert ( u'Test Folder', True ) not in filenames | |
170 | assert ( u'子文件夹', True ) in filenames | |
171 | ||
172 | @with_setup(setup_func_SMB1) | |
173 | @with_teardown(teardown_func) | |
174 | def test_listPathFilterEmptyList_SMB1(): | |
175 | global conn | |
176 | results = conn.listPath('smbtest', '/RFC Archive', pattern = '*.abc') | |
177 | filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results)) | |
178 | ||
179 | @with_setup(setup_func_SMB2) | |
180 | @with_teardown(teardown_func) | |
181 | def test_listPathFilterEmptyList_SMB2(): | |
182 | global conn | |
183 | results = conn.listPath('smbtest', '/RFC Archive', pattern = '*.abc') | |
184 | filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results)) |
0 | 0 | |
1 | from nose2.tools.decorators import with_setup, with_teardown | |
1 | 2 | from smb.SMBConnection import SMBConnection |
3 | from smb import smb_structs | |
2 | 4 | from .util import getConnectionInfo |
3 | from nose.tools import with_setup | |
4 | from smb import smb_structs | |
5 | 5 | |
6 | 6 | conn = None |
7 | 7 | |
23 | 23 | global conn |
24 | 24 | conn.close() |
25 | 25 | |
26 | @with_setup(setup_func_SMB1, teardown_func) | |
26 | @with_setup(setup_func_SMB1) | |
27 | @with_teardown(teardown_func) | |
27 | 28 | def test_listshares_SMB1(): |
28 | 29 | global conn |
29 | 30 | results = conn.listShares() |
30 | 31 | assert 'smbtest' in [r.name.lower() for r in results] |
31 | 32 | |
32 | @with_setup(setup_func_SMB2, teardown_func) | |
33 | @with_setup(setup_func_SMB2) | |
34 | @with_teardown(teardown_func) | |
33 | 35 | def test_listshares_SMB2(): |
34 | 36 | global conn |
35 | 37 | results = conn.listShares() |
0 | 0 | |
1 | from nose2.tools.decorators import with_setup, with_teardown | |
1 | 2 | from smb.SMBConnection import SMBConnection |
3 | from smb import smb_structs | |
2 | 4 | from .util import getConnectionInfo |
3 | from nose.tools import with_setup | |
4 | from smb import smb_structs | |
5 | 5 | |
6 | 6 | conn = None |
7 | 7 | |
23 | 23 | global conn |
24 | 24 | conn.close() |
25 | 25 | |
26 | @with_setup(setup_func_SMB1, teardown_func) | |
26 | @with_setup(setup_func_SMB1) | |
27 | @with_teardown(teardown_func) | |
27 | 28 | def test_listsnapshots_SMB1(): |
28 | 29 | global conn |
29 | 30 | results = conn.listSnapshots('smbtest', '/rfc1001.txt') |
30 | 31 | assert len(results) > 0 |
31 | 32 | |
32 | @with_setup(setup_func_SMB2, teardown_func) | |
33 | @with_setup(setup_func_SMB2) | |
34 | @with_teardown(teardown_func) | |
33 | 35 | def test_listsnapshots_SMB2(): |
34 | 36 | global conn |
35 | 37 | results = conn.listSnapshots('smbtest', '/rfc1001.txt') |
1 | 1 | |
2 | 2 | import os, time, random |
3 | 3 | from io import BytesIO |
4 | from nose2.tools.decorators import with_setup, with_teardown | |
4 | 5 | from smb.SMBConnection import SMBConnection |
6 | from smb import smb_structs | |
5 | 7 | from .util import getConnectionInfo |
6 | from nose.tools import with_setup | |
7 | from smb import smb_structs | |
8 | 8 | |
9 | 9 | conn = None |
10 | 10 | |
26 | 26 | global conn |
27 | 27 | conn.close() |
28 | 28 | |
29 | @with_setup(setup_func_SMB1, teardown_func) | |
29 | @with_setup(setup_func_SMB1) | |
30 | @with_teardown(teardown_func) | |
30 | 31 | def test_rename_english_file_SMB1(): |
31 | 32 | global conn |
32 | 33 | |
49 | 50 | |
50 | 51 | conn.deleteFiles('smbtest', new_path) |
51 | 52 | |
52 | @with_setup(setup_func_SMB2, teardown_func) | |
53 | @with_setup(setup_func_SMB2) | |
54 | @with_teardown(teardown_func) | |
53 | 55 | def test_rename_english_file_SMB2(): |
54 | 56 | global conn |
55 | 57 | |
72 | 74 | |
73 | 75 | conn.deleteFiles('smbtest', new_path) |
74 | 76 | |
75 | @with_setup(setup_func_SMB1, teardown_func) | |
77 | @with_setup(setup_func_SMB1) | |
78 | @with_teardown(teardown_func) | |
76 | 79 | def test_rename_unicode_file_SMB1(): |
77 | 80 | global conn |
78 | 81 | |
95 | 98 | |
96 | 99 | conn.deleteFiles('smbtest', new_path) |
97 | 100 | |
98 | @with_setup(setup_func_SMB2, teardown_func) | |
101 | @with_setup(setup_func_SMB2) | |
102 | @with_teardown(teardown_func) | |
99 | 103 | def test_rename_unicode_file_SMB2(): |
100 | 104 | global conn |
101 | 105 | |
118 | 122 | |
119 | 123 | conn.deleteFiles('smbtest', new_path) |
120 | 124 | |
121 | @with_setup(setup_func_SMB1, teardown_func) | |
125 | @with_setup(setup_func_SMB1) | |
126 | @with_teardown(teardown_func) | |
122 | 127 | def test_rename_english_directory_SMB1(): |
123 | 128 | global conn |
124 | 129 | |
141 | 146 | |
142 | 147 | conn.deleteDirectory('smbtest', new_path) |
143 | 148 | |
144 | @with_setup(setup_func_SMB2, teardown_func) | |
149 | @with_setup(setup_func_SMB2) | |
150 | @with_teardown(teardown_func) | |
145 | 151 | def test_rename_english_directory_SMB2(): |
146 | 152 | global conn |
147 | 153 | |
164 | 170 | |
165 | 171 | conn.deleteDirectory('smbtest', new_path) |
166 | 172 | |
167 | @with_setup(setup_func_SMB1, teardown_func) | |
173 | @with_setup(setup_func_SMB1) | |
174 | @with_teardown(teardown_func) | |
168 | 175 | def test_rename_unicode_directory_SMB1(): |
169 | 176 | global conn |
170 | 177 | |
187 | 194 | |
188 | 195 | conn.deleteDirectory('smbtest', new_path) |
189 | 196 | |
190 | @with_setup(setup_func_SMB2, teardown_func) | |
197 | @with_setup(setup_func_SMB2) | |
198 | @with_teardown(teardown_func) | |
191 | 199 | def test_rename_unicode_directory_SMB2(): |
192 | 200 | global conn |
193 | 201 |
1 | 1 | |
2 | 2 | import os, tempfile |
3 | 3 | from io import BytesIO |
4 | from nose2.tools.decorators import with_setup, with_teardown | |
4 | 5 | from smb.SMBConnection import SMBConnection |
6 | from smb import smb_structs | |
5 | 7 | from .util import getConnectionInfo |
6 | from nose.tools import with_setup | |
7 | from smb import smb_structs | |
8 | 8 | |
9 | 9 | try: |
10 | 10 | import hashlib |
33 | 33 | global conn |
34 | 34 | conn.close() |
35 | 35 | |
36 | @with_setup(setup_func_SMB1, teardown_func) | |
36 | @with_setup(setup_func_SMB1) | |
37 | @with_teardown(teardown_func) | |
37 | 38 | def test_retr_multiplereads_SMB1(): |
38 | 39 | # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes) |
39 | 40 | global conn |
47 | 48 | |
48 | 49 | temp_fh.close() |
49 | 50 | |
50 | @with_setup(setup_func_SMB2, teardown_func) | |
51 | @with_setup(setup_func_SMB2) | |
52 | @with_teardown(teardown_func) | |
51 | 53 | def test_retr_multiplereads_SMB2(): |
52 | 54 | # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes) |
53 | 55 | global conn |
61 | 63 | |
62 | 64 | temp_fh.close() |
63 | 65 | |
64 | @with_setup(setup_func_SMB1, teardown_func) | |
66 | @with_setup(setup_func_SMB1) | |
67 | @with_teardown(teardown_func) | |
65 | 68 | def test_retr_longfilename_SMB1(): |
66 | 69 | # Test file retrieval that has a long English filename |
67 | 70 | global conn |
75 | 78 | |
76 | 79 | temp_fh.close() |
77 | 80 | |
78 | @with_setup(setup_func_SMB2, teardown_func) | |
81 | @with_setup(setup_func_SMB2) | |
82 | @with_teardown(teardown_func) | |
79 | 83 | def test_retr_longfilename_SMB2(): |
80 | 84 | # Test file retrieval that has a long English filename |
81 | 85 | global conn |
89 | 93 | |
90 | 94 | temp_fh.close() |
91 | 95 | |
92 | @with_setup(setup_func_SMB1, teardown_func) | |
96 | @with_setup(setup_func_SMB1) | |
97 | @with_teardown(teardown_func) | |
93 | 98 | def test_retr_unicodefilename_SMB1(): |
94 | 99 | # Test file retrieval that has a long non-English filename inside a folder with a non-English name |
95 | 100 | global conn |
103 | 108 | |
104 | 109 | temp_fh.close() |
105 | 110 | |
106 | @with_setup(setup_func_SMB2, teardown_func) | |
111 | @with_setup(setup_func_SMB2) | |
112 | @with_teardown(teardown_func) | |
107 | 113 | def test_retr_unicodefilename_SMB2(): |
108 | 114 | # Test file retrieval that has a long non-English filename inside a folder with a non-English name |
109 | 115 | global conn |
117 | 123 | |
118 | 124 | temp_fh.close() |
119 | 125 | |
120 | @with_setup(setup_func_SMB1, teardown_func) | |
126 | @with_setup(setup_func_SMB1) | |
127 | @with_teardown(teardown_func) | |
121 | 128 | def test_retr_offset_SMB1(): |
122 | 129 | # Test file retrieval from offset to EOF |
123 | 130 | global conn |
131 | 138 | |
132 | 139 | temp_fh.close() |
133 | 140 | |
134 | @with_setup(setup_func_SMB2, teardown_func) | |
141 | @with_setup(setup_func_SMB2) | |
142 | @with_teardown(teardown_func) | |
135 | 143 | def test_retr_offset_SMB2(): |
136 | 144 | # Test file retrieval from offset to EOF |
137 | 145 | global conn |
145 | 153 | |
146 | 154 | temp_fh.close() |
147 | 155 | |
148 | @with_setup(setup_func_SMB1, teardown_func) | |
156 | @with_setup(setup_func_SMB1) | |
157 | @with_teardown(teardown_func) | |
149 | 158 | def test_retr_offset_and_biglimit_SMB1(): |
150 | 159 | # Test file retrieval from offset with a big max_length |
151 | 160 | global conn |
159 | 168 | |
160 | 169 | temp_fh.close() |
161 | 170 | |
162 | @with_setup(setup_func_SMB2, teardown_func) | |
171 | @with_setup(setup_func_SMB2) | |
172 | @with_teardown(teardown_func) | |
163 | 173 | def test_retr_offset_and_biglimit_SMB2(): |
164 | 174 | # Test file retrieval from offset with a big max_length |
165 | 175 | global conn |
173 | 183 | |
174 | 184 | temp_fh.close() |
175 | 185 | |
176 | @with_setup(setup_func_SMB1, teardown_func) | |
186 | @with_setup(setup_func_SMB1) | |
187 | @with_teardown(teardown_func) | |
177 | 188 | def test_retr_offset_and_smalllimit_SMB1(): |
178 | 189 | # Test file retrieval from offset with a small max_length |
179 | 190 | global conn |
187 | 198 | |
188 | 199 | temp_fh.close() |
189 | 200 | |
190 | @with_setup(setup_func_SMB2, teardown_func) | |
201 | @with_setup(setup_func_SMB2) | |
202 | @with_teardown(teardown_func) | |
191 | 203 | def test_retr_offset_and_smalllimit_SMB2(): |
192 | 204 | # Test file retrieval from offset with a small max_length |
193 | 205 | global conn |
201 | 213 | |
202 | 214 | temp_fh.close() |
203 | 215 | |
204 | @with_setup(setup_func_SMB1, teardown_func) | |
216 | @with_setup(setup_func_SMB1) | |
217 | @with_teardown(teardown_func) | |
205 | 218 | def test_retr_offset_and_zerolimit_SMB1(): |
206 | 219 | # Test file retrieval from offset to EOF with max_length=0 |
207 | 220 | global conn |
215 | 228 | |
216 | 229 | temp_fh.close() |
217 | 230 | |
218 | @with_setup(setup_func_SMB2, teardown_func) | |
231 | @with_setup(setup_func_SMB2) | |
232 | @with_teardown(teardown_func) | |
219 | 233 | def test_retr_offset_and_zerolimit_SMB2(): |
220 | 234 | # Test file retrieval from offset to EOF with max_length=0 |
221 | 235 | global conn |
1 | 1 | |
2 | 2 | import os, tempfile, random, time |
3 | 3 | from io import BytesIO |
4 | from nose2.tools.decorators import with_setup, with_teardown | |
4 | 5 | from smb.SMBConnection import SMBConnection |
6 | from smb import smb_structs | |
5 | 7 | from .util import getConnectionInfo |
6 | from nose.tools import with_setup | |
7 | from smb import smb_structs | |
8 | 8 | |
9 | 9 | try: |
10 | 10 | import hashlib |
40 | 40 | conn.close() |
41 | 41 | |
42 | 42 | |
43 | @with_setup(setup_func_SMB1, teardown_func) | |
43 | @with_setup(setup_func_SMB1) | |
44 | @with_teardown(teardown_func) | |
44 | 45 | def test_store_long_filename_SMB1(): |
45 | 46 | filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) |
46 | 47 | |
63 | 64 | conn.deleteFiles('smbtest', filename) |
64 | 65 | |
65 | 66 | |
66 | @with_setup(setup_func_SMB2, teardown_func) | |
67 | @with_setup(setup_func_SMB2) | |
68 | @with_teardown(teardown_func) | |
67 | 69 | def test_store_long_filename_SMB2(): |
68 | 70 | filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) |
69 | 71 | |
86 | 88 | conn.deleteFiles('smbtest', filename) |
87 | 89 | |
88 | 90 | |
89 | @with_setup(setup_func_SMB1, teardown_func) | |
91 | @with_setup(setup_func_SMB1) | |
92 | @with_teardown(teardown_func) | |
90 | 93 | def test_store_unicode_filename_SMB1(): |
91 | 94 | filename = os.sep + '上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) |
92 | 95 | |
109 | 112 | conn.deleteFiles('smbtest', filename) |
110 | 113 | |
111 | 114 | |
112 | @with_setup(setup_func_SMB1, teardown_func) | |
115 | @with_setup(setup_func_SMB1) | |
116 | @with_teardown(teardown_func) | |
113 | 117 | def test_store_from_offset_SMB1(): |
114 | 118 | filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) |
115 | 119 | |
129 | 133 | |
130 | 134 | conn.deleteFiles('smbtest', filename) |
131 | 135 | |
132 | @with_setup(setup_func_SMB2, teardown_func) | |
136 | @with_setup(setup_func_SMB2) | |
137 | @with_teardown(teardown_func) | |
133 | 138 | def test_store_unicode_filename_SMB2(): |
134 | 139 | filename = os.sep + '上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) |
135 | 140 | |
151 | 156 | |
152 | 157 | conn.deleteFiles('smbtest', filename) |
153 | 158 | |
154 | @with_setup(setup_func_SMB2, teardown_func) | |
159 | @with_setup(setup_func_SMB2) | |
160 | @with_teardown(teardown_func) | |
155 | 161 | def test_store_from_offset_SMB2(): |
156 | 162 | filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) |
157 | 163 |
0 | # -*- coding: utf-8 -*- | |
1 | ||
2 | from smb.SMBConnection import SMBConnection | |
3 | from .util import getConnectionInfo | |
4 | ||
5 | def test_context(): | |
6 | info = getConnectionInfo() | |
7 | with SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) as conn: | |
8 | assert conn.connect(info['server_ip'], info['server_port']) | |
9 | ||
10 | assert conn.sock is None |
0 | ||
1 | from nose.twistedtools import reactor, deferred | |
2 | from twisted.internet import defer | |
3 | from smb.SMBProtocol import SMBProtocolFactory | |
4 | from smb import smb_structs | |
5 | from .util import getConnectionInfo | |
6 | ||
7 | ||
8 | class AuthFactory(SMBProtocolFactory): | |
9 | ||
10 | def __init__(self, *args, **kwargs): | |
11 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
12 | self.d = defer.Deferred() | |
13 | self.d.addBoth(self.testDone) | |
14 | ||
15 | def testDone(self, r): | |
16 | if self.instance: | |
17 | self.instance.transport.loseConnection() | |
18 | return r | |
19 | ||
20 | def onAuthOK(self): | |
21 | self.d.callback(True) | |
22 | ||
23 | def onAuthFailed(self): | |
24 | self.d.callback(False) | |
25 | ||
26 | ||
27 | @deferred(timeout=5.0) | |
28 | def test_NTLMv1_auth_SMB1(): | |
29 | def result(auth_passed): | |
30 | assert auth_passed | |
31 | ||
32 | smb_structs.SUPPORT_SMB2 = False | |
33 | info = getConnectionInfo() | |
34 | factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False) | |
35 | factory.d.addCallback(result) | |
36 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
37 | return factory.d | |
38 | ||
39 | ||
40 | @deferred(timeout=5.0) | |
41 | def test_NTLMv2_auth_SMB1(): | |
42 | def result(auth_passed): | |
43 | assert auth_passed | |
44 | ||
45 | smb_structs.SUPPORT_SMB2 = False | |
46 | info = getConnectionInfo() | |
47 | factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
48 | factory.d.addCallback(result) | |
49 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
50 | return factory.d | |
51 | ||
52 | ||
53 | @deferred(timeout=5.0) | |
54 | def test_NTLMv1_auth_SMB2(): | |
55 | def result(auth_passed): | |
56 | assert auth_passed | |
57 | ||
58 | smb_structs.SUPPORT_SMB2 = True | |
59 | info = getConnectionInfo() | |
60 | factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False) | |
61 | factory.d.addCallback(result) | |
62 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
63 | return factory.d | |
64 | ||
65 | ||
66 | @deferred(timeout=5.0) | |
67 | def test_NTLMv2_auth_SMB2(): | |
68 | def result(auth_passed): | |
69 | assert auth_passed | |
70 | ||
71 | smb_structs.SUPPORT_SMB2 = True | |
72 | info = getConnectionInfo() | |
73 | factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
74 | factory.d.addCallback(result) | |
75 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
76 | return factory.d |
0 | # -*- coding: utf-8 -*- | |
1 | ||
2 | import os, random, time | |
3 | from nose.twistedtools import reactor, deferred | |
4 | from twisted.internet import defer | |
5 | from smb.SMBProtocol import SMBProtocolFactory | |
6 | from smb import smb_structs | |
7 | from .util import getConnectionInfo | |
8 | ||
9 | ||
10 | class DirectoryFactory(SMBProtocolFactory): | |
11 | ||
12 | def __init__(self, *args, **kwargs): | |
13 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
14 | self.d = defer.Deferred() | |
15 | self.d.addBoth(self.testDone) | |
16 | self.service_name = '' | |
17 | self.path = '' | |
18 | ||
19 | def testDone(self, r): | |
20 | if self.instance: | |
21 | self.instance.transport.loseConnection() | |
22 | return r | |
23 | ||
24 | def createDone(self, result): | |
25 | d = self.listPath(self.service_name, os.path.dirname(self.path.replace('/', os.sep))) | |
26 | d.addCallback(self.listComplete) | |
27 | d.addErrback(self.d.errback) | |
28 | ||
29 | def listComplete(self, entries): | |
30 | names = [e.filename for e in entries] | |
31 | assert os.path.basename(self.path.replace('/', os.sep)) in names | |
32 | ||
33 | d = self.deleteDirectory(self.service_name, self.path) | |
34 | d.addCallback(self.deleteDone) | |
35 | d.addErrback(self.d.errback) | |
36 | ||
37 | def deleteDone(self, result): | |
38 | d = self.listPath(self.service_name, os.path.dirname(self.path.replace('/', os.sep))) | |
39 | d.addCallback(self.list2Complete) | |
40 | d.addErrback(self.d.errback) | |
41 | ||
42 | def list2Complete(self, entries): | |
43 | names = [e.filename for e in entries] | |
44 | assert os.path.basename(self.path.replace('/', os.sep)) not in names | |
45 | self.d.callback(True) | |
46 | ||
47 | def onAuthOK(self): | |
48 | d = self.createDirectory(self.service_name, self.path) | |
49 | d.addCallback(self.createDone) | |
50 | d.addErrback(self.d.errback) | |
51 | ||
52 | def onAuthFailed(self): | |
53 | self.d.errback('Auth failed') | |
54 | ||
55 | ||
56 | @deferred(timeout=15.0) | |
57 | def test_english_directory_SMB1(): | |
58 | info = getConnectionInfo() | |
59 | smb_structs.SUPPORT_SMB2 = False | |
60 | ||
61 | factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
62 | factory.service_name = 'smbtest' | |
63 | factory.path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
64 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
65 | return factory.d | |
66 | ||
67 | @deferred(timeout=15.0) | |
68 | def test_english_directory_SMB2(): | |
69 | info = getConnectionInfo() | |
70 | smb_structs.SUPPORT_SMB2 = True | |
71 | ||
72 | factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
73 | factory.service_name = 'smbtest' | |
74 | factory.path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
75 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
76 | return factory.d | |
77 | ||
78 | @deferred(timeout=15.0) | |
79 | def test_unicode_directory_SMB1(): | |
80 | info = getConnectionInfo() | |
81 | smb_structs.SUPPORT_SMB2 = False | |
82 | ||
83 | factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
84 | factory.service_name = 'smbtest' | |
85 | factory.path = os.sep + '文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
86 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
87 | return factory.d | |
88 | ||
89 | @deferred(timeout=15.0) | |
90 | def test_unicode_directory_SMB2(): | |
91 | info = getConnectionInfo() | |
92 | smb_structs.SUPPORT_SMB2 = True | |
93 | ||
94 | factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
95 | factory.service_name = 'smbtest' | |
96 | factory.path = os.sep + '文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) ) | |
97 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
98 | return factory.d |
0 | ||
1 | from nose.twistedtools import reactor, deferred | |
2 | from twisted.internet import defer | |
3 | from smb.SMBProtocol import SMBProtocolFactory | |
4 | from .util import getConnectionInfo | |
5 | ||
6 | ||
7 | class EchoFactory(SMBProtocolFactory): | |
8 | ||
9 | def __init__(self, *args, **kwargs): | |
10 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
11 | self.d = defer.Deferred() | |
12 | self.d.addBoth(self.testDone) | |
13 | self.echo_data = 'This is an echo test' | |
14 | ||
15 | def testDone(self, r): | |
16 | if self.instance: | |
17 | self.instance.transport.loseConnection() | |
18 | return r | |
19 | ||
20 | def onAuthOK(self): | |
21 | def cb(data): | |
22 | assert data == self.echo_data | |
23 | self.d.callback(True) | |
24 | ||
25 | d = self.echo(self.echo_data) | |
26 | d.addCallback(cb) | |
27 | d.addErrback(self.d.errback) | |
28 | ||
29 | def onAuthFailed(self): | |
30 | self.d.errback('Auth failed') | |
31 | ||
32 | ||
33 | @deferred(timeout=15.0) | |
34 | def test_echo(): | |
35 | info = getConnectionInfo() | |
36 | factory = EchoFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
37 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
38 | return factory.d |
0 | ||
1 | from nose.twistedtools import reactor, deferred | |
2 | from twisted.internet import defer | |
3 | from smb.SMBProtocol import SMBProtocolFactory | |
4 | from smb import smb_structs | |
5 | from util import getConnectionInfo | |
6 | ||
7 | ||
8 | class GetAttributesFactory(SMBProtocolFactory): | |
9 | ||
10 | def __init__(self, *args, **kwargs): | |
11 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
12 | self.d = defer.Deferred() | |
13 | self.d.addBoth(self.testDone) | |
14 | self.path = '' | |
15 | self.is_directory = False | |
16 | ||
17 | def testDone(self, r): | |
18 | if self.instance: | |
19 | self.instance.transport.loseConnection() | |
20 | return r | |
21 | ||
22 | def onAuthOK(self): | |
23 | def cb(info): | |
24 | assert info.isDirectory == self.is_directory | |
25 | self.d.callback(True) | |
26 | ||
27 | d = self.getAttributes('smbtest', self.path, timeout = 15) | |
28 | d.addCallback(cb) | |
29 | d.addErrback(self.d.errback) | |
30 | ||
31 | def onAuthFailed(self): | |
32 | self.d.errback('Auth failed') | |
33 | ||
34 | ||
35 | @deferred(timeout=15.0) | |
36 | def test_getAttributes_SMB1_test1(): | |
37 | info = getConnectionInfo() | |
38 | smb_structs.SUPPORT_SMB2 = False | |
39 | ||
40 | factory = GetAttributesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
41 | factory.path = '/Test Folder with Long Name/' | |
42 | factory.is_directory = True | |
43 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
44 | return factory.d | |
45 | ||
46 | @deferred(timeout=15.0) | |
47 | def test_getAttributes_SMB1_test2(): | |
48 | info = getConnectionInfo() | |
49 | smb_structs.SUPPORT_SMB2 = False | |
50 | ||
51 | factory = GetAttributesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
52 | factory.path = '/rfc1001.txt' | |
53 | factory.is_directory = False | |
54 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
55 | return factory.d | |
56 | ||
57 | @deferred(timeout=15.0) | |
58 | def test_getAttributes_SMB1_test3(): | |
59 | info = getConnectionInfo() | |
60 | smb_structs.SUPPORT_SMB2 = False | |
61 | ||
62 | factory = GetAttributesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
63 | factory.path = u'/\u6d4b\u8bd5\u6587\u4ef6\u5939' | |
64 | factory.is_directory = True | |
65 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
66 | return factory.d | |
67 | ||
68 | @deferred(timeout=15.0) | |
69 | def test_getAttributes_SMB2_test1(): | |
70 | info = getConnectionInfo() | |
71 | smb_structs.SUPPORT_SMB2 = True | |
72 | ||
73 | factory = GetAttributesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
74 | factory.path = '/Test Folder with Long Name/' | |
75 | factory.is_directory = True | |
76 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
77 | return factory.d | |
78 | ||
79 | @deferred(timeout=15.0) | |
80 | def test_getAttributes_SMB2_test2(): | |
81 | info = getConnectionInfo() | |
82 | smb_structs.SUPPORT_SMB2 = True | |
83 | ||
84 | factory = GetAttributesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
85 | factory.path = '/rfc1001.txt' | |
86 | factory.is_directory = False | |
87 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
88 | return factory.d | |
89 | ||
90 | @deferred(timeout=15.0) | |
91 | def test_getAttributes_SMB2_test3(): | |
92 | info = getConnectionInfo() | |
93 | smb_structs.SUPPORT_SMB2 = True | |
94 | ||
95 | factory = GetAttributesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
96 | factory.path = u'/\u6d4b\u8bd5\u6587\u4ef6\u5939' | |
97 | factory.is_directory = True | |
98 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
99 | return factory.d |
0 | ||
1 | from nose.twistedtools import reactor, deferred | |
2 | from twisted.internet import defer | |
3 | from smb.SMBProtocol import SMBProtocolFactory | |
4 | from smb import smb_structs | |
5 | from .util import getConnectionInfo | |
6 | ||
7 | ||
8 | class ListPathFactory(SMBProtocolFactory): | |
9 | ||
10 | def __init__(self, *args, **kwargs): | |
11 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
12 | self.d = defer.Deferred() | |
13 | self.d.addBoth(self.testDone) | |
14 | ||
15 | def testDone(self, r): | |
16 | if self.instance: | |
17 | self.instance.transport.loseConnection() | |
18 | return r | |
19 | ||
20 | def onAuthOK(self): | |
21 | def cb(results): | |
22 | filenames = [( r.filename, r.isDirectory ) for r in results] | |
23 | assert ( '\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames # Test non-English folder names | |
24 | assert ( 'Test Folder with Long Name', True ) in filenames # Test long English folder names | |
25 | assert ( 'TestDir1', True ) in filenames # Test short English folder names | |
26 | assert ( 'Implementing CIFS - SMB.html', False ) in filenames # Test long English file names | |
27 | assert ( 'rfc1001.txt', False ) in filenames # Test short English file names | |
28 | ||
29 | self.d.callback(True) | |
30 | ||
31 | d = self.listPath('smbtest', '/', timeout = 15) | |
32 | d.addCallback(cb) | |
33 | d.addErrback(self.d.errback) | |
34 | ||
35 | def onAuthFailed(self): | |
36 | self.d.errback('Auth failed') | |
37 | ||
38 | ||
39 | @deferred(timeout=15.0) | |
40 | def test_listPath_SMB1(): | |
41 | info = getConnectionInfo() | |
42 | smb_structs.SUPPORT_SMB2 = False | |
43 | ||
44 | factory = ListPathFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
45 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
46 | return factory.d | |
47 | ||
48 | @deferred(timeout=15.0) | |
49 | def test_listPath_SMB2(): | |
50 | info = getConnectionInfo() | |
51 | smb_structs.SUPPORT_SMB2 = True | |
52 | ||
53 | factory = ListPathFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
54 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
55 | return factory.d |
0 | ||
1 | from nose.twistedtools import reactor, deferred | |
2 | from twisted.internet import defer | |
3 | from smb.SMBProtocol import SMBProtocolFactory | |
4 | from smb import smb_structs | |
5 | from .util import getConnectionInfo | |
6 | ||
7 | ||
8 | class ListSharesFactory(SMBProtocolFactory): | |
9 | ||
10 | def __init__(self, *args, **kwargs): | |
11 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
12 | self.d = defer.Deferred() | |
13 | self.d.addBoth(self.testDone) | |
14 | ||
15 | def testDone(self, r): | |
16 | if self.instance: | |
17 | self.instance.transport.loseConnection() | |
18 | return r | |
19 | ||
20 | def onAuthOK(self): | |
21 | def cb(results): | |
22 | assert 'smbtest' in [r.name.lower() for r in results] | |
23 | self.d.callback(True) | |
24 | self.instance.transport.loseConnection() | |
25 | ||
26 | d = self.listShares(timeout = 15) | |
27 | d.addCallback(cb) | |
28 | d.addErrback(self.d.errback) | |
29 | ||
30 | def onAuthFailed(self): | |
31 | self.d.errback('Auth failed') | |
32 | ||
33 | ||
34 | @deferred(timeout=15.0) | |
35 | def test_listshares_SMB1(): | |
36 | info = getConnectionInfo() | |
37 | smb_structs.SUPPORT_SMB2 = False | |
38 | ||
39 | factory = ListSharesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
40 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
41 | return factory.d | |
42 | ||
43 | @deferred(timeout=15.0) | |
44 | def test_listshares_SMB2(): | |
45 | info = getConnectionInfo() | |
46 | smb_structs.SUPPORT_SMB2 = True | |
47 | ||
48 | factory = ListSharesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
49 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
50 | return factory.d |
0 | ||
1 | from nose.twistedtools import reactor, deferred | |
2 | from twisted.internet import defer | |
3 | from smb.SMBProtocol import SMBProtocolFactory | |
4 | from smb import smb_structs | |
5 | from .util import getConnectionInfo | |
6 | ||
7 | ||
8 | class ListSnapshotsFactory(SMBProtocolFactory): | |
9 | ||
10 | def __init__(self, *args, **kwargs): | |
11 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
12 | self.d = defer.Deferred() | |
13 | self.d.addBoth(self.testDone) | |
14 | self.service_name = None | |
15 | self.path = None | |
16 | ||
17 | def testDone(self, r): | |
18 | if self.instance: | |
19 | self.instance.transport.loseConnection() | |
20 | return r | |
21 | ||
22 | def onAuthOK(self): | |
23 | def cb(results): | |
24 | assert len(results) > 0 | |
25 | self.d.callback(True) | |
26 | self.instance.transport.loseConnection() | |
27 | ||
28 | d = self.listSnapshots(self.service_name, self.path, timeout = 15) | |
29 | d.addCallback(cb) | |
30 | d.addErrback(self.d.errback) | |
31 | ||
32 | def onAuthFailed(self): | |
33 | self.d.errback('Auth failed') | |
34 | ||
35 | ||
36 | @deferred(timeout=15.0) | |
37 | def test_listshares_SMB1(): | |
38 | info = getConnectionInfo() | |
39 | smb_structs.SUPPORT_SMB2 = False | |
40 | ||
41 | factory = ListSnapshotsFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
42 | factory.service_name = 'smbtest' | |
43 | factory.path = '/rfc1001.txt' | |
44 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
45 | return factory.d | |
46 | ||
47 | @deferred(timeout=15.0) | |
48 | def test_listshares_SMB2(): | |
49 | info = getConnectionInfo() | |
50 | smb_structs.SUPPORT_SMB2 = True | |
51 | ||
52 | factory = ListSnapshotsFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
53 | factory.service_name = 'smbtest' | |
54 | factory.path = '/rfc1001.txt' | |
55 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
56 | return factory.d |
0 | # -*- coding: utf-8 -*- | |
1 | ||
2 | import os, random, time | |
3 | from io import StringIO | |
4 | from nose.twistedtools import reactor, deferred | |
5 | from twisted.internet import defer | |
6 | from smb.SMBProtocol import SMBProtocolFactory | |
7 | from smb import smb_structs | |
8 | from .util import getConnectionInfo | |
9 | ||
10 | ||
11 | class RenameFactory(SMBProtocolFactory): | |
12 | ||
13 | def __init__(self, *args, **kwargs): | |
14 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
15 | self.d = defer.Deferred() | |
16 | self.d.addBoth(self.testDone) | |
17 | self.service = '' | |
18 | self.new_path = '' | |
19 | self.old_path = '' | |
20 | ||
21 | def testDone(self, r): | |
22 | if self.instance: | |
23 | self.instance.transport.loseConnection() | |
24 | return r | |
25 | ||
26 | def pathCreated(self, result): | |
27 | d = self.listPath(self.service, os.path.dirname(self.old_path.replace('/', os.sep))) | |
28 | d.addCallback(self.listComplete) | |
29 | d.addErrback(self.d.errback) | |
30 | ||
31 | def listComplete(self, entries): | |
32 | filenames = [e.filename for e in entries] | |
33 | assert os.path.basename(self.old_path.replace('/', os.sep)) in filenames | |
34 | assert os.path.basename(self.new_path.replace('/', os.sep)) not in filenames | |
35 | ||
36 | d = self.rename(self.service, self.old_path, self.new_path) | |
37 | d.addCallback(self.renameComplete) | |
38 | d.addErrback(self.d.errback) | |
39 | ||
40 | def renameComplete(self, result): | |
41 | d = self.listPath(self.service, os.path.dirname(self.new_path.replace('/', os.sep))) | |
42 | d.addCallback(self.list2Complete) | |
43 | d.addErrback(self.d.errback) | |
44 | ||
45 | def list2Complete(self, entries): | |
46 | filenames = [e.filename for e in entries] | |
47 | assert os.path.basename(self.new_path.replace('/', os.sep)) in filenames | |
48 | assert os.path.basename(self.old_path.replace('/', os.sep)) not in filenames | |
49 | self.cleanup() | |
50 | ||
51 | def onAuthFailed(self): | |
52 | self.d.errback('Auth failed') | |
53 | ||
54 | ||
55 | class RenameFileFactory(RenameFactory): | |
56 | ||
57 | def onAuthOK(self): | |
58 | d = self.storeFile(self.service, self.old_path, StringIO('Rename file test')) | |
59 | d.addCallback(self.pathCreated) | |
60 | d.addErrback(self.d.errback) | |
61 | ||
62 | def cleanup(self): | |
63 | d = self.deleteFiles(self.service, self.new_path) | |
64 | d.chainDeferred(self.d) | |
65 | ||
66 | ||
67 | class RenameDirectoryFactory(RenameFactory): | |
68 | ||
69 | def onAuthOK(self): | |
70 | d = self.createDirectory(self.service, self.old_path) | |
71 | d.addCallback(self.pathCreated) | |
72 | d.addErrback(self.d.errback) | |
73 | ||
74 | def cleanup(self): | |
75 | d = self.deleteDirectory(self.service, self.new_path) | |
76 | d.chainDeferred(self.d) | |
77 | ||
78 | ||
79 | @deferred(timeout=30.0) | |
80 | def test_rename_english_file_SMB1(): | |
81 | info = getConnectionInfo() | |
82 | smb_structs.SUPPORT_SMB2 = False | |
83 | ||
84 | factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
85 | factory.service = 'smbtest' | |
86 | factory.old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
87 | factory.new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
88 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
89 | return factory.d | |
90 | ||
91 | @deferred(timeout=30.0) | |
92 | def test_rename_english_file_SMB2(): | |
93 | info = getConnectionInfo() | |
94 | smb_structs.SUPPORT_SMB2 = True | |
95 | ||
96 | factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
97 | factory.service = 'smbtest' | |
98 | factory.old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
99 | factory.new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
100 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
101 | return factory.d | |
102 | ||
103 | @deferred(timeout=30.0) | |
104 | def test_rename_unicode_file_SMB1(): | |
105 | info = getConnectionInfo() | |
106 | smb_structs.SUPPORT_SMB2 = False | |
107 | ||
108 | factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
109 | factory.service = 'smbtest' | |
110 | factory.old_path = '/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
111 | factory.new_path = '/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
112 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
113 | return factory.d | |
114 | ||
115 | @deferred(timeout=30.0) | |
116 | def test_rename_unicode_file_SMB2(): | |
117 | info = getConnectionInfo() | |
118 | smb_structs.SUPPORT_SMB2 = True | |
119 | ||
120 | factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
121 | factory.service = 'smbtest' | |
122 | factory.old_path = '/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
123 | factory.new_path = '/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) ) | |
124 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
125 | return factory.d | |
126 | ||
127 | @deferred(timeout=30.0) | |
128 | def test_rename_english_directory_SMB1(): | |
129 | info = getConnectionInfo() | |
130 | smb_structs.SUPPORT_SMB2 = False | |
131 | ||
132 | factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
133 | factory.service = 'smbtest' | |
134 | factory.old_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
135 | factory.new_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
136 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
137 | return factory.d | |
138 | ||
139 | @deferred(timeout=30.0) | |
140 | def test_rename_english_directory_SMB2(): | |
141 | info = getConnectionInfo() | |
142 | smb_structs.SUPPORT_SMB2 = True | |
143 | ||
144 | factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
145 | factory.service = 'smbtest' | |
146 | factory.old_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
147 | factory.new_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
148 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
149 | return factory.d | |
150 | ||
151 | @deferred(timeout=30.0) | |
152 | def test_rename_unicode_directory_SMB1(): | |
153 | info = getConnectionInfo() | |
154 | smb_structs.SUPPORT_SMB2 = False | |
155 | ||
156 | factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
157 | factory.service = 'smbtest' | |
158 | factory.old_path = '/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
159 | factory.new_path = '/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
160 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
161 | return factory.d | |
162 | ||
163 | @deferred(timeout=30.0) | |
164 | def test_rename_unicode_directory_SMB2(): | |
165 | info = getConnectionInfo() | |
166 | smb_structs.SUPPORT_SMB2 = True | |
167 | ||
168 | factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
169 | factory.service = 'smbtest' | |
170 | factory.old_path = '/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
171 | factory.new_path = '/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) ) | |
172 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
173 | return factory.d |
0 | # -*- coding: utf-8 -*- | |
1 | ||
2 | import os, tempfile | |
3 | from nose.twistedtools import reactor, deferred | |
4 | from twisted.internet import defer | |
5 | from smb.SMBProtocol import SMBProtocolFactory | |
6 | from smb import smb_structs | |
7 | from .util import getConnectionInfo | |
8 | ||
9 | try: | |
10 | import hashlib | |
11 | def MD5(): return hashlib.md5() | |
12 | except ImportError: | |
13 | import md5 | |
14 | def MD5(): return md5.new() | |
15 | ||
16 | ||
17 | class RetrieveFileFactory(SMBProtocolFactory): | |
18 | ||
19 | def __init__(self, *args, **kwargs): | |
20 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
21 | self.d = defer.Deferred() | |
22 | self.d.addBoth(self.testDone) | |
23 | self.temp_fh = tempfile.NamedTemporaryFile(prefix = 'pysmbtest-') | |
24 | self.service = '' | |
25 | self.path = '' | |
26 | self.digest = '' | |
27 | self.offset = 0 | |
28 | self.max_length = -1 | |
29 | self.filesize = 0 | |
30 | ||
31 | def testDone(self, r): | |
32 | if self.instance: | |
33 | self.instance.transport.loseConnection() | |
34 | return r | |
35 | ||
36 | def fileRetrieved(self, write_result): | |
37 | file_obj, file_attributes, file_size = write_result | |
38 | assert file_obj == self.temp_fh | |
39 | ||
40 | md = MD5() | |
41 | filesize = 0 | |
42 | self.temp_fh.seek(0) | |
43 | while True: | |
44 | s = self.temp_fh.read(8192) | |
45 | if not s: | |
46 | break | |
47 | md.update(s) | |
48 | filesize += len(s) | |
49 | ||
50 | assert self.filesize == filesize | |
51 | assert md.hexdigest() == self.digest | |
52 | ||
53 | self.temp_fh.close() | |
54 | self.d.callback(True) | |
55 | self.instance.transport.loseConnection() | |
56 | ||
57 | def onAuthOK(self): | |
58 | assert self.service | |
59 | assert self.path | |
60 | ||
61 | d = self.retrieveFileFromOffset(self.service, self.path, self.temp_fh, self.offset, self.max_length, timeout = 15) | |
62 | d.addCallback(self.fileRetrieved) | |
63 | d.addErrback(self.d.errback) | |
64 | ||
65 | def onAuthFailed(self): | |
66 | self.d.errback('Auth failed') | |
67 | ||
68 | ||
69 | @deferred(timeout=30.0) | |
70 | def test_retr_multiplereads_SMB1(): | |
71 | # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes) | |
72 | info = getConnectionInfo() | |
73 | smb_structs.SUPPORT_SMB2 = False | |
74 | ||
75 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
76 | factory.service = 'smbtest' | |
77 | factory.path = '/rfc1001.txt' | |
78 | factory.digest = '5367c2bbf97f521059c78eab65309ad3' | |
79 | factory.filesize = 158437 | |
80 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
81 | return factory.d | |
82 | ||
83 | @deferred(timeout=30.0) | |
84 | def test_retr_multiplereads_SMB2(): | |
85 | # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes) | |
86 | info = getConnectionInfo() | |
87 | smb_structs.SUPPORT_SMB2 = True | |
88 | ||
89 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
90 | factory.service = 'smbtest' | |
91 | factory.path = '/rfc1001.txt' | |
92 | factory.digest = '5367c2bbf97f521059c78eab65309ad3' | |
93 | factory.filesize = 158437 | |
94 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
95 | return factory.d | |
96 | ||
97 | @deferred(timeout=30.0) | |
98 | def test_retr_longfilename_SMB1(): | |
99 | # Test file retrieval that has a long English filename | |
100 | info = getConnectionInfo() | |
101 | smb_structs.SUPPORT_SMB2 = False | |
102 | ||
103 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
104 | factory.service = 'smbtest' | |
105 | factory.path = '/Implementing CIFS - SMB.html' | |
106 | factory.digest = '671c5700d279fcbbf958c1bba3c2639e' | |
107 | factory.filesize = 421269 | |
108 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
109 | return factory.d | |
110 | ||
111 | @deferred(timeout=30.0) | |
112 | def test_retr_longfilename_SMB2(): | |
113 | # Test file retrieval that has a long English filename | |
114 | info = getConnectionInfo() | |
115 | smb_structs.SUPPORT_SMB2 = True | |
116 | ||
117 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
118 | factory.service = 'smbtest' | |
119 | factory.path = '/Implementing CIFS - SMB.html' | |
120 | factory.digest = '671c5700d279fcbbf958c1bba3c2639e' | |
121 | factory.filesize = 421269 | |
122 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
123 | return factory.d | |
124 | ||
125 | @deferred(timeout=30.0) | |
126 | def test_retr_unicodefilename_SMB1(): | |
127 | # Test file retrieval that has a long non-English filename inside a folder with a non-English name | |
128 | info = getConnectionInfo() | |
129 | smb_structs.SUPPORT_SMB2 = False | |
130 | ||
131 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
132 | factory.service = 'smbtest' | |
133 | factory.path = '/测试文件夹/垃圾文件.dat' | |
134 | factory.digest = '8a44c1e80d55e91c92350955cdf83442' | |
135 | factory.filesize = 256000 | |
136 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
137 | return factory.d | |
138 | ||
139 | @deferred(timeout=30.0) | |
140 | def test_retr_unicodefilename_SMB2(): | |
141 | # Test file retrieval that has a long non-English filename inside a folder with a non-English name | |
142 | info = getConnectionInfo() | |
143 | smb_structs.SUPPORT_SMB2 = True | |
144 | ||
145 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
146 | factory.service = 'smbtest' | |
147 | factory.path = '/测试文件夹/垃圾文件.dat' | |
148 | factory.digest = '8a44c1e80d55e91c92350955cdf83442' | |
149 | factory.filesize = 256000 | |
150 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
151 | return factory.d | |
152 | ||
153 | @deferred(timeout=30.0) | |
154 | def test_retr_offset_SMB1(): | |
155 | # Test file retrieval from offset to EOF | |
156 | info = getConnectionInfo() | |
157 | smb_structs.SUPPORT_SMB2 = False | |
158 | ||
159 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
160 | factory.service = 'smbtest' | |
161 | factory.path = '/测试文件夹/垃圾文件.dat' | |
162 | factory.digest = 'a141bd8024571ce7cb5c67f2b0d8ea0b' | |
163 | factory.filesize = 156000 | |
164 | factory.offset = 100000 | |
165 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
166 | return factory.d | |
167 | ||
168 | @deferred(timeout=30.0) | |
169 | def test_retr_offset_SMB2(): | |
170 | # Test file retrieval from offset to EOF | |
171 | info = getConnectionInfo() | |
172 | smb_structs.SUPPORT_SMB2 = True | |
173 | ||
174 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
175 | factory.service = 'smbtest' | |
176 | factory.path = '/测试文件夹/垃圾文件.dat' | |
177 | factory.digest = 'a141bd8024571ce7cb5c67f2b0d8ea0b' | |
178 | factory.filesize = 156000 | |
179 | factory.offset = 100000 | |
180 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
181 | return factory.d | |
182 | ||
183 | @deferred(timeout=30.0) | |
184 | def test_retr_offset_and_biglimit_SMB1(): | |
185 | # Test file retrieval from offset with a big max_length | |
186 | info = getConnectionInfo() | |
187 | smb_structs.SUPPORT_SMB2 = False | |
188 | ||
189 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
190 | factory.service = 'smbtest' | |
191 | factory.path = '/测试文件夹/垃圾文件.dat' | |
192 | factory.digest = '83b7afd7c92cdece3975338b5ca0b1c5' | |
193 | factory.filesize = 100000 | |
194 | factory.offset = 100000 | |
195 | factory.max_length = 100000 | |
196 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
197 | return factory.d | |
198 | ||
199 | @deferred(timeout=30.0) | |
200 | def test_retr_offset_and_biglimit_SMB2(): | |
201 | # Test file retrieval from offset with a big max_length | |
202 | info = getConnectionInfo() | |
203 | smb_structs.SUPPORT_SMB2 = True | |
204 | ||
205 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
206 | factory.service = 'smbtest' | |
207 | factory.path = '/测试文件夹/垃圾文件.dat' | |
208 | factory.digest = '83b7afd7c92cdece3975338b5ca0b1c5' | |
209 | factory.filesize = 100000 | |
210 | factory.offset = 100000 | |
211 | factory.max_length = 100000 | |
212 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
213 | return factory.d | |
214 | ||
215 | @deferred(timeout=30.0) | |
216 | def test_retr_offset_and_smalllimit_SMB1(): | |
217 | # Test file retrieval from offset with a small max_length | |
218 | info = getConnectionInfo() | |
219 | smb_structs.SUPPORT_SMB2 = False | |
220 | ||
221 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
222 | factory.service = 'smbtest' | |
223 | factory.path = '/测试文件夹/垃圾文件.dat' | |
224 | factory.digest = '746f60a96b39b712a7b6e17ddde19986' | |
225 | factory.filesize = 10 | |
226 | factory.offset = 100000 | |
227 | factory.max_length = 10 | |
228 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
229 | return factory.d | |
230 | ||
231 | @deferred(timeout=30.0) | |
232 | def test_retr_offset_and_smalllimit_SMB2(): | |
233 | # Test file retrieval from offset with a small max_length | |
234 | info = getConnectionInfo() | |
235 | smb_structs.SUPPORT_SMB2 = True | |
236 | ||
237 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
238 | factory.service = 'smbtest' | |
239 | factory.path = '/测试文件夹/垃圾文件.dat' | |
240 | factory.digest = '746f60a96b39b712a7b6e17ddde19986' | |
241 | factory.filesize = 10 | |
242 | factory.offset = 100000 | |
243 | factory.max_length = 10 | |
244 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
245 | return factory.d | |
246 | ||
247 | @deferred(timeout=30.0) | |
248 | def test_retr_offset_and_zerolimit_SMB1(): | |
249 | # Test file retrieval from offset to EOF with max_length=0 | |
250 | info = getConnectionInfo() | |
251 | smb_structs.SUPPORT_SMB2 = False | |
252 | ||
253 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
254 | factory.service = 'smbtest' | |
255 | factory.path = '/测试文件夹/垃圾文件.dat' | |
256 | factory.digest = 'd41d8cd98f00b204e9800998ecf8427e' | |
257 | factory.filesize = 0 | |
258 | factory.offset = 100000 | |
259 | factory.max_length = 0 | |
260 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
261 | return factory.d | |
262 | ||
263 | @deferred(timeout=30.0) | |
264 | def test_retr_offset_and_zerolimit_SMB2(): | |
265 | # Test file retrieval from offset to EOF with max_length=0 | |
266 | info = getConnectionInfo() | |
267 | smb_structs.SUPPORT_SMB2 = True | |
268 | ||
269 | factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
270 | factory.service = 'smbtest' | |
271 | factory.path = '/测试文件夹/垃圾文件.dat' | |
272 | factory.digest = 'd41d8cd98f00b204e9800998ecf8427e' | |
273 | factory.filesize = 0 | |
274 | factory.offset = 100000 | |
275 | factory.max_length = 0 | |
276 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
277 | return factory.d |
0 | # -*- coding: utf-8 -*- | |
1 | ||
2 | import os, time, random | |
3 | from io import StringIO | |
4 | from nose.twistedtools import reactor, deferred | |
5 | from twisted.internet import defer | |
6 | from smb.SMBProtocol import SMBProtocolFactory | |
7 | from smb import smb_structs | |
8 | from .util import getConnectionInfo | |
9 | ||
10 | try: | |
11 | import hashlib | |
12 | def MD5(): return hashlib.md5() | |
13 | except ImportError: | |
14 | import md5 | |
15 | def MD5(): return md5.new() | |
16 | ||
17 | class StoreFilesFactory(SMBProtocolFactory): | |
18 | """ | |
19 | A super test factory that tests store file, list files, retrieve file and delete file functionlities in sequence. | |
20 | """ | |
21 | ||
22 | TEST_FILENAME = os.path.join(os.path.dirname(__file__), os.pardir, 'SupportFiles', 'binary.dat') | |
23 | TEST_FILESIZE = 256000 | |
24 | TEST_DIGEST = 'bb6303f76e29f354b6fdf6ef58587e48' | |
25 | ||
26 | def __init__(self, *args, **kwargs): | |
27 | SMBProtocolFactory.__init__(self, *args, **kwargs) | |
28 | self.d = defer.Deferred() | |
29 | self.d.addBoth(self.testDone) | |
30 | self.service_name = '' | |
31 | self.filename = '' | |
32 | ||
33 | def testDone(self, r): | |
34 | if self.instance: | |
35 | self.instance.transport.loseConnection() | |
36 | return r | |
37 | ||
38 | def storeComplete(self, result): | |
39 | file_obj, filesize = result | |
40 | file_obj.close() | |
41 | assert filesize == self.TEST_FILESIZE | |
42 | ||
43 | d = self.listPath(self.service_name, os.path.dirname(self.filename.replace('/', os.sep))) | |
44 | d.addCallback(self.listComplete) | |
45 | d.addErrback(self.d.errback) | |
46 | ||
47 | def listComplete(self, entries): | |
48 | filenames = [e.filename for e in entries] | |
49 | assert os.path.basename(self.filename.replace('/', os.sep)) in filenames | |
50 | ||
51 | for entry in entries: | |
52 | if os.path.basename(self.filename.replace('/', os.sep)) == entry.filename: | |
53 | # The following asserts will fail if the remote machine's time is not in sync with the test machine's time | |
54 | assert abs(entry.create_time - time.time()) < 3 | |
55 | assert abs(entry.last_access_time - time.time()) < 3 | |
56 | assert abs(entry.last_write_time - time.time()) < 3 | |
57 | assert abs(entry.last_attr_change_time - time.time()) < 3 | |
58 | break | |
59 | ||
60 | d = self.retrieveFile(self.service_name, self.filename, StringIO()) | |
61 | d.addCallback(self.retrieveComplete) | |
62 | d.addErrback(self.d.errback) | |
63 | ||
64 | def retrieveComplete(self, result): | |
65 | file_obj, file_attributes, file_size = result | |
66 | ||
67 | md = MD5() | |
68 | md.update(file_obj.getvalue()) | |
69 | file_obj.close() | |
70 | ||
71 | assert file_size == self.TEST_FILESIZE | |
72 | assert md.hexdigest() == self.TEST_DIGEST | |
73 | ||
74 | d = self.deleteFiles(self.service_name, self.filename) | |
75 | d.addCallback(self.deleteComplete) | |
76 | d.addErrback(self.d.errback) | |
77 | ||
78 | def deleteComplete(self, result): | |
79 | d = self.listPath(self.service_name, os.path.dirname(self.filename.replace('/', os.sep))) | |
80 | d.addCallback(self.list2Complete) | |
81 | d.addErrback(self.d.errback) | |
82 | ||
83 | def list2Complete(self, entries): | |
84 | filenames = [e.filename for e in entries] | |
85 | assert os.path.basename(self.filename.replace('/', os.sep)) not in filenames | |
86 | self.d.callback(True) | |
87 | self.instance.transport.loseConnection() | |
88 | ||
89 | def onAuthOK(self): | |
90 | d = self.storeFile(self.service_name, self.filename, open(self.TEST_FILENAME, 'rb')) | |
91 | d.addCallback(self.storeComplete) | |
92 | d.addErrback(self.d.errback) | |
93 | ||
94 | def onAuthFailed(self): | |
95 | self.d.errback('Auth failed') | |
96 | ||
97 | ||
98 | @deferred(timeout=30.0) | |
99 | def test_store_long_filename_SMB1(): | |
100 | info = getConnectionInfo() | |
101 | smb_structs.SUPPORT_SMB2 = False | |
102 | ||
103 | factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
104 | factory.service_name = 'smbtest' | |
105 | factory.filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) | |
106 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
107 | return factory.d | |
108 | ||
109 | @deferred(timeout=30.0) | |
110 | def test_store_long_filename_SMB2(): | |
111 | info = getConnectionInfo() | |
112 | smb_structs.SUPPORT_SMB2 = True | |
113 | ||
114 | factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
115 | factory.service_name = 'smbtest' | |
116 | factory.filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) | |
117 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
118 | return factory.d | |
119 | ||
120 | @deferred(timeout=30.0) | |
121 | def test_store_unicode_filename_SMB1(): | |
122 | info = getConnectionInfo() | |
123 | smb_structs.SUPPORT_SMB2 = False | |
124 | ||
125 | factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
126 | factory.service_name = 'smbtest' | |
127 | factory.filename = os.sep + '上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) | |
128 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
129 | return factory.d | |
130 | ||
131 | @deferred(timeout=30.0) | |
132 | def test_store_unicode_filename_SMB2(): | |
133 | info = getConnectionInfo() | |
134 | smb_structs.SUPPORT_SMB2 = True | |
135 | ||
136 | factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) | |
137 | factory.service_name = 'smbtest' | |
138 | factory.filename = os.sep + '上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) ) | |
139 | reactor.connectTCP(info['server_ip'], info['server_port'], factory) | |
140 | return factory.d |
0 | ||
1 | import os | |
2 | from configparser import SafeConfigParser | |
3 | ||
4 | def getConnectionInfo(): | |
5 | config_filename = os.path.join(os.path.dirname(__file__), os.path.pardir, 'connection.ini') | |
6 | cp = SafeConfigParser() | |
7 | cp.read(config_filename) | |
8 | ||
9 | info = { | |
10 | 'server_name': cp.get('server', 'name'), | |
11 | 'server_ip': cp.get('server', 'ip'), | |
12 | 'server_port': cp.getint('server', 'port'), | |
13 | 'client_name': cp.get('client', 'name'), | |
14 | 'user': cp.get('user', 'name'), | |
15 | 'password': cp.get('user', 'password'), | |
16 | } | |
17 | return info | |
18 |
2 | 2 | name = SERVER |
3 | 3 | ip = 192.168.1.1 |
4 | 4 | port = 139 |
5 | direct_port = 445 | |
5 | 6 | |
6 | 7 | [client] |
7 | 8 | name = TESTCLIENT |
0 | import binascii | |
1 | ||
2 | from smb import security_descriptors as sd | |
3 | from smb import smb_constants as sc | |
4 | ||
5 | ||
6 | def test_sid_string_representation(): | |
7 | sid = sd.SID(1, 5, [2, 3, 4]) | |
8 | assert str(sid) == "S-1-5-2-3-4" | |
9 | sid = sd.SID(1, 2**32 + 3, []) | |
10 | assert str(sid) == "S-1-0x100000003" | |
11 | sid = sd.SID(1, 2**32, [3, 2, 1]) | |
12 | assert str(sid) == "S-1-0x100000000-3-2-1" | |
13 | ||
14 | ||
15 | def test_sid_binary_parsing(): | |
16 | raw_sid = binascii.unhexlify(b""" | |
17 | 01 05 00 00 00 00 00 05 15 00 00 00 de 53 c1 2a | |
18 | 2a 4f da ca c1 79 a6 32 b1 04 00 00 | |
19 | """.translate(None, b' \n')) | |
20 | assert str(sd.SID.from_bytes(raw_sid)) == "S-1-5-21-717312990-3403304746-849770945-1201" | |
21 | raw_sid += b"garbage" | |
22 | assert str(sd.SID.from_bytes(raw_sid)) == "S-1-5-21-717312990-3403304746-849770945-1201" | |
23 | sid, tail = sd.SID.from_bytes(raw_sid, return_tail=True) | |
24 | assert str(sid) == "S-1-5-21-717312990-3403304746-849770945-1201" | |
25 | assert tail == b"garbage" | |
26 | ||
27 | ||
28 | def test_ace_binary_parsing(): | |
29 | raw_ace = binascii.unhexlify(b""" | |
30 | 00 10 24 00 ff 01 1f 00 01 05 00 00 00 00 00 05 | |
31 | 15 00 00 00 de 53 c1 2a 2a 4f da ca c1 79 a6 32 | |
32 | 6e 04 00 00 | |
33 | """.translate(None, b' \n')) | |
34 | ace = sd.ACE.from_bytes(raw_ace) | |
35 | assert str(ace.sid) == "S-1-5-21-717312990-3403304746-849770945-1134" | |
36 | assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED | |
37 | assert ace.flags == sd.ACE_FLAG_INHERITED | |
38 | assert ace.mask == (sc.SYNCHRONIZE | sc.WRITE_OWNER | sc.WRITE_DAC | |
39 | | sc.READ_CONTROL | sc.DELETE | sc.FILE_READ_DATA | |
40 | | sc.FILE_WRITE_DATA | sc.FILE_APPEND_DATA | |
41 | | sc.FILE_READ_EA | sc.FILE_WRITE_EA | sc.FILE_EXECUTE | |
42 | | sc.FILE_DELETE_CHILD | sc.FILE_READ_ATTRIBUTES | |
43 | | sc.FILE_WRITE_ATTRIBUTES) | |
44 | assert not ace.additional_data | |
45 | ||
46 | raw_ace = binascii.unhexlify(b""" | |
47 | 00 13 18 00 a9 00 12 00 01 02 00 00 00 00 00 05 | |
48 | 20 00 00 00 21 02 00 00 | |
49 | """.translate(None, b' \n')) | |
50 | ace = sd.ACE.from_bytes(raw_ace) | |
51 | assert str(ace.sid) == "S-1-5-32-545" | |
52 | assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED | |
53 | assert ace.flags == (sd.ACE_FLAG_INHERITED | sd.ACE_FLAG_CONTAINER_INHERIT | |
54 | | sd.ACE_FLAG_OBJECT_INHERIT) | |
55 | assert ace.mask == (sc.SYNCHRONIZE | sc.READ_CONTROL | sc.FILE_READ_DATA | |
56 | | sc.FILE_READ_EA | sc.FILE_EXECUTE | |
57 | | sc.FILE_READ_ATTRIBUTES) | |
58 | assert not ace.additional_data | |
59 | ||
60 | raw_ace = binascii.unhexlify(b""" | |
61 | 01 03 24 00 a9 00 02 00 01 05 00 00 00 00 00 05 | |
62 | 15 00 00 00 de 53 c1 2a 2a 4f da ca c1 79 a6 32 | |
63 | 6c 04 00 00 | |
64 | """.translate(None, b' \n')) | |
65 | ace = sd.ACE.from_bytes(raw_ace) | |
66 | assert str(ace.sid) == "S-1-5-21-717312990-3403304746-849770945-1132" | |
67 | assert ace.type == sd.ACE_TYPE_ACCESS_DENIED | |
68 | assert ace.flags == (sd.ACE_FLAG_CONTAINER_INHERIT | |
69 | | sd.ACE_FLAG_OBJECT_INHERIT) | |
70 | assert ace.mask == (sc.READ_CONTROL | sc.FILE_READ_DATA | sc.FILE_READ_EA | |
71 | | sc.FILE_EXECUTE | sc.FILE_READ_ATTRIBUTES) | |
72 | assert not ace.additional_data | |
73 | ||
74 | ||
75 | def test_acl_binary_parsing(): | |
76 | raw_acl = binascii.unhexlify(b""" | |
77 | 02 00 70 00 04 00 00 00 00 10 18 00 89 00 10 00 | |
78 | 01 02 00 00 00 00 00 05 20 00 00 00 21 02 00 00 | |
79 | 00 10 14 00 ff 01 1f 00 01 01 00 00 00 00 00 05 | |
80 | 12 00 00 00 00 10 18 00 ff 01 1f 00 01 02 00 00 | |
81 | 00 00 00 05 20 00 00 00 20 02 00 00 00 10 24 00 | |
82 | ff 01 1f 00 01 05 00 00 00 00 00 05 15 00 00 00 | |
83 | de 53 c1 2a 2a 4f da ca c1 79 a6 32 b1 04 00 00 | |
84 | """.translate(None, b' \n')) | |
85 | acl = sd.ACL.from_bytes(raw_acl) | |
86 | assert acl.revision == 2 | |
87 | assert len(acl.aces) == 4 | |
88 | ||
89 | ace = acl.aces[0] | |
90 | assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED | |
91 | assert str(ace.sid) == "S-1-5-32-545" | |
92 | assert ace.flags == sd.ACE_FLAG_INHERITED | |
93 | assert ace.mask == (sc.SYNCHRONIZE | sc.FILE_READ_DATA | sc.FILE_READ_EA | |
94 | | sc.FILE_READ_ATTRIBUTES) | |
95 | ||
96 | ace = acl.aces[3] | |
97 | assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED | |
98 | assert str(ace.sid) == "S-1-5-21-717312990-3403304746-849770945-1201" | |
99 | assert ace.flags == sd.ACE_FLAG_INHERITED | |
100 | assert ace.mask == (sc.SYNCHRONIZE | sc.WRITE_OWNER | sc.WRITE_DAC | |
101 | | sc.READ_CONTROL | sc.DELETE | sc.FILE_READ_DATA | |
102 | | sc.FILE_WRITE_DATA | sc.FILE_APPEND_DATA | |
103 | | sc.FILE_READ_EA | sc.FILE_WRITE_EA | sc.FILE_EXECUTE | |
104 | | sc.FILE_DELETE_CHILD | sc.FILE_READ_ATTRIBUTES | |
105 | | sc.FILE_WRITE_ATTRIBUTES) | |
106 | ||
107 | ||
108 | def test_descriptor_binary_parsing(): | |
109 | raw_descriptor = binascii.unhexlify(b""" | |
110 | 01 00 04 84 14 00 00 00 30 00 00 00 00 00 00 00 | |
111 | 4c 00 00 00 01 05 00 00 00 00 00 05 15 00 00 00 | |
112 | de 53 c1 2a 2a 4f da ca c1 79 a6 32 b1 04 00 00 | |
113 | 01 05 00 00 00 00 00 05 15 00 00 00 de 53 c1 2a | |
114 | 2a 4f da ca c1 79 a6 32 01 02 00 00 02 00 70 00 | |
115 | 04 00 00 00 00 10 18 00 89 00 10 00 01 02 00 00 | |
116 | 00 00 00 05 20 00 00 00 21 02 00 00 00 10 14 00 | |
117 | ff 01 1f 00 01 01 00 00 00 00 00 05 12 00 00 00 | |
118 | 00 10 18 00 ff 01 1f 00 01 02 00 00 00 00 00 05 | |
119 | 20 00 00 00 20 02 00 00 00 10 24 00 ff 01 1f 00 | |
120 | 01 05 00 00 00 00 00 05 15 00 00 00 de 53 c1 2a | |
121 | 2a 4f da ca c1 79 a6 32 b1 04 00 00 | |
122 | """.translate(None, b' \n')) | |
123 | descriptor = sd.SecurityDescriptor.from_bytes(raw_descriptor) | |
124 | assert descriptor.flags == (sd.SECURITY_DESCRIPTOR_SELF_RELATIVE | |
125 | | sd.SECURITY_DESCRIPTOR_DACL_PRESENT | |
126 | | sd.SECURITY_DESCRIPTOR_DACL_AUTO_INHERITED) | |
127 | assert descriptor.dacl is not None | |
128 | assert descriptor.sacl is None | |
129 | assert str(descriptor.owner) == "S-1-5-21-717312990-3403304746-849770945-1201" | |
130 | assert str(descriptor.group) == "S-1-5-21-717312990-3403304746-849770945-513" | |
131 | ||
132 | acl = descriptor.dacl | |
133 | assert acl.revision == 2 | |
134 | assert len(acl.aces) == 4 | |
135 | assert str(acl.aces[0].sid) == sd.SID_BUILTIN_USERS | |
136 | assert str(acl.aces[1].sid) == sd.SID_LOCAL_SYSTEM | |
137 | assert str(acl.aces[2].sid) == sd.SID_BUILTIN_ADMINISTRATORS | |
138 | assert str(acl.aces[3].sid) == "S-1-5-21-717312990-3403304746-849770945-1201" |
7 | 7 | |
8 | 8 | setup( |
9 | 9 | name = "pysmb", |
10 | version = "1.1.19", | |
10 | version = "1.2.6", | |
11 | 11 | author = "Michael Teo", |
12 | 12 | author_email = "[email protected]", |
13 | 13 | license = "zlib/libpng", |
5 | 5 | |
6 | 6 | Notes |
7 | 7 | ----- |
8 | * Note that you need to pass in a valid hostname or IP address for the host component of the URL. | |
9 | Do not use the Windows/NetBIOS machine name for the host component. | |
8 | * The host component of the URL must be one of the following: | |
9 | ||
10 | * A fully-qualified hostname that can be resolved by your local DNS service. Example: myserver.test.com | |
11 | * An IP address. Example: 192.168.1.1 | |
12 | * A comma-separated string "<NBName>,<IP>" where *<NBName>* is the Windows/NetBIOS machine name for remote SMB service, and *<IP>* is the service's IP address. Example: MYSERVER,192.168.1.1 | |
13 | ||
10 | 14 | * The first component of the path in the URL points to the name of the shared folder. |
11 | 15 | Subsequent path components will point to the directory/folder of the file. |
12 | 16 | * You can retrieve and upload files, but you cannot delete files/folders or create folders. |
15 | 19 | Example |
16 | 20 | ------- |
17 | 21 | |
18 | The following code snippet illustrates file retrieval.:: | |
22 | The following code snippet illustrates file retrieval with Python 2.:: | |
19 | 23 | |
20 | 24 | # -*- coding: utf-8 -*- |
21 | 25 | import urllib2 |
33 | 37 | # Process fh2 like a file-like object and then close it. |
34 | 38 | fh2.close() |
35 | 39 | |
36 | The following code snippet illustrates file upload. You need to provide a file-like object for the *data* parameter in the *open()* method:: | |
40 | The following code snippet illustrates file upload with Python 2. You need to provide a file-like object for the *data* parameter in the *open()* method:: | |
37 | 41 | |
38 | 42 | import urllib2 |
39 | 43 | from smb.SMBHandler import SMBHandler |
45 | 49 | |
46 | 50 | # Reading from fh will only return an empty string |
47 | 51 | fh.close() |
52 | ||
53 | ||
54 | The following code snippet illustrates file retrieval with Python 3.:: | |
55 | ||
56 | import urllib | |
57 | from smb.SMBHandler import SMBHandler | |
58 | ||
59 | director = urllib.request.build_opener(SMBHandler) | |
60 | fh = director.open('smb://myuserID:[email protected]/sharedfolder/rfc1001.txt') | |
61 | ||
62 | # Process fh like a file-like object and then close it. | |
63 | fh.close() | |
64 | ||
65 | # For paths/files with unicode characters, simply pass in the URL as an unicode string | |
66 | fh2 = director.open(u'smb://myuserID:[email protected]/sharedfolder/测试文件夹/垃圾文件.dat') | |
67 | ||
68 | # Process fh2 like a file-like object and then close it. | |
69 | fh2.close() | |
70 | ||
71 | The following code snippet illustrates file upload with Python 3. You need to provide a file-like object for the *data* parameter in the *open()* method:: | |
72 | ||
73 | import urllib | |
74 | from smb.SMBHandler import SMBHandler | |
75 | ||
76 | file_fh = open('local_file.dat', 'rb') | |
77 | ||
78 | director = urllib.request.build_opener(SMBHandler) | |
79 | fh = director.open('smb://myuserID:[email protected]/sharedfolder/upload_file.dat', data = file_fh) | |
80 | ||
81 | # Reading from fh will only return an empty string | |
82 | fh.close() |
0 | ||
1 | Security Descriptors | |
2 | ==================== | |
3 | ||
4 | .. module:: smb.security_descriptors | |
5 | :synopsis: Data structures used in Windows security descriptors. | |
6 | ||
7 | This module implements security descriptors, and associated data | |
8 | structures, as specified in `[MS-DTYP]`_. | |
9 | ||
10 | .. autoclass:: SID | |
11 | :members: | |
12 | ||
13 | .. autoclass:: ACE | |
14 | :members: | |
15 | ||
16 | .. autoclass:: ACL | |
17 | :members: | |
18 | ||
19 | .. autoclass:: SecurityDescriptor | |
20 | :members: | |
21 | ||
22 | .. _[MS-DTYP]: https://msdn.microsoft.com/en-us/library/cc230273.aspx |
0 | 0 | # -*- coding: utf-8 -*- |
1 | # | |
2 | # pysmb documentation build configuration file, created by | |
3 | # sphinx-quickstart on Sun Dec 18 15:54:40 2011. | |
4 | # | |
5 | # This file is execfile()d with the current directory set to its containing dir. | |
6 | # | |
7 | # Note that not all possible configuration values are present in this | |
8 | # autogenerated file. | |
9 | 1 | # |
10 | 2 | # All configuration values have a default; values that are commented out |
11 | 3 | # serve to show the default. |
16 | 8 | # add these directories to sys.path here. If the directory is relative to the |
17 | 9 | # documentation root, use os.path.abspath to make it absolute, like shown here. |
18 | 10 | #sys.path.insert(0, os.path.abspath('.')) |
19 | sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'python2')) | |
11 | sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'python3')) | |
20 | 12 | |
21 | 13 | # -- General configuration ----------------------------------------------------- |
22 | 14 | |
41 | 33 | |
42 | 34 | # General information about the project. |
43 | 35 | project = u'pysmb' |
44 | copyright = u'2001-2015, Michael Teo http://miketeo.net/' | |
36 | copyright = u'2001-2021, Michael Teo https://miketeo.net/' | |
45 | 37 | |
46 | 38 | # The version info for the project you're documenting, acts as replacement for |
47 | 39 | # |version| and |release|, also used in various other places throughout the |
48 | 40 | # built documents. |
49 | 41 | # |
50 | 42 | # The short X.Y version. |
51 | version = '1.1.18' | |
43 | version = '1.2.6' | |
52 | 44 | # The full version, including alpha/beta/rc tags. |
53 | release = '1.1.18' | |
45 | release = '1.2.6' | |
54 | 46 | |
55 | 47 | # The language for content autogenerated by Sphinx. Refer to documentation |
56 | 48 | # for a list of supported languages. |
13 | 13 | 3. Write your own loop handling method to read data from the socket. Once data have been read, call *feedData* method with the parameter. |
14 | 14 | The *feedData* method has its own internal buffer, so it can accept incomplete NetBIOS session packet data. |
15 | 15 | 4. Override |
16 | ||
16 | 17 | * *onAuthOK* method to include your own operations to perform when authentication is successful. You can initiate file operations in this method. |
17 | 18 | * *onAuthFailed* method to include your own processing on what to do when authentication fails. You can report this as an error, or to try a different NTLM authentication algorithm (*use_ntlm_v2* parameter in the constructor). |
18 | 19 | * *onNMBSessionFailed* method to include your own processing on what to do when pysmb fails to setup the NetBIOS session with the remote server. Usually, this is due to a wrong *remote_name* parameter in the constructor. |
0 | .. pysmb documentation master file, created by | |
1 | sphinx-quickstart on Sun Dec 18 15:54:40 2011. | |
2 | You can adapt this file completely to your liking, but it should at least | |
3 | contain the root `toctree` directive. | |
4 | ||
5 | 0 | Welcome to pysmb's documentation! |
6 | 1 | ================================= |
7 | 2 | |
8 | 3 | pysmb is a pure Python implementation of the client-side SMB/CIFS protocol (SMB1 and SMB2) which is the underlying protocol |
9 | 4 | that facilitates file sharing and printing between Windows machines, as well as with Linux machines via the Samba server application. |
10 | pysmb is developed in Python 2.4.6, Python 2.7.1 and Python 3.2.3 and has been tested against shared folders on Windows XP SP3, Windows Vista, Windows 7 and Samba 3.x. | |
5 | pysmb is developed in Python 2.7.x and Python 3.8.x and has been tested against shared folders on Windows 7, Windows 10 and Samba 4.x. | |
11 | 6 | |
12 | The latest version of pysmb is always available at the pysmb project page at `miketeo.net <http://miketeo.net/wp/index.php/projects/pysmb>`_. | |
7 | The latest version of pysmb is always available at the pysmb project page at `miketeo.net <http://miketeo.net/projects/pysmb>`_. | |
13 | 8 | |
14 | 9 | License |
15 | 10 | ------- |
89 | 84 | As a software developer who is looking to modify pysmb so that you can integrate it to other network frameworks: |
90 | 85 | * Read :doc:`extending` |
91 | 86 | |
87 | If you are upgrading from older pysmb versions: | |
88 | * Read :doc:`upgrading` | |
92 | 89 | |
93 | 90 | |
94 | 91 | Indices and tables |
100 | 97 | |
101 | 98 | api/* |
102 | 99 | extending |
100 | upgrading | |
103 | 101 | |
104 | 102 | * :ref:`genindex` |
105 | 103 | * :ref:`search` |
0 | Upgrading from older pysmb versions | |
1 | ==================================== | |
2 | ||
3 | This page documents the improvements and changes to the API that could be incompatible with previous releases. | |
4 | ||
5 | pysmb 1.2.0 | |
6 | ----------- | |
7 | - Add new `delete_matching_folders` parameter to `deleteFiles()` method in SMBProtocolFactory and SMBConnection | |
8 | class to support deletion of sub-folders. If you are passing timeout parameter to the `deleteFiles()` method | |
9 | in your application, please switch to using named parameter for timeout. | |
10 | ||
11 | pysmb 1.1.28 | |
12 | ------------ | |
13 | - SharedFile instances returned from the `listPath()` method now has a new property | |
14 | `file_id` attribute which represents the file reference number given by the remote SMB server. | |
15 | ||
16 | pysmb 1.1.26 | |
17 | ------------ | |
18 | - SMBConnection class can now be used as a context manager | |
19 | ||
20 | pysmb 1.1.25 | |
21 | ------------ | |
22 | - SharedFile class has a new property `isNormal` which will be True if the file is a | |
23 | 'normal' file. pysmb defines a 'normal' file as a file entry that is not | |
24 | read-only, not hidden, not system, not archive and not a directory; | |
25 | it ignores other attributes like compression, indexed, sparse, temporary and encryption. | |
26 | - `listPath()` method in SMBProtocolFactory and SMBConnection class will now include | |
27 | 'normal' files by default if you do not specify the `search` parameter. | |
28 | ||
29 | pysmb 1.1.20 | |
30 | ------------ | |
31 | - A new method `getSecurity()` was added to SMBConnection and SMBProtocolFactory class. | |
32 | ||
33 | pysmb 1.1.15 | |
34 | ------------ | |
35 | - Add new `truncate` parameter to `storeFileFromOffset()` in SMBProtocolFactory and SMBConnection | |
36 | class to support truncation of the file before writing. If you are passing timeout parameter | |
37 | to the `storeFileFromOffset()` method in your application, please switch to using named parameter for timeout. | |
38 | ||
39 | pysmb 1.1.11 | |
40 | ------------ | |
41 | - A new method `storeFileFromOffset()` was added to SMBConnection and SMBProtocolFactory class. | |
42 | ||
43 | pysmb 1.1.10 | |
44 | ------------ | |
45 | - A new method `getAttributes()` was added to SMBConnection and SMBProtocolFactory class | |
46 | - SharedFile class has a new property `isReadOnly` to indicate the file is read-only on the remote filesystem. | |
47 | ||
48 | pysmb 1.1.2 | |
49 | ----------- | |
50 | - `queryIPForName()` method in nmb.NetBIOS and nmb.NBNSProtocol class will now return only the server machine name and ignore workgroup names. | |
51 | ||
52 | pysmb 1.0.3 | |
53 | ----------- | |
54 | - Two new methods were added to NBNSProtocol class: `queryIPForName()` and `NetBIOS.queryIPForName()` | |
55 | to support querying for a machine's NetBIOS name at the given IP address. | |
56 | - A new method `retrieveFileFromOffset()` was added to SMBProtocolFactory and SMBConnection | |
57 | to support finer control of file retrieval operation. | |
58 | ||
59 | pysmb 1.0.0 | |
60 | ----------- | |
61 | pysmb was completely rewritten in version 1.0.0. | |
62 | If you are upgrading from pysmb 0.x, you most likely have to rewrite your application for the new 1.x API. |