Methods to do various operations on Key metainfo.
int keyStat (Key *key)
int keyRemove (Key *key)
uid_t keyGetUID (const Key *key)
int keySetUID (Key *key, uid_t uid)
gid_t keyGetGID (const Key *key)
int keySetGID (Key *key, gid_t gid)
int keySetDir (Key *key)
mode_t keyGetMode (const Key *key)
int keySetMode (Key *key, mode_t mode)
type_t keyGetType (const Key *key)
int keySetType (Key *key, type_t newType)
time_t keyGetATime (const Key *key)
int keySetATime (Key *key, time_t atime)
time_t keyGetMTime (const Key *key)
int keySetMTime (Key *key, time_t mtime)
time_t keyGetCTime (const Key *key)
int keySetCTime (Key *key, time_t ctime)
Methods to do various operations on Key metainfo.
To use them:
#include <kdb.h>
Next to Name (key and owner) and Value (data and comment) there is the so called metainfo inside every key.
Key metainfo insists of:
The comment can contain userdata which directly belong to that key.
Owner is the user that owns the key. It only works for the user/ hierarchy.
Every user and group of your System has a uniqe ID. These values are used in the keys too. They are very important for the mode. See man 2 chown.
With the mode mode you can choose if a user, group or the world can mode your key. See man 2 chmod.
Every kdbGet() might update the access time of a key. You get information when the key was read the last time from the database.
You will get 0 when the key was not read already.
Beware that multiple copies of keys with keyDup() might have different atimes because you kdbGet() one, but not the other. You can use this information to decide which key is the latest.
Parameters:
Returns:
0 on key that was never kdbGet()
(time_t)-1 on NULL pointer
See also:
kdbGet()
You will get 0 when the key was not read already.
Any changed field in metadata will influence the ctime of a key.
This time is not updated if only value or comment are changed.
Not changed keys will not update this time, even after kdbSet().
It is possible that other keys written to disc influence this time if the backend is not grained enough.
Parameters:
See also:
Returns:
the metadata change time
The group ID is a unique identification for every group present on a system. Keys will belong to root (0) as long as you did not get their real GID with kdbGet().
Unlike UID users might change their group. This makes it possible to share configuration between some users.
A fresh key will have (gid_t)-1 also known as the group nogroup. It means that the key is not related to a group ID at the moment.
Parameters:
Returns:
(gid_t)-1 on NULL key or currently unknown ID
See also:
Default is 0664 (octal) for keys and 0775 for directory keys which used keySetDir().
The defaults are defined with the macros KEY_DEF_MODE and KEY_DEF_DIR.
For more information about the mode permissions see Mode.
Parameters:
Returns:
(mode_t)-1 on NULL pointer
See also:
You will get 0 when the key was not read already.
Everytime you change value or comment and kdbSet() the key the mtime will be updated. When you kdbGet() the key, the atime is set appropriate.
Not changed keys may not even passed to kdbSet_backend() so it will not update this time, even after kdbSet().
It is possible that other keys written to disc influence this time if the backend is not grained enough.
If you add or remove a key the key thereunder in the hierarchy will update the mtime if written with kdbSet() to disc.
Parameters:
See also:
Returns:
(time_t)-1 on NULL pointer
See type_t for the type definition.
See also:
keyIsBinary() and keyIsString()
keyIsDir() is not related to the type system
Parameters:
Returns:
KEY_TYPE_UNDEFINED on keys without type
-1 on NULL pointer
The user ID is a unique identification for every user present on a system. Keys will belong to root (0) as long as you did not get their real UID with kdbGet().
Although usually the same, the UID of a key is not related to its owner.
A fresh key will have (uid_t)-1 also known as the user nobody. It means that the key is not related to a user ID at the moment.
Parameters:
Returns:
(uid_t)-1 on NULL key or currently unknown ID
See also:
This functions sets a flag that the key needs to be removed. It also sets a flag that it is not synced.
Remove the key instead of writing it in the key database when doing kdbSet() and related functions.
This key will be ignored and it is save to delete it afterwards. To be sure that it was removed, check if it needs sync with keyNeedSync().
Note:
Warning:
See also:
Parameters:
Returns:
-1 on NULL pointer
When you do manual sync of keys you might also update the atime to make them indistinguishable.
It can also be useful if you work with keys not using a keydatabase.
Parameters:
Returns:
-1 on NULL pointer
See also:
Parameters:
Returns:
-1 on NULL pointer
See also:
The function will add all executable bits.
The macro KEY_DEF_DIR (defined to 0111) will be used for that.
The executable bits show that child keys are allowed and listable. There is no way to have child keys which are not listable for anyone, but it is possible to restrict listing the keys to the owner only.
For more about mode see keySetMode().
It is not possible to access keys below a not executable key. If a key is not writeable and executable kdbSet() will fail to access the keys below. If a key is not readable and executable kdbGet() will fail to access the keys below.
Parameters:
Returns:
-1 on NULL pointer
See also:
See GID for more information about group IDs.
Parameters:
Returns:
-1 on NULL key
See also:
The mode consists of 9 individual bits for mode permissions. In the following explanation the octal notation with leading zero will be used.
Default is 0664 (octal) for keys and 0775 for directory keys which used keySetDir().
The defaults are defined with the macros KEY_DEF_MODE and KEY_DEF_DIR.
Note:
0000 is the most restrictive mode. No user might read, write or execute the key.
Reading the key means to get the value and comment by kdbGet() or all highlevel methods.
Writing the key means to set the value and comment by kdbSet() or all highlevel methods.
Execute the key means to make a step deeper in the hierarchy. But you must be able to read the key to be able to list the keys below. See also keySetDir() in that context. But you must be able to write the key to be able to add or remove keys below.
0777 is the most relaxing mode. Every user is allowed to read, write and execute the key, if he is allowed to execute and read all keys below.
0700 allows every action for the current user, identified by the uid. See keyGetUID() and keySetUID().
To be more specific for the user the single bits can elect the mode for read, write and execute. 0100 only allows executing which gives the information that it is a directory for that user, but not accessible. 0200 only allows reading. This information may be combined to 0300, which allows execute and reading of the directory. Last 0400 decides about the writing permissions.
The same as above is also valid for the 2 other octal digits. 0070 decides about the group permissions, in that case full access. Groups are identified by the gid. See keyGetGID() and keySetGID(). In that example everyone with a different uid, but the gid of the the key, has full access.
0007 decides about the world permissions. This is taken into account when neighter the uid nor the gid matches. So that example would allow everyone with a different uid and gid of that key gains full access.
Parameters:
Returns:
-1 on NULL key
See also:
Parameters:
Returns:
See also:
This method is usually not needed, unless you are working with more semantic value types, or want to force a specific value type for a key. It is not usually needed because the data type is automatically set when setting the key value.
See type_t for the type defintion.
Example:
// here we define the new type
enum
{
KEY_TYPE_COLOR=KEY_TYPE_STRING+4
};
// here we make a new key with the type
Key *k1 = keyNew ('user/sw/oyranos/current/color1',
KEY_VALUE, '#4B52CA',
KEY_COMMENT, 'a custom color',
KEY_TYPE, KEY_TYPE_COLOR,
KEY_END);
// lets check if it is really correct type
if (keyGetType(k1) == KEY_TYPE_COLOR) printf ('correct type');
When using type_t::KEY_TYPE_DIR, this method will not set mode permissions to the key. You'll have to set it manually after keySetType(), calling keySetMode() with appropriate permissions. Or use the keySetDir().
See also:
keySetDir() to see that the directory concept is independent of types
Parameters:
Returns:
-1 on NULL pointer and when newType >= KEY_TYPE_MAX
See UID for more information about user IDs.
Parameters:
Returns:
-1 on NULL key
See also:
Only stat the key in the database when doing kdbGet(). The key may not have any value, comment or key type set.
It is not possible to revert the action on per-key basis. When you want to remove the flag you have to pass option_t::KDB_O_NOSTAT to the next kdbGet().
See also:
Parameters:
Returns:
-1 on NULL pointer
Generated automatically by Doxygen for Elektra Projekt from the source code.