Changeset 534 for trunk/src


Ignore:
Timestamp:
Sep 16, 2018, 8:56:38 PM (6 years ago)
Author:
katerina
Message:

Version 4.3.0, support for /etc/subuid, /etc/subgid

Location:
trunk/src
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_hash.c

    r516 r534  
    2424#include <stdio.h>
    2525#include <sys/types.h>
     26#ifdef HAVE_SYS_SYSMACROS_H
     27#include <sys/sysmacros.h>
     28#endif
    2629#include <sys/stat.h>
    2730#include <unistd.h>
  • trunk/src/sh_unix.c

    r516 r534  
    28272827
    28282828/* --------- end caching code --------- */
    2829  
     2829
     2830#include "sh_subuid.h"
     2831
    28302832char *  sh_unix_getUIDname (int level, uid_t uid, char * out, size_t len)
    28312833{
     
    28632865  status = errno;
    28642866#endif
    2865  
    2866   if (tempres == NULL)
    2867     {
    2868       sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_PWNULL,
    2869                        sh_error_message(status, errbuf, sizeof(errbuf)),
    2870                        _("getpwuid"), (long) uid, _("completely missing"));
    2871 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R)
    2872       SH_FREE(buffer);
    2873 #endif
    2874       sh_userid_add(uid, NULL, CACHE_UID);
    2875       SL_RETURN( NULL, _("sh_unix_getUIDname"));
    2876     }
    2877 
    2878 
    2879   if (tempres->pw_name != NULL)
     2867
     2868  /* case 1: we have it
     2869   */
     2870  if (tempres && tempres->pw_name != NULL)
    28802871    {
    28812872
     
    28882879
    28892880      SL_RETURN( out, _("sh_unix_getUIDname"));
    2890     }
    2891   else
    2892     {
     2881    }
     2882
     2883#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R)
     2884  SH_FREE(buffer);
     2885#endif
     2886 
     2887  if (tempres == NULL)
     2888    {
     2889      char * pwname = sh_get_subuid ((unsigned long) uid);
     2890
     2891      if (pwname)
     2892        {
     2893          sl_strlcpy(out, pwname, len);
     2894          sh_userid_add(uid, out, CACHE_UID);
     2895          SL_RETURN( out, _("sh_unix_getUIDname"));
     2896        }
     2897
    28932898      sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_PWNULL,
    28942899                       sh_error_message(status, errbuf, sizeof(errbuf)),
    2895                        _("getpwuid"), (long) uid, _("pw_user"));
    2896 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R)
    2897       SH_FREE(buffer);
    2898 #endif
     2900                       _("getpwuid"), (long) uid, _("completely missing"));
     2901      sh_userid_add(uid, NULL, CACHE_UID);
    28992902      SL_RETURN( NULL, _("sh_unix_getUIDname"));
    29002903    }
    2901   /* notreached */
     2904
     2905
     2906  /* getwpuid returns struct, but no pw_name
     2907   */
     2908  sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_PWNULL,
     2909                   sh_error_message(status, errbuf, sizeof(errbuf)),
     2910                   _("getpwuid"), (long) uid, _("pw_user"));
     2911  SL_RETURN( NULL, _("sh_unix_getUIDname"));
    29022912}
    29032913
     
    29592969    }
    29602970
    2961   if (tempres == NULL)
    2962     {
    2963       sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_GRNULL,
    2964                        sh_error_message(status, errbuf, sizeof(errbuf)),
    2965                        _("getgrgid"), (long) gid, _("completely missing"));
    2966      
    2967 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R)
    2968       SH_FREE(buffer);
    2969 #endif
    2970 
    2971       sh_userid_add(gid, NULL, CACHE_GID);
    2972       SL_RETURN( NULL, _("sh_unix_getGIDname"));
    2973     }
    2974 
    2975   if (tempres->gr_name != NULL)
     2971  if (tempres && tempres->gr_name != NULL)
    29762972    {
    29772973
     
    29852981      SL_RETURN( out, _("sh_unix_getGIDname"));
    29862982    }
    2987   else
    2988     {
     2983
     2984#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R)
     2985  SH_FREE(buffer);
     2986#endif
     2987
     2988  if (tempres == NULL)
     2989    {
     2990      char * grname = sh_get_subgid ((unsigned long) gid);
     2991
     2992      if (grname)
     2993        {
     2994          sl_strlcpy(out, grname, len);
     2995          sh_userid_add((uid_t)gid, out, CACHE_GID);
     2996          SL_RETURN( out, _("sh_unix_getGIDname"));
     2997        }
     2998
    29892999      sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_GRNULL,
    29903000                       sh_error_message(status, errbuf, sizeof(errbuf)),
    2991                        _("getgrgid"), (long) gid, _("gr_name"));
    2992 
    2993 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R)
    2994       SH_FREE(buffer);
    2995 #endif
    2996 
     3001                       _("getgrgid"), (long) gid, _("completely missing"));
     3002      sh_userid_add(gid, NULL, CACHE_GID);
    29973003      SL_RETURN( NULL, _("sh_unix_getGIDname"));
    29983004    }
    2999   /* notreached */
     3005
     3006  sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_GRNULL,
     3007                   sh_error_message(status, errbuf, sizeof(errbuf)),
     3008                   _("getgrgid"), (long) gid, _("gr_name"));
     3009  SL_RETURN( NULL, _("sh_unix_getGIDname"));
    30003010}
    30013011
     
    30663076}
    30673077
    3068 
     3078/* return >0 on success, -1 on EOF */
    30693079int sh_unix_getline (SL_TICKET fd, char * line, int sizeofline)
    30703080{
Note: See TracChangeset for help on using the changeset viewer.