コード例 #1
0
NSS_STATUS _nss_registry_getspent_r (struct spwd *pw, char * buffer,
                                     size_t buflen,int * errnop)
{
    Key *tempkey;
    int usernamesize;
    char *username;
    NSS_STATUS tmpstatus;
    /* Hmm..I wonder if I should start it implicitly when this function is
     * called without setent */

    if(shadowks==NULL)
        return NSS_STATUS_UNAVAIL;
    if(shadowkey==NULL)
    {
        /* End of list */
        return NSS_STATUS_NOTFOUND;
    }
    usernamesize = keyGetBaseNameSize(shadowkey);
    username = (char *)malloc(usernamesize);
    keyGetBaseName(shadowkey, username, usernamesize);
    tmpstatus = _nss_registry_getspnam_r(username, pw, buffer, buflen, errnop);
    free(username);
    tempkey = shadowkey;
    shadowkey = tempkey->next;
    return tmpstatus;
}
コード例 #2
0
static void test_keyGetBaseName (const size_t storagePlugin, const char * tmpFile)
{
	Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
	open_storage_plugin (storagePlugin);
	Plugin * plugin = plugins[storagePlugin];

	KeySet * ks = metaTestKeySet ();
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");

	const char * name = "user/tests/storage/a";
	Key * found = ksLookupByName (ks, name, 0);
	succeed_if (found, "did not find key");

	const char * constBaseName = "a";
	size_t constBaseNameSize = elektraStrLen (constBaseName);
	ssize_t baseNameSize = keyGetFullNameSize (found);
	char * baseName = elektraMalloc (baseNameSize);
	ssize_t ret = keyGetBaseName (found, baseName, baseNameSize);
	if (ret < 1)
	{
		yield_error ("Key base name NULL or size error");
	}
	else
	{
		succeed_if ((size_t) ret == elektraStrLen (constBaseName), "Key base name has wrong size");
	}

	succeed_if (elektraStrNCmp (constBaseName, baseName, constBaseNameSize) == 0, "Key base name is wrong");

	elektraFree (baseName);
	keyDel (parentKey);
	ksDel (ks);
	closeStoragePlugin (storagePlugin);
}