+
+#if !HAVE_GETPWNAM_R
+int getpwnam_r (const char *name, struct passwd *pwbuf, char *buf,
+ size_t buflen, struct passwd **pwbufp)
+{
+ int status = 0;
+ struct passwd *pw;
+
+ memset (pwbuf, '\0', sizeof (struct passwd));
+
+ pthread_mutex_lock (&getpwnam_r_lock);
+
+ do
+ {
+ pw = getpwnam (name);
+ if (pw == NULL)
+ {
+ status = (errno != 0) ? errno : ENOENT;
+ break;
+ }
+
+#define GETPWNAM_COPY_MEMBER(member) \
+ if (pw->member != NULL) \
+ { \
+ int len = strlen (pw->member); \
+ if (len >= buflen) \
+ { \
+ status = ENOMEM; \
+ break; \
+ } \
+ sstrncpy (buf, pw->member, buflen); \
+ pwbuf->member = buf; \
+ buf += (len + 1); \
+ buflen -= (len + 1); \
+ }
+ GETPWNAM_COPY_MEMBER(pw_name);
+ GETPWNAM_COPY_MEMBER(pw_passwd);
+ GETPWNAM_COPY_MEMBER(pw_gecos);
+ GETPWNAM_COPY_MEMBER(pw_dir);
+ GETPWNAM_COPY_MEMBER(pw_shell);
+
+ pwbuf->pw_uid = pw->pw_uid;
+ pwbuf->pw_gid = pw->pw_gid;
+
+ if (pwbufp != NULL)
+ *pwbufp = pwbuf;
+ } while (0);
+
+ pthread_mutex_unlock (&getpwnam_r_lock);
+
+ return (status);
+} /* int getpwnam_r */
+#endif /* !HAVE_GETPWNAM_R */
+
+int notification_init (notification_t *n, int severity, const char *message,
+ const char *host,
+ const char *plugin, const char *plugin_instance,
+ const char *type, const char *type_instance)
+{
+ memset (n, '\0', sizeof (notification_t));
+
+ n->severity = severity;
+
+ if (message != NULL)
+ strncpy (n->message, message, sizeof (n->message));
+ if (host != NULL)
+ strncpy (n->host, host, sizeof (n->host));
+ if (plugin != NULL)
+ strncpy (n->plugin, plugin, sizeof (n->plugin));
+ if (plugin_instance != NULL)
+ strncpy (n->plugin_instance, plugin_instance,
+ sizeof (n->plugin_instance));
+ if (type != NULL)
+ strncpy (n->type, type, sizeof (n->type));
+ if (type_instance != NULL)
+ strncpy (n->type_instance, type_instance,
+ sizeof (n->type_instance));
+
+ n->message[sizeof (n->message) - 1] = '\0';
+ n->host[sizeof (n->host) - 1] = '\0';
+ n->plugin[sizeof (n->plugin) - 1] = '\0';
+ n->plugin_instance[sizeof (n->plugin_instance) - 1] = '\0';
+ n->type[sizeof (n->type) - 1] = '\0';
+ n->type_instance[sizeof (n->type_instance) - 1] = '\0';
+
+ return (0);
+} /* int notification_init */