Browse Source

The FreeBSD has no _SC_GETPW_R_SIZE_MAX macroses

git-svn-id: https://klish.googlecode.com/svn/trunk@506 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 12 years ago
parent
commit
5190de648f
2 changed files with 18 additions and 0 deletions
  1. 2 0
      clish/callback_access.c
  2. 16 0
      lub/db/db.c

+ 2 - 0
clish/callback_access.c

@@ -45,6 +45,8 @@ bool_t clish_access_callback(const clish_shell_t * shell, const char *access)
 		/* The internal loop goes trough the system group list */
 		for (i = 0; i < num_groups; i++) {
 			struct group *ptr = lub_db_getgrgid(group_list[i]);
+			if (!ptr)
+				continue;
 			if (0 == strcmp(ptr->gr_name, tmp_access)) {
 				/* The current user is permitted to use this command */
 				allowed = BOOL_TRUE;

+ 16 - 0
lub/db/db.c

@@ -15,7 +15,11 @@ struct passwd *lub_db_getpwnam(const char *name)
 	struct passwd *pw = NULL;
 	int res = 0;
 
+#ifdef _SC_GETPW_R_SIZE_MAX
 	size = sysconf(_SC_GETPW_R_SIZE_MAX);
+#else
+	size = 1024;
+#endif
 	pwbuf = malloc(sizeof(*pwbuf) + size);
 	if (!pwbuf)
 		return NULL;
@@ -42,7 +46,11 @@ struct passwd *lub_db_getpwuid(uid_t uid)
 	struct passwd *pw = NULL;
 	int res = 0;
 
+#ifdef _SC_GETPW_R_SIZE_MAX
 	size = sysconf(_SC_GETPW_R_SIZE_MAX);
+#else
+	size = 1024;
+#endif
 	pwbuf = malloc(sizeof(*pwbuf) + size);
 	if (!pwbuf)
 		return NULL;
@@ -70,7 +78,11 @@ struct group *lub_db_getgrnam(const char *name)
 	struct group *gr = NULL;
 	int res = 0;
 
+#ifdef _SC_GETGR_R_SIZE_MAX
 	size = sysconf(_SC_GETGR_R_SIZE_MAX);
+#else
+	size = 1024;
+#endif
 	grbuf = malloc(sizeof(*grbuf) + size);
 	if (!grbuf)
 		return NULL;
@@ -98,7 +110,11 @@ struct group *lub_db_getgrgid(gid_t gid)
 	struct group *gr = NULL;
 	int res = 0;
 
+#ifdef _SC_GETGR_R_SIZE_MAX
 	size = sysconf(_SC_GETGR_R_SIZE_MAX);
+#else
+	size = 1024;
+#endif
 	grbuf = malloc(sizeof(struct group) + size);
 	if (!grbuf)
 		return NULL;