Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
c734c13b
Commit
c734c13b
authored
Jun 13, 2007
by
J. Alexander Treuman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding parsePath and making parseConfigFilePath use it.
git-svn-id:
https://svn.musicpd.org/mpd/trunk@6622
09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent
b496239e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
47 deletions
+64
-47
conf.c
src/conf.c
+4
-47
utils.c
src/utils.c
+58
-0
utils.h
src/utils.h
+2
-0
No files found.
src/conf.c
View file @
c734c13b
...
@@ -397,55 +397,12 @@ ConfigParam *parseConfigFilePath(char *name, int force)
...
@@ -397,55 +397,12 @@ ConfigParam *parseConfigFilePath(char *name, int force)
if
(
!
param
)
if
(
!
param
)
return
NULL
;
return
NULL
;
path
=
param
->
value
;
path
=
parsePath
(
param
->
value
);
if
(
!
path
)
FATAL
(
"error parsing
\"
%s
\"
at line %i
\n
"
,
name
,
param
->
line
);
if
(
path
[
0
]
!=
'/'
&&
path
[
0
]
!=
'~'
)
{
FATAL
(
"
\"
%s
\"
is not an absolute path at line %i
\n
"
,
param
->
value
,
param
->
line
);
}
/* Parse ~ in path */
else
if
(
path
[
0
]
==
'~'
)
{
struct
passwd
*
pwd
=
NULL
;
char
*
newPath
;
int
pos
=
1
;
if
(
path
[
1
]
==
'/'
||
path
[
1
]
==
'\0'
)
{
ConfigParam
*
userParam
=
getConfigParam
(
CONF_USER
);
if
(
userParam
)
{
pwd
=
getpwnam
(
userParam
->
value
);
if
(
!
pwd
)
{
FATAL
(
"no such user %s at line %i
\n
"
,
userParam
->
value
,
userParam
->
line
);
}
}
else
{
uid_t
uid
=
geteuid
();
if
((
pwd
=
getpwuid
(
uid
))
==
NULL
)
{
FATAL
(
"problems getting passwd entry "
"for current user
\n
"
);
}
}
}
else
{
int
foundSlash
=
0
;
char
*
ch
=
path
+
1
;
for
(;
*
ch
!=
'\0'
&&
*
ch
!=
'/'
;
ch
++
)
;
if
(
*
ch
==
'/'
)
foundSlash
=
1
;
*
ch
=
'\0'
;
pos
+=
ch
-
path
-
1
;
if
((
pwd
=
getpwnam
(
path
+
1
))
==
NULL
)
{
FATAL
(
"user
\"
%s
\"
not found at line %i
\n
"
,
path
+
1
,
param
->
line
);
}
if
(
foundSlash
)
*
ch
=
'/'
;
}
newPath
=
xmalloc
(
strlen
(
pwd
->
pw_dir
)
+
strlen
(
path
+
pos
)
+
1
);
strcpy
(
newPath
,
pwd
->
pw_dir
);
strcat
(
newPath
,
path
+
pos
);
free
(
param
->
value
);
free
(
param
->
value
);
param
->
value
=
newPath
;
param
->
value
=
path
;
}
return
param
;
return
param
;
}
}
src/utils.c
View file @
c734c13b
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include "utils.h"
#include "utils.h"
#include "log.h"
#include "log.h"
#include "conf.h"
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
...
@@ -28,6 +29,7 @@
...
@@ -28,6 +29,7 @@
#include <sys/time.h>
#include <sys/time.h>
#include <unistd.h>
#include <unistd.h>
#include <assert.h>
#include <assert.h>
#include <pwd.h>
char
*
myFgets
(
char
*
buffer
,
int
bufferSize
,
FILE
*
fp
)
char
*
myFgets
(
char
*
buffer
,
int
bufferSize
,
FILE
*
fp
)
{
{
...
@@ -158,4 +160,60 @@ mpd_malloc void *xcalloc(size_t nmemb, size_t size)
...
@@ -158,4 +160,60 @@ mpd_malloc void *xcalloc(size_t nmemb, size_t size)
return
ret
;
return
ret
;
}
}
char
*
parsePath
(
char
*
path
)
{
ConfigParam
*
param
;
struct
passwd
*
passwd
;
char
*
newPath
;
char
*
c
;
int
foundSlash
=
0
;
int
pos
=
1
;
if
(
path
[
0
]
!=
'/'
&&
path
[
0
]
!=
'~'
)
{
ERROR
(
"
\"
%s
\"
is not an absolute path
\n
"
,
path
);
return
NULL
;
}
else
if
(
path
[
0
]
==
'~'
)
{
if
(
path
[
1
]
==
'/'
||
path
[
1
]
==
'\0'
)
{
param
=
getConfigParam
(
CONF_USER
);
if
(
param
&&
param
->
value
)
{
passwd
=
getpwnam
(
param
->
value
);
if
(
!
passwd
)
{
ERROR
(
"no such user %s
\n
"
,
param
->
value
);
return
NULL
;
}
}
else
{
passwd
=
getpwuid
(
geteuid
());
if
(
!
passwd
)
{
ERROR
(
"problems getting passwd entry "
"for current user
\n
"
);
return
NULL
;
}
}
}
else
{
for
(
c
=
path
+
1
;
*
c
!=
'\0'
&&
*
c
!=
'/'
;
c
++
);
if
(
*
c
==
'/'
)
{
foundSlash
=
1
;
*
c
=
'\0'
;
}
pos
=
c
-
path
;
passwd
=
getpwnam
(
path
+
1
);
if
(
!
passwd
)
{
ERROR
(
"user
\"
%s
\"
not found
\n
"
,
path
+
1
);
return
NULL
;
}
if
(
foundSlash
)
*
c
=
'/'
;
}
newPath
=
xmalloc
(
strlen
(
passwd
->
pw_dir
)
+
strlen
(
path
+
pos
)
+
1
);
strcpy
(
newPath
,
passwd
->
pw_dir
);
strcat
(
newPath
,
path
+
pos
);
}
else
{
newPath
=
xstrdup
(
path
);
}
return
newPath
;
}
src/utils.h
View file @
c734c13b
...
@@ -82,4 +82,6 @@ mpd_malloc void *xrealloc(void *ptr, size_t size);
...
@@ -82,4 +82,6 @@ mpd_malloc void *xrealloc(void *ptr, size_t size);
mpd_malloc
void
*
xcalloc
(
size_t
nmemb
,
size_t
size
);
mpd_malloc
void
*
xcalloc
(
size_t
nmemb
,
size_t
size
);
char
*
parsePath
(
char
*
path
);
#endif
#endif
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