make_build_data uses the output of the id command in order to generate the
string in build_data.c indicating who built the program. Unfortunately, the
previous parsing code looked for the presence of a ")" in order to determine
where the user field ended. If the user is not found in the user database,
the output looks more like:
uid=59784003 gid=60243 groups=60243
Instead, now it just calls the glibc helpers and formats the line based
upon those instead of shelling out and trying to parse the output of id.
If it cannot retrieve the username, it just sets the UID.
Signed-off-by: Sargun Dhillon <sargun(a)sargun.me>
---
configure.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/configure.c b/configure.c
index 10bc6e1..8ddec66 100644
--- a/configure.c
+++ b/configure.c
@@ -56,6 +56,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <ctype.h>
+#include <pwd.h>
struct supported_gdb_version;
void build_configure(struct supported_gdb_version *);
@@ -1252,7 +1253,7 @@ count_chars(char *s, char c)
void
make_build_data(char *target)
{
- char *p;
+ struct passwd *passwd;
char hostname[MAXSTRLEN];
char progname[MAXSTRLEN];
char datebuf[MAXSTRLEN];
@@ -1274,14 +1275,15 @@ make_build_data(char *target)
if (gethostname(hostname, MAXSTRLEN) != 0)
hostname[0] = '\0';
- p = fgets(datebuf, 79, fp_date);
+ fgets(datebuf, 79, fp_date);
- p = fgets(idbuf, 79, fp_id);
- p = strstr(idbuf, ")");
- p++;
- *p = '\0';
+ passwd = getpwuid(getuid());
+ if (passwd)
+ sprintf(idbuf, "uid=%d(%s)", passwd->pw_uid, passwd->pw_name);
+ else
+ sprintf(idbuf, "uid=%d", getuid());
- p = fgets(gccversionbuf, 79, fp_gcc);
+ fgets(gccversionbuf, 79, fp_gcc);
lower_case(target_data.program, progname);
--
2.9.3