LCOV - code coverage report
Current view: top level - setup_native/scripts/source - getuid.c (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 10 0.0 %
Date: 2015-06-13 12:38:46 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 <assert.h>
      21             : #include <fcntl.h>
      22             : #include <sys/types.h>
      23             : #include <sys/stat.h>
      24             : #include <unistd.h>
      25             : #include <dlfcn.h>
      26             : 
      27             : #ifdef _cplusplus
      28             : extern "C" {
      29             : #endif
      30             : 
      31             : #ifdef SOLARIS
      32             : 
      33             : #include <sys/systeminfo.h>
      34             : #include <strings.h>
      35             : 
      36             : int   chown  (const char *path, uid_t owner, gid_t group) {return 0;}
      37             : int   lchown (const char *path, uid_t owner, gid_t group) {return 0;}
      38             : int   fchown (int fildes, uid_t owner, gid_t group)       {return 0;}
      39             : 
      40             : uid_t getuid  (void) {return 0;}
      41             : int stat(const char *path,  struct stat *buf);
      42             : #ifdef __notdef__
      43             : uid_t geteuid (void) {return 0;}
      44             : gid_t getgid  (void) {return 0;}
      45             : gid_t getegid (void) {return 0;}
      46             : #endif
      47             : 
      48             : int   setuid  (uid_t p)  {return 0;}
      49             : int   setgid  (gid_t p)  {return 0;}
      50             : 
      51             : /* This is to fool cpio and pkgmk */
      52             : int fstat(int fildes, struct stat *buf)
      53             : {
      54             :     int ret = 0;
      55             :     static int (*p_fstat) (int fildes, struct stat *buf) = NULL;
      56             :     if (p_fstat == NULL)
      57             :         p_fstat = (int (*)(int fildes, struct stat *buf))
      58             :             dlsym (RTLD_NEXT, "fstat");
      59             :     ret = (*p_fstat)(fildes, buf);
      60             :     if (buf != NULL)
      61             :     {
      62             :         buf->st_uid = 0; /* root */
      63             :         buf->st_gid = 2; /* bin */
      64             :     }
      65             : 
      66             :     return ret;
      67             : }
      68             : 
      69             : /* this is to fool mkdir, don't allow to remove owner execute right from directories */
      70             : int chmod(const char *path, mode_t mode)
      71             : {
      72             :     int ret = 0;
      73             :     static int (*p_chmod) (const char *path, mode_t mode) = NULL;
      74             :     if (p_chmod == NULL)
      75             :         p_chmod = (int (*)(const char *path, mode_t mode))
      76             :             dlsym (RTLD_NEXT, "chmod");
      77             : 
      78             :     if ((mode & S_IXUSR) == 0)
      79             :     {
      80             :         struct stat statbuf;
      81             :         if (stat(path, &statbuf) == 0)
      82             :         {
      83             :             if ((statbuf.st_mode & S_IFDIR) != 0)
      84             :                 mode = (mode | S_IXUSR);
      85             :         }
      86             :     }
      87             : 
      88             :     ret = (*p_chmod)(path, mode);
      89             :     return ret;
      90             : }
      91             : 
      92             : 
      93             : 
      94             : /* This is to fool tar */
      95             : int fstatat64(int fildes, const char *path, struct stat64  *buf, int flag)
      96             : {
      97             :     int ret = 0;
      98             :     static int (*p_fstatat) (int fildes, const char *path, struct stat64 *buf, int flag) = NULL;
      99             :     if (p_fstatat == NULL)
     100             :         p_fstatat = (int (*)(int fildes, const char *path, struct stat64 *buf, int flag))
     101             :             dlsym (RTLD_NEXT, "fstatat64");
     102             :     ret = (*p_fstatat)(fildes, path, buf, flag);
     103             :     if (buf != NULL)
     104             :     {
     105             :         buf->st_uid = 0; /* root */
     106             :         buf->st_gid = 2; /* bin */
     107             :     }
     108             : 
     109             :     return ret;
     110             : }
     111             : #elif  defined LINUX
     112             : 
     113           0 : uid_t getuid  (void) {return 0;}
     114           0 : uid_t geteuid (void) {return 0;}
     115             : 
     116             : /* This is to fool tar */
     117             : #ifdef X86_64
     118             : int __lxstat(int n, const char *path, struct stat *buf)
     119             : {
     120           0 :     int ret = 0;
     121             :     static int (*p_lstat) (int n, const char *path, struct stat *buf) = NULL;
     122           0 :     if (p_lstat == NULL)
     123           0 :         p_lstat = (int (*)(int n, const char *path, struct stat *buf))
     124           0 :             dlsym (RTLD_NEXT, "__lxstat");
     125           0 :     ret = (*p_lstat)(n, path, buf);
     126             :     assert(buf != NULL);
     127           0 :     buf->st_uid = 0; /* root */
     128           0 :     buf->st_gid = 0; /* root */
     129           0 :     return ret;
     130             : }
     131             : #else
     132             : int __lxstat64(int n, const char *path, struct stat64 *buf)
     133             : {
     134             :     int ret = 0;
     135             :     static int (*p_lstat) (int n, const char *path, struct stat64 *buf) = NULL;
     136             :     if (p_lstat == NULL)
     137             :         p_lstat = (int (*)(int n, const char *path, struct stat64 *buf))
     138             :             dlsym (RTLD_NEXT, "__lxstat64");
     139             :     ret = (*p_lstat)(n, path, buf);
     140             :     assert(buf != NULL);
     141             :     buf->st_uid = 0;
     142             :     buf->st_gid = 0;
     143             :     return ret;
     144             : }
     145             : #endif
     146             : #endif
     147             : 
     148             : #ifdef _cplusplus
     149             : }
     150             : #endif
     151             : 
     152             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11