Skip to content

Commit

Permalink
* nis/nisplus-parser.h (_nss_nisplus_parse_pwent): Add entry
Browse files Browse the repository at this point in the history
	parameter.
	(_nss_nisplus_parse_pwent_chk): New prototype.
	* nis/nss_nisplus/nisplus-parser.c (_nss_nisplus_parse_pwent):
	Add entry parameter.  Use it for column value in all accesses.
	Move checks for well-formed reply to...
	(_nss_nisplus_parse_pwent_chk): ...here.  New function.
	* nis/nss_nisplus/nisplus-pwd.c: Support SETENT_BATCH_READ option.
  • Loading branch information
Ulrich Drepper committed Apr 29, 2006
1 parent 5b4f9fa commit d08a1d4
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 88 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
2006-04-29 Ulrich Drepper <drepper@redhat.com>

* nis/nisplus-parser.h (_nss_nisplus_parse_pwent): Add entry
parameter.
(_nss_nisplus_parse_pwent_chk): New prototype.
* nis/nss_nisplus/nisplus-parser.c (_nss_nisplus_parse_pwent):
Add entry parameter. Use it for column value in all accesses.
Move checks for well-formed reply to...
(_nss_nisplus_parse_pwent_chk): ...here. New function.
* nis/nss_nisplus/nisplus-pwd.c: Support SETENT_BATCH_READ option.

* nis/nss_nisplus/nisplus-parser.c: Some cleanups. Remove
hidden_def definitions.
* nis/nisplus-parser.h: Add parameter names. Remove hidden_proto
Expand Down
8 changes: 6 additions & 2 deletions nis/nisplus-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
#include <grp.h>
#include <shadow.h>

extern int _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
char *buffer, size_t buflen, int *errnop);
extern int _nss_nisplus_parse_pwent (nis_result *result, size_t entry,
struct passwd *pw, char *buffer,
size_t buflen, int *errnop);
extern int _nss_nisplus_parse_pwent_chk (nis_result *result, struct passwd *pw,
char *buffer, size_t buflen,
int *errnop);
extern int _nss_nisplus_parse_grent (nis_result *result, u_long entry,
struct group *gr, char *buffer,
size_t buflen, int *errnop);
Expand Down
99 changes: 52 additions & 47 deletions nis/nss_nisplus/nisplus-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,106 +33,111 @@


int
_nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
char *buffer, size_t buflen, int *errnop)
_nss_nisplus_parse_pwent_chk (nis_result *result, struct passwd *pw,
char *buffer, size_t buflen, int *errnop)
{
char *first_unused = buffer;
size_t room_left = buflen;
size_t len;

if (result == NULL)
return 0;

if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
|| NIS_RES_NUMOBJ (result) != 1
|| __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
|| strcmp (NIS_RES_OBJECT (result)->EN_data.en_type, "passwd_tbl") != 0
|| NIS_RES_OBJECT (result)->EN_data.en_cols.en_cols_len < 7)
return 0;

if (NISENTRYLEN (0, 0, result) >= room_left)
return _nss_nisplus_parse_pwent (result, 0, pw, buffer, buflen, errnop);
}


int
_nss_nisplus_parse_pwent (nis_result *result, size_t entry, struct passwd *pw,
char *buffer, size_t buflen, int *errnop)
{
char *first_unused = buffer;
size_t room_left = buflen;
size_t len;

if (NISENTRYLEN (entry, 0, result) >= room_left)
{
/* The line is too long for our buffer. */
no_more_room:
*errnop = ERANGE;
return -1;
}

strncpy (first_unused, NISENTRYVAL (0, 0, result),
NISENTRYLEN (0, 0, result));
first_unused[NISENTRYLEN (0, 0, result)] = '\0';
strncpy (first_unused, NISENTRYVAL (entry, 0, result),
NISENTRYLEN (entry, 0, result));
first_unused[NISENTRYLEN (entry, 0, result)] = '\0';
len = strlen (first_unused);
if (len == 0) /* No name ? Should never happen, database is corrupt */
return 0;
pw->pw_name = first_unused;
room_left -= (len + 1);
first_unused += (len + 1);
room_left -= len + 1;
first_unused += len + 1;

if (NISENTRYLEN (0, 1, result) >= room_left)
if (NISENTRYLEN (entry, 1, result) >= room_left)
goto no_more_room;

strncpy (first_unused, NISENTRYVAL (0, 1, result),
NISENTRYLEN (0, 1, result));
first_unused[NISENTRYLEN (0, 1, result)] = '\0';
strncpy (first_unused, NISENTRYVAL (entry, 1, result),
NISENTRYLEN (entry, 1, result));
first_unused[NISENTRYLEN (entry, 1, result)] = '\0';
pw->pw_passwd = first_unused;
len = strlen (first_unused);
room_left -= (len + 1);
first_unused += (len + 1);
room_left -= len + 1;
first_unused += len + 1;

if (NISENTRYLEN(0, 2, result) >= room_left)
if (NISENTRYLEN (entry, 2, result) >= room_left)
goto no_more_room;

strncpy (first_unused, NISENTRYVAL (0, 2, result),
NISENTRYLEN (0, 2, result));
first_unused[NISENTRYLEN (0, 2, result)] = '\0';
strncpy (first_unused, NISENTRYVAL (entry, 2, result),
NISENTRYLEN (entry, 2, result));
first_unused[NISENTRYLEN (entry, 2, result)] = '\0';
len = strlen (first_unused);
if (len == 0) /* If we don't have a uid, it's an invalid shadow entry */
return 0;
pw->pw_uid = strtoul (first_unused, NULL, 10);

if (NISENTRYLEN (0, 3, result) >= room_left)
if (NISENTRYLEN (entry, 3, result) >= room_left)
goto no_more_room;

strncpy (first_unused, NISENTRYVAL (0, 3, result),
NISENTRYLEN (0, 3, result));
first_unused[NISENTRYLEN (0, 3, result)] = '\0';
strncpy (first_unused, NISENTRYVAL (entry, 3, result),
NISENTRYLEN (entry, 3, result));
first_unused[NISENTRYLEN (entry, 3, result)] = '\0';
len = strlen (first_unused);
if (len == 0) /* If we don't have a gid, it's an invalid shadow entry */
return 0;
pw->pw_gid = strtoul (first_unused, NULL, 10);

if (NISENTRYLEN(0, 4, result) >= room_left)
if (NISENTRYLEN(entry, 4, result) >= room_left)
goto no_more_room;

strncpy (first_unused, NISENTRYVAL (0, 4, result),
NISENTRYLEN (0, 4, result));
first_unused[NISENTRYLEN (0, 4, result)] = '\0';
strncpy (first_unused, NISENTRYVAL (entry, 4, result),
NISENTRYLEN (entry, 4, result));
first_unused[NISENTRYLEN (entry, 4, result)] = '\0';
pw->pw_gecos = first_unused;
len = strlen (first_unused);
room_left -= (len + 1);
first_unused += (len + 1);
room_left -= len + 1;
first_unused += len + 1;

if (NISENTRYLEN (0, 5, result) >= room_left)
if (NISENTRYLEN (entry, 5, result) >= room_left)
goto no_more_room;

strncpy (first_unused, NISENTRYVAL (0, 5, result),
NISENTRYLEN (0, 5, result));
first_unused[NISENTRYLEN (0, 5, result)] = '\0';
strncpy (first_unused, NISENTRYVAL (entry, 5, result),
NISENTRYLEN (entry, 5, result));
first_unused[NISENTRYLEN (entry, 5, result)] = '\0';
pw->pw_dir = first_unused;
len = strlen (first_unused);
room_left -= (len + 1);
first_unused += (len + 1);
room_left -= len + 1;
first_unused += len + 1;

if (NISENTRYLEN (0, 6, result) >= room_left)
if (NISENTRYLEN (entry, 6, result) >= room_left)
goto no_more_room;

strncpy (first_unused, NISENTRYVAL (0, 6, result),
NISENTRYLEN (0, 6, result));
first_unused[NISENTRYLEN (0, 6, result)] = '\0';
strncpy (first_unused, NISENTRYVAL (entry, 6, result),
NISENTRYLEN (entry, 6, result));
first_unused[NISENTRYLEN (entry, 6, result)] = '\0';
pw->pw_shell = first_unused;
len = strlen (first_unused);
room_left -= (len + 1);
first_unused += (len + 1);
room_left -= len + 1;
first_unused += len + 1;

return 1;
}
Expand Down
Loading

0 comments on commit d08a1d4

Please sign in to comment.