181861Sdd/* 281861Sdd * Copyright (c) 2001 Dima Dorfman. 381861Sdd * All rights reserved. 481861Sdd * 581861Sdd * Redistribution and use in source and binary forms, with or without 681861Sdd * modification, are permitted provided that the following conditions 781861Sdd * are met: 881861Sdd * 1. Redistributions of source code must retain the above copyright 981861Sdd * notice, this list of conditions and the following disclaimer. 1081861Sdd * 2. Redistributions in binary form must reproduce the above copyright 1181861Sdd * notice, this list of conditions and the following disclaimer in the 1281861Sdd * documentation and/or other materials provided with the distribution. 1381861Sdd * 1481861Sdd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1581861Sdd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1681861Sdd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1781861Sdd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1881861Sdd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1981861Sdd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2081861Sdd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2181861Sdd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2281861Sdd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2381861Sdd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2481861Sdd * SUCH DAMAGE. 2581861Sdd */ 2681861Sdd 2790050Sobrien#include <sys/cdefs.h> 2890039Sobrien__FBSDID("$FreeBSD$"); 2981861Sdd 3081861Sdd#include <sys/param.h> 3181861Sdd#include <sys/socket.h> 3281861Sdd#include <sys/ucred.h> 3381861Sdd#include <sys/un.h> 3481861Sdd 3591354Sdd#include <errno.h> 3681861Sdd#include <unistd.h> 3781861Sdd 3881861Sddint 3981861Sddgetpeereid(int s, uid_t *euid, gid_t *egid) 4081861Sdd{ 4181861Sdd struct xucred xuc; 4281861Sdd socklen_t xuclen; 4381861Sdd int error; 4481861Sdd 4581861Sdd xuclen = sizeof(xuc); 46107929Smaxim error = getsockopt(s, 0, LOCAL_PEERCRED, &xuc, &xuclen); 4781861Sdd if (error != 0) 4881861Sdd return (error); 4991354Sdd if (xuc.cr_version != XUCRED_VERSION) 5091354Sdd return (EINVAL); 5181861Sdd *euid = xuc.cr_uid; 5281861Sdd *egid = xuc.cr_gid; 5381861Sdd return (0); 5481861Sdd} 55