/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#include <fcntl.h>
#include <unistd.h>
#include <elf.h>
#include <gelf.h>
#include <liblist.h>
#include <elfextract.h>
#include <Python.h>
/*
* When getting information about ELF files, sometimes we want to decide
* which types of hash we want to calculate. This structure is used to
* return information from arg parsing Python method arguments.
*
* 'fd' the file descriptor of an ELF file
* 'elfhash' an integer > 0 if we should calculate the old elfhash
* 'sha256' an integer > 0 if we should calculate an SHA-256 hash
* 'sha512t_256' an integer > 0 if we should calculate an SHA-512t_256 hash
*/
typedef struct
{
int fd;
int elfhash;
int sha256;
int sha512t_256;
} hargs_t;
static int
{
int rval;
char *str;
return (-1);
}
return (rval);
}
static int
{
char *str;
pverlist = PyList_New(0);
dyn) == -1) {
goto out;
}
goto out;
}
goto out;
}
out:
return (rval);
}
static int
{
int rval;
char *str;
return (-1);
}
return (rval);
}
/*
* Open a file named by python, setting an appropriate error on failure.
*/
static int
{
int fd;
char *f;
return (-1);
}
return (-1);
}
return (fd);
}
static hargs_t
{
char *f;
int get_sha512t_256 = 0;
/*
* By default, we always get SHA-256 hashes with and without
* the signature sections. Optionally, we get 256-bit
* truncated SHA-512 hashes in addition to or instead of
* 256-bit.
*
* The old-style calculation of elfhash will be dropped, but
* for now, we continue to default to also retrieving it.
*/
return (hargs);
}
return (hargs);
}
return (hargs);
}
/*
* For ELF operations: Need to check if a file is an ELF object.
*/
/*ARGSUSED*/
static PyObject *
{
return (NULL);
}
if (ret == -1) {
return (NULL);
}
}
/*
* Returns information about the ELF file in a dictionary
* of the following format:
*
* {
* type: exe|so|core|rel,
* bits: 32|64,
* arch: sparc|x86|ppc|other|none,
* end: lsb|msb,
* osabi: none|linux|solaris|other
* }
*
* XXX: I have yet to find a binary with osabi set to something
* aside from "none."
*/
/*ARGSUSED*/
static PyObject *
{
int fd;
return (NULL);
}
goto out;
}
{ \
int rval; \
goto err; \
} \
if (rval == -1) { \
goto err; \
} \
}
pdict = PyDict_New();
out:
}
return (pdict);
err:
goto out;
}
/*
* Returns a dictionary with the requested hash(es).
*
* Dictionary format:
*
* {
* elfhash: "sha1hash",
* }
*
* If a hash was not requested, it is omitted from the dictionary.
*
*/
/*ARGSUSED*/
static PyObject *
{
hashinfo_t *h = NULL;
return (NULL);
}
goto out;
}
goto out;
}
/*
* From here forward, error exits from get_hashes() should
* jump to label err instead of label out.
*/
goto err;
}
}
plist = PyList_New(0);
goto err;
}
}
if (hargs.sha512t_256 > 0) {
goto err;
}
goto err;
}
}
goto err;
}
goto err;
}
}
out:
if (h != NULL) {
free(h);
}
return (pdict);
err:
goto out;
}
/*
* Returns a dictionary with the relevant information.
*
* Dictionary format:
*
* {
* runpath: "/path:/entries",
* defs: ["version", ... ],
* deps: [["file", ["versionlist"]], ...],
* }
*
* If any item is empty or has no value, it is omitted from the
* dictionary.
*
* XXX: Currently, defs contains some duplicate entries. There
* may be meaning attached to this, or it may just be something
* worth trimming out at this stage or above.
*
*/
/*ARGSUSED*/
static PyObject *
{
int i;
int fd;
if (fd < 0) {
return (NULL);
}
goto out;
}
goto out;
}
goto err;
}
if (liblist_foreach(
goto err;
}
goto err;
}
}
char *str;
goto err;
if (liblist_foreach(
goto err;
}
goto err;
}
if ((str = elf_strptr(
goto err;
}
goto err;
}
}
char *str;
if ((str = elf_strptr(
goto err;
}
goto err;
}
}
out:
}
return (pdict);
err:
goto out;
}
};
#if PY_MAJOR_VERSION >= 3
"elf",
NULL,
-1,
};
#endif
static PyObject *
moduleinit(void)
{
PyObject *m;
#if PY_MAJOR_VERSION >= 3
#else
#endif
return (NULL);
}
return (NULL);
}
return (m);
}
#if PY_MAJOR_VERSION >= 3
PyInit_elf(void)
{
return (moduleinit());
}
#else
initelf(void)
{
moduleinit();
}
#endif