本文整理汇总了C++中s_free函数的典型用法代码示例。如果您正苦于以下问题:C++ s_free函数的具体用法?C++ s_free怎么用?C++ s_free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了s_free函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: cssp_encode_tssmartcardcreds
static STREAM
cssp_encode_tssmartcardcreds(char *username, char *password, char *domain)
{
STREAM out, h1, h2;
struct stream tmp = { 0 };
struct stream message = { 0 };
// pin [0]
s_realloc(&tmp, strlen(password) * sizeof(uint16));
s_reset(&tmp);
rdp_out_unistr(&tmp, password, strlen(password) * sizeof(uint16));
s_mark_end(&tmp);
h2 = ber_wrap_hdr_data(BER_TAG_OCTET_STRING, &tmp);
h1 = ber_wrap_hdr_data(BER_TAG_CTXT_SPECIFIC | BER_TAG_CONSTRUCTED | 0, h2);
s_realloc(&message, s_length(&message) + s_length(h1));
out_uint8p(&message, h1->data, s_length(h1));
s_mark_end(&message);
s_free(h2);
s_free(h1);
// cspData[1]
h2 = cssp_encode_tscspdatadetail(AT_KEYEXCHANGE, g_sc_card_name, g_sc_reader_name,
g_sc_container_name, g_sc_csp_name);
h1 = ber_wrap_hdr_data(BER_TAG_CTXT_SPECIFIC | BER_TAG_CONSTRUCTED | 1, h2);
s_realloc(&message, s_length(&message) + s_length(h1));
out_uint8p(&message, h1->data, s_length(h1));
s_mark_end(&message);
s_free(h2);
s_free(h1);
// userHint [2]
if (username && strlen(username))
{
s_realloc(&tmp, strlen(username) * sizeof(uint16));
s_reset(&tmp);
rdp_out_unistr(&tmp, username, strlen(username) * sizeof(uint16));
s_mark_end(&tmp);
h2 = ber_wrap_hdr_data(BER_TAG_OCTET_STRING, &tmp);
h1 = ber_wrap_hdr_data(BER_TAG_CTXT_SPECIFIC | BER_TAG_CONSTRUCTED | 2, h2);
s_realloc(&message, s_length(&message) + s_length(h1));
out_uint8p(&message, h1->data, s_length(h1));
s_mark_end(&message);
s_free(h2);
s_free(h1);
}
// domainHint [3]
if (domain && strlen(domain))
{
s_realloc(&tmp, strlen(domain) * sizeof(uint16));
s_reset(&tmp);
rdp_out_unistr(&tmp, domain, strlen(domain) * sizeof(uint16));
s_mark_end(&tmp);
h2 = ber_wrap_hdr_data(BER_TAG_OCTET_STRING, &tmp);
h1 = ber_wrap_hdr_data(BER_TAG_CTXT_SPECIFIC | BER_TAG_CONSTRUCTED | 3, h2);
s_realloc(&message, s_length(&message) + s_length(h1));
out_uint8p(&message, h1->data, s_length(h1));
s_mark_end(&message);
s_free(h2);
s_free(h1);
}
s_mark_end(&message);
// build message
out = ber_wrap_hdr_data(BER_TAG_SEQUENCE | BER_TAG_CONSTRUCTED, &message);
// cleanup
free(tmp.data);
free(message.data);
return out;
}
开发者ID:jeppeter,项目名称:vbox,代码行数:72,代码来源:cssp.c
示例2: hello
char *
hello(char *me, int encrypted)
{
int ehlo;
String *r;
char *ret, *s, *t;
if (!encrypted) {
if(trysecure > 1){
if((ret = wraptls()) != nil)
return ret;
encrypted = 1;
}
/*
* Verizon fails to print the smtp greeting banner when it
* answers a call. Send a no-op in the hope of making it
* talk.
*/
if (autistic) {
dBprint("NOOP\r\n");
getreply(); /* consume the smtp greeting */
/* next reply will be response to noop */
}
switch(getreply()){
case 2:
break;
case 5:
return Giveup;
default:
return Retry;
}
}
ehlo = 1;
Again:
if(ehlo)
dBprint("EHLO %s\r\n", me);
else
dBprint("HELO %s\r\n", me);
switch (getreply()) {
case 2:
break;
case 5:
if(ehlo){
ehlo = 0;
goto Again;
}
return Giveup;
default:
return Retry;
}
r = s_clone(reply);
if(r == nil)
return Retry; /* Out of memory or couldn't get string */
/* Invariant: every line has a newline, a result of getcrlf() */
for(s = s_to_c(r); (t = strchr(s, '\n')) != nil; s = t + 1){
*t = '\0';
for (t = s; *t != '\0'; t++)
*t = toupper(*t);
if(!encrypted && trysecure &&
(strcmp(s, "250-STARTTLS") == 0 ||
strcmp(s, "250 STARTTLS") == 0)){
s_free(r);
return dotls(me);
}
if(tryauth && (encrypted || insecure) &&
(strncmp(s, "250 AUTH", strlen("250 AUTH")) == 0 ||
strncmp(s, "250-AUTH", strlen("250 AUTH")) == 0)){
ret = doauth(s + strlen("250 AUTH "));
s_free(r);
return ret;
}
}
s_free(r);
return 0;
}
开发者ID:grobe0ba,项目名称:plan9front,代码行数:78,代码来源:smtp.c
示例3: lwqq_free_extension
void lwqq_free_extension(LwqqClient* lc,LwqqExtension* ext)
{
ext->remove(lc, ext);
s_free(ext);
}
开发者ID:cricketlong,项目名称:lwqq,代码行数:5,代码来源:async.c
示例4: gettimeofday
//.........这里部分代码省略.........
pady, // int pady,
MO->MI->max_X, // int max_X
MO->MI->max_Y, // int max_Y
MO->MI->def, // FLOAT *def
tmp_array_size, // int tmp_array_size
dst_PIDX, // int *dst_PIDX
dst_DID_4 // int *DID_4
);
gettimeofday(&tv_dt_end, nullptr);
tvsub(&tv_dt_end, &tv_dt_start, &tv);
time_dt += tv.tv_sec * 1000.0 + (float)tv.tv_usec / 1000.0;
/* add part score */
for(int level=interval; level<L_MAX; level++){
int L = level - interval;
if(feature_size[level*2]+2*pady<MO->MI->max_Y ||(feature_size[level*2+1]+2*padx<MO->MI->max_X))
{
continue;
}
for(int j=0; j<NoC; j++) {
for(int k=0; k<numpart[j]; k++) {
int PSSIZE[2] ={pm_size_array[L][PIDX_array[L][j][k]*2],
pm_size_array[L][PIDX_array[L][j][k]*2+1]}; // Size of C
int R_S[2]={rm_size_array[level][j*2], rm_size_array[level][j*2+1]};
dpm_ttic_add_part_calculation(SCORE_array[L][j], M_array[L][j][k], R_S,
PSSIZE, ax_array[L][j][k], ay_array[L][j][k]);
}
}
}
s_free(M_array[0][0][0]);
s_free(M_array[0][0]);
s_free(M_array[0]);
s_free(M_array);
/* free temporary arrays */
free(dst_DIDX);
free(sub_dst_DIDX);
free(DIDX_array);
res = cuMemFreeHost(dst_DID_4);
if(res != CUDA_SUCCESS) {
printf("cuMemFreeHost(dst_DID_4) failed: res = %s\n", cuda_response_to_string(res));
exit(1);
}
free(sub_dst_DID_4);
free(DID_4_array);
res = cuMemFreeHost(dst_PIDX);
if(res != CUDA_SUCCESS) {
printf("cuMemFreeHost(dst_PIDX) failed: res = %s\n", cuda_response_to_string(res));
exit(1);
}
free(sub_dst_PIDX);
free(PIDX_array);
res = cuCtxSetCurrent(ctx[0]);
if(res != CUDA_SUCCESS) {
printf("cuCtxSetCurrent(ctx[0]) failed: res = %s\n", cuda_response_to_string(res));
exit(1);
}
} // start from if(NoP>0)
开发者ID:obrianjunior,项目名称:Autoware,代码行数:67,代码来源:get_boxes.cpp
示例5: main
//.........这里部分代码省略.........
exit(0);
}
filename_out = argv[i];
printf("Output filename set to \"%s\"\n", filename_out);
}
else if (strcmp(argv[i], "-n")==0)
{ /* Number of generations requested. */
i++;
if (i==argc)
{
printf("Number of generations not specified.\n");
write_usage();
exit(0);
}
generations = atoi(argv[i]);
printf("Number of generations set to %d.\n", generations);
}
else
{ /* Error parsing args. */
printf("Unable to parse command-line argument \"%s\"\n", argv[i]);
write_usage();
exit(0);
}
}
/*
* Check that we had the required inputs.
*/
if (filename_out == NULL)
{
printf("No output filename was specified.\n");
write_usage();
exit(0);
}
/*
* Read or create population.
*/
if (filename_in == NULL)
{
pop = ga_genesis_char(
40, /* const int population_size */
1, /* const int num_chromo */
strlen(target_text), /* const int len_chromo */
NULL, /* GAgeneration_hook generation_hook */
NULL, /* GAiteration_hook iteration_hook */
NULL, /* GAdata_destructor data_destructor */
NULL, /* GAdata_ref_incrementor data_ref_incrementor */
struggle_score, /* GAevaluate evaluate */
ga_seed_printable_random, /* GAseed seed */
NULL, /* GAadapt adapt */
ga_select_one_roulette, /* GAselect_one select_one */
ga_select_two_roulette, /* GAselect_two select_two */
ga_mutate_printable_singlepoint_drift, /* GAmutate mutate */
ga_crossover_char_allele_mixing, /* GAcrossover crossover */
NULL, /* GAreplace replace */
NULL /* vpointer User data */
);
ga_population_set_parameters(
pop, /* population *pop */
GA_SCHEME_DARWIN, /* const ga_scheme_type scheme */
GA_ELITISM_PARENTS_SURVIVE, /* const ga_elitism_type elitism */
1.0, /* double crossover */
0.1, /* double mutation */
0.0 /* double migration */
);
}
else
{
pop = ga_population_read(filename_in);
pop->evaluate = struggle_score; /* Custom functions can't be saved and
* therefore "pop->evaluate" must be
* defined manually. Likewise, if a
* custom crossover routine was used, for
* example, then that would also need
* to be manually defined here.
*/
}
ga_evolution(
pop, /* population *pop */
generations /* const int max_generations */
);
printf("The final solution with seed = %d was:\n", i);
beststring = ga_chromosome_char_to_string(pop, ga_get_entity_from_rank(pop,0), beststring, &beststrlen);
printf("%s\n", beststring);
printf("With score = %f\n", ga_entity_get_fitness(ga_get_entity_from_rank(pop,0)) );
ga_population_write(pop, filename_out);
printf("Population has been saved as \"%s\"\n", filename_out);
ga_extinction(pop);
s_free(beststring);
exit(EXIT_SUCCESS);
}
开发者ID:dunghand,项目名称:msrds,代码行数:101,代码来源:test_io.c
示例6: set_online_status
/**
* Set online status, this is the last step of login
*
* @param err
* @param lc
*/
static void set_online_status(LwqqClient *lc, char *status, LwqqErrorCode *err)
{
char msg[1024] ={0};
char *buf;
LwqqHttpRequest *req = NULL;
char *response = NULL;
char *cookies;
int ret;
json_t *json = NULL;
char *value;
if (!status || !err) {
goto done ;
}
lc->clientid = generate_clientid();
if (!lc->clientid) {
lwqq_log(LOG_ERROR, "Generate clientid error\n");
*err = LWQQ_EC_ERROR;
goto done ;
}
snprintf(msg, sizeof(msg), "{\"status\":\"%s\",\"ptwebqq\":\"%s\","
"\"passwd_sig\":""\"\",\"clientid\":\"%s\""
", \"psessionid\":null}"
,status, lc->cookies->ptwebqq
,lc->clientid);
buf = url_encode(msg);
snprintf(msg, sizeof(msg), "r=%s", buf);
s_free(buf);
/* Create a POST request */
req = lwqq_http_create_default_request(LWQQ_URL_SET_STATUS, err);
if (!req) {
goto done;
}
/* Set header needed by server */
req->set_header(req, "Cookie2", "$Version=1");
req->set_header(req, "Referer", "http://d.web2.qq.com/proxy.html?v=20101025002");
req->set_header(req, "Content-type", "application/x-www-form-urlencoded");
/* Set http cookie */
cookies = lwqq_get_cookies(lc);
if (cookies) {
req->set_header(req, "Cookie", cookies);
s_free(cookies);
}
ret = req->do_request(req, 1, msg);
if (ret) {
*err = LWQQ_EC_NETWORK_ERROR;
goto done;
}
if (req->http_code != 200) {
*err = LWQQ_EC_HTTP_ERROR;
goto done;
}
/**
* Here, we got a json object like this:
* {"retcode":0,"result":{"uin":1421032531,"cip":2013211875,"index":1060,"port":43415,"status":"online","vfwebqq":"e7ce7913336ad0d28de9cdb9b46a57e4a6127161e35b87d09486001870226ec1fca4c2ba31c025c7","psessionid":"8368046764001e636f6e6e7365727665725f77656271714031302e3133332e34312e32303200006b2900001544016e0400533cb3546d0000000a4046674d4652585136496d00000028e7ce7913336ad0d28de9cdb9b46a57e4a6127161e35b87d09486001870226ec1fca4c2ba31c025c7","user_state":0,"f":0}}
*
*/
response = req->response;
ret = json_parse_document(&json, response);
if (ret != JSON_OK) {
*err = LWQQ_EC_ERROR;
goto done;
}
if (!(value = json_parse_simple_value(json, "retcode"))) {
*err = LWQQ_EC_ERROR;
goto done;
}
/**
* Do we need parse "seskey? from kernelhcy's code, we need it,
* but from the response we got like above, we dont need
*
*/
if ((value = json_parse_simple_value(json, "seskey"))) {
lc->seskey = s_strdup(value);
}
if ((value = json_parse_simple_value(json, "cip"))) {
lc->cip = s_strdup(value);
}
if ((value = json_parse_simple_value(json, "index"))) {
lc->index = s_strdup(value);
}
if ((value = json_parse_simple_value(json, "port"))) {
lc->port = s_strdup(value);
//.........这里部分代码省略.........
开发者ID:yet,项目名称:lwqq,代码行数:101,代码来源:login.c
示例7: changedir
/*
* change to a remote directory.
*/
int
changedir(Node *node)
{
Node *to;
String *cdpath;
to = node;
if(to == remdir)
return 0;
/* build an absolute path */
switch(os){
case Tops:
case VM:
switch(node->depth){
case 0:
remdir = node;
return 0;
case 1:
cdpath = s_clone(node->remname);
break;
default:
return seterr(nosuchfile);
}
break;
case VMS:
switch(node->depth){
case 0:
remdir = node;
return 0;
default:
cdpath = s_new();
vmspath(node, cdpath);
}
break;
case MVS:
if(node->depth == 0)
cdpath = s_clone(remrootpath);
else{
cdpath = s_new();
mvspath(node, cdpath);
}
break;
default:
if(node->depth == 0)
cdpath = s_clone(remrootpath);
else{
cdpath = s_new();
unixpath(node, cdpath);
}
break;
}
uncachedir(remdir, 0);
/*
* connect, if we need a password (Incomplete)
* act like it worked (best we can do).
*/
sendrequest("CWD", s_to_c(cdpath));
s_free(cdpath);
switch(getreply(&ctlin, msg, sizeof(msg), 0)){
case Success:
case Incomplete:
remdir = node;
return 0;
default:
return seterr(nosuchfile);
}
}
开发者ID:99years,项目名称:plan9,代码行数:73,代码来源:proto.c
示例8: main
int main(int argc, char **argv)
{
population *popd=NULL; /* Population for Darwinian evolution. */
population *popb=NULL; /* Population for Baldwinian evolution. */
population *popl=NULL; /* Population for Lamarckian evolution. */
char *beststring=NULL; /* Human readable form of best solution. */
size_t beststrlen=0; /* Length of beststring. */
random_seed(23091975);
popd = ga_genesis_char(
150, /* const int population_size */
1, /* const int num_chromo */
(int) strlen(target_text), /* const int len_chromo */
NULL, /* GAgeneration_hook generation_hook */
NULL, /* GAiteration_hook iteration_hook */
NULL, /* GAdata_destructor data_destructor */
NULL, /* GAdata_ref_incrementor data_ref_incrementor */
struggle_score, /* GAevaluate evaluate */
ga_seed_printable_random, /* GAseed seed */
struggle_adaptation, /* GAadapt adapt */
ga_select_one_sus, /* GAselect_one select_one */
ga_select_two_sus, /* GAselect_two select_two */
ga_mutate_printable_singlepoint_drift, /* GAmutate mutate */
ga_crossover_char_allele_mixing, /* GAcrossover crossover */
NULL, /* GAreplace replace */
NULL /* vpointer User data */
);
ga_population_set_parameters(
popd, /* population *pop */
GA_SCHEME_DARWIN, /* const ga_scheme_type scheme */
GA_ELITISM_PARENTS_DIE, /* const ga_elitism_type elitism */
0.9, /* const double crossover */
0.1, /* const double mutation */
0.0 /* const double migration */
);
/*
* Make exact copies of the populations, except modify
* their evolutionary schemes.
*/
popb = ga_population_clone(popd);
ga_population_set_scheme(popb, GA_SCHEME_BALDWIN_CHILDREN);
popl = ga_population_clone(popd);
ga_population_set_scheme(popl, GA_SCHEME_LAMARCK_CHILDREN);
/*
* Evolve each population in turn.
*/
ga_evolution(
popd, /* population *pop */
600 /* const int max_generations */
);
printf( "The final solution with Darwinian evolution with score %f was:\n",
ga_get_entity_from_rank(popd,0)->fitness );
beststring = ga_chromosome_char_to_string(popd, ga_get_entity_from_rank(popd,0), beststring, &beststrlen);
printf("%s\n", beststring);
ga_evolution(
popb, /* population *pop */
300 /* const int max_generations */
);
printf( "The final solution with Baldwinian evolution with score %f was:\n",
ga_get_entity_from_rank(popb,0)->fitness );
beststring = ga_chromosome_char_to_string(popb, ga_get_entity_from_rank(popb,0), beststring, &beststrlen);
printf("%s\n", beststring);
ga_evolution(
popl, /* population *pop */
300 /* const int max_generations */
);
printf( "The final solution with Lamarckian evolution with score %f was:\n",
ga_get_entity_from_rank(popl,0)->fitness );
beststring = ga_chromosome_char_to_string(popl, ga_get_entity_from_rank(popl,0), beststring, &beststrlen);
printf("%s\n", beststring);
/* Deallocate population structures. */
ga_extinction(popd);
ga_extinction(popb);
ga_extinction(popl);
/* Deallocate string buffer. */
s_free(beststring);
exit(EXIT_SUCCESS);
}
开发者ID:versionzero,项目名称:gaul,代码行数:91,代码来源:struggle2.c
示例9: iUtlSignalsIgnoreHandler
/*
Function: iUtlSignalsIgnoreHandler()
Purpose: To set the signal handler to 'ignore', and optionally
recover the current signal handler
Parameters: iSignal signal
ppsaSigAction return pointer for the current
signal action (optional)
Globals: none
Returns: UTL error code
*/
int iUtlSignalsIgnoreHandler
(
int iSignal,
struct sigaction **ppsaSigAction
)
{
int iError = UTL_NoError;
struct sigaction *psaSigAction = NULL;
struct sigaction saSigAction;
sigset_t ssSigSet;
/* Clear the structures */
s_memset(&ssSigSet, 0, sizeof(sigset_t));
s_memset(&saSigAction, 0, sizeof(struct sigaction));
/* Set the structure fields */
saSigAction.sa_handler = SIG_IGN;
saSigAction.sa_mask = ssSigSet;
saSigAction.sa_flags = SA_RESTART;
/* Allocate space for the signal action structure if the return pointer is passed */
if ( ppsaSigAction != NULL ) {
if ( (psaSigAction = (struct sigaction *)s_malloc(sizeof(struct sigaction))) == NULL ) {
iError = UTL_MemError;
goto bailFromiSignalsIgnoreHandler;
}
}
/* Install the signal action */
if ( s_sigaction(iSignal, &saSigAction, psaSigAction) != 0 ) {
iError = UTL_SignalActionInstallFailed;
goto bailFromiSignalsIgnoreHandler;
}
/* Bail label */
bailFromiSignalsIgnoreHandler:
/* Handle the error */
if ( iError == UTL_NoError ) {
/* Set the return pointer if it was passed */
if ( ppsaSigAction != NULL ) {
*ppsaSigAction = psaSigAction;
}
}
else {
/* Free allocations */
s_free(psaSigAction);
}
return (iError);
}
开发者ID:fschiettecatte,项目名称:mps,代码行数:78,代码来源:signals.c
示例10: _readmbox
//
// read in the mailbox and parse into messages.
//
static char*
_readmbox(Mailbox *mb, int doplumb, Mlock *lk)
{
int fd, n;
String *tmp;
Dir *d;
static char err[128];
Message *m, **l;
Inbuf *inb;
char *x;
l = &mb->root->part;
/*
* open the mailbox. If it doesn't exist, try the temporary one.
*/
n = 0;
retry:
fd = open(mb->path, OREAD);
if(fd < 0){
rerrstr(err, sizeof(err));
if(strstr(err, "exclusive lock") != 0 && n++ < 20){
sleep(500); /* wait for lock to go away */
goto retry;
}
if(strstr(err, "exist") != 0){
tmp = s_copy(mb->path);
s_append(tmp, ".tmp");
if(sysrename(s_to_c(tmp), mb->path) == 0){
s_free(tmp);
goto retry;
}
s_free(tmp);
}
return err;
}
/*
* a new qid.path means reread the mailbox, while
* a new qid.vers means read any new messages
*/
d = dirfstat(fd);
if(d == nil){
close(fd);
errstr(err, sizeof(err));
return err;
}
if(mb->d != nil){
if(d->qid.path == mb->d->qid.path && d->qid.vers == mb->d->qid.vers){
close(fd);
free(d);
return nil;
}
if(d->qid.path == mb->d->qid.path){
while(*l != nil)
l = &(*l)->next;
seek(fd, mb->d->length, 0);
}
free(mb->d);
}
mb->d = d;
mb->vers++;
henter(PATH(0, Qtop), mb->name,
(Qid){PATH(mb->id, Qmbox), mb->vers, QTDIR}, nil, mb);
inb = emalloc(sizeof(Inbuf));
inb->rptr = inb->wptr = inb->data;
inb->fd = fd;
// read new messages
snprint(err, sizeof err, "reading '%s'", mb->path);
logmsg(err, nil);
for(;;){
if(lk != nil)
syslockrefresh(lk);
m = newmessage(mb->root);
m->mallocd = 1;
m->inmbox = 1;
if(readmessage(m, inb) < 0){
delmessage(mb, m);
mb->root->subname--;
break;
}
// merge mailbox versions
while(*l != nil){
if(memcmp((*l)->digest, m->digest, SHA1dlen) == 0){
// matches mail we already read, discard
logmsg("duplicate", *l);
delmessage(mb, m);
mb->root->subname--;
m = nil;
l = &(*l)->next;
break;
} else {
// old mail no longer in box, mark deleted
logmsg("disappeared", *l);
//.........这里部分代码省略.........
开发者ID:AustenConrad,项目名称:plan-9,代码行数:101,代码来源:plan9.c
示例11: _writembox
static void
_writembox(Mailbox *mb, Mlock *lk)
{
Dir *d;
Message *m;
String *tmp;
int mode, errs;
Biobuf *b;
tmp = s_copy(mb->path);
s_append(tmp, ".tmp");
/*
* preserve old files permissions, if possible
*/
d = dirstat(mb->path);
if(d != nil){
mode = d->mode&0777;
free(d);
} else
mode = MBOXMODE;
sysremove(s_to_c(tmp));
b = sysopen(s_to_c(tmp), "alc", mode);
if(b == 0){
fprint(2, "can't write temporary mailbox %s: %r\n", s_to_c(tmp));
return;
}
logmsg("writing new mbox", nil);
errs = 0;
for(m = mb->root->part; m != nil; m = m->next){
if(lk != nil)
syslockrefresh(lk);
if(m->deleted)
continue;
logmsg("writing", m);
if(Bwrite(b, m->start, m->end - m->start) < 0)
errs = 1;
if(Bwrite(b, "\n", 1) < 0)
errs = 1;
}
logmsg("wrote new mbox", nil);
if(sysclose(b) < 0)
errs = 1;
if(errs){
fprint(2, "error writing temporary mail file\n");
s_free(tmp);
return;
}
sysremove(mb->path);
if(sysrename(s_to_c(tmp), mb->path) < 0)
fprint(2, "%s: can't rename %s to %s: %r\n", argv0,
s_to_c(tmp), mb->path);
s_free(tmp);
if(mb->d != nil)
free(mb->d);
mb->d = dirstat(mb->path);
}
开发者ID:AustenConrad,项目名称:plan-9,代码行数:62,代码来源:plan9.c
示例12: cssp_connect
//.........这里部分代码省略.........
{
if (i == 0)
error("CredSSP: Initialize failed, do you have correct kerberos tgt initialized ?\n");
else
error("CredSSP: Negotiation failed.\n");
#ifdef WITH_DEBUG_CREDSSP
cssp_gss_report_error(GSS_C_GSS_CODE, "CredSSP: SPNEGO negotiation failed.",
major_status, minor_status);
#endif
goto bail_out;
}
// validate required services
if (!(actual_services & GSS_C_CONF_FLAG))
{
error("CredSSP: Confidiality service required but is not available.\n");
goto bail_out;
}
// Send token to server
if (output_tok.length != 0)
{
if (output_tok.length > token.size)
s_realloc(&token, output_tok.length);
s_reset(&token);
out_uint8p(&token, output_tok.value, output_tok.length);
s_mark_end(&token);
if (!cssp_send_tsrequest(&token, NULL, NULL))
goto bail_out;
(void) gss_release_buffer(&minor_status, &output_tok);
}
// Read token from server
if (major_status & GSS_S_CONTINUE_NEEDED)
{
(void) gss_release_buffer(&minor_status, &input_tok);
if (!cssp_read_tsrequest(&token, NULL))
goto bail_out;
input_tok.value = token.data;
input_tok.length = s_length(&token);
}
else
{
// Send encrypted pubkey for verification to server
context_established = 1;
if (!cssp_gss_wrap(gss_ctx, &pubkey, &blob))
goto bail_out;
if (!cssp_send_tsrequest(NULL, NULL, &blob))
goto bail_out;
context_established = 1;
}
i++;
}
while (!context_established);
// read tsrequest response and decrypt for public key validation
if (!cssp_read_tsrequest(NULL, &blob))
goto bail_out;
if (!cssp_gss_unwrap(gss_ctx, &blob, &pubkey_cmp))
goto bail_out;
pubkey_cmp.data[0] -= 1;
// validate public key
if (memcmp(pubkey.data, pubkey_cmp.data, s_length(&pubkey)) != 0)
{
error("CredSSP: Cannot guarantee integrity of server connection, MITM ? "
"(public key data mismatch)\n");
goto bail_out;
}
// Send TSCredentials
ts_creds = cssp_encode_tscredentials(user, password, domain);
if (!cssp_gss_wrap(gss_ctx, ts_creds, &blob))
goto bail_out;
s_free(ts_creds);
if (!cssp_send_tsrequest(NULL, &blob, NULL))
goto bail_out;
return True;
bail_out:
xfree(token.data);
return False;
}
开发者ID:jeppeter,项目名称:vbox,代码行数:101,代码来源:cssp.c
示例13: cssp_send_tsrequest
RD_BOOL
cssp_send_tsrequest(STREAM token, STREAM auth, STREAM pubkey)
{
STREAM s;
STREAM h1, h2, h3, h4, h5;
struct stream tmp = { 0 };
struct stream message = { 0 };
memset(&message, 0, sizeof(message));
memset(&tmp, 0, sizeof(tmp));
// version [0]
s_realloc(&tmp, sizeof(uint8));
s_reset(&tmp);
out_uint8(&tmp, 2);
s_mark_end(&tmp);
h2 = ber_wrap_hdr_data(BER_TAG_INTEGER, &tmp);
h1 = ber_wrap_hdr_data(BER_TAG_CTXT_SPECIFIC | BER_TAG_CONSTRUCTED | 0, h2);
s_realloc(&message, s_length(&message) + s_length(h1));
out_uint8p(&message, h1->data, s_length(h1));
s_mark_end(&message);
s_free(h2);
s_free(h1);
// negoToken [1]
if (token && s_length(token))
{
h5 = ber_wrap_hdr_data(BER_TAG_OCTET_STRING, token);
h4 = ber_wrap_hdr_data(BER_TAG_CTXT_SPECIFIC | BER_TAG_CONSTRUCTED | 0, h5);
h3 = ber_wrap_hdr_data(BER_TAG_SEQUENCE | BER_TAG_CONSTRUCTED, h4);
h2 = ber_wrap_hdr_data(BER_TAG_SEQUENCE | BER_TAG_CONSTRUCTED, h3);
h1 = ber_wrap_hdr_data(BER_TAG_CTXT_SPECIFIC | BER_TAG_CONSTRUCTED | 1, h2);
s_realloc(&message, s_length(&message) + s_length(h1));
out_uint8p(&message, h1->data, s_length(h1));
s_mark_end(&message);
s_free(h5);
s_free(h4);
s_free(h3);
s_free(h2);
s_free(h1);
}
// authInfo [2]
if (auth && s_length(auth))
{
h2 = ber_wrap_hdr_data(BER_TAG_OCTET_STRING, auth);
h1 = ber_wrap_hdr_data(BER_TAG_CTXT_SPECIFIC | BER_TAG_CONSTRUCTED | 2, h2);
s_realloc(&message, s_length(&message) + s_length(h1));
out_uint8p(&message, h1->data, s_length(h1));
s_free(h2);
s_free(h1);
}
// pubKeyAuth [3]
if (pubkey && s_length(pubkey))
{
h2 = ber_wrap_hdr_data(BER_TAG_OCTET_STRING, pubkey);
h1 = ber_wrap_hdr_data(BER_TAG_CTXT_SPECIFIC | BER_TAG_CONSTRUCTED | 3, h2);
s_realloc(&message, s_length(&message) + s_length(h1));
out_uint8p(&message, h1->data, s_length(h1));
s_mark_end(&message);
s_free(h2);
s_free(h1);
}
s_mark_end(&message);
// Construct ASN.1 Message
// Todo: can h1 be send directly instead of tcp_init() approach
h1 = ber_wrap_hdr_data(BER_TAG_SEQUENCE | BER_TAG_CONSTRUCTED, &message);
s = tcp_init(s_length(h1));
out_uint8p(s, h1->data, s_length(h1));
s_mark_end(s);
s_free(h1);
#if WITH_DEBUG_CREDSSP
streamsave(s, "tsrequest_out.raw");
printf("Out TSRequest %ld bytes\n", s_length(s));
hexdump(s->data, s_length(s));
#endif
tcp_send(s);
// cleanup
xfree(message.data);
xfree(tmp.data);
return True;
}
开发者ID:jeppeter,项目名称:vbox,代码行数:92,代码来源:cssp.c
示例14: cssp_encode_tscredentials
STREAM
cssp_encode_tscredentials(char *username, char *password, char *domain)
{
STREAM out;
STREAM h1, h2, h3;
struct stream tmp = { 0 };
struct stream message = { 0 };
// credType [0]
s_realloc(&tmp, sizeof(uint8));
s_reset(&tmp);
if (g_use_password_as_pin == False)
{
out_uint8(&tmp, 1); // TSPasswordCreds
}
else
{
out_uint8(&tmp, 2); // TSSmartCardCreds
}
s_mark_end(&tmp);
h2 = ber_wrap_hdr_data(BER_TAG_INTEGER, &tmp);
h1 = ber_wrap_hdr_data(BER_TAG_CTXT_SPECIFIC | BER_TAG_CONSTRUCTED | 0, h2);
s_realloc(&message, s_length(&message) + s_length(h1));
out_uint8p(&message, h1->data, s_length(h1));
s_mark_end(&message);
s_free(h2);
s_free(h1);
// credentials [1]
if (g_use_password_as_pin == False)
{
h3 = cssp_encode_tspasswordcreds(username, password, domain);
}
else
{
h3 = cssp_encode_tssmartcardcreds(username, password, domain);
}
h2 = ber_wrap_hdr_data(BER_TAG_OCTET_STRING, h3);
h1 = ber_wrap_hdr_data(BER_TAG_CTXT_SPECIFIC | BER_TAG_CONSTRUCTED | 1, h2);
s_realloc(&message, s_length(&message) + s_length(h1));
out_uint8p(&message, h1->data, s_length(h1));
s_mark_end(&message);
s_free(h3);
s_free(h2);
s_free(h1);
// Construct ASN.1 message
out = ber_wrap_hdr_data(BER_TAG_SEQUENCE | BER_TAG_CONSTRUCTED, &message);
#if WITH_DEBUG_CREDSSP
streamsave(out, "tscredentials.raw");
printf("Out TSCredentials %ld bytes\n", s_length(out));
hexdump(out->data, s_length(out));
#endif
// cleanup
xfree(message.data);
xfree(tmp.data);
return out;
}
开发者ID:jeppeter,项目名称:vbox,代码行数:63,代码来源:cssp.c
示例15: do_login
/**
* Do really login
*
* @param lc
* @param md5 The md5 calculated from calculate_password_md5()
* @param err
*/
static void do_login(LwqqClient *lc, const char *md5, LwqqErrorCode *err)
{
char url[1024];
LwqqHttpRequest *req;
char *response = NULL;
char *cookies;
int ret;
snprintf(url, sizeof(url), "%s/login?u=%s&p=%s&verifycode=%s&"
"webqq_type=10&remember_uin=1&aid=1003903&login2qq=1&"
"u1=http%%3A%%2F%%2Fweb.qq.com%%2Floginproxy.html"
"%%3Flogin2qq%%3D1%%26webqq_type%%3D10&h=1&ptredirect=0&"
"ptlang=2052&from_ui=1&pttype=1&dumy=&fp=loginerroralert&"
"action=2-11-7438&mibao_css=m_webqq&t=1&g=1", LWQQ_URL_LOGIN_HOST, lc->username, md5, lc->vc->str);
req = lwqq_http_create_default_request(url, err);
if (!req) {
goto done;
}
/* Setup http header */
cookies = lwqq_get_cookies(lc);
if (cookies) {
req->set_header(req, "Cookie", cookies);
s_free(cookies);
}
/* Send request */
ret = req->do_request(req, 0, NULL);
if (ret) {
*err = LWQQ_EC_NETWORK_ERROR;
goto done;
}
if (req->http_code != 200) {
*err = LWQQ_EC_HTTP_ERROR;
goto done;
}
response = req->response;
char *p = strstr(response, "\'");
if (!p) {
*err = LWQQ_EC_ERROR;
goto done;
}
char buf[4] = {0};
int status;
strncpy(buf, p + 1, 1);
status = atoi(buf);
switch (status) {
case 0:
if (sava_cookie(lc, req, err)) {
goto done;
}
break;
case 1:
lwqq_log(LOG_WARNING, "Server busy! Please try again\n");
*err = LWQQ_EC_ERROR;
goto done;
case 2:
lwqq_log(LOG_ERROR, "Out of date QQ number\n");
*err = LWQQ_EC_ERROR;
goto done;
case 3:
lwqq_log(LOG_ERROR, "Wrong password\n");
*err = LWQQ_EC_ERROR;
goto done;
case 4:
lwqq_log(LOG_ERROR, "Wrong verify code\n");
*err = LWQQ_EC_ERROR;
goto done;
case 5:
lwqq_log(LOG_ERROR, "Verify failed\n");
*err = LWQQ_EC_ERROR;
goto done;
case 6:
lwqq_log(LOG_WARNING, "You may need to try login again\n");
*err = LWQQ_EC_ERROR;
goto done;
case 7:
lwqq_log(LOG_ERROR, "Wrong input\n");
*err = LWQQ_EC_ERROR;
goto done;
case 8:
lwqq_log(LOG_ERROR, "Too many logins on this IP. Please try again\n");
*err = LWQQ_EC_ERROR;
//.........这里部分代码省略.........
开发者ID:yet,项目名称:lwqq,代码行数:101,代码来源:login.c
示例16: pipemsg
//.........这里部分代码省略.........
}
if(destination == 0){
nbytes += Bprint(pp->std[0]->fp, "To: ");
for(l = rcvers.first; l; l = l->next){
if(l != rcvers.first)
nbytes += Bprint(pp->std[0]->fp, ", ");
nbytes += Bprint(pp->std[0]->fp, "%s", s_to_c(l->p));
}
nbytes += Bprint(pp->std[0]->fp, "\n");
}
/*
* add sender's domain to any domainless addresses
* (to avoid forging local addresses)
*/
cp = s_to_c(hdr);
for(f = firstfield; cp != nil && f; f = f->next){
for(p = f->node; cp != 0 && p; p = p->next) {
bpr = 0;
cp = bprintnode(pp->std[0]->fp, p, &bpr);
nbytes += bpr;
}
if(status == 0 && Bprint(pp->std[0]->fp, "\n") < 0){
piperror = "write error";
status = 1;
}
nbytes++; /* for newline */
}
if(cp == nil){
piperror = "sender domain";
status = 1;
}
/* write anything we read following the header */
nonhdr = s_to_c(hdr) + s_len(hdr) - cp;
if(status == 0 && Bwrite(pp->std[0]->fp, cp, nonhdr) < 0){
piperror = "write error 2";
status = 1;
}
nbytes += nonhdr;
s_free(hdr);
/*
* pass rest of message to mailer. take care of '.'
* escapes.
*/
while(sawdot == 0){
n = getcrnl(s_reset(line), &bin);
/* eof or error ends the message */
if(n <= 0)
break;
/* a line with only a '.' ends the message */
cp = s_to_c(line);
if(n == 2 && *cp == '.' && *(cp+1) == '\n'){
sawdot = 1;
break;
}
if(cp[0] == '.'){
cp++;
n--;
}
nbytes += n;
if(status == 0 && Bwrite(pp->std[0]->fp, cp, n) < 0){
piperror = "write error 3";
status = 1;
}
}
s_free(line);
if(sawdot == 0){
/* message did not terminate normally */
snprint(pipbuf, sizeof pipbuf, "network eof: %r");
piperror = pipbuf;
if (pp->pid > 0) {
syskillpg(pp->pid);
/* none can't syskillpg, so try a variant */
sleep(500);
syskill(pp->pid);
}
status = 1;
}
if(status == 0 && Bflush(pp->std[0]->fp) < 0){
piperror = "write error 4";
status = 1;
}
if (debug) {
stamp();
fprint(2, "at end of message; %s .\n",
(sawdot? "saw": "didn't see"));
}
stream_free(pp->std[0]);
pp->std[0] = 0;
*byteswritten = nbytes;
pipesigoff();
if(status && !piperror)
piperror = "write on closed pipe";
return status;
}
开发者ID:99years,项目名称:plan9,代码行数:101,代码来源:smtpd.c
示例17: update_cookies
/**
* Update the cookies needed by webqq
*
* @param req
* @param key
* @param value
* @param update_cache Weather update lwcookies member
*/
static void update_cookies(LwqqCookies *cookies, LwqqHttpRequest *req,
const char *key, int update_cache)
{
if (!cookies || !req || !key) {
lwqq_log(LOG_ERROR, "Null pointer access\n");
return ;
}
char *value = req->get_cookie(req, key);
if (!value)
return ;
#define FREE_AND_STRDUP(a, b) \
if (a) \
s_free(a); \
a = s_strdup(b);
if (!strcmp(key, "ptvfsession")) {
FREE_AND_STRDUP(cookies->ptvfsession, value);
} else if (!strcmp(key, "ptcz")) {
FREE_AND_STRDUP(cookies->ptcz, value);
} else if (!strcmp(key, "skey")) {
FREE_AND_STRDUP(cookies->skey, value);
} else if (!strcmp(key, "ptwebqq")) {
FREE_AND_STRDUP(cookies->ptwebqq, value);
} else if (!strcmp(key, "ptuserinfo")) {
FREE_AND_STRDUP(cookies->ptuserinfo, value);
} else if (!strcmp(key, "uin")) {
FREE_AND_STRDUP(cookies->uin, value);
} else if (!strcmp(key, "ptisp")) {
FREE_AND_STRDUP(cookies->ptisp, value);
} else if (!strcmp(key, "pt2gguin")) {
FREE_AND_STRDUP(cookies->pt2gguin, value);
} else if (!strcmp(key, "verifysession")) {
FREE_AND_STRDUP(cookies->verifysession, value);
} else {
lwqq_log(LOG_WARNING, "No this cookie: %s\n", key);
}
s_free(value);
if (update_cache) {
char buf[4096] = {0}; /* 4K is enough for cookies. */
int buflen = 0;
if (cookies->ptvfsession) {
snprintf(buf, sizeof(buf), "ptvfsession=%s; ", cookies->ptvfsession);
buflen = strlen(buf);
}
if (cookies->ptcz) {
snprintf(buf + buflen, sizeof(buf) - buflen, "ptcz=%s; ", cookies->ptcz);
buflen = strlen(buf);
}
if (cookies->skey) {
snprintf(buf + buflen, sizeof(buf) - buflen, "skey=%s; ", cookies->skey);
buflen = strlen(buf);
}
if (cookies->ptwebqq) {
snprintf(buf + buflen, sizeof(buf) - buflen, "ptwebqq=%s; ", cookies->ptwebqq);
buflen = strlen(buf);
}
if (cookies->ptuserinfo) {
snprintf(buf + buflen, sizeof(buf) - buflen, "ptuserinfo=%s; ", cookies->ptuserinfo);
buflen = strlen(buf);
}
if (cookies->uin) {
snprintf(buf + buflen, sizeof(buf) - buflen, "uin=%s; ", cookies->uin);
buflen = strlen(buf);
}
if (cookies->ptisp) {
snprintf(buf + buflen, sizeof(buf) - buflen, "ptisp=%s; ", cookies->ptisp);
buflen = strlen(buf);
}
if (cookies->pt2gguin) {
snprintf(buf + buflen, sizeof(buf) - buflen, "pt2gguin=%s; ", cookies->pt2gguin);
buflen = strlen(buf);
}
if (cookies->verifysession) {
snprintf(buf + buflen, sizeof(buf) - buflen, "verifysession=%s; ", cookies->verifysession);
buflen = strlen(buf);
}
FREE_AND_STRDUP(cookies->lwcookies, buf);
}
#undef FREE_AND_STRDUP
}
开发者ID:yet,项目名称:lwqq,代码行数:92,代码来源:login.c
示例18: data
//.........这里部分代码省略.........
* allow 145 more minutes to move the data
*/
alarm(145*60*1000);
status = pipemsg(&nbytes);
/*
* read any error messages
*/
err = s_new();
if (debug) {
stamp();
fprint(2, "waiting for upas/send to close stderr\n");
}
while(s_read_line(pp->std[2]->fp, err))
;
alarm(0);
atnotify(catchalarm, 0);
if (debug) {
stamp();
fprint(2, "waiting for upas/send to exit\n");
}
status |= proc_wait(pp);
if(debug){
seek(2, 0, 2);
stamp();
fprint(2, "# %d upas/send status %#ux at %s\n",
getpid(), status, thedate());
if(*s_to_c(err))
fprint(2, "# %d
|
请发表评论