I need to add an ip address to the Trust firewall zone. Wrote the code, trying to use the library. However, when calling the DBUS call method, the code in a strange way hangs up and the output is only via controller. I could only find the inserts of the library itself in the codebook. Unfortunately, I have so far more exploiter than the developer, do not scold much. I give my code as is. This is a prototype. Stop after e03. Thanks to everyone who responds, I have been fighting for work for a week now.

package main import ( "fmt" "log" "net" "github.com/godbus/dbus" ) func AEnableIp (ipin string) { ``` ipaddr := net.ParseIP(ipin) stipaddr := fmt.Sprintf("%s", ipaddr) var CallMethod string = "org.fedoraproject.FirewallD1.config.zone.addSource string:'"+stipaddr+"'" fmt.Println(CallMethod) log.Println("e01") //использую как dbus.SystemBusPrivate так и dbus.SystemBus conn, err := dbus.SystemBusPrivate() //conn, err := dbus.SystemBus() log.Println(conn) if err != nil { panic(err) } log.Println("e02") obj := conn.Object("org.fedoraproject.FirewallD1", "/org/fedoraproject/FirewallD1/config/zone/9") log.Println("e03") call := obj.Call(CallMethod, 0) log.Println("e04") if call.Err != nil { panic(call.Err) } ``` } func main() { var ipset string = "192.168.200.200" AEnableIp(ipset) } 
  • It may freeze due to the fact that you are trying to connect to the system bus, and you do not have rights. Try running code from sudo - Bleser
  • Oh, if only. full root, sudo, tried everything. Immediately run dbus-send - everything passes. There is a thought to transfer to processing the dbus-send utility, but I wanted a beautiful solution without crutches. - Vlad
  • Does anyone even work with System Dbus or is it a dead technology and should you not get involved with it? - Vlad
  • I decided to rewrite the method with the call of this utility on the dbus-send mechanism from my session. So it's not about rights. While I’m going to rewrite for the utility, then maybe I’ll draw up a separate lib, taking the method from C of the dbus project that dbus-send uses - Vlad
  • Hello. I managed to figure it out. First, the call to the Private System Bus is created with authentication and the hello function about which the documentation is written. Secondly, the transfer of the ip address takes place as a separate argument like this: = obj.Call (CallMethod, 0, stipaddr) where the last argument to stipaddr is the ip address to be transferred. Good luck. - Vlad

1 answer 1

Hello. I managed to figure it out. First, the call to the Private System Bus is created with authentication and the hello function about which the documentation is written. Looks like this:

 conn, err := dbus.SystemBusPrivate () if err != nil { panic(err) } if err = conn.Auth(nil); err != nil { conn.Close() conn = nil return } if err = conn.Hello(); err != nil { conn.Close() conn = nil } 

Secondly, the transfer of the ip address takes place as a separate argument like this: = obj.Call (CallMethod, 0, stipaddr) where the last argument to stipaddr is the ip address to be transferred. Good luck.