mirror of
https://github.com/kubernetes/sample-controller.git
synced 2025-01-22 09:52:52 +08:00
ec723b2112
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. sample-controller: add example CRD controller **What this PR does / why we need it**: Adds a sample-controller example repository fixes #52752 **Special notes for your reviewer**: This is currently based on the sttts:sttts-codegen-scripts branch and should not be merged until that is (ref https://github.com/kubernetes/kubernetes/pull/52186) **Release note**: ``` Add sample-controller repository ``` /cc @sttts @nikhita @colemickens Kubernetes-commit: 9a7800f7d2efb88b397674672ac56f898826cf7c
37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
// Copyright 2011 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Socket control messages
|
|
|
|
package unix
|
|
|
|
import "unsafe"
|
|
|
|
// UnixCredentials encodes credentials into a socket control message
|
|
// for sending to another process. This can be used for
|
|
// authentication.
|
|
func UnixCredentials(ucred *Ucred) []byte {
|
|
b := make([]byte, CmsgSpace(SizeofUcred))
|
|
h := (*Cmsghdr)(unsafe.Pointer(&b[0]))
|
|
h.Level = SOL_SOCKET
|
|
h.Type = SCM_CREDENTIALS
|
|
h.SetLen(CmsgLen(SizeofUcred))
|
|
*((*Ucred)(cmsgData(h))) = *ucred
|
|
return b
|
|
}
|
|
|
|
// ParseUnixCredentials decodes a socket control message that contains
|
|
// credentials in a Ucred structure. To receive such a message, the
|
|
// SO_PASSCRED option must be enabled on the socket.
|
|
func ParseUnixCredentials(m *SocketControlMessage) (*Ucred, error) {
|
|
if m.Header.Level != SOL_SOCKET {
|
|
return nil, EINVAL
|
|
}
|
|
if m.Header.Type != SCM_CREDENTIALS {
|
|
return nil, EINVAL
|
|
}
|
|
ucred := *(*Ucred)(unsafe.Pointer(&m.Data[0]))
|
|
return &ucred, nil
|
|
}
|