This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to...
[sfrench/samba-autobuild/.git] / source3 / utils / pdbedit.c
1 /* 
2    Unix SMB/CIFS implementation.
3    passdb editing frontend
4    
5    Copyright (C) Simo Sorce      2000
6    Copyright (C) Andrew Bartlett 2001   
7    Copyright (C) Jelmer Vernooij 2002
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "includes.h"
25
26 #define BIT_CONFIGFILE  0x00000001
27 #define BIT_DEBUGLEVEL  0x00000002
28 #define BIT_BACKEND     0x00000004
29 #define BIT_VERBOSE     0x00000008
30 #define BIT_SPSTYLE     0x00000010
31 #define BIT_RESERV_1    0x00000020
32 #define BIT_RESERV_2    0x00000040
33 #define BIT_RESERV_3    0x00000080
34 #define BIT_FULLNAME    0x00000100
35 #define BIT_HOMEDIR     0x00000200
36 #define BIT_HDIRDRIVE   0x00000400
37 #define BIT_LOGSCRIPT   0x00000800
38 #define BIT_PROFILE     0x00001000
39 #define BIT_MACHINE     0x00002000
40 #define BIT_RESERV_4    0x00004000
41 #define BIT_USER        0x00008000
42 #define BIT_LIST        0x00010000
43 #define BIT_MODIFY      0x00020000
44 #define BIT_CREATE      0x00040000
45 #define BIT_DELETE      0x00080000
46 #define BIT_ACCPOLICY   0x00100000
47 #define BIT_ACCPOLVAL   0x00200000
48 #define BIT_RESERV_6    0x00400000
49 #define BIT_RESERV_7    0x00800000
50 #define BIT_IMPORT      0x01000000
51 #define BIT_EXPORT      0x02000000
52
53 #define MASK_ALWAYS_GOOD        0x0000001F
54 #define MASK_USER_GOOD          0x00001F00
55 extern pstring global_myname;
56 extern BOOL AllowDebugChange;
57
58 /*********************************************************
59  Add all currently available users to another db
60  ********************************************************/
61
62 static int export_database (struct pdb_context *in, struct pdb_context *out) {
63         SAM_ACCOUNT *user = NULL;
64
65         if (!in->pdb_setsampwent(in, 0)) {
66                 fprintf(stderr, "Can't sampwent!\n");
67                 return 1;
68         }
69
70         if (!NT_STATUS_IS_OK(pdb_init_sam(&user))) {
71                 fprintf(stderr, "Can't initialize new SAM_ACCOUNT!\n");
72                 return 1;
73         }
74
75         while (in->pdb_getsampwent(in, user)) {
76                 out->pdb_add_sam_account(out, user);
77                 if (!NT_STATUS_IS_OK(pdb_reset_sam(user))){
78                         fprintf(stderr, "Can't reset SAM_ACCOUNT!\n");
79                         return 1;
80                 }
81         }
82
83         in->pdb_endsampwent(in);
84
85         return 0;
86 }
87
88 /*********************************************************
89  Print info from sam structure
90 **********************************************************/
91
92 static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdstyle)
93 {
94         uid_t uid;
95         gid_t gid;
96         time_t tmp;
97
98         /* TODO: chaeck if entry is a user or a workstation */
99         if (!sam_pwent) return -1;
100         
101         if (verbosity) {
102                 printf ("Unix username:        %s\n", pdb_get_username(sam_pwent));
103                 printf ("NT username:          %s\n", pdb_get_nt_username(sam_pwent));
104                 printf ("Account Flags:        %s\n", pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent), NEW_PW_FORMAT_SPACE_PADDED_LEN));
105                 
106                 if (IS_SAM_UNIX_USER(sam_pwent)) {
107                         uid = pdb_get_uid(sam_pwent);
108                         gid = pdb_get_gid(sam_pwent);
109                         printf ("User ID/Group ID:     %d/%d\n", uid, gid);
110                 }
111                 printf ("User SID:             %s\n",
112                         sid_string_static(pdb_get_user_sid(sam_pwent)));
113                 printf ("Primary Group SID:    %s\n",
114                         sid_string_static(pdb_get_group_sid(sam_pwent)));
115                 printf ("Full Name:            %s\n", pdb_get_fullname(sam_pwent));
116                 printf ("Home Directory:       %s\n", pdb_get_homedir(sam_pwent));
117                 printf ("HomeDir Drive:        %s\n", pdb_get_dir_drive(sam_pwent));
118                 printf ("Logon Script:         %s\n", pdb_get_logon_script(sam_pwent));
119                 printf ("Profile Path:         %s\n", pdb_get_profile_path(sam_pwent));
120                 printf ("Domain:               %s\n", pdb_get_domain(sam_pwent));
121                 printf ("Account desc:         %s\n", pdb_get_acct_desc(sam_pwent));
122                 printf ("Workstations:         %s\n", pdb_get_workstations(sam_pwent));
123                 printf ("Munged dial:          %s\n", pdb_get_munged_dial(sam_pwent));
124                 
125                 tmp = pdb_get_logon_time(sam_pwent);
126                 printf ("Logon time:           %s\n", tmp ? http_timestring(tmp) : "0");
127                 
128                 tmp = pdb_get_logoff_time(sam_pwent);
129                 printf ("Logoff time:          %s\n", tmp ? http_timestring(tmp) : "0");
130                 
131                 tmp = pdb_get_kickoff_time(sam_pwent);
132                 printf ("Kickoff time:         %s\n", tmp ? http_timestring(tmp) : "0");
133                 
134                 tmp = pdb_get_pass_last_set_time(sam_pwent);
135                 printf ("Password last set:    %s\n", tmp ? http_timestring(tmp) : "0");
136                 
137                 tmp = pdb_get_pass_can_change_time(sam_pwent);
138                 printf ("Password can change:  %s\n", tmp ? http_timestring(tmp) : "0");
139                 
140                 tmp = pdb_get_pass_must_change_time(sam_pwent);
141                 printf ("Password must change: %s\n", tmp ? http_timestring(tmp) : "0");
142                 
143         } else if (smbpwdstyle) {
144                 if (IS_SAM_UNIX_USER(sam_pwent)) {
145                         char lm_passwd[33];
146                         char nt_passwd[33];
147
148                         uid = pdb_get_uid(sam_pwent);
149                         pdb_sethexpwd(lm_passwd, 
150                                       pdb_get_lanman_passwd(sam_pwent), 
151                                       pdb_get_acct_ctrl(sam_pwent));
152                         pdb_sethexpwd(nt_passwd, 
153                                       pdb_get_nt_passwd(sam_pwent), 
154                                       pdb_get_acct_ctrl(sam_pwent));
155                         
156                         printf("%s:%d:%s:%s:%s:LCT-%08X:\n",
157                                pdb_get_username(sam_pwent),
158                                uid,
159                                lm_passwd,
160                                nt_passwd,
161                                pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent),NEW_PW_FORMAT_SPACE_PADDED_LEN),
162                                (uint32)pdb_get_pass_last_set_time(sam_pwent));
163                 } else {
164                         fprintf(stderr, "Can't output in smbpasswd format, no uid on this record.\n");
165                 }
166         } else {
167                 if (IS_SAM_UNIX_USER(sam_pwent)) {
168                         printf ("%s:%d:%s\n", pdb_get_username(sam_pwent), pdb_get_uid(sam_pwent), 
169                                 pdb_get_fullname(sam_pwent));
170                 } else {        
171                         printf ("%s:(null):%s\n", pdb_get_username(sam_pwent), pdb_get_fullname(sam_pwent));
172                 }
173         }
174
175         return 0;       
176 }
177
178 /*********************************************************
179  Get an Print User Info
180 **********************************************************/
181
182 static int print_user_info (struct pdb_context *in, char *username, BOOL verbosity, BOOL smbpwdstyle)
183 {
184         SAM_ACCOUNT *sam_pwent=NULL;
185         BOOL ret;
186         
187         if (!NT_STATUS_IS_OK(pdb_init_sam (&sam_pwent))) {
188                 return -1;
189         }
190         
191         ret = in->pdb_getsampwnam (in, sam_pwent, username);
192
193         if (ret==False) {
194                 fprintf (stderr, "Username not found!\n");
195                 pdb_free_sam(&sam_pwent);
196                 return -1;
197         }
198         
199         ret=print_sam_info (sam_pwent, verbosity, smbpwdstyle);
200         pdb_free_sam(&sam_pwent);
201         
202         return ret;
203 }
204         
205 /*********************************************************
206  List Users
207 **********************************************************/
208 static int print_users_list (struct pdb_context *in, BOOL verbosity, BOOL smbpwdstyle)
209 {
210         SAM_ACCOUNT *sam_pwent=NULL;
211         BOOL check, ret;
212         
213         check = in->pdb_setsampwent(in, False);
214         if (!check) {
215                 return 1;
216         }
217
218         check = True;
219         if (!(NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent)))) return 1;
220
221         while (check && (ret = in->pdb_getsampwent (in, sam_pwent))) {
222                 if (verbosity)
223                         printf ("---------------\n");
224                 print_sam_info (sam_pwent, verbosity, smbpwdstyle);
225                 pdb_free_sam(&sam_pwent);
226                 check = NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent));
227         }
228         if (check) pdb_free_sam(&sam_pwent);
229         
230         in->pdb_endsampwent(in);
231         return 0;
232 }
233
234 /*********************************************************
235  Set User Info
236 **********************************************************/
237
238 static int set_user_info (struct pdb_context *in, char *username, char *fullname, char *homedir, char *drive, char *script, char *profile)
239 {
240         SAM_ACCOUNT *sam_pwent=NULL;
241         BOOL ret;
242         
243         pdb_init_sam(&sam_pwent);
244         
245         ret = in->pdb_getsampwnam (in, sam_pwent, username);
246         if (ret==False) {
247                 fprintf (stderr, "Username not found!\n");
248                 pdb_free_sam(&sam_pwent);
249                 return -1;
250         }
251         
252         if (fullname)
253                 pdb_set_fullname(sam_pwent, fullname);
254         if (homedir)
255                 pdb_set_homedir(sam_pwent, homedir, True);
256         if (drive)
257                 pdb_set_dir_drive(sam_pwent,drive, True);
258         if (script)
259                 pdb_set_logon_script(sam_pwent, script, True);
260         if (profile)
261                 pdb_set_profile_path (sam_pwent, profile, True);
262         
263         if (in->pdb_update_sam_account (in, sam_pwent))
264                 print_user_info (in, username, True, False);
265         else {
266                 fprintf (stderr, "Unable to modify entry!\n");
267                 pdb_free_sam(&sam_pwent);
268                 return -1;
269         }
270         pdb_free_sam(&sam_pwent);
271         return 0;
272 }
273
274 /*********************************************************
275  Add New User
276 **********************************************************/
277 static int new_user (struct pdb_context *in, char *username, char *fullname, char *homedir, char *drive, char *script, char *profile)
278 {
279         SAM_ACCOUNT *sam_pwent=NULL;
280         struct passwd  *pwd = NULL;
281         char *password1, *password2, *staticpass;
282         
283         ZERO_STRUCT(sam_pwent);
284
285         if ((pwd = getpwnam_alloc(username))) {
286                 pdb_init_sam_pw (&sam_pwent, pwd);
287                 passwd_free(&pwd);
288         } else {
289                 fprintf (stderr, "WARNING: user %s does not exist in system passwd\n", username);
290                 pdb_init_sam(&sam_pwent);
291                 if (!pdb_set_username(sam_pwent, username)) {
292                         return False;
293                 }
294         }
295
296         staticpass = getpass("new password:");
297         password1 = strdup(staticpass);
298         memset(staticpass, 0, strlen(staticpass));
299         staticpass = getpass("retype new password:");
300         password2 = strdup(staticpass);
301         memset(staticpass, 0, strlen(staticpass));
302         if (strcmp (password1, password2)) {
303                 fprintf (stderr, "Passwords does not match!\n");
304                 memset(password1, 0, strlen(password1));
305                 SAFE_FREE(password1);
306                 memset(password2, 0, strlen(password2));
307                 SAFE_FREE(password2);
308                 pdb_free_sam (&sam_pwent);
309                 return -1;
310         }
311
312         pdb_set_plaintext_passwd(sam_pwent, password1);
313         memset(password1, 0, strlen(password1));
314         SAFE_FREE(password1);
315         memset(password2, 0, strlen(password2));
316         SAFE_FREE(password2);
317
318         if (fullname)
319                 pdb_set_fullname(sam_pwent, fullname);
320         if (homedir)
321                 pdb_set_homedir (sam_pwent, homedir, True);
322         if (drive)
323                 pdb_set_dir_drive (sam_pwent, drive, True);
324         if (script)
325                 pdb_set_logon_script(sam_pwent, script, True);
326         if (profile)
327                 pdb_set_profile_path (sam_pwent, profile, True);
328         
329         pdb_set_acct_ctrl (sam_pwent, ACB_NORMAL);
330         
331         if (in->pdb_add_sam_account (in, sam_pwent)) { 
332                 print_user_info (in, username, True, False);
333         } else {
334                 fprintf (stderr, "Unable to add user! (does it alredy exist?)\n");
335                 pdb_free_sam (&sam_pwent);
336                 return -1;
337         }
338         pdb_free_sam (&sam_pwent);
339         return 0;
340 }
341
342 /*********************************************************
343  Add New Machine
344 **********************************************************/
345
346 static int new_machine (struct pdb_context *in, char *machinename)
347 {
348         SAM_ACCOUNT *sam_pwent=NULL;
349         char name[16];
350         char *password = NULL;
351         
352         if (!NT_STATUS_IS_OK(pdb_init_sam (&sam_pwent))) {
353                 return -1;
354         }
355
356         if (machinename[strlen (machinename) -1] == '$')
357                 machinename[strlen (machinename) -1] = '\0';
358         
359         safe_strcpy (name, machinename, 16);
360         safe_strcat (name, "$", 16);
361         
362         string_set (&password, machinename);
363         strlower_m(password);
364         
365         pdb_set_plaintext_passwd (sam_pwent, password);
366
367         pdb_set_username (sam_pwent, name);
368         
369         pdb_set_acct_ctrl (sam_pwent, ACB_WSTRUST);
370         
371         pdb_set_group_sid_from_rid(sam_pwent, DOMAIN_GROUP_RID_COMPUTERS);
372         
373         if (in->pdb_add_sam_account (in, sam_pwent)) {
374                 print_user_info (in, name, True, False);
375         } else {
376                 fprintf (stderr, "Unable to add machine! (does it already exist?)\n");
377                 pdb_free_sam (&sam_pwent);
378                 return -1;
379         }
380         pdb_free_sam (&sam_pwent);
381         return 0;
382 }
383
384 /*********************************************************
385  Delete user entry
386 **********************************************************/
387
388 static int delete_user_entry (struct pdb_context *in, char *username)
389 {
390         SAM_ACCOUNT *samaccount = NULL;
391
392         if (!NT_STATUS_IS_OK(pdb_init_sam (&samaccount))) {
393                 return -1;
394         }
395
396         if (!in->pdb_getsampwnam(in, samaccount, username)) {
397                 fprintf (stderr, "user %s does not exist in the passdb\n", username);
398                 return -1;
399         }
400
401         return in->pdb_delete_sam_account (in, samaccount);
402 }
403
404 /*********************************************************
405  Delete machine entry
406 **********************************************************/
407
408 static int delete_machine_entry (struct pdb_context *in, char *machinename)
409 {
410         char name[16];
411         SAM_ACCOUNT *samaccount = NULL;
412         
413         safe_strcpy (name, machinename, 16);
414         if (name[strlen(name)] != '$')
415                 safe_strcat (name, "$", 16);
416
417         if (!NT_STATUS_IS_OK(pdb_init_sam (&samaccount))) {
418                 return -1;
419         }
420
421         if (!in->pdb_getsampwnam(in, samaccount, name)) {
422                 fprintf (stderr, "machine %s does not exist in the passdb\n", name);
423                 return -1;
424         }
425
426         return in->pdb_delete_sam_account (in, samaccount);
427 }
428
429 /*********************************************************
430  Start here.
431 **********************************************************/
432
433 int main (int argc, char **argv)
434 {
435         static BOOL list_users = False;
436         static BOOL verbose = False;
437         static BOOL spstyle = False;
438         static BOOL machine = False;
439         static BOOL add_user = False;
440         static BOOL delete_user = False;
441         static BOOL modify_user = False;
442         uint32  setparms, checkparms;
443         int opt;
444         static char *full_name = NULL;
445         static char *user_name = NULL;
446         static char *home_dir = NULL;
447         static char *home_drive = NULL;
448         static char *backend = NULL;
449         static char *backend_in = NULL;
450         static char *backend_out = NULL;
451         static char *logon_script = NULL;
452         static char *profile_path = NULL;
453         static char *config_file = dyn_CONFIGFILE;
454         static char *new_debuglevel = NULL;
455         static char *account_policy = NULL;
456         static long int account_policy_value = 0;
457         BOOL account_policy_value_set = False;
458
459         struct pdb_context *bin;
460         struct pdb_context *bout;
461         struct pdb_context *bdef;
462         poptContext pc;
463         struct poptOption long_options[] = {
464                 POPT_AUTOHELP
465                 {"list",        'l', POPT_ARG_NONE, &list_users, 0, "list all users", NULL},
466                 {"verbose",     'v', POPT_ARG_NONE, &verbose, 0, "be verbose", NULL },
467                 {"smbpasswd-style",     'w',POPT_ARG_NONE, &spstyle, 0, "give output in smbpasswd style", NULL},
468                 {"user",        'u', POPT_ARG_STRING, &user_name, 0, "use username", "USER" },
469                 {"fullname",    'f', POPT_ARG_STRING, &full_name, 0, "set full name", NULL},
470                 {"homedir",     'h', POPT_ARG_STRING, &home_dir, 0, "set home directory", NULL},
471                 {"drive",       'd', POPT_ARG_STRING, &home_drive, 0, "set home drive", NULL},
472                 {"script",      's', POPT_ARG_STRING, &logon_script, 0, "set logon script", NULL},
473                 {"profile",     'p', POPT_ARG_STRING, &profile_path, 0, "set profile path", NULL},
474                 {"create",      'a', POPT_ARG_NONE, &add_user, 0, "create user", NULL},
475                 {"modify",      'r', POPT_ARG_NONE, &modify_user, 0, "modify user", NULL},
476                 {"machine",     'm', POPT_ARG_NONE, &machine, 0, "account is a machine account", NULL},
477                 {"delete",      'x', POPT_ARG_NONE, &delete_user, 0, "delete user", NULL},
478                 {"backend",     'b', POPT_ARG_STRING, &backend, 0, "use different passdb backend as default backend", NULL},
479                 {"import",      'i', POPT_ARG_STRING, &backend_in, 0, "import user accounts from this backend", NULL},
480                 {"export",      'e', POPT_ARG_STRING, &backend_out, 0, "export user accounts to this backend", NULL},
481                 {"debuglevel",  'D', POPT_ARG_STRING, &new_debuglevel, 0,"set debuglevel",NULL},
482                 {"configfile",  'c', POPT_ARG_STRING, &config_file, 0,"use different configuration file",NULL},
483                 {"account-policy",      'P', POPT_ARG_STRING, &account_policy, 0,"value of an account policy (like maximum password age)",NULL},
484                 {"value",       'V', POPT_ARG_LONG, &account_policy_value, 'V',"set the account policy to this value", NULL},
485                 {0,0,0,0}
486         };
487         
488         setup_logging("pdbedit", True);
489         
490         pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
491                             POPT_CONTEXT_KEEP_FIRST);
492         
493         while((opt = poptGetNextOpt(pc)) != -1) {
494                 switch (opt) {
495                 case 'V':
496                         account_policy_value_set = True;
497                         break;
498                 }
499         }
500         
501         if (new_debuglevel) {
502                 debug_parse_levels(new_debuglevel);
503                 AllowDebugChange = False;
504         }
505         
506         if (!lp_load(config_file,True,False,False)) {
507                 fprintf(stderr, "Can't load %s - run testparm to debug it\n", config_file);
508                 exit(1);
509         }
510
511         setparms =      (config_file ? BIT_CONFIGFILE : 0) +
512                         (new_debuglevel ? BIT_DEBUGLEVEL : 0) +
513                         (backend ? BIT_BACKEND : 0) +
514                         (verbose ? BIT_VERBOSE : 0) +
515                         (spstyle ? BIT_SPSTYLE : 0) +
516                         (full_name ? BIT_FULLNAME : 0) +
517                         (home_dir ? BIT_HOMEDIR : 0) +
518                         (home_drive ? BIT_HDIRDRIVE : 0) +
519                         (logon_script ? BIT_LOGSCRIPT : 0) +
520                         (profile_path ? BIT_PROFILE : 0) +
521                         (machine ? BIT_MACHINE : 0) +
522                         (user_name ? BIT_USER : 0) +
523                         (list_users ? BIT_LIST : 0) +
524                         (modify_user ? BIT_MODIFY : 0) +
525                         (add_user ? BIT_CREATE : 0) +
526                         (delete_user ? BIT_DELETE : 0) +
527                         (account_policy ? BIT_ACCPOLICY : 0) +
528                         (account_policy_value_set ? BIT_ACCPOLVAL : 0) +
529                         (backend_in ? BIT_IMPORT : 0) +
530                         (backend_out ? BIT_EXPORT : 0);
531
532         if (setparms & BIT_BACKEND) {
533                 if (!NT_STATUS_IS_OK(make_pdb_context_string(&bdef, backend))) {
534                         fprintf(stderr, "Can't initialize passdb backend.\n");
535                         return 1;
536                 }
537         } else {
538                 if (!NT_STATUS_IS_OK(make_pdb_context_list(&bdef, lp_passdb_backend()))) {
539                         fprintf(stderr, "Can't initialize passdb backend.\n");
540                         return 1;
541                 }
542         }
543         
544         /* the lowest bit options are always accepted */
545         checkparms = setparms & ~MASK_ALWAYS_GOOD;
546
547         /* accoun tpolicy operations */
548         if ((checkparms & BIT_ACCPOLICY) && !(checkparms & ~(BIT_ACCPOLICY + BIT_ACCPOLVAL))) {
549                 uint32 value;
550                 int field = account_policy_name_to_fieldnum(account_policy);
551                 if (field == 0) {
552                         fprintf(stderr, "No account policy by that name\n");
553                         exit(1);
554                 }
555                 if (!account_policy_get(field, &value)) {
556                         fprintf(stderr, "valid account policy, but unable to fetch value!\n");
557                         exit(1);
558                 }
559                 if (account_policy_value_set) {
560                         printf("account policy value for %s was %u\n", account_policy, value);
561                         if (!account_policy_set(field, account_policy_value)) {
562                                 fprintf(stderr, "valid account policy, but unable to set value!\n");
563                                 exit(1);
564                         }
565                         printf("account policy value for %s is now %lu\n", account_policy, account_policy_value);
566                         exit(0);
567                 } else {
568                         printf("account policy value for %s is %u\n", account_policy, value);
569                         exit(0);
570                 }
571         }
572
573         /* import and export operations */
574         if (((checkparms & BIT_IMPORT) || (checkparms & BIT_EXPORT))
575                         && !(checkparms & ~(BIT_IMPORT +BIT_EXPORT))) {
576                 if (backend_in) {
577                         if (!NT_STATUS_IS_OK(make_pdb_context_string(&bin, backend_in))) {
578                                 fprintf(stderr, "Can't initialize passdb backend.\n");
579                                 return 1;
580                         }
581                 } else {
582                         bin = bdef;
583                 }
584                 if (backend_out) {
585                         if (!NT_STATUS_IS_OK(make_pdb_context_string(&bout, backend_out))) {
586                                 fprintf(stderr, "Can't initialize %s.\n", backend_out);
587                                 return 1;
588                         }
589                 } else {
590                         bout = bdef;
591                 }
592                 return export_database(bin, bout);
593         }
594
595         /* if BIT_USER is defined but nothing else then threat it as -l -u for compatibility */
596         /* fake up BIT_LIST if only BIT_USER is defined */
597         if ((checkparms & BIT_USER) && !(checkparms & ~BIT_USER)) {
598                 checkparms += BIT_LIST;
599         }
600         
601         /* modify flag is optional to maintain backwards compatibility */
602         /* fake up BIT_MODIFY if BIT_USER  and at least one of MASK_USER_GOOD is defined */
603         if (!((checkparms & ~MASK_USER_GOOD) & ~BIT_USER) && (checkparms & MASK_USER_GOOD)) {
604                 checkparms += BIT_MODIFY;
605         }
606
607         /* list users operations */
608         if (checkparms & BIT_LIST) {
609                 if (!(checkparms & ~BIT_LIST)) {
610                         return print_users_list (bdef, verbose, spstyle);
611                 }
612                 if (!(checkparms & ~(BIT_USER + BIT_LIST))) {
613                         return print_user_info (bdef, user_name, verbose, spstyle);
614                 }
615         }
616         
617         /* mask out users options */
618         checkparms &= ~MASK_USER_GOOD;
619         
620         /* account operation */
621         if ((checkparms & BIT_CREATE) || (checkparms & BIT_MODIFY) || (checkparms & BIT_DELETE)) {
622                 /* check use of -u option */
623                 if (!(checkparms & BIT_USER)) {
624                         fprintf (stderr, "Username not specified! (use -u option)\n");
625                         return -1;
626                 }
627
628                 /* account creation operations */
629                 if (!(checkparms & ~(BIT_CREATE + BIT_USER + BIT_MACHINE))) {
630                         if (checkparms & BIT_MACHINE) {
631                                 return new_machine (bdef, user_name);
632                         } else {
633                                 return new_user (bdef, user_name, full_name, home_dir, 
634                                                  home_drive, logon_script, 
635                                                  profile_path);
636                         }
637                 }
638
639                 /* account deletion operations */
640                 if (!(checkparms & ~(BIT_DELETE + BIT_USER + BIT_MACHINE))) {
641                         if (checkparms & BIT_MACHINE) {
642                                 return delete_machine_entry (bdef, user_name);
643                         } else {
644                                 return delete_user_entry (bdef, user_name);
645                         }
646                 }
647
648                 /* account modification operations */
649                 if (!(checkparms & ~(BIT_MODIFY + BIT_USER))) {
650                         return set_user_info (bdef, user_name, full_name,
651                                               home_dir,
652                                               home_drive,
653                                               logon_script,
654                                               profile_path);
655                 }
656         }
657
658         if (setparms >= 0x20) {
659                 fprintf (stderr, "Incompatible or insufficient options on command line!\n");
660         }
661         poptPrintHelp(pc, stderr, 0);
662
663         return 1;
664 }