Exemplo n.º 1
0
//--------------------------------------------------------------------------------------------------
LE_SHARED void cfgInstall_Add
(
    const char* appName
)
//--------------------------------------------------------------------------------------------------
{
    le_result_t result;

    char filePath[256] = "/opt/legato/apps/";

    result = le_utf8_Append(filePath, appName, sizeof(filePath), NULL);
    LE_FATAL_IF(result != LE_OK, "App name '%s' is too long.", appName);

    result = le_utf8_Append(filePath, "/root.cfg", sizeof(filePath), NULL);
    LE_FATAL_IF(result != LE_OK, "App name '%s' is too long.", appName);

    LE_INFO("Importing configuration for application '%s' from '%s'.", appName, filePath);

    le_cfg_IteratorRef_t i = le_cfg_CreateWriteTxn("/apps");

    result = le_cfgAdmin_ImportTree(i, filePath, appName);

    LE_FATAL_IF(result != LE_OK,
                "Failed to import configuration from '%s' to 'root:/apps/%s' (%s)",
                filePath,
                appName,
                LE_RESULT_TXT(result));

    le_cfg_CommitTxn(i);
}
Exemplo n.º 2
0
//--------------------------------------------------------------------------------------------------
void userAddRemove_Add
(
    const char* appName
)
//--------------------------------------------------------------------------------------------------
{
    le_result_t result;
    uid_t uid;
    gid_t gid;

    char userName[256] = "app";

    result = le_utf8_Append(userName, appName, sizeof(userName), NULL);
    LE_FATAL_IF(result != LE_OK, "App name '%s' is too long.", appName);

    LE_INFO("Creating user '%s' for application '%s'.", userName, appName);

    // Start a read transaction and go to node /apps/app-name
    le_cfg_ConnectService();
    le_cfg_IteratorRef_t i = le_cfg_CreateReadTxn("/apps");
    le_cfg_GoToNode(i, appName);

    // If the node doesn't exist, bail out.
    if (!le_cfg_NodeExists(i, ""))
    {
        fprintf(stderr, "** ERROR: App '%s' doesn't exist in the system configuration.\n", appName);
    }
    else
    {
        result = user_Create(userName, &uid, &gid);

        if (result == LE_OK)
        {
            printf("Created user '%s' (uid %u, gid %u).\n", userName, uid, gid);

            // TODO: Groups configuration.

            le_cfg_CancelTxn(i);

            exit(EXIT_SUCCESS);
        }
        else if (result == LE_DUPLICATE)
        {
            // TODO: Verify correct groups configuration.

            printf("User '%s' already exists (uid %u, gid %u).\n", userName, uid, gid);

            le_cfg_CancelTxn(i);

            exit(EXIT_SUCCESS);
        }
        else
        {
            fprintf(stderr, "** ERROR: user_Create() failed for user '%s'.\n", userName);
        }
    }

    le_cfg_CancelTxn(i);
    exit(EXIT_FAILURE);
}
Exemplo n.º 3
0
//--------------------------------------------------------------------------------------------------
static void AppendToCommand
(
    le_msg_MessageRef_t msgRef, ///< Command message to which the text should be appended.
    const char* textPtr         ///< Text to append to the message.
)
{
    if (LE_OVERFLOW == le_utf8_Append(le_msg_GetPayloadPtr(msgRef),
                                      textPtr,
                                      le_msg_GetMaxPayloadSize(msgRef),
                                      NULL) )
    {
        ExitWithErrorMsg("Command string is too long.");
    }
}
Exemplo n.º 4
0
//--------------------------------------------------------------------------------------------------
static inline void SafeStrAppend
(
    char        *destBufferPtr,         ///< [IN]  Buffer to append to.
    size_t       destBufferSize,        ///< [IN]  Buffer size.
    size_t      *currentDestStrLenPtr,  ///< [OUT] Length of resulting string.
    const char  *appendStrPtr           ///< [IN]  String to append to buffer.
)
{
    le_result_t result = le_utf8_Append(destBufferPtr, appendStrPtr, destBufferSize,
                            currentDestStrLenPtr);
    if (result != LE_OK)
    {
        LE_WARN("Error appending to string: %s", LE_RESULT_TXT(result));
    }
}
Exemplo n.º 5
0
//--------------------------------------------------------------------------------------------------
static le_result_t GetAppUid
(
    le_cfg_IteratorRef_t i, ///< [in] Configuration tree iterator.
    uid_t*          uidPtr  ///< [out] Pointer to where the user ID will be put if successful.
)
//--------------------------------------------------------------------------------------------------
{
    le_result_t result;

    char appName[LIMIT_MAX_APP_NAME_BYTES];
    result = le_cfg_GetNodeName(i, "", appName, sizeof(appName));
    if (result != LE_OK)
    {
        LE_CRIT("Configuration node name too long under 'system/apps/'.");
        return LE_OVERFLOW;
    }

    // If this is an "unsandboxed" app, use the root user ID.
    if (le_cfg_GetBool(i, "sandboxed", true) == false)
    {
        char path[256];
        le_cfg_GetPath(i, "", path, sizeof(path));
        LE_DEBUG("'%s' = <root>", path);

        *uidPtr = 0;
        return LE_OK;
    }

    // Convert the app name into a user name by prefixing it with "app".
    char userName[LIMIT_MAX_USER_NAME_BYTES] = "app";
    result = le_utf8_Append(userName, appName, sizeof(userName), NULL);
    if (result != LE_OK)
    {
        LE_CRIT("Failed to convert app name into user name.");
        return LE_OVERFLOW;
    }

    // Convert the app user name into a user ID.
    result = user_GetUid(userName, uidPtr);
    if (result != LE_OK)
    {
        LE_CRIT("Failed to get user ID for user '%s'. (%s)", userName, LE_RESULT_TXT(result));
        return LE_NOT_FOUND;
    }

    return LE_OK;
}
Exemplo n.º 6
0
//--------------------------------------------------------------------------------------------------
void userAddRemove_Remove
(
    const char* appName
)
//--------------------------------------------------------------------------------------------------
{
    le_result_t result;

    char userName[256] = "app";

    result = le_utf8_Append(userName, appName, sizeof(userName), NULL);
    LE_FATAL_IF(result != LE_OK, "App name '%s' is too long.", appName);

    LE_INFO("Deleting user '%s' for application '%s'.",
            userName,
            appName);

    result = user_Delete(userName);

    if (result == LE_OK)
    {
        printf("Deleted user '%s'.\n", userName);

        // TODO: Remove from supplementary groups.

        exit(EXIT_SUCCESS);
    }
    else if (result == LE_NOT_FOUND)
    {
        // TODO: Verify groups have been cleaned of this user.

        printf("User '%s' doesn't exist.\n", userName);

        exit(EXIT_SUCCESS);
    }
    else
    {
        fprintf(stderr,
                "** ERROR: user_Delete() failed for user '%s'.\n",
                userName);
    }

    exit(EXIT_FAILURE);
}