176866Skris/* crypto/uid.c */
276866Skris/* ====================================================================
376866Skris * Copyright (c) 2001 The OpenSSL Project.  All rights reserved.
476866Skris *
576866Skris * Redistribution and use in source and binary forms, with or without
676866Skris * modification, are permitted provided that the following conditions
776866Skris * are met:
876866Skris *
976866Skris * 1. Redistributions of source code must retain the above copyright
10280304Sjkim *    notice, this list of conditions and the following disclaimer.
1176866Skris *
1276866Skris * 2. Redistributions in binary form must reproduce the above copyright
1376866Skris *    notice, this list of conditions and the following disclaimer in
1476866Skris *    the documentation and/or other materials provided with the
1576866Skris *    distribution.
1676866Skris *
1776866Skris * 3. All advertising materials mentioning features or use of this
1876866Skris *    software must display the following acknowledgment:
1976866Skris *    "This product includes software developed by the OpenSSL Project
2076866Skris *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
2176866Skris *
2276866Skris * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
2376866Skris *    endorse or promote products derived from this software without
2476866Skris *    prior written permission. For written permission, please contact
2576866Skris *    licensing@OpenSSL.org.
2676866Skris *
2776866Skris * 5. Products derived from this software may not be called "OpenSSL"
2876866Skris *    nor may "OpenSSL" appear in their names without prior written
2976866Skris *    permission of the OpenSSL Project.
3076866Skris *
3176866Skris * 6. Redistributions of any form whatsoever must retain the following
3276866Skris *    acknowledgment:
3376866Skris *    "This product includes software developed by the OpenSSL Project
3476866Skris *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
3576866Skris *
3676866Skris * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
3776866Skris * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3876866Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
3976866Skris * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
4076866Skris * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4176866Skris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4276866Skris * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
4376866Skris * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4476866Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
4576866Skris * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4676866Skris * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
4776866Skris * OF THE POSSIBILITY OF SUCH DAMAGE.
4876866Skris * ====================================================================
4976866Skris *
5076866Skris * This product includes cryptographic software written by Eric Young
5176866Skris * (eay@cryptsoft.com).  This product includes software written by Tim
5276866Skris * Hudson (tjh@cryptsoft.com).
5376866Skris *
5476866Skris */
5576866Skris
5676866Skris#include <openssl/crypto.h>
57109998Smarkm#include <openssl/opensslconf.h>
5876866Skris
5976866Skris#if defined(__OpenBSD__) || (defined(__FreeBSD__) && __FreeBSD__ > 2)
6076866Skris
61280304Sjkim# include OPENSSL_UNISTD
6276866Skris
6376866Skrisint OPENSSL_issetugid(void)
64280304Sjkim{
65280304Sjkim    return issetugid();
66280304Sjkim}
6776866Skris
68160814Ssimon#elif defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE)
6976866Skris
7076866Skrisint OPENSSL_issetugid(void)
71280304Sjkim{
72280304Sjkim    return 0;
73280304Sjkim}
7476866Skris
7576866Skris#else
7676866Skris
77280304Sjkim# include OPENSSL_UNISTD
78280304Sjkim# include <sys/types.h>
7976866Skris
8076866Skrisint OPENSSL_issetugid(void)
81280304Sjkim{
82280304Sjkim    if (getuid() != geteuid())
83280304Sjkim        return 1;
84280304Sjkim    if (getgid() != getegid())
85280304Sjkim        return 1;
86280304Sjkim    return 0;
87280304Sjkim}
8876866Skris#endif
89