github.com/iDigitalFlame/xmt@v0.5.4/device/local/unix_crypt.go (about)

     1  //go:build !windows && !js && !ios && !darwin && crypt
     2  // +build !windows,!js,!ios,!darwin,crypt
     3  
     4  // Copyright (C) 2020 - 2023 iDigitalFlame
     5  //
     6  // This program is free software: you can redistribute it and/or modify
     7  // it under the terms of the GNU General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // any later version.
    10  //
    11  // This program is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU General Public License
    17  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    18  //
    19  
    20  package local
    21  
    22  import (
    23  	"os"
    24  	"strings"
    25  
    26  	"github.com/iDigitalFlame/xmt/data"
    27  	"github.com/iDigitalFlame/xmt/util/crypt"
    28  )
    29  
    30  func release() map[string]string {
    31  	var (
    32  		b      = crypt.Get(92) // /etc
    33  		f, err = os.OpenFile(b, 0, 0)
    34  	)
    35  	if err != nil {
    36  		return nil
    37  	}
    38  	e, err := f.Readdirnames(0)
    39  	if f.Close(); err != nil || len(e) == 0 {
    40  		return nil
    41  	}
    42  	var (
    43  		m = make(map[string]string)
    44  		s = crypt.Get(93) // release
    45  	)
    46  	for i := range e {
    47  		if e[i] != s && !strings.Contains(e[i], s) {
    48  			continue
    49  		}
    50  		for _, v := range data.ReadSplit(b+string(os.PathSeparator)+e[i], "\n") {
    51  			x := strings.IndexByte(v, '=')
    52  			if x < 1 || len(v)-x < 2 {
    53  				continue
    54  			}
    55  			c, s := len(v)-1, x+1
    56  			for ; c > x && v[c] == '"'; c-- {
    57  			}
    58  			for ; s < c && v[s] == '"'; s++ {
    59  			}
    60  			m[strings.ToUpper(v[:x])] = v[s : c+1]
    61  		}
    62  	}
    63  	return m
    64  }