Click here to Skip to main content
15,890,897 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: RegQueryValueEx returns wrong value Pin
vks1126-May-14 23:23
vks1126-May-14 23:23 
AnswerRe: RegQueryValueEx returns wrong value Pin
Randor 26-May-14 14:06
professional Randor 26-May-14 14:06 
GeneralRe: RegQueryValueEx returns wrong value Pin
vks1126-May-14 23:23
vks1126-May-14 23:23 
GeneralProblem in reading BMP Header Pin
Benjamin Bruno25-May-14 19:03
Benjamin Bruno25-May-14 19:03 
GeneralRe: Problem in reading BMP Header Pin
Richard MacCutchan25-May-14 21:48
mveRichard MacCutchan25-May-14 21:48 
GeneralRe: Problem in reading BMP Header Pin
Heng Xiangzhong26-May-14 15:11
Heng Xiangzhong26-May-14 15:11 
GeneralRe: Problem in reading BMP Header Pin
CPallini26-May-14 22:01
mveCPallini26-May-14 22:01 
QuestionC Makefile warning: passing arg 2 of 'connect' from incompatible pointer type Pin
Office 36525-May-14 17:03
Office 36525-May-14 17:03 
can u help me Sun Directory warning is build file gmake

after build gmake show
- warning:passing arg 2 of 'connect' from incompatible pointer type id -G -o 64/dpss.so dpss.o

Code...

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <sys types.h="">
#include <sys socket.h="">
#include <netinet in.h="">
#include <netdb.h>
#ifndef _WIN32
#include <libgen.h>#endif
#include "slapi-plugin.h"

#define SLAPD_LOGGING 1
#define _ADD 0
#define _MOD 1
#define _DEL 2
#define _MODRDN 3

Slapi_PluginDesc DPSS_desc = {
"DPSS", /* plug-in identifier */
"DThai Professional Services", /* vendor name */
"1.0", /* plug-in revision number */
"capture password change plugin" /* plug-in description */
};

static Slapi_ComponentId * DPSS_id; /* Used to set log */

char * changelogfile = NULL; /* Write changes to this file */
char * changelogfile2 = NULL; /* Write changes to this file */
char **argument; /* receive username and port */
#define NULL_CHANGELOG_WARNING_ID 0L
#define CANNOT_APPEND_TO_CHANGELOG_WARNING_ID 1L

/* Current time is a function defined in the server */
time_t current_time(void);
/* Initialization function before write log file */
int DPSS_set_log(Slapi_PBlock * pb);
/* Log the DN of the added entry */
int DPSS_add(Slapi_PBlock * pb);
/* Log the DN of the modified entry */
int DPSS_mod(Slapi_PBlock * pb);
/* Logs information on an operation to a change log file */
static void write_changelog(int optype, char *dn, void *change);

