Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux_syscall.c:67:13: error: implicit declaration of function 'setresgid' is invalid in C99 #88

Open
osok opened this issue Jun 30, 2021 · 2 comments

Comments

@osok
Copy link

osok commented Jun 30, 2021

I'm building in a docker ubuntu 20.04 Linux container.

Below is a snippet of the code I'm using, the the relevant part of the Docker build file that I'm using to run my server in.
My server compiles code on demand for different environments. The code shown is part of that file that is being compiled when the error is thrown.

I have it working

  • Linux->Windows
  • Windows->Linux
  • Windows-> Darwin
  • Darwin->Windows
  • Darwin->Linux

The last thing I need is to be ale to compile on Linux for Darwin. Since I'm running in Docker it is a must have, the other combinations make development easy.

I can build other go files that doesn't use this library.

The code is fairly straight forward. Here is the portion that uses this library

import (
	set_var "components/payload/macos/commands/set-var"
	"components/payload/types"
	types3 "components/protocol/types"
	"github.com/99designs/keyring"
	"os/user"
	"strconv"
)

[some code redacted]

	kr, e1 := keyring.Open(keyring.Config{})
	if e1 != nil {
		response.Value = []byte("Failed to get a keyring object.  This one is not on me.")
		return
	}

	keys, e1 := kr.Keys()
	if err != nil {
		response.Value = []byte("Failed getting a list of keys from keyring\n")
		return
	}
	var item keyring.Item
	occurred := 0
	for _, k := range keys{
		if k == name {
			item, err = kr.Get(k)
			if err == nil {
				if(skip == occurred) {
					response.Value = []byte( item.Data)
				}else{
					occurred++
				}
				return
			}else{
				response.Value = []byte("I was not able to retrieve any values, I think they might have not allowed the activity.")
				return
			}
		}
	}

I have built the container with

FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get -y update 
RUN apt-get -y upgrade
RUN apt-get install -yq wget git build-essential mysql-client

#required for windows xcompile
RUN apt-get install -yq mingw-w64 libc6-dev-i386 

#required for darwin xcompile
RUN apt-get install -yq libpython2.7 libpython2.7-dev
RUN apt-get install -yq llvm libicu-dev clang 

RUN wget -c https://dl.google.com/go/go1.16.5.linux-amd64.tar.gz -O - | tar -xz -C /usr/local

ENV PATH /usr/local/go/bin:$PATH
ENV GOROOT /usr/local/go
ENV GOPATH /var/go

# Now ot create the actual osx xcompiler
RUN apt-get install -yq gcc g++ zlib1g-dev libmpc-dev libmpfr-dev libgmp-dev
RUN apt-get install -yq cmake patch python libssl-dev lzma-dev libxml2-dev
RUN git clone https://github.com/tpoechtrager/osxcross.git

#Note you can get update tarbars at https://developer.apple.com/download/all/?q=xcode
# the instructions for creating the tarball are in the osxcross repo
# we are storing the current on in gitlab xcode 12.5.1

COPY ./deploy/osxcross/MacOSX11.3.sdk.tar.bz2 /osxcross/tarballs/MacOSX11.3.sdk.tar.bz2
#COPY ./deploy/osxcross/MacOSX11.sdk.tar.bz2 /osxcross/tarballs/MacOSX11.sdk.tar.bz2
#COPY ./deploy/osxcross/MacOSX10.15.sdk.tar.bz2 /osxcross/tarballs/MacOSX10.15.sdk.tar.bz2

ENV CXX clang++ 
ENV CC clang 

RUN cd /osxcross
RUN  UNATTENDED=1 SDK_VERSION=11.3 /osxcross/build.sh
ENV PATH /osxcross/target/bin:$PATH

# I don't think I need this. but I'll leave it here for now.
#RUN /osxcross/build_gcc.sh


#reset the build in environment    
RUN cd ..
ENV CXX g++ 
ENV CC gcc 

I add a bunch of modules after this.


Since the server is building this code, I log much of the environment settings in place in order to debug issues like this:


================================================================
=  Build File 
=  OS = darwin
=  ARCH = amd64
================================================================
Old PATH = /osxcross/target/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
New PATH = /osxcross/target/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/go/bin
*****************************
**** Environment : darwin - amd64
*****************************
*****************************
CGO_ENABLED=1
GO111MODULE=off
CXX=o64-clang++
GOOS=darwin
HOME=/root
GOARCH=amd64
PWD=/usr/lib/test
GOROOT=/usr/local/go
PATH=/osxcross/target/bin:/usr/local/go/bin:/usr/share/swift/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/go/bin
OLDPWD=/
GOPATH=/var/go
CC=o64-clang
CGO_CFLAGS=-I/usr/share/swift/usr/lib/swift
OSXCROSS_NO_INCLUDE_PATH_WARNINGS=1
MACOSX_DEPLOYMENT_TARGET=11.3
*****************************

