LCOV - code coverage report
Current view: top level - setup_native/scripts/source - getuid.c (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 11 0.0 %
Date: 2014-04-14 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <fcntl.h>
      21             : #include <sys/types.h>
      22             : #include <sys/stat.h>
      23             : #include <unistd.h>
      24             : #include <dlfcn.h>
      25             : 
      26             : #ifdef _cplusplus
      27             : extern "C" {
      28             : #endif
      29             : 
      30             : #ifdef SOLARIS
      31             : 
      32             : #include <sys/systeminfo.h>
      33             : #include <strings.h>
      34             : 
      35             : int   chown  (const char *path, uid_t owner, gid_t group) {return 0;}
      36             : int   lchown (const char *path, uid_t owner, gid_t group) {return 0;}
      37             : int   fchown (int fildes, uid_t owner, gid_t group)       {return 0;}
      38             : 
      39             : uid_t getuid  (void) {return 0;}
      40             : int stat(const char *path,  struct stat *buf);
      41             : #ifdef __notdef__
      42             : uid_t geteuid (void) {return 0;}
      43             : gid_t getgid  (void) {return 0;}
      44             : gid_t getegid (void) {return 0;}
      45             : #endif
      46             : 
      47             : int   setuid  (uid_t p)  {return 0;}
      48             : int   setgid  (gid_t p)  {return 0;}
      49             : 
      50             : /* This is to fool cpio and pkgmk */
      51             : int fstat(int fildes, struct stat *buf)
      52             : {
      53             :     int ret = 0;
      54             :     static int (*p_fstat) (int fildes, struct stat *buf) = NULL;
      55             :     if (p_fstat == NULL)
      56             :         p_fstat = (int (*)(int fildes, struct stat *buf))
      57             :             dlsym (RTLD_NEXT, "fstat");
      58             :     ret = (*p_fstat)(fildes, buf);
      59             :     if (buf != NULL)
      60             :     {
      61             :         buf->st_uid = 0; /* root */
      62             :         buf->st_gid = 2; /* bin */
      63             :     }
      64             : 
      65             :     return ret;
      66             : }
      67             : 
      68             : /* this is to fool mkdir, don't allow to remove owner execute right from directories */
      69             : int chmod(const char *path, mode_t mode)
      70             : {
      71             :     int ret = 0;
      72             :     static int (*p_chmod) (const char *path, mode_t mode) = NULL;
      73             :     if (p_chmod == NULL)
      74             :         p_chmod = (int (*)(const char *path, mode_t mode))
      75             :             dlsym (RTLD_NEXT, "chmod");
      76             : 
      77             :     if ((mode & S_IXUSR) == 0)
      78             :     {
      79             :         struct stat statbuf;
      80             :         if (stat(path, &statbuf) == 0)
      81             :         {
      82             :             if ((statbuf.st_mode & S_IFDIR) != 0)
      83             :                 mode = (mode | S_IXUSR);
      84             :         }
      85             :     }
      86             : 
      87             :     ret = (*p_chmod)(path, mode);
      88             :     return ret;
      89             : }
      90             : 
      91             : 
      92             : 
      93             : /* This is to fool tar */
      94             : int fstatat64(int fildes, const char *path, struct stat64  *buf, int flag)
      95             : {
      96             :     int ret = 0;
      97             :     static int (*p_fstatat) (int fildes, const char *path, struct stat64 *buf, int flag) = NULL;
      98             :     if (p_fstatat == NULL)
      99             :         p_fstatat = (int (*)(int fildes, const char *path, struct stat64 *buf, int flag))
     100             :             dlsym (RTLD_NEXT, "fstatat64");
     101             :     ret = (*p_fstatat)(fildes, path, buf, flag);
     102             :     if (buf != NULL)
     103             :     {
     104             :         buf->st_uid = 0; /* root */
     105             :         buf->st_gid = 2; /* bin */
     106             :     }
     107             : 
     108             :     return ret;
     109             : }
     110             : #elif  defined LINUX
     111             : 
     112           0 : uid_t getuid  (void) {return 0;}
     113           0 : uid_t geteuid (void) {return 0;}
     114             : 
     115             : /* This is to fool tar */
     116             : #ifdef X86_64
     117             : int __lxstat(int n, const char *path, struct stat *buf)
     118             : {
     119             :     int ret = 0;
     120             :     static int (*p_lstat) (int n, const char *path, struct stat *buf) = NULL;
     121             :     if (p_lstat == NULL)
     122             :         p_lstat = (int (*)(int n, const char *path, struct stat *buf))
     123             :             dlsym (RTLD_NEXT, "__lxstat");
     124             :     ret = (*p_lstat)(n, path, buf);
     125             :     if (buf != NULL)
     126             :     {
     127             :         buf->st_uid = 0; /* root */
     128             :         buf->st_gid = 0; /* root */
     129             :     }
     130             :     return ret;
     131             : }
     132             : #else
     133             : int __lxstat64(int n, const char *path, struct stat64 *buf)
     134             : {
     135           0 :     int ret = 0;
     136             :     static int (*p_lstat) (int n, const char *path, struct stat64 *buf) = NULL;
     137           0 :     if (p_lstat == NULL)
     138           0 :         p_lstat = (int (*)(int n, const char *path, struct stat64 *buf))
     139           0 :             dlsym (RTLD_NEXT, "__lxstat64");
     140           0 :     ret = (*p_lstat)(n, path, buf);
     141           0 :     if (buf != NULL)
     142             :     {
     143           0 :         buf->st_uid = 0;
     144           0 :         buf->st_gid = 0;
     145             :     }
     146           0 :     return ret;
     147             : }
     148             : #endif
     149             : #endif
     150             : 
     151             : #ifdef _cplusplus
     152             : }
     153             : #endif
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10