Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liblongpath-rsync
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liblongpath
liblongpath-rsync
Commits
56017d31
Commit
56017d31
authored
May 07, 2009
by
Wayne Davison
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhance name_to_{u,g}id() to optionally parse numbers and rename
to {user,group}_to_*(). Based on a patch by Matt McCutchen.
parent
d960af72
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
30 deletions
+25
-30
clientserver.c
clientserver.c
+8
-14
uidlist.c
uidlist.c
+5
-12
util.c
util.c
+12
-4
No files found.
clientserver.c
View file @
56017d31
...
...
@@ -416,13 +416,10 @@ static int path_failure(int f_out, const char *dir, BOOL was_chdir)
static
int
add_a_group
(
int
f_out
,
const
char
*
gname
)
{
gid_t
gid
;
if
(
!
name_to_gid
(
gname
,
&
gid
))
{
if
(
!
isDigit
(
gname
))
{
rprintf
(
FLOG
,
"Invalid gid %s
\n
"
,
gname
);
io_printf
(
f_out
,
"@ERROR: invalid gid %s
\n
"
,
gname
);
return
-
1
;
}
gid
=
atol
(
gname
);
if
(
!
group_to_gid
(
gname
,
&
gid
,
True
))
{
rprintf
(
FLOG
,
"Invalid gid %s
\n
"
,
gname
);
io_printf
(
f_out
,
"@ERROR: invalid gid %s
\n
"
,
gname
);
return
-
1
;
}
if
(
gid_count
==
MAX_GID_LIST
)
{
rprintf
(
FLOG
,
"Too many groups specified via gid parameter.
\n
"
);
...
...
@@ -558,13 +555,10 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char
p
=
*
lp_uid
(
i
)
?
lp_uid
(
i
)
:
am_root
?
NOBODY_USER
:
NULL
;
if
(
p
)
{
if
(
!
name_to_uid
(
p
,
&
uid
))
{
if
(
!
isDigit
(
p
))
{
rprintf
(
FLOG
,
"Invalid uid %s
\n
"
,
p
);
io_printf
(
f_out
,
"@ERROR: invalid uid %s
\n
"
,
p
);
return
-
1
;
}
uid
=
atol
(
p
);
if
(
!
user_to_uid
(
p
,
&
uid
,
True
))
{
rprintf
(
FLOG
,
"Invalid uid %s
\n
"
,
p
);
io_printf
(
f_out
,
"@ERROR: invalid uid %s
\n
"
,
p
);
return
-
1
;
}
set_uid
=
1
;
}
else
...
...
uidlist.c
View file @
56017d31
...
...
@@ -181,10 +181,10 @@ static struct idlist *recv_add_id(struct idlist **idlist_ptr, struct idlist *idm
else
if
(
*
name
&&
id
)
{
if
(
idlist_ptr
==
&
uidlist
)
{
uid_t
uid
;
id2
=
name_to_uid
(
name
,
&
uid
)
?
uid
:
id
;
id2
=
user_to_uid
(
name
,
&
uid
,
False
)
?
uid
:
id
;
}
else
{
gid_t
gid
;
id2
=
name_to_gid
(
name
,
&
gid
)
?
gid
:
id
;
id2
=
group_to_gid
(
name
,
&
gid
,
False
)
?
gid
:
id
;
}
}
else
id2
=
id
;
...
...
@@ -415,7 +415,6 @@ void parse_name_map(char *map, BOOL usernames)
char
*
dash
=
strchr
(
cp
,
'-'
);
if
(
strspn
(
cp
,
"0123456789-"
)
!=
(
size_t
)(
colon
-
cp
)
||
(
dash
&&
(
!
dash
[
1
]
||
strchr
(
dash
+
1
,
'-'
))))
{
bad_number:
rprintf
(
FERROR
,
"Invalid number in --%smap: %s
\n
"
,
usernames
?
"user"
:
"group"
,
cp
);
exit_cleanup
(
RERR_SYNTAX
);
...
...
@@ -436,15 +435,9 @@ void parse_name_map(char *map, BOOL usernames)
id1
=
0
;
}
if
(
isDigit
(
colon
+
1
))
{
if
(
strspn
(
colon
+
1
,
"0123456789"
)
!=
(
size_t
)(
end
-
colon
-
1
))
{
cp
=
colon
+
1
;
goto
bad_number
;
}
add_to_list
(
idmap_ptr
,
id1
,
name
,
atol
(
colon
+
1
),
flags
);
}
else
if
(
usernames
)
{
if
(
usernames
)
{
uid_t
uid
;
if
(
name_to_uid
(
colon
+
1
,
&
uid
))
if
(
user_to_uid
(
colon
+
1
,
&
uid
,
True
))
add_to_list
(
idmap_ptr
,
id1
,
name
,
uid
,
flags
);
else
{
rprintf
(
FERROR
,
...
...
@@ -453,7 +446,7 @@ void parse_name_map(char *map, BOOL usernames)
}
}
else
{
gid_t
gid
;
if
(
name_to_gid
(
colon
+
1
,
&
gid
))
if
(
group_to_gid
(
colon
+
1
,
&
gid
,
True
))
add_to_list
(
idmap_ptr
,
id1
,
name
,
gid
,
flags
);
else
{
rprintf
(
FERROR
,
...
...
util.c
View file @
56017d31
...
...
@@ -534,24 +534,32 @@ void kill_all(int sig)
}
}
/*
* Turn a user name
into a uid */
int
name_to_uid
(
const
char
*
name
,
uid_t
*
uid_p
)
/*
Parse a user name or (optionally) a number
into a uid */
int
user_to_uid
(
const
char
*
name
,
uid_t
*
uid_p
,
BOOL
num_ok
)
{
struct
passwd
*
pass
;
if
(
!
name
||
!*
name
)
return
0
;
if
(
num_ok
&&
name
[
strspn
(
name
,
"0123456789"
)]
==
'\0'
)
{
*
uid_p
=
atol
(
name
);
return
1
;
}
if
(
!
(
pass
=
getpwnam
(
name
)))
return
0
;
*
uid_p
=
pass
->
pw_uid
;
return
1
;
}
/*
* Turn a group name
into a gid */
int
name_to_gid
(
const
char
*
name
,
gid_t
*
gid_p
)
/*
Parse a group name or (optionally) a number
into a gid */
int
group_to_gid
(
const
char
*
name
,
gid_t
*
gid_p
,
BOOL
num_ok
)
{
struct
group
*
grp
;
if
(
!
name
||
!*
name
)
return
0
;
if
(
num_ok
&&
name
[
strspn
(
name
,
"0123456789"
)]
==
'\0'
)
{
*
gid_p
=
atol
(
name
);
return
1
;
}
if
(
!
(
grp
=
getgrnam
(
name
)))
return
0
;
*
gid_p
=
grp
->
gr_gid
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment