Browse Source

konfd uses getpwnam() like functions from liblub

Serj Kalichev 2 years ago
parent
commit
2c28a4deb1
2 changed files with 6 additions and 3 deletions
  1. 5 2
      bin/konfd.c
  2. 1 1
      lub/db/db.c

+ 5 - 2
bin/konfd.c

@@ -47,6 +47,7 @@
 #include "lub/argv.h"
 #include "lub/argv.h"
 #include "lub/string.h"
 #include "lub/string.h"
 #include "lub/log.h"
 #include "lub/log.h"
+#include "lub/db.h"
 
 
 #ifndef VERSION
 #ifndef VERSION
 #define VERSION 1.2.2
 #define VERSION 1.2.2
@@ -689,13 +690,14 @@ static int opts_parse(int argc, char *argv[], struct options *opts)
 			break;
 			break;
 		case 'u': {
 		case 'u': {
 #ifdef HAVE_PWD_H
 #ifdef HAVE_PWD_H
-			struct passwd *pwd = getpwnam(optarg);
+			struct passwd *pwd = lub_db_getpwnam(optarg);
 			if (!pwd) {
 			if (!pwd) {
 				fprintf(stderr, "Error: Can't identify user \"%s\"\n",
 				fprintf(stderr, "Error: Can't identify user \"%s\"\n",
 					optarg);
 					optarg);
 				return -1;
 				return -1;
 			}
 			}
 			opts->uid = pwd->pw_uid;
 			opts->uid = pwd->pw_uid;
+			free(pwd);
 #else
 #else
 			fprintf(stderr, "The --user option is not supported.\n");
 			fprintf(stderr, "The --user option is not supported.\n");
 			return -1;
 			return -1;
@@ -704,13 +706,14 @@ static int opts_parse(int argc, char *argv[], struct options *opts)
 		}
 		}
 		case 'g': {
 		case 'g': {
 #ifdef HAVE_GRP_H
 #ifdef HAVE_GRP_H
-			struct group *grp = getgrnam(optarg);
+			struct group *grp = lub_db_getgrnam(optarg);
 			if (!grp) {
 			if (!grp) {
 				fprintf(stderr, "Can't identify group \"%s\"\n",
 				fprintf(stderr, "Can't identify group \"%s\"\n",
 					optarg);
 					optarg);
 				return -1;
 				return -1;
 			}
 			}
 			opts->gid = grp->gr_gid;
 			opts->gid = grp->gr_gid;
+			free(grp);
 #else
 #else
 			fprintf(stderr, "The --group option is not supported.\n");
 			fprintf(stderr, "The --group option is not supported.\n");
 			return -1;
 			return -1;

+ 1 - 1
lub/db/db.c

@@ -14,7 +14,7 @@ struct passwd *lub_db_getpwnam(const char *name)
 {
 {
 	long int size;
 	long int size;
 	char *buf;
 	char *buf;
-	struct passwd *pwbuf; 
+	struct passwd *pwbuf;
 	struct passwd *pw = NULL;
 	struct passwd *pw = NULL;
 	int res = 0;
 	int res = 0;