4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
30 #include <directory.h>
32 extern int sid_to_id(char *sid
, boolean_t user
, uid_t
*id
);
35 py_sid_to_id(PyObject
*self
, PyObject
*args
)
41 if (!PyArg_ParseTuple(args
, "si", &sid
, &isuser
))
44 err
= sid_to_id(sid
, isuser
, &id
);
46 PyErr_SetString(PyExc_KeyError
, sid
);
50 return (Py_BuildValue("I", id
));
54 * Translate the sid string ("S-1-...") to the user@domain name, if
58 py_sid_to_name(PyObject
*self
, PyObject
*args
)
60 int isuser
, err
, flag
= IDMAP_REQ_FLG_USE_CACHE
;
66 if (!PyArg_ParseTuple(args
, "si", &sid
, &isuser
))
69 err
= sid_to_id(sid
, isuser
, &pid
);
71 PyErr_SetString(PyExc_KeyError
, sid
);
75 stat
= idmap_getwinnamebyuid(pid
, flag
, &name
, NULL
);
77 stat
= idmap_getwinnamebygid(pid
, flag
, &name
, NULL
);
79 PyErr_SetString(PyExc_KeyError
, sid
);
84 PyErr_SetString(PyExc_KeyError
, sid
);
88 ret
= PyString_FromString(name
);
94 py_isglobalzone(PyObject
*self
, PyObject
*args
)
96 return (Py_BuildValue("i", getzoneid() == GLOBAL_ZONEID
));
100 py_gettext(PyObject
*self
, PyObject
*args
)
102 char *message
, *result
;
103 PyObject
*ret
= NULL
;
105 if (!PyArg_ParseTuple(args
, "s", &message
))
108 result
= dgettext(TEXT_DOMAIN
, message
);
110 ret
= Py_BuildValue("s", result
);
114 static PyMethodDef solarismethods
[] = {
115 {"sid_to_id", py_sid_to_id
, METH_VARARGS
, "Map SID to UID/GID."},
116 {"sid_to_name", py_sid_to_name
, METH_VARARGS
,
117 "Map SID to name@domain."},
118 {"isglobalzone", py_isglobalzone
, METH_NOARGS
,
119 "Determine if this is the global zone."},
120 {"gettext", py_gettext
, METH_VARARGS
, "Native call to gettext(3C)"},
121 {NULL
, NULL
, 0, NULL
}
127 PyObject
*solaris_misc
= Py_InitModule("solaris.misc", solarismethods
);