/**************************************************************************
    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"



void traceForce(int debugMode, int err, const char* format, ...);

/******************************* 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
