MCPcopy
hub / github.com/rclone/rclone / SetConfigPassword

Function SetConfigPassword

fs/config/crypt.go:272–316  ·  view source on GitHub ↗

SetConfigPassword will set the configKey to the hash of the password. If the length of the password is zero after trimming+normalization, an error is returned.

(password string)

Source from the content-addressed store, hash-verified

270// the password. If the length of the password is
271// zero after trimming+normalization, an error is returned.
272func SetConfigPassword(password string) error {
273 password, err := checkPassword(password)
274 if err != nil {
275 return err
276 }
277 // Create SHA256 has of the password
278 sha := sha256.New()
279 _, err = sha.Write([]byte("[" + password + "][rclone-config]"))
280 if err != nil {
281 return err
282 }
283 configKey = sha.Sum(nil)
284 if PassConfigKeyForDaemonization {
285 tempFile, err := os.CreateTemp("", "rclone")
286 if err != nil {
287 return fmt.Errorf("cannot create temp file to store configKey: %w", err)
288 }
289 _, err = tempFile.WriteString(obscure.MustObscure(string(configKey)))
290 if err != nil {
291 errRemove := os.Remove(tempFile.Name())
292 if errRemove != nil {
293 return fmt.Errorf("error writing configKey to temp file and also error deleting it: %w", err)
294 }
295 return fmt.Errorf("error writing configKey to temp file: %w", err)
296 }
297 err = tempFile.Close()
298 if err != nil {
299 errRemove := os.Remove(tempFile.Name())
300 if errRemove != nil {
301 return fmt.Errorf("error closing temp file with configKey and also error deleting it: %w", err)
302 }
303 return fmt.Errorf("error closing temp file with configKey: %w", err)
304 }
305 fs.Debugf(nil, "saving configKey to temp file")
306 err = os.Setenv("_RCLONE_CONFIG_KEY_FILE", tempFile.Name())
307 if err != nil {
308 errRemove := os.Remove(tempFile.Name())
309 if errRemove != nil {
310 return fmt.Errorf("unable to set environment variable _RCLONE_CONFIG_KEY_FILE and unable to delete the temp file: %w", err)
311 }
312 return fmt.Errorf("unable to set environment variable _RCLONE_CONFIG_KEY_FILE: %w", err)
313 }
314 }
315 return nil
316}
317
318// ClearConfigPassword sets the current the password to empty
319func ClearConfigPassword() {

Callers 7

TestConfigLoadEncryptedFunction · 0.92
rcConfigPasswordFunction · 0.85
DecryptFunction · 0.85
getConfigPasswordFunction · 0.85
changeConfigPasswordFunction · 0.85
hashedKeyCompareFunction · 0.85
TestPasswordFunction · 0.85

Calls 11

MustObscureFunction · 0.92
DebugfFunction · 0.92
checkPasswordFunction · 0.85
WriteMethod · 0.65
WriteStringMethod · 0.65
RemoveMethod · 0.65
NameMethod · 0.65
CloseMethod · 0.65
SetenvMethod · 0.65
SumMethod · 0.45
ErrorfMethod · 0.45

Tested by 3

TestConfigLoadEncryptedFunction · 0.74
hashedKeyCompareFunction · 0.68
TestPasswordFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…