s3-smbldap: extend smbldap_init() with binddn/bindsecret arguments.
[Samba/vl.git] / source3 / utils / net_sam.c
blob7163e663f87e0294baeae53408ef38df300d7940
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_alias( 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", lp_ldap_group_suffix());
1703 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domusers_gid);
1704 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
1706 if (!uname || !wname || !dn || !gidstr || !gtype) {
1707 d_fprintf(stderr, "Out of Memory!\n");
1708 goto failed;
1711 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
1712 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
1713 if (is_ipa) {
1714 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
1715 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
1716 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
1718 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
1719 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
1720 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1721 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
1722 sid_string_talloc(tc, &gsid));
1723 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
1725 talloc_autofree_ldapmod(tc, mods);
1727 rc = smbldap_add(state, dn, mods);
1729 if (rc != LDAP_SUCCESS) {
1730 d_fprintf(stderr, _("Failed to add Domain Users group "
1731 "to ldap directory\n"));
1734 if (is_ipa) {
1735 if (!pdb_getgrsid(gmap, gsid)) {
1736 d_fprintf(stderr, _("Failed to read just "
1737 "created domain group.\n"));
1738 goto failed;
1739 } else {
1740 domusers_gid = gmap->gid;
1743 } else {
1744 domusers_gid = gmap->gid;
1745 d_printf(_("found!\n"));
1748 domu_done:
1750 d_printf(_("Checking for Domain Admins group.\n"));
1752 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_ADMINS);
1754 if (!pdb_getgrsid(gmap, gsid)) {
1755 LDAPMod **mods = NULL;
1756 char *dn;
1757 char *uname;
1758 char *wname;
1759 char *gidstr;
1760 char *gtype;
1761 int rc;
1763 d_printf(_("Adding the Domain Admins group.\n"));
1765 /* lets allocate a new groupid for this group */
1766 if (is_ipa) {
1767 domadmins_gid = 999;
1768 } else {
1769 if (!winbind_allocate_gid(&domadmins_gid)) {
1770 d_fprintf(stderr, _("Unable to allocate a new gid to "
1771 "create Domain Admins group!\n"));
1772 goto doma_done;
1776 uname = talloc_strdup(tc, "domadmins");
1777 wname = talloc_strdup(tc, "Domain Admins");
1778 dn = talloc_asprintf(tc, "cn=%s,%s", "domadmins", lp_ldap_group_suffix());
1779 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domadmins_gid);
1780 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
1782 if (!uname || !wname || !dn || !gidstr || !gtype) {
1783 d_fprintf(stderr, _("Out of Memory!\n"));
1784 goto failed;
1787 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
1788 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
1789 if (is_ipa) {
1790 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
1791 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
1792 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
1794 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
1795 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
1796 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1797 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
1798 sid_string_talloc(tc, &gsid));
1799 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
1801 talloc_autofree_ldapmod(tc, mods);
1803 rc = smbldap_add(state, dn, mods);
1805 if (rc != LDAP_SUCCESS) {
1806 d_fprintf(stderr, _("Failed to add Domain Admins group "
1807 "to ldap directory\n"));
1810 if (is_ipa) {
1811 if (!pdb_getgrsid(gmap, gsid)) {
1812 d_fprintf(stderr, _("Failed to read just "
1813 "created domain group.\n"));
1814 goto failed;
1815 } else {
1816 domadmins_gid = gmap->gid;
1819 } else {
1820 domadmins_gid = gmap->gid;
1821 d_printf(_("found!\n"));
1824 doma_done:
1826 d_printf(_("Check for Administrator account.\n"));
1828 samuser = samu_new(tc);
1829 if (!samuser) {
1830 d_fprintf(stderr, _("Out of Memory!\n"));
1831 goto failed;
1834 if (!pdb_getsampwnam(samuser, "Administrator")) {
1835 LDAPMod **mods = NULL;
1836 struct dom_sid sid;
1837 char *dn;
1838 char *name;
1839 char *uidstr;
1840 char *gidstr;
1841 char *shell;
1842 char *dir;
1843 char *princ;
1844 uid_t uid;
1845 int rc;
1847 d_printf(_("Adding the Administrator user.\n"));
1849 if (domadmins_gid == -1) {
1850 d_fprintf(stderr,
1851 _("Can't create Administrator user, Domain "
1852 "Admins group not available!\n"));
1853 goto done;
1856 if (is_ipa) {
1857 uid = 999;
1858 } else {
1859 if (!winbind_allocate_uid(&uid)) {
1860 d_fprintf(stderr,
1861 _("Unable to allocate a new uid to create "
1862 "the Administrator user!\n"));
1863 goto done;
1867 name = talloc_strdup(tc, "Administrator");
1868 dn = talloc_asprintf(tc, "uid=Administrator,%s", lp_ldap_user_suffix());
1869 uidstr = talloc_asprintf(tc, "%u", (unsigned int)uid);
1870 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domadmins_gid);
1871 dir = talloc_sub_specified(tc, lp_template_homedir(),
1872 "Administrator",
1873 get_global_sam_name(),
1874 uid, domadmins_gid);
1875 shell = talloc_sub_specified(tc, lp_template_shell(),
1876 "Administrator",
1877 get_global_sam_name(),
1878 uid, domadmins_gid);
1880 if (!name || !dn || !uidstr || !gidstr || !dir || !shell) {
1881 d_fprintf(stderr, _("Out of Memory!\n"));
1882 goto failed;
1885 sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_ADMINISTRATOR);
1887 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_ACCOUNT);
1888 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT);
1889 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SAMBASAMACCOUNT);
1890 if (is_ipa) {
1891 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "person");
1892 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "organizationalperson");
1893 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetorgperson");
1894 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetuser");
1895 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbprincipalaux");
1896 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbticketpolicyaux");
1897 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sn", name);
1898 princ = talloc_asprintf(tc, "%s@%s", name, lp_realm());
1899 if (!princ) {
1900 d_fprintf(stderr, _("Out of Memory!\n"));
1901 goto failed;
1903 smbldap_set_mod(&mods, LDAP_MOD_ADD, "krbPrincipalName", princ);
1905 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", name);
1906 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", name);
1907 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", name);
1908 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uidNumber", uidstr);
1909 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1910 smbldap_set_mod(&mods, LDAP_MOD_ADD, "homeDirectory", dir);
1911 smbldap_set_mod(&mods, LDAP_MOD_ADD, "loginShell", shell);
1912 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSID",
1913 sid_string_talloc(tc, &sid));
1914 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaAcctFlags",
1915 pdb_encode_acct_ctrl(ACB_NORMAL|ACB_DISABLED,
1916 NEW_PW_FORMAT_SPACE_PADDED_LEN));
1918 talloc_autofree_ldapmod(tc, mods);
1920 rc = smbldap_add(state, dn, mods);
1922 if (rc != LDAP_SUCCESS) {
1923 d_fprintf(stderr, _("Failed to add Administrator user "
1924 "to ldap directory\n"));
1927 if (is_ipa) {
1928 if (!pdb_getsampwnam(samuser, "Administrator")) {
1929 d_fprintf(stderr, _("Failed to read just "
1930 "created user.\n"));
1931 goto failed;
1934 } else {
1935 d_printf(_("found!\n"));
1938 d_printf(_("Checking for Guest user.\n"));
1940 samuser = samu_new(tc);
1941 if (!samuser) {
1942 d_fprintf(stderr, _("Out of Memory!\n"));
1943 goto failed;
1946 if (!pdb_getsampwnam(samuser, lp_guestaccount())) {
1947 LDAPMod **mods = NULL;
1948 struct dom_sid sid;
1949 char *dn;
1950 char *uidstr;
1951 char *gidstr;
1952 int rc;
1954 d_printf(_("Adding the Guest user.\n"));
1956 sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_GUEST);
1958 pwd = Get_Pwnam_alloc(tc, lp_guestaccount());
1960 if (!pwd) {
1961 if (domusers_gid == -1) {
1962 d_fprintf(stderr,
1963 _("Can't create Guest user, Domain "
1964 "Users group not available!\n"));
1965 goto done;
1967 if ((pwd = talloc(tc, struct passwd)) == NULL) {
1968 d_fprintf(stderr, _("talloc failed\n"));
1969 goto done;
1971 pwd->pw_name = talloc_strdup(pwd, lp_guestaccount());
1973 if (is_ipa) {
1974 pwd->pw_uid = 999;
1975 } else {
1976 if (!winbind_allocate_uid(&(pwd->pw_uid))) {
1977 d_fprintf(stderr,
1978 _("Unable to allocate a new uid to "
1979 "create the Guest user!\n"));
1980 goto done;
1983 pwd->pw_gid = domusers_gid;
1984 pwd->pw_dir = talloc_strdup(tc, "/");
1985 pwd->pw_shell = talloc_strdup(tc, "/bin/false");
1986 if (!pwd->pw_dir || !pwd->pw_shell) {
1987 d_fprintf(stderr, _("Out of Memory!\n"));
1988 goto failed;
1992 dn = talloc_asprintf(tc, "uid=%s,%s", pwd->pw_name, lp_ldap_user_suffix ());
1993 uidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_uid);
1994 gidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_gid);
1995 if (!dn || !uidstr || !gidstr) {
1996 d_fprintf(stderr, _("Out of Memory!\n"));
1997 goto failed;
2000 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_ACCOUNT);
2001 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT);
2002 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SAMBASAMACCOUNT);
2003 if (is_ipa) {
2004 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "person");
2005 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "organizationalperson");
2006 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetorgperson");
2007 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetuser");
2008 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbprincipalaux");
2009 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbticketpolicyaux");
2010 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sn", pwd->pw_name);
2012 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", pwd->pw_name);
2013 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", pwd->pw_name);
2014 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", pwd->pw_name);
2015 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uidNumber", uidstr);
2016 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
2017 if ((pwd->pw_dir != NULL) && (pwd->pw_dir[0] != '\0')) {
2018 smbldap_set_mod(&mods, LDAP_MOD_ADD, "homeDirectory", pwd->pw_dir);
2020 if ((pwd->pw_shell != NULL) && (pwd->pw_shell[0] != '\0')) {
2021 smbldap_set_mod(&mods, LDAP_MOD_ADD, "loginShell", pwd->pw_shell);
2023 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSID",
2024 sid_string_talloc(tc, &sid));
2025 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaAcctFlags",
2026 pdb_encode_acct_ctrl(ACB_NORMAL|ACB_DISABLED,
2027 NEW_PW_FORMAT_SPACE_PADDED_LEN));
2029 talloc_autofree_ldapmod(tc, mods);
2031 rc = smbldap_add(state, dn, mods);
2033 if (rc != LDAP_SUCCESS) {
2034 d_fprintf(stderr, _("Failed to add Guest user to "
2035 "ldap directory\n"));
2038 if (is_ipa) {
2039 if (!pdb_getsampwnam(samuser, lp_guestaccount())) {
2040 d_fprintf(stderr, _("Failed to read just "
2041 "created user.\n"));
2042 goto failed;
2045 } else {
2046 d_printf(_("found!\n"));
2049 d_printf(_("Checking Guest's group.\n"));
2051 pwd = Get_Pwnam_alloc(tc, lp_guestaccount());
2052 if (!pwd) {
2053 d_fprintf(stderr,
2054 _("Failed to find just created Guest account!\n"
2055 " Is nss properly configured?!\n"));
2056 goto failed;
2059 if (pwd->pw_gid == domusers_gid) {
2060 d_printf(_("found!\n"));
2061 goto done;
2064 if (!pdb_getgrgid(gmap, pwd->pw_gid)) {
2065 LDAPMod **mods = NULL;
2066 char *dn;
2067 char *uname;
2068 char *wname;
2069 char *gidstr;
2070 char *gtype;
2071 int rc;
2073 d_printf(_("Adding the Domain Guests group.\n"));
2075 uname = talloc_strdup(tc, "domguests");
2076 wname = talloc_strdup(tc, "Domain Guests");
2077 dn = talloc_asprintf(tc, "cn=%s,%s", "domguests", lp_ldap_group_suffix());
2078 gidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_gid);
2079 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
2081 if (!uname || !wname || !dn || !gidstr || !gtype) {
2082 d_fprintf(stderr, _("Out of Memory!\n"));
2083 goto failed;
2086 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_GUESTS);
2088 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
2089 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
2090 if (is_ipa) {
2091 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
2092 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
2093 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
2095 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
2096 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
2097 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
2098 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
2099 sid_string_talloc(tc, &gsid));
2100 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
2102 talloc_autofree_ldapmod(tc, mods);
2104 rc = smbldap_add(state, dn, mods);
2106 if (rc != LDAP_SUCCESS) {
2107 d_fprintf(stderr,
2108 _("Failed to add Domain Guests group to ldap "
2109 "directory\n"));
2111 } else {
2112 d_printf(_("found!\n"));
2116 done:
2117 talloc_free(state);
2118 return 0;
2120 failed:
2121 talloc_free(state);
2122 return -1;
2125 #endif
2127 /***********************************************************
2128 migrated functionality from smbgroupedit
2129 **********************************************************/
2130 int net_sam(struct net_context *c, int argc, const char **argv)
2132 struct functable func[] = {
2134 "createbuiltingroup",
2135 net_sam_createbuiltingroup,
2136 NET_TRANSPORT_LOCAL,
2137 N_("Create a new BUILTIN group"),
2138 N_("net sam createbuiltingroup\n"
2139 " Create a new BUILTIN group")
2142 "createlocalgroup",
2143 net_sam_createlocalgroup,
2144 NET_TRANSPORT_LOCAL,
2145 N_("Create a new local group"),
2146 N_("net sam createlocalgroup\n"
2147 " Create a new local group")
2150 "createdomaingroup",
2151 net_sam_createdomaingroup,
2152 NET_TRANSPORT_LOCAL,
2153 N_("Create a new group"),
2154 N_("net sam createdomaingroup\n"
2155 " Create a new group")
2158 "deletelocalgroup",
2159 net_sam_deletelocalgroup,
2160 NET_TRANSPORT_LOCAL,
2161 N_("Delete an existing local group"),
2162 N_("net sam deletelocalgroup\n"
2163 " Delete an existing local group")
2166 "deletedomaingroup",
2167 net_sam_deletedomaingroup,
2168 NET_TRANSPORT_LOCAL,
2169 N_("Delete a domain group"),
2170 N_("net sam deletedomaingroup\n"
2171 " Delete a group")
2174 "mapunixgroup",
2175 net_sam_mapunixgroup,
2176 NET_TRANSPORT_LOCAL,
2177 N_("Map a unix group to a domain group"),
2178 N_("net sam mapunixgroup\n"
2179 " Map a unix group to a domain group")
2182 "unmapunixgroup",
2183 net_sam_unmapunixgroup,
2184 NET_TRANSPORT_LOCAL,
2185 N_("Remove a group mapping of an unix group to a "
2186 "domain group"),
2187 N_("net sam unmapunixgroup\n"
2188 " Remove a group mapping of an unix group to a "
2189 "domain group")
2192 "addmem",
2193 net_sam_addmem,
2194 NET_TRANSPORT_LOCAL,
2195 N_("Add a member to a group"),
2196 N_("net sam addmem\n"
2197 " Add a member to a group")
2200 "delmem",
2201 net_sam_delmem,
2202 NET_TRANSPORT_LOCAL,
2203 N_("Delete a member from a group"),
2204 N_("net sam delmem\n"
2205 " Delete a member from a group")
2208 "listmem",
2209 net_sam_listmem,
2210 NET_TRANSPORT_LOCAL,
2211 N_("List group members"),
2212 N_("net sam listmem\n"
2213 " List group members")
2216 "list",
2217 net_sam_list,
2218 NET_TRANSPORT_LOCAL,
2219 N_("List users, groups and local groups"),
2220 N_("net sam list\n"
2221 " List users, groups and local groups")
2224 "show",
2225 net_sam_show,
2226 NET_TRANSPORT_LOCAL,
2227 N_("Show details of a SAM entry"),
2228 N_("net sam show\n"
2229 " Show details of a SAM entry")
2232 "set",
2233 net_sam_set,
2234 NET_TRANSPORT_LOCAL,
2235 N_("Set details of a SAM account"),
2236 N_("net sam set\n"
2237 " Set details of a SAM account")
2240 "policy",
2241 net_sam_policy,
2242 NET_TRANSPORT_LOCAL,
2243 N_("Set account policies"),
2244 N_("net sam policy\n"
2245 " Set account policies")
2248 "rights",
2249 net_sam_rights,
2250 NET_TRANSPORT_LOCAL,
2251 N_("Manipulate user privileges"),
2252 N_("net sam rights\n"
2253 " Manipulate user privileges")
2255 #ifdef HAVE_LDAP
2257 "provision",
2258 net_sam_provision,
2259 NET_TRANSPORT_LOCAL,
2260 N_("Provision a clean user database"),
2261 N_("net sam privison\n"
2262 " Provision a clear user database")
2264 #endif
2265 {NULL, NULL, 0, NULL, NULL}
2268 if (getuid() != 0) {
2269 d_fprintf(stderr, _("You are not root, most things won't "
2270 "work\n"));
2273 return net_run_function(c, argc, argv, "net sam", func);