]> Cypherpunks.ru repositories - nncp.git/commitdiff
Ability to forcefully override umask
authorSergey Matveev <stargrave@stargrave.org>
Fri, 15 Nov 2019 14:45:14 +0000 (17:45 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 15 Nov 2019 16:12:39 +0000 (19:12 +0300)
19 files changed:
doc/cfg.texi
doc/news.ru.texi
doc/news.texi
src/cfg.go
src/cmd/nncp-bundle/main.go
src/cmd/nncp-call/main.go
src/cmd/nncp-caller/main.go
src/cmd/nncp-cfgnew/main.go
src/cmd/nncp-check/main.go
src/cmd/nncp-daemon/main.go
src/cmd/nncp-exec/main.go
src/cmd/nncp-file/main.go
src/cmd/nncp-freq/main.go
src/cmd/nncp-reass/main.go
src/cmd/nncp-rm/main.go
src/cmd/nncp-stat/main.go
src/cmd/nncp-toss/main.go
src/cmd/nncp-xfer/main.go
src/ctx.go

index 46e3f5eca5a9bd3322250ea843e748606e729836..0aca8f9d5694b5a953289f895ef6fc8dd2192262 100644 (file)
@@ -7,6 +7,8 @@ Example @url{https://hjson.org/, Hjson} configuration file:
 {
   spool: /var/spool/nncp
   log: /var/spool/nncp/log
+  umask: "022"
+
   notify: {
     file: {
       from: nncp@localhost
@@ -17,6 +19,7 @@ Example @url{https://hjson.org/, Hjson} configuration file:
       to: user+freq@example.com
     }
   }
+
   self: {
     id: TIJQL...2NGIA
     exchpub: CYVGQ...PSEWQ
@@ -26,6 +29,7 @@ Example @url{https://hjson.org/, Hjson} configuration file:
     noiseprv: D62XU...NKYPA
     noisepub: KIBKK...ESM7Q
   }
+
   neigh: {
     self: {
       id: TIJQL...2NGIA
@@ -78,6 +82,10 @@ Example @url{https://hjson.org/, Hjson} configuration file:
 directory. @strong{log} field contains an absolute path to @ref{Log,
 log} file.
 
+Non-empty optional @strong{umask} will force all invoked commands to
+override their umask to specified octal mask. Useful for using with
+@ref{Shared spool, shared spool directories}.
+
 @anchor{CfgNotify}
 @strong{notify} section contains notification settings for successfully
 tossed file and freq packets. Corresponding @strong{from} and
@@ -191,3 +199,22 @@ List of @ref{Call, call configuration}s. Can be omitted if
 @ref{nncp-caller} won't be used to call that node.
 
 @end table
+
+@menu
+* Shared spool directory: Shared spool.
+@end menu
+
+@node Shared spool
+@section Shared spool directory
+
+If you want to share single spool directory with multiple grouped Unix
+users, then you can @command{setgid} it and assure that umask is group
+friendly. For convenience you can set @option{umask} globally for
+invoked NNCP commands in the configuration file. For example:
+
+@verbatim
+$ chgrp nncp /usr/local/etc/nncp.hjson /var/spool/nncp
+$ chmod g+r /usr/local/etc/nncp.hjson
+$ chmod g+rwxs /var/spool/nncp
+$ echo 'umask: "007"' >> /usr/local/etc/nncp.hjson
+@end verbatim
index 2b09a72069252f4f4ea55eafbb7723f776e4b24e..828a3cd152d221ff7f86b6e5f9868b0f0d1a578b 100644 (file)
@@ -29,6 +29,10 @@ pipe вызов сторонней команды.
 Дубликаты имён файлов имеют суффикс @file{.CTR}, вместо @file{CTR},
 чтобы избежать возможных коллизий с @file{.nncp.chunkCTR}.
 
+@item
+Возможность переопределить umask процесса через опцию конфигурационного
+файла.
+
 @item
 По умолчанию файлы и директории создаются с 666/777 правами доступа,
 позволяя управлять ими @command{umask}-ом.
index 5cc2e6f04f2908fda4beba61c35116156cb87d2a..b57c5ea567e3d07c1724ce98c58b2613c39a17d1 100644 (file)
@@ -31,6 +31,9 @@ behaviour.
 Duplicate filenames have @file{.CTR} suffix, instead of @file{CTR}, to
 avoid possible collisions with @file{.nncp.chunkCTR}.
 
+@item
+Ability to override process umask through configuration file option.
+
 @item
 Files and directories are created with 666/777 permissions by default,
 allowing control with @command{umask}.
index deebd1981d8d5c3cb80417e5ab1ebcbf40d68032..a4450e0ae9ff7877d4961322b8abc0bd90d41942 100644 (file)
@@ -24,6 +24,7 @@ import (
        "log"
        "os"
        "path"
+       "strconv"
 
        "github.com/gorhill/cronexpr"
        "github.com/hjson/hjson-go"
@@ -97,8 +98,10 @@ type NotifyJSON struct {
 }
 
 type CfgJSON struct {
-       Spool  string      `json:"spool"`
-       Log    string      `json:"log"`
+       Spool string `json:"spool"`
+       Log   string `json:"log"`
+       Umask string `json:"umask",omitempty`
+
        Notify *NotifyJSON `json:"notify,omitempty"`
 
        Self  *NodeOurJSON        `json:"self"`
@@ -397,12 +400,22 @@ func CfgParse(data []byte) (*Ctx, error) {
        if !path.IsAbs(logPath) {
                return nil, errors.New("Log path must be absolute")
        }
+       var umaskForce *int
+       if cfgJSON.Umask != "" {
+               r, err := strconv.ParseUint(cfgJSON.Umask, 8, 16)
+               if err != nil {
+                       return nil, err
+               }
+               rInt := int(r)
+               umaskForce = &rInt
+       }
        ctx := Ctx{
-               Spool:   spoolPath,
-               LogPath: logPath,
-               Self:    self,
-               Neigh:   make(map[NodeId]*Node, len(cfgJSON.Neigh)),
-               Alias:   make(map[string]*NodeId),
+               Spool:      spoolPath,
+               LogPath:    logPath,
+               UmaskForce: umaskForce,
+               Self:       self,
+               Neigh:      make(map[NodeId]*Node, len(cfgJSON.Neigh)),
+               Alias:      make(map[string]*NodeId),
        }
        if cfgJSON.Notify != nil {
                if cfgJSON.Notify.File != nil {
index c8f87d81153c7e806ea8dde0d60cda4700f36e17..4f5bca1b9d72890c25f33bc6069626c48e4a9c7c 100644 (file)
@@ -102,6 +102,8 @@ func main() {
                nodeIds[*node.Id] = struct{}{}
        }
 
+       ctx.Umask()
+
        sds := nncp.SDS{}
        if *doTx {
                sds["xx"] = string(nncp.TTx)
index 07deec1ca4f893e88a379ced3c6dc745f6be4bcf..dde658ff3a7b938b9037e2d6403b9c2814a6cbab 100644 (file)
@@ -139,6 +139,7 @@ func main() {
                }
        }
 
+       ctx.Umask()
        if !ctx.CallNode(
                node,
                addrs,
index 3f9ddca8d4ca07577ac00e8856626cdf6d224873..e97ea8555f4e6d91dda10d5500f529cde4c59fdc 100644 (file)
@@ -66,6 +66,7 @@ func main() {
        if ctx.Self == nil {
                log.Fatalln("Config lacks private keys")
        }
+       ctx.Umask()
 
        var nodes []*nncp.Node
        if flag.NArg() > 0 {
index a9bea4f4b63c737efc9fc0414423c286eb3d8345..c7bb14ef571d2653141a4d7abd0f8672495974bb 100644 (file)
@@ -68,6 +68,7 @@ func main() {
     noiseprv: %s
     noisepub: %s
   }
+
   neigh: {
     self: {
       id: %s
@@ -99,6 +100,8 @@ func main() {
   spool: %s
   # Path to log file
   log: %s
+  # Enforce specified umask usage
+  # umask: "022"
 
   # Enable notification email sending
   # notify: {
@@ -122,6 +125,7 @@ func main() {
     noiseprv: %s
     noisepub: %s
   }
+
   neigh: {
     self: {
       # You should give public keys below to your neighbours
index bf48638d97b411e2ebf19e9a8725ecd7f8d9b8e5..186357ee3d458698d8993aa4fb664e34df6741db 100644 (file)
@@ -60,6 +60,7 @@ func main() {
        if err != nil {
                log.Fatalln("Error during initialization:", err)
        }
+       ctx.Umask()
 
        var nodeOnly *nncp.Node
        if *nodeRaw != "" {
index 0f7e460e401016165956c50987fcac6dd70026dc..897dc06f1d181f8c72614ad9279c08884158ee2b 100644 (file)
@@ -124,6 +124,7 @@ func main() {
        if ctx.Self == nil {
                log.Fatalln("Config lacks private keys")
        }
+       ctx.Umask()
 
        if *inetd {
                os.Stderr.Close()
index 39de8ab12a3f2fed180ecd2b89cdab763cfe8e07..54394e8863e99c786d5e76d2ae35023713f4d447 100644 (file)
@@ -86,6 +86,7 @@ func main() {
        }
 
        nncp.ViaOverride(*viaOverride, ctx, node)
+       ctx.Umask()
 
        if err = ctx.TxExec(
                node,
index 2e7933391cfbcf869aba109c4a9f4d40402a44c0..f3572ca04fc95f2b6a38aca6171324a92b9cfd71 100644 (file)
@@ -93,6 +93,7 @@ func main() {
        }
 
        nncp.ViaOverride(*viaOverride, ctx, node)
+       ctx.Umask()
 
        var minSize int64
        if *argMinSize < 0 {
index 08adaf9c794932e50d68c193f31db24d10057ab2..4332ff1ca1906ad02db2b7d47521ffe4d3cbf1d4 100644 (file)
@@ -93,6 +93,7 @@ func main() {
        }
 
        nncp.ViaOverride(*viaOverride, ctx, node)
+       ctx.Umask()
 
        var dst string
        if flag.NArg() == 2 {
index 7ca8db871339230addc337fc22b32c32491102d0..77a5f139a879c986387aa877fc55638a98368fb4 100644 (file)
@@ -317,6 +317,8 @@ func main() {
                os.Exit(1)
        }
 
+       ctx.Umask()
+
        if flag.NArg() > 0 {
                if process(ctx, flag.Arg(0), *keep, *dryRun, *stdout, *dumpMeta) {
                        return
index 74aa24c14c72b0502419fe5509d2184d44b9862b..765ed4942660655fe8c252cafcd0bbe3548446e8 100644 (file)
@@ -74,6 +74,7 @@ func main() {
        if err != nil {
                log.Fatalln("Error during initialization:", err)
        }
+       ctx.Umask()
 
        if *doTmp {
                err = filepath.Walk(filepath.Join(ctx.Spool, "tmp"), func(path string, info os.FileInfo, err error) error {
index a173707f2386e4334d56e826b99b44b036929f4d..c03745a5241e9361ae83626386af2e9dbb067f35 100644 (file)
@@ -77,6 +77,7 @@ func main() {
        }
        sort.Strings(nodeNames)
 
+       ctx.Umask()
        var node *nncp.Node
        for _, nodeName := range nodeNames {
                node = nodeNameToNode[nodeName]
index 010d93ed6fad85e3e2e056cc51ca62268585f8f2..3f31ff9fb41d27adcff5d930e224e42a83b909e6 100644 (file)
@@ -85,6 +85,8 @@ func main() {
                }
        }
 
+       ctx.Umask()
+
 Cycle:
        isBad := false
        for nodeId, node := range ctx.Neigh {
index db390088cdd9062dae3f5113fa55ebe6742e6b51..fde11174e9c19297aa573a8af86cd4c64d8848c3 100644 (file)
@@ -90,6 +90,7 @@ func main() {
                }
        }
 
+       ctx.Umask()
        selfPath := filepath.Join(flag.Arg(0), ctx.SelfId.String())
        isBad := false
        var dir *os.File
index 0030c706d71fdb35c7edddeda60a63f0a42b627a..3793bbba6b6808b3c3b9d0630a788682b54e615b 100644 (file)
@@ -25,6 +25,7 @@ import (
        "path/filepath"
 
        "golang.org/x/sys/unix"
+       "syscall"
 )
 
 type Ctx struct {
@@ -35,6 +36,7 @@ type Ctx struct {
 
        Spool      string
        LogPath    string
+       UmaskForce *int
        Quiet      bool
        Debug      bool
        NotifyFile *FromToJSON
@@ -113,3 +115,9 @@ func (ctx *Ctx) IsEnoughSpace(want int64) bool {
        }
        return int64(s.Bavail)*int64(s.Bsize) > want
 }
+
+func (ctx *Ctx) Umask() {
+       if ctx.UmaskForce != nil {
+               syscall.Umask(*ctx.UmaskForce)
+       }
+}