/* get the DS errorlog path by reading configuration entry */
/* which has dn=config and find nsslapd-errorlog attribute */
/* then create changelogfile path near the errorlog */
int DPSS_set_log(Slapi_PBlock * pb)
{
Slapi_DN * confdn = NULL; /* DN for configuration entry */
Slapi_Entry * config = NULL; /* Configuration entry */
char * errlog = NULL; /* Errors log file name */
char * logdir = NULL; /* Errors log directory name */
FILE * fp; /* Use to open changelog file */
int rc = 0; /* Use to check success */

#ifdef _WIN32
char drive[_MAX_DRIVE]; /* Windows disk drive */
char dir[_MAX_DIR]; /* Windows folder name */
char fname[_MAX_FNAME]; /* Windows file name */
char ext[_MAX_EXT]; /* Windows file extension */
char tmp_path[_MAX_PATH]; /* Working log directory name */
#endif

/* if changelogfile already set, return it */
if (changelogfile != NULL) return (rc);

/* get configuration entry */
confdn = slapi_sdn_new_dn_byval("cn=config");
if (confdn == NULL) return (rc);
rc |= slapi_search_internal_get_entry(confdn, NULL, &config, DPSS_id);

/* if cannot get configuration entry, write error to errorlog */
if (rc != 0) {
slapi_log_info_ex(
SLAPI_LOG_INFO_AREA_PLUGIN,
SLAPI_LOG_INFO_LEVEL_DEFAULT,
SLAPI_LOG_NO_MSGID,
SLAPI_LOG_NO_CONNID,
SLAPI_LOG_NO_OPID,
"DPSS_init in DPSS plug-in",
"Failed to read configuration entry: %d\n", rc
);
return (rc);
}
/* returns allocated memory for confdn */
slapi_sdn_free(&confdn);

/* get error log filename */
errlog = slapi_entry_attr_get_charptr(config, "nsslapd-errorlog");
slapi_entry_free(config);
config = NULL;

/* set changelog file path which next to the DS error log */
/* windows OS */
#ifdef _WIN32
_splitpath(errlog, drive, dir, fname, ext);
logdir = slapi_ch_strdup((char *)dir);
_makepath(tmp_path, drive, logdir, "changelog", "txt");
changelogfile = slapi_ch_strdup((char *)tmp_path);
/* Unix or Linux OS */
#else
logdir = slapi_ch_strdup((char *)dirname(errlog));
changelogfile = slapi_ch_malloc(strlen(logdir)+strlen("/changelog.txt")+1);
sprintf(changelogfile, "%s%s", logdir, "/changelog.txt");
#endif

slapi_ch_free_string(&errlog);
slapi_ch_free_string(&logdir);

/* if error and changelog path cannot be set */
if (changelogfile == NULL) {
slapi_log_warning_ex(
NULL_CHANGELOG_WARNING_ID,
SLAPI_LOG_NO_MSGID,
SLAPI_LOG_NO_CONNID,
SLAPI_LOG_NO_OPID,
"write_changelog in DPSS plug-in",
"No changelog file for DPSS plug-in",
"Path to changelog file is NULL!\n"
);
return (-1);
}

/* cannot open changelog file */
if ((fp = fopen(changelogfile, "ab")) == NULL) {
slapi_log_warning_ex(
CANNOT_APPEND_TO_CHANGELOG_WARNING_ID,
SLAPI_LOG_NO_MSGID,
SLAPI_LOG_NO_CONNID,
SLAPI_LOG_NO_OPID,
"DPSS_set_log in DPSS plug-in",
"Write error in DPSS plug-in",
"Plug-in cannot create log file %s\n", changelogfile
);
return (-1);
}

fclose(fp);
return (rc);
}

/* returns memory allocated for changelog file*/
int DPSS_free_log(Slapi_PBlock * pb)
{
slapi_ch_free_string(&changelogfile);
return 0;
}

/* Log the DN of the added entry and write to the changelog */
int DPSS_add(Slapi_PBlock * pb)
{
char * dn; /* DN of entry to add */
Slapi_Entry * entry; /* Entry to add */
int is_repl = 0; /* Is this replication? */
int rc = 0; /* 0 mean success */
int connId, opId;
long msgId;

rc |= slapi_pblock_get(pb, SLAPI_ADD_TARGET, &dn);
rc |= slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &entry);
rc |= slapi_pblock_get(pb, SLAPI_OPERATION_MSGID, &msgId);
rc |= slapi_pblock_get(pb, SLAPI_CONN_ID, &connId);
rc |= slapi_pblock_get(pb, SLAPI_OPERATION_ID, &opId);
rc |= slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_repl);

/* write error log */
if (rc != 0) return (rc);
slapi_log_info_ex(
SLAPI_LOG_INFO_AREA_PLUGIN,
SLAPI_LOG_INFO_LEVEL_DEFAULT,
msgId,
connId,
opId,
"DPSS_add in DPSS plug-in",
"Added entry (%s)\n", dn
);

/* In general, do not interfere in replication operations. */
/* Log the DN and the entry to the change log file. */
if (!is_repl) write_changelog(_ADD, dn, (void *) entry);

return (rc);
}

/* Log the DN of the modified entry and write to the changelog */
int DPSS_mod(Slapi_PBlock * pb)
{
char * dn; /* DN of entry to modify */
LDAPMod ** mods; /* Modifications to apply */
int is_repl = 0; /* Is this replication? */
int connId, opId, rc = 0;
long msgId;

rc |= slapi_pblock_get(pb, SLAPI_MODIFY_TARGET, &dn);
rc |= slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
rc |= slapi_pblock_get(pb, SLAPI_OPERATION_MSGID, &msgId);
rc |= slapi_pblock_get(pb, SLAPI_CONN_ID, &connId);
rc |= slapi_pblock_get(pb, SLAPI_OPERATION_ID, &opId);
rc |= slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_repl);

