* use getpwent_r
authorWilfried Göesgens <willi@citadel.org>
Sat, 20 Jan 2007 19:25:23 +0000 (19:25 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 20 Jan 2007 19:25:23 +0000 (19:25 +0000)
* tag the message valid. thanks IG for the how to change.

citadel/msgbase.c
citadel/server_main.c

index badbc8f7cc351e2bf6ab01e3e127289ba8285414..5442bcfcede9a983241a9b4a543d20801dc9d364 100644 (file)
@@ -742,6 +742,9 @@ void cmd_msgs(char *cmdbuf)
                template = (struct CtdlMessage *)
                        malloc(sizeof(struct CtdlMessage));
                memset(template, 0, sizeof(struct CtdlMessage));
+               template->cm_magic = CTDLMESSAGE_MAGIC;
+               template->cm_anon_type = MES_NORMAL;
+
                while(client_getln(buf, sizeof buf), strcmp(buf,"000")) {
                        extract_token(tfield, buf, 0, '|', sizeof tfield);
                        extract_token(tvalue, buf, 1, '|', sizeof tvalue);
index 3fb00e3c706b54caa96bbcd09ed88177b9f56dce..c46f80a37b0919bd21923156471b847533db5811 100644 (file)
@@ -74,7 +74,8 @@ int main(int argc, char **argv)
 {
        char facility[32];
        int a, i;                       /* General-purpose variables */
-       struct passwd *pw;
+       struct passwd pw, *pwp = NULL;
+       char pwbuf[SIZ];
        int drop_root_perms = 1;
        size_t size;
        int relh=0;
@@ -195,10 +196,9 @@ int main(int argc, char **argv)
        /* on some dists rundir gets purged on startup. so we need to recreate it. */
 
        if (stat(ctdl_run_dir, &filestats)==-1){
-               pw=getpwuid(config.c_ctdluid);
+               getpwuid_r(config.c_ctdluid, &pw, pwbuf, sizeof(pwbuf), &pwp);
                mkdir(ctdl_run_dir, 0755);
-               chown(ctdl_run_dir, config.c_ctdluid, (pw==NULL)?-1:pw->pw_gid);
-
+               chown(ctdl_run_dir, config.c_ctdluid, (pwp==NULL)?-1:pw.pw_gid);
        }
                        
 
@@ -242,14 +242,16 @@ int main(int argc, char **argv)
         * corresponding group ids
         */
        if (drop_root_perms) {
-               if ((pw = getpwuid(CTDLUID)) == NULL)
+               getpwuid_r(config.c_ctdluid, &pw, pwbuf, sizeof(pwbuf), &pwp);
+
+               if (pwp == NULL)
                        lprintf(CTDL_CRIT, "WARNING: getpwuid(%ld): %s\n"
                                   "Group IDs will be incorrect.\n", (long)CTDLUID,
                                strerror(errno));
                else {
-                       initgroups(pw->pw_name, pw->pw_gid);
-                       if (setgid(pw->pw_gid))
-                               lprintf(CTDL_CRIT, "setgid(%ld): %s\n", (long)pw->pw_gid,
+                       initgroups(pw.pw_name, pw.pw_gid);
+                       if (setgid(pw.pw_gid))
+                               lprintf(CTDL_CRIT, "setgid(%ld): %s\n", (long)pw.pw_gid,
                                        strerror(errno));
                }
                lprintf(CTDL_INFO, "Changing uid to %ld\n", (long)CTDLUID);