int xp_user_add(Xpnodeset *nds, char *adminkey, char *uname, uid_t uid, char *gname, char *ukey) { Xcmd *addcmd; Spstr *cmd; char *qkey; if (!nds) return -1; cmd = sp_malloc(sizeof(*cmd)); cmd->len = 4096; cmd->str = sp_malloc(cmd->len); qkey = quotestrdup(ukey); snprintf(cmd->str, cmd->len, "user-add %s %d %s %s\n", uname, uid, gname, qkey); free(qkey); addcmd = xcmd_init(cmd, adminkey); if (!addcmd) goto error; if (xp_nodeset_iterate(nds, xp_ctl_cmd, addcmd) > 0) goto error; xcmd_destroy(addcmd); return 0; error: if (addcmd) xcmd_destroy(addcmd); xp_nodeerror_print("xp_user_add"); return -1; }
void do_expand(char* expanded, char* key) // Search for environment var `key` and append it to the `expanded` string { // If `key` is not an empty string do the expansion, else do nothing if(key[0]) { // Get the environment variable and do the expansion if it exists char* env = getenv(key); if(env) { char* quote = quotestrdup(env); free(env); strcat(expanded, quote); free(quote); } // else // { // strcat(expanded, "$"); // strcat(expanded, key); // } } }