if (rc != 0) return (rc);
slapi_log_info_ex(
SLAPI_LOG_INFO_AREA_PLUGIN,
SLAPI_LOG_INFO_LEVEL_DEFAULT,
msgId,
connId,
opId,
"DPSS_mod in DPSS plug-in",
"Modified entry (%s)\n", dn
);

/* In general, do not interfere in replication operations. */
/* Log the DN and the modifications made to the change log file. */
if (!is_repl) write_changelog(_MOD, dn, (void *) mods);

return (rc);
}

/* Register plug-in to the server. */
#ifdef _WIN32
__declspec(dllexport)
#endif

/* Function for generating a generalizedTime */
static char* format_localTime(time_t timeval)
{
char* into;
struct tm t;
#ifdef _WIN32
memcpy (&t, localtime (&timeval), sizeof(t));
#else
localtime_r (&timeval, &t);
#endif

/* Allocate memory for the formatted string. */
/* This string is freed by call function write_changelog(). */
into = slapi_ch_malloc(15);
sprintf (into, "%.4li%.2i%.2i%.2i%.2i%.2i",
1900L + t.tm_year, 1 + t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
return into;
}

static void debugs(char *message)
{
changelogfile2 = "/var/opt/dsee7/dsins1/logs/changelog2.txt";
FILE *fp;
/* if cannot open change log file */
if (changelogfile2 == NULL) {
return;
}

/* if cannot append to change log file */
if ((fp = fopen(changelogfile2, "ab")) == NULL) {
return;
}

fprintf(fp, "--- pass %s ---\n", message);

fclose(fp);
return;
}

/* Logs information on an operation to a change log file.
Parameters;
- optype is type of LDAP operation to record:
1. _ADD for LDAP add operations
2. _MOD for LDAP modify operations
- dn is DN of the entry affected by the operation.
- change is information about the operation performed.
The type of information depends on the value of optype:
1. For _ADD, it is the newly added entry (Slapi_Entry).
2. For _MOD, it is the list of modifications made (array of LDAPMod).
*/
void write_changelog(int optype, char *dn, void *change)
{
LDAPMod **mods;
Slapi_Entry *e;
int len, i, j;
FILE *fp;
char *timestr;
char *password;
const char *PSW_ATTR = "unhashed#user#password";

/* if cannot open change log file */
if (changelogfile == NULL) {
slapi_log_warning_ex(
CANNOT_APPEND_TO_CHANGELOG_WARNING_ID,
SLAPI_LOG_NO_MSGID,
SLAPI_LOG_NO_CONNID,
SLAPI_LOG_NO_OPID,
"write_changelog in DPSS plug-in",
"Write error in DPSS plug-in",
"Plug-in cannot append to log file\n"
);
return;
}

/* if cannot append to change log file */
if ((fp = fopen(changelogfile, "ab")) == NULL) {
slapi_log_warning_ex(
CANNOT_APPEND_TO_CHANGELOG_WARNING_ID,
SLAPI_LOG_NO_MSGID,
SLAPI_LOG_NO_CONNID,
SLAPI_LOG_NO_OPID,
"DPSS_set_log in DPSS plug-in",
"Write error in DPSS plug-in",
"Plug-in cannot create log file %s\n", changelogfile
);
return;
}

/* write current date and time when event is handled */
timestr = format_localTime(current_time());
fprintf(fp, "time: %s\n", timestr);

/* write user dn */
fprintf(fp, "dn: %s\n", dn);

/* check if type is create or modify */
switch (optype) {

/* if add user */
case _ADD:

/* For LDAP add operations, log the newly added entry. */
e = (Slapi_Entry *)change;
fprintf( fp, "type: add\n" );

/* get password value from PSW_ATTR attribute */
char* pvalue = NULL;
if (pvalue = slapi_entry_attr_get_charptr(e, PSW_ATTR)) {

/* send uid & password over machine*/
char *message = NULL;
message = slapi_ch_malloc(strlen(dn) + strlen("<value>") + strlen(pvalue) +
strlen("<value><add><value>") + strlen(timestr) + strlen("<end>") + 1);
sprintf(message, "%s%s%s%s%s%s", dn, "<value>", pvalue, "<value>add<value>", timestr, "<end>");
send_message(message);

/* write changed password value */
fprintf( fp, "%s\n\n", pvalue );

slapi_ch_free_string(&message);
slapi_ch_free((void **)&pvalue);
}

break;

/* if modify user */
case _MOD:
/* convert modify entry to LDAPMod type */
mods = (LDAPMod **)change;
fprintf(fp, "type: reset\n");
for (j = 0; mods[j] != NULL; j++) {
/* if set attribute value to blank */
if ((mods[j]->mod_op & ~LDAP_MOD_BVALUES) == LDAP_MOD_DELETE) {

/* send uid & password over machine*/
char *message = NULL;
message = slapi_ch_malloc(strlen(dn) + strlen("<value><value><modify><value>") +
strlen(timestr) + strlen("<end>") + 1);
sprintf(message, "%s%s%s%s", dn, "<value><value>modify<value>", timestr, "<end>");
send_message(message);
slapi_ch_free_string(&message);

/* write blank password value */
fprintf(fp, "%s: %s\n", mods[j]->mod_type, "");
}
/* if modify attribute value */
else {
for (i = 0; mods[j]->mod_bvalues != NULL &&
mods[j]->mod_bvalues[i] != NULL; i++) {
/* if changed attribute is password */
if (strcmp(mods[j]->mod_type, PSW_ATTR) == 0) {

/* send uid & password over machine*/
char *message = NULL;
message = slapi_ch_malloc(strlen(dn) + strlen("<value>") +
strlen(mods[j]->mod_bvalues[i]->bv_val) + strlen("<value><modify><value>") +
strlen(timestr) + strlen("<end>") + 1);
sprintf(message, "%s%s%s%s%s%s", dn, "<value>",
mods[j]->mod_bvalues[i]->bv_val, "<value>modify<value>", timestr, "<end>");

send_message(message);
slapi_ch_free_string(&message);

/* write changed password value */
fprintf(fp, "%s: %s\n", mods[j]->mod_type,
mods[j]->mod_bvalues[i]->bv_val);

//fprintf(fp, "%s %s\n\n", argument[0], argument[1]);
}
}
}
}
break;
}
slapi_ch_free((void **) ×tr);
fprintf(fp, "\n");
fclose(fp);
}

void error(char *msg)
{
perror(msg);
exit(0);
}

int send_message(char* message)
{
char* ip = "172.32.5.107";
char* port = "12199";

if (argument[0] != NULL)
ip = argument[0];
if (argument[1] != NULL)
port = argument[1];

int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;

char buffer[256];
portno = atoi(port);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
error("ERROR opening socket");
exit(0);
}
else
{
server = gethostbyname(ip);
if (server == NULL) {
//fprintf(stderr,"ERROR, no such host\n");
//exit(0);
close(sockfd);
return(0);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;

bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
serv_addr.sin_port = htons(portno);

=> this warning		if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) {
        	//error("ERROR connecting");			
			close(sockfd);			
			return(0);
		}

bzero(buffer,256);
n = write(sockfd,message,strlen(message));
//if (n < 0)
// error("ERROR writing to socket");
bzero(buffer,256);
//n = read(sockfd,buffer,255);
//if (n < 0)
//error("ERROR reading from socket");

//printf("%s\n",buffer);
}
close(sockfd);
return 0;

}

/* Initial function */
/* must register this function when run "dsconf create-plugin..." */
int DPSS_init(Slapi_PBlock * pb)
{
char ** argv; /* Args from configuration */
int argc; /* entry for plug-in. */
int rc = 0; /* 0 means success */
//static char **config;
int i;

/* Get the arguments from the configuration entry. */
rc |= slapi_pblock_get(pb, SLAPI_PLUGIN_ARGV, &argv);
rc |= slapi_pblock_get(pb, SLAPI_PLUGIN_ARGC, &argc);

if (rc != 0) {
slapi_log_info_ex(
SLAPI_LOG_INFO_AREA_PLUGIN,
SLAPI_LOG_INFO_LEVEL_DEFAULT,
SLAPI_LOG_NO_MSGID,
SLAPI_LOG_NO_CONNID,
SLAPI_LOG_NO_OPID,
"DPSS_init in DPSS plug-in",
"Could not get plug-in arguments.\n");
return (rc);
}

argument = (char **)slapi_ch_malloc((argc + 1) * sizeof(char *));
for (i = 0; i < argc; ++i) {
argument[i] = slapi_ch_strdup(argv[i]);
}
argument[argc] = NULL;

rc |= slapi_pblock_set( /* Plug-in API version */
pb,
SLAPI_PLUGIN_VERSION,
SLAPI_PLUGIN_CURRENT_VERSION
);
rc |= slapi_pblock_set( /* Plug-in description */
pb,
SLAPI_PLUGIN_DESCRIPTION,
(void *) &DPSS_desc
);
rc |= slapi_pblock_set( /* Open log at startup */
pb,
SLAPI_PLUGIN_START_FN,
(void *) DPSS_set_log
);
rc |= slapi_pblock_set( /* Post-op add function */
pb,
SLAPI_PLUGIN_POST_ADD_FN,
(void *) DPSS_add
);
rc |= slapi_pblock_set( /* Post-op modify function */
pb,
SLAPI_PLUGIN_POST_MODIFY_FN,
(void *) DPSS_mod
);
rc |= slapi_pblock_set( /* Close log on shutdown */
pb,
SLAPI_PLUGIN_CLOSE_FN,
(void *) DPSS_free_log
);
/* Plug-in identifier is required for internal search. */
rc |= slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &DPSS_id);
return (rc);
}

modified 26-May-14 4:36am.

AnswerRe: C Makefile warning: passing arg 2 of 'connect' from incompatible pointer type Pin
Richard MacCutchan25-May-14 21:43
mveRichard MacCutchan25-May-14 21:43 
GeneralRe: C Makefile warning: passing arg 2 of 'connect' from incompatible pointer type Pin
Office 36525-May-14 22:37
Office 36525-May-14 22:37 
GeneralRe: C Makefile warning: passing arg 2 of 'connect' from incompatible pointer type Pin
Richard MacCutchan25-May-14 22:52
mveRichard MacCutchan25-May-14 22:52 
GeneralRe: C Makefile warning: passing arg 2 of 'connect' from incompatible pointer type Pin
Office 36526-May-14 0:14
Office 36526-May-14 0:14 
GeneralRe: C Makefile warning: passing arg 2 of 'connect' from incompatible pointer type Pin
Richard MacCutchan26-May-14 0:23
mveRichard MacCutchan26-May-14 0:23 
GeneralRe: C Makefile warning: passing arg 2 of 'connect' from incompatible pointer type Pin
Office 36526-May-14 18:48
Office 36526-May-14 18:48 
GeneralRe: C Makefile warning: passing arg 2 of 'connect' from incompatible pointer type Pin
Richard MacCutchan26-May-14 21:33
mveRichard MacCutchan26-May-14 21:33 
QuestionGNU Gettext and windows localization Pin
Member 854422623-May-14 16:31
Member 854422623-May-14 16:31 
AnswerRe: GNU Gettext and windows localization Pin
Richard MacCutchan23-May-14 21:40
mveRichard MacCutchan23-May-14 21:40 
QuestionCFormView in CDocktablePane or docking frame CMDIChildWndEx Pin
Member 1074879523-May-14 6:16
Member 1074879523-May-14 6:16 
SuggestionRe: CFormView in CDocktablePane or docking frame CMDIChildWndEx Pin
Richard MacCutchan23-May-14 7:46
mveRichard MacCutchan23-May-14 7:46 
GeneralRe: CFormView in CDocktablePane or docking frame CMDIChildWndEx Pin
Member 1074879523-May-14 8:56
Member 1074879523-May-14 8:56 
GeneralRe: CFormView in CDocktablePane or docking frame CMDIChildWndEx Pin
Richard MacCutchan23-May-14 11:36
mveRichard MacCutchan23-May-14 11:36 
GeneralRe: CFormView in CDocktablePane or docking frame CMDIChildWndEx Pin
Member 1074879523-May-14 23:09
Member 1074879523-May-14 23:09 
GeneralRe: CFormView in CDocktablePane or docking frame CMDIChildWndEx Pin
Richard MacCutchan23-May-14 23:17
mveRichard MacCutchan23-May-14 23:17 
AnswerRe: here Pin
Software_Developer23-May-14 20:59
Software_Developer23-May-14 20:59 
QuestionCreateProcess() not working Pin
Member 420182022-May-14 23:51
Member 420182022-May-14 23:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.