~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/syscall/sockcmsg_linux.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
package syscall
8
8
 
9
 
import (
10
 
        "unsafe"
11
 
)
 
9
import "unsafe"
12
10
 
13
11
// UnixCredentials encodes credentials into a socket control message
14
12
// for sending to another process. This can be used for
15
13
// authentication.
16
14
func UnixCredentials(ucred *Ucred) []byte {
17
 
        buf := make([]byte, CmsgSpace(SizeofUcred))
18
 
        cmsg := (*Cmsghdr)(unsafe.Pointer(&buf[0]))
19
 
        cmsg.Level = SOL_SOCKET
20
 
        cmsg.Type = SCM_CREDENTIALS
21
 
        cmsg.SetLen(CmsgLen(SizeofUcred))
22
 
        *((*Ucred)(cmsgData(cmsg))) = *ucred
23
 
        return buf
 
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
24
22
}
25
23
 
26
24
// ParseUnixCredentials decodes a socket control message that contains
27
25
// credentials in a Ucred structure. To receive such a message, the
28
26
// SO_PASSCRED option must be enabled on the socket.
29
 
func ParseUnixCredentials(msg *SocketControlMessage) (*Ucred, error) {
30
 
        if msg.Header.Level != SOL_SOCKET {
31
 
                return nil, EINVAL
32
 
        }
33
 
        if msg.Header.Type != SCM_CREDENTIALS {
34
 
                return nil, EINVAL
35
 
        }
36
 
        ucred := *(*Ucred)(unsafe.Pointer(&msg.Data[0]))
 
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]))
37
35
        return &ucred, nil
38
36
}