Apply patch: ncpfs-hg-commit-448.patch
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
^autom4te.cache/
|
||||
^config\.log$
|
||||
^config\.status$
|
||||
^contrib/ncp_nss_lib/libnss_ncp\.so\.2$
|
||||
^contrib/ncp_nss_lib/test_ncp_nss$
|
||||
^contrib/pam/Makefile$
|
||||
^contrib/php/Makefile$
|
||||
^contrib/php/Makefile\.in$
|
||||
|
||||
4136
.patches/ncpfs-2.2.6-r6/ncpfs-hg-commit-448.patch
Normal file
4136
.patches/ncpfs-2.2.6-r6/ncpfs-hg-commit-448.patch
Normal file
File diff suppressed because it is too large
Load Diff
111
contrib/ncp_nss_lib/Makefile
Normal file
111
contrib/ncp_nss_lib/Makefile
Normal file
@@ -0,0 +1,111 @@
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
top_srcdir = ../..
|
||||
top_builddir = ../..
|
||||
this_srcdir = ${top_srcdir}/lib
|
||||
|
||||
include ${top_builddir}/Make.rules
|
||||
|
||||
VERSION_SOLIB := 2
|
||||
VERSION_SONAME := 2.3
|
||||
|
||||
vpath %.c ${this_srcdir}
|
||||
|
||||
LIBS :=
|
||||
REENTRANT_CFLAGS := -D_REENTRANT
|
||||
VERSIONED_LINK := yes
|
||||
|
||||
SHARED_NSSLIB := libnss_ncp.so
|
||||
SHARED_NSSLIB_BIN := $(SHARED_NSSLIB).$(VERSION_SOLIB)
|
||||
SHARED_NSSLIB_SONAME := $(SHARED_NSSLIB).$(VERSION_SONAME)
|
||||
|
||||
O_UTILS1 = test_ncp_nss.o\
|
||||
#
|
||||
O_TMP1 =
|
||||
UTILS1 = $(O_UTILS1:%.o=%)
|
||||
|
||||
CCFLAGS += -I.
|
||||
PIC_FLAGS := -fPIC
|
||||
NWCOMPAT := 1
|
||||
|
||||
SHARED_VLINK :=
|
||||
SHARED_VLINK_CFLAGS :=
|
||||
ifeq ($(VERSIONED_LINK),yes)
|
||||
SHARED_VLINK := -Wl,-version-script=${this_srcdir}/libncp.vers
|
||||
SHARED_VLINK_CFLAGS := -DMULTIVERSION
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_ELF),yes)
|
||||
NCP_LIB = libncp.so
|
||||
NCPLIB_DIR = ../../lib
|
||||
LIBDEP = $(NCPLIB_DIR)/$(NCP_LIB)
|
||||
else
|
||||
NCP_LIB = libncp.a
|
||||
NCPLIB_DIR = ../../lib
|
||||
LIBDEP = $(NCPLIB_DIR)/$(NCP_LIB)
|
||||
endif
|
||||
|
||||
STATIC_BASE_OBJ := nss_ncp.o nss_cfgfile.o
|
||||
SHARED_BASE_OBJ := $(STATIC_BASE_OBJ:.o=.do)
|
||||
|
||||
SHARED_O_OBJ := $(SHARED_BASE_OBJ)
|
||||
|
||||
BASE_CFLAGS := -DHAVE_CONFIG_H -DMAKE_NCPLIB -D_GNU_SOURCE
|
||||
|
||||
SHARED_CFLAGS := $(CFLAGS) $(CCFLAGS) $(REENTRANT_CFLAGS) $(PIC_FLAGS) $(SHARED_VLINK_CFLAGS)
|
||||
|
||||
|
||||
.PHONY : all dep install install-dev clean mrproper distclean
|
||||
.PHONY : install_shared install_static install_static_su
|
||||
|
||||
all: $(SHARED_NSSLIB) $(UTILS1)
|
||||
|
||||
install: install_shared
|
||||
|
||||
%.d: %.c %h
|
||||
set -e; $(CC) -M $(STATIC_CFLAGS) $(CFLAGS_$(@:.d=.o)) $(BASE_CFLAGS) $< \
|
||||
| sed 's,\($*\)\.o[ :]*,\1.o \1.do \1.to $@ : ,g' > $@; \
|
||||
[ -s $@ ] || rm -f $@
|
||||
|
||||
$(STATIC_BASE_OBJ): %.o: %.c %.h
|
||||
$(CC) $(STATIC_CFLAGS) $(CFLAGS_$@) $(BASE_CFLAGS) -o $@ -c $<
|
||||
|
||||
|
||||
$(SHARED_BASE_OBJ): %.do: %.c %.h
|
||||
$(CC) $(SHARED_CFLAGS) $(CFLAGS_$(@:.do=.o)) $(BASE_CFLAGS) -o $@ -c $<
|
||||
|
||||
|
||||
$(O_UTILS1) $(O_TMP1): %.o: %.c
|
||||
$(CC) $(CCFLAGS) $(CFLAGS) $(CFLAGS_$@) -o $@ -c $<
|
||||
|
||||
$(UTILS1):: %: %.o $(O_TMP1)
|
||||
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(addsuffix .o,$@) $(OBJS_$@) -L$(top_builddir)/lib -lnss_ncp -lncp $(LDFLAGS_$@)
|
||||
|
||||
|
||||
dep:
|
||||
|
||||
clean:
|
||||
rm -f *.o *.do *.to *~
|
||||
|
||||
mrproper: clean
|
||||
rm -f $(UTILS) $(DISTFILE)
|
||||
|
||||
distclean: mrproper
|
||||
|
||||
install_shared: $(SHARED_NCPLIB_BIN)
|
||||
$(INSTALL) -d $(DESTDIR)$(libsodir)
|
||||
$(INSTALL) $(SHARED_NCPLIB_BIN) $(DESTDIR)$(libsodir)
|
||||
-ldconfig
|
||||
|
||||
|
||||
$(SHARED_NSSLIB): $(SHARED_NSSLIB_BIN)
|
||||
rm -f $@
|
||||
ln -sf $< $@
|
||||
|
||||
$(SHARED_NSSLIB_BIN): $(SHARED_O_OBJ) ${this_srcdir}/libncp.vers
|
||||
$(CC) -shared -o $@ -Wl,-soname=$(SHARED_NSSLIB_SONAME) $(SHARED_VLINK) $(SHARED_O_OBJ) -L$(NCPLIB_DIR) -lncp ${LIBS}
|
||||
|
||||
|
||||
|
||||
29
contrib/ncp_nss_lib/ncpfs.conf
Normal file
29
contrib/ncp_nss_lib/ncpfs.conf
Normal file
@@ -0,0 +1,29 @@
|
||||
[Requester]
|
||||
|
||||
|
||||
[ncp_nss]
|
||||
useTree=1
|
||||
server=INSA_ROOT
|
||||
startCtx=
|
||||
ctrlGroup=
|
||||
doPasswd=1
|
||||
doShadow=1
|
||||
doGroup=1
|
||||
|
||||
defGid=100
|
||||
defShell=/bin/bash
|
||||
debug=1
|
||||
|
||||
fallbackUid=-1
|
||||
fallbackGid=-1
|
||||
|
||||
[pam]
|
||||
useTree=1
|
||||
server=INSA_ROOT
|
||||
searchCtx=PC,S.PC,GCP.PC
|
||||
debug=1
|
||||
mountLocally=1
|
||||
createLocalHome=0
|
||||
|
||||
zenOn=
|
||||
zenOff=
|
||||
333
contrib/ncp_nss_lib/nss_cfgfile.c
Normal file
333
contrib/ncp_nss_lib/nss_cfgfile.c
Normal file
@@ -0,0 +1,333 @@
|
||||
/*
|
||||
nss_cfgfile.c - Configuration file handling
|
||||
Copyright (C) 2000 Petr Vandrovec
|
||||
Copyright (C) 2003 Patrick Pollet
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Revision history:
|
||||
|
||||
1.00 2003, Jan 16 Patrick Pollet <patrick.pollet@insa-lyon.fr>
|
||||
Initial revision, stronly inspired by ncpfs/lib/cfgfile.c
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
#include "private/libncp-lock.h"
|
||||
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/syslog.h>
|
||||
|
||||
#include "nss_cfgfile.h"
|
||||
// temporary define (waiting for a better Makefile)
|
||||
#define GLOBALCFGFILE "/etc/ncpfs.conf"
|
||||
#ifndef GLOBALCFGFILE
|
||||
#error "GLOBALCFGFILE must be defined"
|
||||
#endif
|
||||
|
||||
|
||||
// #define DEBUG 1
|
||||
|
||||
static struct nss_ncp_conf* alloc_nss_ncp_conf (){
|
||||
struct nss_ncp_conf * conf;
|
||||
|
||||
conf= (struct nss_ncp_conf *)malloc(sizeof(*conf));
|
||||
if (!conf)
|
||||
return NULL;
|
||||
return conf;
|
||||
}
|
||||
|
||||
|
||||
void free_nss_ncp_conf (struct nss_ncp_conf *conf){
|
||||
#define FREEFIELD(x) do if (conf->x) {free(conf->x) ; conf->x=NULL;} while (0);
|
||||
if (conf && conf !=&defConf) {
|
||||
FREEFIELD(server);
|
||||
FREEFIELD(startCtx);
|
||||
FREEFIELD(ctrlGroup);
|
||||
FREEFIELD(defShell);
|
||||
}
|
||||
#undef FREEFIELD
|
||||
}
|
||||
|
||||
|
||||
struct cfgFile {
|
||||
ncpt_mutex_t mutex;
|
||||
FILE* file;
|
||||
};
|
||||
|
||||
static struct cfgFile* cfgOpenFile(
|
||||
const char* path,
|
||||
int writeRequired) {
|
||||
struct cfgFile* cfg;
|
||||
|
||||
cfg = (struct cfgFile*)malloc(sizeof(*cfg));
|
||||
if (cfg) {
|
||||
cfg->file = fopen(path, writeRequired ? "r+" : "r");
|
||||
if (cfg->file) {
|
||||
ncpt_mutex_init(&cfg->mutex);
|
||||
} else {
|
||||
free(cfg);
|
||||
cfg = NULL;
|
||||
}
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
|
||||
static void cfgClose(
|
||||
struct cfgFile* cfg) {
|
||||
ncpt_mutex_lock(&cfg->mutex);
|
||||
fclose(cfg->file);
|
||||
ncpt_mutex_destroy(&cfg->mutex);
|
||||
free(cfg);
|
||||
}
|
||||
|
||||
|
||||
struct check {
|
||||
const char *option; /* configuration option */
|
||||
int mandatory; /* can be empty or null */
|
||||
int found; /*set to TRUE if found in cfg file */
|
||||
void ** value_ptr; /* temporary storage place */
|
||||
int isNum; /* 1 is numeric, 0 is string*/
|
||||
const char* defValue;
|
||||
};
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
void printResults (const char * infos,struct check * results) {
|
||||
struct check* ptr;
|
||||
printf ("%s\n",infos);
|
||||
for (ptr=results; ptr->option; ptr++) {
|
||||
if (ptr->isNum)
|
||||
printf ("option=%s mandatory=%d found=%d value=%d isNum=%d defvalue=%s\n",
|
||||
ptr->option,ptr->mandatory,ptr->found,(int*)*ptr->value_ptr,ptr->isNum,ptr->defValue);
|
||||
else
|
||||
printf ("option=%s mandatory=%d found=%d value=%s isNum=%d defvalue=%s\n",
|
||||
ptr->option,ptr->mandatory,ptr->found,(char*)*ptr->value_ptr,ptr->isNum,ptr->defValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void printConf (const char* infos,struct nss_ncp_conf * conf) {
|
||||
printf ("%s\n",infos);
|
||||
printf ("debug=%d useTree=%d server=%s startCtx=%s ctrlGroup=%s defGid=%d defShell=%s fallbackUid=%d fallbackGid=%d "
|
||||
"doPassword=%d doGroup=%d doShadow=%d\n",
|
||||
conf->debug,conf->useTree,conf->server,conf->startCtx,
|
||||
conf->ctrlGroup,conf->defGid,conf->defShell,conf->fallbackUid,conf->fallbackGid,
|
||||
conf->doPassword,conf->doGroup,conf->doShadow);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static int process_line (char* cptr, struct check *ptr) {
|
||||
|
||||
char* sptr; // start of real value
|
||||
char* eptr; // end of real value
|
||||
char* errPtr; // err
|
||||
|
||||
char ec;
|
||||
char cc;
|
||||
|
||||
while (*cptr && isspace(*cptr))
|
||||
cptr++;
|
||||
if (*cptr != '=' && *cptr != ':')
|
||||
return 1; //no equal sign found
|
||||
cptr++;
|
||||
|
||||
while (*cptr && isspace(*cptr))
|
||||
cptr++;
|
||||
|
||||
// space are allowed in value only if surrounded by " or ' (eg a NDS control group)
|
||||
if (*cptr == '"' || *cptr == '\'')
|
||||
ec = *cptr++;
|
||||
else
|
||||
ec = 0;
|
||||
sptr=cptr;
|
||||
eptr=cptr;
|
||||
while ((cc = *cptr++) != 0) {
|
||||
if (cc == '\n')
|
||||
break;
|
||||
if (!ec && isspace(cc))
|
||||
break;
|
||||
if (cc == ec)
|
||||
break;
|
||||
eptr++;
|
||||
}
|
||||
*eptr = 0;
|
||||
if (ptr->isNum) {
|
||||
(int *)*ptr->value_ptr=strtoul (sptr,&errPtr,0);
|
||||
ptr->found= ((*sptr) && !(*errPtr)); //not empty and no error
|
||||
} else {
|
||||
if (eptr>sptr) { // do not take an empty string value
|
||||
char *v=strdup(sptr);
|
||||
if (v) {
|
||||
(char*) *ptr->value_ptr=v;
|
||||
ptr->found= TRUE;
|
||||
}else
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fix_conf (struct check *results) {
|
||||
struct check* ptr;
|
||||
|
||||
for (ptr=results; ptr->option; ptr++) {
|
||||
if (! ptr->found) {
|
||||
if (ptr->mandatory) {
|
||||
traceForce(0,LOG_ERR, "ncp_nss aborting :missing mandatory information '%s=' in config file %s ",ptr->option,GLOBALCFGFILE);
|
||||
return 1;
|
||||
}
|
||||
if (ptr->isNum) {
|
||||
(int *)*ptr->value_ptr=strtoul (ptr->defValue,NULL,0);
|
||||
}else {
|
||||
char * v=strdup(ptr->defValue);
|
||||
if (v)
|
||||
(char*) *ptr->value_ptr=v;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static struct nss_ncp_conf *read_conf_file( const char * mySection, struct cfgFile *cfg) {
|
||||
|
||||
struct nss_ncp_conf *conf;
|
||||
|
||||
conf=alloc_nss_ncp_conf ();
|
||||
if (!conf)
|
||||
return NULL;
|
||||
{
|
||||
struct nss_ncp_conf * pconf=conf;
|
||||
struct check check_confs[] = {
|
||||
/*option mandat found value_ptr isNum defValue */
|
||||
{"debug", FALSE,FALSE,(void**)&conf->debug, TRUE, "0"},
|
||||
{"useTree", FALSE,FALSE,(void**)&conf->useTree, TRUE, "0"},
|
||||
{"server", TRUE,FALSE, (void**)&conf->server, FALSE, ""},
|
||||
{"startCtx", FALSE,FALSE,(void**)&conf->startCtx, FALSE, ""},
|
||||
{"ctrlGroup", FALSE,FALSE,(void**)&conf->ctrlGroup, FALSE, ""},
|
||||
{"defGid", FALSE,FALSE,(void**)&conf->defGid, TRUE, "100"},
|
||||
{"defShell", FALSE,FALSE,(void**)&conf->defShell, FALSE, "/bin/bash"},
|
||||
{"fallbackUid", FALSE,FALSE,(void**)&conf->fallbackUid, TRUE, "-1"},
|
||||
{"fallbackGid", FALSE,FALSE,(void**)&conf->fallbackGid, TRUE, "-1"},
|
||||
{"doPasswd", FALSE,FALSE,(void**)&conf->doPassword, TRUE, "0"},
|
||||
{"doGroup", FALSE,FALSE,(void**)&conf->doGroup, TRUE, "0"},
|
||||
{"doShadow", FALSE,FALSE,(void**)&conf->doShadow, TRUE, "0"},
|
||||
{NULL , FALSE,FALSE,NULL, FALSE, NULL}
|
||||
};
|
||||
|
||||
char cfgline[16384];
|
||||
size_t seclen = strlen(mySection);
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
// DO NOT DO IT A a second call (using test_ncp_nss -2) coredump !!!
|
||||
// printResults("before reading CFG",check_confs);
|
||||
#endif
|
||||
ncpt_mutex_lock(&cfg->mutex);
|
||||
//rewind(cfg->file);
|
||||
while (fgets(cfgline, sizeof(cfgline)-1, cfg->file)) {
|
||||
char* cptr = cfgline;
|
||||
struct check* ptr;
|
||||
|
||||
while (*cptr && isspace(*cptr))
|
||||
cptr++;
|
||||
if (*cptr != '[')
|
||||
continue;
|
||||
sstart:;
|
||||
if (strncasecmp(++cptr, mySection, seclen))
|
||||
continue;
|
||||
if (cptr[seclen] != ']')
|
||||
continue;
|
||||
while (fgets(cfgline, sizeof(cfgline) - 1, cfg->file)) {
|
||||
cptr = cfgline;
|
||||
|
||||
while (*cptr && isspace(*cptr))
|
||||
cptr++;
|
||||
if (!*cptr)
|
||||
continue; //empty line
|
||||
if (*cptr == '[') // start of another section
|
||||
goto ssend;
|
||||
for (ptr=check_confs; ptr->option; ptr++) {
|
||||
size_t keylen=strlen(ptr->option);
|
||||
if (!strncasecmp(cptr, ptr->option,keylen)) {
|
||||
cptr += keylen;
|
||||
process_line (cptr,ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ssend:
|
||||
#ifdef DEBUG
|
||||
printResults("after reading CFG no error",check_confs);
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
printConf("before fixing ",conf);
|
||||
#endif
|
||||
|
||||
if (!fix_conf (check_confs)) { // fill in missing values with default,
|
||||
#ifdef DEBUG
|
||||
printConf("after fixing ",conf);
|
||||
#endif
|
||||
ncpt_mutex_unlock(&cfg->mutex);
|
||||
return conf;
|
||||
}
|
||||
|
||||
error:
|
||||
#ifdef DEBUG
|
||||
printResults("after reading CFG error",check_confs);
|
||||
#endif
|
||||
ncpt_mutex_unlock(&cfg->mutex);
|
||||
free_nss_ncp_conf(conf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct nss_ncp_conf * parse_conf (char * confFile) {
|
||||
|
||||
struct cfgFile *cfg;
|
||||
struct nss_ncp_conf *conf;
|
||||
#ifdef DEBUG
|
||||
printf("entering parse_conf\n");
|
||||
#endif
|
||||
//return &defConf;
|
||||
cfg = cfgOpenFile(GLOBALCFGFILE, FALSE);
|
||||
if (!cfg)
|
||||
return NULL;
|
||||
conf=read_conf_file(NSS_SECTION,cfg);
|
||||
cfgClose(cfg);
|
||||
#ifdef DEBUG
|
||||
if (conf)
|
||||
printConf("final value ",conf);
|
||||
#endif
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
30
contrib/ncp_nss_lib/nss_cfgfile.h
Normal file
30
contrib/ncp_nss_lib/nss_cfgfile.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef HAVE_NSS_CFGFILE
|
||||
#define HAVE_NSS_CFGFILE
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
#define NSS_SECTION "ncp_nss"
|
||||
struct nss_ncp_conf {
|
||||
int debug;
|
||||
int useTree; // use Tree connection or server connection
|
||||
char * server; // name of server or tree
|
||||
char * startCtx; // start searching is this context (and below)
|
||||
char * ctrlGroup; // limit search to members of this NDS group for passwd and shadow
|
||||
gid_t defGid; // if no primary group found in NDS use this value
|
||||
char * defShell; // if no shell found in NDS use this value
|
||||
uid_t fallbackUid; // if no UID found in NDS use this one (-1= skip user, NFS_NOBODY= use this UID)
|
||||
gid_t fallbackGid; // if no GID found in NDS use this one (-1= skip group, NFS_NOBODY= use this GID)
|
||||
int doPassword; // if 0, will return immediarly NSS_STATUS_UNAVAILABLE even if ncp is listed in /etc/nsswitch.conf
|
||||
int doGroup; // if 0, will return immediarly NSS_STATUS_UNAVAILABLE even if ncp is listed in /etc/nsswitch.conf
|
||||
int doShadow; // if 0, will return immediarly NSS_STATUS_UNAVAILABLE even if ncp is listed in /etc/nsswitch.conf
|
||||
};
|
||||
|
||||
|
||||
|
||||
static struct nss_ncp_conf defConf ={0,TRUE,"INSA_ROOT","[Root]",NULL,100,"/bin/bash",-1,-1,TRUE,TRUE,TRUE};
|
||||
|
||||
struct nss_ncp_conf * parse_conf (char * confFile);
|
||||
void free_nss_ncp_conf (struct nss_ncp_conf *conf);
|
||||
|
||||
#endif
|
||||
3091
contrib/ncp_nss_lib/nss_ncp.c
Normal file
3091
contrib/ncp_nss_lib/nss_ncp.c
Normal file
File diff suppressed because it is too large
Load Diff
175
contrib/ncp_nss_lib/nss_ncp.h
Normal file
175
contrib/ncp_nss_lib/nss_ncp.h
Normal file
@@ -0,0 +1,175 @@
|
||||
/**************************************************************************
|
||||
nss_ncp.h header for NSS for NDS
|
||||
|
||||
Copyright (C) 2002 Patrick Pollet
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Revision history:
|
||||
|
||||
1.00 2003, January 06 Patrick Pollet <patrick.pollet@insa-lyon.fr>
|
||||
initial release
|
||||
|
||||
************************************************************************/
|
||||
#ifndef HAVE_NSS_NCP_H
|
||||
#define HAVE_NSS_NCP_H
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <ncp/nwnet.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <shadow.h>
|
||||
#include <sys/syslog.h>
|
||||
|
||||
#include <nss.h>
|
||||
|
||||
|
||||
|
||||
// USE_DUMMY_ATTRibutes must be set in the Makefile
|
||||
//#define USING_DUMMY_ATTRIBUTES
|
||||
|
||||
#ifndef USING_DUMMY_ATTRIBUTES
|
||||
// the real ones
|
||||
#define ATTR_UID "UNIX:UID"
|
||||
#define ATTR_PGNAME "UNIX:Primary GroupName"
|
||||
#define ATTR_PGID "UNIX:Primary GroupID"
|
||||
#define ATTR_GID "UNIX:GID"
|
||||
#define ATTR_SHELL "UNIX:Login Shell"
|
||||
#define ATTR_COM "UNIX:Comments"
|
||||
#define ATTR_HOME "UNIX:Home Directory"
|
||||
#else
|
||||
// dummy attributes for testing
|
||||
// created with Schemax with the same syntax
|
||||
// and associated to user class and group class
|
||||
#define ATTR_UID "LINUX:UID"
|
||||
#define ATTR_PGNAME "LINUX:Primary GroupName"
|
||||
#define ATTR_PGID "LINUX:Primary GroupID"
|
||||
#define ATTR_GID "LINUX:GID"
|
||||
#define ATTR_SHELL "LINUX:Login Shell"
|
||||
#define ATTR_COM "LINUX:Comments"
|
||||
#define ATTR_HOME "LINUX:Home Directory"
|
||||
#endif
|
||||
|
||||
// the attribute used to test presence of NDS8
|
||||
// either real or dummy (not used yet)
|
||||
#define ATTR_NDS8 ATTR_UID
|
||||
|
||||
// other attributes used
|
||||
// absent NDS8 attributes are searched in L attribute
|
||||
// also new properties ( Zenux Flags, Other group...)
|
||||
|
||||
#define ATTR_CN "CN"
|
||||
#define ATTR_LOCATION "L"
|
||||
|
||||
#define ATTR_GRP_MBS "Group Membership"
|
||||
#define ATTR_MEMBERS "Member"
|
||||
#define ATTR_FULL_NAME "Full Name"
|
||||
|
||||
#define ATTR_DATE_PWD_EXPIRE "Password Expiration Time"
|
||||
#define ATTR_INT_PWD_EXPIRE "Password Expiration Interval"
|
||||
#define ATTR_GRACE_LIMIT "Login Grace Limit"
|
||||
#define ATTR_DATE_ACCT_EXPIRE "Login Expiration Time"
|
||||
|
||||
|
||||
// the proper naming attribute may be customized here (must be a CI_STRING )
|
||||
#define ATTR_GECOS ATTR_FULL_NAME
|
||||
|
||||
// syntaxes of the used attributes
|
||||
#define SYN_CN SYN_CI_STRING
|
||||
#define SYN_LOCATION SYN_CI_STRING
|
||||
#define SYN_UID SYN_INTEGER
|
||||
#define SYN_PGNAME SYN_DIST_NAME
|
||||
#define SYN_PGID SYN_INTEGER
|
||||
#define SYN_GID SYN_INTEGER
|
||||
#define SYN_SHELL SYN_CE_STRING
|
||||
#define SYN_COM SYN_CI_STRING
|
||||
#define SYN_HOME SYN_CE_STRING
|
||||
#define SYN_GRP_MBS SYN_DIST_NAME
|
||||
#define SYN_MEMBERS SYN_DIST_NAME
|
||||
|
||||
|
||||
|
||||
#define QF_DEBUG 0x0001
|
||||
#define QF_VERBOSE 0x0002
|
||||
|
||||
#define NFS_NOBODY = 65534
|
||||
#define CNF_FILE "/etc/nss_ncp.conf"
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************* NSS API ***************************************/
|
||||
|
||||
|
||||
enum nss_status _nss_ncp_initgroups (const char *userName, gid_t group,
|
||||
long int *start, long int *size, gid_t * groups,
|
||||
long int limit,int *errnop);
|
||||
|
||||
|
||||
enum nss_status _nss_ncp_getpwnam_r (const char* name, struct passwd *pwd,
|
||||
char * buffer, size_t buflen, int * errnop);
|
||||
|
||||
|
||||
|
||||
enum nss_status _nss_ncp_getpwuid_r (uid_t uid, struct passwd *pwd,
|
||||
char * buffer, size_t buflen, int * errnop);
|
||||
|
||||
|
||||
enum nss_status _nss_ncp_getgrnam_r (const char* name, struct group *grp,
|
||||
char * buffer, size_t buflen, int * errnop);
|
||||
|
||||
|
||||
|
||||
enum nss_status _nss_ncp_getspnam_r (const char * name, struct spwd *spw,
|
||||
char *buffer, size_t buflen,int * errnop);
|
||||
|
||||
|
||||
enum nss_status _nss_ncp_getgrgid_r (gid_t gid, struct group *grp,
|
||||
char * buffer, size_t buflen, int * errnop);
|
||||
|
||||
|
||||
|
||||
enum nss_status _nss_ncp_setpwent(void);
|
||||
|
||||
enum nss_status _nss_ncp_setgrent(void);
|
||||
|
||||
enum nss_status _nss_ncp_setspent (void);
|
||||
|
||||
enum nss_status _nss_ncp_endpwent(void);
|
||||
|
||||
enum nss_status _nss_ncp_endgrent(void);
|
||||
|
||||
enum nss_status _nss_ncp_endspent (void);
|
||||
|
||||
enum nss_status _nss_ncp_getpwent_r(struct passwd *pwd, char * buffer, size_t buflen, int * errnop);
|
||||
|
||||
enum nss_status _nss_ncp_getgrent_r(struct group *grp,char * buffer, size_t buflen, int * errnop);
|
||||
|
||||
|
||||
enum nss_status _nss_ncp_getspent_r (struct spwd *spw,char * buffer, size_t buflen,int * errnop);
|
||||
|
||||
#endif
|
||||
318
contrib/ncp_nss_lib/test_ncp_nss.c
Normal file
318
contrib/ncp_nss_lib/test_ncp_nss.c
Normal file
@@ -0,0 +1,318 @@
|
||||
/**************************************************************************
|
||||
getpwduid.c:test program for NSS for NDS
|
||||
|
||||
Copyright (C) 2002 Patrick Pollet
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Revision history:
|
||||
|
||||
1.00 2003, January 06 Patrick Pollet <patrick.pollet@insa-lyon.fr>
|
||||
initial release
|
||||
1.01 2003, January 08 Patrick Pollet <patrick.pollet@insa-lyon.fr>
|
||||
added conf structure and control group
|
||||
added optional fallback UID and GID if none found in NDS (default is to skip user,group)
|
||||
1.02 2003, January 09 Patrick Pollet <patrick.pollet@insa-lyon.fr>
|
||||
added initgroups
|
||||
1.03 2003, January 10 Patrick Pollet <patrick.pollet@insa-lyon.fr>
|
||||
fixed bug in nds_user_info2 (bad structure received by nds_user_location2)
|
||||
1.04 2003, January 11 Patrick Pollet <patrick.pollet@insa-lyon.fr>
|
||||
fixed setting ndsXXX=NULL trees in case of errors in _nss_ncp_setxxent()
|
||||
made always NAME_CONTEXT=[Root] in CreateContextAndConn
|
||||
calling NWCCloseIteration only it some errors has occured in the search
|
||||
1.05
|
||||
modified to use nss_ncp.so
|
||||
************************************************************************/
|
||||
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <ncp/nwnet.h>
|
||||
|
||||
#ifdef VERBOSE
|
||||
#include <ncp/ncplib.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "private/libintl.h"
|
||||
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <shadow.h>
|
||||
#include <sys/syslog.h>
|
||||
|
||||
#include <nss.h>
|
||||
|
||||
#include "nss_ncp.h"
|
||||
#include "nss_cfgfile.h"
|
||||
|
||||
|
||||
|
||||
/**************** TESTING ******************/
|
||||
|
||||
static void print_passwd (struct passwd pwd){
|
||||
printf("%s:%s:%d:%d:%s:%s:%s\n",pwd.pw_name,pwd.pw_passwd,pwd.pw_uid,pwd.pw_gid,pwd.pw_gecos,pwd.pw_dir,pwd.pw_shell);
|
||||
}
|
||||
|
||||
static void print_group (struct group grp){
|
||||
char ** mmb; int num;
|
||||
printf("%s:%s:%d:",grp.gr_name,grp.gr_passwd,grp.gr_gid);
|
||||
for (mmb=grp.gr_mem,num=0;*mmb; mmb++,num++) {
|
||||
if (num)
|
||||
printf(",");
|
||||
printf ("%s",*mmb);
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
}
|
||||
|
||||
static void print_shadow (struct spwd spw){
|
||||
printf("%s:%s:%ld:%ld:%ld:%ld:%ld:%ld:%ld\n",spw.sp_namp,spw.sp_pwdp,spw.sp_lstchg,spw.sp_min,spw.sp_max,spw.sp_warn,spw.sp_inact,spw.sp_expire,spw.sp_flag);
|
||||
}
|
||||
|
||||
|
||||
static void print_user_groups(gid_t * groups, long int start, long int size){
|
||||
int i;
|
||||
printf("start=%d size=%d\n",start,size);
|
||||
for (i=0; i<start; i++)
|
||||
printf("%d ",groups[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void give_details_on_user_groups(gid_t *groups, long int start){
|
||||
struct group grp;
|
||||
char buffer[65000];
|
||||
long int i;
|
||||
for (i=0; i<start;i++) {
|
||||
enum nss_status err=_nss_ncp_getgrgid_r (groups[i],&grp,buffer,sizeof(buffer),&errno);
|
||||
if (err==NSS_STATUS_SUCCESS)
|
||||
print_group(grp);
|
||||
else printf("nss result is %d for group %d\n",err,groups[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#define _(X) gettext(X)
|
||||
|
||||
static char *progname;
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr, _("usage: %s [options]\n"), progname);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
static void help(void)
|
||||
{
|
||||
printf(_("\n"
|
||||
"usage: %s [options]\n"), progname);
|
||||
printf(_("\n"
|
||||
"-h Print this help text\n"
|
||||
"-u id Unix User passwd info to search by uid in NDS\n"
|
||||
"-n login Unix User passwd infos to search by name in NDS\n"
|
||||
"-s login Unix User shadow infos to search by name in NDS\n"
|
||||
"-i grpid Unix group to search by gid in NDS\n"
|
||||
"-g grpname Unix group to search by name in NDS\n"
|
||||
"-m login Get Unix groups of user login\n"
|
||||
"-U all Unix users to search in NDS\n"
|
||||
"-G all Unix groups to search in NDS\n"
|
||||
"-S all Unix shadows to search in NDS\n"
|
||||
"-D verbose mode (fill /var/log/secure && screen)\n"
|
||||
"-T treeName use this Tree \n"
|
||||
"-B serverName use this server\n"
|
||||
"-C NDS ctx start in this context (default=[Root])\n"
|
||||
"-O NDS group restrict user's search to this group\n"
|
||||
"-f fallbackID if no UID,GID found in NDS use this one (default=-1 skip user & group)\n"
|
||||
"-2 show the BUG (two calls )\n"
|
||||
"\n"));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
static void error ( char * s) {
|
||||
printf (_("\n%s\n"),s);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
** main
|
||||
*/
|
||||
int main (int argc, char** argv) {
|
||||
|
||||
const char* userName=NULL;
|
||||
uid_t userId=-1;
|
||||
const char* groupName=NULL;
|
||||
gid_t groupId=-1;
|
||||
const char* shadowName=NULL;
|
||||
const char* memberName=NULL;
|
||||
int opt;
|
||||
int allUsers=0;
|
||||
int allGroups=0;
|
||||
int allShadows=0;
|
||||
char buffer[65000];
|
||||
int nbCalls=1;
|
||||
|
||||
struct passwd pwd;
|
||||
struct group grp;
|
||||
struct spwd spw;
|
||||
enum nss_status err;
|
||||
|
||||
progname = argv[0];
|
||||
while ((opt = getopt(argc, argv, "h?u:n:g:i:s:m:T:B:C:O:f:UGSD2")) != EOF)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'n':
|
||||
userName = optarg;
|
||||
break;
|
||||
case 'm':
|
||||
memberName = optarg;
|
||||
break;
|
||||
case 's':
|
||||
shadowName = optarg;
|
||||
break;
|
||||
case 'g':
|
||||
groupName = optarg;
|
||||
break;
|
||||
case 'i':
|
||||
groupId = strtoul(optarg, NULL, 0);
|
||||
break;
|
||||
case 'u':
|
||||
userId = strtoul(optarg, NULL, 0);
|
||||
break;
|
||||
case 'U':
|
||||
allUsers=1;
|
||||
break;
|
||||
case 'G':
|
||||
allGroups=1;
|
||||
break;
|
||||
case 'S':
|
||||
allShadows=1;
|
||||
break;
|
||||
case 'D':
|
||||
defConf.debug=QF_DEBUG;
|
||||
break;
|
||||
case 'T':
|
||||
defConf.server=optarg;
|
||||
defConf.useTree=1;
|
||||
break;
|
||||
case 'B':
|
||||
defConf.server=optarg;
|
||||
defConf.useTree=0;
|
||||
break;
|
||||
case 'C':
|
||||
defConf.startCtx=optarg;
|
||||
break;
|
||||
case 'O':
|
||||
defConf.ctrlGroup=optarg;
|
||||
break;
|
||||
case 'f':
|
||||
defConf.fallbackUid=strtoul(optarg, NULL, 0);
|
||||
defConf.fallbackGid=strtoul(optarg, NULL, 0);
|
||||
break;
|
||||
case '2':
|
||||
nbCalls=2;
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
help();
|
||||
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
if (defConf.debug)
|
||||
openlog("ncp_nss", LOG_PID, LOG_AUTHPRIV);
|
||||
|
||||
while(nbCalls--) { // do it once or twice (freeze at the second !!!!)
|
||||
|
||||
if (userName) {
|
||||
printf ("searching in passwd for login %s\n",userName);
|
||||
if (_nss_ncp_getpwnam_r (userName,&pwd,buffer,sizeof(buffer),&errno)==NSS_STATUS_SUCCESS)
|
||||
print_passwd(pwd);
|
||||
}
|
||||
if (memberName) {
|
||||
#define MAX_GRP 30
|
||||
gid_t groups[MAX_GRP];
|
||||
long int start=0;
|
||||
long int size=MAX_GRP;
|
||||
printf ("searching groups of %s\n",memberName);
|
||||
if ( _nss_ncp_initgroups (memberName, /*999 */ defConf.defGid,&start,&size,groups,0,&errno)==NSS_STATUS_SUCCESS) {
|
||||
//long int *start, long int *size, gid_t * groups,long int limit,int *errnop) {
|
||||
print_user_groups(groups,start,size);
|
||||
give_details_on_user_groups(groups,start);// FREEZE AT THIS SECOND CALL to NWCCOpenConnByNAME !!!!
|
||||
}
|
||||
|
||||
}
|
||||
if (userId != -1) {
|
||||
printf ("searching in passwd for uid %d\n",userId);
|
||||
if ( _nss_ncp_getpwuid_r (userId, &pwd,buffer,sizeof(buffer),&errno)==NSS_STATUS_SUCCESS)
|
||||
print_passwd(pwd);
|
||||
}
|
||||
|
||||
if (allUsers) {
|
||||
_nss_ncp_setpwent();
|
||||
|
||||
while ( _nss_ncp_getpwent_r(&pwd,buffer,sizeof(buffer),&errno)==NSS_STATUS_SUCCESS)
|
||||
print_passwd(pwd);
|
||||
_nss_ncp_endpwent();
|
||||
}
|
||||
|
||||
if (groupName) {
|
||||
printf ("searching in group for %s\n",groupName);
|
||||
if (_nss_ncp_getgrnam_r (groupName,&grp,buffer,sizeof(buffer),&errno)==NSS_STATUS_SUCCESS) {
|
||||
print_group(grp);
|
||||
}
|
||||
}
|
||||
|
||||
if (groupId != -1) {
|
||||
printf ("searching in group for gid %d\n",groupId);
|
||||
if ( _nss_ncp_getgrgid_r (groupId, &grp,buffer,sizeof(buffer),&errno)==NSS_STATUS_SUCCESS)
|
||||
print_group(grp);
|
||||
}
|
||||
|
||||
if (allGroups) {
|
||||
_nss_ncp_setgrent();
|
||||
|
||||
while ( _nss_ncp_getgrent_r(&grp,buffer,sizeof(buffer),&errno)==NSS_STATUS_SUCCESS)
|
||||
print_group(grp);
|
||||
_nss_ncp_endgrent();
|
||||
}
|
||||
|
||||
if (shadowName) {
|
||||
printf ("searching in shadow for login %s\n",shadowName);
|
||||
if (_nss_ncp_getspnam_r (shadowName,&spw,buffer,sizeof(buffer),&errno)==NSS_STATUS_SUCCESS)
|
||||
print_shadow(spw);
|
||||
}
|
||||
|
||||
if (allShadows) {
|
||||
_nss_ncp_setspent();
|
||||
while ( _nss_ncp_getspent_r(&spw,buffer,sizeof(buffer),&errno)==NSS_STATUS_SUCCESS)
|
||||
print_shadow(spw);
|
||||
_nss_ncp_endspent();
|
||||
}
|
||||
}
|
||||
|
||||
if (defConf.debug)
|
||||
closelog();
|
||||
exit(0);
|
||||
}
|
||||
Reference in New Issue
Block a user