Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1610)

Side by Side Diff: unix/sockcmsg_linux.go

Issue 126960043: code review 126960043: go.sys: copy files from syscall package to go.sys/{plan... (Closed)
Patch Set: Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « unix/so_solaris.go ('k') | unix/sockcmsg_unix.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Socket control messages
6
7 package syscall
8
9 import "unsafe"
10
11 // UnixCredentials encodes credentials into a socket control message
12 // for sending to another process. This can be used for
13 // authentication.
14 func UnixCredentials(ucred *Ucred) []byte {
15 b := make([]byte, CmsgSpace(SizeofUcred))
16 h := (*Cmsghdr)(unsafe.Pointer(&b[0]))
17 h.Level = SOL_SOCKET
18 h.Type = SCM_CREDENTIALS
19 h.SetLen(CmsgLen(SizeofUcred))
20 *((*Ucred)(cmsgData(h))) = *ucred
21 return b
22 }
23
24 // ParseUnixCredentials decodes a socket control message that contains
25 // credentials in a Ucred structure. To receive such a message, the
26 // SO_PASSCRED option must be enabled on the socket.
27 func ParseUnixCredentials(m *SocketControlMessage) (*Ucred, error) {
28 if m.Header.Level != SOL_SOCKET {
29 return nil, EINVAL
30 }
31 if m.Header.Type != SCM_CREDENTIALS {
32 return nil, EINVAL
33 }
34 ucred := *(*Ucred)(unsafe.Pointer(&m.Data[0]))
35 return &ucred, nil
36 }
OLDNEW
« no previous file with comments | « unix/so_solaris.go ('k') | unix/sockcmsg_unix.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b