├── .gitignore ├── LICENSE.md ├── README.md ├── SMBClient.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── masc.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── masc.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── SMBClient.xcscheme │ ├── Universal Framework.xcscheme │ └── xcschememanagement.plist ├── SMBClient ├── Info.plist ├── Protected │ ├── SMBError.h │ ├── SMBError.m │ ├── SMBFileServer_Protected.h │ ├── SMBFile_Protected.h │ └── SMBShare_Protected.h ├── SMBClient.h ├── SMBDevice.h ├── SMBDevice.m ├── SMBDiscovery.h ├── SMBDiscovery.m ├── SMBFile.h ├── SMBFile.m ├── SMBFileServer.h ├── SMBFileServer.m ├── SMBShare.h └── SMBShare.m ├── SMBClientTests ├── Info.plist └── SMBClientTests.m └── ThirdParty ├── libdsm ├── include │ ├── bdsm.h │ ├── netbios_defs.h │ ├── netbios_ns.h │ ├── smb_defs.h │ ├── smb_dir.h │ ├── smb_file.h │ ├── smb_session.h │ ├── smb_share.h │ ├── smb_stat.h │ └── smb_types.h ├── libdsm-iOS.a └── libdsm-tvOS.a └── libtasn1 ├── include └── libtasn1.h ├── libtasn1-iOS.a └── libtasn1-tvOS.a /.gitignore: -------------------------------------------------------------------------------- 1 | SMBClient.framework 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # SMBClient License 2 | `SMBClient` is licensed under the GNU Lesser General Public License version 2.1 3 | or later. 4 | 5 | ## The GNU Lesser General Public License, version 2.1 (LGPL-2.1) 6 | _Version 2.1, February 1999_ 7 | _Copyright © 1991, 1999 Free Software Foundation, Inc._ 8 | _51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA_ 9 | 10 | _This is the first released version of the Lesser GPL. It also counts 11 | as the successor of the GNU Library Public License, version 2, hence 12 | the version number 2.1._ 13 | 14 | ### Preamble 15 | 16 | The licenses for most software are designed to take away your 17 | freedom to share and change it. By contrast, the GNU General Public 18 | Licenses are intended to guarantee your freedom to share and change 19 | free software--to make sure the software is free for all its users. 20 | 21 | This license, the Lesser General Public License, applies to some 22 | specially designated software packages--typically libraries--of the 23 | Free Software Foundation and other authors who decide to use it. You 24 | can use it too, but we suggest you first think carefully about whether 25 | this license or the ordinary General Public License is the better 26 | strategy to use in any particular case, based on the explanations below. 27 | 28 | When we speak of free software, we are referring to freedom of use, 29 | not price. Our General Public Licenses are designed to make sure that 30 | you have the freedom to distribute copies of free software (and charge 31 | for this service if you wish); that you receive source code or can get 32 | it if you want it; that you can change the software and use pieces of 33 | it in new free programs; and that you are informed that you can do 34 | these things. 35 | 36 | To protect your rights, we need to make restrictions that forbid 37 | distributors to deny you these rights or to ask you to surrender these 38 | rights. These restrictions translate to certain responsibilities for 39 | you if you distribute copies of the library or if you modify it. 40 | 41 | For example, if you distribute copies of the library, whether gratis 42 | or for a fee, you must give the recipients all the rights that we gave 43 | you. You must make sure that they, too, receive or can get the source 44 | code. If you link other code with the library, you must provide 45 | complete object files to the recipients, so that they can relink them 46 | with the library after making changes to the library and recompiling 47 | it. And you must show them these terms so they know their rights. 48 | 49 | We protect your rights with a two-step method: **(1)** we copyright the 50 | library, and **(2)** we offer you this license, which gives you legal 51 | permission to copy, distribute and/or modify the library. 52 | 53 | To protect each distributor, we want to make it very clear that 54 | there is no warranty for the free library. Also, if the library is 55 | modified by someone else and passed on, the recipients should know 56 | that what they have is not the original version, so that the original 57 | author's reputation will not be affected by problems that might be 58 | introduced by others. 59 | 60 | Finally, software patents pose a constant threat to the existence of 61 | any free program. We wish to make sure that a company cannot 62 | effectively restrict the users of a free program by obtaining a 63 | restrictive license from a patent holder. Therefore, we insist that 64 | any patent license obtained for a version of the library must be 65 | consistent with the full freedom of use specified in this license. 66 | 67 | Most GNU software, including some libraries, is covered by the 68 | ordinary GNU General Public License. This license, the GNU Lesser 69 | General Public License, applies to certain designated libraries, and 70 | is quite different from the ordinary General Public License. We use 71 | this license for certain libraries in order to permit linking those 72 | libraries into non-free programs. 73 | 74 | When a program is linked with a library, whether statically or using 75 | a shared library, the combination of the two is legally speaking a 76 | combined work, a derivative of the original library. The ordinary 77 | General Public License therefore permits such linking only if the 78 | entire combination fits its criteria of freedom. The Lesser General 79 | Public License permits more lax criteria for linking other code with 80 | the library. 81 | 82 | We call this license the “Lesser” General Public License because it 83 | does Less to protect the user's freedom than the ordinary General 84 | Public License. It also provides other free software developers Less 85 | of an advantage over competing non-free programs. These disadvantages 86 | are the reason we use the ordinary General Public License for many 87 | libraries. However, the Lesser license provides advantages in certain 88 | special circumstances. 89 | 90 | For example, on rare occasions, there may be a special need to 91 | encourage the widest possible use of a certain library, so that it becomes 92 | a de-facto standard. To achieve this, non-free programs must be 93 | allowed to use the library. A more frequent case is that a free 94 | library does the same job as widely used non-free libraries. In this 95 | case, there is little to gain by limiting the free library to free 96 | software only, so we use the Lesser General Public License. 97 | 98 | In other cases, permission to use a particular library in non-free 99 | programs enables a greater number of people to use a large body of 100 | free software. For example, permission to use the GNU C Library in 101 | non-free programs enables many more people to use the whole GNU 102 | operating system, as well as its variant, the GNU/Linux operating 103 | system. 104 | 105 | Although the Lesser General Public License is Less protective of the 106 | users' freedom, it does ensure that the user of a program that is 107 | linked with the Library has the freedom and the wherewithal to run 108 | that program using a modified version of the Library. 109 | 110 | The precise terms and conditions for copying, distribution and 111 | modification follow. Pay close attention to the difference between a 112 | “work based on the library” and a “work that uses the library”. The 113 | former contains code derived from the library, whereas the latter must 114 | be combined with the library in order to run. 115 | 116 | ### TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | **0.** This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called “this License”). 122 | Each licensee is addressed as “you”. 123 | 124 | A “library” means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The “Library”, below, refers to any such software library or work 129 | which has been distributed under these terms. A “work based on the 130 | Library” means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term “modification”.) 135 | 136 | “Source code” for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | **1.** You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | **2.** You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | * **a)** The modified work must itself be a software library. 168 | * **b)** You must cause the files modified to carry prominent notices 169 | stating that you changed the files and the date of any change. 170 | * **c)** You must cause the whole of the work to be licensed at no 171 | charge to all third parties under the terms of this License. 172 | * **d)** If a facility in the modified Library refers to a function or a 173 | table of data to be supplied by an application program that uses 174 | the facility, other than as an argument passed when the facility 175 | is invoked, then you must make a good faith effort to ensure that, 176 | in the event an application does not supply such function or 177 | table, the facility still operates, and performs whatever part of 178 | its purpose remains meaningful. 179 | (For example, a function in a library to compute square roots has 180 | a purpose that is entirely well-defined independent of the 181 | application. Therefore, Subsection 2d requires that any 182 | application-supplied function or table used by this function must 183 | be optional: if the application does not supply it, the square 184 | root function must still compute square roots.) 185 | 186 | These requirements apply to the modified work as a whole. If 187 | identifiable sections of that work are not derived from the Library, 188 | and can be reasonably considered independent and separate works in 189 | themselves, then this License, and its terms, do not apply to those 190 | sections when you distribute them as separate works. But when you 191 | distribute the same sections as part of a whole which is a work based 192 | on the Library, the distribution of the whole must be on the terms of 193 | this License, whose permissions for other licensees extend to the 194 | entire whole, and thus to each and every part regardless of who wrote 195 | it. 196 | 197 | Thus, it is not the intent of this section to claim rights or contest 198 | your rights to work written entirely by you; rather, the intent is to 199 | exercise the right to control the distribution of derivative or 200 | collective works based on the Library. 201 | 202 | In addition, mere aggregation of another work not based on the Library 203 | with the Library (or with a work based on the Library) on a volume of 204 | a storage or distribution medium does not bring the other work under 205 | the scope of this License. 206 | 207 | **3.** You may opt to apply the terms of the ordinary GNU General Public 208 | License instead of this License to a given copy of the Library. To do 209 | this, you must alter all the notices that refer to this License, so 210 | that they refer to the ordinary GNU General Public License, version 2, 211 | instead of to this License. (If a newer version than version 2 of the 212 | ordinary GNU General Public License has appeared, then you can specify 213 | that version instead if you wish.) Do not make any other change in 214 | these notices. 215 | 216 | Once this change is made in a given copy, it is irreversible for 217 | that copy, so the ordinary GNU General Public License applies to all 218 | subsequent copies and derivative works made from that copy. 219 | 220 | This option is useful when you wish to copy part of the code of 221 | the Library into a program that is not a library. 222 | 223 | **4.** You may copy and distribute the Library (or a portion or 224 | derivative of it, under Section 2) in object code or executable form 225 | under the terms of Sections 1 and 2 above provided that you accompany 226 | it with the complete corresponding machine-readable source code, which 227 | must be distributed under the terms of Sections 1 and 2 above on a 228 | medium customarily used for software interchange. 229 | 230 | If distribution of object code is made by offering access to copy 231 | from a designated place, then offering equivalent access to copy the 232 | source code from the same place satisfies the requirement to 233 | distribute the source code, even though third parties are not 234 | compelled to copy the source along with the object code. 235 | 236 | **5.** A program that contains no derivative of any portion of the 237 | Library, but is designed to work with the Library by being compiled or 238 | linked with it, is called a “work that uses the Library”. Such a 239 | work, in isolation, is not a derivative work of the Library, and 240 | therefore falls outside the scope of this License. 241 | 242 | However, linking a “work that uses the Library” with the Library 243 | creates an executable that is a derivative of the Library (because it 244 | contains portions of the Library), rather than a “work that uses the 245 | library”. The executable is therefore covered by this License. 246 | Section 6 states terms for distribution of such executables. 247 | 248 | When a “work that uses the Library” uses material from a header file 249 | that is part of the Library, the object code for the work may be a 250 | derivative work of the Library even though the source code is not. 251 | Whether this is true is especially significant if the work can be 252 | linked without the Library, or if the work is itself a library. The 253 | threshold for this to be true is not precisely defined by law. 254 | 255 | If such an object file uses only numerical parameters, data 256 | structure layouts and accessors, and small macros and small inline 257 | functions (ten lines or less in length), then the use of the object 258 | file is unrestricted, regardless of whether it is legally a derivative 259 | work. (Executables containing this object code plus portions of the 260 | Library will still fall under Section 6.) 261 | 262 | Otherwise, if the work is a derivative of the Library, you may 263 | distribute the object code for the work under the terms of Section 6. 264 | Any executables containing that work also fall under Section 6, 265 | whether or not they are linked directly with the Library itself. 266 | 267 | **6.** As an exception to the Sections above, you may also combine or 268 | link a “work that uses the Library” with the Library to produce a 269 | work containing portions of the Library, and distribute that work 270 | under terms of your choice, provided that the terms permit 271 | modification of the work for the customer's own use and reverse 272 | engineering for debugging such modifications. 273 | 274 | You must give prominent notice with each copy of the work that the 275 | Library is used in it and that the Library and its use are covered by 276 | this License. You must supply a copy of this License. If the work 277 | during execution displays copyright notices, you must include the 278 | copyright notice for the Library among them, as well as a reference 279 | directing the user to the copy of this License. Also, you must do one 280 | of these things: 281 | 282 | * **a)** Accompany the work with the complete corresponding 283 | machine-readable source code for the Library including whatever 284 | changes were used in the work (which must be distributed under 285 | Sections 1 and 2 above); and, if the work is an executable linked 286 | with the Library, with the complete machine-readable “work that 287 | uses the Library”, as object code and/or source code, so that the 288 | user can modify the Library and then relink to produce a modified 289 | executable containing the modified Library. (It is understood 290 | that the user who changes the contents of definitions files in the 291 | Library will not necessarily be able to recompile the application 292 | to use the modified definitions.) 293 | * **b)** Use a suitable shared library mechanism for linking with the 294 | Library. A suitable mechanism is one that (1) uses at run time a 295 | copy of the library already present on the user's computer system, 296 | rather than copying library functions into the executable, and (2) 297 | will operate properly with a modified version of the library, if 298 | the user installs one, as long as the modified version is 299 | interface-compatible with the version that the work was made with. 300 | * **c)** Accompany the work with a written offer, valid for at 301 | least three years, to give the same user the materials 302 | specified in Subsection 6a, above, for a charge no more 303 | than the cost of performing this distribution. 304 | * **d)** If distribution of the work is made by offering access to copy 305 | from a designated place, offer equivalent access to copy the above 306 | specified materials from the same place. 307 | * **e)** Verify that the user has already received a copy of these 308 | materials or that you have already sent this user a copy. 309 | 310 | For an executable, the required form of the “work that uses the 311 | Library” must include any data and utility programs needed for 312 | reproducing the executable from it. However, as a special exception, 313 | the materials to be distributed need not include anything that is 314 | normally distributed (in either source or binary form) with the major 315 | components (compiler, kernel, and so on) of the operating system on 316 | which the executable runs, unless that component itself accompanies 317 | the executable. 318 | 319 | It may happen that this requirement contradicts the license 320 | restrictions of other proprietary libraries that do not normally 321 | accompany the operating system. Such a contradiction means you cannot 322 | use both them and the Library together in an executable that you 323 | distribute. 324 | 325 | **7.** You may place library facilities that are a work based on the 326 | Library side-by-side in a single library together with other library 327 | facilities not covered by this License, and distribute such a combined 328 | library, provided that the separate distribution of the work based on 329 | the Library and of the other library facilities is otherwise 330 | permitted, and provided that you do these two things: 331 | 332 | * **a)** Accompany the combined library with a copy of the same work 333 | based on the Library, uncombined with any other library 334 | facilities. This must be distributed under the terms of the 335 | Sections above. 336 | * **b)** Give prominent notice with the combined library of the fact 337 | that part of it is a work based on the Library, and explaining 338 | where to find the accompanying uncombined form of the same work. 339 | 340 | **8.** You may not copy, modify, sublicense, link with, or distribute 341 | the Library except as expressly provided under this License. Any 342 | attempt otherwise to copy, modify, sublicense, link with, or 343 | distribute the Library is void, and will automatically terminate your 344 | rights under this License. However, parties who have received copies, 345 | or rights, from you under this License will not have their licenses 346 | terminated so long as such parties remain in full compliance. 347 | 348 | **9.** You are not required to accept this License, since you have not 349 | signed it. However, nothing else grants you permission to modify or 350 | distribute the Library or its derivative works. These actions are 351 | prohibited by law if you do not accept this License. Therefore, by 352 | modifying or distributing the Library (or any work based on the 353 | Library), you indicate your acceptance of this License to do so, and 354 | all its terms and conditions for copying, distributing or modifying 355 | the Library or works based on it. 356 | 357 | **10.** Each time you redistribute the Library (or any work based on the 358 | Library), the recipient automatically receives a license from the 359 | original licensor to copy, distribute, link with or modify the Library 360 | subject to these terms and conditions. You may not impose any further 361 | restrictions on the recipients' exercise of the rights granted herein. 362 | You are not responsible for enforcing compliance by third parties with 363 | this License. 364 | 365 | **11.** If, as a consequence of a court judgment or allegation of patent 366 | infringement or for any other reason (not limited to patent issues), 367 | conditions are imposed on you (whether by court order, agreement or 368 | otherwise) that contradict the conditions of this License, they do not 369 | excuse you from the conditions of this License. If you cannot 370 | distribute so as to satisfy simultaneously your obligations under this 371 | License and any other pertinent obligations, then as a consequence you 372 | may not distribute the Library at all. For example, if a patent 373 | license would not permit royalty-free redistribution of the Library by 374 | all those who receive copies directly or indirectly through you, then 375 | the only way you could satisfy both it and this License would be to 376 | refrain entirely from distribution of the Library. 377 | 378 | If any portion of this section is held invalid or unenforceable under any 379 | particular circumstance, the balance of the section is intended to apply, 380 | and the section as a whole is intended to apply in other circumstances. 381 | 382 | It is not the purpose of this section to induce you to infringe any 383 | patents or other property right claims or to contest validity of any 384 | such claims; this section has the sole purpose of protecting the 385 | integrity of the free software distribution system which is 386 | implemented by public license practices. Many people have made 387 | generous contributions to the wide range of software distributed 388 | through that system in reliance on consistent application of that 389 | system; it is up to the author/donor to decide if he or she is willing 390 | to distribute software through any other system and a licensee cannot 391 | impose that choice. 392 | 393 | This section is intended to make thoroughly clear what is believed to 394 | be a consequence of the rest of this License. 395 | 396 | **12.** If the distribution and/or use of the Library is restricted in 397 | certain countries either by patents or by copyrighted interfaces, the 398 | original copyright holder who places the Library under this License may add 399 | an explicit geographical distribution limitation excluding those countries, 400 | so that distribution is permitted only in or among countries not thus 401 | excluded. In such case, this License incorporates the limitation as if 402 | written in the body of this License. 403 | 404 | **13.** The Free Software Foundation may publish revised and/or new 405 | versions of the Lesser General Public License from time to time. 406 | Such new versions will be similar in spirit to the present version, 407 | but may differ in detail to address new problems or concerns. 408 | 409 | Each version is given a distinguishing version number. If the Library 410 | specifies a version number of this License which applies to it and 411 | “any later version”, you have the option of following the terms and 412 | conditions either of that version or of any later version published by 413 | the Free Software Foundation. If the Library does not specify a 414 | license version number, you may choose any version ever published by 415 | the Free Software Foundation. 416 | 417 | **14.** If you wish to incorporate parts of the Library into other free 418 | programs whose distribution conditions are incompatible with these, 419 | write to the author to ask for permission. For software which is 420 | copyrighted by the Free Software Foundation, write to the Free 421 | Software Foundation; we sometimes make exceptions for this. Our 422 | decision will be guided by the two goals of preserving the free status 423 | of all derivatives of our free software and of promoting the sharing 424 | and reuse of software generally. 425 | 426 | ### NO WARRANTY 427 | 428 | **15.** BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 429 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 430 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 431 | OTHER PARTIES PROVIDE THE LIBRARY “AS IS” WITHOUT WARRANTY OF ANY 432 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 433 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 434 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 435 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 436 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 437 | 438 | **16.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 439 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 440 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 441 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 442 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 443 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 444 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 445 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 446 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 447 | DAMAGES. 448 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SMBClient 2 | `SMBClient` is a small dynamic library that allows iOS apps to access SMB/CIFS file servers. `SMBClient` is written in Objective C. The library supports the discovery of SMB devices and shares, listing and managing directories, reading meta data as well as reading and writing files. All functions are implemented in an asynchronous manner, to allow for a fluid user interface. 3 | 4 | ## Features 5 | * Discover SMB devices on your network 6 | * List file shares 7 | * List/create/delete directories 8 | * Read file meta data 9 | * Read/write/delete files 10 | * Seek/read partial 11 | 12 | ## Examples 13 | 14 | ### Discovery 15 | 16 | Start the discovery of SMB devices on your network: 17 | 18 | ```objectivec 19 | [[SMBDiscovery sharedInstance] startDiscoveryOfType:SMBDeviceTypeAny added:^(SMBDevice *device) { 20 | NSLog(@"Device added: %@", device); 21 | } removed:^(SMBDevice *device) { 22 | NSLog(@"Device removed: %@", device); 23 | }]; 24 | ``` 25 | 26 | You can also limit the search to file servers: 27 | 28 | ```objectivec 29 | [[SMBDiscovery sharedInstance] startDiscoveryOfType:SMBDeviceTypeFileServer added:^(SMBDevice *device) { 30 | SMBFileServer *fileServer = (SMBFileServer *)device; 31 | 32 | NSLog(@"File server added: %@", fileServer); 33 | } removed:nil]; 34 | ``` 35 | 36 | When your app goes into the background, or you don't need discovery anymore, make sure to stop it: 37 | 38 | ```objectivec 39 | [[SMBDiscovery sharedInstance] stopDiscovery]; 40 | ``` 41 | 42 | If however you don't need/want discovery at all, you can also instantiate a file server directly: 43 | 44 | ```objectivec 45 | NSString *host = @"localhost"; 46 | 47 | SMBFileServer *fileServer = [[SMBFileServer alloc] initWithHost:host netbiosName:host group:nil]; 48 | ``` 49 | 50 | ### Login 51 | 52 | Be it through discovery or direct instantiation, once you have a file server instance, you might want to login: 53 | 54 | ```objectivec 55 | [fileServer connectAsUser:@"john" password:@"secret" completion:^(BOOL guest, NSError *error) { 56 | if (error) { 57 | NSLog(@"Unable to connect: %@", error); 58 | } else if (guest) { 59 | NSLog(@"Logged in as guest"); 60 | } else { 61 | NSLog(@"Logged in"); 62 | } 63 | }]; 64 | ``` 65 | 66 | Don't forget to `disconnect:` from the server when you are finished. 67 | 68 | ### Shares 69 | 70 | List the shares on a file server: 71 | 72 | ```objectivec 73 | [fileServer listShares:^(NSArray *shares, NSError *error) { 74 | if (error) { 75 | NSLog(@"Unable to list the shares: %@", error); 76 | } else { 77 | for (SMBShare *share in shares) { 78 | NSLog(@"Got share: %@", share.name); 79 | } 80 | } 81 | }]; 82 | ``` 83 | 84 | Or, if you already know the name of a share you want to use: 85 | 86 | ```objectivec 87 | [fileServer findShare:@"Guest Share" completion:^(SMBShare *share, NSError *error) { 88 | if (error) { 89 | NSLog(@"Unable to find the share: %@", error); 90 | } else { 91 | NSLog(@"Got share: %@", share.name); 92 | } 93 | }]; 94 | ``` 95 | 96 | You need to open a share to be able to work on it: 97 | 98 | ```objectivec 99 | [share open:^(NSError *error) { 100 | if (error) { 101 | NSLog(@"Unable to open share: %@", error); 102 | } else { 103 | NSLog(@"Opened share '%@'", share.name); 104 | } 105 | }]; 106 | ``` 107 | 108 | Don't forget to `close:` the share, once you're done. 109 | 110 | ### Listing files 111 | 112 | You have two options to list the files on an open share. Either use `listFiles:` on the share instance: 113 | 114 | ```objectivec 115 | [share listFiles:^(NSArray *files, NSError *error) { 116 | if (error) { 117 | NSLog(@"Unable to list files: %@", error); 118 | } else { 119 | NSLog(@"Found %lu files", (unsigned long)files.count); 120 | } 121 | }]; 122 | ``` 123 | 124 | Or, you can get the root directory of the share and `listFiles:` there: 125 | 126 | ```objectivec 127 | SMBFile *root = [SMBFile rootOfShare:share]; 128 | 129 | [root listFiles:^(NSArray *files, NSError *error) { 130 | if (error) { 131 | NSLog(@"Unable to list files: %@", error); 132 | } else { 133 | NSLog(@"Found %lu files", (unsigned long)files.count); 134 | } 135 | }]; 136 | ``` 137 | 138 | Both methods are equivalent and the choice is just a matter of your personal taste. 139 | 140 | You can also filter files when you list them, e.g. to only list directories: 141 | 142 | ```objectivec 143 | [root listFilesUsingFilter:^BOOL(SMBFile *file) { 144 | return file.isDirectory; 145 | } completion:^(NSArray *files, NSError *error) { 146 | if (error) { 147 | NSLog(@"Unable to list files: %@", error); 148 | } else { 149 | NSLog(@"Found %lu files", (unsigned long)files.count); 150 | } 151 | }]; 152 | ``` 153 | 154 | This brings us to the meta data of files. 155 | 156 | ### Meta data 157 | 158 | All properties (including `isDirectory` and `exists`) of the `SMBFile` class apart from `path` (and `name`, which is part of `path`) are considered meta data. Meta data of a file or directory are implicitly read, when a file was listed (when it was in the result of `listFiles` or `findFile`), opened (`open`) or closed (`close`), or if it has beed created (using `createDirectory` or `createDirectories`). Meta data are not live data and they are not updated automatically. You can check if the meta data was already read for an instance of `SMBFile` with the `hasStatus` property. The property `statusTime` returns the date the meta data was last read (or nil if it was never read). 159 | 160 | To explicitly read or update a file's meta data use `updateStatus:`: 161 | 162 | ```objectivec 163 | SMBFile *file = [SMBFile fileWithPath:@"/a/test.txt" share:share]; 164 | 165 | [file updateStatus:^(NSError *error) { 166 | if (error) { 167 | NSLog(@"Unable to read the meta data: %@", error); 168 | } else { 169 | if (file.exists) { 170 | NSLog(@"File %@", file); 171 | } else { 172 | NSLog(@"File does not exist"); 173 | } 174 | } 175 | }]; 176 | ``` 177 | 178 | ### Deleting files and directories 179 | 180 | You can delete files and directories if you have the permission. Directories need to be empty before they can be deleted. 181 | 182 | ```objectivec 183 | [file delete:^(NSError *error) { 184 | if (error) { 185 | NSLog(@"Unable to delete file: %@", error); 186 | } else { 187 | NSLog(@"File deleted"); 188 | } 189 | }]; 190 | ``` 191 | 192 | ### Creating directories 193 | 194 | This is how you create the directory c as a subdirectory of b: 195 | 196 | ```objectivec 197 | SMBFile *file = [SMBFile fileWithPath:@"/a/b/c" share:share]; 198 | 199 | [file createDirectory:^(NSError *error) { 200 | if (error) { 201 | NSLog(@"Unable to create the directory: %@", error); 202 | } else { 203 | NSLog(@"Directory created"); 204 | } 205 | }]; 206 | ``` 207 | 208 | The code above will create directory c only, if directory b (and a) already exists. If you want intermediate directories to be created automatically use `createDirectories:`: 209 | 210 | ```objectivec 211 | SMBFile *file = [SMBFile fileWithPath:@"/a/b/c" share:share]; 212 | 213 | [file createDirectories:^(NSError *error) { 214 | if (error) { 215 | NSLog(@"Unable to create the directory: %@", error); 216 | } else { 217 | NSLog(@"Directory created"); 218 | } 219 | }]; 220 | ``` 221 | 222 | ### Opening files 223 | 224 | You need to open a file before you can read from or write to it: 225 | 226 | ```objectivec 227 | [file open:SMBFileModeRead completion:^(NSError *error) { 228 | if (error) { 229 | NSLog(@"Unable to open the file: %@", error); 230 | } else { 231 | NSLog(@"File opened: %@", file.name); 232 | } 233 | }]; 234 | ``` 235 | 236 | Use `SMBFileModeRead` if you only want to read from a file. Use `SMBFileModeReadWrite` if you want to write to a file (even if you think that you might not require to read it). If you open a file in order to write to it, it will be created if it doesn't exist. 237 | 238 | Don't forget to `close:` the file once you're done with it. 239 | 240 | ### Reading files 241 | 242 | Here is how you read (download) a file. Obviously, in a real-life situation you probably wouldn't collect all data in memory. Note, how you are informed about the progress, which makes it easy to e.g. update a progress bar in the user interface. The progress handler may return NO to indicate that the read process should be stopped. Since the progress handler is called asynchronously, this might however not happen instantaneously. 243 | 244 | ```objectivec 245 | NSUInteger bufferSize = 12000; 246 | NSMutableData *result = [NSMutableData new]; 247 | 248 | [file read:bufferSize 249 | progress:^BOOL(unsigned long long bytesReadTotal, NSData *data, BOOL complete, NSError *error) { 250 | 251 | if (error) { 252 | NSLog(@"Unable to read from the file: %@", error); 253 | } else { 254 | NSLog(@"Read %ld bytes, in total %llu bytes (%0.2f %%)", 255 | data.length, bytesReadTotal, (double)bytesReadTotal / file.size * 100); 256 | 257 | if (data) { 258 | [result appendData:data]; 259 | } 260 | } 261 | 262 | if (complete) { 263 | [file close:^(NSError *error) { 264 | NSLog(@"Finished reading file"); 265 | }]; 266 | } 267 | 268 | return YES; 269 | }]; 270 | ``` 271 | 272 | Note that there is also a variant of the `read` method where you can specify the maximum number of bytes to read, which is useful if you only want to read a portion of the file. This method will probably be used in combination with the `seek` method of `SMBFile`. 273 | 274 | ### Writing files 275 | 276 | Writing (uploading) a file is equally simple: 277 | 278 | ```objectivec 279 | NSUInteger bufferSize = 12000; 280 | NSData *data = [@"Hello world!\n" dataUsingEncoding:NSUTF8StringEncoding]; 281 | 282 | [file write:^NSData *(unsigned long long offset) { 283 | if (offset < data.length) { 284 | return [data subdataWithRange:NSMakeRange(offset, MIN(bufferSize, data.length - offset))]; 285 | } else { 286 | return nil; 287 | } 288 | } progress:^(unsigned long long bytesWrittenTotal, long bytesWrittenLast, BOOL complete, NSError *error) { 289 | if (error) { 290 | NSLog(@"Unable to write to the file: %@", error); 291 | } else { 292 | NSLog(@"Wrote %ld bytes, in total %llu bytes (%0.2f %%)", 293 | bytesWrittenLast, bytesWrittenTotal, (double)bytesWrittenTotal / data.length * 100); 294 | } 295 | 296 | if (complete) { 297 | [file close:^(NSError *error) { 298 | NSLog(@"Finished writing file"); 299 | }]; 300 | } 301 | }]; 302 | ``` 303 | 304 | If you want to append data to an existing file, or if you want to write at a particular position, you can use the `seek` method of `SMBFile` to position the file pointer. 305 | 306 | ## Dependencies 307 | 308 | `SMBClient` relies on [libdsm](http://videolabs.github.io/libdsm), a low level SMB client library written in C, and [libtasn1](https://www.gnu.org/software/libtasn1/), an implementation of the Abstract Syntax Notification ASN.1. Binaries and headers of both libraries are embedded in this library to eliminate external dependencies. The version of `SMBClient` is (currently) tied to the version of `libdsm` included in this library. 309 | 310 | ## License 311 | 312 | `SMBClient` as well as `libdsm` and `libtasn1` are licensed under the [GNU Lesser General Public License version 2.1](https://www.gnu.org/licenses/lgpl-2.1.html) or later. See the [LICENSE file](LICENSE.md). A commercial license option is available for `libdsm`. [Contact](mailto:info@naxos-software.de) us if you require a license of `SMBClient` to be used with the commercial license of `libdsm`. 313 | 314 | -------------------------------------------------------------------------------- /SMBClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SMBClient.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SMBClient.xcodeproj/project.xcworkspace/xcuserdata/masc.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naxos/SMBClient/82dfd479c0f85aed4534a81c68cd4cb528dbfbe4/SMBClient.xcodeproj/project.xcworkspace/xcuserdata/masc.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /SMBClient.xcodeproj/xcuserdata/masc.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 35 | 36 | 50 | 51 | 65 | 66 | 67 | 68 | 69 | 71 | 83 | 84 | 85 | 87 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /SMBClient.xcodeproj/xcuserdata/masc.xcuserdatad/xcschemes/SMBClient.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 65 | 71 | 72 | 73 | 74 | 75 | 76 | 82 | 83 | 89 | 90 | 91 | 92 | 94 | 95 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /SMBClient.xcodeproj/xcuserdata/masc.xcuserdatad/xcschemes/Universal Framework.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /SMBClient.xcodeproj/xcuserdata/masc.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SMBClient.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | Universal Framework.xcscheme 13 | 14 | orderHint 15 | 1 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | 452A27D21CF89E65004456E5 21 | 22 | primary 23 | 24 | 25 | 452A27DC1CF89E65004456E5 26 | 27 | primary 28 | 29 | 30 | 452A28F51D02FB01004456E5 31 | 32 | primary 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /SMBClient/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 0.2.8 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /SMBClient/Protected/SMBError.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import 26 | #import "smb_session.h" 27 | 28 | @interface SMBError : NSObject 29 | 30 | + (NSError *)unknownError; 31 | + (NSError *)hostNotFoundError; 32 | + (NSError *)noIPAddressError; 33 | + (NSError *)notConnectedError; 34 | + (NSError *)notOpenError; 35 | + (NSError *)notSuchFileOrDirectory; 36 | + (NSError *)writeError; 37 | + (NSError *)readError; 38 | + (NSError *)seekError; 39 | + (NSError *)dsmError:(int)dsmError session:(smb_session *)session; 40 | 41 | #pragma mark - Unavailable methods 42 | 43 | + new NS_UNAVAILABLE; 44 | - init NS_UNAVAILABLE; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /SMBClient/Protected/SMBError.m: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import "SMBError.h" 26 | 27 | @implementation SMBError 28 | 29 | + (NSError *)unknownError { 30 | return [NSError errorWithDomain:@"smb.error" code:50 userInfo:@{ NSLocalizedDescriptionKey : @"Unknown error"} ]; 31 | } 32 | 33 | + (NSError *)hostNotFoundError { 34 | return [NSError errorWithDomain:@"smb.error" code:51 userInfo:@{ NSLocalizedDescriptionKey : @"Host not found"} ]; 35 | } 36 | 37 | + (NSError *)noIPAddressError { 38 | return [NSError errorWithDomain:@"smb.error" code:52 userInfo:@{ NSLocalizedDescriptionKey : @"Unable to resolve IP address"} ]; 39 | } 40 | 41 | + (NSError *)notConnectedError { 42 | return [NSError errorWithDomain:@"smb.error" code:53 userInfo:@{ NSLocalizedDescriptionKey : @"Not connected"} ]; 43 | } 44 | 45 | + (NSError *)notOpenError { 46 | return [NSError errorWithDomain:@"smb.error" code:54 userInfo:@{ NSLocalizedDescriptionKey : @"Not open"} ]; 47 | } 48 | 49 | + (NSError *)writeError { 50 | return [NSError errorWithDomain:@"smb.error" code:55 userInfo:@{ NSLocalizedDescriptionKey : @"Unable to write to file"} ]; 51 | } 52 | 53 | + (NSError *)readError { 54 | return [NSError errorWithDomain:@"smb.error" code:56 userInfo:@{ NSLocalizedDescriptionKey : @"Unable to read from file"} ]; 55 | } 56 | 57 | + (NSError *)seekError { 58 | return [NSError errorWithDomain:@"smb.error" code:57 userInfo:@{ NSLocalizedDescriptionKey : @"Unable to seek position in file"} ]; 59 | } 60 | 61 | + (NSError *)notSuchFileOrDirectory { 62 | return [NSError errorWithDomain:@"smb.error" code:58 userInfo:@{ NSLocalizedDescriptionKey : @"No such file or directory"} ]; 63 | } 64 | 65 | + (NSError *)dsmError:(int)dsmError session:(smb_session *)session { 66 | NSString *domain = @"dsm.error"; 67 | NSError *error = nil; 68 | 69 | switch (dsmError) { 70 | case DSM_SUCCESS: 71 | break; 72 | case DSM_ERROR_GENERIC: 73 | error = [NSError errorWithDomain:domain code:1 userInfo:@{ NSLocalizedDescriptionKey : @"Generic error"} ]; 74 | break; 75 | case DSM_ERROR_NETWORK: 76 | error = [NSError errorWithDomain:domain code:2 userInfo:@{ NSLocalizedDescriptionKey : @"Network error"} ]; 77 | break; 78 | case DSM_ERROR_NT: 79 | error = [self _ntError:smb_session_get_nt_status(session)]; 80 | error = [NSError errorWithDomain:domain code:3 userInfo:@{ NSLocalizedDescriptionKey : @"SMB error", NSUnderlyingErrorKey : error } ]; 81 | break; 82 | case DSM_ERROR_CHARSET: 83 | error = [NSError errorWithDomain:domain code:4 userInfo:@{ NSLocalizedDescriptionKey : @"Encoding error"} ]; 84 | break; 85 | default: 86 | error = [self unknownError]; 87 | break; 88 | } 89 | 90 | return error; 91 | } 92 | 93 | + (NSError *)_ntError:(uint32_t)nt_status { 94 | NSString *domain = @"nt.error"; 95 | NSError *error = nil; 96 | 97 | switch (nt_status) { 98 | case NT_STATUS_SUCCESS: 99 | error = [NSError errorWithDomain:domain code:10 userInfo:@{ NSLocalizedDescriptionKey : @"Success"} ]; 100 | break; 101 | case NT_STATUS_INVALID_SMB: 102 | error = [NSError errorWithDomain:domain code:11 userInfo:@{ NSLocalizedDescriptionKey : @"Invalid SMB"} ]; 103 | break; 104 | case NT_STATUS_SMB_BAD_TID: 105 | error = [NSError errorWithDomain:domain code:12 userInfo:@{ NSLocalizedDescriptionKey : @"Bad TID"} ]; 106 | break; 107 | case NT_STATUS_SMB_BAD_UID: 108 | error = [NSError errorWithDomain:domain code:13 userInfo:@{ NSLocalizedDescriptionKey : @"Bad UID"} ]; 109 | break; 110 | case NT_STATUS_NOT_IMPLEMENTED: 111 | error = [NSError errorWithDomain:domain code:14 userInfo:@{ NSLocalizedDescriptionKey : @"Not implemented"} ]; 112 | break; 113 | case NT_STATUS_INVALID_DEVICE_REQUEST: 114 | error = [NSError errorWithDomain:domain code:15 userInfo:@{ NSLocalizedDescriptionKey : @"Invalid device request"} ]; 115 | break; 116 | case NT_STATUS_NO_SUCH_DEVICE: 117 | error = [NSError errorWithDomain:domain code:16 userInfo:@{ NSLocalizedDescriptionKey : @"No such device"} ]; 118 | break; 119 | case NT_STATUS_NO_SUCH_FILE: 120 | error = [NSError errorWithDomain:domain code:17 userInfo:@{ NSLocalizedDescriptionKey : @"No such file"} ]; 121 | break; 122 | case NT_STATUS_MORE_PROCESSING_REQUIRED: 123 | error = [NSError errorWithDomain:domain code:18 userInfo:@{ NSLocalizedDescriptionKey : @"More processing required"} ]; 124 | break; 125 | case NT_STATUS_INVALID_LOCK_SEQUENCE: 126 | error = [NSError errorWithDomain:domain code:19 userInfo:@{ NSLocalizedDescriptionKey : @"Invalid lock sequence"} ]; 127 | break; 128 | case NT_STATUS_INVALID_VIEW_SIZE: 129 | error = [NSError errorWithDomain:domain code:20 userInfo:@{ NSLocalizedDescriptionKey : @"Invalid view size"} ]; 130 | break; 131 | case NT_STATUS_ALREADY_COMMITTED: 132 | error = [NSError errorWithDomain:domain code:21 userInfo:@{ NSLocalizedDescriptionKey : @"Already committed"} ]; 133 | break; 134 | case NT_STATUS_ACCESS_DENIED: 135 | error = [NSError errorWithDomain:domain code:22 userInfo:@{ NSLocalizedDescriptionKey : @"Access denied"} ]; 136 | break; 137 | case NT_STATUS_OBJECT_NAME_NOT_FOUND: 138 | error = [NSError errorWithDomain:domain code:23 userInfo:@{ NSLocalizedDescriptionKey : @"Object name not found"} ]; 139 | break; 140 | case NT_STATUS_OBJECT_NAME_COLLISION: 141 | error = [NSError errorWithDomain:domain code:24 userInfo:@{ NSLocalizedDescriptionKey : @"Object name collision"} ]; 142 | break; 143 | case NT_STATUS_OBJECT_PATH_INVALID: 144 | error = [NSError errorWithDomain:domain code:25 userInfo:@{ NSLocalizedDescriptionKey : @"Object path invalid"} ]; 145 | break; 146 | case NT_STATUS_OBJECT_PATH_NOT_FOUND: 147 | error = [NSError errorWithDomain:domain code:26 userInfo:@{ NSLocalizedDescriptionKey : @"Object path not found"} ]; 148 | break; 149 | case NT_STATUS_OBJECT_PATH_SYNTAX_BAD: 150 | error = [NSError errorWithDomain:domain code:27 userInfo:@{ NSLocalizedDescriptionKey : @"Object path syntax bad"} ]; 151 | break; 152 | case NT_STATUS_PORT_CONNECTION_REFUSED: 153 | error = [NSError errorWithDomain:domain code:28 userInfo:@{ NSLocalizedDescriptionKey : @"Port connection refused"} ]; 154 | break; 155 | case NT_STATUS_THREAD_IS_TERMINATING: 156 | error = [NSError errorWithDomain:domain code:29 userInfo:@{ NSLocalizedDescriptionKey : @"Thread is terminating"} ]; 157 | break; 158 | case NT_STATUS_DELETE_PENDING: 159 | error = [NSError errorWithDomain:domain code:30 userInfo:@{ NSLocalizedDescriptionKey : @"Delete pending"} ]; 160 | break; 161 | case NT_STATUS_PRIVILEGE_NOT_HELD: 162 | error = [NSError errorWithDomain:domain code:31 userInfo:@{ NSLocalizedDescriptionKey : @"Privilege not held"} ]; 163 | break; 164 | case NT_STATUS_LOGON_FAILURE: 165 | error = [NSError errorWithDomain:domain code:32 userInfo:@{ NSLocalizedDescriptionKey : @"Logon failure"} ]; 166 | break; 167 | case NT_STATUS_DFS_EXIT_PATH_FOUND: 168 | error = [NSError errorWithDomain:domain code:33 userInfo:@{ NSLocalizedDescriptionKey : @"DFS exit path found"} ]; 169 | break; 170 | case NT_STATUS_MEDIA_WRITE_PROTECTED: 171 | error = [NSError errorWithDomain:domain code:34 userInfo:@{ NSLocalizedDescriptionKey : @"Media write protected"} ]; 172 | break; 173 | case NT_STATUS_ILLEGAL_FUNCTION: 174 | error = [NSError errorWithDomain:domain code:35 userInfo:@{ NSLocalizedDescriptionKey : @"Illegal function"} ]; 175 | break; 176 | case NT_STATUS_FILE_IS_A_DIRECTORY: 177 | error = [NSError errorWithDomain:domain code:36 userInfo:@{ NSLocalizedDescriptionKey : @"File is a directory"} ]; 178 | break; 179 | case NT_STATUS_FILE_RENAMED: 180 | error = [NSError errorWithDomain:domain code:37 userInfo:@{ NSLocalizedDescriptionKey : @"File renamed"} ]; 181 | break; 182 | case NT_STATUS_REDIRECTOR_NOT_STARTED: 183 | error = [NSError errorWithDomain:domain code:38 userInfo:@{ NSLocalizedDescriptionKey : @"Redirector not started"} ]; 184 | break; 185 | case NT_STATUS_DIRECTORY_NOT_EMPTY: 186 | error = [NSError errorWithDomain:domain code:39 userInfo:@{ NSLocalizedDescriptionKey : @"Directory not empty"} ]; 187 | break; 188 | case NT_STATUS_PROCESS_IS_TERMINATING: 189 | error = [NSError errorWithDomain:domain code:40 userInfo:@{ NSLocalizedDescriptionKey : @"Process is terminating"} ]; 190 | break; 191 | case NT_STATUS_TOO_MANY_OPENED_FILES: 192 | error = [NSError errorWithDomain:domain code:41 userInfo:@{ NSLocalizedDescriptionKey : @"Too many opened files"} ]; 193 | break; 194 | case NT_STATUS_CANNOT_DELETE: 195 | error = [NSError errorWithDomain:domain code:42 userInfo:@{ NSLocalizedDescriptionKey : @"Can not delete"} ]; 196 | break; 197 | case NT_STATUS_FILE_DELETED: 198 | error = [NSError errorWithDomain:domain code:43 userInfo:@{ NSLocalizedDescriptionKey : @"File deleted"} ]; 199 | break; 200 | case NT_STATUS_INSUFF_SERVER_RESOURCES: 201 | error = [NSError errorWithDomain:domain code:44 userInfo:@{ NSLocalizedDescriptionKey : @"Insufficient server resources"} ]; 202 | break; 203 | case 0xC000A000: 204 | error = [NSError errorWithDomain:domain code:45 userInfo:@{ NSLocalizedDescriptionKey : @"Cryptographic signature invalid"} ]; 205 | break; 206 | case 0xC00000CC: 207 | error = [NSError errorWithDomain:domain code:46 userInfo:@{ NSLocalizedDescriptionKey : @"Share name invalid"} ]; 208 | break; 209 | default: 210 | error = [NSError errorWithDomain:domain code:100 userInfo:@{ NSLocalizedDescriptionKey : [NSString stringWithFormat:@"%@: %x", @"Unknown NT status", nt_status] } ]; 211 | break; 212 | } 213 | 214 | return error; 215 | } 216 | 217 | @end 218 | -------------------------------------------------------------------------------- /SMBClient/Protected/SMBFileServer_Protected.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import "SMBFileServer.h" 26 | 27 | #import "smb_session.h" 28 | 29 | @interface SMBFileServer () 30 | 31 | @property (nonatomic, assign, readonly, nullable) smb_session *smbSession; 32 | 33 | - (void)openShare:(nonnull NSString *)name completion:(nullable void (^)(smb_tid tid, NSError * _Nullable error))completion; 34 | - (void)closeShare:(smb_tid)shareID completion:(nullable void (^)(NSError * _Nullable error))completion; 35 | 36 | @end -------------------------------------------------------------------------------- /SMBClient/Protected/SMBFile_Protected.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import "SMBFile.h" 26 | 27 | @class SMBStat; 28 | 29 | @interface SMBFile () 30 | 31 | @property (nonatomic, nullable) SMBStat *smbStat; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /SMBClient/Protected/SMBShare_Protected.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import "SMBShare.h" 26 | #import "SMBFile_Protected.h" 27 | #import "SMBFileServer_Protected.h" 28 | 29 | #import "smb_session.h" 30 | 31 | @interface SMBStat : NSObject 32 | 33 | @property (nonatomic, readonly) BOOL exists; 34 | @property (nonatomic, readonly, getter=isDirectory) BOOL directory; 35 | @property (nonatomic, readonly) unsigned long long size; 36 | @property (nonatomic, readonly, nullable) NSDate *creationTime; 37 | @property (nonatomic, readonly, nullable) NSDate *modificationTime; 38 | @property (nonatomic, readonly, nullable) NSDate *accessTime; 39 | @property (nonatomic, readonly, nullable) NSDate *writeTime; 40 | @property (nonatomic, readonly, nullable) NSDate *statTime; 41 | @property (nonatomic, readonly, nullable) NSString *smbName; 42 | 43 | + (nullable instancetype)statForNonExistingFile; 44 | + (nullable instancetype)statForRoot; 45 | + (nullable instancetype)statWithStat:(nonnull smb_stat)stat; 46 | 47 | - (nullable instancetype)initWithStat:(nonnull smb_stat)stat; 48 | - (nullable instancetype)initForRoot; 49 | - (nullable instancetype)initForNonExistingFile; 50 | 51 | #pragma mark - Unavailable methods 52 | 53 | + new NS_UNAVAILABLE; 54 | - init NS_UNAVAILABLE; 55 | 56 | @end 57 | 58 | @interface SMBShare () 59 | 60 | - (nullable instancetype)initWithName:(nonnull NSString *)name server:(nonnull SMBFileServer *)server; 61 | 62 | - (void)listFiles:(nonnull NSString *)path filter:(nullable BOOL (^)(SMBFile *_Nonnull file))filter completion:(nullable void (^)(NSArray *_Nullable files, NSError *_Nullable error))completion; 63 | - (void)getStatusOfFile:(nonnull NSString *)path completion:(nullable void (^)(SMBStat *_Nullable status, NSError *_Nullable error))completion; 64 | - (void)createDirectory:(nonnull NSString *)path completion:(nullable void (^)(SMBFile *_Nullable file, NSError *_Nullable error))completion; 65 | - (void)createDirectories:(nonnull NSString *)path completion:(nullable void (^)(SMBFile *_Nullable file, NSError *_Nullable error))completion; 66 | - (void)moveFile:(nonnull NSString *)oldPath to:(nonnull NSString *)newPath completion:(nullable void (^)(SMBFile *_Nullable file, NSError *_Nullable error))completion; 67 | - (void)deleteFile:(nonnull NSString *)path completion:(nullable void (^)(NSError *_Nullable error))completion; 68 | - (void)openFile:(nonnull NSString *)path mode:(SMBFileMode)mode completion:(nullable void (^)(SMBFile *_Nullable file, smb_fd fd, NSError *_Nullable error))completion; 69 | - (void)closeFile:(smb_fd)fd path:(nonnull NSString *)path completion:(nullable void (^)(SMBFile *_Nullable file, NSError *_Nullable error))completion; 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /SMBClient/SMBClient.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import 26 | 27 | //! Project version number for SMBClient. 28 | FOUNDATION_EXPORT double SMBClientVersionNumber; 29 | 30 | //! Project version string for SMBClient. 31 | FOUNDATION_EXPORT const unsigned char SMBClientVersionString[]; 32 | 33 | #import 34 | #import 35 | #import 36 | #import 37 | #import 38 | 39 | -------------------------------------------------------------------------------- /SMBClient/SMBDevice.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import 26 | 27 | @interface SMBDevice : NSObject 28 | 29 | typedef NS_OPTIONS(NSUInteger, SMBDeviceType) { 30 | SMBDeviceTypeUnknown = 1 << 0, 31 | SMBDeviceTypeWorkstation = 1 << 1, 32 | SMBDeviceTypeMessenger = 1 << 2, 33 | SMBDeviceTypeFileServer = 1 << 3, 34 | SMBDeviceTypeDomainMaster = 1 << 4, 35 | 36 | SMBDeviceTypeNone = 0, 37 | SMBDeviceTypeAny = SMBDeviceTypeUnknown | SMBDeviceTypeWorkstation | SMBDeviceTypeMessenger | SMBDeviceTypeFileServer | SMBDeviceTypeDomainMaster 38 | }; 39 | 40 | @property (nonatomic, readonly) SMBDeviceType type; 41 | @property (nonatomic, readonly) NSString *host; 42 | @property (nonatomic, readonly) NSString *netbiosName; 43 | @property (nonatomic, readonly) NSString *group; 44 | 45 | - (instancetype)initWithType:(SMBDeviceType)type host:(NSString *)ipAddressOrHostname netbiosName:(NSString *)name group:(NSString *)group; 46 | 47 | #pragma mark - Unavailable methods 48 | 49 | + new NS_UNAVAILABLE; 50 | - init NS_UNAVAILABLE; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /SMBClient/SMBDevice.m: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import "SMBDevice.h" 26 | 27 | @implementation SMBDevice 28 | 29 | - (instancetype)initWithType:(SMBDeviceType)type host:(NSString *)ipAddressOrHostname netbiosName:(NSString *)name group:(NSString *)group { 30 | self = [super init]; 31 | if (self) { 32 | _type = type; 33 | _host = ipAddressOrHostname; 34 | _netbiosName = name; 35 | _group = group; 36 | } 37 | return self; 38 | } 39 | 40 | - (NSString *)description { 41 | return [NSString stringWithFormat:@"%@ %@(%@)/%@", [self _typeName], _netbiosName, _host, _group]; 42 | } 43 | 44 | - (BOOL)isEqual:(id)other { 45 | if (other == self) 46 | return YES; 47 | if (other == nil || ![other isKindOfClass:self.class]) 48 | return NO; 49 | return [self.description isEqualToString:((SMBDevice *)other).description]; 50 | } 51 | 52 | #pragma mark - Private methods 53 | 54 | - (NSString *)_typeName { 55 | switch (_type) { 56 | case SMBDeviceTypeWorkstation: 57 | return @"workstation"; 58 | case SMBDeviceTypeMessenger: 59 | return @"messenger"; 60 | case SMBDeviceTypeDomainMaster: 61 | return @"domain master"; 62 | case SMBDeviceTypeFileServer: 63 | return @"file server"; 64 | case SMBDeviceTypeUnknown: 65 | default: 66 | return @"unknown device"; 67 | } 68 | } 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /SMBClient/SMBDiscovery.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import 26 | #import "SMBDevice.h" 27 | 28 | @interface SMBDiscovery : NSObject 29 | 30 | + (nullable instancetype)sharedInstance; 31 | 32 | - (BOOL)startDiscoveryOfType:(SMBDeviceType)typeMask added:(nullable void (^)(SMBDevice *_Nonnull device))added removed:(nullable void (^)(SMBDevice *_Nonnull device))removed; 33 | - (void)stopDiscovery; 34 | 35 | #pragma mark - Unavailable methods 36 | 37 | + new NS_UNAVAILABLE; 38 | - init NS_UNAVAILABLE; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /SMBClient/SMBDiscovery.m: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import "SMBDiscovery.h" 26 | #import "SMBFileServer.h" 27 | #import "netbios_ns.h" 28 | #import "netbios_defs.h" 29 | 30 | #import 31 | #import 32 | 33 | @implementation SMBDiscovery { 34 | netbios_ns *_nameService; 35 | } 36 | 37 | static void (^_addedHandler)(SMBDevice *_Nonnull); 38 | static void (^_removedHandler)(SMBDevice *_Nonnull); 39 | static SMBDeviceType _typeMask; 40 | 41 | + (instancetype)sharedInstance { 42 | static dispatch_once_t pred = 0; 43 | __strong static id _sharedObject = nil; 44 | dispatch_once(&pred, ^{ 45 | _sharedObject = [[self alloc] init]; 46 | }); 47 | return _sharedObject; 48 | } 49 | 50 | - (void)dealloc { 51 | [self stopDiscovery]; 52 | } 53 | 54 | - (BOOL)startDiscoveryOfType:(SMBDeviceType)typeMask added:(nullable void (^)(SMBDevice *_Nonnull))added removed:(nullable void (^)(SMBDevice *_Nonnull))removed { 55 | if (_nameService) { 56 | [self stopDiscovery]; 57 | } 58 | 59 | _nameService = netbios_ns_new(); 60 | _addedHandler = added; 61 | _removedHandler = removed; 62 | _typeMask = typeMask; 63 | 64 | netbios_ns_discover_callbacks callbacks; 65 | 66 | callbacks.p_opaque = (__bridge void *)self; 67 | callbacks.pf_on_entry_added = _on_entry_added; 68 | callbacks.pf_on_entry_removed = _on_entry_removed; 69 | 70 | return netbios_ns_discover_start(_nameService, 71 | 4, // broadcast every 4 sec 72 | &callbacks) == 0; 73 | } 74 | 75 | - (void)stopDiscovery { 76 | if (_nameService) { 77 | netbios_ns_discover_stop(_nameService); 78 | netbios_ns_destroy(_nameService); 79 | _nameService = NULL; 80 | _addedHandler = NULL; 81 | _removedHandler = NULL; 82 | } 83 | } 84 | 85 | static SMBDevice *_device(netbios_ns_entry *entry) { 86 | SMBDevice *device; 87 | struct in_addr addr; 88 | 89 | addr.s_addr = netbios_ns_entry_ip(entry); 90 | 91 | const char *i = inet_ntoa(addr); 92 | const char *g = netbios_ns_entry_group(entry); 93 | const char *n = netbios_ns_entry_name(entry); 94 | const char t = netbios_ns_entry_type(entry); 95 | 96 | SMBDeviceType type = SMBDeviceTypeUnknown; 97 | NSString *ip = i ? [NSString stringWithUTF8String:i] : nil; 98 | NSString *group = g ? [NSString stringWithUTF8String:g] : nil; 99 | NSString *name = n ? [NSString stringWithUTF8String:n] : nil; 100 | 101 | switch (t) { 102 | case NETBIOS_FILESERVER: 103 | device = [[SMBFileServer alloc] initWithHost:ip netbiosName:name group:group]; 104 | break; 105 | case NETBIOS_WORKSTATION: 106 | case NETBIOS_MESSENGER: 107 | case NETBIOS_DOMAINMASTER: 108 | default: 109 | device = [[SMBDevice alloc] initWithType:type host:ip netbiosName:name group:group]; 110 | break; 111 | } 112 | 113 | return device; 114 | } 115 | 116 | static void _on_entry_added(void *p_opaque, netbios_ns_entry *entry) { 117 | dispatch_async(dispatch_get_main_queue(), ^{ 118 | if (_addedHandler) { 119 | SMBDevice *device = _device(entry); 120 | 121 | if (_typeMask & device.type) { 122 | _addedHandler(_device(entry)); 123 | } 124 | } 125 | }); 126 | } 127 | 128 | static void _on_entry_removed(void *p_opaque, netbios_ns_entry *entry) { 129 | dispatch_async(dispatch_get_main_queue(), ^{ 130 | if (_removedHandler) { 131 | SMBDevice *device = _device(entry); 132 | 133 | if (_typeMask & device.type) { 134 | _removedHandler(_device(entry)); 135 | } 136 | } 137 | }); 138 | } 139 | 140 | @end 141 | -------------------------------------------------------------------------------- /SMBClient/SMBFile.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import 26 | 27 | @class SMBShare; 28 | 29 | @interface SMBFile : NSObject 30 | 31 | typedef NS_OPTIONS(NSUInteger, SMBFileMode) { 32 | SMBFileModeRead = 1 << 0, 33 | SMBFileModeWrite = 1 << 1, 34 | 35 | SMBFileModeReadWrite = SMBFileModeRead | SMBFileModeWrite 36 | }; 37 | 38 | @property (nonatomic, readonly, nonnull) SMBShare *share; 39 | @property (nonatomic, readonly, nonnull) NSString *path; 40 | @property (nonatomic, readonly, nonnull) NSString *name; 41 | @property (nonatomic, readonly) BOOL exists; 42 | @property (nonatomic, readonly) BOOL isDirectory; 43 | @property (nonatomic, readonly) unsigned long long size; 44 | @property (nonatomic, readonly, nullable) NSDate *creationTime; 45 | @property (nonatomic, readonly, nullable) NSDate *modificationTime; 46 | @property (nonatomic, readonly, nullable) NSDate *accessTime; 47 | @property (nonatomic, readonly, nullable) NSDate *writeTime; 48 | @property (nonatomic, readonly, nullable) NSDate *statusTime; 49 | @property (nonatomic, readonly) BOOL hasStatus; 50 | @property (nonatomic, readonly, nullable) SMBFile *parent; 51 | @property (nonatomic, readonly) BOOL isOpen; 52 | 53 | + (nullable instancetype)rootOfShare:(nonnull SMBShare *)share; 54 | + (nullable instancetype)fileWithPath:(nonnull NSString *)path share:(nonnull SMBShare *)share; 55 | + (nullable instancetype)fileWithPath:(nonnull NSString *)path relativeToFile:(nonnull SMBFile *)file; 56 | 57 | - (nullable instancetype)initWithPath:(nonnull NSString *)path share:(nonnull SMBShare *)share; 58 | - (nullable instancetype)initWithPath:(nonnull NSString *)path relativeToFile:(nonnull SMBFile *)file; 59 | 60 | - (void)open:(SMBFileMode)mode completion:(nullable void (^)(NSError *_Nullable error))completion; 61 | - (void)close:(nullable void (^)(NSError *_Nullable error))completion; 62 | //- (void)write:(nonnull NSData *)data completion:(nullable void (^)(long bytesWritten, NSError *_Nullable error))completion; 63 | - (void)write:(nonnull NSData *_Nullable (^)(unsigned long long))dataHandler progress:(nullable void (^)(unsigned long long bytesWrittenTotal, long bytesWrittenLast, BOOL complete, NSError *_Nullable error))progress; 64 | - (void)read:(NSUInteger)bufferSize progress:(nullable BOOL (^)(unsigned long long bytesReadTotal, NSData *_Nullable data, BOOL complete, NSError *_Nullable error))progress; 65 | - (void)read:(NSUInteger)bufferSize maxBytes:(unsigned long long)maxBytes progress:(nullable BOOL (^)(unsigned long long bytesReadTotal, NSData *_Nullable data, BOOL complete, NSError *_Nullable error))progress; 66 | - (void)seek:(unsigned long long)offset absolute:(BOOL)absolute completion:(nullable void (^)(unsigned long long position, NSError *_Nullable error))completion; 67 | 68 | - (void)listFiles:(nullable void (^)(NSArray *_Nullable files, NSError *_Nullable error))completion; 69 | - (void)listFilesUsingFilter:(nullable BOOL (^)(SMBFile *_Nonnull file))filter completion:(nullable void (^)(NSArray *_Nullable files, NSError *_Nullable error))completion; 70 | - (void)updateStatus:(nullable void (^)(NSError *_Nullable error))completion; 71 | - (void)createDirectory:(nullable void (^)(NSError *_Nullable error))completion; 72 | - (void)createDirectories:(nullable void (^)(NSError *_Nullable error))completion; 73 | - (void)delete:(nullable void (^)(NSError *_Nullable error))completion; 74 | - (void)moveTo:(nonnull NSString *)path completion:(nullable void (^)(NSError *_Nullable error))completion; 75 | 76 | #pragma mark - Unavailable methods 77 | 78 | + new NS_UNAVAILABLE; 79 | - init NS_UNAVAILABLE; 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /SMBClient/SMBFile.m: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import "SMBFile_Protected.h" 26 | #import "SMBShare_Protected.h" 27 | #import "SMBError.h" 28 | 29 | #import "smb_file.h" 30 | 31 | @interface SMBFile () 32 | 33 | @property (nonatomic) dispatch_queue_t serialQueue; 34 | @property (nonatomic) smb_fd fileID; 35 | 36 | @end 37 | 38 | @implementation SMBFile 39 | 40 | + (instancetype)rootOfShare:(SMBShare *)share { 41 | SMBFile *root = [[self alloc] initWithPath:@"/" share:share]; 42 | 43 | root.smbStat = [SMBStat statForRoot]; 44 | 45 | return root; 46 | } 47 | 48 | + (nullable instancetype)fileWithPath:(nonnull NSString *)path share:(nonnull SMBShare *)share { 49 | return [[self alloc] initWithPath:path share:share]; 50 | } 51 | 52 | + (nullable instancetype)fileWithPath:(nonnull NSString *)path relativeToFile:(nonnull SMBFile *)file { 53 | return [[self alloc] initWithPath:path relativeToFile:file]; 54 | } 55 | 56 | - (instancetype)initWithPath:(NSString *)path share:(SMBShare *)share { 57 | self = [super init]; 58 | if (self) { 59 | NSString *queueName = [NSString stringWithFormat:@"smb_file_queue_%@", path]; 60 | 61 | _path = path; 62 | _share = share; 63 | _serialQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL); 64 | 65 | if ([_path isEqualToString:@"/"]) { 66 | self.smbStat = [SMBStat statForRoot]; 67 | } else { 68 | if (![_path hasPrefix:@"/"]) { 69 | _path = [@"/" stringByAppendingString:_path]; 70 | } 71 | 72 | if ([_path hasSuffix:@"/"]) { 73 | _path = [_path substringToIndex:_path.length - 1]; 74 | } 75 | } 76 | } 77 | return self; 78 | } 79 | 80 | - (instancetype)initWithPath:(NSString *)path relativeToFile:(SMBFile *)file { 81 | NSString *p = file.path; 82 | 83 | if (file.isDirectory) { 84 | p = [p stringByAppendingString:@"/"]; 85 | } 86 | 87 | NSURL *url = [NSURL fileURLWithPath:p]; 88 | NSString *absolutePath = [NSURL fileURLWithPath:path relativeToURL:url].path; 89 | 90 | return [self initWithPath:absolutePath share:file.share]; 91 | } 92 | 93 | - (NSString *)description { 94 | if (_smbStat) { 95 | return [NSString stringWithFormat:@"%@ (%@)", _path, _smbStat.description]; 96 | } else { 97 | return _path; 98 | } 99 | } 100 | 101 | #pragma mark - Public methods 102 | 103 | - (SMBFile *)parent { 104 | SMBFile *parent = nil; 105 | NSString *path; 106 | 107 | if ([self.path isEqualToString:@"/"]) { 108 | path = nil; 109 | } else { 110 | path = [self.path stringByDeletingLastPathComponent]; 111 | } 112 | 113 | if (path.length) { 114 | parent = [[SMBFile alloc] initWithPath:path share:self.share]; 115 | } 116 | 117 | return parent; 118 | } 119 | 120 | - (void)open:(SMBFileMode)mode completion:(nullable void (^)(NSError *_Nullable))completion { 121 | 122 | dispatch_async(_serialQueue, ^{ 123 | 124 | [self.share openFile:self.path mode:mode completion:^(SMBFile *file, smb_fd fileID, NSError *error) { 125 | if (error == nil) { 126 | self->_fileID = fileID; 127 | self->_smbStat = file.smbStat; 128 | } 129 | if (completion) { 130 | dispatch_async(dispatch_get_main_queue(), ^{ 131 | completion(error); 132 | }); 133 | } 134 | }]; 135 | }); 136 | 137 | } 138 | 139 | - (void)close:(nullable void (^)(NSError *_Nullable))completion { 140 | 141 | dispatch_async(_serialQueue, ^{ 142 | 143 | if (self->_fileID == 0) { 144 | dispatch_async(dispatch_get_main_queue(), ^{ 145 | completion([SMBError notOpenError]); 146 | }); 147 | } else { 148 | [self.share closeFile:self->_fileID path:self.path completion:^(SMBFile *file, NSError * _Nullable error) { 149 | if (error == nil) { 150 | self->_fileID = 0; 151 | self->_smbStat = file.smbStat; 152 | } 153 | if (completion) { 154 | dispatch_async(dispatch_get_main_queue(), ^{ 155 | completion(error); 156 | }); 157 | } 158 | }]; 159 | 160 | } 161 | }); 162 | } 163 | 164 | - (BOOL)isOpen { 165 | return _fileID > 0; 166 | } 167 | 168 | - (void)seek:(unsigned long long)offset absolute:(BOOL)absolute completion:(nullable void (^)(unsigned long long, NSError *_Nullable))completion { 169 | 170 | dispatch_async(_serialQueue, ^{ 171 | 172 | NSError *error = nil; 173 | unsigned long long position = 0; 174 | 175 | if (self.share.server.smbSession) { 176 | if ([self isOpen]) { 177 | 178 | off_t pos = smb_fseek(self.share.server.smbSession, self->_fileID, offset, absolute ? SMB_SEEK_SET : SMB_SEEK_CUR); 179 | 180 | position = MAX(0L, pos); 181 | 182 | if (pos < 0L) { 183 | error = [SMBError seekError]; 184 | } 185 | 186 | } else { 187 | error = [SMBError notOpenError]; 188 | } 189 | } else { 190 | error = [SMBError notConnectedError]; 191 | } 192 | 193 | if (completion) { 194 | dispatch_async(dispatch_get_main_queue(), ^{ 195 | completion(position, error); 196 | }); 197 | } 198 | 199 | }); 200 | } 201 | 202 | - (void)read:(NSUInteger)bufferSize progress:(nullable BOOL (^)(unsigned long long, NSData *_Nullable, BOOL, NSError *_Nullable))progress { 203 | [self read:bufferSize maxBytes:0 progress:progress]; 204 | } 205 | 206 | - (void)read:(NSUInteger)bufferSize maxBytes:(unsigned long long)maxBytes progress:(nullable BOOL (^)(unsigned long long, NSData *_Nullable, BOOL, NSError *_Nullable))progress { 207 | 208 | dispatch_async(_serialQueue, ^{ 209 | 210 | NSError *error = nil; 211 | __block BOOL finished = NO; 212 | unsigned long long bytesReadTotal = 0; 213 | 214 | if (self.share.server.smbSession) { 215 | if ([self isOpen]) { 216 | 217 | char buf[bufferSize]; 218 | 219 | if (progress) { 220 | dispatch_async(dispatch_get_main_queue(), ^{ 221 | BOOL readMore = progress(bytesReadTotal, nil, NO, error); 222 | 223 | if (!readMore) { 224 | finished = YES; 225 | } 226 | }); 227 | } 228 | 229 | while (!finished) { 230 | 231 | NSUInteger bytesToRead = maxBytes == 0 ? bufferSize : MIN(bufferSize, (NSUInteger)(maxBytes - bytesReadTotal)); 232 | long bytesRead = smb_fread(self.share.server.smbSession, self->_fileID, buf, bytesToRead); 233 | 234 | if (bytesRead < 0) { 235 | finished = YES; 236 | error = [SMBError readError]; 237 | } else if (bytesRead == 0) { 238 | finished = YES; 239 | } else { 240 | bytesReadTotal += bytesRead; 241 | 242 | if (bytesReadTotal == maxBytes) { 243 | finished = YES; 244 | } 245 | 246 | if (progress) { 247 | NSData *data = [NSData dataWithBytes:buf length:bytesRead]; 248 | 249 | dispatch_async(dispatch_get_main_queue(), ^{ 250 | BOOL readMore = progress(bytesReadTotal, data, NO, error); 251 | 252 | if (!readMore) { 253 | finished = YES; 254 | } 255 | }); 256 | } 257 | } 258 | } 259 | } else { 260 | finished = YES; 261 | error = [SMBError notOpenError]; 262 | } 263 | } else { 264 | finished = YES; 265 | error = [SMBError notConnectedError]; 266 | } 267 | 268 | if (progress) { 269 | dispatch_async(dispatch_get_main_queue(), ^{ 270 | progress(bytesReadTotal, nil, YES, error); 271 | }); 272 | } 273 | }); 274 | } 275 | 276 | - (void)write:(nonnull NSData *_Nullable (^)(unsigned long long))dataHandler progress:(nullable void (^)(unsigned long long, long, BOOL, NSError *_Nullable))progress { 277 | 278 | dispatch_async(_serialQueue, ^{ 279 | 280 | NSError *error = nil; 281 | unsigned long long offset = 0; 282 | BOOL finished = NO; 283 | 284 | if (self.share.server.smbSession) { 285 | if ([self isOpen]) { 286 | 287 | NSData *data; 288 | 289 | if (progress) { 290 | dispatch_async(dispatch_get_main_queue(), ^{ 291 | progress(offset, 0, finished, error); 292 | }); 293 | } 294 | 295 | while (!finished) { 296 | 297 | data = dataHandler(offset); 298 | 299 | if (data.length == 0) { 300 | finished = YES; 301 | } else { 302 | long bytesToWrite = data.length; 303 | long bytesWritten = smb_fwrite(self.share.server.smbSession, self->_fileID, (void *)data.bytes, bytesToWrite); 304 | 305 | offset += MAX(0, bytesWritten); 306 | 307 | if (bytesWritten != bytesToWrite) { 308 | finished = YES; 309 | error = [SMBError writeError]; 310 | } else { 311 | if (progress) { 312 | dispatch_async(dispatch_get_main_queue(), ^{ 313 | progress(offset, MAX(0, bytesWritten), finished, error); 314 | }); 315 | } 316 | } 317 | } 318 | } 319 | } else { 320 | finished = YES; 321 | error = [SMBError notOpenError]; 322 | } 323 | } else { 324 | finished = YES; 325 | error = [SMBError notConnectedError]; 326 | } 327 | 328 | if (progress) { 329 | dispatch_async(dispatch_get_main_queue(), ^{ 330 | progress(offset, 0, finished, error); 331 | }); 332 | } 333 | }); 334 | } 335 | 336 | - (void)listFiles:(nullable void (^)(NSArray *_Nullable, NSError *_Nullable))completion { 337 | [self listFilesUsingFilter:nil completion:completion]; 338 | } 339 | 340 | - (void)listFilesUsingFilter:(nullable BOOL (^)(SMBFile *_Nonnull file))filter completion:(nullable void (^)(NSArray *_Nullable files, NSError *_Nullable error))completion { 341 | //if (_smbStat == nil || !self.exists) { 342 | [self updateStatus:^(NSError *error) { 343 | if (error) { 344 | if (completion) { 345 | dispatch_async(dispatch_get_main_queue(), ^{ 346 | completion(nil, error); 347 | }); 348 | } 349 | } else if (!self.hasStatus || !self.isDirectory) { 350 | dispatch_async(dispatch_get_main_queue(), ^{ 351 | completion(nil, [SMBError notSuchFileOrDirectory]); 352 | }); 353 | } else { 354 | [self.share listFiles:self.path filter:filter completion:completion]; 355 | } 356 | }]; 357 | //} else { 358 | // [self.share listFiles:self.path filter:filter completion:completion]; 359 | //} 360 | } 361 | 362 | - (void)updateStatus:(nullable void (^)(NSError *_Nullable))completion { 363 | [self.share getStatusOfFile:self.path completion:^(SMBStat * _Nullable smbStat, NSError * _Nullable error) { 364 | if (error == nil) { 365 | self->_smbStat = smbStat; 366 | } 367 | if (completion) { 368 | dispatch_async(dispatch_get_main_queue(), ^{ 369 | completion(error); 370 | }); 371 | } 372 | }]; 373 | } 374 | 375 | - (void)createDirectory:(nullable void (^)(NSError *_Nullable))completion { 376 | [self.share createDirectory:self.path completion:^(SMBFile * _Nullable file, NSError * _Nullable error) { 377 | if (error == nil) { 378 | self->_smbStat = file.smbStat; 379 | } 380 | if (completion) { 381 | dispatch_async(dispatch_get_main_queue(), ^{ 382 | completion(error); 383 | }); 384 | } 385 | }]; 386 | } 387 | 388 | - (void)createDirectories:(nullable void (^)(NSError *_Nullable))completion { 389 | [self.share createDirectories:self.path completion:^(SMBFile * _Nullable file, NSError * _Nullable error) { 390 | if (error == nil) { 391 | self->_smbStat = file.smbStat; 392 | } 393 | if (completion) { 394 | dispatch_async(dispatch_get_main_queue(), ^{ 395 | completion(error); 396 | }); 397 | } 398 | }]; 399 | } 400 | 401 | - (void)delete:(nullable void (^)(NSError *_Nullable))completion { 402 | [self.share deleteFile:self.path completion:^(NSError * _Nullable error) { 403 | if (error == nil) { 404 | self->_smbStat = [SMBStat statForNonExistingFile]; 405 | } 406 | if (completion) { 407 | dispatch_async(dispatch_get_main_queue(), ^{ 408 | completion(error); 409 | }); 410 | } 411 | }]; 412 | } 413 | 414 | - (void)moveTo:(nonnull NSString *)path completion:(nullable void (^)(NSError *_Nullable))completion { 415 | SMBFile *f = [SMBFile fileWithPath:path relativeToFile:self]; 416 | 417 | [self.share moveFile:self.path to:f.path completion:^(SMBFile *_Nullable newFile, NSError * _Nullable error) { 418 | if (error == nil) { 419 | self->_smbStat = newFile.smbStat; 420 | self->_path = newFile.path; 421 | } 422 | if (completion) { 423 | dispatch_async(dispatch_get_main_queue(), ^{ 424 | completion(error); 425 | }); 426 | } 427 | }]; 428 | } 429 | 430 | #pragma mark - Overwritten getters and setters 431 | 432 | - (NSString *)name { 433 | return _path.pathComponents.lastObject; 434 | } 435 | 436 | - (BOOL)exists { 437 | return self.smbStat.exists; 438 | } 439 | 440 | - (BOOL)isDirectory { 441 | return self.smbStat.isDirectory; 442 | } 443 | 444 | - (unsigned long long)size { 445 | return self.smbStat.size; 446 | } 447 | 448 | - (NSDate *)creationTime { 449 | return self.smbStat.creationTime; 450 | } 451 | 452 | - (NSDate *)modificationTime { 453 | return self.smbStat.modificationTime; 454 | } 455 | 456 | - (NSDate *)accessTime { 457 | return self.smbStat.accessTime; 458 | } 459 | 460 | - (NSDate *)writeTime { 461 | return self.smbStat.writeTime; 462 | } 463 | 464 | - (NSDate *)statusTime { 465 | return self.smbStat.statTime; 466 | } 467 | 468 | - (BOOL)hasStatus { 469 | return self.smbStat != nil; 470 | } 471 | 472 | @end 473 | -------------------------------------------------------------------------------- /SMBClient/SMBFileServer.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import "SMBDevice.h" 26 | #import "SMBShare.h" 27 | 28 | @interface SMBFileServer : SMBDevice 29 | 30 | - (nullable instancetype)initWithHost:(nonnull NSString *)ipAddressOrHostname netbiosName:(nonnull NSString *)name group:(nullable NSString *)group; 31 | 32 | - (void)disconnect:(nullable void (^)(void))completion; 33 | - (void)connectAsUser:(nullable NSString *)username password:(nullable NSString *)password completion:(nullable void (^)(BOOL guest, NSError *_Nullable error))completion; 34 | - (void)connectAsUser:(nullable NSString *)username password:(nullable NSString *)password domain:(nullable NSString *)domain completion:(nullable void (^)(BOOL guest, NSError *_Nullable error))completion; 35 | - (void)listShares:(nullable void (^)(NSArray *_Nullable shares, NSError *_Nullable error))completion; 36 | - (void)findShare:(nonnull NSString *)name completion:(nullable void (^)(SMBShare *_Nullable share, NSError *_Nullable error))completion; 37 | 38 | #pragma mark - Unavailable methods 39 | 40 | + new NS_UNAVAILABLE; 41 | - init NS_UNAVAILABLE; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /SMBClient/SMBFileServer.m: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import "SMBFileServer_Protected.h" 26 | #import "SMBError.h" 27 | #import "SMBShare_Protected.h" 28 | 29 | #import 30 | 31 | #import "smb_session.h" 32 | #import "smb_share.h" 33 | 34 | @interface SMBFileServer () 35 | 36 | @property (nonatomic) dispatch_queue_t serialQueue; 37 | 38 | @end 39 | 40 | @implementation SMBFileServer 41 | 42 | - (instancetype)initWithHost:(NSString *)ipAddressOrHostname netbiosName:(NSString *)name group:(NSString *)group { 43 | self = [super initWithType:SMBDeviceTypeFileServer host:ipAddressOrHostname netbiosName:name group:group]; 44 | if (self) { 45 | NSString *queueName = [NSString stringWithFormat:@"smb_server_queue_%@", ipAddressOrHostname]; 46 | 47 | _serialQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL); 48 | } 49 | return self; 50 | } 51 | 52 | - (void)dealloc { 53 | if (_smbSession) { 54 | smb_session_destroy(_smbSession); 55 | _smbSession = nil; 56 | } 57 | } 58 | 59 | - (void)connectAsUser:(NSString *)username password:(NSString *)password completion:(void (^)(BOOL, NSError *))completion { 60 | [self connectAsUser:username password:password domain:nil completion:completion]; 61 | } 62 | 63 | - (void)connectAsUser:(NSString *)username password:(NSString *)password domain:(NSString *)domain completion:(void (^)(BOOL, NSError *))completion { 64 | [self disconnect:^{ 65 | 66 | dispatch_async(self->_serialQueue, ^{ 67 | 68 | const char *name = self.netbiosName.UTF8String; 69 | const char *host = self.host.UTF8String; 70 | const char *user = username.length > 0 ? username.UTF8String : " "; 71 | const char *pass = password.length > 0 ? password.UTF8String : " "; 72 | const char *domn = domain.length > 0 ? domain.UTF8String : " "; 73 | NSError *error = nil; 74 | BOOL guest = NO; 75 | const struct hostent *host_entry = gethostbyname(host); 76 | 77 | if (host_entry == NULL) { 78 | error = [SMBError hostNotFoundError]; 79 | } else if (host_entry->h_addr_list[0] == NULL) { 80 | error = [SMBError noIPAddressError]; 81 | } else { 82 | 83 | self->_smbSession = smb_session_new(); 84 | 85 | if (self->_smbSession) { 86 | const struct in_addr addr = *(struct in_addr *)host_entry->h_addr_list[0]; 87 | 88 | smb_session_set_creds(self->_smbSession, domn, user, pass); 89 | 90 | // Connect to the host 91 | int result = smb_session_connect(self->_smbSession, name, addr.s_addr, SMB_TRANSPORT_TCP); 92 | 93 | if (result == 0) { 94 | // Login 95 | result = smb_session_login(self->_smbSession); 96 | } 97 | 98 | if (result == 0) { 99 | if (smb_session_is_guest(self->_smbSession) > 0) { 100 | guest = YES; 101 | } 102 | } else { 103 | error = [SMBError dsmError:result session:self->_smbSession]; 104 | 105 | [self disconnect:nil]; 106 | } 107 | } else { 108 | error = [SMBError unknownError]; 109 | } 110 | } 111 | 112 | if (completion) { 113 | dispatch_async(dispatch_get_main_queue(), ^{ 114 | completion(guest, error); 115 | }); 116 | } 117 | }); 118 | }]; 119 | 120 | } 121 | 122 | - (void)disconnect:(nullable void (^)(void))completion { 123 | 124 | dispatch_async(_serialQueue, ^{ 125 | if (self->_smbSession) { 126 | smb_session_destroy(self->_smbSession); 127 | self->_smbSession = nil; 128 | } 129 | 130 | if (completion) { 131 | dispatch_async(dispatch_get_main_queue(), ^{ 132 | completion(); 133 | }); 134 | } 135 | }); 136 | } 137 | 138 | - (void)findShare:(nonnull NSString *)name completion:(nullable void (^)(SMBShare *_Nullable, NSError *_Nullable))completion { 139 | 140 | [self listShares:^(NSArray *shares, NSError *error) { 141 | SMBShare *share = nil; 142 | 143 | if (error == nil) { 144 | for (SMBShare *s in shares) { 145 | if ([s.name caseInsensitiveCompare:name] == NSOrderedSame) { 146 | share = s; 147 | break; 148 | } 149 | } 150 | } 151 | 152 | if (completion) { 153 | completion(share, error); 154 | } 155 | }]; 156 | } 157 | 158 | - (void)listShares:(nullable void (^)(NSArray *_Nullable, NSError *_Nullable))completion { 159 | 160 | dispatch_async(_serialQueue, ^{ 161 | 162 | NSMutableArray *shares = nil; 163 | NSError *error = nil; 164 | smb_share_list list; 165 | size_t shareCount = 0; 166 | 167 | if (self.smbSession) { 168 | int dsm_error = smb_share_get_list(self.smbSession, &list, &shareCount); 169 | 170 | if (dsm_error == 0) { 171 | 172 | shares = [NSMutableArray array]; 173 | 174 | for (NSInteger i = 0; i < shareCount; i++) { 175 | const char *cname = smb_share_list_at(list, i); 176 | 177 | // Exclude system shares suffixed by '$' 178 | if (cname[strlen(cname) - 1] != '$') { 179 | 180 | NSString *shareName = [NSString stringWithUTF8String:cname]; 181 | 182 | SMBShare *share = [[SMBShare alloc] initWithName:shareName server:self]; 183 | 184 | [shares addObject:share]; 185 | } 186 | } 187 | 188 | smb_share_list_destroy(list); 189 | } else { 190 | error = [SMBError dsmError:dsm_error session:self.smbSession]; 191 | } 192 | } else { 193 | error = [SMBError notConnectedError]; 194 | } 195 | 196 | if (completion) { 197 | dispatch_async(dispatch_get_main_queue(), ^{ 198 | completion(shares, error); 199 | }); 200 | } 201 | }); 202 | } 203 | 204 | - (void)openShare:(nonnull NSString *)name completion:(nullable void (^)(smb_tid, NSError * _Nullable))completion { 205 | dispatch_async(_serialQueue, ^{ 206 | smb_tid shareID = -1; 207 | NSError *error = nil; 208 | 209 | if (self.smbSession) { 210 | int dsm_error = smb_tree_connect(self.smbSession, name.UTF8String, &shareID); 211 | 212 | if (dsm_error != 0) { 213 | error = [SMBError dsmError:dsm_error session:self.smbSession]; 214 | } 215 | 216 | } else { 217 | error = [SMBError notConnectedError]; 218 | } 219 | 220 | if (completion) { 221 | dispatch_async(dispatch_get_main_queue(), ^{ 222 | completion(shareID, error); 223 | }); 224 | } 225 | }); 226 | } 227 | 228 | - (void)closeShare:(smb_tid)shareID completion:(nullable void (^)(NSError * _Nullable))completion { 229 | dispatch_async(_serialQueue, ^{ 230 | NSError *error = nil; 231 | 232 | if (self.smbSession) { 233 | int dsm_error = smb_tree_disconnect(self.smbSession, shareID); 234 | 235 | if (dsm_error != 0) { 236 | error = [SMBError dsmError:dsm_error session:self.smbSession]; 237 | } 238 | 239 | } else { 240 | error = [SMBError notConnectedError]; 241 | } 242 | 243 | if (completion) { 244 | dispatch_async(dispatch_get_main_queue(), ^{ 245 | completion(error); 246 | }); 247 | } 248 | }); 249 | } 250 | 251 | @end 252 | -------------------------------------------------------------------------------- /SMBClient/SMBShare.h: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import 26 | 27 | @class SMBFile; 28 | @class SMBFileServer; 29 | 30 | @interface SMBShare : NSObject 31 | 32 | @property (nonatomic, readonly, nonnull) SMBFileServer *server; 33 | @property (nonatomic, readonly, nonnull) NSString *name; 34 | @property (nonatomic, readonly) BOOL isOpen; 35 | 36 | - (void)open:(nullable void (^)(NSError *_Nullable error))completion; 37 | - (void)close:(nullable void (^)(NSError *_Nullable error))completion; 38 | - (void)listFiles:(nullable void (^)(NSArray *_Nullable files, NSError *_Nullable error))completion; 39 | - (void)listFilesUsingFilter:(nullable BOOL (^)(SMBFile *_Nonnull file))filter completion:(nullable void (^)(NSArray *_Nullable files, NSError *_Nullable error))completion; 40 | 41 | #pragma mark - Unavailable methods 42 | 43 | + new NS_UNAVAILABLE; 44 | - init NS_UNAVAILABLE; 45 | 46 | @end 47 | 48 | 49 | -------------------------------------------------------------------------------- /SMBClient/SMBShare.m: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------------- 2 | // This file is part of SMBClient. 3 | // Copyright © 2016 Naxos Software Solutions GmbH. 4 | // 5 | // Author: Martin Schaefer 6 | // 7 | // SMBClient is licensed under the GNU Lesser General Public License version 2.1 8 | // or later 9 | // ----------------------------------------------------------------------------- 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | // ----------------------------------------------------------------------------- 24 | 25 | #import "SMBShare_Protected.h" 26 | #import "SMBError.h" 27 | #import "SMBFile_Protected.h" 28 | 29 | #import "smb_share.h" 30 | #import "smb_dir.h" 31 | #import "smb_file.h" 32 | #import "smb_stat.h" 33 | 34 | @interface SMBShare () 35 | 36 | @property (nonatomic) dispatch_queue_t serialQueue; 37 | @property (nonatomic) smb_tid shareID; 38 | 39 | @end 40 | 41 | @implementation SMBShare 42 | 43 | - (nullable instancetype)initWithName:(nonnull NSString *)name server:(nonnull SMBFileServer *)server { 44 | self = [super init]; 45 | if (self) { 46 | NSString *queueName = [NSString stringWithFormat:@"smb_share_queue_%@", name]; 47 | 48 | _name = name; 49 | _server = server; 50 | _shareID = 0; 51 | _serialQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL); 52 | } 53 | return self; 54 | } 55 | 56 | - (void)dealloc { 57 | // [self close:nil]; 58 | // smb_tree_disconnect(_server.smbSession, _shareID); 59 | } 60 | 61 | - (NSString *)description { 62 | return [NSString stringWithFormat:@"%@ on %@", self.name, self.server]; 63 | } 64 | 65 | - (void)open:(nullable void (^)(NSError *_Nullable))completion { 66 | dispatch_async(_serialQueue, ^{ 67 | [self.server openShare:self.name completion:^(smb_tid shareID, NSError *error){ 68 | if (error == nil) { 69 | self->_shareID = shareID; 70 | } 71 | if (completion) { 72 | completion(error); 73 | } 74 | }]; 75 | }); 76 | } 77 | 78 | - (void)close:(nullable void (^)(NSError *_Nullable))completion { 79 | dispatch_async(_serialQueue, ^{ 80 | if (self->_shareID == 0) { 81 | dispatch_async(dispatch_get_main_queue(), ^{ 82 | completion([SMBError notOpenError]); 83 | }); 84 | } else { 85 | [self.server closeShare:self->_shareID completion:completion]; 86 | self->_shareID = 0; 87 | } 88 | }); 89 | } 90 | 91 | - (BOOL)isOpen { 92 | return _shareID > 0; 93 | } 94 | 95 | - (void)createDirectories:(nonnull NSString *)path completion:(nullable void (^)(SMBFile *_Nullable, NSError *_Nullable))completion { 96 | dispatch_async(_serialQueue, ^{ 97 | SMBFile *file = nil; 98 | NSError *error = nil; 99 | 100 | if (self.server.smbSession) { 101 | if ([self isOpen]) { 102 | NSString *p = path; 103 | 104 | while ([p hasPrefix:@"/"]) { 105 | p = [path substringFromIndex:1]; 106 | } 107 | NSArray *directories = p.pathComponents; 108 | 109 | p = @""; 110 | 111 | for (NSUInteger i = 0; error == nil && i < directories.count; i++) { 112 | p = [p stringByAppendingFormat:@"\\%@", [directories objectAtIndex:i]]; 113 | 114 | const char *cpath = p.UTF8String; 115 | SMBStat *stat = [self _stat:cpath]; 116 | 117 | if (!stat.exists) { 118 | int dsm_error = smb_directory_create(self.server.smbSession, self->_shareID, cpath); 119 | 120 | if (dsm_error != 0) { 121 | error = [SMBError dsmError:dsm_error session:self.server.smbSession]; 122 | } 123 | } 124 | 125 | if (error == nil && i == directories.count - 1) { 126 | file = [[SMBFile alloc] initWithPath:path share:self]; 127 | 128 | if (!stat.exists) { 129 | stat = [self _stat:cpath]; 130 | } 131 | file.smbStat = stat; 132 | } 133 | } 134 | 135 | } else { 136 | error = [SMBError notOpenError]; 137 | } 138 | } else { 139 | error = [SMBError notConnectedError]; 140 | } 141 | 142 | if (completion) { 143 | dispatch_async(dispatch_get_main_queue(), ^{ 144 | completion(file, error); 145 | }); 146 | } 147 | }); 148 | } 149 | 150 | - (void)createDirectory:(nonnull NSString *)path completion:(nullable void (^)(SMBFile *_Nullable, NSError *_Nullable))completion { 151 | dispatch_async(_serialQueue, ^{ 152 | SMBFile *file = nil; 153 | NSError *error = nil; 154 | 155 | if (self.server.smbSession) { 156 | if ([self isOpen]) { 157 | 158 | NSString *smbPath = [path stringByReplacingOccurrencesOfString:@"/" withString:@"\\"]; 159 | const char *cpath = smbPath.UTF8String; 160 | SMBStat *stat = [self _stat:cpath]; 161 | 162 | if (!stat.exists) { 163 | int dsm_error = smb_directory_create(self.server.smbSession, self->_shareID, cpath); 164 | 165 | if (dsm_error != 0) { 166 | error = [SMBError dsmError:dsm_error session:self.server.smbSession]; 167 | } 168 | } 169 | 170 | if (error == nil) { 171 | file = [[SMBFile alloc] initWithPath:path share:self]; 172 | 173 | if (!stat.exists) { 174 | stat = [self _stat:cpath]; 175 | } 176 | file.smbStat = stat; 177 | } 178 | } else { 179 | error = [SMBError notOpenError]; 180 | } 181 | } else { 182 | error = [SMBError notConnectedError]; 183 | } 184 | 185 | if (completion) { 186 | dispatch_async(dispatch_get_main_queue(), ^{ 187 | completion(file, error); 188 | }); 189 | } 190 | }); 191 | } 192 | 193 | - (uint32_t)_mod:(SMBFileMode)mode { 194 | uint32_t mod = 0; 195 | 196 | if (mode & SMBFileModeRead) { 197 | mod |= SMB_MOD_READ | SMB_MOD_READ_EXT | SMB_MOD_READ_ATTR | SMB_MOD_READ_CTL; 198 | } 199 | if (mode & SMBFileModeWrite) { 200 | mod |= SMB_MOD_WRITE | SMB_MOD_WRITE_EXT | SMB_MOD_WRITE_ATTR | SMB_MOD_APPEND; 201 | } 202 | 203 | return mod; 204 | } 205 | 206 | - (void)openFile:(nonnull NSString *)path mode:(SMBFileMode)mode completion:(nullable void (^)(SMBFile *, smb_fd, NSError *_Nullable))completion { 207 | 208 | dispatch_async(_serialQueue, ^{ 209 | 210 | smb_fd fd = -1; 211 | NSError *error = nil; 212 | SMBFile *file = nil; 213 | 214 | if (self.server.smbSession) { 215 | if ([self isOpen]) { 216 | NSString *smbPath = [path stringByReplacingOccurrencesOfString:@"/" withString:@"\\"]; 217 | const char *cpath = smbPath.UTF8String; 218 | uint32_t mod = [self _mod:mode]; 219 | 220 | file = [[SMBFile alloc] initWithPath:path share:self]; 221 | file.smbStat = [self _stat:cpath]; 222 | 223 | int dsm_error = smb_fopen(self.server.smbSession, self.shareID, cpath, mod, &fd); 224 | 225 | if (dsm_error != 0) { 226 | error = [SMBError dsmError:dsm_error session:self.server.smbSession]; 227 | } 228 | } else { 229 | error = [SMBError notOpenError]; 230 | } 231 | } else { 232 | error = [SMBError notConnectedError]; 233 | } 234 | 235 | if (completion) { 236 | dispatch_async(dispatch_get_main_queue(), ^{ 237 | completion(file, fd, error); 238 | }); 239 | } 240 | }); 241 | } 242 | 243 | - (void)closeFile:(smb_fd)fd path:(NSString *)path completion:(nullable void (^)(SMBFile *_Nullable, NSError *_Nullable))completion { 244 | 245 | dispatch_async(_serialQueue, ^{ 246 | 247 | NSError *error = nil; 248 | SMBFile *file = nil; 249 | 250 | if (self.server.smbSession) { 251 | if ([self isOpen]) { 252 | 253 | smb_fclose(self.server.smbSession, fd); 254 | 255 | NSString *smbPath = [path stringByReplacingOccurrencesOfString:@"/" withString:@"\\"]; 256 | const char *cpath = smbPath.UTF8String; 257 | 258 | file = [[SMBFile alloc] initWithPath:path share:self]; 259 | file.smbStat = [self _stat:cpath]; 260 | 261 | } else { 262 | error = [SMBError notOpenError]; 263 | } 264 | } else { 265 | error = [SMBError notConnectedError]; 266 | } 267 | 268 | if (completion) { 269 | dispatch_async(dispatch_get_main_queue(), ^{ 270 | completion(file, error); 271 | }); 272 | } 273 | }); 274 | } 275 | 276 | - (void)deleteFile:(nonnull NSString *)path completion:(nullable void (^)(NSError *_Nullable))completion { 277 | dispatch_async(_serialQueue, ^{ 278 | NSError *error = nil; 279 | 280 | if (self.server.smbSession) { 281 | if ([self isOpen]) { 282 | 283 | NSString *smbPath = [path stringByReplacingOccurrencesOfString:@"/" withString:@"\\"]; 284 | const char *cpath = smbPath.UTF8String; 285 | SMBStat *stat = [self _stat:cpath]; 286 | 287 | if (stat.exists) { 288 | int dsm_error = 0; 289 | 290 | if (stat.isDirectory) { 291 | dsm_error = smb_directory_rm(self.server.smbSession, self->_shareID, cpath); 292 | } else { 293 | dsm_error = smb_file_rm(self.server.smbSession, self->_shareID, cpath); 294 | } 295 | 296 | if (dsm_error != 0) { 297 | error = [SMBError dsmError:dsm_error session:self.server.smbSession]; 298 | } 299 | } 300 | 301 | } else { 302 | error = [SMBError notOpenError]; 303 | } 304 | } else { 305 | error = [SMBError notConnectedError]; 306 | } 307 | 308 | if (completion) { 309 | dispatch_async(dispatch_get_main_queue(), ^{ 310 | completion(error); 311 | }); 312 | } 313 | }); 314 | } 315 | 316 | - (void)listFiles:(void (^)(NSArray *, NSError *))completion { 317 | [self listFiles:@"/" filter:nil completion:completion]; 318 | } 319 | 320 | - (void)listFilesUsingFilter:(nullable BOOL (^)(SMBFile *_Nonnull))filter completion:(void (^)(NSArray *, NSError *))completion { 321 | [self listFiles:@"/" filter:filter completion:completion]; 322 | } 323 | 324 | - (void)listFiles:(NSString *)path filter:(nullable BOOL (^)(SMBFile *_Nonnull file))filter completion:(void (^)(NSArray *, NSError *))completion { 325 | 326 | dispatch_async(_serialQueue, ^{ 327 | 328 | NSMutableArray *fileList = nil; 329 | NSError *error = nil; 330 | 331 | if (self.server.smbSession) { 332 | if ([self isOpen]) { 333 | 334 | NSString *smbPath = [path stringByReplacingOccurrencesOfString:@"/" withString:@"\\"]; 335 | 336 | if (![smbPath hasSuffix:@"\\"]) { 337 | smbPath = [smbPath stringByAppendingString:@"\\"]; 338 | } 339 | smbPath = [smbPath stringByAppendingString:@"*"]; 340 | 341 | //Query for a list of files in this directory 342 | smb_stat_list statList = smb_find(self.server.smbSession, self->_shareID, smbPath.UTF8String); 343 | 344 | if (statList != NULL) { 345 | size_t listCount = smb_stat_list_count(statList); 346 | 347 | fileList = [NSMutableArray array]; 348 | 349 | for (NSInteger i = 0; i < listCount; i++) { 350 | smb_stat item = smb_stat_list_at(statList, i); 351 | const char *name = smb_stat_name(item); 352 | 353 | NSString *filePath = [path stringByAppendingPathComponent:[NSString stringWithUTF8String:name]]; 354 | 355 | SMBFile *file = [[SMBFile alloc] initWithPath:filePath share:self]; 356 | 357 | file.smbStat = [[SMBStat alloc] initWithStat:item]; 358 | 359 | if (!(file.isDirectory && ([file.name isEqualToString:@".."] || [file.name isEqualToString:@"."]))) { 360 | if (filter == nil || filter(file)) { 361 | [fileList addObject:file]; 362 | } 363 | } 364 | } 365 | smb_stat_list_destroy(statList); 366 | } else { 367 | /* 368 | uint32_t nt_status = smb_session_get_nt_status(self.server.smbSession); 369 | if (nt_status != NT_STATUS_SUCCESS) { 370 | error = [SMBError dsmError:DSM_ERROR_NT session:self.server.smbSession]; 371 | } 372 | */ 373 | } 374 | 375 | } else { 376 | error = [SMBError notOpenError]; 377 | } 378 | } else { 379 | error = [SMBError notConnectedError]; 380 | } 381 | 382 | if (completion) { 383 | dispatch_async(dispatch_get_main_queue(), ^{ 384 | completion(fileList, error); 385 | }); 386 | } 387 | }); 388 | } 389 | 390 | - (void)moveFile:(NSString *)oldPath to:(NSString *)newPath completion:(void (^)(SMBFile *, NSError *))completion { 391 | dispatch_async(_serialQueue, ^{ 392 | NSError *error = nil; 393 | SMBFile *file = nil; 394 | 395 | if (self.server.smbSession) { 396 | if ([self isOpen]) { 397 | NSString *smbOldPath = [oldPath stringByReplacingOccurrencesOfString:@"/" withString:@"\\"]; 398 | NSString *smbNewPath = [newPath stringByReplacingOccurrencesOfString:@"/" withString:@"\\"]; 399 | 400 | int res = smb_file_mv(self.server.smbSession, self->_shareID, smbOldPath.UTF8String, smbNewPath.UTF8String); 401 | 402 | if (res != 0) { 403 | error = [SMBError notSuchFileOrDirectory]; 404 | } else { 405 | file = [SMBFile fileWithPath:newPath share:self]; 406 | file.smbStat = [self _stat:smbNewPath.UTF8String]; 407 | } 408 | } else { 409 | error = [SMBError notOpenError]; 410 | } 411 | } else { 412 | error = [SMBError notConnectedError]; 413 | } 414 | 415 | if (completion) { 416 | dispatch_async(dispatch_get_main_queue(), ^{ 417 | completion(file, error); 418 | }); 419 | } 420 | }); 421 | } 422 | 423 | - (void)getStatusOfFile:(NSString *)path completion:(void (^)(SMBStat *, NSError *))completion { 424 | 425 | if (path.length == 0 || [path isEqualToString:@"/"]) { 426 | if (completion) { 427 | completion([SMBStat statForRoot], nil); 428 | } 429 | } else { 430 | dispatch_async(_serialQueue, ^{ 431 | NSError *error = nil; 432 | SMBStat *smbStat = nil; 433 | 434 | if (self.server.smbSession) { 435 | if ([self isOpen]) { 436 | NSString *smbPath = [path stringByReplacingOccurrencesOfString:@"/" withString:@"\\"]; 437 | smbStat = [self _stat:smbPath.UTF8String]; 438 | } else { 439 | error = [SMBError notOpenError]; 440 | } 441 | } else { 442 | error = [SMBError notConnectedError]; 443 | } 444 | 445 | if (completion) { 446 | dispatch_async(dispatch_get_main_queue(), ^{ 447 | completion(smbStat, error); 448 | }); 449 | } 450 | }); 451 | } 452 | } 453 | 454 | #pragma mark - Private methods 455 | 456 | - (SMBStat *)_stat:(const char *)path { 457 | smb_stat stat = smb_fstat(self.server.smbSession, _shareID, path); 458 | SMBStat *smbStat = [SMBStat statForNonExistingFile]; 459 | 460 | // This is a workaround because the above doesn't seem to work on directories 461 | // See https://github.com/videolabs/libdsm/issues/79 462 | 463 | if (stat == NULL) { 464 | smb_stat_list statList = smb_find(self.server.smbSession, _shareID, path); 465 | 466 | if (statList != NULL) { 467 | size_t listCount = smb_stat_list_count(statList); 468 | 469 | if (listCount == 1) { 470 | stat = smb_stat_list_at(statList, 0); 471 | smbStat = [SMBStat statWithStat:stat]; 472 | } else { 473 | NSLog(@"Unexpectedly got multiple stat entries for %s", path); 474 | } 475 | 476 | smb_stat_list_destroy(statList); 477 | } 478 | } else { 479 | smbStat = [SMBStat statWithStat:stat]; 480 | smb_stat_destroy(stat); 481 | } 482 | // end of workaround 483 | 484 | return smbStat; 485 | } 486 | 487 | @end 488 | 489 | @implementation SMBStat 490 | 491 | + (nullable instancetype)statForNonExistingFile { 492 | return [[self alloc] initForNonExistingFile]; 493 | } 494 | 495 | + (nullable instancetype)statForRoot { 496 | return [[self alloc] initForRoot]; 497 | } 498 | 499 | + (nullable instancetype)statWithStat:(smb_stat)stat { 500 | return [[self alloc] initWithStat:stat]; 501 | } 502 | 503 | - (nullable instancetype)initForNonExistingFile { 504 | self = [super init]; 505 | if (self) { 506 | _statTime = [NSDate new]; 507 | } 508 | return self; 509 | } 510 | 511 | - (instancetype)initForRoot { 512 | self = [super init]; 513 | if (self) { 514 | _directory = YES; 515 | _exists = YES; 516 | _statTime = [NSDate new]; 517 | _smbName = @"\\"; 518 | } 519 | return self; 520 | } 521 | 522 | - (instancetype)initWithStat:(smb_stat)stat { 523 | self = [super init]; 524 | if (self) { 525 | if (stat != NULL) { 526 | uint64_t modificationTimestamp = smb_stat_get(stat, SMB_STAT_MTIME); 527 | uint64_t creationTimestamp = smb_stat_get(stat, SMB_STAT_CTIME); 528 | uint64_t accessTimestamp = smb_stat_get(stat, SMB_STAT_ATIME); 529 | uint64_t writeTimestamp = smb_stat_get(stat, SMB_STAT_WTIME); 530 | 531 | _smbName = [NSString stringWithUTF8String:smb_stat_name(stat)]; 532 | 533 | _size = smb_stat_get(stat, SMB_STAT_SIZE); 534 | _directory = (smb_stat_get(stat, SMB_STAT_ISDIR) != 0); 535 | 536 | _modificationTime = [self _dateFromSMBTime:modificationTimestamp]; 537 | _creationTime = [self _dateFromSMBTime:creationTimestamp]; 538 | _accessTime = [self _dateFromSMBTime:accessTimestamp]; 539 | _writeTime = [self _dateFromSMBTime:writeTimestamp]; 540 | 541 | _exists = YES; 542 | } 543 | 544 | _statTime = [NSDate new]; 545 | } 546 | return self; 547 | } 548 | 549 | - (NSString *)description { 550 | return [NSString stringWithFormat:@"Status of %@ %@ as of %@: Size: %llu, Created: %@, Modified: %@, Last opened: %@", self.isDirectory ? @"directory" : @"file", self.smbName, self.statTime, self.size, self.creationTime, self.modificationTime, self.accessTime]; 551 | } 552 | 553 | #pragma mark - Private methods 554 | 555 | - (NSDate *)_dateFromSMBTime:(uint64_t)smbTime { 556 | // If you really want some explanation, search for 557 | // 'SystemTimeLow and SystemTimeHigh' at http://ubiqx.org/cifs/SMB.html 558 | 559 | NSTimeInterval timestamp = (NSTimeInterval)((smbTime/10000000.) - 11644473600); 560 | 561 | return [NSDate dateWithTimeIntervalSince1970:timestamp]; 562 | } 563 | 564 | @end 565 | -------------------------------------------------------------------------------- /SMBClientTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ThirdParty/libdsm/include/bdsm.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * __________________ _________ _____ _____ .__ ._. 3 | * \______ \______ \ / _____/ / \ / _ \ |__| ____ | | 4 | * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | | 5 | * | | \| ` \/ / Y \ / | | \ ___/ \| 6 | * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __ 7 | * \/ \/ \/ \/ )/ \/ \/ \/ 8 | * 9 | * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS 10 | * 11 | * Author: Julien 'Lta' BALLET 12 | * 13 | * liBDSM is released under LGPLv2.1 (or later) and is also available 14 | * under a commercial license. 15 | ***************************************************************************** 16 | * This program is free software; you can redistribute it and/or modify it 17 | * under the terms of the GNU Lesser General Public License as published by 18 | * the Free Software Foundation; either version 2.1 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU Lesser General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU Lesser General Public License 27 | * along with this program; if not, write to the Free Software Foundation, 28 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 29 | *****************************************************************************/ 30 | 31 | #ifndef __BDSM_H_ 32 | #define __BDSM_H_ 33 | 34 | #define BDSM_VERSION_CURRENT 4 35 | #define BDSM_VERSION_REVISION 0 36 | #define BDSM_VERSION_AGE 1 37 | 38 | #include "netbios_ns.h" 39 | #include "netbios_defs.h" 40 | #include "smb_types.h" 41 | #include "smb_session.h" 42 | #include "smb_share.h" 43 | #include "smb_file.h" 44 | #include "smb_stat.h" 45 | #include "smb_dir.h" 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /ThirdParty/libdsm/include/netbios_defs.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * __________________ _________ _____ _____ .__ ._. 3 | * \______ \______ \ / _____/ / \ / _ \ |__| ____ | | 4 | * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | | 5 | * | | \| ` \/ / Y \ / | | \ ___/ \| 6 | * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __ 7 | * \/ \/ \/ \/ )/ \/ \/ \/ 8 | * 9 | * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS 10 | * 11 | * Author: Julien 'Lta' BALLET 12 | * 13 | * liBDSM is released under LGPLv2.1 (or later) and is also available 14 | * under a commercial license. 15 | ***************************************************************************** 16 | * This program is free software; you can redistribute it and/or modify it 17 | * under the terms of the GNU Lesser General Public License as published by 18 | * the Free Software Foundation; either version 2.1 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU Lesser General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU Lesser General Public License 27 | * along with this program; if not, write to the Free Software Foundation, 28 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 29 | *****************************************************************************/ 30 | 31 | #ifndef _BDSM_NETBIOS_DEFS_H_ 32 | #define _BDSM_NETBIOS_DEFS_H_ 33 | 34 | // Netbios name types 35 | #define NETBIOS_WORKSTATION 0x00 36 | #define NETBIOS_MESSENGER 0x03 37 | #define NETBIOS_FILESERVER 0x20 38 | #define NETBIOS_DOMAINMASTER 0x1b 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /ThirdParty/libdsm/include/netbios_ns.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * __________________ _________ _____ _____ .__ ._. 3 | * \______ \______ \ / _____/ / \ / _ \ |__| ____ | | 4 | * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | | 5 | * | | \| ` \/ / Y \ / | | \ ___/ \| 6 | * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __ 7 | * \/ \/ \/ \/ )/ \/ \/ \/ 8 | * 9 | * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS 10 | * 11 | * Author: Julien 'Lta' BALLET 12 | * 13 | * liBDSM is released under LGPLv2.1 (or later) and is also available 14 | * under a commercial license. 15 | ***************************************************************************** 16 | * This program is free software; you can redistribute it and/or modify it 17 | * under the terms of the GNU Lesser General Public License as published by 18 | * the Free Software Foundation; either version 2.1 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU Lesser General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU Lesser General Public License 27 | * along with this program; if not, write to the Free Software Foundation, 28 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 29 | *****************************************************************************/ 30 | 31 | #ifndef __BDSM_NETBIOS_NS_H_ 32 | #define __BDSM_NETBIOS_NS_H_ 33 | 34 | #include 35 | 36 | /** 37 | * @file netbios_ns.h 38 | * @brief Netbios name service 39 | */ 40 | 41 | typedef struct netbios_ns_entry netbios_ns_entry; 42 | typedef struct netbios_ns netbios_ns; 43 | 44 | /** 45 | * @brief Get the name of the entry referenced by the iterator iter. 46 | * @details The pointer points to an area of memory owned by the netbios name 47 | * service 48 | * 49 | * @return A null-terminated ASCII string representing the name of a netbios machine. 50 | */ 51 | const char *netbios_ns_entry_name(netbios_ns_entry *entry); 52 | 53 | /** 54 | * @brief Get the name of the entry referenced by the iterator iter. 55 | * @details The pointer points to an area of memory owned by the netbios name 56 | * service 57 | * 58 | * @return A null-terminated ASCII string representing the group of a netbios machine. 59 | */ 60 | const char *netbios_ns_entry_group(netbios_ns_entry *entry); 61 | 62 | /** 63 | * @brief Return the IP address of the correspondance referenced by the iterator 64 | * 65 | * @return The ip address of this entry, in network byte order. 66 | */ 67 | uint32_t netbios_ns_entry_ip(netbios_ns_entry *entry); 68 | 69 | /** 70 | * @brief Return the type of record 71 | * 72 | * @return The type of netbios record (.ie 0x20 for FileServer, 73 | * 0 for workstation, etc.) or a value < 0 if the iterator is invalid or an 74 | * error occured. 75 | */ 76 | char netbios_ns_entry_type(netbios_ns_entry *entry); 77 | 78 | /** 79 | * @brief Allocate and initialize the Netbios name service client object. 80 | * @return A newly allocated netbios_ns ready for querying. 81 | * Deallocate with netbios_ns_destroy(). 82 | */ 83 | netbios_ns *netbios_ns_new(); 84 | 85 | /** 86 | * @brief Destroy the netbios name service object 87 | * @param[in] ns A pointer on the netbios_ns to destroy and deallocate 88 | */ 89 | void netbios_ns_destroy(netbios_ns *ns); 90 | 91 | /** 92 | * @brief Resolve a Netbios name 93 | * @details This function tries to resolves the given NetBIOS name with the 94 | * given type on the LAN, using broadcast queries. No WINS server is called. 95 | * 96 | * @param ns the netbios name service object. 97 | * @param name the null-terminated ASCII netbios name to resolve. If it's 98 | * longer than 15 chars, it'll be truncated. 99 | * @param type The type of the name to look for. @see netbios_defs.h 100 | * @param[out] addr The IP address in network byte order of the machine if found. 101 | * @return 0 on success or -1 on failure 102 | */ 103 | int netbios_ns_resolve(netbios_ns *ns, const char *name, 104 | char type, uint32_t *addr); 105 | 106 | /** 107 | * @brief Perform an inverse netbios lookup (get name from ip) 108 | * @details This function does a NBSTAT and stores all the returned entry in 109 | * the internal list of entries. It returns one of the name found. (Normally 110 | * the <20> or <0> name) 111 | * 112 | * @param ns The name service object. 113 | * @param ip The ip address in network byte order. 114 | * 115 | * @return A null-terminated ASCII string containing the NETBIOS name. You don't 116 | * own the it (it'll be freed when destroying/clearing the name service) 117 | */ 118 | const char *netbios_ns_inverse(netbios_ns *ns, uint32_t ip); 119 | 120 | typedef struct 121 | { 122 | // Opaque pointer that will be passed to callbacks 123 | void *p_opaque; 124 | // Called when a new entry is added 125 | void (*pf_on_entry_added) (void *p_opaque, netbios_ns_entry *entry); 126 | // Called when an entry is removed 127 | void (*pf_on_entry_removed)(void *p_opaque, netbios_ns_entry *entry); 128 | } netbios_ns_discover_callbacks; 129 | 130 | /** @brief Perform a NETBIOS discovery in a separate thread. 131 | * 132 | * @details This functions starts a new thread that will send a message to '*' 133 | * Netbios name (broadcast NB query on 255.255.255.255). It'll wait for the 134 | * machine on the LAN to answer. It'll then perform a reverse lookup on all the 135 | * ip he received packet from. Once a name and an ip is found, this function 136 | * will notify the caller by a callback. 137 | * 138 | * @param ns The name service object. @param broadcast_timeout Do a broadcast 139 | * every timeout seconds @param callbacks The callbacks previously setup by the 140 | * caller 141 | * 142 | * @return 0 on success or -1 on failure 143 | */ 144 | int netbios_ns_discover_start(netbios_ns *ns, unsigned int broadcast_timeout, 145 | netbios_ns_discover_callbacks *callbacks); 146 | 147 | /** 148 | * @brief Stop the NETBIOS discovery. 149 | * @param ns The name service object. 150 | * @return 0 on success or -1 on failure 151 | */ 152 | int netbios_ns_discover_stop(netbios_ns *ns); 153 | 154 | #endif 155 | -------------------------------------------------------------------------------- /ThirdParty/libdsm/include/smb_defs.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * __________________ _________ _____ _____ .__ ._. 3 | * \______ \______ \ / _____/ / \ / _ \ |__| ____ | | 4 | * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | | 5 | * | | \| ` \/ / Y \ / | | \ ___/ \| 6 | * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __ 7 | * \/ \/ \/ \/ )/ \/ \/ \/ 8 | * 9 | * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS 10 | * 11 | * Author: Julien 'Lta' BALLET 12 | * 13 | * liBDSM is released under LGPLv2.1 (or later) and is also available 14 | * under a commercial license. 15 | ***************************************************************************** 16 | * This program is free software; you can redistribute it and/or modify it 17 | * under the terms of the GNU Lesser General Public License as published by 18 | * the Free Software Foundation; either version 2.1 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU Lesser General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU Lesser General Public License 27 | * along with this program; if not, write to the Free Software Foundation, 28 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 29 | *****************************************************************************/ 30 | 31 | /** 32 | * @file smb_defs.h 33 | * @brief SMB usefull constants 34 | */ 35 | 36 | #ifndef __BSDM_SMB_DEFS_H_ 37 | #define __BSDM_SMB_DEFS_H_ 38 | 39 | #define SMB_DEFAULT_BUFSIZE (8192) 40 | 41 | enum 42 | { 43 | /// SMB with Direct-TCP connection (OSX supports only this) 44 | SMB_TRANSPORT_TCP = 1, 45 | /// SMB with Netbios over TCP (older mechanism) 46 | SMB_TRANSPORT_NBT = 2 47 | }; 48 | 49 | //-----------------------------------------------------------------------------/ 50 | // SMB Session states 51 | //-----------------------------------------------------------------------------/ 52 | enum 53 | { 54 | /// Error state, there was an error somewhere 55 | SMB_STATE_ERROR = -1, 56 | /// The SMB session has just been created 57 | SMB_STATE_NEW = 0, 58 | /// A Netbios session has been successfully established. 59 | SMB_STATE_NETBIOS_OK = 1, 60 | /// Dialect was successfully negotiated 61 | SMB_STATE_DIALECT_OK = 2, 62 | /// Session Authentication was successfull, you can become nasty 63 | SMB_STATE_SESSION_OK = 3 64 | }; 65 | 66 | //-----------------------------------------------------------------------------/ 67 | // smb_fseek() operations 68 | //-----------------------------------------------------------------------------/ 69 | // smb_fseek operations 70 | enum 71 | { 72 | /// Set the read pointer at the given position 73 | SMB_SEEK_SET = 0, 74 | /// Adjusts the read pointer relatively to the actual position 75 | SMB_SEEK_CUR = 1 76 | }; 77 | 78 | enum smb_session_supports_what 79 | { 80 | SMB_SESSION_XSEC = 0, 81 | }; 82 | 83 | //-----------------------------------------------------------------------------/ 84 | // File access rights (used when smb_open() files) 85 | //-----------------------------------------------------------------------------/ 86 | /// Flag for smb_file_open. Request right for reading 87 | #define SMB_MOD_READ (1 << 0) 88 | /// Flag for smb_file_open. Request right for writing 89 | #define SMB_MOD_WRITE (1 << 1) 90 | /// Flag for smb_file_open. Request right for appending 91 | #define SMB_MOD_APPEND (1 << 2) 92 | /// Flag for smb_file_open. Request right for extended read (?) 93 | #define SMB_MOD_READ_EXT (1 << 3) 94 | /// Flag for smb_file_open. Request right for extended write (?) 95 | #define SMB_MOD_WRITE_EXT (1 << 4) 96 | /// Flag for smb_file_open. Request right for execution (?) 97 | #define SMB_MOD_EXEC (1 << 5) 98 | /// Flag for smb_file_open. Request right for child removal (?) 99 | #define SMB_MOD_RMCHILD (1 << 6) 100 | /// Flag for smb_file_open. Request right for reading file attributes 101 | #define SMB_MOD_READ_ATTR (1 << 7) 102 | /// Flag for smb_file_open. Request right for writing file attributes 103 | #define SMB_MOD_WRITE_ATTR (1 << 8) 104 | /// Flag for smb_file_open. Request right for removing file 105 | #define SMB_MOD_RM (1 << 16) 106 | /// Flag for smb_file_open. Request right for reading ACL 107 | #define SMB_MOD_READ_CTL (1 << 17) 108 | /// Flag for smb_file_open. Request right for writing ACL 109 | #define SMB_MOD_WRITE_DAC (1 << 18) 110 | /// Flag for smb_file_open. Request right for changing owner 111 | #define SMB_MOD_CHOWN (1 << 19) 112 | /// Flag for smb_file_open. (??) 113 | #define SMB_MOD_SYNC (1 << 20) 114 | /// Flag for smb_file_open. (??) 115 | #define SMB_MOD_SYS (1 << 24) 116 | /// Flag for smb_file_open. (??) 117 | #define SMB_MOD_MAX_ALLOWED (1 << 25) 118 | /// Flag for smb_file_open. Request all generic rights (??) 119 | #define SMB_MOD_GENERIC_ALL (1 << 28) 120 | /// Flag for smb_file_open. Request generic exec right (??) 121 | #define SMB_MOD_GENERIC_EXEC (1 << 29) 122 | /// Flag for smb_file_open. Request generic read right (??) 123 | #define SMB_MOD_GENERIC_READ (1 << 30) 124 | /// Flag for smb_file_open. Request generic write right (??) 125 | #define SMB_MOD_GENERIC_WRITE (1 << 31) 126 | /** 127 | * @brief Flag for smb_file_open. Default R/W mode 128 | * @details A few flags OR'ed 129 | */ 130 | #define SMB_MOD_RW (SMB_MOD_READ | SMB_MOD_WRITE | SMB_MOD_APPEND \ 131 | | SMB_MOD_READ_EXT | SMB_MOD_WRITE_EXT \ 132 | | SMB_MOD_READ_ATTR | SMB_MOD_WRITE_ATTR \ 133 | | SMB_MOD_READ_CTL ) 134 | /** 135 | * @brief Flag for smb_file_open. Default R/O mode 136 | * @details A few flags OR'ed 137 | */ 138 | #define SMB_MOD_RO (SMB_MOD_READ | SMB_MOD_READ_EXT \ 139 | | SMB_MOD_READ_ATTR | SMB_MOD_READ_CTL ) 140 | 141 | //-----------------------------------------------------------------------------/ 142 | // NTSTATUS & internal return codes 143 | //-----------------------------------------------------------------------------/ 144 | #define NT_STATUS_SUCCESS 0x00000000 145 | #define NT_STATUS_INVALID_SMB 0x00010002 146 | #define NT_STATUS_SMB_BAD_TID 0x00050002 147 | #define NT_STATUS_SMB_BAD_UID 0x005b0002 148 | #define NT_STATUS_NOT_IMPLEMENTED 0xc0000002 149 | #define NT_STATUS_INVALID_DEVICE_REQUEST 0xc0000010 150 | #define NT_STATUS_NO_SUCH_DEVICE 0xc000000e 151 | #define NT_STATUS_NO_SUCH_FILE 0xc000000f 152 | #define NT_STATUS_MORE_PROCESSING_REQUIRED 0xc0000016 153 | #define NT_STATUS_INVALID_LOCK_SEQUENCE 0xc000001e 154 | #define NT_STATUS_INVALID_VIEW_SIZE 0xc000001f 155 | #define NT_STATUS_ALREADY_COMMITTED 0xc0000021 156 | #define NT_STATUS_ACCESS_DENIED 0xc0000022 157 | #define NT_STATUS_OBJECT_NAME_NOT_FOUND 0xc0000034 158 | #define NT_STATUS_OBJECT_NAME_COLLISION 0xc0000035 159 | #define NT_STATUS_OBJECT_PATH_INVALID 0xc0000039 160 | #define NT_STATUS_OBJECT_PATH_NOT_FOUND 0xc000003a 161 | #define NT_STATUS_OBJECT_PATH_SYNTAX_BAD 0xc000003b 162 | #define NT_STATUS_PORT_CONNECTION_REFUSED 0xc0000041 163 | #define NT_STATUS_THREAD_IS_TERMINATING 0xc000004b 164 | #define NT_STATUS_DELETE_PENDING 0xc0000056 165 | #define NT_STATUS_PRIVILEGE_NOT_HELD 0xc0000061 166 | #define NT_STATUS_LOGON_FAILURE 0xc000006D 167 | #define NT_STATUS_DFS_EXIT_PATH_FOUND 0xc000009b 168 | #define NT_STATUS_MEDIA_WRITE_PROTECTED 0xc00000a2 169 | #define NT_STATUS_ILLEGAL_FUNCTION 0xc00000af 170 | #define NT_STATUS_FILE_IS_A_DIRECTORY 0xc00000ba 171 | #define NT_STATUS_FILE_RENAMED 0xc00000d5 172 | #define NT_STATUS_REDIRECTOR_NOT_STARTED 0xc00000fb 173 | #define NT_STATUS_DIRECTORY_NOT_EMPTY 0xc0000101 174 | #define NT_STATUS_PROCESS_IS_TERMINATING 0xc000010a 175 | #define NT_STATUS_TOO_MANY_OPENED_FILES 0xc000011f 176 | #define NT_STATUS_CANNOT_DELETE 0xc0000121 177 | #define NT_STATUS_FILE_DELETED 0xc0000123 178 | #define NT_STATUS_INSUFF_SERVER_RESOURCES 0xc0000205 179 | 180 | #define DSM_SUCCESS (0) 181 | #define DSM_ERROR_GENERIC (-1) 182 | #define DSM_ERROR_NT (-2) /* see smb_session_get_nt_status */ 183 | #define DSM_ERROR_NETWORK (-3) 184 | #define DSM_ERROR_CHARSET (-4) 185 | 186 | #endif 187 | -------------------------------------------------------------------------------- /ThirdParty/libdsm/include/smb_dir.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * __________________ _________ _____ _____ .__ ._. 3 | * \______ \______ \ / _____/ / \ / _ \ |__| ____ | | 4 | * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | | 5 | * | | \| ` \/ / Y \ / | | \ ___/ \| 6 | * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __ 7 | * \/ \/ \/ \/ )/ \/ \/ \/ 8 | * 9 | * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS 10 | * 11 | * Author: Sylver Bruneau 12 | * 13 | * liBDSM is released under LGPLv2.1 (or later) and is also available 14 | * under a commercial license. 15 | ***************************************************************************** 16 | * This program is free software; you can redistribute it and/or modify it 17 | * under the terms of the GNU Lesser General Public License as published by 18 | * the Free Software Foundation; either version 2.1 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU Lesser General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU Lesser General Public License 27 | * along with this program; if not, write to the Free Software Foundation, 28 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 29 | *****************************************************************************/ 30 | 31 | /** 32 | * @file smb_dir.h 33 | * @brief Directory operations 34 | */ 35 | 36 | #ifndef __BDSM_SMB_DIR_H_ 37 | #define __BDSM_SMB_DIR_H_ 38 | 39 | #include "smb_session.h" 40 | 41 | 42 | /** 43 | * @brief remove a directory on a share. 44 | * @details Use this function to delete an empty directory 45 | * 46 | * @param s The session object 47 | * @param tid The tid of the share the file is in, obtained via smb_tree_connect() 48 | * @param path The path of the file to delete 49 | * @return 0 on success or a DSM error code in case of error 50 | */ 51 | int smb_directory_rm(smb_session *s, smb_tid tid, const char *path); 52 | 53 | /** 54 | * @brief create a directory on a share. 55 | * @details Use this function to create a directory 56 | * 57 | * @param s The session object 58 | * @param tid The tid of the share the file is in, obtained via smb_tree_connect() 59 | * @param path The path of the directory to create 60 | * @return 0 on success or a DSM error code in case of error 61 | */ 62 | int smb_directory_create(smb_session *s, smb_tid tid, const char *path); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /ThirdParty/libdsm/include/smb_file.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * __________________ _________ _____ _____ .__ ._. 3 | * \______ \______ \ / _____/ / \ / _ \ |__| ____ | | 4 | * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | | 5 | * | | \| ` \/ / Y \ / | | \ ___/ \| 6 | * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __ 7 | * \/ \/ \/ \/ )/ \/ \/ \/ 8 | * 9 | * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS 10 | * 11 | * Author: Julien 'Lta' BALLET 12 | * 13 | * liBDSM is released under LGPLv2.1 (or later) and is also available 14 | * under a commercial license. 15 | ***************************************************************************** 16 | * This program is free software; you can redistribute it and/or modify it 17 | * under the terms of the GNU Lesser General Public License as published by 18 | * the Free Software Foundation; either version 2.1 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU Lesser General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU Lesser General Public License 27 | * along with this program; if not, write to the Free Software Foundation, 28 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 29 | *****************************************************************************/ 30 | 31 | /** 32 | * @file smb_file.h 33 | * @brief File operations 34 | */ 35 | 36 | #ifndef __BDSM_SMB_FILE_H_ 37 | #define __BDSM_SMB_FILE_H_ 38 | 39 | #include "smb_session.h" 40 | 41 | 42 | /** 43 | * @brief Open a file on a share. 44 | * @details Use this function to obtain an smb_fd, necesary for file operations 45 | * 46 | * @param s The session object 47 | * @param tid The tid of the share the file is in, obtained via smb_tree_connect() 48 | * @param path The path of the file to open 49 | * @param mod The access modes requested (example: #SMB_MOD_RO) 50 | * @param fd The pointer to the smb file description that can be used for 51 | * further file operations 52 | * @return 0 on success or a DSM error code in case of error 53 | * 54 | * @see smb_tree_connect 55 | */ 56 | int smb_fopen(smb_session *s, smb_tid tid, const char *path, 57 | uint32_t mod, smb_fd *fd); 58 | 59 | /** 60 | * @brief Close an open file 61 | * @details The smb_fd is invalidated and MUST not be use it anymore. You can 62 | * give it the 0 value. 63 | * 64 | * @param s The session object 65 | * @param fd The SMB file descriptor 66 | */ 67 | void smb_fclose(smb_session *s, smb_fd fd); 68 | 69 | /** 70 | * @brief Read from an open file 71 | * @details The semantics is basically the same that the unix read() one. 72 | * At most 'buf_size' bytes are read from the current seek offset and copied into 73 | * the memory pointed by 'buf' from the open file represented by the smb file 74 | * descriptor 'fd'. 75 | * 76 | * @param[in] s The session object 77 | * @param[in] fd [description] 78 | * @param[out] buf can be NULL in order to skip buf_size bytes 79 | * @param[in] buf_size [description] 80 | * @return The number of bytes read or -1 in case of error. 81 | */ 82 | ssize_t smb_fread(smb_session *s, smb_fd fd, void *buf, size_t buf_size); 83 | 84 | /** 85 | * @brief Write to an open file 86 | * @details At most 'buf_size' bytes from memory pointed by 'buf' are written 87 | * to the current seek offset of the open file represented by the smb file 88 | * descriptor 'fd'. 89 | * 90 | * @param[in] s The session object 91 | * @param[in] fd [description] 92 | * @param[out] buf [description] 93 | * @param[in] buf_size [description] 94 | * @return The number of bytes written or -1 in case of error. 95 | */ 96 | ssize_t smb_fwrite(smb_session *s, smb_fd fd, void *buf, size_t buf_size); 97 | 98 | /** 99 | * @brief Sets/Moves/Get the read/write pointer for a given file 100 | * @details The behavior of this function is the same as the Unix fseek() 101 | * function, except the SEEK_END argument isn't supported. 102 | * 103 | * This functions adjust the read/write pointer depending on the value of 104 | * offset and whence. 105 | * 106 | * - If whence == #SMB_SEEK_SET, the read pointer is set at 'offset' 107 | * - If whence == #SMB_SEEK_CUR, the read pointer is adjusted by 'offset' 108 | * 109 | * @param s The session object 110 | * @param fd The file descriptors for which the read pointer is to be adjusted 111 | * @param offset Set/Adjust quantity 112 | * @param whence Which action to perform. Supported operations are 113 | * #SMB_SEEK_SET and #SMB_SEEK_CUR 114 | * @return The current read pointer position or -1 on error 115 | */ 116 | ssize_t smb_fseek(smb_session *s, smb_fd fd, off_t offset, int whence); 117 | 118 | /** 119 | * @brief remove a file on a share. 120 | * @details Use this function to delete a file 121 | * 122 | * @param s The session object 123 | * @param tid The tid of the share the file is in, obtained via smb_tree_connect() 124 | * @param path The path of the file to delete 125 | * @return 0 if delete OK or "NT" error code 126 | */ 127 | int smb_file_rm(smb_session *s, smb_tid tid, const char *path); 128 | 129 | /** 130 | * @brief move/rename a file/directory on a share. 131 | * @details Use this function to move and/or rename a file/directory 132 | * 133 | * @param s The session object 134 | * @param tid The tid of the share the file is in, obtained via smb_tree_connect() 135 | * @param old_path The current path of the file/directory to move/rename 136 | * @param new_path The new path of the file/directory 137 | * @return 0 if move OK or -1 in case of error 138 | */ 139 | int smb_file_mv(smb_session *s, smb_tid tid, const char *old_path, const char *new_path); 140 | 141 | #endif 142 | -------------------------------------------------------------------------------- /ThirdParty/libdsm/include/smb_session.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * __________________ _________ _____ _____ .__ ._. 3 | * \______ \______ \ / _____/ / \ / _ \ |__| ____ | | 4 | * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | | 5 | * | | \| ` \/ / Y \ / | | \ ___/ \| 6 | * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __ 7 | * \/ \/ \/ \/ )/ \/ \/ \/ 8 | * 9 | * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS 10 | * 11 | * Author: Julien 'Lta' BALLET 12 | * 13 | * liBDSM is released under LGPLv2.1 (or later) and is also available 14 | * under a commercial license. 15 | ***************************************************************************** 16 | * This program is free software; you can redistribute it and/or modify it 17 | * under the terms of the GNU Lesser General Public License as published by 18 | * the Free Software Foundation; either version 2.1 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU Lesser General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU Lesser General Public License 27 | * along with this program; if not, write to the Free Software Foundation, 28 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 29 | *****************************************************************************/ 30 | 31 | #ifndef __BDSM_SMB_SESSION_H_ 32 | #define __BDSM_SMB_SESSION_H_ 33 | 34 | 35 | #include "smb_defs.h" 36 | #include "smb_types.h" 37 | 38 | /** 39 | * @file smb_session.h 40 | * @brief Functions to connect and authenticate to an SMB server 41 | */ 42 | 43 | /** 44 | * @brief Allocates a new Session object 45 | * @details To be able to perform actions on shares and file, you'll need to 46 | * call smb_session_connect, then authenticate with smb_authenticate. 47 | * @return A new Session object. 48 | */ 49 | smb_session *smb_session_new(); 50 | 51 | /** 52 | * @brief Close a session and deallocate its ressources 53 | * @details After destroying a session, all the smb_tid, smb_fid and smb_fd 54 | * associated with this session becomes invalid. 55 | * 56 | * @param s The session to destroy 57 | */ 58 | void smb_session_destroy(smb_session *s); 59 | 60 | /** 61 | * @brief Set the credentials for this session. 62 | * @details Any of the params except s can be NULL. 63 | * 64 | * @param s The session object. 65 | * @param domain Domain to authenticate on. Often it's the same as netbios host. 66 | * @param login The user to login as. 67 | * @param password the user's password. 68 | */ 69 | void smb_session_set_creds(smb_session *s, const char *domain, 70 | const char *login, const char *password); 71 | #define SMB_CREDS_MAXLEN 128 72 | 73 | 74 | 75 | /** 76 | * @brief Establish a connection and negotiate a session protocol with a remote 77 | * host 78 | * @details You have to provide both the ip and the name. This is a constraint 79 | * of Netbios, which requires you to know its name before he accepts to speak 80 | * with you. 81 | * 82 | * @param s A session object. 83 | * @param hostname The ASCII netbios name, the name type will be coerced to <20> 84 | * since libdsm is about reading files 85 | * @param ip The ip of the machine to connect to (in network byte order) 86 | * @param transport The type of transport used, it could be SMB_TRANSPORT_TCP 87 | * or SMB_TRANSPORT_NBT (Netbios over TCP, ie legacy) 88 | * @return 0 on success or a DSM error code in case of error 89 | */ 90 | int smb_session_connect(smb_session *s, const char *hostname, 91 | uint32_t ip, int transport); 92 | 93 | /** 94 | * @brief Authenticate on the remote host with the provided credentials 95 | * @details Can be called if session state is SMB_STATE_DIALECT_OK. 96 | * If successfull, session state transition to SMB_STATE_SESSION_OK 97 | * Provides the credentials with smb_session_set_creds. 98 | * 99 | * @param s The session object. 100 | * 101 | * @return 0 on success or a DSM error code in case of error. Success doesn't 102 | * mean you are logged in with the user you requested. If guest are activated 103 | * on the remote host, when login fails, you are logged in as 'Guest'. Failure 104 | * might also indicate you didn't supplied all the credentials 105 | */ 106 | int smb_session_login(smb_session *s); 107 | 108 | 109 | int smb_session_logoff(smb_session *s); 110 | 111 | /** 112 | * @brief Am i logged in as Guest ? 113 | * 114 | * @param s The session object 115 | * @return 1 -> Logged in as guest 116 | * 0 -> Logged in as regular user 117 | * -1 -> Error (not logged in, invalid session, etc.) 118 | */ 119 | int smb_session_is_guest(smb_session *s); 120 | 121 | /** 122 | * @brief Returns the server name with the type 123 | * 124 | * @param s The session object 125 | * @return The server name or NULL. The memory is owned by the session object. 126 | */ 127 | const char *smb_session_server_name(smb_session *s); 128 | 129 | /** 130 | * @brief Check if a feature is supported/has been negociated with the server 131 | * 132 | * @param s The session object 133 | * @param what Which features to check ? @see smb_session_supports_what 134 | * 135 | * @return 0 if the feature is not supported, something else otherwise 136 | */ 137 | int smb_session_supports(smb_session *s, int what); 138 | 139 | /** 140 | 141 | * @brief Get the last NT_STATUS 142 | * @details Valid only if a smb_ function returned the DSM_ERROR_NT error. 143 | * 144 | * @param s The session object 145 | */ 146 | uint32_t smb_session_get_nt_status(smb_session *s); 147 | 148 | 149 | #endif 150 | -------------------------------------------------------------------------------- /ThirdParty/libdsm/include/smb_share.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * __________________ _________ _____ _____ .__ ._. 3 | * \______ \______ \ / _____/ / \ / _ \ |__| ____ | | 4 | * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | | 5 | * | | \| ` \/ / Y \ / | | \ ___/ \| 6 | * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __ 7 | * \/ \/ \/ \/ )/ \/ \/ \/ 8 | * 9 | * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS 10 | * 11 | * Author: Julien 'Lta' BALLET 12 | * 13 | * liBDSM is released under LGPLv2.1 (or later) and is also available 14 | * under a commercial license. 15 | ***************************************************************************** 16 | * This program is free software; you can redistribute it and/or modify it 17 | * under the terms of the GNU Lesser General Public License as published by 18 | * the Free Software Foundation; either version 2.1 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU Lesser General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU Lesser General Public License 27 | * along with this program; if not, write to the Free Software Foundation, 28 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 29 | *****************************************************************************/ 30 | 31 | #ifndef __BDSM_SMB_SHARE_H_ 32 | #define __BDSM_SMB_SHARE_H_ 33 | 34 | #include "smb_session.h" 35 | #include "smb_file.h" 36 | 37 | /** 38 | * @file smb_share.h 39 | * @brief List and connect to SMB shares 40 | */ 41 | 42 | /** 43 | * @brief List the existing share of this sessions's machine 44 | * @details This function makes a RPC to the machine this session is currently 45 | * authenticated to and list all the existing shares of this machines. The share 46 | * starting with a $ are supposed to be system/hidden share. 47 | * 48 | * @param[in] s The session object 49 | * @param[out] list A pointer to an opaque share_list object. 50 | * @param[out] pointer to the number of elements in the list 51 | * 52 | * @return 0 on success or a DSM error code in case of error 53 | */ 54 | int smb_share_get_list(smb_session *s, smb_share_list *list, size_t *p_count); 55 | 56 | /** 57 | * @brief Get the number of share in the list 58 | * 59 | * @param list An opaque share list returned by smb_share_list() 60 | * @return The number of share in the opaque share_list object 61 | */ 62 | size_t smb_share_list_count(smb_share_list list); 63 | 64 | /** 65 | * @brief Get the name of the share in the list at the given index 66 | 67 | * @param list An opaque share list object 68 | * @param index The index of the returned item in the list 69 | * 70 | * @return The string has been decoded from UTF16 to you local encoding 71 | */ 72 | const char *smb_share_list_at(smb_share_list list, size_t index); 73 | 74 | /** 75 | * @brief Destroy an opaque share list object 76 | * 77 | * @param list The list to destroy. The object is not usable anymore afterward, 78 | * you can set it to 'NULL' 79 | */ 80 | void smb_share_list_destroy(smb_share_list list); 81 | 82 | /** 83 | * @brief Connects to a SMB share 84 | * @details Before being able to list/read files on a SMB file server, you have 85 | * to be connected to the share containing the files you want to read or 86 | * the directories you want to list 87 | * 88 | * @param s The session object 89 | * @param name The share name @see smb_share_list 90 | * @param tid The pointer to an opaque open share 91 | * @return 0 on success or a DSM error code in case of error 92 | */ 93 | int smb_tree_connect(smb_session *s, const char *name, smb_tid *tid); 94 | 95 | /** 96 | * @brief Disconnect from a share 97 | * @details UNIMPLEMENTED 98 | * 99 | * @return 0 on success or a DSM error code in case of error 100 | */ 101 | int smb_tree_disconnect(smb_session *s, smb_tid tid); 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /ThirdParty/libdsm/include/smb_stat.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * __________________ _________ _____ _____ .__ ._. 3 | * \______ \______ \ / _____/ / \ / _ \ |__| ____ | | 4 | * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | | 5 | * | | \| ` \/ / Y \ / | | \ ___/ \| 6 | * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __ 7 | * \/ \/ \/ \/ )/ \/ \/ \/ 8 | * 9 | * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS 10 | * 11 | * Author: Julien 'Lta' BALLET 12 | * 13 | * liBDSM is released under LGPLv2.1 (or later) and is also available 14 | * under a commercial license. 15 | ***************************************************************************** 16 | * This program is free software; you can redistribute it and/or modify it 17 | * under the terms of the GNU Lesser General Public License as published by 18 | * the Free Software Foundation; either version 2.1 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU Lesser General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU Lesser General Public License 27 | * along with this program; if not, write to the Free Software Foundation, 28 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 29 | *****************************************************************************/ 30 | 31 | /** 32 | * @file smb_stat.h 33 | * @brief File status / listing 34 | */ 35 | 36 | #ifndef __BDSM_SMB_STAT_H_ 37 | #define __BDSM_SMB_STAT_H_ 38 | 39 | #include "smb_defs.h" 40 | #include "smb_session.h" 41 | 42 | /// smb_stat_get() OP: Get file size 43 | #define SMB_STAT_SIZE 0 44 | /// smb_stat_get() OP: Get file allocation size (Size on disk) 45 | #define SMB_STAT_ALLOC_SIZE 1 46 | /// smb_stat_get() OP: 0 -> not a directory, != 0 -> directory 47 | #define SMB_STAT_ISDIR 2 48 | /// smb_stat_get() OP: Get file creation time 49 | #define SMB_STAT_CTIME 3 50 | /// smb_stat_get() OP: Get file last access time 51 | #define SMB_STAT_ATIME 4 52 | /// smb_stat_get() OP: Get file last write time 53 | #define SMB_STAT_WTIME 5 54 | /// smb_stat_get() OP: Get file last moditification time 55 | #define SMB_STAT_MTIME 6 56 | 57 | /** 58 | * @brief Returns infos about files matching a pattern 59 | * @details This functions uses the FIND_FIRST2 SMB operations to list files 60 | * matching a certain pattern. It's basically used to list folder contents 61 | * 62 | * @param s The session object 63 | * @param tid The share inside of which we want to find files obtained by 64 | * smb_tree_connect() 65 | * @param pattern The pattern to match files. '\\*' will list all the files at 66 | * the root of the share. '\\afolder\\*' will list all the files inside of the 67 | * 'afolder' directory. 68 | * @return An opaque list of smb_stat or NULL in case of error 69 | */ 70 | smb_stat_list smb_find(smb_session *s, smb_tid tid, const char *pattern); 71 | 72 | /** 73 | * @brief Get the status of a file from it's path inside of a share 74 | * 75 | * @param s The session object 76 | * @param tid The tree id of a share obtained by smb_tree_connect() 77 | * @param path The full path of the file relative to the root of the share 78 | * (e.g. '\\folder\\file.ext') 79 | * 80 | * @return An opaque smb_stat or NULL in case of error. You need to 81 | * destory this object with smb_stat_destroy after usage. 82 | */ 83 | smb_stat smb_fstat(smb_session *s, smb_tid tid, const char *path); 84 | 85 | /** 86 | * @brief Get the status of an open file from it's file descriptor 87 | * @details The file status will be those at the time of open 88 | * 89 | * @param s The session object 90 | * @param fd The smb_fd from which you want infos/status 91 | * 92 | * @return An opaque smb_stat or NULL in case of error. You don't own 93 | * this object memory, and then don't have to destory it 94 | */ 95 | smb_stat smb_stat_fd(smb_session *s, smb_fd fd); 96 | 97 | /** 98 | * @brief Clear a smb_stat object, reclaiming its memory 99 | * 100 | * @param stat A smb_stat object returned by smb_fstat. 101 | */ 102 | void smb_stat_destroy(smb_stat stat); 103 | 104 | /** 105 | * @brief Get the number of item in a smb_stat_list file info 106 | * 107 | * @param list The list you want the length of 108 | * @return The length of the list. It returns 0 if the list is invalid 109 | */ 110 | size_t smb_stat_list_count(smb_stat_list list); 111 | 112 | smb_stat smb_stat_list_next(smb_stat_list stat); 113 | /** 114 | * @brief Get the element at the given position. 115 | * 116 | * @param list A stat list 117 | * @param index The position of the element you want. 118 | * 119 | * @return An opaque smb_stat or NULL in case of error 120 | */ 121 | smb_stat smb_stat_list_at(smb_stat_list list, size_t index); 122 | 123 | /** 124 | * @brief Destroy and release a list of file stat returned by smb_find 125 | * 126 | * @param list The stat_list to free 127 | */ 128 | void smb_stat_list_destroy(smb_stat_list list); 129 | 130 | /** 131 | * @brief Get the name of the file from its status 132 | * 133 | * @param info A file status 134 | * @return A null-terminated string in you current locale encoding or NULL. 135 | */ 136 | const char *smb_stat_name(smb_stat info); 137 | 138 | /** 139 | * @brief Get a file attribute 140 | * @details This function is a getter that allow you to retrieve various 141 | * informations about a file on a smb_stat object. You can get its size, 142 | * various timestamps, etc. 143 | * 144 | * @param info The smb_stat object to get info from. 145 | * @param what This parameter tells the functions which information to get, can 146 | * be one of #SMB_STAT_SIZE, #SMB_STAT_ALLOC_SIZE, #SMB_STAT_ISDIR, 147 | * #SMB_STAT_CTIME, #SMB_STAT_ATIME, #SMB_STAT_MTIME, #SMB_STAT_WTIME. 148 | * 149 | * @return The meaning of the returned value depends on the 'what' parameter. 150 | * See each item documentation. 151 | */ 152 | uint64_t smb_stat_get(smb_stat info, int what); 153 | 154 | #endif 155 | -------------------------------------------------------------------------------- /ThirdParty/libdsm/include/smb_types.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * __________________ _________ _____ _____ .__ ._. 3 | * \______ \______ \ / _____/ / \ / _ \ |__| ____ | | 4 | * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | | 5 | * | | \| ` \/ / Y \ / | | \ ___/ \| 6 | * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __ 7 | * \/ \/ \/ \/ )/ \/ \/ \/ 8 | * 9 | * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS 10 | * 11 | * Author: Julien 'Lta' BALLET 12 | * 13 | * liBDSM is released under LGPLv2.1 (or later) and is also available 14 | * under a commercial license. 15 | ***************************************************************************** 16 | * This program is free software; you can redistribute it and/or modify it 17 | * under the terms of the GNU Lesser General Public License as published by 18 | * the Free Software Foundation; either version 2.1 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU Lesser General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU Lesser General Public License 27 | * along with this program; if not, write to the Free Software Foundation, 28 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 29 | *****************************************************************************/ 30 | 31 | /** 32 | * @file smb_types.h 33 | * @brief liBDSM types and structures 34 | */ 35 | 36 | #ifndef __BDSM_SMB_TYPES_H_ 37 | #define __BDSM_SMB_TYPES_H_ 38 | 39 | #include 40 | #include 41 | 42 | #define _FILE_OFFSET_BITS 64 43 | 44 | #include 45 | 46 | #if defined(__ANDROID__) 47 | # undef off_t 48 | # define off_t off64_t 49 | #endif 50 | /** 51 | * @struct smb_tid 52 | * @brief The id of a connection to a share within a session. 53 | */ 54 | typedef uint16_t smb_tid; 55 | 56 | /** 57 | * @struct smb_fid 58 | * @brief The id of a file within a share within a session. 59 | */ 60 | typedef uint16_t smb_fid; 61 | 62 | // Concatenation of the two above, representing a file inside of a session 63 | // First 4 bytes are the TreeID (smb_tid), last 4 are the File ID (FUID) 64 | // A map between smb_fd and smb_file is maintained inside each session 65 | /** @struct smb_fd 66 | * @brief SMB File descriptor, represents a file within a session. 67 | */ 68 | typedef uint32_t smb_fd; 69 | 70 | // An structure to store user credentials; 71 | // login:password@domain (also DOMAIN\login) 72 | typedef struct 73 | { 74 | char *domain; 75 | char *login; 76 | char *password; 77 | } smb_creds; 78 | 79 | /** 80 | * @brief An opaque data structure to represent a SMB Session. 81 | */ 82 | typedef struct smb_session smb_session; 83 | 84 | /** 85 | * @struct smb_share_list 86 | * @brief An opaque object representing the list of share of a SMB file server. 87 | */ 88 | typedef char **smb_share_list; 89 | 90 | /** 91 | * @brief An opaque data structure to represent file 92 | */ 93 | typedef struct smb_file smb_file; 94 | 95 | /** 96 | * @struct smb_stat_list 97 | * @brief An opaque structure containing a list of file status 98 | */ 99 | typedef smb_file *smb_stat_list; 100 | 101 | /** 102 | * @struct smb_stat 103 | * @brief An opaque structure containing info about a file 104 | */ 105 | typedef smb_file *smb_stat; 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /ThirdParty/libdsm/libdsm-iOS.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naxos/SMBClient/82dfd479c0f85aed4534a81c68cd4cb528dbfbe4/ThirdParty/libdsm/libdsm-iOS.a -------------------------------------------------------------------------------- /ThirdParty/libdsm/libdsm-tvOS.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naxos/SMBClient/82dfd479c0f85aed4534a81c68cd4cb528dbfbe4/ThirdParty/libdsm/libdsm-tvOS.a -------------------------------------------------------------------------------- /ThirdParty/libtasn1/include/libtasn1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002-2014 Free Software Foundation, Inc. 3 | * 4 | * This file is part of LIBTASN1. 5 | * 6 | * LIBTASN1 is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * LIBTASN1 is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with LIBTASN1; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 | * 02110-1301, USA 20 | * 21 | */ 22 | 23 | #ifndef LIBTASN1_H 24 | #define LIBTASN1_H 25 | 26 | #ifndef ASN1_API 27 | #if defined ASN1_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY 28 | #define ASN1_API __attribute__((__visibility__("default"))) 29 | #elif defined ASN1_BUILDING && defined _MSC_VER && ! defined ASN1_STATIC 30 | #define ASN1_API __declspec(dllexport) 31 | #elif defined _MSC_VER && ! defined ASN1_STATIC 32 | #define ASN1_API __declspec(dllimport) 33 | #else 34 | #define ASN1_API 35 | #endif 36 | #endif 37 | 38 | #include 39 | #include 40 | #include /* for FILE* */ 41 | 42 | #ifdef __cplusplus 43 | extern "C" 44 | { 45 | #endif 46 | 47 | #define ASN1_VERSION "4.8" 48 | 49 | #if defined(__GNUC__) && !defined(ASN1_INTERNAL_BUILD) 50 | # define _ASN1_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 51 | # if _ASN1_GCC_VERSION >= 30100 52 | # define _ASN1_GCC_ATTR_DEPRECATED __attribute__ ((__deprecated__)) 53 | # endif 54 | #endif 55 | 56 | #ifndef _ASN1_GCC_ATTR_DEPRECATED 57 | #define _ASN1_GCC_ATTR_DEPRECATED 58 | #endif 59 | 60 | /*****************************************/ 61 | /* Errors returned by libtasn1 functions */ 62 | /*****************************************/ 63 | #define ASN1_SUCCESS 0 64 | #define ASN1_FILE_NOT_FOUND 1 65 | #define ASN1_ELEMENT_NOT_FOUND 2 66 | #define ASN1_IDENTIFIER_NOT_FOUND 3 67 | #define ASN1_DER_ERROR 4 68 | #define ASN1_VALUE_NOT_FOUND 5 69 | #define ASN1_GENERIC_ERROR 6 70 | #define ASN1_VALUE_NOT_VALID 7 71 | #define ASN1_TAG_ERROR 8 72 | #define ASN1_TAG_IMPLICIT 9 73 | #define ASN1_ERROR_TYPE_ANY 10 74 | #define ASN1_SYNTAX_ERROR 11 75 | #define ASN1_MEM_ERROR 12 76 | #define ASN1_MEM_ALLOC_ERROR 13 77 | #define ASN1_DER_OVERFLOW 14 78 | #define ASN1_NAME_TOO_LONG 15 79 | #define ASN1_ARRAY_ERROR 16 80 | #define ASN1_ELEMENT_NOT_EMPTY 17 81 | 82 | /*************************************/ 83 | /* Constants used in asn1_visit_tree */ 84 | /*************************************/ 85 | #define ASN1_PRINT_NAME 1 86 | #define ASN1_PRINT_NAME_TYPE 2 87 | #define ASN1_PRINT_NAME_TYPE_VALUE 3 88 | #define ASN1_PRINT_ALL 4 89 | 90 | /*****************************************/ 91 | /* Constants returned by asn1_read_tag */ 92 | /*****************************************/ 93 | #define ASN1_CLASS_UNIVERSAL 0x00 /* old: 1 */ 94 | #define ASN1_CLASS_APPLICATION 0x40 /* old: 2 */ 95 | #define ASN1_CLASS_CONTEXT_SPECIFIC 0x80 /* old: 3 */ 96 | #define ASN1_CLASS_PRIVATE 0xC0 /* old: 4 */ 97 | #define ASN1_CLASS_STRUCTURED 0x20 98 | 99 | /*****************************************/ 100 | /* Constants returned by asn1_read_tag */ 101 | /*****************************************/ 102 | #define ASN1_TAG_BOOLEAN 0x01 103 | #define ASN1_TAG_INTEGER 0x02 104 | #define ASN1_TAG_SEQUENCE 0x10 105 | #define ASN1_TAG_SET 0x11 106 | #define ASN1_TAG_OCTET_STRING 0x04 107 | #define ASN1_TAG_BIT_STRING 0x03 108 | #define ASN1_TAG_UTCTime 0x17 109 | #define ASN1_TAG_GENERALIZEDTime 0x18 110 | #define ASN1_TAG_OBJECT_ID 0x06 111 | #define ASN1_TAG_ENUMERATED 0x0A 112 | #define ASN1_TAG_NULL 0x05 113 | #define ASN1_TAG_GENERALSTRING 0x1B 114 | #define ASN1_TAG_NUMERIC_STRING 0x12 115 | #define ASN1_TAG_IA5_STRING 0x16 116 | #define ASN1_TAG_TELETEX_STRING 0x14 117 | #define ASN1_TAG_PRINTABLE_STRING 0x13 118 | #define ASN1_TAG_UNIVERSAL_STRING 0x1C 119 | #define ASN1_TAG_BMP_STRING 0x1E 120 | #define ASN1_TAG_UTF8_STRING 0x0C 121 | #define ASN1_TAG_VISIBLE_STRING 0x1A 122 | 123 | /******************************************************/ 124 | /* Structure definition used for the node of the tree */ 125 | /* that represent an ASN.1 DEFINITION. */ 126 | /******************************************************/ 127 | 128 | typedef struct asn1_node_st asn1_node_st; 129 | 130 | typedef asn1_node_st *asn1_node; 131 | 132 | /* maximum number of characters of a name */ 133 | /* inside a file with ASN1 definitons */ 134 | #define ASN1_MAX_NAME_SIZE 64 135 | 136 | 137 | /*****************************************/ 138 | /* For the on-disk format of ASN.1 trees */ 139 | /*****************************************/ 140 | struct asn1_static_node_st 141 | { 142 | const char *name; /* Node name */ 143 | unsigned int type; /* Node type */ 144 | const void *value; /* Node value */ 145 | }; 146 | typedef struct asn1_static_node_st asn1_static_node; 147 | 148 | /* List of constants for field type of node_asn */ 149 | #define ASN1_ETYPE_INVALID 0 150 | #define ASN1_ETYPE_CONSTANT 1 151 | #define ASN1_ETYPE_IDENTIFIER 2 152 | #define ASN1_ETYPE_INTEGER 3 153 | #define ASN1_ETYPE_BOOLEAN 4 154 | #define ASN1_ETYPE_SEQUENCE 5 155 | #define ASN1_ETYPE_BIT_STRING 6 156 | #define ASN1_ETYPE_OCTET_STRING 7 157 | #define ASN1_ETYPE_TAG 8 158 | #define ASN1_ETYPE_DEFAULT 9 159 | #define ASN1_ETYPE_SIZE 10 160 | #define ASN1_ETYPE_SEQUENCE_OF 11 161 | #define ASN1_ETYPE_OBJECT_ID 12 162 | #define ASN1_ETYPE_ANY 13 163 | #define ASN1_ETYPE_SET 14 164 | #define ASN1_ETYPE_SET_OF 15 165 | #define ASN1_ETYPE_DEFINITIONS 16 166 | #define ASN1_ETYPE_CHOICE 18 167 | #define ASN1_ETYPE_IMPORTS 19 168 | #define ASN1_ETYPE_NULL 20 169 | #define ASN1_ETYPE_ENUMERATED 21 170 | #define ASN1_ETYPE_GENERALSTRING 27 171 | #define ASN1_ETYPE_NUMERIC_STRING 28 172 | #define ASN1_ETYPE_IA5_STRING 29 173 | #define ASN1_ETYPE_TELETEX_STRING 30 174 | #define ASN1_ETYPE_PRINTABLE_STRING 31 175 | #define ASN1_ETYPE_UNIVERSAL_STRING 32 176 | #define ASN1_ETYPE_BMP_STRING 33 177 | #define ASN1_ETYPE_UTF8_STRING 34 178 | #define ASN1_ETYPE_VISIBLE_STRING 35 179 | #define ASN1_ETYPE_UTC_TIME 36 180 | #define ASN1_ETYPE_GENERALIZED_TIME 37 181 | 182 | /* Flags used by asn1_delete_structure2() */ 183 | 184 | /* makes sure the values are zeroized prior to deinitialization */ 185 | #define ASN1_DELETE_FLAG_ZEROIZE 1 186 | 187 | /* Flags used by asn1_der_decoding2(). */ 188 | 189 | /* This flag would allow arbitrary data past the DER data */ 190 | #define ASN1_DECODE_FLAG_ALLOW_PADDING 1 191 | /* This flag would ensure that no BER decoding takes place */ 192 | #define ASN1_DECODE_FLAG_STRICT_DER (1<<1) 193 | 194 | 195 | struct asn1_data_node_st 196 | { 197 | const char *name; /* Node name */ 198 | const void *value; /* Node value */ 199 | unsigned int value_len; /* Node value size */ 200 | unsigned int type; /* Node value type (ASN1_ETYPE_*) */ 201 | }; 202 | typedef struct asn1_data_node_st asn1_data_node_st; 203 | 204 | /***********************************/ 205 | /* Fixed constants */ 206 | /***********************************/ 207 | 208 | 209 | /* maximum number of characters */ 210 | /* of a description message */ 211 | /* (null character included) */ 212 | #define ASN1_MAX_ERROR_DESCRIPTION_SIZE 128 213 | 214 | /***********************************/ 215 | /* Functions definitions */ 216 | /***********************************/ 217 | 218 | extern ASN1_API int 219 | asn1_parser2tree (const char *file, 220 | asn1_node * definitions, char *error_desc); 221 | 222 | extern ASN1_API int 223 | asn1_parser2array (const char *inputFileName, 224 | const char *outputFileName, 225 | const char *vectorName, char *error_desc); 226 | 227 | extern ASN1_API int 228 | asn1_array2tree (const asn1_static_node * array, 229 | asn1_node * definitions, char *errorDescription); 230 | 231 | extern ASN1_API void 232 | asn1_print_structure (FILE * out, asn1_node structure, 233 | const char *name, int mode); 234 | 235 | extern ASN1_API int 236 | asn1_create_element (asn1_node definitions, 237 | const char *source_name, asn1_node * element); 238 | 239 | extern ASN1_API int asn1_delete_structure (asn1_node * structure); 240 | 241 | extern ASN1_API int asn1_delete_structure2 (asn1_node * structure, unsigned int flags); 242 | 243 | extern ASN1_API int 244 | asn1_delete_element (asn1_node structure, const char *element_name); 245 | 246 | extern ASN1_API int 247 | asn1_write_value (asn1_node node_root, const char *name, 248 | const void *ivalue, int len); 249 | 250 | extern ASN1_API int 251 | asn1_read_value (asn1_node root, const char *name, 252 | void *ivalue, int *len); 253 | 254 | extern ASN1_API int 255 | asn1_read_value_type (asn1_node root, const char *name, 256 | void *ivalue, int *len, unsigned int *etype); 257 | 258 | extern ASN1_API int 259 | asn1_read_node_value (asn1_node node, asn1_data_node_st * data); 260 | 261 | extern ASN1_API int 262 | asn1_number_of_elements (asn1_node element, const char *name, int *num); 263 | 264 | extern ASN1_API int 265 | asn1_der_coding (asn1_node element, const char *name, 266 | void *ider, int *len, char *ErrorDescription); 267 | 268 | extern ASN1_API int 269 | asn1_der_decoding2 (asn1_node *element, const void *ider, 270 | int *max_ider_len, unsigned int flags, 271 | char *errorDescription); 272 | 273 | extern ASN1_API int 274 | asn1_der_decoding (asn1_node * element, const void *ider, 275 | int len, char *errorDescription); 276 | 277 | /* Do not use. Use asn1_der_decoding() instead. */ 278 | extern ASN1_API int 279 | asn1_der_decoding_element (asn1_node * structure, 280 | const char *elementName, 281 | const void *ider, int len, 282 | char *errorDescription) _ASN1_GCC_ATTR_DEPRECATED; 283 | 284 | extern ASN1_API int 285 | asn1_der_decoding_startEnd (asn1_node element, 286 | const void *ider, int len, 287 | const char *name_element, 288 | int *start, int *end); 289 | 290 | extern ASN1_API int 291 | asn1_expand_any_defined_by (asn1_node definitions, asn1_node * element); 292 | 293 | extern ASN1_API int 294 | asn1_expand_octet_string (asn1_node definitions, 295 | asn1_node * element, 296 | const char *octetName, const char *objectName); 297 | 298 | extern ASN1_API int 299 | asn1_read_tag (asn1_node root, const char *name, 300 | int *tagValue, int *classValue); 301 | 302 | extern ASN1_API const char *asn1_find_structure_from_oid (asn1_node 303 | definitions, 304 | const char 305 | *oidValue); 306 | 307 | extern ASN1_API const char *asn1_check_version (const char *req_version); 308 | 309 | extern ASN1_API const char *asn1_strerror (int error); 310 | 311 | extern ASN1_API void asn1_perror (int error); 312 | 313 | #define ASN1_MAX_TAG_SIZE 4 314 | #define ASN1_MAX_LENGTH_SIZE 9 315 | #define ASN1_MAX_TL_SIZE (ASN1_MAX_TAG_SIZE+ASN1_MAX_LENGTH_SIZE) 316 | extern ASN1_API long 317 | asn1_get_length_der (const unsigned char *der, int der_len, int *len); 318 | 319 | extern ASN1_API long 320 | asn1_get_length_ber (const unsigned char *ber, int ber_len, int *len); 321 | 322 | extern ASN1_API void 323 | asn1_length_der (unsigned long int len, unsigned char *der, int *der_len); 324 | 325 | /* Other utility functions. */ 326 | 327 | extern ASN1_API 328 | int asn1_decode_simple_der (unsigned int etype, const unsigned char *der, 329 | unsigned int der_len, 330 | const unsigned char **str, 331 | unsigned int *str_len); 332 | 333 | extern ASN1_API 334 | int asn1_decode_simple_ber (unsigned int etype, const unsigned char *der, 335 | unsigned int der_len, 336 | unsigned char **str, 337 | unsigned int *str_len, 338 | unsigned int *ber_len); 339 | 340 | extern ASN1_API int 341 | asn1_encode_simple_der (unsigned int etype, const unsigned char *str, 342 | unsigned int str_len, unsigned char *tl, 343 | unsigned int *tl_len); 344 | 345 | extern ASN1_API asn1_node 346 | asn1_find_node (asn1_node pointer, const char *name); 347 | 348 | extern ASN1_API int 349 | asn1_copy_node (asn1_node dst, const char *dst_name, 350 | asn1_node src, const char *src_name); 351 | extern ASN1_API asn1_node 352 | asn1_dup_node (asn1_node src, const char *src_name); 353 | 354 | /* Internal and low-level DER utility functions. */ 355 | 356 | extern ASN1_API int 357 | asn1_get_tag_der (const unsigned char *der, int der_len, 358 | unsigned char *cls, int *len, unsigned long *tag); 359 | 360 | extern ASN1_API void 361 | asn1_octet_der (const unsigned char *str, int str_len, 362 | unsigned char *der, int *der_len); 363 | 364 | extern ASN1_API int 365 | asn1_get_octet_der (const unsigned char *der, int der_len, 366 | int *ret_len, unsigned char *str, 367 | int str_size, int *str_len); 368 | 369 | extern ASN1_API void asn1_bit_der (const unsigned char *str, int bit_len, 370 | unsigned char *der, int *der_len); 371 | 372 | extern ASN1_API int 373 | asn1_get_bit_der (const unsigned char *der, int der_len, 374 | int *ret_len, unsigned char *str, 375 | int str_size, int *bit_len); 376 | 377 | extern ASN1_API int 378 | asn1_get_object_id_der (const unsigned char *der, 379 | int der_len, int *ret_len, 380 | char *str, int str_size); 381 | 382 | /* Compatibility types */ 383 | 384 | typedef int asn1_retCode; /* type returned by libtasn1 functions */ 385 | 386 | #define node_asn_struct asn1_node_st 387 | #define node_asn asn1_node_st 388 | #define ASN1_TYPE asn1_node 389 | #define ASN1_TYPE_EMPTY NULL 390 | 391 | #define static_struct_asn asn1_static_node_st 392 | #define ASN1_ARRAY_TYPE asn1_static_node 393 | #define asn1_static_node_t asn1_static_node 394 | 395 | #define node_data_struct asn1_data_node_st 396 | #define ASN1_DATA_NODE asn1_data_node_st 397 | 398 | #ifdef __cplusplus 399 | } 400 | #endif 401 | 402 | #endif /* LIBTASN1_H */ 403 | -------------------------------------------------------------------------------- /ThirdParty/libtasn1/libtasn1-iOS.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naxos/SMBClient/82dfd479c0f85aed4534a81c68cd4cb528dbfbe4/ThirdParty/libtasn1/libtasn1-iOS.a -------------------------------------------------------------------------------- /ThirdParty/libtasn1/libtasn1-tvOS.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naxos/SMBClient/82dfd479c0f85aed4534a81c68cd4cb528dbfbe4/ThirdParty/libtasn1/libtasn1-tvOS.a --------------------------------------------------------------------------------