1
/* Copyright (C) 2000-2002, 2004, 2005, 2006 Red Hat, Inc.
1
/* Copyright (C) 2000-2002, 2004, 2005, 2006, 2007 Red Hat, Inc.
3
3
* This is free software; you can redistribute it and/or modify it under
4
4
* the terms of the GNU Library General Public License as published by
802
799
struct lu_module *module;
803
800
gpointer scratch;
806
802
gboolean tsuccess;
808
804
value = g_value_array_get_nth(list, i);
809
name = g_value_dup_string(value);
810
module = g_tree_lookup(context->modules, name);
805
module = g_tree_lookup(context->modules,
806
g_value_get_string(value));
812
807
g_assert(module != NULL);
814
809
tsuccess = run_single(context, module, id,
1426
1421
ret = lu_dispatch(context, user_setpass, tmp, LU_VALUE_INVALID_ID,
1427
1422
ent, NULL, error);
1430
1425
ret = lu_refresh_user(context, ent, error);
1434
lu_ent_clear(ent, LU_SHADOWLASTCHANGE);
1435
memset(&value, 0, sizeof(value));
1436
g_value_init(&value, G_TYPE_STRING);
1437
g_value_set_string(&value,
1438
lu_util_shadow_current_date(ent->cache));
1439
lu_ent_add(ent, LU_SHADOWLASTCHANGE, &value);
1440
g_value_unset(&value);
1427
lu_util_update_shadow_last_change(ent);
1428
ret = lu_user_modify(context, ent, error);
1455
1443
ret = lu_dispatch(context, user_removepass, NULL, LU_VALUE_INVALID_ID,
1456
1444
ent, NULL, error);
1458
1446
ret = lu_refresh_user(context, ent, error);
1462
lu_ent_clear(ent, LU_SHADOWLASTCHANGE);
1463
memset(&value, 0, sizeof(value));
1464
g_value_init(&value, G_TYPE_STRING);
1465
g_value_set_string(&value,
1466
lu_util_shadow_current_date(ent->cache));
1467
lu_ent_add(ent, LU_SHADOWLASTCHANGE, &value);
1468
g_value_unset(&value);
1448
lu_util_update_shadow_last_change(ent);
1449
ret = lu_user_modify(context, ent, error);
1545
1526
ret = lu_dispatch(context, group_setpass, tmp, LU_VALUE_INVALID_ID,
1546
1527
ent, NULL, error);
1549
1530
ret = lu_refresh_group(context, ent, error);
1553
lu_ent_clear(ent, LU_SHADOWLASTCHANGE);
1554
memset(&value, 0, sizeof(value));
1555
g_value_init(&value, G_TYPE_STRING);
1556
g_value_set_string(&value,
1557
lu_util_shadow_current_date(ent->cache));
1558
lu_ent_add(ent, LU_SHADOWLASTCHANGE, &value);
1559
g_value_unset(&value);
1574
1544
ret = lu_dispatch(context, group_removepass, NULL, LU_VALUE_INVALID_ID,
1575
1545
ent, NULL, error);
1577
1547
ret = lu_refresh_group(context, ent, error);
1581
lu_ent_clear(ent, LU_SHADOWLASTCHANGE);
1582
memset(&value, 0, sizeof(value));
1583
g_value_init(&value, G_TYPE_STRING);
1584
g_value_set_string(&value,
1585
lu_util_shadow_current_date(ent->cache));
1586
lu_ent_add(ent, LU_SHADOWLASTCHANGE, &value);
1587
g_value_unset(&value);
1712
/* Replace all instances of OLD in g_malloc()'ed STRING by NEW. */
1714
replace_all(char *string, const char *old, const char *new)
1718
pos = strstr(string, old);
1722
old_len = strlen(old);
1726
prefix = g_strndup(string, pos - string);
1727
p = g_strconcat(prefix, new, pos + old_len, NULL);
1731
pos = strstr(string, old);
1732
} while (pos != NULL);
1753
1737
static gboolean
1754
1738
lu_default_int(struct lu_context *context, const char *name,
1755
1739
enum lu_entity_type type, gboolean is_system, struct lu_ent *ent)
1820
1804
if (is_system) {
1823
cfgkey = g_strdup_printf("%s/%s", top, idkey);
1807
cfgkey = g_strconcat(top, "/", idkey, (const gchar *)NULL);
1824
1808
val = lu_cfg_read_single(context, cfgkey, NULL);
1825
1809
g_free(cfgkey);
1826
1810
if (val == NULL) {
1827
cfgkey = g_strdup_printf("%s/%s", top, idkeystring);
1811
cfgkey = g_strconcat(top, "/", idkeystring,
1812
(const gchar *)NULL);
1828
1813
val = lu_cfg_read_single(context, cfgkey, NULL);
1829
1814
g_free(cfgkey);
1891
1876
{LU_EMAIL, G_STRINGIFY_ARG(LU_EMAIL)},
1879
char *tmp, replacement[sizeof (intmax_t) * CHAR_BIT + 1];
1896
1880
const char *key;
1902
{"%d", lu_util_shadow_current_date(context->scache)},
1903
/* Must be index 2, see below! */
1904
{"%u", NULL} /* value set later */
1907
1883
/* Possibly map the key to an internal name. */
1922
1898
/* Generate the key and read the value for the item. */
1923
cfgkey = g_strdup_printf("%s/%s", top, (const char *)p->data);
1899
cfgkey = g_strconcat(top, "/", (const gchar *)p->data,
1900
(const gchar *)NULL);
1924
1901
val = lu_cfg_read_single(context, cfgkey, NULL);
1927
1903
/* Create a copy of the value to mess with. */
1928
1904
g_assert(val != NULL);
1929
1905
tmp = g_strdup(val);
1931
subst[2].value = g_strdup_printf("%jd", (intmax_t)id);
1932
/* Perform substitutions. */
1933
for (i = 0; i < G_N_ELEMENTS(subst); i++) {
1934
while (strstr(tmp, subst[i].format) != NULL) {
1935
char *pre, *post, *tmp2, *where;
1907
tmp = replace_all(tmp, "%n", name);
1908
sprintf(replacement, "%ld", lu_util_shadow_current_date());
1909
tmp = replace_all(tmp, "%d", replacement);
1910
sprintf(replacement, "%jd", (intmax_t)id);
1911
tmp = replace_all(tmp, "%u", replacement);
1937
where = strstr(tmp, subst[i].format);
1938
pre = g_strndup(tmp, where - tmp);
1939
post = g_strdup(where +
1940
strlen(subst[i].format));
1941
tmp2 = g_strconcat(pre,
1913
ok = lu_value_init_set_attr_from_string(&value, key, tmp,
1916
if (error == NULL) {
1917
/* Whatever this attribute is, default to a
1919
g_value_init(&value, G_TYPE_STRING);
1920
g_value_set_string(&value, tmp);
1923
g_warning(_("Invalid default value of field "
1925
lu_strerror(error));
1926
lu_error_free(&error);
1951
g_free((char *)subst[2].value);
1953
/* Check if we can represent this value as a number. */
1955
imax = strtoimax(tmp, &end, 10);
1956
if (errno == 0 && *end == 0 && end != tmp
1957
&& (long)imax == imax) {
1958
g_value_init(&value, G_TYPE_LONG);
1959
g_value_set_long(&value, imax);
1960
} else if (errno == 0 && *end == 0 && end != tmp
1961
&& (id_t)imax == imax)
1962
lu_value_init_set_id(&value, imax);
1964
g_value_init(&value, G_TYPE_STRING);
1965
g_value_set_string(&value, tmp);
1969
/* Add the transformed value. */
1970
lu_ent_clear(ent, key);
1971
lu_ent_add(ent, key, &value);
1972
g_value_unset(&value);
1933
/* Add the transformed value. */
1934
lu_ent_clear(ent, key);
1935
lu_ent_add(ent, key, &value);
1936
g_value_unset(&value);
1974
1939
if (keys != NULL) {
1975
1940
g_list_free(keys);