update to latest c sdk/tunneler sdk. more debug messages. backup config file before saving state in case of crash.

This commit is contained in:
dovholuknf
2020-11-07 21:23:49 -05:00
parent ddb8fb7aea
commit 9885fb3c61
4 changed files with 49 additions and 6 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ REM See the License for the specific language governing permissions and
REM limitations under the License.
REM
SET REPO_URL=https://github.com/openziti/ziti-tunnel-sdk-c.git
SET ZITI_TUNNEL_REPO_BRANCH=v0.7.6
SET ZITI_TUNNEL_REPO_BRANCH=v0.7.8
REM override the c sdk used in the build - leave blank for the same as specified in the tunneler sdk
SET ZITI_SDK_C_BRANCH=
REM the number of TCP connections the tunneler sdk can have at any one time
+16 -5
View File
@@ -39,18 +39,23 @@ import (
//export ziti_pq_domain_go
func ziti_pq_domain_go(ctx C.ziti_context, id *C.char, response_cb C.ziti_pr_domain_cb ) {
svcId := C.GoString(id)
log.Debugf("domain posture check request [%s]", svcId)
domain := C.CString(posture.Domain())
defer C.free(unsafe.Pointer(domain))
log.Debugf("submitting domain posture check info. domain: %v", posture.Domain())
log.Debugf("domain posture check response [%s]. domain: %v", svcId, posture.Domain())
C.return_domain_info_c(ctx, id, response_cb, domain)
}
//export ziti_pq_process_go
func ziti_pq_process_go(ztx C.ziti_context, id *C.char, path *C.char, response_cb C.ziti_pr_process_cb) {
svcId := C.GoString(id)
gopath := C.GoString(path)
pi := posture.Process(gopath)
log.Debugf("proc posture check request [%s, %s]", svcId, gopath)
pi := posture.Process(gopath)
sha := C.CString(pi.Hash)
defer C.free(unsafe.Pointer(sha))
@@ -62,11 +67,14 @@ func ziti_pq_process_go(ztx C.ziti_context, id *C.char, path *C.char, response_c
C.setArrayString(cargs, C.CString(s), C.int(i))
}
log.Debugf("submitting proc posture check info for %s. running:%t, hash:%s, signers:%v", gopath, pi.IsRunning, pi.Hash, signers)
log.Debugf("proc posture check response [%s, %s]. running:%t, hash:%s, signers:%v", svcId, gopath, pi.IsRunning, pi.Hash, signers)
C.return_proc_info_c(ztx, id, path, response_cb, C.bool(pi.IsRunning), sha, cargs, numSigners)
}
//export ziti_pq_os_go
func ziti_pq_os_go(ztx C.ziti_context, id *C.char, response_cb C.ziti_pr_os_cb) {
svcId := C.GoString(id)
log.Debugf("os posture check request [%s]", svcId)
oi := posture.Os()
ostype := C.CString(oi.Type)
defer C.free(unsafe.Pointer(ostype))
@@ -75,17 +83,20 @@ func ziti_pq_os_go(ztx C.ziti_context, id *C.char, response_cb C.ziti_pr_os_cb)
osbuild := C.CString(oi.Build)
defer C.free(unsafe.Pointer(osbuild))
log.Debugf("submitting os posture check info: ostype:%s, osvers:%s, osbuild:%s", oi.Type, oi.Version, oi.Build)
log.Debugf("os posture check response [%s]. ostype:%s, osvers:%s, osbuild:%s", svcId, oi.Type, oi.Version, oi.Build)
C.return_os_info_c(ztx, id, response_cb, ostype, osvers, osbuild)
}
//export ziti_pq_mac_go
func ziti_pq_mac_go(ztx C.ziti_context, id *C.char, response_cb C.ziti_pr_mac_cb) {
svcId := C.GoString(id)
log.Debugf("mac posture check request [%s]", svcId)
macs := posture.MacAddresses()
nummacs := C.int(len(macs))
cargs := C.makeCharArray(C.int(nummacs))
defer C.freeCharArray(cargs, nummacs)
log.Debugf("submitting mac posture check info. macs: %v", macs)
log.Debugf("mac posture check response [%s]. macs: %v", svcId, macs)
C.return_mac_info_c(ztx, id, response_cb, cargs, nummacs)
}
+2
View File
@@ -850,6 +850,8 @@ func removeIdentity(out *json.Encoder, fingerprint string) {
err = os.Remove(id.Path())
if err != nil {
log.Warnf("could not remove file: %s", id.Path())
} else {
log.Debugf("identity file removed: %s", id.Path())
}
resp := dto.Response{Message: "success", Code: SUCCESS, Error: "", Payload: nil}
+30
View File
@@ -28,6 +28,7 @@ import (
"golang.org/x/sys/windows/registry"
"golang.zx2c4.com/wireguard/tun"
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
"io"
"net"
"os"
"strings"
@@ -53,10 +54,19 @@ func (t *RuntimeState) SaveState() {
// overwrite file if it exists
_ = os.MkdirAll(config.Path(), 0644)
log.Debugf("copying original config onto config.json.backup")
backup,err := backupConfig()
if err != nil {
log.Warnf("could not backup config file! %v", err)
} else {
log.Debugf("config file backed up to: %s", backup)
}
cfg, err := os.OpenFile(config.File(), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
log.Panicf("An unexpected and unrecoverable error has occurred while %s: %v", "opening the config file", err)
}
w := bufio.NewWriter(bufio.NewWriter(cfg))
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
@@ -70,6 +80,26 @@ func (t *RuntimeState) SaveState() {
log.Debug("state saved")
}
func backupConfig() (string, error) {
original, err := os.Open(config.File())
if err != nil {
return "", err
}
defer original.Close()
backup := config.File() + ".backup"
new, err := os.Create(backup)
if err != nil {
return "", err
}
defer new.Close()
_, err = io.Copy(new, original)
if err != nil {
return "", err
}
return backup, err
}
func (t *RuntimeState) ToStatus() dto.TunnelStatus {
var uptime int64