Skip to content

Commit b739ba2

Browse files
authored
Merge pull request donapieppo#23 from sshedi/misc-fixes
Misc fixes
2 parents 7f33780 + e8ac930 commit b739ba2

File tree

5 files changed

+36
-40
lines changed

5 files changed

+36
-40
lines changed

Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ test: libnss_ato_test.c
3333

3434
install:
3535
# remeber /lib/libnss_compat.so.2 -> libnss_compat-2.3.6.so
36-
${INSTALL_DATA} libnss_ato.so.2 ${DESTDIR}/${prefix}/lib/libnss_ato-2.3.6.so
37-
${INSTALL_DATA} libnss-ato.3 ${DESTDIR}/${manprefix}/man3
36+
${INSTALL_DATA} -D libnss_ato.so.2 ${DESTDIR}/${prefix}/lib/libnss_ato-2.3.6.so
37+
${INSTALL_DATA} -D libnss-ato.3 ${DESTDIR}/${manprefix}/man3/libnss-ato.3
3838
cd ${DESTDIR}/${prefix}/lib && ln -fs libnss_ato-2.3.6.so libnss_ato.so.2
39+
${INSTALL_DATA} -D libnss-ato.conf ${DESTDIR}/${sysconfdir}/libnss-ato.conf
3940

4041
clean:
4142
rm -f libnss_ato.so.2 libnss_ato_test

libnss-ato.conf

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
test_user:x:1000:1000:Test User,,,:/home/test:/bin/bash
21
# Only the first line of this file is parsed.
32
# All next lines are comments.
43
# You can not set multiple user accounts with this

libnss_ato.c

+18-20
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
* this product may be distributed under the terms of
1010
* the GNU Lesser General Public License.
1111
*
12-
* version 0.2
13-
*
12+
* version 0.2
13+
*
1414
* CHANGELOG:
15-
* strip end of line in reading /etc/libnss-ato
15+
* strip end of line in reading /etc/libnss-ato
1616
* suggested by Kyler Laird
1717
*
1818
* TODO:
1919
*
2020
* check bugs
21-
*
21+
*
2222
*/
2323

2424
#include <nss.h>
@@ -40,8 +40,8 @@
4040
* Extra lines are comments (not processed).
4141
*/
4242

43-
struct passwd *
44-
read_conf()
43+
struct passwd *
44+
read_conf(void)
4545
{
4646
FILE *fd;
4747
struct passwd *conf;
@@ -61,15 +61,15 @@ read_conf()
6161
return conf;
6262
}
6363

64-
/*
64+
/*
6565
* Allocate some space from the nss static buffer. The buffer and buflen
6666
* are the pointers passed in by the C library to the _nss_ntdom_*
67-
* functions.
67+
* functions.
6868
*
69-
* Taken from glibc
69+
* Taken from glibc
7070
*/
7171

72-
static char *
72+
static char *
7373
get_static(char **buffer, size_t *buflen, int len)
7474
{
7575
char *result;
@@ -90,12 +90,11 @@ get_static(char **buffer, size_t *buflen, int len)
9090
return result;
9191
}
9292