Command : [go build -ldflags -extldflags "-static" -s -w -trimpath -gcflags -trimpath=/usr/lib/test/server -asmflags -trimpath=/usr/lib/test/server -o /usr/lib/test/server/L01F/darwin/amd64/test /usr/lib/test/server/L01F/test.go]

[0] go
[1] build
[2] -ldflags
[3] -extldflags "-static" -s -w
[4] -trimpath
[5] -gcflags
[6] -trimpath=/usr/lib/test/server
[7] -asmflags
[8] -trimpath=/usr/lib/test/server
[9] -o
[10] /usr/lib/test/server/L01F/darwin/amd64/test
[11] /usr/lib/test/server/L01F/test.go
------- err | # github.com/99designs/keyring
------- err | /var/go/src/github.com/99designs/keyring/keychain.go:136:8: kcItem.SetAccess undefined (type keychain.Item has no field or method SetAccess)
------- err | /var/go/src/github.com/99designs/keyring/keychain.go:181:9: kcItem.SetAccess undefined (type keychain.Item has no field or method SetAccess)
------- err | /var/go/src/github.com/99designs/keyring/keychain.go:181:21: undefined: keychain.Access
------- err | /var/go/src/github.com/99designs/keyring/keychain.go:187:9: kcItem.SetAccess undefined (type keychain.Item has no field or method SetAccess)
------- err | /var/go/src/github.com/99designs/keyring/keychain.go:187:21: undefined: keychain.Access
Error darwin - amd64 : exit status 2

FIX FOR THIS ERROR
EDIT : Note to fix the above error I had found a thread that suggested adding the following line to the go.mod.

replace github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4

so the output of that is noted below.

@osok osok changed the title 'TARGET_OS_IPHONE' is not defined, kcItem.SetAccess undefined (type keychain.Item has no field or method SetAccess) Jun 30, 2021
@osok
Copy link
Author

osok commented Jun 30, 2021

Ok, I made a few modifications. Using the Docker build file above, I created the following standalone app which does the same thing.

package main

import (
	"fmt"
	"github.com/99designs/keyring"
	"os/user"
	"strconv"
)

func main() {

	var err error
	name := "michael"
	skipStr := "0"

	if  name == "" {
		u, e := user.Current()
		if e != nil {
			fmt.Println("The keyname was not set and I failed to get the users username.  I have failed you, I am a bad agent.")
			return
		}
		name = u.Username
	}
	var skip int
	if skipStr == ""{
		skip = 0
	}else{
		skip, _ = strconv.Atoi(skipStr)
	}

	kr, e1 := keyring.Open(keyring.Config{})
	if e1 != nil {
		fmt.Println("Failed to get a keyring object.  This one is not on me.")
		return
	}

	keys, e1 := kr.Keys()
	if err != nil {
		fmt.Println("Failed getting a list of keys from keyring\n")
		return
	}
	var item keyring.Item
	occurred := 0
	for _, k := range keys{
		if k == name {
			item, err = kr.Get(k)
			if err == nil {
				if(skip == occurred) {
					fmt.Println( item.Data)
				}else{
					occurred++
				}
				return
			}else{
				fmt.Println("I was not able to retrieve any values, I think they might have not allowed the activity.")
				return
			}
		}
	}

	fmt.Println("I was not able to retrieve any values for key name : "+ name)
	return

}

I then set the following environment variables

export CC=o64-clang
export CXX=o64-clang++
export CGO_ENABLED=1
export GO111MODULE=on

I have the following go.mod file in the root of my project

module gitlab.redteam.lab/michael/go-mod-test

go 1.16

require github.com/99designs/keyring v1.1.6
replace github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4

I then downloaded the libraries

go mod download

I then built the .go file from an interactive session with the docker container. So all the code was in the container.

go build test/KeyTest.go

and this is the error I get now

# runtime/cgo
linux_syscall.c:67:13: error: implicit declaration of function 'setresgid' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
linux_syscall.c:67:13: note: did you mean 'setregid'?
/osxcross/target/bin/../SDK/MacOSX11.3.sdk/usr/include/unistd.h:593:6: note: 'setregid' declared here
linux_syscall.c:73:13: error: implicit declaration of function 'setresuid' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
linux_syscall.c:73:13: note: did you mean 'setreuid'?
/osxcross/target/bin/../SDK/MacOSX11.3.sdk/usr/include/unistd.h:595:6: note: 'setreuid' declared here

@osok osok changed the title kcItem.SetAccess undefined (type keychain.Item has no field or method SetAccess) linux_syscall.c:67:13: error: implicit declaration of function 'setresgid' is invalid in C99 Jun 30, 2021
@osok
Copy link
Author

osok commented Jul 1, 2021

It would be nice to find out why this is occurring, but in the mean time I switched to keybase/go-keychain. There are no compile issues with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant