-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from donald/0.2
0.2
- Loading branch information
Showing
6 changed files
with
44 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#ifndef _GET_SHADOW_LINE_H | ||
#define _GET_SHADOW_LINE_H | ||
|
||
int get_shadow_line_from_server(char *user, char *buf, size_t buflen); | ||
int get_shadow_line(char *user, char **line); | ||
|
||
#endif /* _GET_SHADOW_LINE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,29 @@ | ||
#include <nss.h> | ||
#include <shadow.h> | ||
#include <stdio.h> | ||
#include <sys/types.h> | ||
#include <sys/socket.h> | ||
#include <netinet/in.h> | ||
#include <netinet/ip.h> | ||
#include <strings.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <errno.h> | ||
#include <stdlib.h> | ||
|
||
#include "get_shadow_line.h" | ||
|
||
static long int atol_or_minus1(char *p) { | ||
return *p == '\0' ? -1 : atol(p); | ||
} | ||
|
||
static unsigned long int atoul_or_minus1(char *p) { | ||
return *p == '\0' ? (unsigned long int) -1 : strtoul(p, NULL, 10); | ||
} | ||
#include "common.h" | ||
|
||
enum nss_status _nss_mxshadow_getspnam_r(const char *name, struct spwd *spwd, char *buffer, size_t buflen, int *errnop) { | ||
|
||
int status = get_shadow_line_from_server((char *)name, buffer, buflen); | ||
char *line _cleanup_(free_string) = NULL; | ||
|
||
int status = get_shadow_line((char *)name, &line); | ||
if (status == -1) { | ||
perror(__func__); | ||
*errnop = errno; | ||
return NSS_STATUS_UNAVAIL; | ||
} | ||
if (buffer[0] == '\0') | ||
if (line[0] == '\0') { | ||
errno = ENOENT; | ||
*errnop = errno; | ||
return NSS_STATUS_NOTFOUND; | ||
|
||
char *p; | ||
|
||
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_namp = p; | ||
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_pwdp = p; | ||
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_lstchg = atol_or_minus1(p); | ||
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_min = atol_or_minus1(p); | ||
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_max = atol_or_minus1(p); | ||
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_warn = atol_or_minus1(p); | ||
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_inact = atol_or_minus1(p); | ||
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_expire = atol_or_minus1(p); | ||
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_flag = atoul_or_minus1(p); | ||
} | ||
struct spwd *spbufp; | ||
status = sgetspent_r(line, spwd, buffer, buflen, &spbufp); | ||
if (status == -1) { | ||
*errnop = errno; | ||
return NSS_STATUS_UNAVAIL; | ||
} | ||
return NSS_STATUS_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters