Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 160880 Details for
Bug 251262
ldap-agent needs to find slapd.stats file dynamically
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
Revised Diffs
diffs.txt (text/plain), 10.04 KB, created by
Nathan Kinder
on 2007-08-08 06:18:52 UTC
(
hide
)
Description:
Revised Diffs
Filename:
MIME Type:
Creator:
Nathan Kinder
Created:
2007-08-08 06:18:52 UTC
Size:
10.04 KB
patch
obsolete
>Index: Makefile.am >=================================================================== >RCS file: /cvs/dirsec/ldapserver/Makefile.am,v >retrieving revision 1.53 >diff -u -5 -t -r1.53 Makefile.am >--- Makefile.am 2 Aug 2007 14:39:00 -0000 1.53 >+++ Makefile.am 8 Aug 2007 06:12:40 -0000 >@@ -857,11 +857,11 @@ > ldap_agent_bin_SOURCES = ldap/servers/snmp/main.c \ > ldap/servers/snmp/ldap-agent.c \ > ldap/servers/slapd/agtmmap.c > > ldap_agent_bin_CPPFLAGS = $(AM_CPPFLAGS) @netsnmp_inc@ @ldapsdk_inc@ @nss_inc@ @nspr_inc@ >-ldap_agent_bin_LDADD = $(NETSNMP_LINK) >+ldap_agent_bin_LDADD = $(NETSNMP_LINK) $(LDAPSDK_LINK) > > #------------------------ > # ldclt > #------------------------ > ldclt_bin_SOURCES = ldap/servers/slapd/tools/ldaptool-sasl.c \ >Index: ldap/servers/snmp/main.c >=================================================================== >RCS file: /cvs/dirsec/ldapserver/ldap/servers/snmp/main.c,v >retrieving revision 1.10 >diff -u -5 -t -r1.10 main.c >--- ldap/servers/snmp/main.c 10 Nov 2006 23:45:53 -0000 1.10 >+++ ldap/servers/snmp/main.c 8 Aug 2007 06:13:28 -0000 >@@ -45,10 +45,11 @@ > #include <stdio.h> > #include <unistd.h> > #include <signal.h> > #include <sys/stat.h> > #include "ldap-agent.h" >+#include "ldif.h" > > static char *agentx_master = NULL; > static char *agent_logdir = NULL; > static char *pidfile = NULL; > server_instance *server_head = NULL; >@@ -237,23 +238,25 @@ > server_instance *serv_p = NULL; > FILE *conf_file = NULL; > FILE *dse_fp = NULL; > char line[MAXLINE]; > char *p = NULL; >- char *p2 = NULL; >+ int error = 0; > > /* Make sure we are getting an absolute path */ > if (*conf_path != '/') { > printf("ldap-agent: Error opening config file: %s\n", conf_path); > printf("ldap-agent: You must specify the absolute path to your config file\n"); >- exit(1); >+ error = 1; >+ goto close_and_exit; > } > > /* Open config file */ > if ((conf_file = fopen(conf_path, "r")) == NULL) { > printf("ldap-agent: Error opening config file: %s\n", conf_path); >- exit(1); >+ error = 1; >+ goto close_and_exit; > } > > /* set pidfile path */ > for (p = (conf_path + strlen(conf_path) - 1); p >= conf_path; p--) { > if (*p == '/') { >@@ -263,21 +266,23 @@ > strncpy(pidfile, conf_path, (p - conf_path + 1)); > strcat(pidfile, LDAP_AGENT_PIDFILE); > pidfile[((p - conf_path) + strlen(LDAP_AGENT_PIDFILE) + 1)] = (char)0; > } else { > printf("ldap-agent: malloc error processing config file\n"); >- exit(1); >+ error = 1; >+ goto close_and_exit; > } > > /* set default logdir to location of config file */ > if ((agent_logdir = malloc((p - conf_path) + 1)) != NULL) { > strncpy(agent_logdir, conf_path, (p - conf_path)); > agent_logdir[(p - conf_path)] = (char)0; > break; > } else { > printf("ldap-agent: malloc error processing config file\n"); >- exit(1); >+ error = 1; >+ goto close_and_exit; > } > } > } > > while (fgets(line, MAXLINE, conf_file) != NULL) { >@@ -303,63 +308,138 @@ > if ((p = strtok(p, " \t\n")) != NULL) { > if ((agent_logdir = (char *) malloc(strlen(p) + 1)) != NULL) > strcpy(agent_logdir, p); > } > } else if ((p = strstr(line, "server")) != NULL) { >+ int got_port = 0; >+ int got_tmpdir = 0; >+ int lineno = 0; >+ char *entry = NULL; >+ > /* Allocate a server_instance */ > if ((serv_p = malloc(sizeof(server_instance))) == NULL) { > printf("ldap-agent: malloc error processing config file\n"); >- exit(1); >+ error = 1; >+ goto close_and_exit; > } > > /* load server setting */ > p = p + 6; >- if ((p = strtok_r(p, " :\t\n", &p2)) != NULL) { >- /* first token is the instance root */ >- if ((serv_p->stats_file = malloc(strlen(p) + 18)) != NULL) >- snprintf(serv_p->stats_file, strlen(p) + 18, >- "%s/logs/slapd.stats", p); >- serv_p->stats_file[(strlen(p) + 17)] = (char)0; >- if ((serv_p->dse_ldif = malloc(strlen(p) + 17)) != NULL) { >- snprintf(serv_p->dse_ldif, strlen(p) + 17, "%s/config/dse.ldif", p); >- serv_p->dse_ldif[(strlen(p) + 16)] = (char)0; >+ if ((p = strtok(p, " \t\n")) != NULL) { >+ /* first token is the instance name */ >+ serv_p->dse_ldif = malloc(strlen(p) + strlen(SYSCONFDIR) + >+ strlen(PACKAGE_NAME) + 12); >+ if (serv_p->dse_ldif != NULL) { >+ snprintf(serv_p->dse_ldif, strlen(p) + strlen(SYSCONFDIR) + >+ strlen(PACKAGE_NAME) + 12, "%s/%s/%s/dse.ldif", >+ SYSCONFDIR, PACKAGE_NAME, p); >+ serv_p->dse_ldif[(strlen(p) + strlen(SYSCONFDIR) + >+ strlen(PACKAGE_NAME) + 11)] = (char)0; >+ } else { >+ printf("ldap-agent: malloc error processing config file\n"); >+ error = 1; >+ goto close_and_exit; > } > } > > /* Open dse.ldif */ > if ((dse_fp = fopen(serv_p->dse_ldif, "r")) == NULL) { > printf("ldap-agent: Error opening server config file: %s\n", > serv_p->dse_ldif); >- exit(1); >+ error = 1; >+ goto close_and_exit; > } > >- /* Get port value */ >- while (fgets(line, MAXLINE, dse_fp) != NULL) { >- if ((p = strstr(line, "nsslapd-port: ")) != NULL) { >- p = p + 14; >- if ((p = strtok(p, ": \t\n")) != NULL) >- serv_p->port = atol(p); >+ /* ldif_get_entry will realloc the entry if it's not null, >+ * so we can just free it when we're done fetching entries >+ * from the dse.ldif. Unfortunately, ldif_getline moves >+ * the pointer that is passed to it, so we need to save a >+ * pointer to the beginning of the entry so we can free it >+ * later. */ >+ while ((entry = ldif_get_entry(dse_fp, &lineno)) != NULL) { >+ char *entryp = entry; >+ char *attr = NULL; >+ char *val = NULL; >+ int vlen; >+ >+ /* Check if this is the cn=config entry */ >+ ldif_parse_line(ldif_getline(&entryp), &attr, &val, &vlen); >+ if ((strcmp(attr, "dn") == 0) && >+ (strcmp(val, "cn=config") == 0)) { >+ char *dse_line = NULL; >+ /* Look for port and tmpdir attributes */ >+ while ((dse_line = ldif_getline(&entryp)) != NULL) { >+ ldif_parse_line(dse_line, &attr, &val, &vlen); >+ if (strcmp(attr, "nsslapd-port") == 0) { >+ serv_p->port = atol(val); >+ got_port = 1; >+ } else if (strcmp(attr, "nsslapd-tmpdir") == 0) { >+ serv_p->stats_file = malloc(vlen + 13); >+ if (serv_p->stats_file != NULL) { >+ snprintf(serv_p->stats_file, vlen + 13, >+ "%s/slapd.stats", val); >+ serv_p->stats_file[(vlen + 12)] = (char)0; >+ } else { >+ printf("ldap-agent: malloc error processing config file\n"); >+ free(entry); >+ error = 1; >+ goto close_and_exit; >+ } >+ got_tmpdir = 1; >+ } >+ >+ /* Stop processing this entry if we found the >+ * port and tmpdir settings */ >+ if (got_port && got_tmpdir) { >+ break; >+ } >+ } >+ /* The port and tmpdir settings must be in the >+ * cn=config entry, so we can stop reading through >+ * the dse.ldif now. */ >+ break; > } > } > >- /* Close dse.ldif */ >- fclose(dse_fp); >+ /* We're done reading entries from dse_ldif now, so >+ * we can free entry */ >+ free(entry); >+ >+ /* Make sure we were able to read the port and >+ * location of the stats file. */ >+ if (!got_port) { >+ printf("ldap-agent: Error reading nsslapd-port from " >+ "server config file: %s\n", serv_p->dse_ldif); >+ error = 1; >+ goto close_and_exit; >+ } else if (!got_tmpdir) { >+ printf("ldap-agent: Error reading nsslapd-tmpdir from " >+ "server config file: %s\n", serv_p->dse_ldif); >+ error = 1; >+ goto close_and_exit; >+ } > > /* Insert server instance into linked list */ > serv_p->next = server_head; > server_head = serv_p; > } > } > >- /* Close config file */ >- fclose(conf_file); >- > /* check for at least one directory server instance */ > if (server_head == NULL) { > printf("ldap-agent: No server instances defined in config file\n"); >- exit(1); >+ error = 1; >+ goto close_and_exit; > } >+ >+close_and_exit: >+ if (conf_file) >+ fclose(conf_file); >+ if (dse_fp) >+ fclose(dse_fp); >+ if (error) >+ exit(error); > } > > /************************************************************************ > * exit_usage > *
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 251262
:
160867
| 160880