idmap.c revision 48258c6b4e17f36ab09fba0bd6307d1fec9dcbce
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * CDDL HEADER START
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * The contents of this file are subject to the terms of the
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Common Development and Distribution License (the "License").
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * You may not use this file except in compliance with the License.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * See the License for the specific language governing permissions
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * and limitations under the License.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * When distributing Covered Code, include this CDDL HEADER in each
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5dbfd19ad5fcc2b779f40f80fa05c1bd28fd0b4eTheo Schlossnagle * If applicable, add the following below this CDDL HEADER, with the
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore * fields enclosed by brackets "[]" replaced with your own identifying
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * information: Portions Copyright [yyyy] [name of copyright owner]
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * CDDL HEADER END
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * Use is subject to license terms.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#pragma ident "%Z%%M% %I% %E% SMI"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Initialization values for pids/rids: */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* is_user values */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * used in do_show for the type of argument, which can be winname,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * unixname, uid, gid, sid or not given at all:
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#define IS_WIN 0x010 /* mask for the windows types */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#define IS_NAME 0x100 /* mask for string name types */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#define IS_GROUP 0x002 /* mask for group types */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Identity type strings */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#define INHIBITED(str) (str == NULL || *str == 0 || strcmp(str, "\"\"") == 0)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowetypedef struct {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* used in the function do_import */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowetypedef struct {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Formats of the output:
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Idmap reads/prints mappings in several formats: ordinary mappings,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * name mappings in Samba username map format (smbusers), Netapp
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * DEFAULT_FORMAT are in fact the idmap subcommands suitable for
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * piping to idmap standart input. For example
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * add -d winuser:bob@foo.com unixuser:fred
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * add -d winuser:bob2bar.com unixuser:fred
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * SMBUSERS is the format of Samba username map (smbusers). For full
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * documentation, search for "username map" in smb.conf manpage.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * The format is for example
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * fred = bob@foo.com bob2@bar.com
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * USERMAP_CFG is the format of Netapp usermap.cfg file. Search
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * http://www.netapp.com/ for more documentation. IP qualifiers are not
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * supported.
296749875bd503e7a14e25b4c57d3142cb496df1Joshua M. Clulow * The format is for example
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * bob@foo.com => fred
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * "Bob With Spaces"@bar.com => fred #comment
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * The previous formats were for name rules. MAPPING_NAME and
d2b9ba291ef0d1dc8807b6d46996674c723924d0Robert Mustacchi * MAPPING_ID are for the actual mappings, as seen in show/dump
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * commands. MAPPING_NAME prefers the string names of the user over
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * their numerical identificators. MAPPING_ID prints just the
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * identificators.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Example of the MAPPING_NAME:
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * winname:bob@foo.com -> unixname:fred
b65dd972486b1f5913d705d2a0cb9c3fb189a9e0Robert Mustacchi * Example of the MAPPING_ID:
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * sid:S-1-2-3-4 -> uid:5678
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowetypedef enum {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowetypedef struct {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * idmap_api batch related variables:
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * idmap can operate in two modes. It the batch mode, the idmap_api
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * batch is committed at the end of a batch of several
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * commands. At the end of input file, typically. This mode is used
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * for processing input from a file.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * In the non-batch mode, each command is committed immediately. This
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * mode is used for tty input.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Are we in the batch mode? */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int batch_mode = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Self describing stricture for positions */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Handles for idmap_api batch */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Do we need to commit the udt batch at the end? */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Command handlers */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int do_show_mapping(flag_t *f, int argc, char **argv, cmd_pos_t *pos);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int do_dump(flag_t *f, int argc, char **argv, cmd_pos_t *pos);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int do_import(flag_t *f, int argc, char **argv, cmd_pos_t *pos);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int do_list_name_mappings(flag_t *f, int argc, char **argv,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int do_add_name_mapping(flag_t *f, int argc, char **argv,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int do_remove_name_mapping(flag_t *f, int argc, char **argv,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int do_exit(flag_t *f, int argc, char **argv, cmd_pos_t *pos);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int do_export(flag_t *f, int argc, char **argv, cmd_pos_t *pos);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int do_help(flag_t *f, int argc, char **argv, cmd_pos_t *pos);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Command names and their hanlers to be passed to idmap_engine */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "c(create)v(verbose)",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "n(names)v(verbose)",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "F(flush)f:(file)",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "d(directional)",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "a(all)t(to)f(from)d(directional)",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Print error message, possibly with a position */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* printflike */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Loweprint_error(cmd_pos_t *pos, const char *format, ...)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Skip newlines etc at the end: */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe while (length > 0 && isspace(pos->line[length - 1]))
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Inits positions sds. 0 means everything went OK, -1 for errors */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe int init_size = 32; /* Initial size of the positions array */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe positions = (struct pos_sds *) malloc(sizeof (struct pos_sds) +
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe print_error(NULL, gettext("Not enough memory.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Free the positions array */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Add another position to the positions array. 0 means everything
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * went OK, -1 for errors
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe positions = (struct pos_sds *)realloc(positions,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe sizeof (struct pos_sds) +
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe positions->pos[positions->last] = (cmd_pos_t *)calloc(1,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe positions->pos[positions->last]->line = strdup(pos->line);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (positions->pos[positions->last]->line == NULL)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe print_error(NULL, gettext("Not enough memory.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Compare two strings just like strcmp, but stop before the end of
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Print help message */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "idmap -f command-file\n"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "idmap show [-c] [-v] identity [targettype]\n"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "idmap dump [-n] [-v]\n"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "idmap add [-d] name1 name2\n"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "idmap remove -a\n"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "idmap remove [-f|-t] name\n"
d3864341aacc6a2ecc95960d23ac0e49f1f538faRobert Mustacchi "idmap remove [-d] name1 name2\n"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "idmap list\n"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "idmap import [-F] [-f file] format\n"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "idmap export [-f file] format\n"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "idmap help\n");
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* The handler for the "help" command. */
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore/* LINTED E_FUNC_ARG_UNUSED */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowedo_help(flag_t *f, int argc, char **argv, cmd_pos_t *pos)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Initialization of the idmap api batch */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Initialization common to all commands */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Finalization common to all commands */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Initialization of the commands which perform write operations */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore/* Finalization of the write commands */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* If everythings is OK, send the udt batch to idmapd */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe gettext("Internal error: uninitiated batch.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe stat1 = idmap_udt_get_error_index(udt, &failpos);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe gettext("Error diagnosing transaction (%s)\n"),
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Convert numeric expression of the direction to it's string form */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic char *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return ("==");
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return ("=>");
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return ("<=");
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* This can never happen: */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe gettext("Internal error: invalid direction.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return ("");
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* never reached */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Returns 1 if c is a shell-meta-character requiring quoting, 0
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * otherwise.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * We don't quote '*' and ':' because they cannot do any harm
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * a) they have no meaning to idmap_engine b) even ifsomebody copy &
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * paste idmap output to a shell commandline, there is the identity
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * type string in front of them. On the other hand, '*' and ':' are
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * everywhere.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (strchr("&^{}#;'\"\\`!$()[]><|~", c) != NULL)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Returns 1 if c is a shell-meta-character requiring quoting even
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * inside double quotes, 0 otherwise. It means \, " and $ .
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * This set of characters is a subset of those in is_shell_special().
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Quote any shell meta-characters in the given string. If 'quote' is
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * true then use double-quotes to quote the whole string, else use
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * back-slash to quote each individual meta-character.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * The resulting string is placed in *res. Callers must free *res if the
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * return value isn't 0 (even if the given string had no meta-chars).
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * If there are any errors this returns -1, else 0.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint_t noss = 0; /* Number Of Shell Special chars in the input */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint_t noqb = 0; /* Number Of Quotes and Backslahes in the input */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe print_error(NULL, gettext("Not enough memory.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* First, let us count how many characters we need to quote: */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe for (i = 0; i < len_orig; i++) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Do we need to quote at all? */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe print_error(NULL, gettext("Not enough memory.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* What is the length of the result? */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe len = strlen(string) + 2 + noqb + 1; /* 2 for quotation marks */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe print_error(NULL, gettext("Not enough memory.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe for (i = 0; i < len_orig; i++) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Quote the dangerous chars by a backslash */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Assemble string form sid */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic char *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* 'usid:' + sidprefix + '-' + rid + '\0' */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe len = strlen(nm->sidprefix) + 7 + 3 * sizeof (nm->rid);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) snprintf(to, len, "%s:%s-%u", typestring, nm->sidprefix,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Assemble string form uid or gid */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic char *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* ID_UID ":" + uid + '\0' */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) snprintf(to, 16, "%s:%u", is_user ? ID_UID : ID_GID, from);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Assemble winname, e.g. "winuser:bob@foo.sun.com", from name_mapping_t */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Sometimes there are no text names. Return a sid, then. */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (nm->winname == NULL && nm->sidprefix != NULL) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Windomain is not mandatory: */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (nm->windomain == NULL || INHIBITED(nm->winname))
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* LINTED E_NOP_IF_STMT */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Assemble a text unixname, e.g. unixuser:fred. Use only for
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * mapping, not namerules - there an empty name means inhibited
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * mappings, while here pid is printed if there is no name.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowenm2unixname(name_mapping_t *nm, char **unixname)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Sometimes there is no name, just pid: */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Allocate a new name_mapping_t and initialize the values. */
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore name_mapping_t *nm = (name_mapping_t *)malloc(sizeof (name_mapping_t));
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore print_error(NULL, gettext("Not enough memory.\n"));
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore nm->winname = nm->windomain = nm->unixname = nm->sidprefix = NULL;
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore/* Free name_mapping_t */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowename_mapping_cpy(name_mapping_t *to, name_mapping_t *from)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) memcpy(to, from, sizeof (name_mapping_t));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe to->winname = to->windomain = to->unixname = to->sidprefix = NULL;
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore print_error(NULL, gettext("Not enough memory.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe print_error(NULL, gettext("Not enough memory.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe print_error(NULL, gettext("Not enough memory.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe print_error(NULL, gettext("Not enough memory.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowename_mapping_format(name_mapping_t *nm, char **out)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* 10 is strlen("add -d\t\t\n") + 1 */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe maxlen = 10 + strlen(unixname) + strlen(winname);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) snprintf(*out, maxlen, "add -d\t%s\t%s\n",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) snprintf(*out, maxlen, "add %s\t%s\t%s\n",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe nm->direction == IDMAP_DIRECTION_BI? "" : "-d",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Initialize print_mapping variables. Must be called before print_mapping */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe out = (print_handle_t *)malloc(sizeof (print_handle_t));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe print_error(NULL, gettext("Not enough memory.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/* Finalize print_mapping. */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic char *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Compare two possibly NULL strings
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestrcmp_null(char *a, char *b)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (strcmp(a, b));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * This prints both name rules and ordinary mappings, based on the pnm_format
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * set in print_mapping_init().
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Loweprint_mapping(print_handle_t *pnm, name_mapping_t *nm)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* LINTED E_CASE_FALLTHRU */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) fprintf(f, "%s\t%s\t%s\n", winname, dirstring,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (nm->is_user != I_YES || nm->is_wuser != I_YES) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else if (nm->direction == IDMAP_DIRECTION_U2W) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe gettext("Opposite direction of the mapping: "));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else if (INHIBITED(nm->winname) || INHIBITED(nm->unixname)) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe print_error(NULL, gettext("Inhibited rule: "));
ead9bb4b1be81d7bbf8ed86ee41d6c1e58b069a3Yuri Pankov return (-1);
bad51a906c423d0d7ab33fcc1a4e317d789e3c49Robert Mustacchi unixname = INHIBITED(nm->unixname) ? "\"\"" : nm->unixname;
bad51a906c423d0d7ab33fcc1a4e317d789e3c49Robert Mustacchi (void) fprintf(f, "%s=%s\n", unixname, winname);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (nm->is_user != I_YES || nm->is_wuser != I_YES) {
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore dirstring = direction2string(nm->direction);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if ((winname = usermap_cfg_string(nm->winname)) == NULL ||
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (unixname = usermap_cfg_string(nm->unixname)) == NULL ||
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (windomain = usermap_cfg_string(nm->windomain)) == NULL) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe print_error(NULL, gettext("Not enough memory.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "%s\\%s\t%s\t%s\n" :
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "%2$s@%1$s\t%3$s\t%4$s\n",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* This is a format for namerules */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * If nm is the same as the last one except is_wuser, we combine
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * winuser & wingroup to winname
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore strcmp_null(pnm->last->unixname, nm->unixname) == 0 &&
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore strcmp_null(pnm->last->winname, nm->winname) == 0 &&
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore strcmp_null(pnm->last->windomain, nm->windomain) == 0) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* This can never happen: */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe gettext("Internal error: invalid print format.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) printf(gettext("Method:\tAD Directory\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) printf(gettext("Method:\tNative LDAP Directory\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) printf(gettext("Method:\tName Rule\n"));
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore * The name rules as specified by the user can have a
f07f0fb66492a2792d4da5e0a6f9a92b4c581ab3Garrett D'Amore * "winname", "winuser" or "wingroup". "Winname" rules are
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * decomposed to a "winuser" and "wingroup" rules by idmap.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Currently is_wuser is a boolean. Due to these reasons
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * the returned is_wuser does not represent the original rule.
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore * It is therefore better set is_wuser to unknown.
f07f0fb66492a2792d4da5e0a6f9a92b4c581ab3Garrett D'Amore if (name_mapping_format(&nm, &rule_text) == 0) {
538aa54d819fa7751ca82bcc30d4ed8c57ec2ef2Garrett D'Amore (void) printf(gettext("Rule:\t%s"), rule_text);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) printf(gettext("Method:\tEphemeral\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) printf(gettext("Method:\tLocal SID\n"));
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore (void) printf(gettext("Method:\tWell-Known mapping\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (info->how.map_type != IDMAP_MAP_TYPE_UNKNOWN) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) printf(gettext("Source:\tHard Coded\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) printf(gettext("Source:\tAlgorithmic\n"));
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov (void) fprintf(stderr, gettext("Attribute:\t%s=%s\n"),
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov gettext("Failed Method:\tNative LDAP Directory\n"));
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov (void) fprintf(stderr, gettext("Attribute:\t%s=%s\n"),
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov (void) fprintf(stderr, gettext("Failed Method:\tName Rule\n"));
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * The name rules as specified by the user can have a
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * "winname", "winuser" or "wingroup". "Winname" rules are
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * decomposed to a "winuser" and "wingroup" rules by idmap.
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * Currently is_wuser is a boolean. Due to these reasons
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * the returned is_wuser does not represent the original rule.
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * It is therefore better to set is_wuser to unknown.
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov if (name_mapping_format(&nm, &rule_text) == 0) {
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov (void) fprintf(stderr, gettext("Rule:\t%s"), rule_text);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov (void) fprintf(stderr, gettext("Failed Method:\tEphemeral\n"));
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov (void) fprintf(stderr, gettext("Failed Method:\tLocal SID\n"));
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov gettext("Failed Method:\tWell-Known mapping\n"));
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov/* dump command handler */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov/* LINTED E_FUNC_ARG_UNUSED */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankovdo_dump(flag_t *f, int argc, char **argv, cmd_pos_t *pos)
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov ph = print_mapping_init(f[n_FLAG] != NULL ? MAPPING_NAME : MAPPING_ID,
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov stat = idmap_iter_mappings(handle, &ihandle, flag);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov gettext("Iteration handle not obtained (%s)\n"),
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov } while (stat > 0);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* IDMAP_ERR_NOTFOUND indicates end of the list */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * The same as strdup, but length chars is duplicated, no matter on
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * '\0'. The caller must guarantee "length" chars in "from".
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankovstatic char *
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov print_error(NULL, gettext("Not enough memory\n"));
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * Convert pid from string to it's numerical representation. If it is
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * a valid string, i.e. number of a proper length, return 1. Otherwise
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * print an error message and return 0.
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankovpid_convert(char *string, uid_t *number, int type, cmd_pos_t *pos)
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov for (i = 0; i < len; i++) {
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore gettext("\"%s\" is not a valid %s: the non-digit"
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* Isn't it too large? */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * Convert SID from string to prefix and rid. If it has a valid
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * format, i.e. S(\-\d+)+, return 1. Otherwise print an error
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * message and return 0.
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankovsid_convert(char *from, char **prefix, idmap_rid_t *rid, cmd_pos_t *pos)
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov unsigned long r;
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov gettext("Invalid %s \"%s\": the authority and RID parts are"
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov " missing.\n"),
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* count '-'s */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* can't end on a '-' */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov gettext("Invalid %s \"%s\": '-' at the end.\n"),
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* check that we only have digits and '-' */
e232d9863a8486cf94eaa4bc06c2e9ff52bf3140Robert Mustacchi gettext("Invalid %s \"%s\": invalid character '%c'.\n"),
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* 64-bit safe parsing of unsigned 48-bit authority value */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* errors parsing the authority or too many bits */
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore if (cp == ecp || (a == 0 && errno == EINVAL)) {
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov gettext("Invalid %s \"%s\": unable to parse the "
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov "authority \"%.*s\".\n"), ID_SID, from, ecp - cp,
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov (a & 0x0000ffffffffffffULL) != a) {
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov if (j < 3) {
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov gettext("Invalid %s \"%s\": must have at least one RID.\n"),
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov for (i = 2; i < j; i++) {
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* Should never happen */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov " '-' missing.\n"),
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* 32-bit safe parsing of unsigned 32-bit RID */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* errors parsing the RID */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* should never happen */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov "unable to parse the RID "
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* check that all of the string SID has been consumed */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* Should never happen */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov "something is still left.\n"),
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* -1 for the '-' at the end: */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov/* Does the line start with USERMAP_CFG IP qualifier? */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * returns interior of quotation marks in USERMAP_CFG. In this format,
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * there cannot be a protected quotation mark inside.
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankovstatic char *
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * Grab next token from the line in USERMAP_CFG format. terminators,
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * the 3rd parameter, contains all the characters which can terminate
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * the token. line_num is the line number of input used for error
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * reporting.
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankovstatic char *
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankovucp_grab_token(char **line, cmd_pos_t *pos, const char *terminators)
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore * Convert a line in usermap.cfg format to name_mapping.
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * Return values: -1 for error, 0 for empty line, 1 for a mapping
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankovucp_line2nm(char *line, cmd_pos_t *pos, name_mapping_t *nm)
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* empty or comment lines are OK: */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* We do not support network qualifiers */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov gettext("Unable to handle network qualifier.\n"));
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore /* The windows name: */
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore token = ucp_grab_token(&it, pos, " \t#\\\n@=<");
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* Didn't we bump to the end of line? */
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore if (separator == '\0' || separator == '#') {
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* Do we have a domainname? */
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore if (separator == '\\' || separator == '@') {
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore token2 = ucp_grab_token(&it, pos, " \t\n#");
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* Direction string is optional: */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* Now unixname: */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* nm->winname to be freed by name_mapping_fini */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
1fcc078ae7c0a359a9274d2a5a90547aceb213a6Robert Mustacchi /* Neither here we support IP qualifiers */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov gettext("Unable to handle network qualifier.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Does something remain on the line */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe gettext("Unrecognized parameters \"%s\".\n"), it);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * Parse SMBUSERS line to name_mapping_t. if line is NULL, then
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * pasrsing of the previous line is continued. line_num is input line
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * number used for error reporting.
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * Return values:
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * rc -1: error
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * rc = 0: mapping found and the line is finished,
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * rc = 1: mapping found and there remains other on the line
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amoresup_line2nm(char *line, cmd_pos_t *pos, name_mapping_t *nm)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov/* Parse line to name_mapping_t. Basicaly just a format switch. */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankovline2nm(char *line, cmd_pos_t *pos, name_mapping_t *nm, format_t f)
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov switch (f) {
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* This can never happen */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov gettext("Internal error: invalid line format.\n"));
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov/* Examine -f flag and return the appropriate format_t */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov print_error(NULL, gettext("Format not given.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe gettext("The only known formats are: \"usermap.cfg\" and "
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov "\"smbusers\".\n"));
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov/* Delete all namerules of the given type */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov is_user ? gettext("Unable to flush users (%s).\n")
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov/* import command handler */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov/* LINTED E_FUNC_ARG_UNUSED */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowedo_import(flag_t *f, int argc, char **argv, cmd_pos_t *pos)
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov gettext("Import is not allowed in the batch mode.\n"));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* We don't flush groups in the usermap.cfg nor smbusers format */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* Where we import from? */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * In SMBUSERS format there can be more mappings on
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * each line. So we need the internal cycle for each line.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe stat = idmap_udt_add_namerule(udt, nm->windomain,
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov } while (rc >= 0);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * List name mappings in the format specified. list_users /
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * list_groups determine which type to list. The output goes to the
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov stat = idmap_iter_namerules(handle, NULL, 0, 0, NULL, NULL, &ihandle);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov gettext("Iteration handle not obtained (%s)\n"),
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov stat = idmap_iter_next_namerule(ihandle, &nm->windomain,
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov &nm->winname, &nm->unixname, &is_user, &is_wuser,
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov } while (stat > 0);
bad51a906c423d0d7ab33fcc1a4e317d789e3c49Robert Mustacchi if (stat < 0 && stat != IDMAP_ERR_NOTFOUND) {
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
bad51a906c423d0d7ab33fcc1a4e317d789e3c49Robert Mustacchi/* Export command handler */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov/* LINTED E_FUNC_ARG_UNUSED */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankovdo_export(flag_t *f, int argc, char **argv, cmd_pos_t *pos)
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* Where do we output to? */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* List the requested types: */
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore/* List command handler */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov/* LINTED E_FUNC_ARG_UNUSED */
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amoredo_list_name_mappings(flag_t *f, int argc, char **argv, cmd_pos_t *pos)
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* List the requested types: */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov rc = list_name_mappings(DEFAULT_FORMAT, stdout);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov/* This is just a debug function for dumping flags */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov for (c = 0; c < FLAG_ALPHABET_SIZE; c++) {
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov (void *) f[c]);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov else if (f[c])
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov (void) printf("FLAG: -%c, VALUE: %s\n", c, f[c]);
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore * Split argument to its identity code and a name part
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore * return values:
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore * -1 for unknown identity
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore * 0 for no identity
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * <TYPE_XXX> for known identity
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankovget_identity(char *arg, char **name, cmd_pos_t *pos)
cb66c7814563eb32e20c1be88ae738ad8d63079dRobert Mustacchi for (i = 0, code = 0;
cb66c7814563eb32e20c1be88ae738ad8d63079dRobert Mustacchi i < sizeof (identity2code) / sizeof (id_code_t);
cb66c7814563eb32e20c1be88ae738ad8d63079dRobert Mustacchi if (strcmp(identity2code[i].identity, arg) == 0) {
cb66c7814563eb32e20c1be88ae738ad8d63079dRobert Mustacchi /* restore the original string: */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov gettext("Error: invalid identity type \"%.*s\"\n"),
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * This function splits name to the relevant pieces: is_user, winname,
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * windomain unixname. E.g. for winname, it strdups nm->winname and possibly
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * nm->windomain and return TYPE_WN.
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov * If there is already one of the text fields allocated, it is OK.
f07f0fb66492a2792d4da5e0a6f9a92b4c581ab3Garrett D'Amore * Return values:
f07f0fb66492a2792d4da5e0a6f9a92b4c581ab3Garrett D'Amore * -1 ... syntax error
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore * 0 ... it wasnt possible to determine
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore * <TYPE_XXX> otherwise
f07f0fb66492a2792d4da5e0a6f9a92b4c581ab3Garrett D'Amorename2parts(char *name, name_mapping_t *nm, cmd_pos_t *pos)
538aa54d819fa7751ca82bcc30d4ed8c57ec2ef2Garrett D'Amore /* syntax error: */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* autodetection: */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov if (nm->winname != NULL && nm->is_wuser != I_UNKNOWN)
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov code = nm->is_wuser == I_YES ? TYPE_UU : TYPE_UG;
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* btw, nm->is_user can never be I_UNKNOWN here */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov /* If the code was guessed succesfully, we are OK. */
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov if (nm->winname != NULL || nm->windomain != NULL)
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov } else if ((it = strrchr(name, '\\')) != NULL) {
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov (void) strncpy(nm->windomain, name, length - 1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (!sid_convert(name, &nm->sidprefix, &nm->rid, pos))
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov return (-1);
return (code);
int code;
switch (code) {
int rc = 0;
int is_first_win;
int is_wuser;
if (init_udt_command()) {
goto cleanup;
if (stat < 0) {
if (rc == 0)
return (rc);
int rc = 0;
int is_first_win;
int is_wuser;
if (argc) {
if (init_udt_command())
if (rc >= 0)
return (rc);
if (init_udt_command()) {
if (stat < 0) {
if (rc == 0)
return (rc);
print_flags(f);
for (i = 0; i < argc; i++) {
switch (type) {
case TYPE_SID:
case TYPE_USID:
case TYPE_GSID:
case TYPE_WN:
case TYPE_WU:
case TYPE_WG:
case TYPE_UID:
case TYPE_GID:
case TYPE_PID:
case TYPE_UN:
case TYPE_UU:
case TYPE_UG:
int flag;
int type_from;
int type_to;
char *fromname;
char *toname;
if (argc == 0) {
if (init_command())
goto cleanup;
if (type_from <= 0) {
goto cleanup;
for (i = 0, type_to = 0;
if (!type_to) {
goto cleanup;
goto cleanup;
flag,
&info);
flag,
&info);
if (stat < 0) {
goto cleanup;
flag,
&uid,
&info,
&map_stat);
flag,
&gid,
&info,
&map_stat);
flag,
&info,
&map_stat);
flag,
&info,
&map_stat);
flag,
&info,
&map_stat);
if (stat < 0) {
goto cleanup;
if (stat < 0) {
goto cleanup;
goto errormsg;
goto errormsg;
goto errormsg;
if (map_stat < 0) {
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();