summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: c4e28e5ed2afcd33d27491c21799a4d611a0d763 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#.
#.	DMI Decode Python Extension Module
#.
#.	(C) 2008 Nima Talebi <nima@it.net.au>
#.
#.	Licensed under the GNU Public License v2
#.

VERSION := 3.10.6
PY      := $(shell python -V 2>&1 |sed -e 's/.\(ython\) \(2\.[0-9]\)\..*/p\1\2/')
PY_VER  := $(subst python,,$(PY))
PACKAGE := python-dmidecode
SRCSRV  := /var/www/nima/sites/src.autonomy.net.au/pub

CC      := gcc
RM      := rm -f
SRC_D   := src
OBJ_D   := lib
CFLAGS   = -g -D_XOPEN_SOURCE=600
CFLAGS  += -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-align
CFLAGS  += -Wwrite-strings -Wmissing-prototypes -Winline -Wundef #-Wcast-qual
CFLAGS  += -pthread -fno-strict-aliasing -DNDEBUG -fPIC
CFLAGS  += -I/usr/include/$(PY)
CFLAGS  += -O3
#CFLAGS += -DNDEBUG
#CFLAGS += -DBIGENDIAN
#CFLAGS += -DALIGNMENT_WORKAROUND
#LDFLAGS = -lefence
LDFLAGS  =
SOFLAGS  = -pthread -shared -L/home/nima/dev-room/projects/dmidecode -lutil
SO       = build/lib.linux-$(shell uname -m)-$(PY_VER)/dmidecode.so

#. Search
vpath %.o $(OBJ_D)
vpath %.c $(SRC_D)
vpath %.h $(SRC_D)
vpath % $(OBJ_D)

ifeq (0,1)
TEMP:
	sudo make install
	sudo python -c 'import dmidecode; print "-"*80; print dmidecode.slot(); print "-"*80; print dmidecode.type(9)'
endif

###############################################################################
build: $(PY)-dmidecode.so
$(PY)-dmidecode.so: $(SO)
	cp $< $@

build: $(SO)
$(SO):
	$(PY) src/setup.py build

install:
	$(PY) src/setup.py install

uninstall:
	$(PY) src/setup.py uninstall

