|
Packit Service |
6d40f9 |
/*
|
|
Packit Service |
6d40f9 |
* adcli
|
|
Packit Service |
6d40f9 |
*
|
|
Packit Service |
6d40f9 |
* Copyright (C) 2013 Red Hat Inc.
|
|
Packit Service |
6d40f9 |
*
|
|
Packit Service |
6d40f9 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
6d40f9 |
* it under the terms of the GNU Lesser General Public License as
|
|
Packit Service |
6d40f9 |
* published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
6d40f9 |
* the License, or (at your option) any later version.
|
|
Packit Service |
6d40f9 |
*
|
|
Packit Service |
6d40f9 |
* This program is distributed in the hope that it will be useful, but
|
|
Packit Service |
6d40f9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
6d40f9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
6d40f9 |
* Lesser General Public License for more details.
|
|
Packit Service |
6d40f9 |
*
|
|
Packit Service |
6d40f9 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
6d40f9 |
* License along with this program; if not, write to the Free Software
|
|
Packit Service |
6d40f9 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
Packit Service |
6d40f9 |
* MA 02110-1301 USA
|
|
Packit Service |
6d40f9 |
*
|
|
Packit Service |
6d40f9 |
* Author: Stef Walter <stefw@redhat.com>
|
|
Packit Service |
6d40f9 |
*/
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
#include "config.h"
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
#include "adcli.h"
|
|
Packit Service |
6d40f9 |
#include "adattrs.h"
|
|
Packit Service |
6d40f9 |
#include "tools.h"
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
#include <assert.h>
|
|
Packit Service |
6d40f9 |
#include <err.h>
|
|
Packit Service |
6d40f9 |
#include <stdio.h>
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
typedef enum {
|
|
Packit Service |
6d40f9 |
/* Have short equivalents */
|
|
Packit Service |
6d40f9 |
opt_domain = 'D',
|
|
Packit Service |
6d40f9 |
opt_domain_realm = 'R',
|
|
Packit Service |
6d40f9 |
opt_domain_controller = 'S',
|
|
Packit Service |
6d40f9 |
opt_login_user = 'U',
|
|
Packit Service |
6d40f9 |
opt_login_ccache = 'C',
|
|
Packit Service |
6d40f9 |
opt_domain_ou = 'O',
|
|
Packit Service |
6d40f9 |
opt_prompt_password = 'W',
|
|
Packit Service |
6d40f9 |
opt_verbose = 'v',
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
/* Don't have short equivalents */
|
|
Packit Service |
6d40f9 |
opt_no_password,
|
|
Packit Service |
6d40f9 |
opt_stdin_password,
|
|
Packit Service |
6d40f9 |
opt_display_name,
|
|
Packit Service |
6d40f9 |
opt_description,
|
|
Packit Service |
6d40f9 |
opt_mail,
|
|
Packit Service |
6d40f9 |
opt_unix_home,
|
|
Packit Service |
6d40f9 |
opt_unix_uid,
|
|
Packit Service |
6d40f9 |
opt_unix_gid,
|
|
Packit Service |
6d40f9 |
opt_unix_shell,
|
|
Packit Service |
371c62 |
opt_nis_domain,
|
|
Packit Service |
6d40f9 |
} Option;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
static adcli_tool_desc common_usages[] = {
|
|
Packit Service |
6d40f9 |
{ opt_display_name, "display name" },
|
|
Packit Service |
6d40f9 |
{ opt_description, "group description" },
|
|
Packit Service |
6d40f9 |
{ opt_mail, "email address" },
|
|
Packit Service |
6d40f9 |
{ opt_unix_home, "unix home directory" },
|
|
Packit Service |
6d40f9 |
{ opt_unix_uid, "unix uid number" },
|
|
Packit Service |
6d40f9 |
{ opt_unix_gid, "unix gid number" },
|
|
Packit Service |
6d40f9 |
{ opt_unix_shell, "unix shell" },
|
|
Packit Service |
371c62 |
{ opt_nis_domain, "NIS domain" },
|
|
Packit Service |
6d40f9 |
{ opt_domain, "active directory domain name" },
|
|
Packit Service |
6d40f9 |
{ opt_domain_realm, "kerberos realm for the domain" },
|
|
Packit Service |
6d40f9 |
{ opt_domain_controller, "domain directory server to connect to" },
|
|
Packit Service |
6d40f9 |
{ opt_login_ccache, "kerberos credential cache file which contains\n"
|
|
Packit Service |
6d40f9 |
"ticket to used to connect to the domain" },
|
|
Packit Service |
6d40f9 |
{ opt_login_user, "user (usually administrative) login name of\n"
|
|
Packit Service |
6d40f9 |
"the account to log into the domain as" },
|
|
Packit Service |
6d40f9 |
{ opt_domain_ou, "a LDAP DN representing an organizational unit in\n"
|
|
Packit Service |
6d40f9 |
"which the user account should be placed." },
|
|
Packit Service |
6d40f9 |
{ opt_no_password, "don't prompt for or read a password" },
|
|
Packit Service |
6d40f9 |
{ opt_prompt_password, "prompt for a login password if necessary" },
|
|
Packit Service |
6d40f9 |
{ opt_stdin_password, "read a login password from stdin (until EOF) if\n"
|
|
Packit Service |
6d40f9 |
"necessary" },
|
|
Packit Service |
6d40f9 |
{ opt_verbose, "show verbose progress and failure messages", },
|
|
Packit Service |
6d40f9 |
{ 0 },
|
|
Packit Service |
6d40f9 |
};
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
bc2650 |
static void
|
|
Packit Service |
6d40f9 |
parse_option (Option opt,
|
|
Packit Service |
6d40f9 |
const char *optarg,
|
|
Packit Service |
6d40f9 |
adcli_conn *conn)
|
|
Packit Service |
6d40f9 |
{
|
|
Packit Service |
6d40f9 |
static int no_password = 0;
|
|
Packit Service |
6d40f9 |
static int prompt_password = 0;
|
|
Packit Service |
6d40f9 |
static int stdin_password = 0;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
switch (opt) {
|
|
Packit Service |
6d40f9 |
case opt_login_ccache:
|
|
Packit Service |
6d40f9 |
adcli_conn_set_login_ccache_name (conn, optarg);
|
|
Packit Service |
bc2650 |
return;
|
|
Packit Service |
6d40f9 |
case opt_login_user:
|
|
Packit Service |
6d40f9 |
adcli_conn_set_login_user (conn, optarg);
|
|
Packit Service |
bc2650 |
return;
|
|
Packit Service |
6d40f9 |
case opt_domain:
|
|
Packit Service |
6d40f9 |
adcli_conn_set_domain_name (conn, optarg);
|
|
Packit Service |
bc2650 |
return;
|
|
Packit Service |
6d40f9 |
case opt_domain_realm:
|
|
Packit Service |
6d40f9 |
adcli_conn_set_domain_realm (conn, optarg);
|
|
Packit Service |
bc2650 |
return;
|
|
Packit Service |
6d40f9 |
case opt_domain_controller:
|
|
Packit Service |
6d40f9 |
adcli_conn_set_domain_controller (conn, optarg);
|
|
Packit Service |
bc2650 |
return;
|
|
Packit Service |
6d40f9 |
case opt_no_password:
|
|
Packit Service |
6d40f9 |
if (stdin_password || prompt_password) {
|
|
Packit Service |
bc2650 |
errx (EUSAGE, "cannot use --no-password argument with %s",
|
|
Packit Service |
bc2650 |
stdin_password ? "--stdin-password" : "--prompt-password");
|
|
Packit Service |
6d40f9 |
} else {
|
|
Packit Service |
6d40f9 |
adcli_conn_set_password_func (conn, NULL, NULL, NULL);
|
|
Packit Service |
6d40f9 |
no_password = 1;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
bc2650 |
return;
|
|
Packit Service |
6d40f9 |
case opt_prompt_password:
|
|
Packit Service |
6d40f9 |
if (stdin_password || no_password) {
|
|
Packit Service |
bc2650 |
errx (EUSAGE, "cannot use --prompt-password argument with %s",
|
|
Packit Service |
bc2650 |
stdin_password ? "--stdin-password" : "--no-password");
|
|
Packit Service |
6d40f9 |
} else {
|
|
Packit Service |
6d40f9 |
adcli_conn_set_password_func (conn, adcli_prompt_password_func, NULL, NULL);
|
|
Packit Service |
6d40f9 |
prompt_password = 1;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
bc2650 |
return;
|
|
Packit Service |
6d40f9 |
case opt_stdin_password:
|
|
Packit Service |
6d40f9 |
if (prompt_password || no_password) {
|
|
Packit Service |
bc2650 |
errx (EUSAGE, "cannot use --stdin-password argument with %s",
|
|
Packit Service |
bc2650 |
prompt_password ? "--prompt-password" : "--no-password");
|
|
Packit Service |
6d40f9 |
} else {
|
|
Packit Service |
6d40f9 |
adcli_conn_set_password_func (conn, adcli_read_password_func, NULL, NULL);
|
|
Packit Service |
6d40f9 |
stdin_password = 1;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
bc2650 |
return;
|
|
Packit Service |
6d40f9 |
case opt_verbose:
|
|
Packit Service |
bc2650 |
return;
|
|
Packit Service |
6d40f9 |
default:
|
|
Packit Service |
6d40f9 |
assert (0 && "not reached");
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
bc2650 |
errx (EUSAGE, "failure to parse option '%c'", opt);
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
int
|
|
Packit Service |
6d40f9 |
adcli_tool_user_create (adcli_conn *conn,
|
|
Packit Service |
6d40f9 |
int argc,
|
|
Packit Service |
6d40f9 |
char *argv[])
|
|
Packit Service |
6d40f9 |
{
|
|
Packit Service |
6d40f9 |
adcli_entry *entry;
|
|
Packit Service |
6d40f9 |
adcli_result res;
|
|
Packit Service |
6d40f9 |
adcli_attrs *attrs;
|
|
Packit Service |
6d40f9 |
const char *ou = NULL;
|
|
Packit Service |
6d40f9 |
int opt;
|
|
Packit Service |
78c748 |
bool has_unix_attr = false;
|
|
Packit Service |
78c748 |
bool has_nis_domain = false;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
struct option options[] = {
|
|
Packit Service |
6d40f9 |
{ "display-name", required_argument, NULL, opt_display_name },
|
|
Packit Service |
6d40f9 |
{ "mail", required_argument, NULL, opt_mail },
|
|
Packit Service |
6d40f9 |
{ "unix-home", required_argument, NULL, opt_unix_home },
|
|
Packit Service |
6d40f9 |
{ "unix-uid", required_argument, NULL, opt_unix_uid },
|
|
Packit Service |
6d40f9 |
{ "unix-gid", required_argument, NULL, opt_unix_gid },
|
|
Packit Service |
6d40f9 |
{ "unix-shell", required_argument, NULL, opt_unix_shell },
|
|
Packit Service |
371c62 |
{ "nis-domain", required_argument, NULL, opt_nis_domain },
|
|
Packit Service |
6d40f9 |
{ "domain-ou", required_argument, NULL, opt_domain_ou },
|
|
Packit Service |
6d40f9 |
{ "domain", required_argument, NULL, opt_domain },
|
|
Packit Service |
6d40f9 |
{ "domain-realm", required_argument, NULL, opt_domain_realm },
|
|
Packit Service |
6d40f9 |
{ "domain-controller", required_argument, NULL, opt_domain_controller },
|
|
Packit Service |
6d40f9 |
{ "login-user", required_argument, NULL, opt_login_user },
|
|
Packit Service |
6d40f9 |
{ "login-ccache", optional_argument, NULL, opt_login_ccache },
|
|
Packit Service |
6d40f9 |
{ "no-password", no_argument, 0, opt_no_password },
|
|
Packit Service |
6d40f9 |
{ "stdin-password", no_argument, 0, opt_stdin_password },
|
|
Packit Service |
6d40f9 |
{ "prompt-password", no_argument, 0, opt_prompt_password },
|
|
Packit Service |
6d40f9 |
{ "verbose", no_argument, NULL, opt_verbose },
|
|
Packit Service |
6d40f9 |
{ "help", no_argument, NULL, 'h' },
|
|
Packit Service |
6d40f9 |
{ 0 },
|
|
Packit Service |
6d40f9 |
};
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
static adcli_tool_desc usages[] = {
|
|
Packit Service |
6d40f9 |
{ 0, "usage: adcli create-user --domain=xxxx user" },
|
|
Packit Service |
6d40f9 |
{ 0 },
|
|
Packit Service |
6d40f9 |
};
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
attrs = adcli_attrs_new ();
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
|
|
Packit Service |
6d40f9 |
switch (opt) {
|
|
Packit Service |
6d40f9 |
case opt_display_name:
|
|
Packit Service |
6d40f9 |
adcli_attrs_add (attrs, "displayName", optarg, NULL);
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
case opt_mail:
|
|
Packit Service |
6d40f9 |
adcli_attrs_add1 (attrs, "mail", optarg);
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
case opt_unix_home:
|
|
Packit Service |
6d40f9 |
adcli_attrs_add (attrs, "unixHomeDirectory", optarg, NULL);
|
|
Packit Service |
78c748 |
has_unix_attr = true;
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
case opt_unix_uid:
|
|
Packit Service |
6d40f9 |
adcli_attrs_add (attrs, "uidNumber", optarg, NULL);
|
|
Packit Service |
78c748 |
has_unix_attr = true;
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
case opt_unix_gid:
|
|
Packit Service |
6d40f9 |
adcli_attrs_add (attrs, "gidNumber", optarg, NULL);
|
|
Packit Service |
78c748 |
has_unix_attr = true;
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
case opt_unix_shell:
|
|
Packit Service |
6d40f9 |
adcli_attrs_add (attrs, "loginShell", optarg, NULL);
|
|
Packit Service |
78c748 |
has_unix_attr = true;
|
|
Packit Service |
70988c |
break;
|
|
Packit Service |
371c62 |
case opt_nis_domain:
|
|
Packit Service |
371c62 |
adcli_attrs_add (attrs, "msSFU30NisDomain", optarg, NULL);
|
|
Packit Service |
78c748 |
has_nis_domain = true;
|
|
Packit Service |
371c62 |
break;
|
|
Packit Service |
6d40f9 |
case opt_domain_ou:
|
|
Packit Service |
6d40f9 |
ou = optarg;
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
case 'h':
|
|
Packit Service |
6d40f9 |
case '?':
|
|
Packit Service |
6d40f9 |
case ':':
|
|
Packit Service |
6d40f9 |
adcli_tool_usage (options, usages);
|
|
Packit Service |
6d40f9 |
adcli_tool_usage (options, common_usages);
|
|
Packit Service |
6d40f9 |
adcli_attrs_free (attrs);
|
|
Packit Service |
6d40f9 |
return opt == 'h' ? 0 : 2;
|
|
Packit Service |
6d40f9 |
default:
|
|
Packit Service |
bc2650 |
parse_option ((Option)opt, optarg, conn);
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
argc -= optind;
|
|
Packit Service |
6d40f9 |
argv += optind;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
bc2650 |
if (argc != 1)
|
|
Packit Service |
bc2650 |
errx (2, "specify one user name to create");
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
entry = adcli_entry_new_user (conn, argv[0]);
|
|
Packit Service |
bc2650 |
if (entry == NULL)
|
|
Packit Service |
bc2650 |
errx (-1, "unexpected memory problems");
|
|
Packit Service |
6d40f9 |
adcli_entry_set_domain_ou (entry, ou);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
res = adcli_conn_connect (conn);
|
|
Packit Service |
6d40f9 |
if (res != ADCLI_SUCCESS) {
|
|
Packit Service |
bc2650 |
errx (-res, "couldn't connect to %s domain: %s",
|
|
Packit Service |
bc2650 |
adcli_conn_get_domain_name (conn),
|
|
Packit Service |
bc2650 |
adcli_get_last_error ());
|
|
Packit Service |
e2b2f2 |
}
|
|
Packit Service |
e2b2f2 |
|
|
Packit Service |
78c748 |
if (has_unix_attr && !has_nis_domain) {
|
|
Packit Service |
78c748 |
res = adcli_get_nis_domain (entry, attrs);
|
|
Packit Service |
78c748 |
if (res != ADCLI_SUCCESS) {
|
|
Packit Service |
78c748 |
adcli_entry_unref (entry);
|
|
Packit Service |
78c748 |
adcli_attrs_free (attrs);
|
|
Packit Service |
78c748 |
errx (-res, "couldn't get NIS domain");
|
|
Packit Service |
78c748 |
}
|
|
Packit Service |
78c748 |
}
|
|
Packit Service |
78c748 |
|
|
Packit Service |
6d40f9 |
res = adcli_entry_create (entry, attrs);
|
|
Packit Service |
6d40f9 |
if (res != ADCLI_SUCCESS) {
|
|
Packit Service |
bc2650 |
errx (-res, "creating user %s in domain %s failed: %s",
|
|
Packit Service |
bc2650 |
adcli_entry_get_sam_name (entry),
|
|
Packit Service |
bc2650 |
adcli_conn_get_domain_name (conn),
|
|
Packit Service |
bc2650 |
adcli_get_last_error ());
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
adcli_entry_unref (entry);
|
|
Packit Service |
6d40f9 |
adcli_attrs_free (attrs);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
return 0;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
int
|
|
Packit Service |
6d40f9 |
adcli_tool_user_delete (adcli_conn *conn,
|
|
Packit Service |
6d40f9 |
int argc,
|
|
Packit Service |
6d40f9 |
char *argv[])
|
|
Packit Service |
6d40f9 |
{
|
|
Packit Service |
6d40f9 |
adcli_result res;
|
|
Packit Service |
6d40f9 |
adcli_entry *entry;
|
|
Packit Service |
6d40f9 |
int opt;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
struct option options[] = {
|
|
Packit Service |
6d40f9 |
{ "domain", required_argument, NULL, opt_domain },
|
|
Packit Service |
6d40f9 |
{ "domain-realm", required_argument, NULL, opt_domain_realm },
|
|
Packit Service |
6d40f9 |
{ "domain-controller", required_argument, NULL, opt_domain_controller },
|
|
Packit Service |
6d40f9 |
{ "login-user", required_argument, NULL, opt_login_user },
|
|
Packit Service |
6d40f9 |
{ "login-ccache", optional_argument, NULL, opt_login_ccache },
|
|
Packit Service |
6d40f9 |
{ "no-password", no_argument, 0, opt_no_password },
|
|
Packit Service |
6d40f9 |
{ "stdin-password", no_argument, 0, opt_stdin_password },
|
|
Packit Service |
6d40f9 |
{ "prompt-password", no_argument, 0, opt_prompt_password },
|
|
Packit Service |
6d40f9 |
{ "verbose", no_argument, NULL, opt_verbose },
|
|
Packit Service |
6d40f9 |
{ "help", no_argument, NULL, 'h' },
|
|
Packit Service |
6d40f9 |
{ 0 },
|
|
Packit Service |
6d40f9 |
};
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
static adcli_tool_desc usages[] = {
|
|
Packit Service |
6d40f9 |
{ 0, "usage: adcli delete-user --domain=xxxx user" },
|
|
Packit Service |
6d40f9 |
{ 0 },
|
|
Packit Service |
6d40f9 |
};
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
|
|
Packit Service |
6d40f9 |
switch (opt) {
|
|
Packit Service |
6d40f9 |
case 'h':
|
|
Packit Service |
6d40f9 |
case '?':
|
|
Packit Service |
6d40f9 |
case ':':
|
|
Packit Service |
6d40f9 |
adcli_tool_usage (options, usages);
|
|
Packit Service |
6d40f9 |
adcli_tool_usage (options, common_usages);
|
|
Packit Service |
6d40f9 |
return opt == 'h' ? 0 : 2;
|
|
Packit Service |
6d40f9 |
default:
|
|
Packit Service |
bc2650 |
parse_option ((Option)opt, optarg, conn);
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
argc -= optind;
|
|
Packit Service |
6d40f9 |
argv += optind;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
bc2650 |
if (argc != 1)
|
|
Packit Service |
bc2650 |
errx (2, "specify one user name to delete");
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
entry = adcli_entry_new_user (conn, argv[0]);
|
|
Packit Service |
bc2650 |
if (entry == NULL)
|
|
Packit Service |
bc2650 |
errx (-1, "unexpected memory problems");
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
res = adcli_conn_connect (conn);
|
|
Packit Service |
6d40f9 |
if (res != ADCLI_SUCCESS) {
|
|
Packit Service |
bc2650 |
errx (-res, "couldn't connect to %s domain: %s",
|
|
Packit Service |
bc2650 |
adcli_conn_get_domain_name (conn),
|
|
Packit Service |
bc2650 |
adcli_get_last_error ());
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
res = adcli_entry_delete (entry);
|
|
Packit Service |
6d40f9 |
if (res != ADCLI_SUCCESS) {
|
|
Packit Service |
bc2650 |
errx (-res, "deleting user %s in domain %s failed: %s",
|
|
Packit Service |
bc2650 |
adcli_entry_get_sam_name (entry),
|
|
Packit Service |
bc2650 |
adcli_conn_get_domain_name (conn),
|
|
Packit Service |
bc2650 |
adcli_get_last_error ());
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
adcli_entry_unref (entry);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
return 0;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
int
|
|
Packit Service |
6d40f9 |
adcli_tool_group_create (adcli_conn *conn,
|
|
Packit Service |
6d40f9 |
int argc,
|
|
Packit Service |
6d40f9 |
char *argv[])
|
|
Packit Service |
6d40f9 |
{
|
|
Packit Service |
6d40f9 |
adcli_entry *entry;
|
|
Packit Service |
6d40f9 |
adcli_result res;
|
|
Packit Service |
6d40f9 |
adcli_attrs *attrs;
|
|
Packit Service |
6d40f9 |
const char *ou = NULL;
|
|
Packit Service |
6d40f9 |
int opt;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
struct option options[] = {
|
|
Packit Service |
6d40f9 |
{ "description", required_argument, NULL, opt_description },
|
|
Packit Service |
6d40f9 |
{ "domain", required_argument, NULL, opt_domain },
|
|
Packit Service |
6d40f9 |
{ "domain-realm", required_argument, NULL, opt_domain_realm },
|
|
Packit Service |
6d40f9 |
{ "domain-controller", required_argument, NULL, opt_domain_controller },
|
|
Packit Service |
6d40f9 |
{ "domain-ou", required_argument, NULL, opt_domain_ou },
|
|
Packit Service |
6d40f9 |
{ "login-user", required_argument, NULL, opt_login_user },
|
|
Packit Service |
6d40f9 |
{ "login-ccache", optional_argument, NULL, opt_login_ccache },
|
|
Packit Service |
6d40f9 |
{ "no-password", no_argument, 0, opt_no_password },
|
|
Packit Service |
6d40f9 |
{ "stdin-password", no_argument, 0, opt_stdin_password },
|
|
Packit Service |
6d40f9 |
{ "prompt-password", no_argument, 0, opt_prompt_password },
|
|
Packit Service |
6d40f9 |
{ "verbose", no_argument, NULL, opt_verbose },
|
|
Packit Service |
6d40f9 |
{ "help", no_argument, NULL, 'h' },
|
|
Packit Service |
6d40f9 |
{ 0 },
|
|
Packit Service |
6d40f9 |
};
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
static adcli_tool_desc usages[] = {
|
|
Packit Service |
6d40f9 |
{ 0, "usage: adcli create-group --domain=xxxx group" },
|
|
Packit Service |
6d40f9 |
{ 0 },
|
|
Packit Service |
6d40f9 |
};
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
attrs = adcli_attrs_new ();
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
|
|
Packit Service |
6d40f9 |
switch (opt) {
|
|
Packit Service |
6d40f9 |
case opt_description:
|
|
Packit Service |
6d40f9 |
adcli_attrs_add (attrs, "description", optarg, NULL);
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
case opt_domain_ou:
|
|
Packit Service |
6d40f9 |
ou = optarg;
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
case 'h':
|
|
Packit Service |
6d40f9 |
case '?':
|
|
Packit Service |
6d40f9 |
case ':':
|
|
Packit Service |
6d40f9 |
adcli_tool_usage (options, usages);
|
|
Packit Service |
6d40f9 |
adcli_tool_usage (options, common_usages);
|
|
Packit Service |
6d40f9 |
adcli_attrs_free (attrs);
|
|
Packit Service |
6d40f9 |
return opt == 'h' ? 0 : 2;
|
|
Packit Service |
6d40f9 |
default:
|
|
Packit Service |
bc2650 |
parse_option ((Option)opt, optarg, conn);
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
argc -= optind;
|
|
Packit Service |
6d40f9 |
argv += optind;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
bc2650 |
if (argc != 1)
|
|
Packit Service |
bc2650 |
errx (2, "specify one group to create");
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
entry = adcli_entry_new_group (conn, argv[0]);
|
|
Packit Service |
bc2650 |
if (entry == NULL)
|
|
Packit Service |
bc2650 |
errx (-1, "unexpected memory problems");
|
|
Packit Service |
6d40f9 |
adcli_entry_set_domain_ou (entry, ou);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
res = adcli_conn_connect (conn);
|
|
Packit Service |
6d40f9 |
if (res != ADCLI_SUCCESS) {
|
|
Packit Service |
bc2650 |
errx (-res, "couldn't connect to domain %s: %s",
|
|
Packit Service |
bc2650 |
adcli_conn_get_domain_name (conn),
|
|
Packit Service |
bc2650 |
adcli_get_last_error ());
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
res = adcli_entry_create (entry, attrs);
|
|
Packit Service |
6d40f9 |
if (res != ADCLI_SUCCESS) {
|
|
Packit Service |
bc2650 |
errx (-res, "creating group %s in domain %s failed: %s",
|
|
Packit Service |
bc2650 |
adcli_entry_get_sam_name (entry),
|
|
Packit Service |
bc2650 |
adcli_conn_get_domain_name (conn),
|
|
Packit Service |
bc2650 |
adcli_get_last_error ());
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
adcli_entry_unref (entry);
|
|
Packit Service |
6d40f9 |
adcli_attrs_free (attrs);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
return 0;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
int
|
|
Packit Service |
6d40f9 |
adcli_tool_group_delete (adcli_conn *conn,
|
|
Packit Service |
6d40f9 |
int argc,
|
|
Packit Service |
6d40f9 |
char *argv[])
|
|
Packit Service |
6d40f9 |
{
|
|
Packit Service |
6d40f9 |
adcli_result res;
|
|
Packit Service |
6d40f9 |
adcli_entry *entry;
|
|
Packit Service |
6d40f9 |
int opt;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
struct option options[] = {
|
|
Packit Service |
6d40f9 |
{ "domain", required_argument, NULL, opt_domain },
|
|
Packit Service |
6d40f9 |
{ "domain-realm", required_argument, NULL, opt_domain_realm },
|
|
Packit Service |
6d40f9 |
{ "domain-controller", required_argument, NULL, opt_domain_controller },
|
|
Packit Service |
6d40f9 |
{ "login-user", required_argument, NULL, opt_login_user },
|
|
Packit Service |
6d40f9 |
{ "login-ccache", optional_argument, NULL, opt_login_ccache },
|
|
Packit Service |
6d40f9 |
{ "no-password", no_argument, 0, opt_no_password },
|
|
Packit Service |
6d40f9 |
{ "stdin-password", no_argument, 0, opt_stdin_password },
|
|
Packit Service |
6d40f9 |
{ "prompt-password", no_argument, 0, opt_prompt_password },
|
|
Packit Service |
6d40f9 |
{ "verbose", no_argument, NULL, opt_verbose },
|
|
Packit Service |
6d40f9 |
{ "help", no_argument, NULL, 'h' },
|
|
Packit Service |
6d40f9 |
{ 0 },
|
|
Packit Service |
6d40f9 |
};
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
static adcli_tool_desc usages[] = {
|
|
Packit Service |
6d40f9 |
{ 0, "usage: adcli delete-group --domain=xxxx group" },
|
|
Packit Service |
6d40f9 |
{ 0 },
|
|
Packit Service |
6d40f9 |
};
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
|
|
Packit Service |
6d40f9 |
switch (opt) {
|
|
Packit Service |
6d40f9 |
case 'h':
|
|
Packit Service |
6d40f9 |
case '?':
|
|
Packit Service |
6d40f9 |
case ':':
|
|
Packit Service |
6d40f9 |
adcli_tool_usage (options, usages);
|
|
Packit Service |
6d40f9 |
adcli_tool_usage (options, common_usages);
|
|
Packit Service |
6d40f9 |
return opt == 'h' ? 0 : 2;
|
|
Packit Service |
6d40f9 |
default:
|
|
Packit Service |
bc2650 |
parse_option ((Option)opt, optarg, conn);
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
argc -= optind;
|
|
Packit Service |
6d40f9 |
argv += optind;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
bc2650 |
if (argc != 1)
|
|
Packit Service |
bc2650 |
errx (2, "specify one group name to delete");
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
entry = adcli_entry_new_group (conn, argv[0]);
|
|
Packit Service |
bc2650 |
if (entry == NULL)
|
|
Packit Service |
bc2650 |
errx (-1, "unexpected memory problems");
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
res = adcli_conn_connect (conn);
|
|
Packit Service |
6d40f9 |
if (res != ADCLI_SUCCESS) {
|
|
Packit Service |
bc2650 |
errx (-res, "couldn't connect to %s domain: %s",
|
|
Packit Service |
bc2650 |
adcli_conn_get_domain_name (conn),
|
|
Packit Service |
bc2650 |
adcli_get_last_error ());
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
res = adcli_entry_delete (entry);
|
|
Packit Service |
6d40f9 |
if (res != ADCLI_SUCCESS) {
|
|
Packit Service |
bc2650 |
errx (-res, "deleting group %s in domain %s failed: %s",
|
|
Packit Service |
bc2650 |
adcli_entry_get_sam_name (entry),
|
|
Packit Service |
bc2650 |
adcli_conn_get_domain_name (conn),
|
|
Packit Service |
bc2650 |
adcli_get_last_error ());
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
adcli_entry_unref (entry);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
return 0;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
bc2650 |
static void
|
|
Packit Service |
6d40f9 |
expand_user_dn_as_member (adcli_conn *conn,
|
|
Packit Service |
6d40f9 |
adcli_attrs *attrs,
|
|
Packit Service |
6d40f9 |
const char *user,
|
|
Packit Service |
6d40f9 |
int adding)
|
|
Packit Service |
6d40f9 |
{
|
|
Packit Service |
6d40f9 |
adcli_entry *entry;
|
|
Packit Service |
6d40f9 |
adcli_result res;
|
|
Packit Service |
6d40f9 |
const char *dn;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
entry = adcli_entry_new_user (conn, user);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
res = adcli_entry_load (entry);
|
|
Packit Service |
6d40f9 |
if (res != ADCLI_SUCCESS) {
|
|
Packit Service |
bc2650 |
errx (-res, "couldn't lookup user %s in domain %s: %s",
|
|
Packit Service |
bc2650 |
user, adcli_conn_get_domain_name (conn),
|
|
Packit Service |
bc2650 |
adcli_get_last_error ());
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
dn = adcli_entry_get_dn (entry);
|
|
Packit Service |
6d40f9 |
if (dn == NULL) {
|
|
Packit Service |
bc2650 |
errx (-ADCLI_ERR_CONFIG,
|
|
Packit Service |
bc2650 |
"couldn't found user %s in domain %s",
|
|
Packit Service |
bc2650 |
user, adcli_conn_get_domain_name (conn));
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
if (adding)
|
|
Packit Service |
6d40f9 |
adcli_attrs_add1 (attrs, "member", dn);
|
|
Packit Service |
6d40f9 |
else
|
|
Packit Service |
6d40f9 |
adcli_attrs_delete1 (attrs, "member", dn);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
adcli_entry_unref (entry);
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
int
|
|
Packit Service |
6d40f9 |
adcli_tool_member_add (adcli_conn *conn,
|
|
Packit Service |
6d40f9 |
int argc,
|
|
Packit Service |
6d40f9 |
char *argv[])
|
|
Packit Service |
6d40f9 |
{
|
|
Packit Service |
6d40f9 |
adcli_result res;
|
|
Packit Service |
6d40f9 |
adcli_entry *entry;
|
|
Packit Service |
6d40f9 |
adcli_attrs *attrs;
|
|
Packit Service |
6d40f9 |
int opt;
|
|
Packit Service |
6d40f9 |
int i;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
struct option options[] = {
|
|
Packit Service |
6d40f9 |
{ "domain", required_argument, NULL, opt_domain },
|
|
Packit Service |
6d40f9 |
{ "domain-realm", required_argument, NULL, opt_domain_realm },
|
|
Packit Service |
6d40f9 |
{ "domain-controller", required_argument, NULL, opt_domain_controller },
|
|
Packit Service |
6d40f9 |
{ "login-user", required_argument, NULL, opt_login_user },
|
|
Packit Service |
6d40f9 |
{ "login-ccache", optional_argument, NULL, opt_login_ccache },
|
|
Packit Service |
6d40f9 |
{ "no-password", no_argument, 0, opt_no_password },
|
|
Packit Service |
6d40f9 |
{ "stdin-password", no_argument, 0, opt_stdin_password },
|
|
Packit Service |
6d40f9 |
{ "prompt-password", no_argument, 0, opt_prompt_password },
|
|
Packit Service |
6d40f9 |
{ "verbose", no_argument, NULL, opt_verbose },
|
|
Packit Service |
6d40f9 |
{ "help", no_argument, NULL, 'h' },
|
|
Packit Service |
6d40f9 |
{ 0 },
|
|
Packit Service |
6d40f9 |
};
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
static adcli_tool_desc usages[] = {
|
|
Packit Service |
6d40f9 |
{ 0, "usage: adcli add-member --domain=xxxx group user ..." },
|
|
Packit Service |
6d40f9 |
{ 0 },
|
|
Packit Service |
6d40f9 |
};
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
|
|
Packit Service |
6d40f9 |
switch (opt) {
|
|
Packit Service |
6d40f9 |
case 'h':
|
|
Packit Service |
6d40f9 |
case '?':
|
|
Packit Service |
6d40f9 |
case ':':
|
|
Packit Service |
6d40f9 |
adcli_tool_usage (options, usages);
|
|
Packit Service |
6d40f9 |
adcli_tool_usage (options, common_usages);
|
|
Packit Service |
6d40f9 |
return opt == 'h' ? 0 : 2;
|
|
Packit Service |
6d40f9 |
default:
|
|
Packit Service |
bc2650 |
parse_option ((Option)opt, optarg, conn);
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
argc -= optind;
|
|
Packit Service |
6d40f9 |
argv += optind;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
bc2650 |
if (argc < 2)
|
|
Packit Service |
bc2650 |
errx (2, "specify a group name and a user to add");
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
entry = adcli_entry_new_group (conn, argv[0]);
|
|
Packit Service |
bc2650 |
if (entry == NULL)
|
|
Packit Service |
bc2650 |
errx (-1, "unexpected memory problems");
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
res = adcli_conn_connect (conn);
|
|
Packit Service |
6d40f9 |
if (res != ADCLI_SUCCESS) {
|
|
Packit Service |
bc2650 |
errx (-res, "couldn't connect to %s domain: %s",
|
|
Packit Service |
bc2650 |
adcli_conn_get_domain_name (conn),
|
|
Packit Service |
bc2650 |
adcli_get_last_error ());
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
attrs = adcli_attrs_new ();
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
bc2650 |
for (i = 1; i < argc; i++)
|
|
Packit Service |
bc2650 |
expand_user_dn_as_member (conn, attrs, argv[i], 1);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
res = adcli_entry_modify (entry, attrs);
|
|
Packit Service |
6d40f9 |
if (res != ADCLI_SUCCESS) {
|
|
Packit Service |
bc2650 |
errx (-res, "adding member(s) to group %s in domain %s failed: %s",
|
|
Packit Service |
bc2650 |
adcli_entry_get_sam_name (entry),
|
|
Packit Service |
bc2650 |
adcli_conn_get_domain_name (conn),
|
|
Packit Service |
bc2650 |
adcli_get_last_error ());
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
adcli_attrs_free (attrs);
|
|
Packit Service |
6d40f9 |
adcli_entry_unref (entry);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
return 0;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
int
|
|
Packit Service |
6d40f9 |
adcli_tool_member_remove (adcli_conn *conn,
|
|
Packit Service |
6d40f9 |
int argc,
|
|
Packit Service |
6d40f9 |
char *argv[])
|
|
Packit Service |
6d40f9 |
{
|
|
Packit Service |
6d40f9 |
adcli_result res;
|
|
Packit Service |
6d40f9 |
adcli_entry *entry;
|
|
Packit Service |
6d40f9 |
adcli_attrs *attrs;
|
|
Packit Service |
6d40f9 |
int opt;
|
|
Packit Service |
6d40f9 |
int i;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
struct option options[] = {
|
|
Packit Service |
6d40f9 |
{ "domain", required_argument, NULL, opt_domain },
|
|
Packit Service |
6d40f9 |
{ "domain-realm", required_argument, NULL, opt_domain_realm },
|
|
Packit Service |
6d40f9 |
{ "domain-controller", required_argument, NULL, opt_domain_controller },
|
|
Packit Service |
6d40f9 |
{ "login-user", required_argument, NULL, opt_login_user },
|
|
Packit Service |
6d40f9 |
{ "login-ccache", optional_argument, NULL, opt_login_ccache },
|
|
Packit Service |
6d40f9 |
{ "no-password", no_argument, 0, opt_no_password },
|
|
Packit Service |
6d40f9 |
{ "stdin-password", no_argument, 0, opt_stdin_password },
|
|
Packit Service |
6d40f9 |
{ "prompt-password", no_argument, 0, opt_prompt_password },
|
|
Packit Service |
6d40f9 |
{ "verbose", no_argument, NULL, opt_verbose },
|
|
Packit Service |
6d40f9 |
{ "help", no_argument, NULL, 'h' },
|
|
Packit Service |
6d40f9 |
{ 0 },
|
|
Packit Service |
6d40f9 |
};
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
static adcli_tool_desc usages[] = {
|
|
Packit Service |
6d40f9 |
{ 0, "usage: adcli remove-member --domain=xxxx group user ..." },
|
|
Packit Service |
6d40f9 |
{ 0 },
|
|
Packit Service |
6d40f9 |
};
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
|
|
Packit Service |
6d40f9 |
switch (opt) {
|
|
Packit Service |
6d40f9 |
case 'h':
|
|
Packit Service |
6d40f9 |
case '?':
|
|
Packit Service |
6d40f9 |
case ':':
|
|
Packit Service |
6d40f9 |
adcli_tool_usage (options, usages);
|
|
Packit Service |
6d40f9 |
adcli_tool_usage (options, common_usages);
|
|
Packit Service |
6d40f9 |
return opt == 'h' ? 0 : 2;
|
|
Packit Service |
6d40f9 |
default:
|
|
Packit Service |
bc2650 |
parse_option ((Option)opt, optarg, conn);
|
|
Packit Service |
6d40f9 |
break;
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
argc -= optind;
|
|
Packit Service |
6d40f9 |
argv += optind;
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
bc2650 |
if (argc < 2)
|
|
Packit Service |
bc2650 |
errx (2, "specify a group name and a user to remove");
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
entry = adcli_entry_new_group (conn, argv[0]);
|
|
Packit Service |
bc2650 |
if (entry == NULL)
|
|
Packit Service |
bc2650 |
errx (-1, "unexpected memory problems");
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
res = adcli_conn_connect (conn);
|
|
Packit Service |
6d40f9 |
if (res != ADCLI_SUCCESS) {
|
|
Packit Service |
bc2650 |
errx (-res, "couldn't connect to %s domain: %s",
|
|
Packit Service |
bc2650 |
adcli_conn_get_domain_name (conn),
|
|
Packit Service |
bc2650 |
adcli_get_last_error ());
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
attrs = adcli_attrs_new ();
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
bc2650 |
for (i = 1; i < argc; i++)
|
|
Packit Service |
bc2650 |
expand_user_dn_as_member (conn, attrs, argv[i], 0);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
res = adcli_entry_modify (entry, attrs);
|
|
Packit Service |
6d40f9 |
if (res != ADCLI_SUCCESS) {
|
|
Packit Service |
bc2650 |
errx (-res, "adding member(s) to group %s in domain %s failed: %s",
|
|
Packit Service |
bc2650 |
adcli_entry_get_sam_name (entry),
|
|
Packit Service |
bc2650 |
adcli_conn_get_domain_name (conn),
|
|
Packit Service |
bc2650 |
adcli_get_last_error ());
|
|
Packit Service |
6d40f9 |
}
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
adcli_attrs_free (attrs);
|
|
Packit Service |
6d40f9 |
adcli_entry_unref (entry);
|
|
Packit Service |
6d40f9 |
|
|
Packit Service |
6d40f9 |
return 0;
|
|
Packit Service |
6d40f9 |
}
|