Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
mailutils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
791a6cc4
...
791a6cc4039fcd808620f4c92592030b5b7c5141
authored
2002-02-19 17:02:35 +0000
by
Sergey Poznyakoff
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
(getMpwnam): Return username along with
other data. (getMpwuid): New function.
1 parent
32d4508e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
12 deletions
MySql/MySql.c
MySql/MySql.c
View file @
791a6cc
...
...
@@ -18,7 +18,7 @@
extern
void
*
xmalloc
(
size_t
);
static
char
*
sql_expand_query
(
const
char
*
query
,
const
char
*
us
ername
)
sql_expand_query
(
const
char
*
query
,
const
char
*
us
tr
)
{
char
*
p
,
*
q
,
*
res
;
int
len
;
...
...
@@ -33,7 +33,7 @@ sql_expand_query (const char *query, const char *username)
{
if
(
p
[
1
]
==
'u'
)
{
len
+=
strlen
(
us
ername
);
len
+=
strlen
(
us
tr
);
p
+=
2
;
}
else
if
(
p
[
1
]
==
'%'
)
...
...
@@ -65,7 +65,7 @@ sql_expand_query (const char *query, const char *username)
switch
(
*++
p
)
{
case
'u'
:
strcpy
(
q
,
us
ername
);
strcpy
(
q
,
us
tr
);
q
+=
strlen
(
q
);
p
++
;
break
;
...
...
@@ -147,23 +147,110 @@ getMpwnam (const char *username)
if
(
!
tpw
)
tpw
=
(
struct
passwd
*
)
xmalloc
(
sizeof
(
struct
passwd
));
tpw
->
pw_name
=
xmalloc
(
strlen
(
username
)
+
1
);
strcpy
(
tpw
->
pw_name
,
username
);
tpw
->
pw_name
=
xmalloc
(
strlen
(
row
[
0
]
)
+
1
);
strcpy
(
tpw
->
pw_name
,
row
[
0
]
);
tpw
->
pw_passwd
=
xmalloc
(
strlen
(
row
[
0
])
+
1
);
tpw
->
pw_passwd
=
xmalloc
(
strlen
(
row
[
1
])
+
1
);
strcpy
(
tpw
->
pw_passwd
,
row
[
1
]);
tpw
->
pw_uid
=
atoi
(
row
[
2
]);
tpw
->
pw_gid
=
atoi
(
row
[
3
]);
tpw
->
pw_gecos
=
xmalloc
(
strlen
(
"Mysql User"
)
+
1
);
strcpy
(
tpw
->
pw_gecos
,
"Mysql User"
);
tpw
->
pw_dir
=
xmalloc
(
strlen
(
row
[
4
])
+
1
);
strcpy
(
tpw
->
pw_dir
,
row
[
4
]);
tpw
->
pw_shell
=
xmalloc
(
strlen
(
row
[
5
])
+
1
);
strcpy
(
tpw
->
pw_shell
,
row
[
5
]);
mysql_free_result
(
res
);
mysql_close
(
m
);
return
tpw
;
}
struct
passwd
*
getMpwuid
(
uid_t
uid
)
{
char
*
QueryStr
=
NULL
;
MYSQL
*
m
;
MYSQL_RES
*
res
;
MYSQL_ROW
row
;
static
struct
passwd
*
tpw
;
char
uidstr
[
64
];
if
(
tpw
)
{
free
(
tpw
->
pw_name
);
free
(
tpw
->
pw_passwd
);
free
(
tpw
->
pw_gecos
);
free
(
tpw
->
pw_dir
);
free
(
tpw
->
pw_shell
);
}
m
=
mysql_init
(
0
);
if
(
!
m
)
return
NULL
;
if
(
!
mysql_real_connect
(
m
,
sql_host
,
sql_user
,
sql_passwd
,
sql_db
,
sql_port
,
sql_socket
,
MFLAGS
))
{
mu_error
(
"MySQL: connect failed: %s"
,
mysql_error
(
m
));
mysql_close
(
m
);
return
NULL
;
}
snprintf
(
uidstr
,
sizeof
(
uidstr
),
"%u"
,
uid
);
QueryStr
=
sql_expand_query
(
sql_getpwuid_query
,
uidstr
);
if
(
!
QueryStr
)
{
mysql_close
(
m
);
return
NULL
;
}
if
(
mysql_query
(
m
,
QueryStr
)
!=
0
)
{
mu_error
(
"MySQL: query failed: %s"
,
mysql_error
(
m
));
mysql_close
(
m
);
return
NULL
;
}
if
((
res
=
mysql_store_result
(
m
))
==
NULL
)
{
mu_error
(
"MySQL: can't store result: %s"
,
mysql_error
(
m
));
mysql_close
(
m
);
return
NULL
;
}
if
((
row
=
mysql_fetch_row
(
res
))
==
NULL
)
{
mu_error
(
"MySQL: can't fetch row: %s"
,
mysql_error
(
m
));
mysql_close
(
m
);
return
NULL
;
}
if
(
!
tpw
)
tpw
=
(
struct
passwd
*
)
xmalloc
(
sizeof
(
struct
passwd
));
tpw
->
pw_name
=
xmalloc
(
strlen
(
row
[
0
]
+
1
));
strcpy
(
tpw
->
pw_name
,
row
[
0
]);
tpw
->
pw_passwd
=
xmalloc
(
strlen
(
row
[
1
])
+
1
);
strcpy
(
tpw
->
pw_passwd
,
row
[
0
]);
tpw
->
pw_uid
=
atoi
(
row
[
1
]);
tpw
->
pw_gid
=
atoi
(
row
[
2
]);
tpw
->
pw_uid
=
atoi
(
row
[
2
]);
tpw
->
pw_gid
=
atoi
(
row
[
3
]);
tpw
->
pw_gecos
=
xmalloc
(
strlen
(
"Mysql User"
)
+
1
);
strcpy
(
tpw
->
pw_gecos
,
"Mysql User"
);
tpw
->
pw_dir
=
xmalloc
(
strlen
(
row
[
3
])
+
1
);
strcpy
(
tpw
->
pw_dir
,
row
[
3
]);
tpw
->
pw_dir
=
xmalloc
(
strlen
(
row
[
4
])
+
1
);
strcpy
(
tpw
->
pw_dir
,
row
[
4
]);
tpw
->
pw_shell
=
xmalloc
(
strlen
(
row
[
4
])
+
1
);
strcpy
(
tpw
->
pw_shell
,
row
[
4
]);
tpw
->
pw_shell
=
xmalloc
(
strlen
(
row
[
5
])
+
1
);
strcpy
(
tpw
->
pw_shell
,
row
[
5
]);
mysql_free_result
(
res
);
mysql_close
(
m
);
...
...
Please
register
or
sign in
to post a comment