Privilege encoding

MoneyWorks 6 and earlier encodes privileges as a string where each privilege is represented by a character in the range 32-130. This is kind of wasteful and also unfortunate, because the last 3 codes are not valid utf-8. Making them valid utf-8 would break the privilege encoding.

In v7, privileges are automatically transmogrified to a bitmap that is stored as a 64 nybble hexadecimal string (the hex encoding is done longword-wise little-endian, which happens to be the MoneyWorks network protocol byte order).

<login>
   <lastmodifiedtime>20110131133003</lastmodifiedtime>
   <initials>rmd</initials>
   <name>Rowan</name>
   <privileges>
      ffffffefffffffffffffffff0000008000000000000000000000000000000000
   </privileges>
</login>

If you are testing privileges, the recommended way of doing so is using the Allowed() function, which takes a textual privilege name. If you're decoding the privileges field yourself, you will need to decode the hexadecimal string to test the bit you want.


on HexDecodeSample
    let bit = 0
    let hex = "ffffffefffffffffffffffff0000008000000000000000000000000000000000"
    foreach word in (0length(hex) / 8)
        let hexlong = ""
        foreach byte in (03)
            let hexlong = hexlong + mid(hexword * 8 + (4 - byte) * 2 - 12)
        endfor
        let w = val("#" + hexlong)
        let mask = #80000000
        foreach bitoff in (031)
            if TestFlags(wmask)
                syslog("bit " + bit + " set")
            else
                syslog("bit " + bit + " NOT set")
            endif
            let mask = mask / 2
            let bit = bit + 1
        endfor
    endfor
end
Posted in Database, Esoterica | Comments Off on Privilege encoding