93-
94-
enum nss_status
95-
_nss_ato_getpwnam_r( const char *name,
96-
struct passwd *p,
97-
char *buffer,
98-
size_t buflen,
93+
enum nss_status
94+
_nss_ato_getpwnam_r( const char *name,
95+
struct passwd *p,
96+
char *buffer,
97+
size_t buflen,
9998
int *errnop)
10099
{
101100
struct passwd *conf;
@@ -121,7 +120,7 @@ _nss_ato_getpwnam_r( const char *name,
121120
/* pw_name stay as the name given */
122121
strcpy(p->pw_name, name);
123122

124-
if ((p->pw_passwd = get_static(&buffer, &buflen, strlen("x") + 1)) == NULL) {
123+
if ((p->pw_passwd = get_static(&buffer, &buflen, (int)sizeof("x"))) == NULL) {
125124
return NSS_STATUS_TRYAGAIN;
126125
}
127126

@@ -130,22 +129,21 @@ _nss_ato_getpwnam_r( const char *name,
130129
return NSS_STATUS_SUCCESS;
131130
}
132131

133-
enum nss_status
132+
enum nss_status
134133
_nss_ato_getspnam_r( const char *name,
135134
struct spwd *s,
136135
char *buffer,
137136
size_t buflen,
138137
int *errnop)
139138
{
140-
141139
/* If out of memory */
142140
if ((s->sp_namp = get_static(&buffer, &buflen, strlen(name) + 1)) == NULL) {
143141
return NSS_STATUS_TRYAGAIN;
144142
}
145143

146144
strcpy(s->sp_namp, name);
147145

148-
if ((s->sp_pwdp = get_static(&buffer, &buflen, strlen("*") + 1)) == NULL) {
146+
if ((s->sp_pwdp = get_static(&buffer, &buflen, (int)sizeof("*"))) == NULL) {
149147
return NSS_STATUS_TRYAGAIN;
150148
}
151149

libnss_ato_test.c

+9-12
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@
66

77
struct spwd *getspnam(const char *name);
88

9-
int main (int argc, char *argv[]){
9+
int main(int argc, char *argv[]) {
1010

1111
struct passwd *p;
1212
struct spwd *s;
1313

14-
char *usern="pippo.pluto";
15-
16-
if(argc ==2)
17-
{
18-
usern=argv[1];
14+
char *usern = "pippo.pluto";
15+
16+
if (argc == 2) {
17+
usern = argv[1];
1918
}
2019

21-
if (!(p=getpwnam(usern))) {
20+
if (!(p = getpwnam(usern))) {
2221
return -1;
2322
}
24-
23+
2524
printf("FROM PASSWORD:\n");
2625

2726
printf("\tname: %s\n", p->pw_name);
@@ -34,10 +33,8 @@ int main (int argc, char *argv[]){
3433
return -1;
3534
}
3635

37-
printf ("\tname: %s\n", s->sp_namp);
38-
printf ("\tpass: %s\n", s->sp_pwdp);
36+
printf("\tname: %s\n", s->sp_namp);
37+
printf("\tpass: %s\n", s->sp_pwdp);
3938

4039
return 0;
41-
4240
}
43-

rpm/libnss-ato.spec

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@ NSS module to match all request of unknown user to a single user (All To One)
1212
%install
1313
%define _copy_to_buildroot() mkdir -p %{buildroot}%2; cp -r %{_topdir}/%1 %{buildroot}%2
1414

15-
# Copy the necessary files to the buildroot.
15+
# Copy the necessary files to the buildroot.
1616
#
1717
# There are lots of ways to do this:
1818
# - Manually write the necessary mkdir/cp commands
1919
# - Use macros to make writing these commands easier
2020
# - Call a helper script to populate the buildroot (e.g. by parsing debian/*.install)
2121
#
22-
# Here is an example of doing this with macros.
22+
# Here is an example of doing this with macros.
2323
%{_copy_to_buildroot libnss_ato.so.2 /lib64}
24-
ln -s /lib64/libnss_ato.so.2 %{buildroot}/lib64/libnss_ato-2.3.6.so
24+
ln -srv %{buildroot}/lib64/libnss_ato.so.2 %{buildroot}/lib64/libnss_ato-2.3.6.so
2525
%{_copy_to_buildroot libnss-ato.3 /usr/share/man/man3}
26+
%{_copy_to_buildroot libnss-ato.conf /etc}
2627

2728
%debug_package
2829

2930
%files
30-
# Specify the files to package.
3131
/lib64/libnss_ato.so.2
3232
/lib64/libnss_ato-2.3.6.so
33-
/usr/share/man/man3/libnss-ato.3.gz
33+
%config(noreplace) /etc/libnss-ato.conf
34+
/usr/share/man/man3/libnss-ato.3

0 commit comments

Comments
 (0)