clean :
	dh_clean
	$(PY) src/setup.py clean
	-$(RM) *.so lib/*.o core
	-rm -rf build .dpkg
	cd unit-tests && $(MAKE) clean

tarball:
	rm -rf $(PACKAGE)-$(VERSION)
	mkdir $(PACKAGE)-$(VERSION)
	cp -r contrib doc examples lib Makefile man README src  $(PACKAGE)-$(VERSION)
	tar -czvf  $(PACKAGE)-$(VERSION).tar.gz  $(PACKAGE)-$(VERSION)

rpm:	tarball
	rm -rf rpm
	mkdir -p rpm/{BUILD,RPMS,SRPMS,SPECS,SOURCES}
	cp contrib/$(PACKAGE).spec rpm/SPECS
	cp $(PACKAGE)-$(VERSION).tar.gz rpm/SOURCES
	rpmbuild -ba --define "_topdir $(shell pwd)/rpm" rpm/SPECS/$(PACKAGE).spec

unit:
	cd unit-tests && $(MAKE)

###############################################################################
libdmidecode.so: dmihelper.o util.o dmioem.o dmidecode.o dmidecodemodule.o
	$(CC) $(LDFLAGS) $(SOFLAGS) $^ -o $@

$(OBJ_D)/dmidecodemodule.o: dmidecodemodule.c
	$(CC) $(CFLAGS) -c -o $@ $<

$(OBJ_D)/dmidecode.o: dmidecode.c version.h types.h util.h config.h dmidecode.h dmioem.h
	$(CC) $(CFLAGS) -c -o $@ $<

$(OBJ_D)/dmihelper.o: dmihelper.c dmihelper.h
	$(CC) $(CFLAGS) -c -o $@ $<

$(OBJ_D)/util.o: util.c types.h util.h config.h
	$(CC) $(CFLAGS) -c -o $@ $<

$(OBJ_D)/dmioem.o: dmioem.c types.h dmidecode.h dmioem.h
	$(CC) $(CFLAGS) -c -o $@ $<



###############################################################################
.PHONY: install clean uninstall build dupload
.PHONY: srcsrv binary source orig.tar.gz all
n> sysdb_ctx *sysdb; }; /* Returns EOK and populates groupname if * the group_dn is actually a group. * Returns ENOENT if group_dn does not point * at a a group. * Returns EINVAL if there is a parsing error. * Returns ENOMEM as appropriate */ errno_t get_ipa_groupname(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb, const char *group_dn, const char **groupname) { errno_t ret; struct ldb_dn *dn; const char *rdn_name; const char *group_comp_name; const char *account_comp_name; const struct ldb_val *rdn_val; const struct ldb_val *group_comp_val; const struct ldb_val *account_comp_val; /* This is an IPA-specific hack. It may not * work for non-IPA servers and will need to * be changed if SSSD ever supports HBAC on * a non-IPA server. */ *groupname = NULL; dn = ldb_dn_new(mem_ctx, sysdb_ctx_get_ldb(sysdb), group_dn); if (dn == NULL) { ret = ENOMEM; goto done; } if (!ldb_dn_validate(dn)) { ret = EINVAL; goto done; } if (ldb_dn_get_comp_num(dn) < 4) { /* RDN, groups, accounts, and at least one DC= */ /* If it's fewer, it's not a group DN */ ret = ENOENT; goto done; } /* If the RDN name is 'cn' */ rdn_name = ldb_dn_get_rdn_name(dn); if (rdn_name == NULL) { /* Shouldn't happen if ldb_dn_validate() * passed, but we'll be careful. */ ret = EINVAL; goto done; } if (strcasecmp("cn", rdn_name) != 0) { /* RDN has the wrong attribute name. * It's not a group. */ ret = ENOENT; goto done; } /* and the second component is "cn=groups" */ group_comp_name = ldb_dn_get_component_name(dn, 1); if (strcasecmp("cn", group_comp_name) != 0) { /* The second component name is not "cn" */ ret = ENOENT; goto done; } group_comp_val = ldb_dn_get_component_val(dn, 1); if (strncasecmp("groups", (const char *) group_comp_val->data, group_comp_val->length) != 0) { /* The second component value is not "groups" */ ret = ENOENT; goto done; } /* and the third component is "accounts" */ account_comp_name = ldb_dn_get_component_name(dn, 2); if (strcasecmp("cn", account_comp_name) != 0) { /* The third component name is not "cn" */ ret = ENOENT; goto done; } account_comp_val = ldb_dn_get_component_val(dn, 2); if (strncasecmp("accounts", (const char *) account_comp_val->data, account_comp_val->length) != 0) { /* The third component value is not "accounts" */ ret = ENOENT; goto done; } /* Then the value of the RDN is the group name */ rdn_val = ldb_dn_get_rdn_val(dn); *groupname = talloc_strndup(mem_ctx, (const char *)rdn_val->data, rdn_val->length); if (*groupname == NULL) { ret = ENOMEM; goto done; } ret = EOK; done: talloc_free(dn); return ret; } errno_t hbac_user_attrs_to_rule(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb, const char *rule_name, struct sysdb_attrs *rule_attrs, struct hbac_rule_element **users) { errno_t ret; TALLOC_CTX *tmp_ctx = NULL; struct hbac_rule_element *new_users = NULL; struct ldb_message_element *el = NULL; struct ldb_message **msgs = NULL; char *filter; char *member_dn; const char *member_user; const char *attrs[] = { SYSDB_NAME, NULL }; size_t num_users = 0; size_t num_groups = 0; const char *name; size_t count; size_t i; tmp_ctx = talloc_new(mem_ctx); if (tmp_ctx == NULL) return ENOMEM; new_users = talloc_zero(tmp_ctx, struct hbac_rule_element); if (new_users == NULL) { ret = ENOMEM; goto done; } DEBUG(7, ("Processing users for rule [%s]\n", rule_name)); ret = hbac_get_category(rule_attrs, IPA_USER_CATEGORY, &new_users->category); if (ret != EOK) { DEBUG(1, ("Could not identify user categories\n")); goto done; } if (new_users->category & HBAC_CATEGORY_ALL) { /* Short-cut to the exit */ ret = EOK; goto done; } ret = sysdb_attrs_get_el(rule_attrs, IPA_MEMBER_USER, &el); if (ret != EOK && ret != ENOENT) { DEBUG(1, ("sysdb_attrs_get_el failed.\n")); goto done; } if (ret == ENOENT || el->num_values == 0) { el->num_values = 0; DEBUG(4, ("No user specified, rule will never apply.\n")); } new_users->names = talloc_array(new_users, const char *, el->num_values + 1); if (new_users->names == NULL) { ret = ENOMEM; goto done; } new_users->groups = talloc_array(new_users, const char *, el->num_values + 1); if (new_users->groups == NULL) { ret = ENOMEM; goto done; } for (i = 0; i < el->num_values; i++) { member_user = (const char *)el->values[i].data; ret = sss_filter_sanitize(tmp_ctx, member_user, &member_dn); if (ret != EOK) goto done; filter = talloc_asprintf(member_dn, "(%s=%s)", SYSDB_ORIG_DN, member_dn); if (filter == NULL) { ret = ENOMEM; goto done; } /* First check if this is a user */ ret = sysdb_search_users(tmp_ctx, sysdb, filter, attrs, &count, &msgs); if (ret != EOK && ret != ENOENT) goto done; if (ret == EOK && count == 0) { ret = ENOENT; } if (ret == EOK) { if (count > 1) { DEBUG(1, ("Original DN matched multiple users. Skipping \n")); talloc_zfree(member_dn); continue; } /* Original DN matched a single user. Get the username */ name = ldb_msg_find_attr_as_string(msgs[0], SYSDB_NAME, NULL); if (name == NULL) { DEBUG(1, ("Attribute is missing!\n")); ret = EFAULT; goto done; } new_users->names[num_users] = talloc_strdup(new_users->names, name); if (new_users->names[num_users] == NULL) { ret = ENOMEM; goto done; } DEBUG(8, ("Added user [%s] to rule [%s]\n", name, rule_name)); num_users++;