21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

different ways. On FreeBSD systems, for example, the information must be explicitly<br />

sent, and the receiver must be able to handle receiving it. On Linux systems, the<br />

information is automatically sent if the receiver asks for it.<br />

A third problem is that not all implementations pass the same information. Linux<br />

passes the process ID, user ID, and group ID of the sending process. FreeBSD<br />

includes all groups that the process is a member of, but it does not include the process<br />

ID. At a minimum, you can expect to get the process’s user and group IDs and<br />

nothing more.<br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#if !defined(linux) && !defined(__NetBSD__)<br />

#include <br />

#endif<br />

#ifndef SCM_CREDS<br />

#define SCM_CREDS SCM_CREDENTIALS<br />

#endif<br />

#ifndef linux<br />

# ifndef __NetBSD__<br />

# define SPC_PEER_UID(c) ((c)->cr_uid)<br />

# define SPC_PEER_GID(c) ((c)->cr_groups[0])<br />

# else<br />

# define SPC_PEER_UID(c) ((c)->sc_uid)<br />

# define SPC_PEER_GID(c) ((c)->sc_gid)<br />

# endif<br />

#else<br />

# define SPC_PEER_UID(c) ((c)->uid)<br />

# define SPC_PEER_GID(c) ((c)->gid)<br />

#endif<br />

#ifdef __NetBSD__<br />

typedef struct sockcred spc_credentials;<br />

#else<br />

typedef struct ucred spc_credentials;<br />

#endif<br />

spc_credentials *spc_get_credentials(int sd) {<br />

int nb, sync;<br />

char ctrl[CMSG_SPACE(sizeof(struct ucred))];<br />

size_t size;<br />

struct iovec iov[1] = { { 0, 0 } };<br />

struct msghdr msg = { 0, 0, iov, 1, ctrl, sizeof(ctrl), 0 };<br />

struct cmsghdr *cmptr;<br />

spc_credentials *credentials;<br />

Performing Authentication with Unix Domain Sockets | 483<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!