Skip to content
This repository was archived by the owner on May 27, 2023. It is now read-only.

Commit fd289d7

Browse files
add patch for set/get exec map function
1 parent 2898c62 commit fd289d7

File tree

2 files changed

+61
-20
lines changed

2 files changed

+61
-20
lines changed

container/container.go

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const (
3333
)
3434

3535
var (
36-
ELFOP = []string{"add_allow_priv", "remove_allow_priv", "add_deny_priv", "remove_deny_priv", "add_map", "remove_map"}
36+
ELFOP = []string{"add_allow_priv", "remove_allow_priv", "add_deny_priv", "remove_deny_priv", "add_map", "remove_map", "add_exec", "remove_exec"}
3737
LD = []string{"/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2", "/lib/ld.so", "/lib64/ld-linux-x86-64.so.2", "/lib/x86_64-linux-gnu/ld-linux-x86-64.so.1", "/lib64/ld-linux-x86-64.so.1", "/lib/ld-linux.so.2", "/lib/ld-linux.so.1"}
3838
LD_LIBRARY_PATH_DEFAULT = []string{"lib", "lib64", "lib/x86_64-linux-gnu", "usr/lib/x86_64-linux-gnu", "usr/lib", "usr/local/lib", "usr/lib64", "usr/local/lib64"}
3939
CACHE_FOLDER = []string{"/var/cache/apt/archives"}
@@ -713,11 +713,12 @@ func Get(id string, name string) *Error {
713713

714714
if err == nil {
715715
if _, ok := sys.Containers[id]; ok {
716-
fmt.Println(fmt.Sprintf("|%-s|%-30s|%-20s|%-20s|%-10s|", "ContainerID", "PROGRAM", "ALLOW_PRIVILEGES", "DENY_PRIVILEGES", "REMAP"))
716+
fmt.Println(fmt.Sprintf("|%-s|%-30s|%-20s|%-20s|%-10s|%-20s|", "ContainerID", "PROGRAM", "ALLOW_PRIVILEGES", "DENY_PRIVILEGES", "REMAP", "ExecMap"))
717717
a_val, _ := getPrivilege(id, name, sys.MemcachedPid, true)
718718
d_val, _ := getPrivilege(id, name, sys.MemcachedPid, false)
719719
m_val, _ := getMap(id, name, sys.MemcachedPid)
720-
fmt.Println(fmt.Sprintf("|%-s|%-30s|%-20s|%-20s|%-10s|", id, name, a_val, d_val, m_val))
720+
e_val, _ := getExec(id, name, sys.MemcachedPid)
721+
fmt.Println(fmt.Sprintf("|%-s|%-30s|%-20s|%-20s|%-10s|%-20s|", id, name, a_val, d_val, m_val, e_val))
721722
} else {
722723
cerr := ErrNew(ErrNExist, fmt.Sprintf("conatiner with id: %s doesn't exist", id))
723724
return cerr
@@ -744,6 +745,13 @@ func Set(id string, tp string, name string, value string) *Error {
744745
if _, vok := v.(map[string]interface{}); vok {
745746
tp = strings.ToLower(strings.TrimSpace(tp))
746747
switch tp {
748+
case ELFOP[6], ELFOP[7]:
749+
{
750+
err := setExec(id, tp, name, value, sys.MemcachedPid)
751+
if err != nil {
752+
return err
753+
}
754+
}
747755
case ELFOP[4], ELFOP[5]:
748756
{
749757
err := setMap(id, tp, name, value, sys.MemcachedPid)
@@ -2324,7 +2332,7 @@ func CommonDelete(name string, permernant bool) *Error {
23242332
return err
23252333
}
23262334

2327-
func Expose(id string, path string, name string) *Error {
2335+
func Expose(id string, ipath string, name string) *Error {
23282336
currdir, err := GetConfigDir()
23292337
if err != nil {
23302338
return err
@@ -2345,11 +2353,11 @@ func Expose(id string, path string, name string) *Error {
23452353
if err != nil {
23462354
return err
23472355
}
2348-
if !strings.Contains(con.ExposeExe, path) {
2356+
if !strings.Contains(con.ExposeExe, ipath) {
23492357
if con.ExposeExe == "" {
2350-
con.ExposeExe = path
2358+
con.ExposeExe = ipath
23512359
} else {
2352-
con.ExposeExe = fmt.Sprintf("%s:%s", con.ExposeExe, path)
2360+
con.ExposeExe = fmt.Sprintf("%s:%s", con.ExposeExe, ipath)
23532361
}
23542362
}
23552363

@@ -2371,8 +2379,11 @@ func Expose(id string, path string, name string) *Error {
23712379
cerr := ErrNew(ferr, fmt.Sprintf("can not create exposed file %s", bdir))
23722380
return cerr
23732381
}
2374-
code := "#!/bin/bash\n" + os.Args[0] +
2375-
" resume " + id + " \"" + path + " " + "$@\"" +
2382+
2383+
ppath := fmt.Sprintf("%s/%s", currdir, os.Args[0])
2384+
ppath = path.Clean(ppath)
2385+
code := "#!/bin/bash\n" + ppath +
2386+
" resume " + id + " \"" + ipath + " " + "$@\"" +
23762387
"\n"
23772388

23782389
fmt.Fprintf(f, code)
@@ -3602,6 +3613,41 @@ func getPrivilege(id string, name string, server string, allow bool) (string, *E
36023613
return str, nil
36033614
}
36043615

3616+
func setExec(id, tp, name, value, server string) *Error {
3617+
mem, err := MInitServers(server)
3618+
if err != nil {
3619+
return err
3620+
}
3621+
3622+
if tp == ELFOP[6] {
3623+
err := mem.MUpdateStrValue(fmt.Sprintf("exec:%s:%s", id, name), value)
3624+
if err != nil {
3625+
return err
3626+
}
3627+
}
3628+
3629+
if tp == ELFOP[7] {
3630+
err := mem.MDeleteByKey(fmt.Sprintf("exec:%s:%s", id, name))
3631+
if err != nil {
3632+
return err
3633+
}
3634+
}
3635+
return nil
3636+
}
3637+
3638+
func getExec(id, name, server string) (string, *Error) {
3639+
mem, err := MInitServers(server)
3640+
if err != nil {
3641+
return "", err
3642+
}
3643+
3644+
str, err := mem.MGetStrValue(fmt.Sprintf("exec:%s:%s", id, name))
3645+
if err != nil {
3646+
return "", err
3647+
}
3648+
return str, nil
3649+
}
3650+
36053651
func setMap(id string, tp string, name string, value string, server string) *Error {
36063652
mem, err := MInitServers(server)
36073653
if err != nil {
@@ -3613,7 +3659,9 @@ func setMap(id string, tp string, name string, value string, server string) *Err
36133659
if err != nil {
36143660
return err
36153661
}
3616-
} else {
3662+
}
3663+
3664+
if tp == ELFOP[5] {
36173665
err := mem.MDeleteByKey(fmt.Sprintf("map:%s:%s", id, name))
36183666
if err != nil {
36193667
return err

main.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -899,12 +899,6 @@ func main() {
899899
},
900900

901901
Run: func(cmd *cobra.Command, args []string) {
902-
if !strings.Contains(SetVal, ":") {
903-
LOGGER.WithFields(logrus.Fields{
904-
"value": SetVal,
905-
}).Fatal("the program value you input does not have ':', the format should be 'file1:replace_file1;file2:replace_file2'")
906-
return
907-
}
908902
err := Set(SetId, SetType, SetProg, SetVal)
909903
if err != nil {
910904
LOGGER.Fatal(err.Error())
@@ -919,12 +913,11 @@ func main() {
919913
}
920914
setCmd.Flags().StringVarP(&SetId, "id", "i", "", "required(container id, you can get the id by command 'lpmx list')")
921915
setCmd.MarkFlagRequired("id")
922-
setCmd.Flags().StringVarP(&SetType, "type", "t", "", "required('add_map','remove_map')")
916+
setCmd.Flags().StringVarP(&SetType, "type", "t", "", "required('add_map','remove_map','add_exec', 'remove_exec')")
923917
setCmd.MarkFlagRequired("type")
924-
setCmd.Flags().StringVarP(&SetProg, "name", "n", "", "required(should be the name of libc 'system calls wrapper')")
918+
setCmd.Flags().StringVarP(&SetProg, "name", "n", "", "required(should be the name of libc 'system calls wrapper' or mapped program path)")
925919
setCmd.MarkFlagRequired("name")
926-
setCmd.Flags().StringVarP(&SetVal, "value", "v", "", "required(value(file1:replace_file1;file2:repalce_file2;)) ")
927-
setCmd.MarkFlagRequired("value")
920+
setCmd.Flags().StringVarP(&SetVal, "value", "v", "", "required in add mode(value(file1:replace_file1;file2:repalce_file2;) or a mapped path) while optional in remove mode")
928921

929922
var uninstallCmd = &cobra.Command{
930923
Use: "uninstall",

0 commit comments

Comments
 (0)