@ -70,6 +70,17 @@ var (
_ convert . Conversion = & SSPIConfig { }
_ convert . Conversion = & SSPIConfig { }
)
)
// jsonUnmarshalIgnoreErroneousBOM - due to a bug in xorm (see https://gitea.com/xorm/xorm/pulls/1957) - it's
// possible that a Blob may gain an unwanted prefix of 0xff 0xfe.
func jsonUnmarshalIgnoreErroneousBOM ( bs [ ] byte , v interface { } ) error {
json := jsoniter . ConfigCompatibleWithStandardLibrary
err := json . Unmarshal ( bs , & v )
if err != nil && len ( bs ) > 2 && bs [ 0 ] == 0xff && bs [ 1 ] == 0xfe {
err = json . Unmarshal ( bs [ 2 : ] , & v )
}
return err
}
// LDAPConfig holds configuration for LDAP login source.
// LDAPConfig holds configuration for LDAP login source.
type LDAPConfig struct {
type LDAPConfig struct {
* ldap . Source
* ldap . Source
@ -77,8 +88,7 @@ type LDAPConfig struct {
// FromDB fills up a LDAPConfig from serialized format.
// FromDB fills up a LDAPConfig from serialized format.
func ( cfg * LDAPConfig ) FromDB ( bs [ ] byte ) error {
func ( cfg * LDAPConfig ) FromDB ( bs [ ] byte ) error {
json := jsoniter . ConfigCompatibleWithStandardLibrary
err := jsonUnmarshalIgnoreErroneousBOM ( bs , & cfg )
err := json . Unmarshal ( bs , & cfg )
if err != nil {
if err != nil {
return err
return err
}
}
@ -119,8 +129,7 @@ type SMTPConfig struct {
// FromDB fills up an SMTPConfig from serialized format.
// FromDB fills up an SMTPConfig from serialized format.
func ( cfg * SMTPConfig ) FromDB ( bs [ ] byte ) error {
func ( cfg * SMTPConfig ) FromDB ( bs [ ] byte ) error {
json := jsoniter . ConfigCompatibleWithStandardLibrary
return jsonUnmarshalIgnoreErroneousBOM ( bs , cfg )
return json . Unmarshal ( bs , cfg )
}
}
// ToDB exports an SMTPConfig to a serialized format.
// ToDB exports an SMTPConfig to a serialized format.
@ -137,8 +146,7 @@ type PAMConfig struct {
// FromDB fills up a PAMConfig from serialized format.
// FromDB fills up a PAMConfig from serialized format.
func ( cfg * PAMConfig ) FromDB ( bs [ ] byte ) error {
func ( cfg * PAMConfig ) FromDB ( bs [ ] byte ) error {
json := jsoniter . ConfigCompatibleWithStandardLibrary
return jsonUnmarshalIgnoreErroneousBOM ( bs , cfg )
return json . Unmarshal ( bs , & cfg )
}
}
// ToDB exports a PAMConfig to a serialized format.
// ToDB exports a PAMConfig to a serialized format.
@ -159,8 +167,7 @@ type OAuth2Config struct {
// FromDB fills up an OAuth2Config from serialized format.
// FromDB fills up an OAuth2Config from serialized format.
func ( cfg * OAuth2Config ) FromDB ( bs [ ] byte ) error {
func ( cfg * OAuth2Config ) FromDB ( bs [ ] byte ) error {
json := jsoniter . ConfigCompatibleWithStandardLibrary
return jsonUnmarshalIgnoreErroneousBOM ( bs , cfg )
return json . Unmarshal ( bs , cfg )
}
}
// ToDB exports an SMTPConfig to a serialized format.
// ToDB exports an SMTPConfig to a serialized format.
@ -180,8 +187,7 @@ type SSPIConfig struct {
// FromDB fills up an SSPIConfig from serialized format.
// FromDB fills up an SSPIConfig from serialized format.
func ( cfg * SSPIConfig ) FromDB ( bs [ ] byte ) error {
func ( cfg * SSPIConfig ) FromDB ( bs [ ] byte ) error {
json := jsoniter . ConfigCompatibleWithStandardLibrary
return jsonUnmarshalIgnoreErroneousBOM ( bs , cfg )
return json . Unmarshal ( bs , cfg )
}
}
// ToDB exports an SSPIConfig to a serialized format.
// ToDB exports an SSPIConfig to a serialized format.