idmap.c revision 9581d9f4f3b1515f88149f920c7e786b4fb901d4
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * CDDL HEADER START
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * The contents of this file are subject to the terms of the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Common Development and Distribution License (the "License").
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * You may not use this file except in compliance with the License.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * See the License for the specific language governing permissions
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * and limitations under the License.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * When distributing Covered Code, include this CDDL HEADER in each
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * If applicable, add the following below this CDDL HEADER, with the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * fields enclosed by brackets "[]" replaced with your own identifying
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * information: Portions Copyright [yyyy] [name of copyright owner]
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * CDDL HEADER END
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Use is subject to license terms.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#pragma ident "%Z%%M% %I% %E% SMI"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/* Initialization values for pids/rids: */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/* is_user values */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/* Directions */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * used in do_show for the type of argument, which can be winname,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * unixname, uid, gid, sid or not given at all:
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#define IS_WIN 0x010 /* mask for the windows types */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#define IS_NAME 0x100 /* mask for string name types */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#define IS_GROUP 0x002 /* mask for, well, TYPE_GID */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/* Identity type strings */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/* used in the function do_import */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsynctypedef struct {
char *windomain;
char *sidprefix;
* usermap.cfg.
* add -u -d winname:bob2bar.com unixname:fred
* documentation, search for "username map" in smb.conf manpage.
* USERMAP_CFG is the format of Netapp usermap.cfg file. Search
* http://www.netapp.com/ for more documentation. IP qualifiers are not
* "Bob With Spaces"@bar.com => fred #comment
DEFAULT_FORMAT = 0,
} format_t;
static char *pnm_last_unixname;
static int batch_mode = 0;
static int udt_used;
help() {
help();
init_batch() {
if (stat < 0) {
init_command() {
if (batch_mode)
return (init_batch());
fini_command() {
if (batch_mode)
init_udt_batch() {
if (init_batch())
if (stat < 0) {
init_udt_command() {
if (batch_mode)
return (init_udt_batch());
if (batch_mode)
if (stat < 0) {
udt_used = 0;
fini_command();
switch (direction) {
case DIR_BI:
case DIR_W2U:
case DIR_U2W:
c = string[i];
char *to;
return (NULL);
return (to);
char *to;
return (NULL);
return (to);
char *out;
is_domain = 0;
if (!is_domain)
char *out;
char *it;
pnm_format = f;
switch (pnm_format) {
case SMBUSERS:
switch (pnm_format) {
case SMBUSERS:
char *dirstring;
char type;
switch (pnm_format) {
case MAPPING_NAME:
case MAPPING_ID:
unixname);
case SMBUSERS:
f = stderr;
f = stderr;
if (pnm_file != f) {
case USERMAP_CFG:
f = stderr;
case DEFAULT_FORMAT:
(void) fprintf(f,
(void) fprintf(f,
static name_mapping_t *
return (NULL);
return (nm);
int is_user;
int rc = 0;
if (init_command())
stdout);
if (stat < 0) {
goto cleanup;
goto cleanup;
if (stat >= 0)
} while (stat > 0);
goto cleanup;
(void) print_mapping_fini();
fini_command();
return (rc);
return (NULL);
return (out);
char *it;
char *out;
line_num);
return (NULL);
return (out);
char *token;
return (token);
* Convert a line in usermap.cfg format to name_mapping. line_num is
char *it;
char *token;
char *token2;
char separator;
int is_direction = 0;
line_num);
line_num);
it ++;
line_num);
is_direction = 0;
if (is_direction) {
line_num);
line_num);
char *token;
case USERMAP_CFG:
case SMBUSERS:
static format_t
return (UNDEFINED_FORMAT);
return (DEFAULT_FORMAT);
return (USERMAP_CFG);
return (SMBUSERS);
return (UNDEFINED_FORMAT);
if (stat < 0) {
int rc = 0;
int line_num;
if (batch_mode) {
if (init_udt_command())
/* We don't flush groups in the usermap.cfg nor smbusers format */
goto cleanup;
line_num = 0;
goto cleanup;
line_num++;
goto cleanup;
if (stat < 0) {
} while (rc >= 0);
if (rc < 0) {
return (rc);
int is_user;
if (stat < 0) {
if (stat >= 0) {
} while (stat > 0);
(void) print_mapping_fini();
int rc;
if (init_command() < 0) {
goto cleanup;
is_group_wanted(f),
fi);
fini_command();
return (rc);
int rc;
if (init_command()) {
is_group_wanted(f),
stdout);
fini_command();
return (rc);
for (c = 0; c < FLAG_ALPHABET_SIZE; c++) {
if (f[c] == FLAG_SET)
char *it;
int rc = 0;
} else if (!is_type_determined(f))
if (is_argv0_unix < 0)
if (init_udt_command()) {
(void) print_mapping_fini();
if (stat < 0) {
return (rc);
int rc = 0;
if (argc) {
if (!is_type_determined(f))
if (init_udt_command())
return (rc);
} else if (!is_type_determined(f)) {
if (is_argv0_unix < 0)
if (init_udt_command()) {
if (stat < 0) {
return (rc);
print_flags(f);
for (i = 0; i < argc; i++) {
return (NULL);
switch (type) {
case TYPE_SID:
case TYPE_WN:
case TYPE_UID:
case TYPE_GID:
case TYPE_PID:
case TYPE_UN:
int flag;
int type_from;
int type_to;
char *root;
char *fromname;
char *toname;
if (argc == 0) {
if (init_command())
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
flag,
flag,
if (stat < 0) {
goto cleanup;
flag,
&uid,
&map_stat);
flag,
&gid,
&map_stat);
flag,
&map_stat);
flag,
&map_stat);
flag,
&map_stat);
if (stat < 0) {
goto cleanup;
if (stat < 0) {
goto cleanup;
if (map_stat < 0) {
goto cleanup;
goto cleanup;
if (flag == 0)
goto cleanup;
fini_command();
int rc;
&batch_mode);
if (rc < 0) {
(void) engine_fini();
help();
udt_used = 0;
if (batch_mode) {
if (init_udt_batch() < 0)
if (batch_mode) {
batch_mode = 0;
(void) engine_fini();