MCPcopy
hub / github.com/OpenListTeam/OpenList / AuthUser

Method AuthUser

server/ftp.go:115–160  ·  view source on GitHub ↗
(cc ftpserver.ClientContext, user, pass string)

Source from the content-addressed store, hash-verified

113}
114
115func (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
162func (d *FtpMainDriver) GetTLSConfig() (*tls.Config, error) {
163 if d.tlsConfig == nil {

Callers

nothing calls this directly

Calls 14

ValidateRawPasswordMethod · 0.95
CanFTPAccessMethod · 0.95
GetGuestFunction · 0.92
GetUserByNameFunction · 0.92
GetBoolFunction · 0.92
HandleLdapLoginFunction · 0.92
CanFTPAccessFunction · 0.92
GetIntFunction · 0.92
NewAferoAdapterFunction · 0.92
tryLdapLoginAndRegisterFunction · 0.85
GetMethod · 0.65
DelMethod · 0.65

Tested by

no test coverage detected