libgpo/security_CSE: fix unicode preamble check of SecEdit/GptTmpl.inf files.
[Samba.git] / source3 / utils / net_sam.c
blobb7b76e80937a6750869dcfaaced3f4f662888e69
1 /*
2 * Unix SMB/CIFS implementation.
3 * Local SAM access routines
4 * Copyright (C) Volker Lendecke 2006
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "system/passwd.h"
23 #include "utils/net.h"
24 #include "../librpc/gen_ndr/samr.h"
25 #include "smbldap.h"
26 #include "../libcli/security/security.h"
27 #include "lib/winbind_util.h"
28 #include "passdb.h"
29 #include "passdb/pdb_ldap_util.h"
30 #include "passdb/pdb_ldap_schema.h"
31 #include "lib/privileges.h"
32 #include "secrets.h"
35 * Set a user's data
38 static int net_sam_userset(struct net_context *c, int argc, const char **argv,
39 const char *field,
40 bool (*fn)(struct samu *, const char *,
41 enum pdb_value_state))
43 struct samu *sam_acct = NULL;
44 struct dom_sid sid;
45 enum lsa_SidType type;
46 const char *dom, *name;
47 NTSTATUS status;
49 if (argc != 2 || c->display_usage) {
50 d_fprintf(stderr, "%s\n", _("Usage:"));
51 d_fprintf(stderr, _("net sam set %s <user> <value>\n"),
52 field);
53 return -1;
56 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
57 &dom, &name, &sid, &type)) {
58 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
59 return -1;
62 if (type != SID_NAME_USER) {
63 d_fprintf(stderr, _("%s is a %s, not a user\n"), argv[0],
64 sid_type_lookup(type));
65 return -1;
68 if ( !(sam_acct = samu_new( NULL )) ) {
69 d_fprintf(stderr, _("Internal error\n"));
70 return -1;
73 if (!pdb_getsampwsid(sam_acct, &sid)) {
74 d_fprintf(stderr, _("Loading user %s failed\n"), argv[0]);
75 return -1;
78 if (!fn(sam_acct, argv[1], PDB_CHANGED)) {
79 d_fprintf(stderr, _("Internal error\n"));
80 return -1;
83 status = pdb_update_sam_account(sam_acct);
84 if (!NT_STATUS_IS_OK(status)) {
85 d_fprintf(stderr, _("Updating sam account %s failed with %s\n"),
86 argv[0], nt_errstr(status));
87 return -1;
90 TALLOC_FREE(sam_acct);
92 d_printf(_("Updated %s for %s\\%s to %s\n"), field, dom, name, argv[1]);
93 return 0;
96 static int net_sam_set_fullname(struct net_context *c, int argc,
97 const char **argv)
99 return net_sam_userset(c, argc, argv, "fullname",
100 pdb_set_fullname);
103 static int net_sam_set_logonscript(struct net_context *c, int argc,
104 const char **argv)
106 return net_sam_userset(c, argc, argv, "logonscript",
107 pdb_set_logon_script);
110 static int net_sam_set_profilepath(struct net_context *c, int argc,
111 const char **argv)
113 return net_sam_userset(c, argc, argv, "profilepath",
114 pdb_set_profile_path);
117 static int net_sam_set_homedrive(struct net_context *c, int argc,
118 const char **argv)
120 return net_sam_userset(c, argc, argv, "homedrive",
121 pdb_set_dir_drive);
124 static int net_sam_set_homedir(struct net_context *c, int argc,
125 const char **argv)
127 return net_sam_userset(c, argc, argv, "homedir",
128 pdb_set_homedir);
131 static int net_sam_set_workstations(struct net_context *c, int argc,
132 const char **argv)
134 return net_sam_userset(c, argc, argv, "workstations",
135 pdb_set_workstations);
139 * Set account flags
142 static int net_sam_set_userflag(struct net_context *c, int argc,
143 const char **argv, const char *field,
144 uint16 flag)
146 struct samu *sam_acct = NULL;
147 struct dom_sid sid;
148 enum lsa_SidType type;
149 const char *dom, *name;
150 NTSTATUS status;
151 uint32_t acct_flags;
153 if ((argc != 2) || c->display_usage ||
154 (!strequal(argv[1], "yes") &&
155 !strequal(argv[1], "no"))) {
156 d_fprintf(stderr, "%s\n", _("Usage:"));
157 d_fprintf(stderr, _("net sam set %s <user> [yes|no]\n"),
158 field);
159 return -1;
162 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
163 &dom, &name, &sid, &type)) {
164 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
165 return -1;
168 if (type != SID_NAME_USER) {
169 d_fprintf(stderr, _("%s is a %s, not a user\n"), argv[0],
170 sid_type_lookup(type));
171 return -1;
174 if ( !(sam_acct = samu_new( NULL )) ) {
175 d_fprintf(stderr, _("Internal error\n"));
176 return -1;
179 if (!pdb_getsampwsid(sam_acct, &sid)) {
180 d_fprintf(stderr, _("Loading user %s failed\n"), argv[0]);
181 return -1;
184 acct_flags = pdb_get_acct_ctrl(sam_acct);
186 if (strequal(argv[1], "yes")) {
187 acct_flags |= flag;
188 } else {
189 acct_flags &= ~flag;
192 pdb_set_acct_ctrl(sam_acct, acct_flags, PDB_CHANGED);
194 status = pdb_update_sam_account(sam_acct);
195 if (!NT_STATUS_IS_OK(status)) {
196 d_fprintf(stderr, _("Updating sam account %s failed with %s\n"),
197 argv[0], nt_errstr(status));
198 return -1;
201 TALLOC_FREE(sam_acct);
203 d_fprintf(stderr, _("Updated flag %s for %s\\%s to %s\n"), field, dom,
204 name, argv[1]);
205 return 0;
208 static int net_sam_set_disabled(struct net_context *c, int argc,
209 const char **argv)
211 return net_sam_set_userflag(c, argc, argv, "disabled", ACB_DISABLED);
214 static int net_sam_set_pwnotreq(struct net_context *c, int argc,
215 const char **argv)
217 return net_sam_set_userflag(c, argc, argv, "pwnotreq", ACB_PWNOTREQ);
220 static int net_sam_set_autolock(struct net_context *c, int argc,
221 const char **argv)
223 return net_sam_set_userflag(c, argc, argv, "autolock", ACB_AUTOLOCK);
226 static int net_sam_set_pwnoexp(struct net_context *c, int argc,
227 const char **argv)
229 return net_sam_set_userflag(c, argc, argv, "pwnoexp", ACB_PWNOEXP);
233 * Set pass last change time, based on force pass change now
236 static int net_sam_set_pwdmustchangenow(struct net_context *c, int argc,
237 const char **argv)
239 struct samu *sam_acct = NULL;
240 struct dom_sid sid;
241 enum lsa_SidType type;
242 const char *dom, *name;
243 NTSTATUS status;
245 if ((argc != 2) || c->display_usage ||
246 (!strequal(argv[1], "yes") &&
247 !strequal(argv[1], "no"))) {
248 d_fprintf(stderr, "%s\n%s",
249 _("Usage:"),
250 _("net sam set pwdmustchangenow <user> [yes|no]\n"));
251 return -1;
254 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
255 &dom, &name, &sid, &type)) {
256 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
257 return -1;
260 if (type != SID_NAME_USER) {
261 d_fprintf(stderr, _("%s is a %s, not a user\n"), argv[0],
262 sid_type_lookup(type));
263 return -1;
266 if ( !(sam_acct = samu_new( NULL )) ) {
267 d_fprintf(stderr, _("Internal error\n"));
268 return -1;
271 if (!pdb_getsampwsid(sam_acct, &sid)) {
272 d_fprintf(stderr, _("Loading user %s failed\n"), argv[0]);
273 return -1;
276 if (strequal(argv[1], "yes")) {
277 pdb_set_pass_last_set_time(sam_acct, 0, PDB_CHANGED);
278 } else {
279 pdb_set_pass_last_set_time(sam_acct, time(NULL), PDB_CHANGED);
282 status = pdb_update_sam_account(sam_acct);
283 if (!NT_STATUS_IS_OK(status)) {
284 d_fprintf(stderr, _("Updating sam account %s failed with %s\n"),
285 argv[0], nt_errstr(status));
286 return -1;
289 TALLOC_FREE(sam_acct);
291 d_fprintf(stderr, _("Updated 'user must change password at next logon' "
292 "for %s\\%s to %s\n"), dom,
293 name, argv[1]);
294 return 0;
299 * Set a user's or a group's comment
302 static int net_sam_set_comment(struct net_context *c, int argc,
303 const char **argv)
305 GROUP_MAP *map;
306 struct dom_sid sid;
307 enum lsa_SidType type;
308 const char *dom, *name;
309 NTSTATUS status;
311 if (argc != 2 || c->display_usage) {
312 d_fprintf(stderr, "%s\n%s",
313 _("Usage:"),
314 _("net sam set comment <name> <comment>\n"));
315 return -1;
318 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
319 &dom, &name, &sid, &type)) {
320 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
321 return -1;
324 if (type == SID_NAME_USER) {
325 return net_sam_userset(c, argc, argv, "comment",
326 pdb_set_acct_desc);
329 if ((type != SID_NAME_DOM_GRP) && (type != SID_NAME_ALIAS) &&
330 (type != SID_NAME_WKN_GRP)) {
331 d_fprintf(stderr, _("%s is a %s, not a group\n"), argv[0],
332 sid_type_lookup(type));
333 return -1;
336 map = talloc_zero(talloc_tos(), GROUP_MAP);
337 if (!map) {
338 d_fprintf(stderr, _("Out of memory!\n"));
339 return -1;
342 if (!pdb_getgrsid(map, sid)) {
343 d_fprintf(stderr, _("Could not load group %s\n"), argv[0]);
344 return -1;
347 map->comment = talloc_strdup(map, argv[1]);
348 if (!map->comment) {
349 d_fprintf(stderr, _("Out of memory!\n"));
350 return -1;
353 status = pdb_update_group_mapping_entry(map);
355 if (!NT_STATUS_IS_OK(status)) {
356 d_fprintf(stderr, _("Updating group mapping entry failed with "
357 "%s\n"), nt_errstr(status));
358 return -1;
361 d_printf("Updated comment of group %s\\%s to %s\n", dom, name,
362 argv[1]);
364 TALLOC_FREE(map);
365 return 0;
368 static int net_sam_set(struct net_context *c, int argc, const char **argv)
370 struct functable func[] = {
372 "homedir",
373 net_sam_set_homedir,
374 NET_TRANSPORT_LOCAL,
375 N_("Change a user's home directory"),
376 N_("net sam set homedir\n"
377 " Change a user's home directory")
380 "profilepath",
381 net_sam_set_profilepath,
382 NET_TRANSPORT_LOCAL,
383 N_("Change a user's profile path"),
384 N_("net sam set profilepath\n"
385 " Change a user's profile path")
388 "comment",
389 net_sam_set_comment,
390 NET_TRANSPORT_LOCAL,
391 N_("Change a users or groups description"),
392 N_("net sam set comment\n"
393 " Change a users or groups description")
396 "fullname",
397 net_sam_set_fullname,
398 NET_TRANSPORT_LOCAL,
399 N_("Change a user's full name"),
400 N_("net sam set fullname\n"
401 " Change a user's full name")
404 "logonscript",
405 net_sam_set_logonscript,
406 NET_TRANSPORT_LOCAL,
407 N_("Change a user's logon script"),
408 N_("net sam set logonscript\n"
409 " Change a user's logon script")
412 "homedrive",
413 net_sam_set_homedrive,
414 NET_TRANSPORT_LOCAL,
415 N_("Change a user's home drive"),
416 N_("net sam set homedrive\n"
417 " Change a user's home drive")
420 "workstations",
421 net_sam_set_workstations,
422 NET_TRANSPORT_LOCAL,
423 N_("Change a user's allowed workstations"),
424 N_("net sam set workstations\n"
425 " Change a user's allowed workstations")
428 "disabled",
429 net_sam_set_disabled,
430 NET_TRANSPORT_LOCAL,
431 N_("Disable/Enable a user"),
432 N_("net sam set disable\n"
433 " Disable/Enable a user")
436 "pwnotreq",
437 net_sam_set_pwnotreq,
438 NET_TRANSPORT_LOCAL,
439 N_("Disable/Enable the password not required flag"),
440 N_("net sam set pwnotreq\n"
441 " Disable/Enable the password not required flag")
444 "autolock",
445 net_sam_set_autolock,
446 NET_TRANSPORT_LOCAL,
447 N_("Disable/Enable a user's lockout flag"),
448 N_("net sam set autolock\n"
449 " Disable/Enable a user's lockout flag")
452 "pwnoexp",
453 net_sam_set_pwnoexp,
454 NET_TRANSPORT_LOCAL,
455 N_("Disable/Enable whether a user's pw does not "
456 "expire"),
457 N_("net sam set pwnoexp\n"
458 " Disable/Enable whether a user's pw does not "
459 "expire")
462 "pwdmustchangenow",
463 net_sam_set_pwdmustchangenow,
464 NET_TRANSPORT_LOCAL,
465 N_("Force users password must change at next logon"),
466 N_("net sam set pwdmustchangenow\n"
467 " Force users password must change at next logon")
469 {NULL, NULL, 0, NULL, NULL}
472 return net_run_function(c, argc, argv, "net sam set", func);
476 * Manage account policies
479 static int net_sam_policy_set(struct net_context *c, int argc, const char **argv)
481 const char *account_policy = NULL;
482 uint32 value = 0;
483 uint32 old_value = 0;
484 enum pdb_policy_type field;
485 char *endptr;
487 if (argc != 2 || c->display_usage) {
488 d_fprintf(stderr, "%s\n%s",
489 _("Usage:"),
490 _("net sam policy set \"<account policy>\" <value>\n"));
491 return -1;
494 account_policy = argv[0];
495 field = account_policy_name_to_typenum(account_policy);
497 if (strequal(argv[1], "forever") || strequal(argv[1], "never")
498 || strequal(argv[1], "off")) {
499 value = -1;
501 else {
502 value = strtoul(argv[1], &endptr, 10);
504 if ((endptr == argv[1]) || (endptr[0] != '\0')) {
505 d_printf(_("Unable to set policy \"%s\"! Invalid value "
506 "\"%s\".\n"),
507 account_policy, argv[1]);
508 return -1;
512 if (field == 0) {
513 const char **names;
514 int i, count;
516 account_policy_names_list(talloc_tos(), &names, &count);
517 d_fprintf(stderr, _("No account policy \"%s\"!\n\n"), argv[0]);
518 d_fprintf(stderr, _("Valid account policies are:\n"));
520 for (i=0; i<count; i++) {
521 d_fprintf(stderr, "%s\n", names[i]);
524 TALLOC_FREE(names);
526 return -1;
529 if (!pdb_get_account_policy(field, &old_value)) {
530 d_fprintf(stderr, _("Valid account policy, but unable to fetch "
531 "value!\n"));
532 } else {
533 d_printf(_("Account policy \"%s\" value was: %d\n"),
534 account_policy, old_value);
537 if (!pdb_set_account_policy(field, value)) {
538 d_fprintf(stderr, _("Valid account policy, but unable to "
539 "set value!\n"));
540 return -1;
541 } else {
542 d_printf(_("Account policy \"%s\" value is now: %d\n"),
543 account_policy, value);
546 return 0;
549 static int net_sam_policy_show(struct net_context *c, int argc, const char **argv)
551 const char *account_policy = NULL;
552 uint32 old_value;
553 enum pdb_policy_type field;
555 if (argc != 1 || c->display_usage) {
556 d_fprintf(stderr, "%s\n%s",
557 _("Usage:"),
558 _("net sam policy show \"<account policy>\"\n"));
559 return -1;
562 account_policy = argv[0];
563 field = account_policy_name_to_typenum(account_policy);
565 if (field == 0) {
566 const char **names;
567 int count;
568 int i;
569 account_policy_names_list(talloc_tos(), &names, &count);
570 d_fprintf(stderr, _("No account policy by that name!\n"));
571 if (count != 0) {
572 d_fprintf(stderr, _("Valid account policies "
573 "are:\n"));
574 for (i=0; i<count; i++) {
575 d_fprintf(stderr, "%s\n", names[i]);
578 TALLOC_FREE(names);
579 return -1;
582 if (!pdb_get_account_policy(field, &old_value)) {
583 fprintf(stderr, _("Valid account policy, but unable to "
584 "fetch value!\n"));
585 return -1;
588 printf(_("Account policy \"%s\" description: %s\n"),
589 account_policy, account_policy_get_desc(field));
590 printf(_("Account policy \"%s\" value is: %d\n"), account_policy,
591 old_value);
592 return 0;
595 static int net_sam_policy_list(struct net_context *c, int argc, const char **argv)
597 const char **names;
598 int count;
599 int i;
601 if (c->display_usage) {
602 d_printf( "%s\n"
603 "net sam policy list\n"
604 " %s\n",
605 _("Usage:"),
606 _("List account policies"));
607 return 0;
610 account_policy_names_list(talloc_tos(), &names, &count);
611 if (count != 0) {
612 d_fprintf(stderr, _("Valid account policies "
613 "are:\n"));
614 for (i = 0; i < count ; i++) {
615 d_fprintf(stderr, "%s\n", names[i]);
618 TALLOC_FREE(names);
619 return -1;
622 static int net_sam_policy(struct net_context *c, int argc, const char **argv)
624 struct functable func[] = {
626 "list",
627 net_sam_policy_list,
628 NET_TRANSPORT_LOCAL,
629 N_("List account policies"),
630 N_("net sam policy list\n"
631 " List account policies")
634 "show",
635 net_sam_policy_show,
636 NET_TRANSPORT_LOCAL,
637 N_("Show account policies"),
638 N_("net sam policy show\n"
639 " Show account policies")
642 "set",
643 net_sam_policy_set,
644 NET_TRANSPORT_LOCAL,
645 N_("Change account policies"),
646 N_("net sam policy set\n"
647 " Change account policies")
649 {NULL, NULL, 0, NULL, NULL}
652 return net_run_function(c, argc, argv, "net sam policy", func);
655 static int net_sam_rights_list(struct net_context *c, int argc,
656 const char **argv)
658 enum sec_privilege privilege;
660 if (argc > 1 || c->display_usage) {
661 d_fprintf(stderr, "%s\n%s",
662 _("Usage:"),
663 _("net sam rights list [privilege name]\n"));
664 return -1;
667 if (argc == 0) {
668 int i;
669 int num = num_privileges_in_short_list();
671 for (i=0; i<num; i++) {
672 d_printf("%s\n", sec_privilege_name_from_index(i));
674 return 0;
677 privilege = sec_privilege_id(argv[0]);
679 if (privilege != SEC_PRIV_INVALID) {
680 struct dom_sid *sids;
681 int i, num_sids;
682 NTSTATUS status;
684 status = privilege_enum_sids(privilege, talloc_tos(),
685 &sids, &num_sids);
686 if (!NT_STATUS_IS_OK(status)) {
687 d_fprintf(stderr, _("Could not list rights: %s\n"),
688 nt_errstr(status));
689 return -1;
692 for (i=0; i<num_sids; i++) {
693 const char *dom, *name;
694 enum lsa_SidType type;
696 if (lookup_sid(talloc_tos(), &sids[i], &dom, &name,
697 &type)) {
698 d_printf("%s\\%s\n", dom, name);
700 else {
701 d_printf("%s\n", sid_string_tos(&sids[i]));
704 return 0;
707 return -1;
710 static int net_sam_rights_grant(struct net_context *c, int argc,
711 const char **argv)
713 struct dom_sid sid;
714 enum lsa_SidType type;
715 const char *dom, *name;
716 int i;
718 if (argc < 2 || c->display_usage) {
719 d_fprintf(stderr, "%s\n%s",
720 _("Usage:"),
721 _("net sam rights grant <name> <rights> ...\n"));
722 return -1;
725 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
726 &dom, &name, &sid, &type)) {
727 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
728 return -1;
731 for (i=1; i < argc; i++) {
732 enum sec_privilege privilege = sec_privilege_id(argv[i]);
733 if (privilege == SEC_PRIV_INVALID) {
734 d_fprintf(stderr, _("%s unknown\n"), argv[i]);
735 return -1;
738 if (!grant_privilege_by_name(&sid, argv[i])) {
739 d_fprintf(stderr, _("Could not grant privilege\n"));
740 return -1;
743 d_printf(_("Granted %s to %s\\%s\n"), argv[i], dom, name);
746 return 0;
749 static int net_sam_rights_revoke(struct net_context *c, int argc,
750 const char **argv)
752 struct dom_sid sid;
753 enum lsa_SidType type;
754 const char *dom, *name;
755 int i;
757 if (argc < 2 || c->display_usage) {
758 d_fprintf(stderr, "%s\n%s",
759 _("Usage:"),
760 _("net sam rights revoke <name> <rights>\n"));
761 return -1;
764 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
765 &dom, &name, &sid, &type)) {
766 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
767 return -1;
770 for (i=1; i < argc; i++) {
771 enum sec_privilege privilege = sec_privilege_id(argv[i]);
772 if (privilege == SEC_PRIV_INVALID) {
773 d_fprintf(stderr, _("%s unknown\n"), argv[i]);
774 return -1;
777 if (!revoke_privilege_by_name(&sid, argv[i])) {
778 d_fprintf(stderr, _("Could not revoke privilege\n"));
779 return -1;
782 d_printf(_("Revoked %s from %s\\%s\n"), argv[i], dom, name);
785 return 0;
788 static int net_sam_rights(struct net_context *c, int argc, const char **argv)
790 struct functable func[] = {
792 "list",
793 net_sam_rights_list,
794 NET_TRANSPORT_LOCAL,
795 N_("List possible user rights"),
796 N_("net sam rights list\n"
797 " List possible user rights")
800 "grant",
801 net_sam_rights_grant,
802 NET_TRANSPORT_LOCAL,
803 N_("Grant right(s)"),
804 N_("net sam rights grant\n"
805 " Grant right(s)")
808 "revoke",
809 net_sam_rights_revoke,
810 NET_TRANSPORT_LOCAL,
811 N_("Revoke right(s)"),
812 N_("net sam rights revoke\n"
813 " Revoke right(s)")
815 {NULL, NULL, 0, NULL, NULL}
817 return net_run_function(c, argc, argv, "net sam rights", func);
821 * Map a unix group to a domain group
824 static NTSTATUS map_unix_group(const struct group *grp, GROUP_MAP *map)
826 const char *dom, *name;
827 uint32 rid;
829 if (pdb_getgrgid(map, grp->gr_gid)) {
830 return NT_STATUS_GROUP_EXISTS;
833 map->gid = grp->gr_gid;
835 if (lookup_name(talloc_tos(), grp->gr_name, LOOKUP_NAME_LOCAL,
836 &dom, &name, NULL, NULL)) {
838 map->nt_name = talloc_asprintf(map, "Unix Group %s",
839 grp->gr_name);
841 DEBUG(5, ("%s exists as %s\\%s, retrying as \"%s\"\n",
842 grp->gr_name, dom, name, map->nt_name));
845 if (lookup_name(talloc_tos(), grp->gr_name, LOOKUP_NAME_LOCAL,
846 NULL, NULL, NULL, NULL)) {
847 DEBUG(3, ("\"%s\" exists, can't map it\n", grp->gr_name));
848 return NT_STATUS_GROUP_EXISTS;
851 if (pdb_capabilities() & PDB_CAP_STORE_RIDS) {
852 if (!pdb_new_rid(&rid)) {
853 DEBUG(3, ("Could not get a new RID for %s\n",
854 grp->gr_name));
855 return NT_STATUS_ACCESS_DENIED;
857 } else {
858 rid = algorithmic_pdb_gid_to_group_rid( grp->gr_gid );
861 sid_compose(&map->sid, get_global_sam_sid(), rid);
862 map->sid_name_use = SID_NAME_DOM_GRP;
863 map->comment = talloc_asprintf(map, "Unix Group %s", grp->gr_name);
865 return pdb_add_group_mapping_entry(map);
868 static int net_sam_mapunixgroup(struct net_context *c, int argc, const char **argv)
870 NTSTATUS status;
871 GROUP_MAP *map;
872 struct group *grp;
874 if (argc != 1 || c->display_usage) {
875 d_fprintf(stderr, "%s\n%s",
876 _("Usage:"),
877 _("net sam mapunixgroup <name>\n"));
878 return -1;
881 grp = getgrnam(argv[0]);
882 if (grp == NULL) {
883 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
884 return -1;
887 map = talloc_zero(talloc_tos(), GROUP_MAP);
888 if (!map) {
889 d_fprintf(stderr, _("Out of memory!\n"));
890 return -1;
893 status = map_unix_group(grp, map);
895 if (!NT_STATUS_IS_OK(status)) {
896 d_fprintf(stderr, _("Mapping group %s failed with %s\n"),
897 argv[0], nt_errstr(status));
898 return -1;
901 d_printf(_("Mapped unix group %s to SID %s\n"), argv[0],
902 sid_string_tos(&map->sid));
904 TALLOC_FREE(map);
905 return 0;
909 * Remove a group mapping
912 static NTSTATUS unmap_unix_group(const struct group *grp)
914 struct dom_sid dom_sid;
916 if (!lookup_name(talloc_tos(), grp->gr_name, LOOKUP_NAME_LOCAL,
917 NULL, NULL, NULL, NULL)) {
918 DEBUG(3, ("\"%s\" does not exist, can't unmap it\n", grp->gr_name));
919 return NT_STATUS_NO_SUCH_GROUP;
922 if (!pdb_gid_to_sid(grp->gr_gid, &dom_sid)) {
923 return NT_STATUS_UNSUCCESSFUL;
926 return pdb_delete_group_mapping_entry(dom_sid);
929 static int net_sam_unmapunixgroup(struct net_context *c, int argc, const char **argv)
931 NTSTATUS status;
932 struct group *grp;
934 if (argc != 1 || c->display_usage) {
935 d_fprintf(stderr, "%s\n%s",
936 _("Usage:"),
937 _("net sam unmapunixgroup <name>\n"));
938 return -1;
941 grp = getgrnam(argv[0]);
942 if (grp == NULL) {
943 d_fprintf(stderr, _("Could not find mapping for group %s.\n"),
944 argv[0]);
945 return -1;
948 status = unmap_unix_group(grp);
950 if (!NT_STATUS_IS_OK(status)) {
951 d_fprintf(stderr, _("Unmapping group %s failed with %s.\n"),
952 argv[0], nt_errstr(status));
953 return -1;
956 d_printf(_("Unmapped unix group %s.\n"), argv[0]);
958 return 0;
962 * Create a domain group
965 static int net_sam_createdomaingroup(struct net_context *c, int argc,
966 const char **argv)
968 NTSTATUS status;
969 uint32 rid;
971 if (argc != 1 || c->display_usage) {
972 d_fprintf(stderr, "%s\n%s",
973 _("Usage:"),
974 _("net sam createdomaingroup <name>\n"));
975 return -1;
978 status = pdb_create_dom_group(talloc_tos(), argv[0], &rid);
980 if (!NT_STATUS_IS_OK(status)) {
981 d_fprintf(stderr, _("Creating %s failed with %s\n"),
982 argv[0], nt_errstr(status));
983 return -1;
986 d_printf(_("Created domain group %s with RID %d\n"), argv[0], rid);
988 return 0;
992 * Delete a domain group
995 static int net_sam_deletedomaingroup(struct net_context *c, int argc,
996 const char **argv)
998 struct dom_sid sid;
999 uint32_t rid;
1000 enum lsa_SidType type;
1001 const char *dom, *name;
1002 NTSTATUS status;
1004 if (argc != 1 || c->display_usage) {
1005 d_fprintf(stderr, "%s\n%s",
1006 _("Usage:"),
1007 _("net sam deletelocalgroup <name>\n"));
1008 return -1;
1011 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1012 &dom, &name, &sid, &type)) {
1013 d_fprintf(stderr, _("Could not find %s.\n"), argv[0]);
1014 return -1;
1017 if (type != SID_NAME_DOM_GRP) {
1018 d_fprintf(stderr, _("%s is a %s, not a domain group.\n"),
1019 argv[0], sid_type_lookup(type));
1020 return -1;
1023 sid_peek_rid(&sid, &rid);
1025 status = pdb_delete_dom_group(talloc_tos(), rid);
1027 if (!NT_STATUS_IS_OK(status)) {
1028 d_fprintf(stderr,_("Deleting domain group %s failed with %s\n"),
1029 argv[0], nt_errstr(status));
1030 return -1;
1033 d_printf(_("Deleted domain group %s.\n"), argv[0]);
1035 return 0;
1039 * Create a local group
1042 static int net_sam_createlocalgroup(struct net_context *c, int argc, const char **argv)
1044 NTSTATUS status;
1045 uint32 rid;
1047 if (argc != 1 || c->display_usage) {
1048 d_fprintf(stderr, "%s\n%s",
1049 _("Usage:"),
1050 _("net sam createlocalgroup <name>\n"));
1051 return -1;
1054 if (!winbind_ping()) {
1055 d_fprintf(stderr, _("winbind seems not to run. "
1056 "createlocalgroup only works when winbind runs.\n"));
1057 return -1;
1060 status = pdb_create_alias(argv[0], &rid);
1062 if (!NT_STATUS_IS_OK(status)) {
1063 d_fprintf(stderr, _("Creating %s failed with %s\n"),
1064 argv[0], nt_errstr(status));
1065 return -1;
1068 d_printf(_("Created local group %s with RID %d\n"), argv[0], rid);
1070 return 0;
1074 * Delete a local group
1077 static int net_sam_deletelocalgroup(struct net_context *c, int argc, const char **argv)
1079 struct dom_sid sid;
1080 enum lsa_SidType type;
1081 const char *dom, *name;
1082 NTSTATUS status;
1084 if (argc != 1 || c->display_usage) {
1085 d_fprintf(stderr, "%s\n%s",
1086 _("Usage:"),
1087 _("net sam deletelocalgroup <name>\n"));
1088 return -1;
1091 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1092 &dom, &name, &sid, &type)) {
1093 d_fprintf(stderr,_("Could not find %s.\n"), argv[0]);
1094 return -1;
1097 if (type != SID_NAME_ALIAS) {
1098 d_fprintf(stderr, _("%s is a %s, not a local group.\n"),argv[0],
1099 sid_type_lookup(type));
1100 return -1;
1103 status = pdb_delete_alias(&sid);
1105 if (!NT_STATUS_IS_OK(status)) {
1106 d_fprintf(stderr, _("Deleting local group %s failed with %s\n"),
1107 argv[0], nt_errstr(status));
1108 return -1;
1111 d_printf(_("Deleted local group %s.\n"), argv[0]);
1113 return 0;
1117 * Create a builtin group
1120 static int net_sam_createbuiltingroup(struct net_context *c, int argc, const char **argv)
1122 NTSTATUS status;
1123 uint32 rid;
1124 enum lsa_SidType type;
1125 fstring groupname;
1126 struct dom_sid sid;
1128 if (argc != 1 || c->display_usage) {
1129 d_fprintf(stderr, "%s\n%s",
1130 _("Usage:"),
1131 _("net sam createbuiltingroup <name>\n"));
1132 return -1;
1135 if (!winbind_ping()) {
1136 d_fprintf(stderr, _("winbind seems not to run. "
1137 "createbuiltingroup only works when winbind "
1138 "runs.\n"));
1139 return -1;
1142 /* validate the name and get the group */
1144 fstrcpy( groupname, "BUILTIN\\" );
1145 fstrcat( groupname, argv[0] );
1147 if ( !lookup_name(talloc_tos(), groupname, LOOKUP_NAME_ALL, NULL,
1148 NULL, &sid, &type)) {
1149 d_fprintf(stderr, _("%s is not a BUILTIN group\n"), argv[0]);
1150 return -1;
1153 if ( !sid_peek_rid( &sid, &rid ) ) {
1154 d_fprintf(stderr, _("Failed to get RID for %s\n"), argv[0]);
1155 return -1;
1158 status = pdb_create_builtin(rid);
1160 if (!NT_STATUS_IS_OK(status)) {
1161 d_fprintf(stderr, _("Creating %s failed with %s\n"),
1162 argv[0], nt_errstr(status));
1163 return -1;
1166 d_printf(_("Created BUILTIN group %s with RID %d\n"), argv[0], rid);
1168 return 0;
1172 * Add a group member
1175 static int net_sam_addmem(struct net_context *c, int argc, const char **argv)
1177 const char *groupdomain, *groupname, *memberdomain, *membername;
1178 struct dom_sid group, member;
1179 enum lsa_SidType grouptype, membertype;
1180 NTSTATUS status;
1182 if (argc != 2 || c->display_usage) {
1183 d_fprintf(stderr, "%s\n%s",
1184 _("Usage:"),
1185 _("net sam addmem <group> <member>\n"));
1186 return -1;
1189 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1190 &groupdomain, &groupname, &group, &grouptype)) {
1191 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
1192 return -1;
1195 /* check to see if the member to be added is a name or a SID */
1197 if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_LOCAL,
1198 &memberdomain, &membername, &member, &membertype))
1200 /* try it as a SID */
1202 if ( !string_to_sid( &member, argv[1] ) ) {
1203 d_fprintf(stderr, _("Could not find member %s\n"),
1204 argv[1]);
1205 return -1;
1208 if ( !lookup_sid(talloc_tos(), &member, &memberdomain,
1209 &membername, &membertype) )
1211 d_fprintf(stderr, _("Could not resolve SID %s\n"),
1212 argv[1]);
1213 return -1;
1217 if ((grouptype == SID_NAME_ALIAS) || (grouptype == SID_NAME_WKN_GRP)) {
1218 if ((membertype != SID_NAME_USER) &&
1219 (membertype != SID_NAME_DOM_GRP)) {
1220 d_fprintf(stderr, _("%s is a local group, only users "
1221 "and domain groups can be added.\n"
1222 "%s is a %s\n"), argv[0], argv[1],
1223 sid_type_lookup(membertype));
1224 return -1;
1226 status = pdb_add_aliasmem(&group, &member);
1228 if (!NT_STATUS_IS_OK(status)) {
1229 d_fprintf(stderr, _("Adding local group member failed "
1230 "with %s\n"), nt_errstr(status));
1231 return -1;
1233 } else if (grouptype == SID_NAME_DOM_GRP) {
1234 uint32_t grouprid, memberrid;
1236 sid_peek_rid(&group, &grouprid);
1237 sid_peek_rid(&member, &memberrid);
1239 status = pdb_add_groupmem(talloc_tos(), grouprid, memberrid);
1240 if (!NT_STATUS_IS_OK(status)) {
1241 d_fprintf(stderr, _("Adding domain group member failed "
1242 "with %s\n"), nt_errstr(status));
1243 return -1;
1245 } else {
1246 d_fprintf(stderr, _("Can only add members to local groups so "
1247 "far, %s is a %s\n"), argv[0],
1248 sid_type_lookup(grouptype));
1249 return -1;
1252 d_printf(_("Added %s\\%s to %s\\%s\n"), memberdomain, membername,
1253 groupdomain, groupname);
1255 return 0;
1259 * Delete a group member
1262 static int net_sam_delmem(struct net_context *c, int argc, const char **argv)
1264 const char *groupdomain, *groupname;
1265 const char *memberdomain = NULL;
1266 const char *membername = NULL;
1267 struct dom_sid group, member;
1268 enum lsa_SidType grouptype;
1269 NTSTATUS status;
1271 if (argc != 2 || c->display_usage) {
1272 d_fprintf(stderr,"%s\n%s",
1273 _("Usage:"),
1274 _("net sam delmem <group> <member>\n"));
1275 return -1;
1278 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1279 &groupdomain, &groupname, &group, &grouptype)) {
1280 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
1281 return -1;
1284 if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_LOCAL,
1285 &memberdomain, &membername, &member, NULL)) {
1286 if (!string_to_sid(&member, argv[1])) {
1287 d_fprintf(stderr, _("Could not find member %s\n"),
1288 argv[1]);
1289 return -1;
1293 if ((grouptype == SID_NAME_ALIAS) ||
1294 (grouptype == SID_NAME_WKN_GRP)) {
1295 status = pdb_del_aliasmem(&group, &member);
1297 if (!NT_STATUS_IS_OK(status)) {
1298 d_fprintf(stderr,_("Deleting local group member failed "
1299 "with %s\n"), nt_errstr(status));
1300 return -1;
1302 } else if (grouptype == SID_NAME_DOM_GRP) {
1303 uint32_t grouprid, memberrid;
1305 sid_peek_rid(&group, &grouprid);
1306 sid_peek_rid(&member, &memberrid);
1308 status = pdb_del_groupmem(talloc_tos(), grouprid, memberrid);
1309 if (!NT_STATUS_IS_OK(status)) {
1310 d_fprintf(stderr, _("Deleting domain group member "
1311 "failed with %s\n"), nt_errstr(status));
1312 return -1;
1314 } else {
1315 d_fprintf(stderr, _("Can only delete members from local groups "
1316 "so far, %s is a %s\n"), argv[0],
1317 sid_type_lookup(grouptype));
1318 return -1;
1321 if (membername != NULL) {
1322 d_printf(_("Deleted %s\\%s from %s\\%s\n"),
1323 memberdomain, membername, groupdomain, groupname);
1324 } else {
1325 d_printf(_("Deleted %s from %s\\%s\n"),
1326 sid_string_tos(&member), groupdomain, groupname);
1329 return 0;
1333 * List group members
1336 static int net_sam_listmem(struct net_context *c, int argc, const char **argv)
1338 const char *groupdomain, *groupname;
1339 struct dom_sid group;
1340 struct dom_sid *members = NULL;
1341 size_t i, num_members = 0;
1342 enum lsa_SidType grouptype;
1343 NTSTATUS status;
1345 if (argc != 1 || c->display_usage) {
1346 d_fprintf(stderr, "%s\n%s",
1347 _("Usage:"),
1348 _("net sam listmem <group>\n"));
1349 return -1;
1352 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1353 &groupdomain, &groupname, &group, &grouptype)) {
1354 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
1355 return -1;
1358 if ((grouptype == SID_NAME_ALIAS) ||
1359 (grouptype == SID_NAME_WKN_GRP)) {
1360 status = pdb_enum_aliasmem(&group, talloc_tos(), &members,
1361 &num_members);
1362 if (!NT_STATUS_IS_OK(status)) {
1363 d_fprintf(stderr, _("Listing group members failed with "
1364 "%s\n"), nt_errstr(status));
1365 return -1;
1367 } else if (grouptype == SID_NAME_DOM_GRP) {
1368 uint32_t *rids;
1370 status = pdb_enum_group_members(talloc_tos(), &group,
1371 &rids, &num_members);
1372 if (!NT_STATUS_IS_OK(status)) {
1373 d_fprintf(stderr, _("Listing group members failed with "
1374 "%s\n"), nt_errstr(status));
1375 return -1;
1378 members = talloc_array(talloc_tos(), struct dom_sid,
1379 num_members);
1380 if (members == NULL) {
1381 TALLOC_FREE(rids);
1382 return -1;
1385 for (i=0; i<num_members; i++) {
1386 sid_compose(&members[i], get_global_sam_sid(),
1387 rids[i]);
1389 TALLOC_FREE(rids);
1390 } else {
1391 d_fprintf(stderr,_("Can only list local group members so far.\n"
1392 "%s is a %s\n"), argv[0], sid_type_lookup(grouptype));
1393 return -1;
1396 d_printf(_("%s\\%s has %u members\n"), groupdomain, groupname,
1397 (unsigned int)num_members);
1398 for (i=0; i<num_members; i++) {
1399 const char *dom, *name;
1400 if (lookup_sid(talloc_tos(), &members[i], &dom, &name, NULL)) {
1401 d_printf(" %s\\%s\n", dom, name);
1402 } else {
1403 d_printf(" %s\n", sid_string_tos(&members[i]));
1407 TALLOC_FREE(members);
1409 return 0;
1413 * Do the listing
1415 static int net_sam_do_list(struct net_context *c, int argc, const char **argv,
1416 struct pdb_search *search, const char *what)
1418 bool verbose = (argc == 1);
1420 if ((argc > 1) || c->display_usage ||
1421 ((argc == 1) && !strequal(argv[0], "verbose"))) {
1422 d_fprintf(stderr, "%s\n", _("Usage:"));
1423 d_fprintf(stderr, _("net sam list %s [verbose]\n"), what);
1424 return -1;
1427 if (search == NULL) {
1428 d_fprintf(stderr, _("Could not start search\n"));
1429 return -1;
1432 while (true) {
1433 struct samr_displayentry entry;
1434 if (!search->next_entry(search, &entry)) {
1435 break;
1437 if (verbose) {
1438 d_printf("%s:%d:%s\n",
1439 entry.account_name,
1440 entry.rid,
1441 entry.description);
1442 } else {
1443 d_printf("%s\n", entry.account_name);
1447 TALLOC_FREE(search);
1448 return 0;
1451 static int net_sam_list_users(struct net_context *c, int argc,
1452 const char **argv)
1454 return net_sam_do_list(c, argc, argv,
1455 pdb_search_users(talloc_tos(), ACB_NORMAL),
1456 "users");
1459 static int net_sam_list_groups(struct net_context *c, int argc,
1460 const char **argv)
1462 return net_sam_do_list(c, argc, argv, pdb_search_groups(talloc_tos()),
1463 "groups");
1466 static int net_sam_list_localgroups(struct net_context *c, int argc,
1467 const char **argv)
1469 return net_sam_do_list(c, argc, argv,
1470 pdb_search_aliases(talloc_tos(),
1471 get_global_sam_sid()),
1472 "localgroups");
1475 static int net_sam_list_builtin(struct net_context *c, int argc,
1476 const char **argv)
1478 return net_sam_do_list(c, argc, argv,
1479 pdb_search_aliases(talloc_tos(),
1480 &global_sid_Builtin),
1481 "builtin");
1484 static int net_sam_list_workstations(struct net_context *c, int argc,
1485 const char **argv)
1487 return net_sam_do_list(c, argc, argv,
1488 pdb_search_users(talloc_tos(), ACB_WSTRUST),
1489 "workstations");
1493 * List stuff
1496 static int net_sam_list(struct net_context *c, int argc, const char **argv)
1498 struct functable func[] = {
1500 "users",
1501 net_sam_list_users,
1502 NET_TRANSPORT_LOCAL,
1503 N_("List SAM users"),
1504 N_("net sam list users\n"
1505 " List SAM users")
1508 "groups",
1509 net_sam_list_groups,
1510 NET_TRANSPORT_LOCAL,
1511 N_("List SAM groups"),
1512 N_("net sam list groups\n"
1513 " List SAM groups")
1516 "localgroups",
1517 net_sam_list_localgroups,
1518 NET_TRANSPORT_LOCAL,
1519 N_("List SAM local groups"),
1520 N_("net sam list localgroups\n"
1521 " List SAM local groups")
1524 "builtin",
1525 net_sam_list_builtin,
1526 NET_TRANSPORT_LOCAL,
1527 N_("List builtin groups"),
1528 N_("net sam list builtin\n"
1529 " List builtin groups")
1532 "workstations",
1533 net_sam_list_workstations,
1534 NET_TRANSPORT_LOCAL,
1535 N_("List domain member workstations"),
1536 N_("net sam list workstations\n"
1537 " List domain member workstations")
1539 {NULL, NULL, 0, NULL, NULL}
1542 return net_run_function(c, argc, argv, "net sam list", func);
1546 * Show details of SAM entries
1549 static int net_sam_show(struct net_context *c, int argc, const char **argv)
1551 struct dom_sid sid;
1552 enum lsa_SidType type;
1553 const char *dom, *name;
1555 if (argc != 1 || c->display_usage) {
1556 d_fprintf(stderr, "%s\n%s",
1557 _("Usage:"),
1558 _("net sam show <name>\n"));
1559 return -1;
1562 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1563 &dom, &name, &sid, &type)) {
1564 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
1565 return -1;
1568 d_printf(_("%s\\%s is a %s with SID %s\n"), dom, name,
1569 sid_type_lookup(type), sid_string_tos(&sid));
1571 return 0;
1574 #ifdef HAVE_LDAP
1577 * Init an LDAP tree with default users and Groups
1578 * if ldapsam:editposix is enabled
1581 static int net_sam_provision(struct net_context *c, int argc, const char **argv)
1583 TALLOC_CTX *tc;
1584 char *ldap_bk;
1585 char *ldap_uri = NULL;
1586 char *p;
1587 struct smbldap_state *state = NULL;
1588 GROUP_MAP *gmap = NULL;
1589 struct dom_sid gsid;
1590 gid_t domusers_gid = -1;
1591 gid_t domadmins_gid = -1;
1592 struct samu *samuser;
1593 struct passwd *pwd;
1594 bool is_ipa = false;
1595 char *bind_dn = NULL;
1596 char *bind_secret = NULL;
1597 NTSTATUS status;
1599 if (c->display_usage) {
1600 d_printf( "%s\n"
1601 "net sam provision\n"
1602 " %s\n",
1603 _("Usage:"),
1604 _("Init an LDAP tree with default users/groups"));
1605 return 0;
1608 tc = talloc_new(NULL);
1609 if (!tc) {
1610 d_fprintf(stderr, _("Out of Memory!\n"));
1611 return -1;
1614 if ((ldap_bk = talloc_strdup(tc, lp_passdb_backend())) == NULL) {
1615 d_fprintf(stderr, _("talloc failed\n"));
1616 talloc_free(tc);
1617 return -1;
1619 p = strchr(ldap_bk, ':');
1620 if (p) {
1621 *p = 0;
1622 ldap_uri = talloc_strdup(tc, p+1);
1623 trim_char(ldap_uri, ' ', ' ');
1626 trim_char(ldap_bk, ' ', ' ');
1628 if (strcmp(ldap_bk, "IPA_ldapsam") == 0 ) {
1629 is_ipa = true;
1632 if (strcmp(ldap_bk, "ldapsam") != 0 && !is_ipa ) {
1633 d_fprintf(stderr,
1634 _("Provisioning works only with ldapsam backend\n"));
1635 goto failed;
1638 if (!lp_parm_bool(-1, "ldapsam", "trusted", false) ||
1639 !lp_parm_bool(-1, "ldapsam", "editposix", false)) {
1641 d_fprintf(stderr, _("Provisioning works only if ldapsam:trusted"
1642 " and ldapsam:editposix are enabled.\n"));
1643 goto failed;
1646 if (!is_ipa && !winbind_ping()) {
1647 d_fprintf(stderr, _("winbind seems not to run. Provisioning "
1648 "LDAP only works when winbind runs.\n"));
1649 goto failed;
1652 if (!fetch_ldap_pw(&bind_dn, &bind_secret)) {
1653 d_fprintf(stderr, _("Failed to retrieve LDAP password from secrets.tdb\n"));
1654 goto failed;
1657 status = smbldap_init(tc, NULL, ldap_uri, false, bind_dn, bind_secret, &state);
1659 memset(bind_secret, '\0', strlen(bind_secret));
1660 SAFE_FREE(bind_secret);
1661 SAFE_FREE(bind_dn);
1663 if (!NT_STATUS_IS_OK(status)) {
1664 d_fprintf(stderr, _("Unable to connect to the LDAP server.\n"));
1665 goto failed;
1668 d_printf(_("Checking for Domain Users group.\n"));
1670 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_USERS);
1672 gmap = talloc_zero(tc, GROUP_MAP);
1673 if (!gmap) {
1674 d_printf(_("Out of memory!\n"));
1675 goto failed;
1678 if (!pdb_getgrsid(gmap, gsid)) {
1679 LDAPMod **mods = NULL;
1680 char *dn;
1681 char *uname;
1682 char *wname;
1683 char *gidstr;
1684 char *gtype;
1685 int rc;
1687 d_printf(_("Adding the Domain Users group.\n"));
1689 /* lets allocate a new groupid for this group */
1690 if (is_ipa) {
1691 domusers_gid = 999;
1692 } else {
1693 if (!winbind_allocate_gid(&domusers_gid)) {
1694 d_fprintf(stderr, _("Unable to allocate a new gid to "
1695 "create Domain Users group!\n"));
1696 goto domu_done;
1700 uname = talloc_strdup(tc, "domusers");
1701 wname = talloc_strdup(tc, "Domain Users");
1702 dn = talloc_asprintf(tc, "cn=%s,%s", "domusers",
1703 lp_ldap_group_suffix(talloc_tos()));
1704 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domusers_gid);
1705 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
1707 if (!uname || !wname || !dn || !gidstr || !gtype) {
1708 d_fprintf(stderr, "Out of Memory!\n");
1709 goto failed;
1712 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
1713 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
1714 if (is_ipa) {
1715 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
1716 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
1717 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
1719 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
1720 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
1721 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1722 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
1723 sid_string_talloc(tc, &gsid));
1724 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
1726 smbldap_talloc_autofree_ldapmod(tc, mods);
1728 rc = smbldap_add(state, dn, mods);
1730 if (rc != LDAP_SUCCESS) {
1731 d_fprintf(stderr, _("Failed to add Domain Users group "
1732 "to ldap directory\n"));
1735 if (is_ipa) {
1736 if (!pdb_getgrsid(gmap, gsid)) {
1737 d_fprintf(stderr, _("Failed to read just "
1738 "created domain group.\n"));
1739 goto failed;
1740 } else {
1741 domusers_gid = gmap->gid;
1744 } else {
1745 domusers_gid = gmap->gid;
1746 d_printf(_("found!\n"));
1749 domu_done:
1751 d_printf(_("Checking for Domain Admins group.\n"));
1753 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_ADMINS);
1755 if (!pdb_getgrsid(gmap, gsid)) {
1756 LDAPMod **mods = NULL;
1757 char *dn;
1758 char *uname;
1759 char *wname;
1760 char *gidstr;
1761 char *gtype;
1762 int rc;
1764 d_printf(_("Adding the Domain Admins group.\n"));
1766 /* lets allocate a new groupid for this group */
1767 if (is_ipa) {
1768 domadmins_gid = 999;
1769 } else {
1770 if (!winbind_allocate_gid(&domadmins_gid)) {
1771 d_fprintf(stderr, _("Unable to allocate a new gid to "
1772 "create Domain Admins group!\n"));
1773 goto doma_done;
1777 uname = talloc_strdup(tc, "domadmins");
1778 wname = talloc_strdup(tc, "Domain Admins");
1779 dn = talloc_asprintf(tc, "cn=%s,%s", "domadmins",
1780 lp_ldap_group_suffix(talloc_tos()));
1781 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domadmins_gid);
1782 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
1784 if (!uname || !wname || !dn || !gidstr || !gtype) {
1785 d_fprintf(stderr, _("Out of Memory!\n"));
1786 goto failed;
1789 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
1790 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
1791 if (is_ipa) {
1792 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
1793 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
1794 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
1796 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
1797 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
1798 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1799 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
1800 sid_string_talloc(tc, &gsid));
1801 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
1803 smbldap_talloc_autofree_ldapmod(tc, mods);
1805 rc = smbldap_add(state, dn, mods);
1807 if (rc != LDAP_SUCCESS) {
1808 d_fprintf(stderr, _("Failed to add Domain Admins group "
1809 "to ldap directory\n"));
1812 if (is_ipa) {
1813 if (!pdb_getgrsid(gmap, gsid)) {
1814 d_fprintf(stderr, _("Failed to read just "
1815 "created domain group.\n"));
1816 goto failed;
1817 } else {
1818 domadmins_gid = gmap->gid;
1821 } else {
1822 domadmins_gid = gmap->gid;
1823 d_printf(_("found!\n"));
1826 doma_done:
1828 d_printf(_("Check for Administrator account.\n"));
1830 samuser = samu_new(tc);
1831 if (!samuser) {
1832 d_fprintf(stderr, _("Out of Memory!\n"));
1833 goto failed;
1836 if (!pdb_getsampwnam(samuser, "Administrator")) {
1837 LDAPMod **mods = NULL;
1838 struct dom_sid sid;
1839 char *dn;
1840 char *name;
1841 char *uidstr;
1842 char *gidstr;
1843 char *shell;
1844 char *dir;
1845 char *princ;
1846 uid_t uid;
1847 int rc;
1849 d_printf(_("Adding the Administrator user.\n"));
1851 if (domadmins_gid == -1) {
1852 d_fprintf(stderr,
1853 _("Can't create Administrator user, Domain "
1854 "Admins group not available!\n"));
1855 goto done;
1858 if (is_ipa) {
1859 uid = 999;
1860 } else {
1861 if (!winbind_allocate_uid(&uid)) {
1862 d_fprintf(stderr,
1863 _("Unable to allocate a new uid to create "
1864 "the Administrator user!\n"));
1865 goto done;
1869 name = talloc_strdup(tc, "Administrator");
1870 dn = talloc_asprintf(tc, "uid=Administrator,%s",
1871 lp_ldap_user_suffix(talloc_tos()));
1872 uidstr = talloc_asprintf(tc, "%u", (unsigned int)uid);
1873 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domadmins_gid);
1874 dir = talloc_sub_specified(tc, lp_template_homedir(),
1875 "Administrator",
1876 NULL,
1877 get_global_sam_name(),
1878 uid, domadmins_gid);
1879 shell = talloc_sub_specified(tc, lp_template_shell(),
1880 "Administrator",
1881 NULL,
1882 get_global_sam_name(),
1883 uid, domadmins_gid);
1885 if (!name || !dn || !uidstr || !gidstr || !dir || !shell) {
1886 d_fprintf(stderr, _("Out of Memory!\n"));
1887 goto failed;
1890 sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_ADMINISTRATOR);
1892 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_ACCOUNT);
1893 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT);
1894 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SAMBASAMACCOUNT);
1895 if (is_ipa) {
1896 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "person");
1897 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "organizationalperson");
1898 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetorgperson");
1899 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetuser");
1900 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbprincipalaux");
1901 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbticketpolicyaux");
1902 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sn", name);
1903 princ = talloc_asprintf(tc, "%s@%s", name, lp_realm());
1904 if (!princ) {
1905 d_fprintf(stderr, _("Out of Memory!\n"));
1906 goto failed;
1908 smbldap_set_mod(&mods, LDAP_MOD_ADD, "krbPrincipalName", princ);
1910 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", name);
1911 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", name);
1912 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", name);
1913 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uidNumber", uidstr);
1914 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1915 smbldap_set_mod(&mods, LDAP_MOD_ADD, "homeDirectory", dir);
1916 smbldap_set_mod(&mods, LDAP_MOD_ADD, "loginShell", shell);
1917 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSID",
1918 sid_string_talloc(tc, &sid));
1919 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaAcctFlags",
1920 pdb_encode_acct_ctrl(ACB_NORMAL|ACB_DISABLED,
1921 NEW_PW_FORMAT_SPACE_PADDED_LEN));
1923 smbldap_talloc_autofree_ldapmod(tc, mods);
1925 rc = smbldap_add(state, dn, mods);
1927 if (rc != LDAP_SUCCESS) {
1928 d_fprintf(stderr, _("Failed to add Administrator user "
1929 "to ldap directory\n"));
1932 if (is_ipa) {
1933 if (!pdb_getsampwnam(samuser, "Administrator")) {
1934 d_fprintf(stderr, _("Failed to read just "
1935 "created user.\n"));
1936 goto failed;
1939 } else {
1940 d_printf(_("found!\n"));
1943 d_printf(_("Checking for Guest user.\n"));
1945 samuser = samu_new(tc);
1946 if (!samuser) {
1947 d_fprintf(stderr, _("Out of Memory!\n"));
1948 goto failed;
1951 if (!pdb_getsampwnam(samuser, lp_guestaccount())) {
1952 LDAPMod **mods = NULL;
1953 struct dom_sid sid;
1954 char *dn;
1955 char *uidstr;
1956 char *gidstr;
1957 int rc;
1959 d_printf(_("Adding the Guest user.\n"));
1961 sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_GUEST);
1963 pwd = Get_Pwnam_alloc(tc, lp_guestaccount());
1965 if (!pwd) {
1966 if (domusers_gid == -1) {
1967 d_fprintf(stderr,
1968 _("Can't create Guest user, Domain "
1969 "Users group not available!\n"));
1970 goto done;
1972 if ((pwd = talloc(tc, struct passwd)) == NULL) {
1973 d_fprintf(stderr, _("talloc failed\n"));
1974 goto done;
1976 pwd->pw_name = talloc_strdup(pwd, lp_guestaccount());
1978 if (is_ipa) {
1979 pwd->pw_uid = 999;
1980 } else {
1981 if (!winbind_allocate_uid(&(pwd->pw_uid))) {
1982 d_fprintf(stderr,
1983 _("Unable to allocate a new uid to "
1984 "create the Guest user!\n"));
1985 goto done;
1988 pwd->pw_gid = domusers_gid;
1989 pwd->pw_dir = talloc_strdup(tc, "/");
1990 pwd->pw_shell = talloc_strdup(tc, "/bin/false");
1991 if (!pwd->pw_dir || !pwd->pw_shell) {
1992 d_fprintf(stderr, _("Out of Memory!\n"));
1993 goto failed;
1997 dn = talloc_asprintf(tc, "uid=%s,%s", pwd->pw_name,
1998 lp_ldap_user_suffix (talloc_tos()));
1999 uidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_uid);
2000 gidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_gid);
2001 if (!dn || !uidstr || !gidstr) {
2002 d_fprintf(stderr, _("Out of Memory!\n"));
2003 goto failed;
2006 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_ACCOUNT);
2007 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT);
2008 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SAMBASAMACCOUNT);
2009 if (is_ipa) {
2010 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "person");
2011 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "organizationalperson");
2012 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetorgperson");
2013 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetuser");
2014 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbprincipalaux");
2015 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbticketpolicyaux");
2016 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sn", pwd->pw_name);
2018 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", pwd->pw_name);
2019 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", pwd->pw_name);
2020 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", pwd->pw_name);
2021 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uidNumber", uidstr);
2022 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
2023 if ((pwd->pw_dir != NULL) && (pwd->pw_dir[0] != '\0')) {
2024 smbldap_set_mod(&mods, LDAP_MOD_ADD, "homeDirectory", pwd->pw_dir);
2026 if ((pwd->pw_shell != NULL) && (pwd->pw_shell[0] != '\0')) {
2027 smbldap_set_mod(&mods, LDAP_MOD_ADD, "loginShell", pwd->pw_shell);
2029 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSID",
2030 sid_string_talloc(tc, &sid));
2031 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaAcctFlags",
2032 pdb_encode_acct_ctrl(ACB_NORMAL|ACB_DISABLED,
2033 NEW_PW_FORMAT_SPACE_PADDED_LEN));
2035 smbldap_talloc_autofree_ldapmod(tc, mods);
2037 rc = smbldap_add(state, dn, mods);
2039 if (rc != LDAP_SUCCESS) {
2040 d_fprintf(stderr, _("Failed to add Guest user to "
2041 "ldap directory\n"));
2044 if (is_ipa) {
2045 if (!pdb_getsampwnam(samuser, lp_guestaccount())) {
2046 d_fprintf(stderr, _("Failed to read just "
2047 "created user.\n"));
2048 goto failed;
2051 } else {
2052 d_printf(_("found!\n"));
2055 d_printf(_("Checking Guest's group.\n"));
2057 pwd = Get_Pwnam_alloc(tc, lp_guestaccount());
2058 if (!pwd) {
2059 d_fprintf(stderr,
2060 _("Failed to find just created Guest account!\n"
2061 " Is nss properly configured?!\n"));
2062 goto failed;
2065 if (pwd->pw_gid == domusers_gid) {
2066 d_printf(_("found!\n"));
2067 goto done;
2070 if (!pdb_getgrgid(gmap, pwd->pw_gid)) {
2071 LDAPMod **mods = NULL;
2072 char *dn;
2073 char *uname;
2074 char *wname;
2075 char *gidstr;
2076 char *gtype;
2077 int rc;
2079 d_printf(_("Adding the Domain Guests group.\n"));
2081 uname = talloc_strdup(tc, "domguests");
2082 wname = talloc_strdup(tc, "Domain Guests");
2083 dn = talloc_asprintf(tc, "cn=%s,%s", "domguests",
2084 lp_ldap_group_suffix(talloc_tos()));
2085 gidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_gid);
2086 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
2088 if (!uname || !wname || !dn || !gidstr || !gtype) {
2089 d_fprintf(stderr, _("Out of Memory!\n"));
2090 goto failed;
2093 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_GUESTS);
2095 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
2096 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
2097 if (is_ipa) {
2098 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
2099 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
2100 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
2102 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
2103 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
2104 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
2105 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
2106 sid_string_talloc(tc, &gsid));
2107 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
2109 smbldap_talloc_autofree_ldapmod(tc, mods);
2111 rc = smbldap_add(state, dn, mods);
2113 if (rc != LDAP_SUCCESS) {
2114 d_fprintf(stderr,
2115 _("Failed to add Domain Guests group to ldap "
2116 "directory\n"));
2118 } else {
2119 d_printf(_("found!\n"));
2123 done:
2124 talloc_free(state);
2125 return 0;
2127 failed:
2128 talloc_free(state);
2129 return -1;
2132 #endif
2134 /***********************************************************
2135 migrated functionality from smbgroupedit
2136 **********************************************************/
2137 int net_sam(struct net_context *c, int argc, const char **argv)
2139 struct functable func[] = {
2141 "createbuiltingroup",
2142 net_sam_createbuiltingroup,
2143 NET_TRANSPORT_LOCAL,
2144 N_("Create a new BUILTIN group"),
2145 N_("net sam createbuiltingroup\n"
2146 " Create a new BUILTIN group")
2149 "createlocalgroup",
2150 net_sam_createlocalgroup,
2151 NET_TRANSPORT_LOCAL,
2152 N_("Create a new local group"),
2153 N_("net sam createlocalgroup\n"
2154 " Create a new local group")
2157 "createdomaingroup",
2158 net_sam_createdomaingroup,
2159 NET_TRANSPORT_LOCAL,
2160 N_("Create a new group"),
2161 N_("net sam createdomaingroup\n"
2162 " Create a new group")
2165 "deletelocalgroup",
2166 net_sam_deletelocalgroup,
2167 NET_TRANSPORT_LOCAL,
2168 N_("Delete an existing local group"),
2169 N_("net sam deletelocalgroup\n"
2170 " Delete an existing local group")
2173 "deletedomaingroup",
2174 net_sam_deletedomaingroup,
2175 NET_TRANSPORT_LOCAL,
2176 N_("Delete a domain group"),
2177 N_("net sam deletedomaingroup\n"
2178 " Delete a group")
2181 "mapunixgroup",
2182 net_sam_mapunixgroup,
2183 NET_TRANSPORT_LOCAL,
2184 N_("Map a unix group to a domain group"),
2185 N_("net sam mapunixgroup\n"
2186 " Map a unix group to a domain group")
2189 "unmapunixgroup",
2190 net_sam_unmapunixgroup,
2191 NET_TRANSPORT_LOCAL,
2192 N_("Remove a group mapping of an unix group to a "
2193 "domain group"),
2194 N_("net sam unmapunixgroup\n"
2195 " Remove a group mapping of an unix group to a "
2196 "domain group")
2199 "addmem",
2200 net_sam_addmem,
2201 NET_TRANSPORT_LOCAL,
2202 N_("Add a member to a group"),
2203 N_("net sam addmem\n"
2204 " Add a member to a group")
2207 "delmem",
2208 net_sam_delmem,
2209 NET_TRANSPORT_LOCAL,
2210 N_("Delete a member from a group"),
2211 N_("net sam delmem\n"
2212 " Delete a member from a group")
2215 "listmem",
2216 net_sam_listmem,
2217 NET_TRANSPORT_LOCAL,
2218 N_("List group members"),
2219 N_("net sam listmem\n"
2220 " List group members")
2223 "list",
2224 net_sam_list,
2225 NET_TRANSPORT_LOCAL,
2226 N_("List users, groups and local groups"),
2227 N_("net sam list\n"
2228 " List users, groups and local groups")
2231 "show",
2232 net_sam_show,
2233 NET_TRANSPORT_LOCAL,
2234 N_("Show details of a SAM entry"),
2235 N_("net sam show\n"
2236 " Show details of a SAM entry")
2239 "set",
2240 net_sam_set,
2241 NET_TRANSPORT_LOCAL,
2242 N_("Set details of a SAM account"),
2243 N_("net sam set\n"
2244 " Set details of a SAM account")
2247 "policy",
2248 net_sam_policy,
2249 NET_TRANSPORT_LOCAL,
2250 N_("Set account policies"),
2251 N_("net sam policy\n"
2252 " Set account policies")
2255 "rights",
2256 net_sam_rights,
2257 NET_TRANSPORT_LOCAL,
2258 N_("Manipulate user privileges"),
2259 N_("net sam rights\n"
2260 " Manipulate user privileges")
2262 #ifdef HAVE_LDAP
2264 "provision",
2265 net_sam_provision,
2266 NET_TRANSPORT_LOCAL,
2267 N_("Provision a clean user database"),
2268 N_("net sam privison\n"
2269 " Provision a clear user database")
2271 #endif
2272 {NULL, NULL, 0, NULL, NULL}
2275 if (getuid() != 0) {
2276 d_fprintf(stderr, _("You are not root, most things won't "
2277 "work\n"));
2280 return net_run_function(c, argc, argv, "net sam", func);