@@ -55,6 +55,7 @@ type SambaShare struct {
5555 ReadOnly string `json:"read_only"`
5656 ForceUser string `json:"force_user"`
5757 ForceGroup string `json:"force_group"`
58+ Anonymous bool `json:"anonymous"`
5859}
5960
6061type SambaSharePathAccount struct {
@@ -283,22 +284,6 @@ func (s *samba) generateConf() {
283284 continue
284285 }
285286
286- shareUser , sharePwd , err := s .getUser (item .PasswordMd5 )
287- if err != nil {
288- klog .Errorf ("samba decode user error: %v, data: %s, id: %s, name: %s, owner: %s" , err , item .PasswordMd5 , item .ID , item .Name , item .Owner )
289- continue
290- }
291-
292- if err := s .commands .CreateGroup (item .Owner , "" ); err != nil {
293- klog .Errorf ("samba create group %s error: %v" , item .Owner , err )
294- return
295- }
296-
297- if err := s .commands .CreateUser (shareUser , sharePwd , item .Owner ); err != nil {
298- klog .Errorf ("samba create user %s error: %v" , shareUser , err )
299- return
300- }
301-
302287 fPath := fmt .Sprintf ("/%s/%s%s" , item .FileType , item .Extend , item .Path )
303288 fp , err := models .CreateFileParam (item .Owner , fPath )
304289 if err != nil {
@@ -312,11 +297,35 @@ func (s *samba) generateConf() {
312297 return
313298 }
314299
315- if item .Permission > 1 {
316- if err := s .commands .SetAcl (shareUser , item .Owner , "-m" , "rwx" , fileUri + fp .Path ); err != nil {
317- klog .Errorf ("samba setfacl error: %v" , err )
300+ var anonymous bool
301+ var shareUser , sharePwd string
302+ if item .PasswordMd5 != "" {
303+ shareUser , sharePwd , err = s .getUser (item .PasswordMd5 )
304+ if err != nil {
305+ klog .Errorf ("samba decode user error: %v, data: %s, id: %s, name: %s, owner: %s" , err , item .PasswordMd5 , item .ID , item .Name , item .Owner )
306+ continue
307+ }
308+
309+ if err := s .commands .CreateGroup (item .Owner , "" ); err != nil {
310+ klog .Errorf ("samba create group %s error: %v" , item .Owner , err )
311+ return
312+ }
313+
314+ if err := s .commands .CreateUser (shareUser , sharePwd , item .Owner ); err != nil {
315+ klog .Errorf ("samba create user %s error: %v" , shareUser , err )
318316 return
319317 }
318+
319+ if item .Permission > 1 {
320+ if err := s .commands .SetAcl (shareUser , item .Owner , "-m" , "rwx" , fileUri + fp .Path ); err != nil {
321+ klog .Errorf ("samba setfacl error: %v" , err )
322+ return
323+ }
324+ }
325+ } else {
326+ // anonymous
327+ anonymous = true
328+ s .commands .SetAnonymousPermission (item .Owner , fileUri + fp .Path )
320329 }
321330
322331 w , r := s .formatPrivilege (item .Permission )
@@ -330,6 +339,7 @@ func (s *samba) generateConf() {
330339 ReadOnly : r ,
331340 ForceUser : shareUser ,
332341 ForceGroup : item .Owner ,
342+ Anonymous : anonymous ,
333343 }
334344 shares .Paths = append (shares .Paths , smbShare )
335345 }
@@ -474,11 +484,14 @@ func (s *samba) recoverSharedOwner(sharedPaths []string) {
474484 continue
475485 }
476486
477- if err := s .commands .SetAcl (smb .User , smb .Owner , "-x" , "" , uri + m .Path ); err != nil { // remove acl
478- klog .Errorf ("samba recover, setfacl remove error: %v" , err )
479- return
487+ if smb .User != "" {
488+ if err := s .commands .SetAcl (smb .User , smb .Owner , "-x" , "" , uri + m .Path ); err != nil { // remove acl
489+ klog .Errorf ("samba recover, setfacl remove error: %v" , err )
490+ return
491+ }
492+
493+ s .commands .DeleteUser ([]string {smb .User })
480494 }
481495
482- s .commands .DeleteUser ([]string {smb .User })
483496 }
484497}
0 commit comments