PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/wfx/samba/src/libsmbclient.pas

https://bitbucket.org/xeningem/dc_fork
Pascal | 149 lines | 105 code | 17 blank | 27 comment | 2 complexity | db62c77ef6f3648479b410dfa7c6db36 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause, GPL-3.0, MIT, GPL-2.0, AGPL-1.0, LGPL-2.1
  1. unit libsmbclient;
  2. {$mode delphi}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Unix, BaseUnix, UnixType;
  7. const
  8. SMBC_WORKGROUP = 1;
  9. SMBC_SERVER = 2;
  10. SMBC_FILE_SHARE = 3;
  11. SMBC_PRINTER_SHARE = 4;
  12. SMBC_COMMS_SHARE = 5;
  13. SMBC_IPC_SHARE = 6;
  14. SMBC_DIR = 7;
  15. SMBC_FILE = 8;
  16. SMBC_LINK = 9;
  17. const
  18. SMBC_DOS_MODE_READONLY = $01;
  19. SMBC_DOS_MODE_HIDDEN = $02;
  20. SMBC_DOS_MODE_SYSTEM = $04;
  21. SMBC_DOS_MODE_VOLUME_ID = $08;
  22. SMBC_DOS_MODE_DIRECTORY = $10;
  23. SMBC_DOS_MODE_ARCHIVE = $20;
  24. type
  25. (**@ingroup structure
  26. * Structure that represents a directory entry.
  27. *
  28. *)
  29. psmbc_dirent = ^smbc_dirent;
  30. smbc_dirent = record
  31. (** Type of entity.
  32. SMBC_WORKGROUP=1,
  33. SMBC_SERVER=2,
  34. SMBC_FILE_SHARE=3,
  35. SMBC_PRINTER_SHARE=4,
  36. SMBC_COMMS_SHARE=5,
  37. SMBC_IPC_SHARE=6,
  38. SMBC_DIR=7,
  39. SMBC_FILE=8,
  40. SMBC_LINK=9,*)
  41. smbc_type: LongWord;
  42. (** Length of this smbc_dirent in bytes
  43. *)
  44. dirlen: LongWord;
  45. (** The length of the comment string in bytes (does not include
  46. * null terminator)
  47. *)
  48. commentlen: LongWord;
  49. (** Points to the null terminated comment string
  50. *)
  51. comment: PAnsiChar;
  52. (** The length of the name string in bytes (does not include
  53. * null terminator)
  54. *)
  55. namelen: LongWord;
  56. (** Points to the null terminated name string
  57. *)
  58. name: array[0..0] of AnsiChar;
  59. end;
  60. smbc_get_auth_data_fn = procedure(server, share: PAnsiChar;
  61. wg: PAnsiChar; wglen: LongInt;
  62. un: PAnsiChar; unlen: LongInt;
  63. pw: PAnsiChar; pwlen: LongInt); cdecl;
  64. smbc_init_fn = function (fn: smbc_get_auth_data_fn; debug: LongInt): LongInt; cdecl;
  65. smbc_open_fn = function(furl: PAnsiChar; flags: LongInt; mode: mode_t): LongInt; cdecl;
  66. smbc_read_fn = function(fd: LongInt; buf: Pointer; bufsize: size_t): ssize_t; cdecl;
  67. smbc_write_fn = function(fd: LongInt; buf: Pointer; bufsize: size_t): ssize_t; cdecl;
  68. smbc_lseek_fn = function(fd: LongInt; offset: off_t; whence: LongInt): off_t; cdecl;
  69. smbc_close_fn = function(fd: LongInt): LongInt; cdecl;
  70. smbc_unlink_fn = function(furl: PAnsiChar): LongInt; cdecl;
  71. smbc_rename_fn = function(ourl: PAnsiChar; nurl: PAnsiChar): LongInt; cdecl;
  72. smbc_opendir_fn = function(durl: PAnsiChar): LongInt; cdecl;
  73. smbc_closedir_fn = function(dh: LongInt): LongInt; cdecl;
  74. smbc_readdir_fn = function(dh: LongInt): psmbc_dirent; cdecl;
  75. smbc_mkdir_fn = function(durl: PAnsiChar; mode: mode_t): LongInt; cdecl;
  76. smbc_rmdir_fn = function(durl: PAnsiChar): LongInt; cdecl;
  77. smbc_stat_fn = function(url: PAnsiChar; st: PStat): LongInt; cdecl;
  78. smbc_getxattr_fn = function(url, name: PAnsiChar; value: Pointer; size: size_t): LongInt; cdecl;
  79. smbc_setxattr_fn = function(url, name: PAnsiChar; value: Pointer; size: size_t; flags: LongInt): LongInt; cdecl;
  80. smbc_utimes_fn = function(url: PAnsiChar; tbuf: ptimeval): LongInt; cdecl;
  81. var
  82. smbc_init: smbc_init_fn;
  83. smbc_open: smbc_open_fn;
  84. smbc_read: smbc_read_fn;
  85. smbc_write: smbc_write_fn;
  86. smbc_lseek: smbc_lseek_fn;
  87. smbc_close: smbc_close_fn;
  88. smbc_unlink: smbc_unlink_fn;
  89. smbc_rename: smbc_rename_fn;
  90. smbc_opendir: smbc_opendir_fn;
  91. smbc_closedir: smbc_closedir_fn;
  92. smbc_readdir: smbc_readdir_fn;
  93. smbc_mkdir: smbc_mkdir_fn;
  94. smbc_rmdir: smbc_rmdir_fn;
  95. smbc_stat: smbc_stat_fn;
  96. smbc_getxattr: smbc_getxattr_fn;
  97. smbc_setxattr: smbc_setxattr_fn;
  98. smbc_utimes: smbc_utimes_fn;
  99. function LoadSambaLibrary: Boolean;
  100. implementation
  101. uses dynlibs;
  102. var
  103. hSamba: TLibHandle = 0;
  104. function LoadSambaLibrary: Boolean;
  105. begin
  106. if (hSamba = 0) then
  107. begin
  108. hSamba:= LoadLibrary('libsmbclient.so.0');
  109. if (hSamba <> 0) then
  110. begin
  111. @smbc_init:= GetProcAddress(hSamba, 'smbc_init');
  112. @smbc_opendir:= GetProcAddress(hSamba, 'smbc_opendir');
  113. @smbc_readdir:= GetProcAddress(hSamba, 'smbc_readdir');
  114. @smbc_closedir:= GetProcAddress(hSamba, 'smbc_closedir');
  115. @smbc_mkdir:= GetProcAddress(hSamba, 'smbc_mkdir');
  116. @smbc_rmdir:= GetProcAddress(hSamba, 'smbc_rmdir');
  117. @smbc_open:= GetProcAddress(hSamba, 'smbc_open');
  118. @smbc_read:= GetProcAddress(hSamba, 'smbc_read');
  119. @smbc_write:= GetProcAddress(hSamba, 'smbc_write');
  120. @smbc_lseek:= GetProcAddress(hSamba, 'smbc_lseek');
  121. @smbc_close:= GetProcAddress(hSamba, 'smbc_close');
  122. @smbc_unlink:= GetProcAddress(hSamba, 'smbc_unlink');
  123. @smbc_rename:= GetProcAddress(hSamba, 'smbc_rename');
  124. @smbc_stat:= GetProcAddress(hSamba, 'smbc_stat');
  125. @smbc_getxattr:= GetProcAddress(hSamba, 'smbc_getxattr');
  126. @smbc_setxattr:= GetProcAddress(hSamba, 'smbc_setxattr');
  127. @smbc_utimes:= GetProcAddress(hSamba, 'smbc_utimes');
  128. end;
  129. end;
  130. Result:= (hSamba <> 0);
  131. end;
  132. end.