Magellan Linux

Diff of /tags/mkinitrd-6_2_0/libpwdgrp/uidgid_get.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 532 by niro, Sat Sep 1 22:45:15 2007 UTC revision 816 by niro, Fri Apr 24 18:33:46 2009 UTC
# Line 25  OTHERWISE) ARISING IN ANY WAY OUT OF THE Line 25  OTHERWISE) ARISING IN ANY WAY OUT OF THE
25  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */  */
27    
28  #include "busybox.h"  #include "libbb.h"
29    
30  int get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok)  /* Always sets uid and gid */
31    int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok)
32  {  {
33   struct passwd *pwd;   struct passwd *pwd;
34   struct group *gr;   struct group *gr;
# Line 53  int get_uidgid(struct bb_uidgid_t *u, co Line 54  int get_uidgid(struct bb_uidgid_t *u, co
54   goto skip;   goto skip;
55   }   }
56   }   }
57     /* Either it is not numeric, or caller disallows numeric username */
58   pwd = getpwnam(user);   pwd = getpwnam(user);
59   if (!pwd)   if (!pwd)
60   return 0;   return 0;
# Line 74  int get_uidgid(struct bb_uidgid_t *u, co Line 76  int get_uidgid(struct bb_uidgid_t *u, co
76   }   }
77   return 1;   return 1;
78  }  }
79    void FAST_FUNC xget_uidgid(struct bb_uidgid_t *u, const char *ug)
80    {
81     if (!get_uidgid(u, ug, 1))
82     bb_error_msg_and_die("unknown user/group %s", ug);
83    }
84    
85    /* chown-like:
86     * "user" sets uid only,
87     * ":group" sets gid only
88     * "user:" sets uid and gid (to user's primary group id)
89     * "user:group" sets uid and gid
90     * ('unset' uid or gid retains the value it has on entry)
91     */
92    void FAST_FUNC parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_group)
93    {
94     char *group;
95    
96     /* Check if there is a group name */
97     group = strchr(user_group, '.'); /* deprecated? */
98     if (!group)
99     group = strchr(user_group, ':');
100     else
101     *group = ':'; /* replace '.' with ':' */
102    
103     /* Parse "user[:[group]]" */
104     if (!group) { /* "user" */
105     u->uid = get_ug_id(user_group, xuname2uid);
106     } else if (group == user_group) { /* ":group" */
107     u->gid = get_ug_id(group + 1, xgroup2gid);
108     } else {
109     if (!group[1]) /* "user:" */
110     *group = '\0';
111     xget_uidgid(u, user_group);
112     }
113    }
114    
115  #if 0  #if 0
116  #include <stdio.h>  #include <stdio.h>

Legend:
Removed from v.532  
changed lines
  Added in v.816