(cc ftpserver.ClientContext, user, pass string)
| 113 | } |
| 114 | |
| 115 | func (d *FtpMainDriver) AuthUser(cc ftpserver.ClientContext, user, pass string) (ftpserver.ClientDriver, error) { |
| 116 | ip := cc.RemoteAddr().String() |
| 117 | count, ok := model.LoginCache.Get(ip) |
| 118 | if ok && count >= model.DefaultMaxAuthRetries { |
| 119 | model.LoginCache.Expire(ip, model.DefaultLockDuration) |
| 120 | return nil, errors.New("Too many unsuccessful sign-in attempts have been made using an incorrect username or password, Try again later.") |
| 121 | } |
| 122 | var userObj *model.User |
| 123 | var err error |
| 124 | if user == "anonymous" || user == "guest" { |
| 125 | userObj, err = op.GetGuest() |
| 126 | if err != nil { |
| 127 | return nil, err |
| 128 | } |
| 129 | } else { |
| 130 | userObj, err = op.GetUserByName(user) |
| 131 | if err == nil { |
| 132 | err = userObj.ValidateRawPassword(pass) |
| 133 | if err != nil && setting.GetBool(conf.LdapLoginEnabled) && userObj.AllowLdap { |
| 134 | err = common.HandleLdapLogin(user, pass) |
| 135 | } |
| 136 | } else if setting.GetBool(conf.LdapLoginEnabled) && model.CanFTPAccess(int32(setting.GetInt(conf.LdapDefaultPermission, 0))) { |
| 137 | userObj, err = tryLdapLoginAndRegister(user, pass) |
| 138 | } |
| 139 | if err != nil { |
| 140 | model.LoginCache.Set(ip, count+1) |
| 141 | return nil, err |
| 142 | } |
| 143 | } |
| 144 | if userObj.Disabled || !userObj.CanFTPAccess() { |
| 145 | model.LoginCache.Set(ip, count+1) |
| 146 | return nil, errors.New("user is not allowed to access via FTP") |
| 147 | } |
| 148 | model.LoginCache.Del(ip) |
| 149 | |
| 150 | ctx := context.Background() |
| 151 | ctx = context.WithValue(ctx, conf.UserKey, userObj) |
| 152 | if user == "anonymous" || user == "guest" { |
| 153 | ctx = context.WithValue(ctx, conf.MetaPassKey, pass) |
| 154 | } else { |
| 155 | ctx = context.WithValue(ctx, conf.MetaPassKey, "") |
| 156 | } |
| 157 | ctx = context.WithValue(ctx, conf.ClientIPKey, ip) |
| 158 | ctx = context.WithValue(ctx, conf.ProxyHeaderKey, d.proxyHeader) |
| 159 | return ftp.NewAferoAdapter(ctx), nil |
| 160 | } |
| 161 | |
| 162 | func (d *FtpMainDriver) GetTLSConfig() (*tls.Config, error) { |
| 163 | if d.tlsConfig == nil { |
nothing calls this directly
no test coverage detected