]> Cypherpunks.ru repositories - gocheese.git/commitdiff
Passwords listing ability
authorSergey Matveev <stargrave@stargrave.org>
Fri, 24 Sep 2021 11:33:15 +0000 (14:33 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 24 Sep 2021 11:33:15 +0000 (14:33 +0300)
doc/passwords.texi
main.go
passwd.go

index d3d9ad4039b09092c0e5969020a8f230359e3850..4660c522afb8495c3ee559e80f4f954c751cf3ea 100644 (file)
@@ -3,11 +3,12 @@
 
 Password authentication is required for packages uploading. Passwords
 are dynamically changed through the FIFO file. You have to create it and
 
 Password authentication is required for packages uploading. Passwords
 are dynamically changed through the FIFO file. You have to create it and
-use in @option{-passwd} option:
+use in @option{-passwd} option. Optionally, to list currently present
+logins use another FIFO and @option{-passwd-list} option:
 
 @example
 
 @example
-$ mkfifo passwd
-$ gocheese -passwd passwd ...
+$ mkfifo passwd passwd-list
+$ gocheese -passwd passwd -passwd-list passwd-list ...
 @end example
 
 Then you must feed it newline-separated records in following format:
 @end example
 
 Then you must feed it newline-separated records in following format:
diff --git a/main.go b/main.go
index 12a325a93435af81d330f2ff9e844e31da891e13..46be5259f871b8bb6fb6fa1f9926608f6443bbd2 100644 (file)
--- a/main.go
+++ b/main.go
@@ -105,8 +105,9 @@ var (
        pypiURL      = flag.String("pypi", "https://pypi.org/simple/", "Upstream (PyPI) URL")
        pypiCertHash = flag.String("pypi-cert-hash", "", "Authenticate upstream by its X.509 certificate's SPKI SHA256 hash")
 
        pypiURL      = flag.String("pypi", "https://pypi.org/simple/", "Upstream (PyPI) URL")
        pypiCertHash = flag.String("pypi-cert-hash", "", "Authenticate upstream by its X.509 certificate's SPKI SHA256 hash")
 
-       passwdPath  = flag.String("passwd", "", "Path to FIFO for upload authentication")
-       passwdCheck = flag.Bool("passwd-check", false, "Run password checker")
+       passwdPath     = flag.String("passwd", "", "Path to FIFO for upload authentication")
+       passwdListPath = flag.String("passwd-list", "", "Path to FIFO for login listing")
+       passwdCheck    = flag.Bool("passwd-check", false, "Run password checker")
 
        logTimestamped = flag.Bool("log-timestamped", false, "Prepend timestmap to log messages")
        fsck           = flag.Bool("fsck", false, "Check integrity of all packages (errors are in stderr)")
 
        logTimestamped = flag.Bool("log-timestamped", false, "Prepend timestmap to log messages")
        fsck           = flag.Bool("fsck", false, "Check integrity of all packages (errors are in stderr)")
@@ -306,7 +307,11 @@ func main() {
        if *passwdPath != "" {
                go func() {
                        for {
        if *passwdPath != "" {
                go func() {
                        for {
-                               fd, err := os.OpenFile(*passwdPath, os.O_RDONLY, os.FileMode(0666))
+                               fd, err := os.OpenFile(
+                                       *passwdPath,
+                                       os.O_RDONLY,
+                                       os.FileMode(0666),
+                               )
                                if err != nil {
                                        log.Fatalln(err)
                                }
                                if err != nil {
                                        log.Fatalln(err)
                                }
@@ -315,6 +320,22 @@ func main() {
                        }
                }()
        }
                        }
                }()
        }
+       if *passwdListPath != "" {
+               go func() {
+                       for {
+                               fd, err := os.OpenFile(
+                                       *passwdListPath,
+                                       os.O_WRONLY|os.O_APPEND,
+                                       os.FileMode(0666),
+                               )
+                               if err != nil {
+                                       log.Fatalln(err)
+                               }
+                               passwdLister(fd)
+                               fd.Close()
+                       }
+               }()
+       }
 
        if (*tlsCert != "" && *tlsKey == "") || (*tlsCert == "" && *tlsKey != "") {
                log.Fatalln("Both -tls-cert and -tls-key are required")
 
        if (*tlsCert != "" && *tlsKey == "") || (*tlsCert == "" && *tlsKey != "") {
                log.Fatalln("Both -tls-cert and -tls-key are required")
index 1a32f70269b16f2d2de2b103b7b542025387144a..a93fbc9e145c7fde84c16d789c0c2efabd334037 100644 (file)
--- a/passwd.go
+++ b/passwd.go
@@ -91,3 +91,15 @@ func passwdReader(fd *os.File) bool {
        }
        return isGood
 }
        }
        return isGood
 }
+
+func passwdLister(fd *os.File) {
+       PasswordsM.RLock()
+       logins := make([]string, 0, len(Passwords))
+       for login := range Passwords {
+               logins = append(logins, login)
+       }
+       PasswordsM.RUnlock()
+       for _, login := range logins {
+               fd.WriteString(login + "\n")
+       }
+}