Make the auth stuff simpler - just have a password

This commit is contained in:
Russell Smith 2015-09-12 19:35:08 -07:00
parent 623794feb2
commit d48cb8c773
5 changed files with 12 additions and 10 deletions

View File

@ -22,6 +22,7 @@ LedisDB now supports multiple different databases as backends.
+ Replication to guarantee data safety. + Replication to guarantee data safety.
+ Supplies tools to load, dump, and repair database. + Supplies tools to load, dump, and repair database.
+ Supports cluster, use [xcodis](https://github.com/siddontang/xcodis) + Supports cluster, use [xcodis](https://github.com/siddontang/xcodis)
+ Authentication (though, not via http)
## Build and Install ## Build and Install

View File

@ -91,7 +91,6 @@ type SnapshotConfig struct {
type Config struct { type Config struct {
m sync.RWMutex `toml:"-"` m sync.RWMutex `toml:"-"`
AuthEnabled bool `toml:"auth_enabled"`
AuthPassword string `toml:"auth_password"` AuthPassword string `toml:"auth_password"`
FileName string `toml:"-"` FileName string `toml:"-"`
@ -171,8 +170,7 @@ func NewConfigDefault() *Config {
cfg.SlaveOf = "" cfg.SlaveOf = ""
cfg.Readonly = false cfg.Readonly = false
// Disable Auth by default // Disable Auth by default, by setting password to blank
cfg.AuthEnabled = false
cfg.AuthPassword = "" cfg.AuthPassword = ""
// default databases number // default databases number

View File

@ -25,6 +25,9 @@ slaveof = ""
# for readonly mode, only replication and flushall can write # for readonly mode, only replication and flushall can write
readonly = false readonly = false
# Authentication (for non-http connections). Connect, then use the AUTH command to authenticate.
# auth_password = "russellwashere"
# Choose which backend storage to use, now support: # Choose which backend storage to use, now support:
# #
# leveldb # leveldb

View File

@ -37,11 +37,7 @@ func startTestAppAuth(password string) {
cfg.Addr = "127.0.0.1:20000" cfg.Addr = "127.0.0.1:20000"
cfg.HttpAddr = "127.0.0.1:20001" cfg.HttpAddr = "127.0.0.1:20001"
cfg.AuthPassword = password
if password != "" {
cfg.AuthPassword = password
cfg.AuthEnabled = true
}
os.RemoveAll(cfg.DataDir) os.RemoveAll(cfg.DataDir)

View File

@ -88,7 +88,7 @@ func newClient(app *App) *client {
c.app = app c.app = app
c.ldb = app.ldb c.ldb = app.ldb
c.is_authed = false || !app.cfg.AuthEnabled c.is_authed = false || c.authEnabled()
c.db, _ = app.ldb.Select(0) //use default db c.db, _ = app.ldb.Select(0) //use default db
return c return c
@ -98,6 +98,10 @@ func (c *client) close() {
} }
func (c *client) authEnabled() bool {
return len(c.app.cfg.AuthPassword) > 0
}
func (c *client) perform() { func (c *client) perform() {
var err error var err error
@ -107,7 +111,7 @@ func (c *client) perform() {
err = ErrEmptyCommand err = ErrEmptyCommand
} else if exeCmd, ok := regCmds[c.cmd]; !ok { } else if exeCmd, ok := regCmds[c.cmd]; !ok {
err = ErrNotFound err = ErrNotFound
} else if c.app.cfg.AuthEnabled && !c.is_authed && c.cmd != "auth" { } else if c.authEnabled() && !c.is_authed && c.cmd != "auth" {
err = ErrNotAuthenticated err = ErrNotAuthenticated
} else { } else {
// if c.db.IsTransaction() { // if c.db.IsTransaction() {