github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/dokan/winacl/debug.go (about)

     1  // Copyright 2016 Keybase Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build debug
     6  // +build debug
     7  
     8  package winacl
     9  
    10  import (
    11  	"fmt"
    12  	"strings"
    13  )
    14  
    15  func (si SecurityInformation) String() string {
    16  	var cf collectFlags
    17  	var raw = uint32(si)
    18  	cf.AddDense(raw, []string{
    19  		"OWNER", "GROUP", "DACL", "SACL", "LABEL", "ATTRIBUTE", "SCOPE",
    20  	})
    21  	cf.AddFlag(raw, 0x10000, "BACKUP")
    22  	cf.AddFlag(raw, 0x80000000, "PROTECTED_DACL")
    23  	cf.AddFlag(raw, 0x40000000, "PROTECTED_SACL")
    24  	cf.AddFlag(raw, 0x20000000, "UNPROTECTED_DACL")
    25  	cf.AddFlag(raw, 0x10000000, "UNPROTECTED_SACL")
    26  
    27  	return cf.String()
    28  }
    29  
    30  func (sd *SecurityDescriptor) String() string {
    31  	var cf collectFlags
    32  	cf.AddDense(uint32(sd.ptr.Control), []string{
    33  		"OWNER_DEFAULTED", "GROUP_DEFAULTED",
    34  		"DACL_PRESENT", "DACL_DEFAULTED",
    35  		"SACL_PRESENT", "SACL_DEFAULTED",
    36  		"", "",
    37  		"DACL_AUTO_INHERIT_REQ", "SACL_AUTO_INHERIT_REQ",
    38  		"DACL_AUTO_INHERITED", "SACL_AUTO_INHERITED",
    39  		"DACL_PROTECTED", "SACL_PROTECTED",
    40  		"RM_CONTROL_VALID", "SELF_RELATIVE",
    41  	})
    42  	var res = cf.String()
    43  	if sd.ptr.Revision != 1 {
    44  		res += "INVALID-REVISION"
    45  	}
    46  	if sd.ptr.Sbz1 != 0 {
    47  		res += "NON-ZERO-SBZ1"
    48  	}
    49  	return fmt.Sprintf("%s offsets (o,g,s,d) = (%d, %d, %d, %d)", res,
    50  		sd.ptr.OwnerOffset, sd.ptr.GroupOffset,
    51  		sd.ptr.SaclOffset, sd.ptr.DaclOffset,
    52  	)
    53  }
    54  
    55  type collectFlags struct {
    56  	parts []string
    57  }
    58  
    59  func (c *collectFlags) String() string {
    60  	return strings.Join(c.parts, "|")
    61  }
    62  
    63  func (c *collectFlags) AddDense(val uint32, sslice []string) {
    64  	for i, s := range sslice {
    65  		if val&(1<<uint32(i)) != 0 {
    66  			c.parts = append(c.parts, s)
    67  		}
    68  	}
    69  }
    70  
    71  func (c *collectFlags) AddFlag(val uint32, flag uint32, s string) {
    72  	if val&flag != 0 {
    73  		c.parts = append(c.parts, s)
    74  	}
    75  }