- group database API. oops and oh dear, the threat has been carried out:
[samba.git] / source3 / passdb / nispass.c
1 /*
2  * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup
3  * Copyright (C) Andrew Tridgell 1992-1998 Modified by Jeremy Allison 1995.
4  * Copyright (C) Benny Holmgren 1998 <bigfoot@astrakan.hgs.se> 
5  * Copyright (C) Luke Kenneth Casson Leighton 1996-1998.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License as published by the Free
9  * Software Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  * 
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc., 675
19  * Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #ifdef WITH_NISPLUS
23
24 #include "includes.h"
25 #include <rpcsvc/nis.h>
26
27 extern int      DEBUGLEVEL;
28
29 static int gotalarm;
30
31 /***************************************************************
32
33  the fields for the NIS+ table, generated from mknissmbpwtbl.sh, are:
34
35         name=S,nogw=r 
36         uid=S,nogw=r 
37                 user_rid=S,nogw=r
38                 smb_grpid=,nw+r
39                 group_rid=,nw+r
40                 acb=,nw+r
41                           
42         lmpwd=C,nw=,g=r,o=rm 
43         ntpwd=C,nw=,g=r,o=rm 
44                                      
45                 logon_t=,nw+r 
46                 logoff_t=,nw+r 
47                 kick_t=,nw+r 
48                 pwdlset_t=,nw+r 
49                 pwdlchg_t=,nw+r 
50                 pwdmchg_t=,nw+r 
51                                 
52                 full_name=,nw+r 
53                 home_dir=,nw+r 
54                 dir_drive=,nw+r 
55                 logon_script=,nw+r 
56                 profile_path=,nw+r 
57                 acct_desc=,nw+r 
58                 workstations=,nw+r 
59                                    
60                 hours=,nw+r 
61
62 ****************************************************************/
63
64 #define NPF_NAME          0
65 #define NPF_UID           1
66 #define NPF_USER_RID      2
67 #define NPF_SMB_GRPID     3
68 #define NPF_GROUP_RID     4
69 #define NPF_ACB           5
70 #define NPF_LMPWD         6
71 #define NPF_NTPWD         7
72 #define NPF_LOGON_T       8
73 #define NPF_LOGOFF_T      9
74 #define NPF_KICK_T        10
75 #define NPF_PWDLSET_T     11
76 #define NPF_PWDLCHG_T     12
77 #define NPF_PWDMCHG_T     13
78 #define NPF_FULL_NAME     14
79 #define NPF_HOME_DIR      15
80 #define NPF_DIR_DRIVE     16
81 #define NPF_LOGON_SCRIPT  17
82 #define NPF_PROFILE_PATH  18
83 #define NPF_ACCT_DESC     19
84 #define NPF_WORKSTATIONS  20
85 #define NPF_HOURS         21
86
87 /***************************************************************
88  Signal function to tell us we timed out.
89 ****************************************************************/
90 static void gotalarm_sig(void)
91 {
92   gotalarm = 1;
93 }
94
95 /***************************************************************
96  make_nisname_from_user_rid
97  ****************************************************************/
98 static char *make_nisname_from_user_rid(uint32 rid, char *pfile)
99 {
100         static pstring nisname;
101
102         safe_strcpy(nisname, "[user_rid=", sizeof(nisname)-1);
103         slprintf(nisname, sizeof(nisname)-1, "%s%d", nisname, rid);
104         safe_strcat(nisname, "],", sizeof(nisname)-strlen(nisname)-1);
105         safe_strcat(nisname, pfile, sizeof(nisname)-strlen(nisname)-1);
106
107         return nisname;
108 }
109
110 /***************************************************************
111  make_nisname_from_uid
112  ****************************************************************/
113 static char *make_nisname_from_uid(int uid, char *pfile)
114 {
115         static pstring nisname;
116
117         safe_strcpy(nisname, "[uid=", sizeof(nisname)-1);
118         slprintf(nisname, sizeof(nisname)-1, "%s%d", nisname, uid);
119         safe_strcat(nisname, "],", sizeof(nisname)-strlen(nisname)-1);
120         safe_strcat(nisname, pfile, sizeof(nisname)-strlen(nisname)-1);
121
122         return nisname;
123 }
124
125 /***************************************************************
126  make_nisname_from_name
127  ****************************************************************/
128 static char *make_nisname_from_name(char *user_name, char *pfile)
129 {
130         static pstring nisname;
131
132         safe_strcpy(nisname, "[name=", sizeof(nisname)-1);
133         safe_strcat(nisname, user_name, sizeof(nisname) - strlen(nisname) - 1);
134         safe_strcat(nisname, "],", sizeof(nisname)-strlen(nisname)-1);
135         safe_strcat(nisname, pfile, sizeof(nisname)-strlen(nisname)-1);
136
137         return nisname;
138 }
139
140 /*************************************************************************
141  gets a NIS+ attribute
142  *************************************************************************/
143 static void get_single_attribute(nis_object *new_obj, int col,
144                                 char *val, int len)
145 {
146         int entry_len;
147
148         if (new_obj == NULL || val == NULL) return;
149         
150         entry_len = ENTRY_LEN(new_obj, col);
151         if (len > entry_len)
152         {
153                 DEBUG(10,("get_single_attribute: entry length truncated\n"));
154                 len = entry_len;
155         }
156
157         safe_strcpy(val, len, ENTRY_VAL(new_obj, col));
158 }
159
160 /***************************************************************
161  calls nis_list, returns results.
162  ****************************************************************/
163 static nis_result *nisp_get_nis_list(char *nis_name)
164 {
165         nis_result *result;
166         result = nis_list(nis_name, FOLLOW_PATH|EXPAND_NAME|HARD_LOOKUP,NULL,NULL);
167
168         alarm(0);
169         CatchSignal(SIGALRM, SIGNAL_CAST SIG_DFL);
170
171         if (gotalarm)
172         {
173                 DEBUG(0,("nisp_get_nis_list: NIS+ lookup time out\n"));
174                 nis_freeresult(result);
175                 return NULL;
176         }
177         return result;
178 }
179
180
181
182 struct nisp_enum_info
183 {
184         nis_result *result;
185         int enum_entry;
186 };
187
188 /***************************************************************
189  Start to enumerate the nisplus passwd list. Returns a void pointer
190  to ensure no modification outside this module.
191
192  do not call this function directly.  use passdb.c instead.
193
194  ****************************************************************/
195 static void *startnisppwent(BOOL update)
196 {
197         static struct nisp_enum_info res;
198         res.result = nisp_get_nis_list(lp_smb_passwd_file());
199         res.enum_entry = 0;
200         return res.result != NULL ? &res : NULL;
201 }
202
203 /***************************************************************
204  End enumeration of the nisplus passwd list.
205 ****************************************************************/
206 static void endnisppwent(void *vp)
207 {
208 }
209
210 /*************************************************************************
211  Routine to return the next entry in the nisplus passwd list.
212  this function is a nice, messy combination of reading:
213  - the nisplus passwd file
214  - the unix password database
215  - nisp.conf options (not done at present).
216
217  do not call this function directly.  use passdb.c instead.
218
219  *************************************************************************/
220 static struct sam_passwd *getnisp21pwent(void *vp)
221 {
222         return NULL;
223 }
224
225 /*************************************************************************
226  Return the current position in the nisplus passwd list as an SMB_BIG_UINT.
227  This must be treated as an opaque token.
228
229  do not call this function directly.  use passdb.c instead.
230
231 *************************************************************************/
232 static SMB_BIG_UINT getnisppwpos(void *vp)
233 {
234         return (SMB_BIG_UINT)0;
235 }
236
237 /*************************************************************************
238  Set the current position in the nisplus passwd list from SMB_BIG_UINT.
239  This must be treated as an opaque token.
240
241  do not call this function directly.  use passdb.c instead.
242
243 *************************************************************************/
244 static BOOL setnisppwpos(void *vp, SMB_BIG_UINT tok)
245 {
246         return False;
247 }
248
249 /*************************************************************************
250  sets a NIS+ attribute
251  *************************************************************************/
252 static void set_single_attribute(nis_object *new_obj, int col,
253                                 char *val, int len, int flags)
254 {
255         if (new_obj == NULL) return;
256
257         ENTRY_VAL(new_obj, col) = val;
258         ENTRY_LEN(new_obj, col) = len;
259
260         if (flags != 0)
261         {
262                 new_obj->EN_data.en_cols.en_cols_val[col].ec_flags = flags;
263         }
264 }
265
266 /************************************************************************
267  Routine to add an entry to the nisplus passwd file.
268
269  do not call this function directly.  use passdb.c instead.
270
271 *************************************************************************/
272 static BOOL add_nisp21pwd_entry(struct sam_passwd *newpwd)
273 {
274         char           *pfile;
275         char           *nisname;
276         nis_result      *nis_user;
277         nis_result *result = NULL,
278         *tblresult = NULL, 
279         *addresult = NULL;
280         nis_object new_obj, *obj;
281
282     fstring uid;
283         fstring user_rid;
284         fstring smb_grpid;
285         fstring group_rid;
286         fstring acb;
287                           
288         fstring smb_passwd;
289         fstring smb_nt_passwd;
290
291         fstring logon_t;
292         fstring logoff_t;
293         fstring kickoff_t;
294         fstring pwdlset_t;
295         fstring pwdlchg_t;
296         fstring pwdmchg_t;
297
298         bzero(logon_t  , sizeof(logon_t  ));
299         bzero(logoff_t , sizeof(logoff_t ));
300         bzero(kickoff_t, sizeof(kickoff_t));
301         bzero(pwdlset_t, sizeof(pwdlset_t));
302         bzero(pwdlchg_t, sizeof(pwdlchg_t));
303         bzero(pwdmchg_t, sizeof(pwdmchg_t));
304
305         pfile = lp_smb_passwd_file();
306
307         nisname = make_nisname_from_name(newpwd->smb_name, pfile);
308         result = nisp_get_nis_list(nisname);
309         if (result->status != NIS_SUCCESS && result->status != NIS_NOTFOUND)
310         {
311                 DEBUG(3, ( "add_nisppwd_entry: nis_list failure: %s: %s\n",
312                             nisname,  nis_sperrno(result->status)));
313                 nis_freeresult(nis_user);
314                 nis_freeresult(result);
315                 return False;
316         }   
317
318         if (result->status == NIS_SUCCESS && NIS_RES_NUMOBJ(result) > 0)
319         {
320                 DEBUG(3, ("add_nisppwd_entry: User already exists in NIS+ password db: %s\n",
321                             pfile));
322                 nis_freeresult(result);
323                 nis_freeresult(nis_user);
324                 return False;
325         }
326
327 #if 0
328         /* User not found. */
329         if (!add_user)
330         {
331                 DEBUG(3, ("add_nisppwd_entry: User not found in NIS+ password db: %s\n",
332                             pfile));
333                 nis_freeresult(result);
334                 nis_freeresult(nis_user);
335                 return False;
336         }
337
338 #endif
339
340         tblresult = nis_lookup(pfile, FOLLOW_PATH | EXPAND_NAME | HARD_LOOKUP );
341         if (tblresult->status != NIS_SUCCESS)
342         {
343                 nis_freeresult(result);
344                 nis_freeresult(nis_user);
345                 nis_freeresult(tblresult);
346                 DEBUG(3, ( "add_nisppwd_entry: nis_lookup failure: %s\n",
347                             nis_sperrno(tblresult->status)));
348                 return False;
349         }
350
351         new_obj.zo_name   = NIS_RES_OBJECT(tblresult)->zo_name;
352         new_obj.zo_domain = NIS_RES_OBJECT(tblresult)->zo_domain;
353         new_obj.zo_owner  = NIS_RES_OBJECT(tblresult)->zo_owner;
354         new_obj.zo_group  = NIS_RES_OBJECT(tblresult)->zo_group;
355         new_obj.zo_access = NIS_RES_OBJECT(tblresult)->zo_access;
356         new_obj.zo_ttl    = NIS_RES_OBJECT(tblresult)->zo_ttl;
357
358         new_obj.zo_data.zo_type = ENTRY_OBJ;
359
360         new_obj.zo_data.objdata_u.en_data.en_type = NIS_RES_OBJECT(tblresult)->zo_data.objdata_u.ta_data.ta_type;
361         new_obj.zo_data.objdata_u.en_data.en_cols.en_cols_len = NIS_RES_OBJECT(tblresult)->zo_data.objdata_u.ta_data.ta_maxcol;
362         new_obj.zo_data.objdata_u.en_data.en_cols.en_cols_val = calloc(new_obj.zo_data.objdata_u.en_data.en_cols.en_cols_len, sizeof(entry_col));
363
364         pwdb_sethexpwd(smb_passwd   , newpwd->smb_passwd   , newpwd->acct_ctrl);
365         pwdb_sethexpwd(smb_nt_passwd, newpwd->smb_nt_passwd, newpwd->acct_ctrl);
366
367         pwdb_set_logon_time      (logon_t  , sizeof(logon_t  ), newpwd->logon_time           );
368         pwdb_set_logoff_time     (logoff_t , sizeof(logoff_t ), newpwd->logoff_time          );
369         pwdb_set_kickoff_time    (kickoff_t, sizeof(kickoff_t), newpwd->kickoff_time         );
370         pwdb_set_last_set_time   (pwdlset_t, sizeof(pwdlset_t), newpwd->pass_last_set_time   ); 
371         pwdb_set_can_change_time (pwdlchg_t, sizeof(pwdlchg_t), newpwd->pass_can_change_time ); 
372         pwdb_set_must_change_time(pwdmchg_t, sizeof(pwdmchg_t), newpwd->pass_must_change_time); 
373
374         slprintf(uid, sizeof(uid), "%u", newpwd->smb_userid);
375         slprintf(user_rid, sizeof(user_rid), "0x%x", newpwd->user_rid);
376         slprintf(smb_grpid, sizeof(smb_grpid), "%u", newpwd->smb_grpid);
377         slprintf(group_rid, sizeof(group_rid), "0x%x", newpwd->group_rid);
378
379         safe_strcpy(acb, pwdb_encode_acct_ctrl(newpwd->acct_ctrl, NEW_PW_FORMAT_SPACE_PADDED_LEN), sizeof(acb)); 
380
381         set_single_attribute(&new_obj, NPF_NAME          , newpwd->smb_name     , strlen(newpwd->smb_name)     , 0);
382         set_single_attribute(&new_obj, NPF_UID           , uid                  , strlen(uid)                  , 0);
383         set_single_attribute(&new_obj, NPF_USER_RID      , user_rid             , strlen(user_rid)             , 0);
384         set_single_attribute(&new_obj, NPF_SMB_GRPID     , smb_grpid            , strlen(smb_grpid)            , 0);
385         set_single_attribute(&new_obj, NPF_GROUP_RID     , group_rid            , strlen(group_rid)            , 0);
386         set_single_attribute(&new_obj, NPF_ACB           , acb                  , strlen(acb)                  , 0);
387         set_single_attribute(&new_obj, NPF_LMPWD         , smb_passwd           , strlen(smb_passwd)           , EN_CRYPT);
388         set_single_attribute(&new_obj, NPF_NTPWD         , smb_nt_passwd        , strlen(smb_nt_passwd)        , EN_CRYPT);
389         set_single_attribute(&new_obj, NPF_LOGON_T       , logon_t              , strlen(logon_t)              , 0);
390         set_single_attribute(&new_obj, NPF_LOGOFF_T      , logoff_t             , strlen(logoff_t)             , 0);
391         set_single_attribute(&new_obj, NPF_KICK_T        , kickoff_t            , strlen(kickoff_t)            , 0);
392         set_single_attribute(&new_obj, NPF_PWDLSET_T     , pwdlset_t            , strlen(pwdlset_t)            , 0);
393         set_single_attribute(&new_obj, NPF_PWDLCHG_T     , pwdlchg_t            , strlen(pwdlchg_t)            , 0);
394         set_single_attribute(&new_obj, NPF_PWDMCHG_T     , pwdmchg_t            , strlen(pwdmchg_t)            , 0);
395         set_single_attribute(&new_obj, NPF_FULL_NAME     , newpwd->full_name    , strlen(newpwd->full_name)    , 0);
396         set_single_attribute(&new_obj, NPF_HOME_DIR      , newpwd->home_dir     , strlen(newpwd->home_dir)     , 0);
397         set_single_attribute(&new_obj, NPF_DIR_DRIVE     , newpwd->dir_drive    , strlen(newpwd->dir_drive)    , 0);
398         set_single_attribute(&new_obj, NPF_LOGON_SCRIPT  , newpwd->logon_script , strlen(newpwd->logon_script) , 0);
399         set_single_attribute(&new_obj, NPF_PROFILE_PATH  , newpwd->profile_path , strlen(newpwd->profile_path) , 0);
400         set_single_attribute(&new_obj, NPF_ACCT_DESC     , newpwd->acct_desc    , strlen(newpwd->acct_desc)    , 0);
401         set_single_attribute(&new_obj, NPF_WORKSTATIONS  , newpwd->workstations , strlen(newpwd->workstations) , 0);
402         set_single_attribute(&new_obj, NPF_HOURS         , newpwd->hours        , newpwd->hours_len            , 0);
403
404         obj = &new_obj;
405
406         addresult = nis_add_entry(pfile, obj, ADD_OVERWRITE | FOLLOW_PATH | EXPAND_NAME | HARD_LOOKUP);
407
408         nis_freeresult(nis_user);
409         if (tblresult)
410         {
411                 nis_freeresult(tblresult);
412         }
413
414         if (addresult->status != NIS_SUCCESS)
415         {
416                 DEBUG(3, ( "add_nisppwd_entry: NIS+ table update failed: %s\n",
417                             nisname, nis_sperrno(addresult->status)));
418                 nis_freeresult(addresult);
419                 nis_freeresult(result);
420                 return False;
421         }
422
423         nis_freeresult(addresult);
424         nis_freeresult(result);
425
426         return True;
427 }
428
429 /************************************************************************
430  Routine to search the nisplus passwd file for an entry matching the username.
431  and then modify its password entry. We can't use the startnisppwent()/
432  getnisppwent()/endnisppwent() interfaces here as we depend on looking
433  in the actual file to decide how much room we have to write data.
434  override = False, normal
435  override = True, override XXXXXXXX'd out password or NO PASS
436
437  do not call this function directly.  use passdb.c instead.
438
439 ************************************************************************/
440 static BOOL mod_nisp21pwd_entry(struct sam_passwd* pwd, BOOL override)
441 {
442         return False;
443 }
444  
445 /************************************************************************
446  makes a struct sam_passwd from a NIS+ result.
447  ************************************************************************/
448 static BOOL make_sam_from_nisp(struct sam_passwd *pw_buf, nis_result *result)
449 {
450         int uidval;
451         static pstring  user_name;
452         static unsigned char smbpwd[16];
453         static unsigned char smbntpwd[16];
454         nis_object *obj;
455         uchar *p;
456
457         if (pw_buf == NULL || result == NULL) return False;
458
459         pwdb_init_sam(pw_buf);
460
461         if (result->status != NIS_SUCCESS)
462         {
463                 DEBUG(0, ("make_smb_from_nisp: NIS+ lookup failure: %s\n",
464                            nis_sperrno(result->status)));
465                 return False;
466         }
467
468         /* User not found. */
469         if (NIS_RES_NUMOBJ(result) <= 0)
470         {
471                 DEBUG(10, ("make_smb_from_nisp: user not found in NIS+\n"));
472                 return False;
473         }
474
475         if (NIS_RES_NUMOBJ(result) > 1)
476         {
477                 DEBUG(10, ("make_smb_from_nisp: WARNING: Multiple entries for user in NIS+ table!\n"));
478         }
479
480         /* Grab the first hit. */
481         obj = &NIS_RES_OBJECT(result)[0];
482
483         /* Check the lanman password column. */
484         p = (uchar *)ENTRY_VAL(obj, NPF_LMPWD);
485         if (strlen((char *)p) != 32 || !pwdb_gethexpwd((char *)p, (char *)smbpwd))
486         {
487                 DEBUG(0, ("make_smb_from_nisp: malformed LM pwd entry.\n"));
488                 return False;
489         }
490
491         /* Check the NT password column. */
492         p = (uchar *)ENTRY_VAL(obj, NPF_NTPWD);
493         if (strlen((char *)p) != 32 || !pwdb_gethexpwd((char *)p, (char *)smbntpwd))
494         {
495                 DEBUG(0, ("make_smb_from_nisp: malformed NT pwd entry\n"));
496                 return False;
497         }
498
499         strncpy(user_name, ENTRY_VAL(obj, NPF_NAME), sizeof(user_name));
500         uidval = atoi(ENTRY_VAL(obj, NPF_UID));
501
502         pw_buf->smb_name      = user_name;
503         pw_buf->smb_userid    = uidval;         
504         pw_buf->smb_passwd    = smbpwd;
505         pw_buf->smb_nt_passwd = smbntpwd;
506
507         return True;
508 }
509
510 /*************************************************************************
511  Routine to search the nisplus passwd file for an entry matching the username
512  *************************************************************************/
513 static struct sam_passwd *getnisp21pwnam(char *name)
514 {
515         /* Static buffers we will return. */
516         static struct sam_passwd pw_buf;
517         nis_result *result;
518         pstring nisname;
519         BOOL ret;
520
521         if (!*lp_smb_passwd_file())
522         {
523                 DEBUG(0, ("No SMB password file set\n"));
524                 return NULL;
525         }
526
527         DEBUG(10, ("getnisppwnam: search by name: %s\n", name));
528         DEBUG(10, ("getnisppwnam: using NIS+ table %s\n", lp_smb_passwd_file()));
529
530         slprintf(nisname, sizeof(nisname)-1, "[name=%s],%s", name, lp_smb_passwd_file());
531
532         /* Search the table. */
533         gotalarm = 0;
534         CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
535         alarm(5);
536
537         result = nis_list(nisname, FOLLOW_PATH | EXPAND_NAME | HARD_LOOKUP, NULL, NULL);
538
539         alarm(0);
540         CatchSignal(SIGALRM, SIGNAL_CAST SIG_DFL);
541
542         if (gotalarm)
543         {
544                 DEBUG(0,("getnisppwnam: NIS+ lookup time out\n"));
545                 nis_freeresult(result);
546                 return NULL;
547         }
548
549         ret = make_sam_from_nisp(&pw_buf, result);
550         nis_freeresult(result);
551
552         return ret ? &pw_buf : NULL;
553 }
554
555 /*************************************************************************
556  Routine to search the nisplus passwd file for an entry matching the username
557  *************************************************************************/
558 static struct sam_passwd *getnisp21pwrid(uint32 rid)
559 {
560         /* Static buffers we will return. */
561         static struct sam_passwd pw_buf;
562         nis_result *result;
563         char *nisname;
564         BOOL ret;
565
566         if (!*lp_smb_passwd_file())
567         {
568                 DEBUG(0, ("No SMB password file set\n"));
569                 return NULL;
570         }
571
572         DEBUG(10, ("getnisp21pwrid: search by rid: %x\n", rid));
573         DEBUG(10, ("getnisp21pwrid: using NIS+ table %s\n", lp_smb_passwd_file()));
574
575         nisname = make_nisname_from_user_rid(rid, lp_smb_passwd_file());
576
577         /* Search the table. */
578         gotalarm = 0;
579         CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
580         alarm(5);
581
582         result = nis_list(nisname, FOLLOW_PATH | EXPAND_NAME | HARD_LOOKUP, NULL, NULL);
583
584         alarm(0);
585         CatchSignal(SIGALRM, SIGNAL_CAST SIG_DFL);
586
587         if (gotalarm)
588         {
589                 DEBUG(0,("getnisp21pwrid: NIS+ lookup time out\n"));
590                 nis_freeresult(result);
591                 return NULL;
592         }
593
594         ret = make_sam_from_nisp(&pw_buf, result);
595         nis_freeresult(result);
596
597         return ret ? &pw_buf : NULL;
598 }
599
600 /*
601  * Derived functions for NIS+.
602  */
603
604 static struct smb_passwd *getnisppwent(void *vp)
605 {
606         return pwdb_sam_to_smb(getnisp21pwent(vp));
607 }
608
609 static BOOL add_nisppwd_entry(struct smb_passwd *newpwd)
610 {
611         return add_nisp21pwd_entry(pwdb_smb_to_sam(newpwd));
612 }
613
614 static BOOL mod_nisppwd_entry(struct smb_passwd* pwd, BOOL override)
615 {
616         return mod_nisp21pwd_entry(pwdb_smb_to_sam(pwd), override);
617 }
618
619 static struct smb_passwd *getnisppwnam(char *name)
620 {
621         return pwdb_sam_to_smb(getnisp21pwnam(name));
622 }
623
624 static struct sam_passwd *getnisp21pwuid(uid_t smb_userid)
625 {
626         return getnisp21pwrid(pwdb_uid_to_user_rid(smb_userid));
627 }
628
629 static struct smb_passwd *getnisppwrid(uid_t user_rid)
630 {
631         return pwdb_sam_to_smb(getnisp21pwuid(pwdb_user_rid_to_uid(user_rid)));
632 }
633
634 static struct smb_passwd *getnisppwuid(uid_t smb_userid)
635 {
636         return pwdb_sam_to_smb(getnisp21pwuid(smb_userid));
637 }
638
639 static struct sam_disp_info *getnispdispnam(char *name)
640 {
641         return pwdb_sam_to_dispinfo(getnisp21pwnam(name));
642 }
643
644 static struct sam_disp_info *getnispdisprid(uint32 rid)
645 {
646         return pwdb_sam_to_dispinfo(getnisp21pwrid(rid));
647 }
648
649 static struct sam_disp_info *getnispdispent(void *vp)
650 {
651         return pwdb_sam_to_dispinfo(getnisp21pwent(vp));
652 }
653
654 static struct passdb_ops nispasswd_ops = {
655   startnisppwent,
656   endnisppwent,
657   getnisppwpos,
658   setnisppwpos,
659   getnisppwnam,
660   getnisppwuid,
661   getnisppwrid,
662   getnisppwent,
663   add_nisppwd_entry,
664   mod_nisppwd_entry,
665   getnisp21pwent,
666   getnisp21pwnam,
667   getnisp21pwuid,
668   getnisp21pwrid, 
669   add_nisp21pwd_entry,
670   mod_nisp21pwd_entry,
671   getnispdispnam,
672   getnispdisprid,
673   getnispdispent
674 };
675
676 struct passdb_ops *nisplus_initialize_password_db(void)
677 {
678   return &nispasswd_ops;
679 }
680  
681 #else
682  void nisplus_dummy_function(void);
683  void nisplus_dummy_function(void) { } /* stop some compilers complaining */
684 #endif /* WITH_NISPLUS */
685
686 /* useful code i can't bring myself to delete */
687 #if 0
688 static void useful_code(void) {
689         /* checks user in unix password database.  don't want to do that, here. */
690         nisname = make_nisname_from_name(newpwd->smb_name, "passwd.org_dir");
691
692         nis_user = nis_list(nisname, FOLLOW_PATH | EXPAND_NAME | HARD_LOOKUP, NULL, NULL);
693
694         if (nis_user->status != NIS_SUCCESS || NIS_RES_NUMOBJ(nis_user) <= 0)
695         {
696                 DEBUG(3, ("add_nisppwd_entry: Unable to get NIS+ passwd entry for user: %s.\n",
697                         nis_sperrno(nis_user->status)));
698                 return False;
699         }
700
701         user_obj = NIS_RES_OBJECT(nis_user);
702         make_nisname_from_name(ENTRY_VAL(user_obj,0), pfile);
703 }
704 #endif