cyrus-imapd-2.4.17-caldav-beta9/0000775000175000017500000000000012253670416014420 5ustar kenkencyrus-imapd-2.4.17-caldav-beta9/perl/0000775000175000017500000000000012253670273015363 5ustar kenkencyrus-imapd-2.4.17-caldav-beta9/perl/sieve/0000775000175000017500000000000012253670273016476 5ustar kenkencyrus-imapd-2.4.17-caldav-beta9/perl/sieve/managesieve/0000775000175000017500000000000012253670273020762 5ustar kenkencyrus-imapd-2.4.17-caldav-beta9/perl/sieve/managesieve/Makefile.PL0000664000175000017500000000534712253670273022745 0ustar kenken# # Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # 3. The name "Carnegie Mellon University" must not be used to # endorse or promote products derived from this software without # prior written permission. For permission or any legal # details, please contact # Carnegie Mellon University # Center for Technology Transfer and Enterprise Creation # 4615 Forbes Avenue # Suite 302 # Pittsburgh, PA 15213 # (412) 268-7393, fax: (412) 268-7395 # innovation@andrew.cmu.edu # # 4. Redistributions of any form whatsoever must retain the following # acknowledgment: # "This product includes software developed by Computing Services # at Carnegie Mellon University (http://www.cmu.edu/computing/)." # # CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO # THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE # FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN # AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING # OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # # $Id: Makefile.PL,v 1.17 2010/01/06 17:01:56 murch Exp $ # use ExtUtils::MakeMaker; use Config; my $SASL_INC = $ENV{SASL_INC}; my $SASL_LIB = $ENV{SASL_LIB} || "-lsasl2"; my $OPENSSL_INC = $ENV{OPENSSL_INC}; my $OPENSSL_LIB = $ENV{OPENSSL_LIB}; my $BDB_INC = $ENV{BDB_INC}; my $BDB_LIB = $ENV{BDB_LIB}; my $LIB_RT = $ENV{LIB_RT}; my $ZLIB = $ENV{ZLIB}; $libs = "-lcyrus"; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Cyrus::SIEVE::managesieve', 'ABSTRACT' => 'Cyurs Sieve management interface', 'VERSION_FROM' => 'managesieve.pm', # finds $VERSION 'MYEXTLIB' => '../lib/isieve.o ../lib/lex.o ../lib/mystring.o ../lib/request.o ../../../lib/libcyrus.a ../../../lib/libcyrus_min.a', 'LIBS' => ["$BDB_LIB $SASL_LIB $OPENSSL_LIB $LIB_RT $ZLIB -lssl -lcrypto"], 'DEFINE' => '-DPERL_POLLUTE', # e.g., '-DHAVE_SOMETHING' 'INC' => "-I../lib/ -I../../../lib/ $SASL_INC $OPENSSL_INC", ); cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/managesieve/typemap0000664000175000017500000000044712253670273022371 0ustar kenkenTYPEMAP unsigned * T_PTROBJ unsigned char ** T_PTROBJ acapsieve_list_cb_t * T_PTROBJ Sieveobj T_PTROBJ_SPECIAL INPUT T_PTROBJ_SPECIAL IV tmp = SvIV((SV*)SvRV($arg)); $var = ($type) tmp; OUTPUT T_PTROBJ_SPECIAL sv_setref_pv($arg, \"${(my $ntt=$ntype)=~s/_/::/g;\$ntt}\", (void *) $var); cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/managesieve/MANIFEST0000664000175000017500000000037612253670273022121 0ustar kenkenMakefile.PL Build Makefile for Cyrus::sieve::managesieve managesieve.h include file managesieve.pm Cyrus::sieve::managesieve perl module managesieve.xs Perl interface routines for calling C typemap Typemap defining Perl "class" MANIFEST This file cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/managesieve/managesieve.h0000664000175000017500000000376012253670273023425 0ustar kenken/* * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "Carnegie Mellon University" must not be used to * endorse or promote products derived from this software without * prior written permission. For permission or any legal * details, please contact * Carnegie Mellon University * Center for Technology Transfer and Enterprise Creation * 4615 Forbes Avenue * Suite 302 * Pittsburgh, PA 15213 * (412) 268-7393, fax: (412) 268-7395 * innovation@andrew.cmu.edu * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by Computing Services * at Carnegie Mellon University (http://www.cmu.edu/computing/)." * * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $Id: managesieve.h,v 1.7 2010/01/06 17:01:56 murch Exp $ */ #include "isieve.h" struct xscyrus { isieve_t *isieve; char *errstr; /* last error, if any */ char *class; /* needed by perl */ }; cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/managesieve/managesieve.pm0000664000175000017500000000715412253670273023613 0ustar kenken# # Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # 3. The name "Carnegie Mellon University" must not be used to # endorse or promote products derived from this software without # prior written permission. For permission or any legal # details, please contact # Carnegie Mellon University # Center for Technology Transfer and Enterprise Creation # 4615 Forbes Avenue # Suite 302 # Pittsburgh, PA 15213 # (412) 268-7393, fax: (412) 268-7395 # innovation@andrew.cmu.edu # # 4. Redistributions of any form whatsoever must retain the following # acknowledgment: # "This product includes software developed by Computing Services # at Carnegie Mellon University (http://www.cmu.edu/computing/)." # # CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO # THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE # FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN # AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING # OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # # $Id: managesieve.pm,v 1.10 2010/01/06 17:01:56 murch Exp $ # package Cyrus::SIEVE::managesieve; use strict; use Carp; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD); require Exporter; require DynaLoader; @ISA = qw(Exporter DynaLoader); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. @EXPORT = qw( sieve_get_handle sieve_get_error sieve_get_global_error sieve_put_file sieve_put_file_withdest sieve_put sieve_delete sieve_list sieve_activate sieve_get sieve_logout ); $VERSION = '0.01'; sub AUTOLOAD { # This AUTOLOAD is used to 'autoload' constants from the constant() # XS function. If a constant is not found then control is passed # to the AUTOLOAD in AutoLoader. my $constname; ($constname = $AUTOLOAD) =~ s/.*:://; my $val = constant($constname, @_ ? $_[0] : 0); if ($! != 0) { if ($! =~ /Invalid/) { $AutoLoader::AUTOLOAD = $AUTOLOAD; goto &AutoLoader::AUTOLOAD; } else { croak "Your vendor has not defined Cyrus::SIEVE::managesieve macro $constname"; } } eval "sub $AUTOLOAD { $val }"; goto &$AUTOLOAD; } bootstrap Cyrus::SIEVE::managesieve $VERSION; # Preloaded methods go here. # Autoload methods go after =cut, and are processed by the autosplit program. 1; __END__ # Below is the stub of documentation for your module. You better edit it! =head1 NAME Cyrus::SIEVE::managesieve - Perl extension for blah blah blah =head1 SYNOPSIS use Cyrus::SIEVE::managesieve; blah blah blah =head1 DESCRIPTION Call sieve_get_handle to get a handle for further calls. sieve_get_error will return a string representing the last error, if any. Blah blah blah. =head1 AUTHOR T. Martin, tmartin@andrew.cmu.edu =head1 SEE ALSO perl(1). =cut cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/managesieve/managesieve.xs0000664000175000017500000002256312253670273023632 0ustar kenken/* * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "Carnegie Mellon University" must not be used to * endorse or promote products derived from this software without * prior written permission. For permission or any legal * details, please contact * Carnegie Mellon University * Center for Technology Transfer and Enterprise Creation * 4615 Forbes Avenue * Suite 302 * Pittsburgh, PA 15213 * (412) 268-7393, fax: (412) 268-7395 * innovation@andrew.cmu.edu * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by Computing Services * at Carnegie Mellon University (http://www.cmu.edu/computing/)." * * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $Id: managesieve.xs,v 1.30 2010/01/06 17:01:56 murch Exp $ */ #ifdef __cplusplus extern "C" { #endif #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #ifdef __cplusplus } #endif #include "managesieve.h" #include #include #include #include #include #include typedef struct xscyrus *Sieveobj; static char *globalerr = NULL; #include "isieve.h" #include "util.h" #include "xmalloc.h" void fatal(const char *s, int t) { croak("failure: %s", s); exit(-1); } static int perlsieve_getpass(conn, context, id, psecret) sasl_conn_t *conn; void *context; int id; sasl_secret_t **psecret; { int count; dSP ; char *tmp; SV * func = (SV *) context; ENTER ; SAVETMPS; PUSHMARK(sp) ; XPUSHs(sv_2mortal(newSVpv("password", 0))); XPUSHs(sv_2mortal(newSVpv("Please enter your password", 0))); PUTBACK ; count = perl_call_sv(func, G_SCALAR); SPAGAIN ; if (count != 1) croak("Big trouble\n") ; tmp = POPp; /* copy result */ *psecret = malloc(sizeof(sasl_secret_t) + strlen(tmp) + 2); if (!*psecret) return SASL_NOMEM; strcpy((char *) (*psecret)->data ,tmp); (*psecret)->len = strlen(tmp); PUTBACK ; FREETMPS ; LEAVE ; PUTBACK ; return SASL_OK; } static int perlsieve_simple(context, id, result, len) void *context; int id; unsigned char **result; unsigned *len; { int count; dSP ; char *tmp; SV * func = (SV *) context; ENTER ; SAVETMPS; PUSHMARK(sp) ; if (id == SASL_CB_USER) { XPUSHs(sv_2mortal(newSVpv("username", 0))); XPUSHs(sv_2mortal(newSVpv("Please enter your username", 0))); } else if (id == SASL_CB_AUTHNAME) { XPUSHs(sv_2mortal(newSVpv("authname", 0))); XPUSHs(sv_2mortal(newSVpv("Please enter your authentication name", 0))); } else if (id == SASL_CB_GETREALM) { XPUSHs(sv_2mortal(newSVpv("realm", 0))); XPUSHs(sv_2mortal(newSVpv("Please enter your realm", 0))); } else { croak("Bad callback\n"); return SASL_FAIL; } PUTBACK ; count = perl_call_sv(func, G_SCALAR); SPAGAIN ; if (count != 1) croak("Big trouble\n") ; tmp = POPp; /* copy result */ *result = malloc(strlen(tmp) + 2); if (!*result) return SASL_NOMEM; strcpy((char *) *result, tmp); if (len) *len = strlen((char *) *result); PUTBACK ; FREETMPS ; LEAVE ; PUTBACK ; return SASL_OK; } static void * call_listcb(unsigned char *name, int isactive, void *rock) { dSP ; PUSHMARK(sp) ; XPUSHs(sv_2mortal(newSVpv((const char *) name, 0))); XPUSHs(sv_2mortal(newSViv(isactive))); PUTBACK ; /* call perl func */ perl_call_sv((SV *)rock, G_DISCARD) ; return NULL; } MODULE = Cyrus::SIEVE::managesieve PACKAGE = Cyrus::SIEVE::managesieve PROTOTYPES: ENABLE Sieveobj sieve_get_handle(servername, username_cb, authname_cb, password_cb, realm_cb) char *servername SV *username_cb SV *authname_cb SV *password_cb SV *realm_cb PREINIT: Sieveobj ret = NULL; sasl_callback_t *callbacks; int port; int r; struct servent *serv; char *mechlist=NULL,*mlist=NULL; const char *mtried; isieve_t *obj; char *p; sasl_ssf_t ssf; CODE: /* xxx this gets leaked! */ callbacks = safemalloc(5 * sizeof(sasl_callback_t)); callbacks[0].id = SASL_CB_USER; callbacks[0].proc = &perlsieve_simple; callbacks[0].context = username_cb; callbacks[1].id = SASL_CB_AUTHNAME; callbacks[1].proc = &perlsieve_simple; callbacks[1].context = authname_cb; callbacks[2].id = SASL_CB_GETREALM; callbacks[2].proc = &perlsieve_simple; callbacks[2].context = realm_cb; callbacks[3].id = SASL_CB_PASS; callbacks[3].proc = &perlsieve_getpass; callbacks[3].context = password_cb; callbacks[4].id = SASL_CB_LIST_END; /* see if we have server:port (or IPv6, etc)*/ p = servername; if (*servername == '[') { if ((p = strrchr(servername + 1, ']')) != NULL) { *p++ = '\0'; servername++; /* skip first bracket */ } else p = servername; } if ((p = strchr(p, ':'))) { *p++ = '\0'; port = atoi(p); } else { /* map port -> num */ serv = getservbyname("sieve", "tcp"); if (serv == NULL) { port = 2000; } else { port = ntohs(serv->s_port); } } if (init_net(servername, port, &obj)) { globalerr = "network initialization failed"; XSRETURN_UNDEF; } if (init_sasl(obj, 128, callbacks)) { globalerr = "sasl initialization failed"; XSRETURN_UNDEF; } ret = malloc(sizeof(struct xscyrus)); ret->class = safemalloc(20); strcpy(ret->class,"managesieve"); ret->isieve = obj; ret->errstr = NULL; mechlist=read_capability(obj); if(!mechlist) { globalerr = "sasl mech list empty"; XSRETURN_UNDEF; } mlist = (char*) xstrdup(mechlist); if(!mlist) { globalerr = "could not allocate memory for mech list"; XSRETURN_UNDEF; } /* loop through all the mechanisms */ do { mtried = NULL; r = auth_sasl(mlist, obj, &mtried, &ssf, &globalerr); if(r) init_sasl(obj, 128, callbacks); if(mtried) { char *newlist = (char*) xmalloc(strlen(mlist)+1); char *mtr = (char*) xstrdup(mtried); char *tmp; ucase(mtr); tmp = strstr(mlist,mtr); *tmp ='\0'; strcpy(newlist, mlist); tmp++; tmp = strchr(tmp,' '); if (tmp) { strcat(newlist,tmp); } free(mtr); free(mlist); mlist = newlist; } } while (r && mtried); if(r) { /* we failed */ safefree(ret->class); free(ret); XSRETURN_UNDEF; } if (ssf) { /* SASL security layer negotiated -- check if SASL mech list changed */ if (detect_mitm(obj, mechlist)) { globalerr = "possible MITM attack: " "list of available SASL mechamisms changed"; free(mechlist); XSRETURN_UNDEF; } } free(mechlist); ST(0) = sv_newmortal(); sv_setref_pv(ST(0), ret->class, (void *) ret); char * sieve_get_error(obj) Sieveobj obj CODE: RETVAL = obj->errstr; OUTPUT: RETVAL char * sieve_get_global_error() CODE: RETVAL = globalerr; OUTPUT: RETVAL int sieve_logout(obj) Sieveobj obj CODE: /* xxx this leaves the object unusable */ isieve_logout(&(obj->isieve)); XSRETURN_UNDEF; int sieve_put_file(obj, filename) Sieveobj obj char *filename CODE: RETVAL = isieve_put_file(obj->isieve, filename, NULL, &obj->errstr); OUTPUT: RETVAL int sieve_put_file_withdest(obj, filename, destname) Sieveobj obj char *filename char *destname CODE: RETVAL = isieve_put_file(obj->isieve, filename, destname, &obj->errstr); OUTPUT: RETVAL int sieve_put(obj,name,data) Sieveobj obj char *name char *data CODE: RETVAL = isieve_put(obj->isieve, name, data, strlen(data), &obj->errstr); OUTPUT: RETVAL int sieve_delete(obj,name) Sieveobj obj char *name CODE: RETVAL = isieve_delete(obj->isieve, name, &obj->errstr); OUTPUT: RETVAL int sieve_list(obj,cb) Sieveobj obj SV *cb CODE: RETVAL = isieve_list(obj->isieve, (isieve_listcb_t *) &call_listcb, cb, &obj->errstr); OUTPUT: RETVAL int sieve_activate(obj,name) Sieveobj obj char *name CODE: RETVAL = isieve_activate(obj->isieve, name, &obj->errstr); OUTPUT: RETVAL int sieve_get(obj,name,output) Sieveobj obj char *name char *output CODE: RETVAL = isieve_get(obj->isieve, name, &output, &obj->errstr); OUTPUT: RETVAL output cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/managesieve/.cvsignore0000664000175000017500000000006612253670273022764 0ustar kenkenMakefile blib managesieve.bs managesieve.c pm_to_blib cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/lib/0000775000175000017500000000000012253670273017244 5ustar kenkencyrus-imapd-2.4.17-caldav-beta9/perl/sieve/lib/isieve.c0000664000175000017500000004521012253670273020676 0ustar kenken/* * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "Carnegie Mellon University" must not be used to * endorse or promote products derived from this software without * prior written permission. For permission or any legal * details, please contact * Carnegie Mellon University * Center for Technology Transfer and Enterprise Creation * 4615 Forbes Avenue * Suite 302 * Pittsburgh, PA 15213 * (412) 268-7393, fax: (412) 268-7395 * innovation@andrew.cmu.edu * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by Computing Services * at Carnegie Mellon University (http://www.cmu.edu/computing/)." * * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $Id: isieve.c,v 1.37 2010/01/06 17:01:56 murch Exp $ */ #ifdef HAVE_CONFIG_H #include #endif #ifdef HAVE_UNISTD_H #include #endif #include #include #include #include #include #include #include #include #include #include "isieve.h" #include "lex.h" #include "request.h" #include "iptostring.h" #include "xmalloc.h" #include "util.h" #include struct iseive_s { char *serverFQDN; int port; int sock; sasl_conn_t *conn; sasl_callback_t *callbacks; char *refer_authinfo; sasl_callback_t *refer_callbacks; int version; struct protstream *pin; struct protstream *pout; }; void fillin_interactions(sasl_interact_t *tlist); /* we need this separate from the free() call so that we can reuse * the same memory for referrals */ static void sieve_dispose(isieve_t *obj) { if(!obj) return; sasl_dispose(&obj->conn); free(obj->serverFQDN); if (obj->refer_authinfo) free(obj->refer_authinfo); if (obj->refer_callbacks) free(obj->refer_callbacks); prot_free(obj->pin); prot_free(obj->pout); } void sieve_free_net(isieve_t *obj) { sieve_dispose(obj); free(obj); } /* initialize the network */ int init_net(char *serverFQDN, int port, isieve_t **obj) { struct addrinfo hints, *res0, *res; int err; char portstr[6]; int sock = -1; snprintf(portstr, sizeof(portstr), "%d", port); memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; if ((err = getaddrinfo(serverFQDN, portstr, &hints, &res0)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(err)); return -1; } for (res = res0; res; res = res->ai_next) { sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (sock < 0) continue; if (connect(sock, res->ai_addr, res->ai_addrlen) >= 0) break; close(sock); sock = -1; } freeaddrinfo(res0); if (sock < 0) { perror("connect"); return -1; } *obj = (isieve_t *) xmalloc(sizeof(isieve_t)); if (!*obj) return -1; memset(*obj, '\0', sizeof(isieve_t)); (*obj)->sock = sock; (*obj)->serverFQDN = xstrdup(serverFQDN); (*obj)->port = port; /* set up the prot layer */ (*obj)->pin = prot_new(sock, 0); (*obj)->pout = prot_new(sock, 1); return 0; } static sasl_security_properties_t *make_secprops(int min,int max) { sasl_security_properties_t *ret=(sasl_security_properties_t *) xmalloc(sizeof(sasl_security_properties_t)); ret->maxbufsize=1024; ret->min_ssf=min; ret->max_ssf=max; /* should make this configurable */ ret->security_flags=SASL_SEC_NOANONYMOUS; ret->property_names=NULL; ret->property_values=NULL; return ret; } /* * Initialize SASL and set necessary options */ int init_sasl(isieve_t *obj, int ssf, sasl_callback_t *callbacks) { static int sasl_started = 0; int saslresult = SASL_OK; sasl_security_properties_t *secprops=NULL; socklen_t addrsize=sizeof(struct sockaddr_storage); struct sockaddr_storage saddr_l, saddr_r; char localip[60], remoteip[60]; /* attempt to start sasl */ if(!sasl_started) { saslresult=sasl_client_init(NULL); obj->conn = NULL; sasl_started = 1; } /* Save the callbacks array */ obj->callbacks = callbacks; if (saslresult!=SASL_OK) return -1; addrsize=sizeof(struct sockaddr_storage); if (getpeername(obj->sock,(struct sockaddr *)&saddr_r,&addrsize)!=0) return -1; addrsize=sizeof(struct sockaddr_storage); if (getsockname(obj->sock,(struct sockaddr *)&saddr_l,&addrsize)!=0) return -1; #if 0 /* XXX The following line causes problems with KERBEROS_V4 decoding. * We're not sure why its an issue, but this code isn't used in any of * our other client code (imtest.c, backend.c), so we're removing it. */ /* set the port manually since getsockname is stupid and doesn't */ ((struct sockaddr_in *)&saddr_l)->sin_port = htons(obj->port); #endif if (iptostring((struct sockaddr *)&saddr_r, addrsize, remoteip, 60)) return -1; if (iptostring((struct sockaddr *)&saddr_l, addrsize, localip, 60)) return -1; if(obj->conn) sasl_dispose(&obj->conn); /* client new connection */ saslresult=sasl_client_new(SIEVE_SERVICE_NAME, obj->serverFQDN, localip, remoteip, callbacks, SASL_SUCCESS_DATA, &obj->conn); if (saslresult!=SASL_OK) return -1; /* create a security structure and give it to sasl */ secprops = make_secprops(0, ssf); if (secprops != NULL) { sasl_setprop(obj->conn, SASL_SEC_PROPS, secprops); free(secprops); } return 0; } char * read_capability(isieve_t *obj) { lexstate_t state; char *cap = NULL; obj->version = NEW_VERSION; while (yylex(&state,obj->pin)==STRING) { char *attr = string_DATAPTR(state.str); char *val; val = NULL; if (yylex(&state,obj->pin)==' ') { if (yylex(&state,obj->pin)!=STRING) { parseerror("STRING"); } val = xstrdup(string_DATAPTR(state.str)); if (yylex(&state,obj->pin)!=EOL) { parseerror("EOL1"); } } if (strcasecmp(attr,"SASL")==0) { free(cap); cap = val ? xstrdup(val) : NULL; } else if (strcasecmp(attr,"SIEVE")==0) { } else if (strcasecmp(attr,"IMPLEMENTATION")==0) { } else if (strcasecmp(attr,"STARTTLS")==0) { /* TODO */ } else if (val && strncmp(val,"SASL=",5)==0) { int len = strlen(val); obj->version = OLD_VERSION; free(cap); cap = (char *) xmalloc(len+1); memset(cap, '\0', len); memcpy(cap, val+5, len-6); free(val); return cap; } else { /* unknown capability */ } free(val); } if (yylex(&state,obj->pin)!=EOL) { parseerror("EOL2"); } return cap; } int detect_mitm(isieve_t *obj, char *mechlist) { char *new_mechlist; int ch, r = 0; /* wait and probe for possible automatic capability response */ usleep(250000); prot_NONBLOCK(obj->pin); if ((ch = prot_getc(obj->pin)) != EOF) { /* automatic capability response */ prot_ungetc(ch, obj->pin); } else { /* manually ask for capabilities */ prot_printf(obj->pout, "CAPABILITY\r\n"); prot_flush(obj->pout); } prot_BLOCK(obj->pin); if ((new_mechlist = read_capability(obj))) { /* if the server still advertises SASL mechs, compare lists */ r = strcmp(new_mechlist, mechlist); free(new_mechlist); } return r; } static int getauthline(isieve_t *obj, char **line, unsigned int *linelen, char **errstrp) { lexstate_t state; int res; int ret; size_t len; mystring_t *errstr; char *last_send; /* now let's see what the server said */ res=yylex(&state, obj->pin); *line = NULL; if (res!=STRING) { ret = handle_response(res,obj->version, obj->pin, &last_send, &errstr); if (res==TOKEN_OK) { /* Was there a last send from the server? */ if(last_send) { /* it's base64 encoded */ int last_send_len = strlen(last_send); len = last_send_len*2+1; *line = xmalloc(len); sasl_decode64(last_send, last_send_len, *line, len, linelen); free(last_send); } return STAT_OK; } else { /* server said no or bye*/ /* xxx handle referrals */ *errstrp = string_DATAPTR(errstr); return STAT_NO; } } len = state.str->len*2+1; *line=(char *) xmalloc(len); sasl_decode64(string_DATAPTR(state.str), state.str->len, *line, len, linelen); if (yylex(&state, obj->pin)!=EOL) return STAT_NO; return STAT_CONT; } int auth_sasl(char *mechlist, isieve_t *obj, const char **mechusing, sasl_ssf_t *ssf, char **errstr) { sasl_interact_t *client_interact=NULL; int saslresult=SASL_INTERACT; const char *out; unsigned int outlen; char *in; unsigned int inlen; char inbase64[2048]; unsigned int inbase64len; imt_stat status = STAT_CONT; if(!mechlist || !obj || !mechusing) return -1; /* call sasl client start */ while (saslresult==SASL_INTERACT) { saslresult=sasl_client_start(obj->conn, mechlist, &client_interact, &out, &outlen, mechusing); if (saslresult==SASL_INTERACT) fillin_interactions(client_interact); /* fill in prompts */ } if ((saslresult!=SASL_OK) && (saslresult!=SASL_CONTINUE)) return saslresult; if (out!=NULL) { prot_printf(obj->pout,"AUTHENTICATE \"%s\" ",*mechusing); sasl_encode64(out, outlen, inbase64, sizeof(inbase64), &inbase64len); prot_printf(obj->pout, "{%d+}\r\n",inbase64len); prot_write(obj->pout,inbase64,inbase64len); prot_printf(obj->pout,"\r\n"); } else { prot_printf(obj->pout,"AUTHENTICATE \"%s\"\r\n",*mechusing); } prot_flush(obj->pout); inlen = 0; /* get reply */ status=getauthline(obj,&in,&inlen, errstr); while (status==STAT_CONT) { saslresult=SASL_INTERACT; while (saslresult==SASL_INTERACT) { saslresult=sasl_client_step(obj->conn, in, inlen, &client_interact, &out,&outlen); if (saslresult==SASL_INTERACT) fillin_interactions(client_interact); /* fill in prompts */ } /* check if sasl suceeded */ if (saslresultpout, "*\r\n"); prot_flush(obj->pout); /* eat the auth line that confirms that we canceled */ if(getauthline(obj,&in,&inlen,errstr) != STAT_NO) { *errstr = strdup("protocol error"); } else { *errstr = strdup(sasl_errstring(saslresult,NULL,NULL)); } return saslresult; } /* send to server */ sasl_encode64(out, outlen, inbase64, sizeof(inbase64), &inbase64len); prot_printf(obj->pout, "{%d+}\r\n",inbase64len); prot_flush(obj->pout); prot_write(obj->pout,inbase64,inbase64len); prot_flush(obj->pout); prot_printf(obj->pout,"\r\n"); prot_flush(obj->pout); /* get reply */ status=getauthline(obj,&in,&inlen, errstr); } if(status == STAT_OK) { /* do we have a last send? */ if(in) { saslresult=sasl_client_step(obj->conn, in, inlen, &client_interact, &out, &outlen); if(saslresult != SASL_OK) return -1; } if (ssf) { const void *ssfp; saslresult = sasl_getprop(obj->conn, SASL_SSF, &ssfp); if(saslresult != SASL_OK) return -1; *ssf = *((sasl_ssf_t *) ssfp); } /* turn on layer if need be */ prot_setsasl(obj->pin, obj->conn); prot_setsasl(obj->pout, obj->conn); /* There wasn't a last send, or we are already OK */ return 0; } else { /* Error */ return -1; } } static int refer_simple_cb(void *context, int id, const char **result, unsigned int *len) { if (!result) { return SASL_BADPARAM; } switch (id) { case SASL_CB_USER: *result = (char *) context; break; case SASL_CB_AUTHNAME: *result = (char *) context; break; default: return SASL_BADPARAM; } if (len) { *len = *result ? strlen(*result) : 0; } return SASL_OK; } int do_referral(isieve_t *obj, char *refer_to) { int ret; struct servent *serv; isieve_t *obj_new; char *mechlist; int port; char *errstr = NULL; const char *mtried; const char *scheme = "sieve://"; char *host, *p; sasl_callback_t *callbacks; sasl_ssf_t ssf; /* check scheme */ if (strncasecmp(refer_to, scheme, strlen(scheme))) return STAT_NO; /* get host */ if ((host = strrchr(refer_to, '@'))) { char *authid, *userid; int n; *host++ = '\0'; /* get authid - make a copy so it persists for the callbacks */ authid = obj->refer_authinfo = xstrdup(refer_to + strlen(scheme)); /* get userid */ if ((userid = strrchr(authid, ';'))) *userid++ = '\0'; /* count the callbacks */ for (n = 0; obj->callbacks[n++].id != SASL_CB_LIST_END;); /* copy the callbacks, substituting some of our own */ callbacks = obj->refer_callbacks = xmalloc(n*sizeof(sasl_callback_t)); while (--n >= 0) { callbacks[n].id = obj->callbacks[n].id; switch (callbacks[n].id) { case SASL_CB_USER: callbacks[n].proc = &refer_simple_cb; callbacks[n].context = userid ? userid : authid; break; case SASL_CB_AUTHNAME: callbacks[n].proc = &refer_simple_cb; callbacks[n].context = authid; break; default: callbacks[n].proc = obj->callbacks[n].proc; callbacks[n].context = obj->callbacks[n].context; break; } } } else { host = refer_to + strlen(scheme); callbacks = obj->callbacks; } /* get port */ p = host; if (*host == '[') { if ((p = strrchr(host + 1, ']')) != NULL) { *p++ = '\0'; host++; /* skip first bracket */ } else p = host; } if ((p = strchr(p, ':'))) { *p++ = '\0'; port = atoi(p); } else { serv = getservbyname("sieve", "tcp"); if (serv == NULL) { port = 2000; } else { port = ntohs(serv->s_port); } } ret = init_net(host, port, &obj_new); if(ret) return STAT_NO; /* Start up SASL */ ret = init_sasl(obj_new, 128, callbacks); if(ret) return STAT_NO; /* Authenticate */ mechlist = read_capability(obj_new); do { mtried = NULL; ret = auth_sasl(mechlist, obj_new, &mtried, &ssf, &errstr); if (errstr) { free(errstr); errstr = NULL; } if(ret) init_sasl(obj_new, 128, callbacks); if(mtried) { char *newlist = (char*) xmalloc(strlen(mechlist)+1); char *mtr = (char*) xstrdup(mtried); char *tmp; ucase(mtr); tmp = strstr(mechlist,mtr); if (tmp) { strcpy(newlist, mechlist); tmp++; tmp = strchr(tmp, ' '); if (tmp) { strcat(newlist,tmp); } } free(mtr); free(mechlist); mechlist = newlist; } } while(ret && mtried); /* xxx leak? */ if(ret) return STAT_NO; if (ssf) { /* SASL security layer negotiated -- check if SASL mech list changed */ if (detect_mitm(obj_new, mechlist)) { free(mechlist); return STAT_NO; } } free(mechlist); /* free old isieve_t */ sieve_dispose(obj); /* Copy new isieve_t into memory used by old object */ memcpy(obj,obj_new,sizeof(isieve_t)); free(obj_new); /* Destroy the string that was allocated to save the destination server */ free(refer_to); return STAT_OK; } int isieve_logout(isieve_t **obj) { prot_printf((*obj)->pout, "LOGOUT"); prot_flush((*obj)->pout); close((*obj)->sock); sieve_free_net(*obj); *obj = NULL; return STAT_OK; } int isieve_put_file(isieve_t *obj, char *filename, char *destname, char **errstr) { char *refer_to; int ret = installafile(obj->version, obj->pout, obj->pin, filename, destname, &refer_to, errstr); if(ret == -2 && refer_to) { ret = do_referral(obj, refer_to); if(ret == STAT_OK) { ret = isieve_put_file(obj, filename, destname, errstr); } else { *errstr = "referral failed"; } } return ret; } int isieve_put(isieve_t *obj, char *name, char *data, int len, char **errstr) { char *refer_to; int ret = installdata(obj->version, obj->pout, obj->pin, name, data, len, &refer_to, errstr); if(ret == -2 && refer_to) { ret = do_referral(obj, refer_to); if(ret == STAT_OK) { ret = isieve_put(obj, name, data, len, errstr); } else { *errstr = "referral failed"; } } return ret; } int isieve_delete(isieve_t *obj, char *name, char **errstr) { char *refer_to; int ret = deleteascript(obj->version, obj->pout, obj->pin, name, &refer_to, errstr); if(ret == -2 && refer_to) { ret = do_referral(obj, refer_to); if(ret == STAT_OK) { ret = isieve_delete(obj, name, errstr); } else { *errstr = "referral failed"; } } return ret; } int isieve_list(isieve_t *obj, isieve_listcb_t *cb,void *rock, char **errstr) { char *refer_to; int ret = list_wcb(obj->version, obj->pout, obj->pin, cb, rock, &refer_to); if(ret == -2 && refer_to) { ret = do_referral(obj, refer_to); if(ret == STAT_OK) { ret = isieve_list(obj, cb, rock, errstr); } } return ret; } int isieve_activate(isieve_t *obj, char *name, char **errstr) { char *refer_to; int ret = setscriptactive(obj->version,obj->pout, obj->pin, name, &refer_to, errstr); if(ret == -2 && refer_to) { ret = do_referral(obj, refer_to); if(ret == STAT_OK) { ret = isieve_activate(obj, name, errstr); } else { *errstr = "referral failed"; } } return ret; } int isieve_get(isieve_t *obj,char *name, char **output, char **errstr) { int ret; char *refer_to; mystring_t *mystr = NULL; ret = getscriptvalue(obj->version,obj->pout, obj->pin, name, &mystr, &refer_to, errstr); if(ret == -2 && *refer_to) { ret = do_referral(obj, refer_to); if(ret == STAT_OK) { ret = isieve_get(obj,name,output,errstr); return ret; } else { *errstr = "referral failed"; } } *output = string_DATAPTR(mystr); return ret; } cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/lib/isieve.h0000664000175000017500000000615112253670273020704 0ustar kenken/* * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "Carnegie Mellon University" must not be used to * endorse or promote products derived from this software without * prior written permission. For permission or any legal * details, please contact * Carnegie Mellon University * Center for Technology Transfer and Enterprise Creation * 4615 Forbes Avenue * Suite 302 * Pittsburgh, PA 15213 * (412) 268-7393, fax: (412) 268-7395 * innovation@andrew.cmu.edu * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by Computing Services * at Carnegie Mellon University (http://www.cmu.edu/computing/)." * * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $Id: isieve.h,v 1.14 2010/01/06 17:01:56 murch Exp $ */ #ifndef ISIEVE_H_ #define ISIEVE_H_ #include "prot.h" #include typedef struct iseive_s isieve_t; int init_net(char *serverFQDN, int port, isieve_t **obj); void sieve_free_net(isieve_t *obj); /* The callbacks that are passed to init_sasl need to persist until * after sieve_free_net is called on the object, so that referrals can * continue to work */ int init_sasl(isieve_t *obj, int ssf, sasl_callback_t *callbacks); char * read_capability(isieve_t *obj); int detect_mitm(isieve_t *obj, char *mechlist); typedef enum { STAT_CONT = 0, STAT_NO = 1, STAT_OK = 2 } imt_stat; int auth_sasl(char *mechlist, isieve_t *obj, const char **mechusing, sasl_ssf_t *ssf, char **errstr); int isieve_logout(isieve_t **obj); int isieve_put_file(isieve_t *obj, char *filename, char *destname, char **errstr); int isieve_put(isieve_t *obj, char *name, char *data, int len, char **errstr); int isieve_delete(isieve_t *obj, char *name, char **errstr); typedef void *isieve_listcb_t(char *name, int isactive, void *rock); int isieve_list(isieve_t *obj, isieve_listcb_t *cb,void *rock, char **errstr); int isieve_activate(isieve_t *obj, char *name, char **errstr); int isieve_get(isieve_t *obj,char *name, char **output, char **errstr); #endif /* ISIEVE_H_ */ cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/lib/lex.c0000664000175000017500000001720012253670273020200 0ustar kenken/* lex.c -- lexers for command line script installer * Tim Martin */ /* * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "Carnegie Mellon University" must not be used to * endorse or promote products derived from this software without * prior written permission. For permission or any legal * details, please contact * Carnegie Mellon University * Center for Technology Transfer and Enterprise Creation * 4615 Forbes Avenue * Suite 302 * Pittsburgh, PA 15213 * (412) 268-7393, fax: (412) 268-7395 * innovation@andrew.cmu.edu * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by Computing Services * at Carnegie Mellon University (http://www.cmu.edu/computing/)." * * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $Id: lex.c,v 1.11 2010/01/06 17:01:56 murch Exp $ */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include "prot.h" #include "lex.h" #include "codes.h" /* current state the lexer is in */ int lexer_state = LEXER_STATE_NORMAL; #define ACAP_MAX_QSTR_LEN 4096 #define ERR() { \ lexer_state=LEXER_STATE_RECOVER; \ return SIEVE_FAIL; \ } #define ERR_PUSHBACK() { \ prot_ungetc(ch, stream); \ ERR(); \ } int token_lookup(char *str, int len __attribute__((unused))) { if (strcmp(str,"ok")==0) return TOKEN_OK; if (strcmp(str,"no")==0) return TOKEN_NO; if (strcmp(str,"bye")==0) return TOKEN_BYE; if (strcmp(str,"active")==0) return TOKEN_ACTIVE; if (strcmp(str,"referral")==0) return TOKEN_REFERRAL; if (strcmp(str,"sasl")==0) return TOKEN_SASL; if (strcmp(str,"quota/maxscripts")==0) return RESP_CODE_QUOTA_MAXSCRIPTS; if (strcmp(str,"quota/maxsize")==0) return RESP_CODE_QUOTA_MAXSIZE; if (strcmp(str,"quota")==0) return RESP_CODE_QUOTA; if (strcmp(str,"transition-needed")==0) return RESP_CODE_TRANSITION_NEEDED; if (strcmp(str,"trylater")==0) return RESP_CODE_TRYLATER; if (strcmp(str,"nonexistant")==0) return RESP_CODE_NONEXISTANT; if (strcmp(str,"alreadyexists")==0) return RESP_CODE_ALREADYEXISTS; if (strcmp(str,"warning")==0) return RESP_CODE_WARNINGS; if (strcmp(str,"tag")==0) return RESP_CODE_TAG; return -1; } int yylex(lexstate_t * lvalp, void * client) { int ch; char buffer[ACAP_MAX_QSTR_LEN]; /* big enough for everything */ char *buff_ptr = buffer; /* ptr into the buffer */ char *buff_end = buffer + ACAP_MAX_QSTR_LEN -1; unsigned long count=0; int result = SIEVE_OK; int synchronizing; /* wheather we are in the process of reading a synchronizing string or not */ struct protstream *stream=(struct protstream *) client; while (1) { /* get a character this may block on a read if there is nothing in the buffer */ ch = prot_getc(stream); if (ch == -1) return SIEVE_FAIL; switch (lexer_state) { case LEXER_STATE_RECOVER: if (ch == '\r') lexer_state=LEXER_STATE_RECOVER_CR; break; case LEXER_STATE_RECOVER_CR: if (ch == '\n') lexer_state=LEXER_STATE_NORMAL; return EOL; case LEXER_STATE_CR: if (ch == '\n') { lexer_state=LEXER_STATE_NORMAL; return EOL; } /* otherwise, life is bad */ ERR_PUSHBACK(); case LEXER_STATE_QSTR: if (ch == '\"') { /* End of the string */ lvalp->str = NULL; result = string_allocate(buff_ptr - buffer, buffer, &lvalp->str); if (result != SIEVE_OK) ERR_PUSHBACK(); lexer_state=LEXER_STATE_NORMAL; return STRING; } if (ch == '\0' || 0x7F < ((unsigned char)ch)) ERR_PUSHBACK(); /* Otherwise, we're appending a character */ if (buff_end <= buff_ptr) ERR_PUSHBACK(); /* too long! */ if (ch == '\\') { ch=prot_getc(stream); if (result != SIEVE_OK) ERR(); if (ch != '\"' && ch != '\\') ERR_PUSHBACK(); } *buff_ptr++ = ch; break; case LEXER_STATE_LITERAL: if (('0' <= ch) && (ch <= '9')) { unsigned long newcount = count * 10 + (ch - '0'); if (newcount < count) ERR_PUSHBACK(); /* overflow */ /* * XXX This should be fatal if non-synchronizing. */ count = newcount; break; } synchronizing = FALSE; if (ch != '}') ERR_PUSHBACK(); ch=prot_getc(stream); if (ch < 0) ERR(); if (ch != '\r') ERR_PUSHBACK(); ch=prot_getc(stream); if (ch < 0) ERR(); if (ch != '\n') ERR_PUSHBACK(); lvalp->str = NULL; result = string_allocate(count, NULL, &lvalp->str); if (result != SIEVE_OK) ERR_PUSHBACK(); /* there is a literal string on the wire. let's read it */ { char *it = string_DATAPTR(lvalp->str), *end = it + count; while (it < end) { *it=prot_getc(stream); it++; } *it = '\0'; } lexer_state=LEXER_STATE_NORMAL; return STRING; case LEXER_STATE_NUMBER: if (('0' <= ch) && (ch <= '9')) { unsigned long newcount = count * 10 + (ch - '0'); if (newcount < count) ERR_PUSHBACK(); /* overflow */ count = newcount; } else { lvalp->number = count; lexer_state=LEXER_STATE_NORMAL; prot_ungetc(ch, stream); return NUMBER; } break; case LEXER_STATE_NORMAL: if (isalpha((unsigned char) ch)) { lexer_state=LEXER_STATE_ATOM; *buff_ptr++ = tolower(ch); break; } switch (ch) { case '(': return '('; case ')': return ')'; case ' ': return ' '; case '\"': lexer_state=LEXER_STATE_QSTR; break; case '*': return '*'; case '0': /* fall through all numbers */ case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': count = ch - '0'; lexer_state=LEXER_STATE_NUMBER; break; case '{': count = 0; synchronizing = TRUE; lexer_state=LEXER_STATE_LITERAL; break; case '\r': lexer_state=LEXER_STATE_CR; break; case '\n': lexer_state=LEXER_STATE_NORMAL; return EOL; break; default: ERR_PUSHBACK(); } break; case LEXER_STATE_ATOM: if (!(isalpha((unsigned char) ch) || ch == '/')) { int token; buffer[ buff_ptr - buffer] = '\0'; /* We've got the atom. */ token = token_lookup((char *) buffer, (int) (buff_ptr - buffer)); if (token!=-1) { lexer_state=LEXER_STATE_NORMAL; prot_ungetc(ch, stream); return token; } else ERR_PUSHBACK(); } if (buff_end <= buff_ptr) ERR_PUSHBACK(); /* atom too long */ *buff_ptr++ = tolower(ch); break; } } /* while (1) */ /* never reached */ } cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/lib/exitcodes.h0000664000175000017500000000770412253670273021414 0ustar kenken/* exitcodes.h -- wrapper around sysextis.h * * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "Carnegie Mellon University" must not be used to * endorse or promote products derived from this software without * prior written permission. For permission or any legal * details, please contact * Carnegie Mellon University * Center for Technology Transfer and Enterprise Creation * 4615 Forbes Avenue * Suite 302 * Pittsburgh, PA 15213 * (412) 268-7393, fax: (412) 268-7395 * innovation@andrew.cmu.edu * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by Computing Services * at Carnegie Mellon University (http://www.cmu.edu/computing/)." * * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $Id: exitcodes.h,v 1.5 2010/01/06 17:01:56 murch Exp $ */ /* Sendmail has some weird ideas on what constitutes permenant failure. On more than one occasion, we have gotten burned by this moving users around through various inadvisable means, screwing up the mailboxes file, whatever. We don't want to fail out permenantly on things like EX_USAGE, EX_SOFTWARE, etc., because that generally means someone was just screwing with the mail store and we don't want to lose mail. Instead, we map these EC_* codes to EX_* codes, thereby lying to Sendmail, since we don't derive any benefit from Sendmail knowing what the error was. We just want it to retry all the time anyway. This way, should sendmail's behavior be different and we start deriving benefit from Sendmail knowing stuff, we can easily change it back. So other code uses the EC_* error, then we maybe change it to TEMPFAIL if we don't agree on whether the error should be permenant or not. Comments below stolen from sysexits.h. */ #ifndef INCLUDED_EXITCODES_H #define INCLUDED_EXITCODES_H #include #define EC_OK 0 /* successful termination */ #define EC_USAGE EX_TEMPFAIL /* command line usage error */ #define EC_DATAERR EX_DATAERR /* data format error */ #define EC_NOINPUT EX_TEMPFAIL /* cannot open input */ #define EC_NOUSER EX_NOUSER /* addressee unknown */ #define EC_NOHOST EX_TEMPFAIL /* host name unknown */ #define EC_UNAVAILABLE EX_TEMPFAIL /* service unavailable */ #define EC_SOFTWARE EX_TEMPFAIL /* internal software error */ #define EC_OSERR EX_TEMPFAIL /* system error (e.g., can't fork) */ #define EC_OSFILE EX_TEMPFAIL /* critical OS file missing */ #define EC_CANTCREAT EX_TEMPFAIL /* can't create (user) output file */ #define EC_IOERR EX_TEMPFAIL /* input/output error */ #define EC_TEMPFAIL EX_TEMPFAIL /* user is invited to retry */ #define EC_PROTOCOL EX_TEMPFAIL /* remote error in protocol */ #define EC_NOPERM EX_TEMPFAIL /* permission denied */ #define EC_CONFIG EX_TEMPFAIL /* configuration error */ #endif /* INCLUDED_EXITCODES_H */ cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/lib/mystring.c0000664000175000017500000001131712253670273021267 0ustar kenken/* mystring.c -- string utility * Tim Martin * 9/21/99 */ /* * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "Carnegie Mellon University" must not be used to * endorse or promote products derived from this software without * prior written permission. For permission or any legal * details, please contact * Carnegie Mellon University * Center for Technology Transfer and Enterprise Creation * 4615 Forbes Avenue * Suite 302 * Pittsburgh, PA 15213 * (412) 268-7393, fax: (412) 268-7395 * innovation@andrew.cmu.edu * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by Computing Services * at Carnegie Mellon University (http://www.cmu.edu/computing/)." * * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $Id: mystring.c,v 1.10 2010/01/06 17:01:56 murch Exp $ */ #ifdef HAVE_CONFIG_H #include #endif #include "mystring.h" #include "codes.h" #include #include int string_allocate(int length, const char *buf, /* NULL => no copy */ mystring_t ** str) { *str=(mystring_t *) malloc(sizeof(mystring_t)+length+3); (*str)->len=length; ((char *) (*str))[sizeof(mystring_t)+length]='\0'; if (buf==NULL) return SIEVE_OK; /* copy the data into the string object */ memcpy(((char *)(*str))+sizeof(mystring_t), buf, length); ((char *) (*str))[sizeof(mystring_t)+length]='\0'; return SIEVE_OK; } int string_copy(mystring_t *oldstr, mystring_t **newstr) { int result; result=string_allocate(oldstr->len, string_DATAPTR(oldstr), newstr); return result; } void string_free(mystring_t **str) { free(*str); } int string_compare(mystring_t *str1, mystring_t *str2) { char *data1; char *data2; int lup; if (str1->len!=str2->len) return SIEVE_FAIL; data1=string_DATAPTR(str1); data2=string_DATAPTR(str2); for (lup=0;luplen;lup++) if (data1[lup]!=data2[lup]) return SIEVE_FAIL; return SIEVE_OK; } int string_compare_with(mystring_t *str1, mystring_t *str2, mystring_t *comp __attribute__((unused))) { char *data1; char *data2; int lup; int len1=str1->len; int len2=str2->len; int low=len1; if (len2data2[lup]) { return 1; } else { /* continue */ } if (len1==len2) return 0; if (len1len!=str2len) return SIEVE_FAIL; data1=string_DATAPTR(str1); data2=str2; for (lup=0;luplen;lup++) if (data1[lup]!=data2[lup]) return SIEVE_FAIL; return SIEVE_OK; } /* eq_result_t string_equal_cstr(const mystring_t * str, const char *cstr) { int len; I(str); I(cstr); len = strlen(cstr); if (len != str->len) return EQ_NOT_EQUAL; if (memcmp(string_DATAPTR(str), cstr, len)==0) return EQ_IS_EQUAL; return EQ_NOT_EQUAL; } */ int safe_to_use_quoted(char *str, int len) { char *end=str+len; if (len > 4096) return FALSE; while (str < end) { if (*str == '\0' /* check illegal chars... */ || *str == '\r' || *str == '\n' #ifdef __CHAR_UNSIGNED__ || 0x7F < *str #else || *str < 0 #endif ) return FALSE; if (*str == '\"' /* check len, with \ escapes... */ || *str == '\\') if (4096 < ++len) return FALSE; ++str; } return TRUE; } cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/lib/lex.h0000664000175000017500000000543612253670273020215 0ustar kenken/* lex.h * Tim Martin * 9/21/99 */ /* * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "Carnegie Mellon University" must not be used to * endorse or promote products derived from this software without * prior written permission. For permission or any legal * details, please contact * Carnegie Mellon University * Center for Technology Transfer and Enterprise Creation * 4615 Forbes Avenue * Suite 302 * Pittsburgh, PA 15213 * (412) 268-7393, fax: (412) 268-7395 * innovation@andrew.cmu.edu * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by Computing Services * at Carnegie Mellon University (http://www.cmu.edu/computing/)." * * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $Id: lex.h,v 1.9 2010/01/06 17:01:56 murch Exp $ */ #ifndef _LEX_H_ #define _LEX_H_ #include "mystring.h" typedef struct lexstate_s { mystring_t *str; int number; } lexstate_t; int yylex(lexstate_t * lvalp, void * client); enum { TAG = 258, EOL = 259, STRING = 260, NUMBER = 261, TOKEN_OK = 280, TOKEN_NO = 281, TOKEN_BYE = 282, TOKEN_ACTIVE = 291, TOKEN_REFERRAL = 301, TOKEN_SASL = 302, RESP_CODE_QUOTA = 303, RESP_CODE_QUOTA_MAXSCRIPTS = 304, RESP_CODE_QUOTA_MAXSIZE = 305, RESP_CODE_TRANSITION_NEEDED = 306, RESP_CODE_TRYLATER = 307, RESP_CODE_NONEXISTANT = 308, RESP_CODE_ALREADYEXISTS = 309, RESP_CODE_WARNINGS = 310, RESP_CODE_TAG = 311 }; enum { LEXER_STATE_TAG = 60, LEXER_STATE_RECOVER, LEXER_STATE_RECOVER_CR, LEXER_STATE_CR, LEXER_STATE_QSTR, LEXER_STATE_LITERAL, LEXER_STATE_NUMBER, LEXER_STATE_NORMAL, LEXER_STATE_ATOM }; #endif /* _LEX_H_ */ cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/lib/mystring.h0000664000175000017500000000523312253670273021274 0ustar kenken/* mystring.h * Tim Martin * 9/21/99 */ /* * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "Carnegie Mellon University" must not be used to * endorse or promote products derived from this software without * prior written permission. For permission or any legal * details, please contact * Carnegie Mellon University * Center for Technology Transfer and Enterprise Creation * 4615 Forbes Avenue * Suite 302 * Pittsburgh, PA 15213 * (412) 268-7393, fax: (412) 268-7395 * innovation@andrew.cmu.edu * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by Computing Services * at Carnegie Mellon University (http://www.cmu.edu/computing/)." * * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $Id: mystring.h,v 1.7 2010/01/06 17:01:56 murch Exp $ */ #include "codes.h" #ifndef INCLUDED_MYSTRING_H #define INCLUDED_MYSTRING_H typedef struct { int len; /* Data immediately following... */ } mystring_t; int string_allocate(int length, const char *buf, /* NULL => no copy */ mystring_t ** str); int string_copy(mystring_t *oldstr, mystring_t **newstr); void string_free(mystring_t **str); int string_compare(mystring_t *str1, mystring_t *str2); int string_comparestr(mystring_t *str1, char *str2); int string_compare_with(mystring_t *str1, mystring_t *str2, mystring_t *comp); /*eq_result_t string_equal_cstr(const mystring_t * str, const char *cstr);*/ #define string_DATAPTR(s) (s ? (((char *) s)+sizeof(mystring_t)) : 0) int safe_to_use_quoted(char *str, int len); #endif /* INCLUDED_MYSTRING_H */ cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/lib/request.h0000664000175000017500000000665712253670273021123 0ustar kenken/* request.h -- request to execute functions on the timsieved server * Tim Martin * 9/21/99 */ /* * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "Carnegie Mellon University" must not be used to * endorse or promote products derived from this software without * prior written permission. For permission or any legal * details, please contact * Carnegie Mellon University * Center for Technology Transfer and Enterprise Creation * 4615 Forbes Avenue * Suite 302 * Pittsburgh, PA 15213 * (412) 268-7393, fax: (412) 268-7395 * innovation@andrew.cmu.edu * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by Computing Services * at Carnegie Mellon University (http://www.cmu.edu/computing/)." * * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $Id: request.h,v 1.9 2010/01/06 17:01:56 murch Exp $ */ #ifndef _REQUEST_H_ #define _REQUEST_H_ #include "mystring.h" #include "isieve.h" /* old and new versions of the protocol */ #define OLD_VERSION 4 #define NEW_VERSION 5 #define ACAP_VERSION 6 int handle_response(int res,int version,struct protstream *pin, char **refer_to, mystring_t **errstr); int deleteascript(int version,struct protstream *pout, struct protstream *pin, char *name, char **refer_to, char **errstr); int installafile(int version,struct protstream *pout, struct protstream *pin, char *filename, char *destname, char **refer_to, char **errstr); int installdata(int version,struct protstream *pout, struct protstream *pin, char *scriptname, char *data, int len, char **refer_to, char **errstr); int showlist(int version, struct protstream *pout, struct protstream *pin, char **refer_to); int list_wcb(int version, struct protstream *pout, struct protstream *pin, isieve_listcb_t *cb , void *rock, char **refer_to); int setscriptactive(int version, struct protstream *pout, struct protstream *pin, char *name, char **refer_to, char **errstr); /* * Getscript. Save {0,1} wheather to save to disk or display on screen */ int getscript(int version, struct protstream *pout, struct protstream *pin, char *name, int save, char **refer_to, char **errstr); int getscriptvalue(int version,struct protstream *pout, struct protstream *pin, char *name, mystring_t **data, char **refer_to, char **errstr); void parseerror(char *str); #endif cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/lib/codes.h0000664000175000017500000000400212253670273020506 0ustar kenken/* * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "Carnegie Mellon University" must not be used to * endorse or promote products derived from this software without * prior written permission. For permission or any legal * details, please contact * Carnegie Mellon University * Center for Technology Transfer and Enterprise Creation * 4615 Forbes Avenue * Suite 302 * Pittsburgh, PA 15213 * (412) 268-7393, fax: (412) 268-7395 * innovation@andrew.cmu.edu * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by Computing Services * at Carnegie Mellon University (http://www.cmu.edu/computing/)." * * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $Id: codes.h,v 1.6 2010/01/06 17:01:55 murch Exp $ */ #ifndef _CODES_H_ #define _CODES_H_ #define SIEVE_OK 0 #define SIEVE_FAIL -1 #define SIEVE_BADPORT -5 #define SIEVE_NOEXIST -6 #define TRUE 1 #define FALSE 0 #endif cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/lib/Makefile.in0000664000175000017500000000567412253670273021325 0ustar kenken# Makefile for imtest # # @configure_input@ # # Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # 3. The name "Carnegie Mellon University" must not be used to # endorse or promote products derived from this software without # prior written permission. For permission or any legal # details, please contact # Carnegie Mellon University # Center for Technology Transfer and Enterprise Creation # 4615 Forbes Avenue # Suite 302 # Pittsburgh, PA 15213 # (412) 268-7393, fax: (412) 268-7395 # innovation@andrew.cmu.edu # # 4. Redistributions of any form whatsoever must retain the following # acknowledgment: # "This product includes software developed by Computing Services # at Carnegie Mellon University (http://www.cmu.edu/computing/)." # # CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO # THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE # FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN # AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING # OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # # $Id: Makefile.in,v 1.17 2010/01/06 17:01:55 murch Exp $ # srcdir = @srcdir@ top_srcdir = @top_srcdir@ VPATH = @srcdir@ CC = @CC@ INSTALL = @INSTALL@ RANLIB = @RANLIB@ DEFS = @DEFS@ @LOCALDEFS@ -Dbool=char -DHAS_BOOL CPPFLAGS = -I. -I../../.. -I$(srcdir) -I$(srcdir)/../../../lib @CPPFLAGS@ @DYNSASLFLAGS@ @COM_ERR_CPPFLAGS@ LIBS = ../../../lib/libcyrus.a ../../../lib/libcyrus_min.a @LIB_DYN_SASL@ @LIBS@ IMAP_LIBS = @IMAP_LIBS@ DEPLIBS = ../../../lib/libcyrus.a ../../../lib/libcyrus_min.a @DEPLIBS@ MAKEDEPEND_CFLAGS = @CFLAGS@ CFLAGS = @CFLAGS@ @PERL_CCCDLFLAGS@ LDFLAGS = @LDFLAGS@ SHELL = /bin/sh MAKEDEPEND = @MAKEDEPEND@ prefix = @prefix@ exec_prefix = @exec_prefix@ cyrus_prefix = @cyrus_prefix@ OBJS=isieve.o lex.o mystring.o request.o all: libisieve.a install: .c.o: $(CC) -c $(CPPFLAGS) $(DEFS) $(CFLAGS) $< libisieve.a: $(OBJS) rm -f libisieve.a ar cr libisieve.a $(OBJS) $(RANLIB) libisieve.a clean: rm -f *.o Makefile.bak makedepend.log libisieve.a distclean: clean rm -f Makefile depend: ${MAKEDEPEND} $(CPPFLAGS) $(DEFS) $(MAKEDEPEND_CFLAGS) *.c $(srcdir)/*.c 1> makedepend.log 2>&1 # DO NOT DELETE THIS LINE -- make depend depends on it. cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/lib/.cvsignore0000664000175000017500000000003012253670273021235 0ustar kenkenMakefile makedepend.log cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/lib/request.c0000664000175000017500000003340612253670273021106 0ustar kenken/* request.c -- request to execute functions on the timsieved server * Tim Martin * 9/21/99 */ /* * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The name "Carnegie Mellon University" must not be used to * endorse or promote products derived from this software without * prior written permission. For permission or any legal * details, please contact * Carnegie Mellon University * Center for Technology Transfer and Enterprise Creation * 4615 Forbes Avenue * Suite 302 * Pittsburgh, PA 15213 * (412) 268-7393, fax: (412) 268-7395 * innovation@andrew.cmu.edu * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by Computing Services * at Carnegie Mellon University (http://www.cmu.edu/computing/)." * * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $Id: request.c,v 1.19 2010/01/06 17:01:56 murch Exp $ */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include #include #include "request.h" #include "prot.h" #include "lex.h" #include "xmalloc.h" #define BLOCKSIZE 1024 void parseerror(char *str) { printf("Bad protocol from MANAGESIEVE server: %s\n", str); exit(2); } int handle_response(int res,int version,struct protstream *pin, char **refer_to, mystring_t **errstr) { lexstate_t state; int r = 0; *refer_to = NULL; if (res == -1) parseerror("lost connection"); if ((res!=TOKEN_OK) && (res!=TOKEN_NO) && (res!=TOKEN_BYE)) parseerror("ATOM"); if(res == TOKEN_BYE) { if (yylex(&state, pin)!=' ') parseerror("expected space"); res = yylex(&state, pin); /* additional error response */ if (res == '(') { /* '(' string [SP string] ')' */ /* we only support the REFERRAL response with BYE */ if (yylex(&state, pin)==TOKEN_REFERRAL) { if (yylex(&state, pin)!=' ') parseerror("expected space"); if (yylex(&state, pin)!=STRING) parseerror("expected string"); *refer_to = xstrdup(string_DATAPTR(state.str)); if (yylex(&state, pin)!=')') parseerror("expected RPAREN"); } else { res = 0; while(res != ')' && res != -1) { res = yylex(&state, pin); } if(res != ')') { parseerror("expected RPAREN"); } } res = yylex(&state, pin); if (res == ' ') res = yylex(&state, pin); } if (res != STRING && res != EOL) parseerror("expected string2"); if (errstr) *errstr = state.str; r = -2; } else if (res==TOKEN_NO) { if (yylex(&state, pin)!=' ') parseerror("expected space"); res = yylex(&state, pin); /* additional error response */ if (res == '(') { /* '(' string [SP string] ')' */ res = 0; while(res != ')' && res != -1) { res = yylex(&state, pin); } if(res != ')') { parseerror("expected RPAREN"); } res = yylex(&state, pin); if (res == ' ') res = yylex(&state, pin); } if (res != STRING) parseerror("expected string"); if (errstr) *errstr = state.str; r = -1; } else { /* ok */ int res; /* SASL response */ res = yylex(&state, pin); if(res == ' ') { if (yylex(&state, pin) != '(') parseerror("expected LPAREN"); if (yylex(&state, pin)==TOKEN_SASL) { if (yylex(&state, pin)!=' ') parseerror("expected space"); if (yylex(&state, pin)!=STRING) parseerror("expected string"); *refer_to = xstrdup(string_DATAPTR(state.str)); if (yylex(&state, pin)!=')') parseerror("expected RPAREN"); } else { parseerror("unexpected response code with OK response"); } } else if (version != OLD_VERSION && res == EOL) { return r; } /* old version of protocol had strings with ok responses too */ if (version == OLD_VERSION) { if (res !=' ') parseerror("expected sp"); if (yylex(&state, pin)!=STRING) parseerror("expected string"); } } if (yylex(&state, pin)!=EOL) parseerror("expected EOL"); return r; } int deleteascript(int version, struct protstream *pout, struct protstream *pin, char *name, char **refer_to, char **errstrp) { lexstate_t state; int res; int ret; mystring_t *errstr; prot_printf(pout,"DELETESCRIPT \"%s\"\r\n",name); prot_flush(pout); res=yylex(&state, pin); ret = handle_response(res,version,pin,refer_to,&errstr); if(ret == -2 && *refer_to) { return -2; } else if (ret!=0) { *errstrp = malloc(128); snprintf(*errstrp, 127, "Deleting script: %s",string_DATAPTR(errstr)); return -1; } return 0; } int installdata(int version,struct protstream *pout, struct protstream *pin, char *scriptname, char *data, int len, char **refer_to, char **errstrp) { int res; int ret; mystring_t *errstr=NULL; lexstate_t state; prot_printf(pout, "PUTSCRIPT \"%s\" ",scriptname); prot_printf(pout, "{%d+}\r\n",len); prot_write(pout, data, len); prot_printf(pout,"\r\n"); prot_flush(pout); /* now let's see what the server said */ res=yylex(&state,pin); ret = handle_response(res,version,pin,refer_to,&errstr); /* if command failed */ if(ret == -2 && *refer_to) { return -2; } else if (ret!=0) { *errstrp = malloc(128); snprintf(*errstrp, 127, "Putting script: %s",string_DATAPTR(errstr)); return -1; } return 0; } static char *getsievename(char *filename) { char *ret, *ptr; ret=(char *) xmalloc( strlen(filename) + 2); /* just take the basename of the file */ ptr = strrchr(filename, '/'); if (ptr == NULL) { ptr = filename; } else { ptr++; } strcpy(ret, ptr); if ( strcmp( ret + strlen(ret) - 7,".script")==0) { ret[ strlen(ret) - 7] = '\0'; } return ret; } int installafile(int version,struct protstream *pout, struct protstream *pin, char *filename, char *destname, char **refer_to, char **errstrp) { FILE *stream; struct stat filestats; /* returned by stat */ int size; /* size of the file */ int result; int cnt; int res; int ret; mystring_t *errstr=NULL; lexstate_t state; char *sievename; if(!destname) destname = filename; result=stat(filename,&filestats); if (result!=0) { if (errno == ENOENT) { *errstrp = "no such file"; } else { *errstrp = "file i/o error"; } return -1; } size=filestats.st_size; stream=fopen(filename, "r"); if (stream==NULL) { *errstrp = malloc(128); snprintf(*errstrp, 127, "put script: internal error: couldn't open temporary file"); return -1; } sievename=getsievename(destname); prot_printf(pout, "PUTSCRIPT \"%s\" ",sievename); prot_printf(pout, "{%d+}\r\n",size); cnt=0; while (cnt < size) { char buf[BLOCKSIZE]; int amount=BLOCKSIZE; int n; if (size-cnt < BLOCKSIZE) amount=size-cnt; n = fread(buf, 1, BLOCKSIZE, stream); if (!n) { *errstrp = malloc(128); snprintf(*errstrp, 127, "put script: failed to finish reading"); fclose(stream); free(sievename); return -1; } prot_write(pout, buf, n); cnt+=amount; } prot_printf(pout,"\r\n"); prot_flush(pout); fclose(stream); free(sievename); /* now let's see what the server said */ res=yylex(&state,pin); ret = handle_response(res,version,pin,refer_to,&errstr); /* if command failed */ if(ret == -2 && *refer_to) { return -2; } else if (ret!=0) { *errstrp = malloc(128); snprintf(*errstrp, 127, "put script: %s", string_DATAPTR(errstr)); return -1; } return 0; } int showlist(int version, struct protstream *pout, struct protstream *pin, char **refer_to) { lexstate_t state; int end=0; int res; int ret = 0; printf("You have the following scripts on the server:\n"); prot_printf(pout, "LISTSCRIPTS\r\n"); prot_flush(pout); do { if ((res=yylex(&state, pin))==STRING) { char *str=string_DATAPTR(state.str); if (yylex(&state, pin)==' ') { if (yylex(&state, pin)!=TOKEN_ACTIVE) printf("Expected ACTIVE\n"); if (yylex(&state, pin)!=EOL) printf("Expected EOL\n"); printf(" %s <- Active Sieve Script\n",str); } else { /* in old version we had that '*' means active script thing */ if (version == OLD_VERSION) { if (str[strlen(str)-1]=='*') { str[strlen(str)-1]='\0'; printf(" %s <- Active Sieve Script\n",str); } else { printf(" %s\n",str); } } else { /* NEW_VERSION */ /* assume it's a EOL */ printf(" %s\n",str); } } } else { ret = handle_response(res,version,pin,refer_to,NULL); end=1; } } while (end==0); return ret; } int list_wcb(int version, struct protstream *pout, struct protstream *pin,isieve_listcb_t *cb ,void *rock, char **refer_to) { lexstate_t state; int end=0; int res; int ret = 0; prot_printf(pout, "LISTSCRIPTS\r\n"); prot_flush(pout); do { if ((res=yylex(&state, pin))==STRING) { char *str=string_DATAPTR(state.str); if (yylex(&state, pin)==' ') { if (yylex(&state, pin)!=TOKEN_ACTIVE) printf("Expected ACTIVE\n"); if (yylex(&state, pin)!=EOL) printf("Expected EOL\n"); cb(str, 1, rock); } else { /* in old version we had that '*' means active script thing */ if (version == OLD_VERSION) { if (str[strlen(str)-1]=='*') { str[strlen(str)-1]='\0'; cb(str, 1, rock); } else { cb(str, 0, rock); } } else { /* NEW_VERSION */ /* assume it's a EOL */ cb(str, 0, rock); } } } else { ret = handle_response(res,version,pin,refer_to,NULL); end=1; } } while (end==0); return ret; } int setscriptactive(int version, struct protstream *pout, struct protstream *pin,char *name, char **refer_to, char **errstrp) { lexstate_t state; int res; int ret; mystring_t *errstr=NULL; /* tell server we want "name" to be the active script */ prot_printf(pout, "SETACTIVE \"%s\"\r\n",name); prot_flush(pout); /* now let's see what the server said */ res=yylex(&state, pin); ret = handle_response(res, version, pin, refer_to, &errstr); /* if command failed */ if(ret == -2 && *refer_to) { return -2; } else if (ret != 0) { *errstrp = malloc(128); snprintf(*errstrp, 127, "Setting script active: %s",string_DATAPTR(errstr)); return -1; } return 0; } static int viewafile(mystring_t *data, char *name __attribute__((unused))) { printf("%s\r\n", string_DATAPTR(data)); return 0; } static int writefile(mystring_t *data, char *name, char **errstrp) { FILE *stream; char *scrname; scrname = strconcat(name, ".script", (char *)NULL); stream=fopen(scrname,"w"); free(scrname); if (stream==NULL) { *errstrp = malloc(128); snprintf(*errstrp, 127, "writefile: unable to open %s for writing", name); return -1; } fwrite(string_DATAPTR(data), 1, data->len, stream); fclose(stream); return 0; } int getscript(int version, struct protstream *pout, struct protstream *pin,char *name, int save, char **refer_to, char **errstrp) { int res; mystring_t *errstr=NULL; lexstate_t state; int ret = 0; prot_printf(pout,"GETSCRIPT \"%s\"\r\n",name); prot_flush(pout); res=yylex(&state,pin); if (res==STRING) { if (save==1) writefile(state.str, name, errstrp); else viewafile(state.str, name); if (yylex(&state, pin)!=EOL) parseerror("EOL"); res=yylex(&state,pin); } ret = handle_response(res, version, pin, refer_to, &errstr); /* if command failed */ if(ret == -2 && *refer_to) { return -2; } else if (ret!=0) { *errstrp = malloc(128); snprintf(*errstrp, 127, "Getting script: %s",string_DATAPTR(errstr)); } return ret; } int getscriptvalue(int version, struct protstream *pout, struct protstream *pin,char *name, mystring_t **data, char **refer_to, char **errstrp) { int res; int ret; mystring_t *errstr=NULL; lexstate_t state; prot_printf(pout,"GETSCRIPT \"%s\"\r\n",name); prot_flush(pout); res=yylex(&state,pin); if (res==STRING) { *data=state.str; if (yylex(&state, pin)!=EOL) parseerror("EOL"); res=yylex(&state,pin); } ret = handle_response(res,version,pin, refer_to, &errstr); /* if command failed */ if(ret == -2 && *refer_to) { return -2; } else if (ret!=0) { *errstrp = malloc(128); snprintf(*errstrp, 127, "Getting script: %s",string_DATAPTR(errstr)); return -1; } return 0; } cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/Makefile.in0000664000175000017500000001061712253670273020550 0ustar kenken# SIEVE Makefile for cyrus software # # @configure_input@ # # Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # 3. The name "Carnegie Mellon University" must not be used to # endorse or promote products derived from this software without # prior written permission. For permission or any legal # details, please contact # Carnegie Mellon University # Center for Technology Transfer and Enterprise Creation # 4615 Forbes Avenue # Suite 302 # Pittsburgh, PA 15213 # (412) 268-7393, fax: (412) 268-7395 # innovation@andrew.cmu.edu # # 4. Redistributions of any form whatsoever must retain the following # acknowledgment: # "This product includes software developed by Computing Services # at Carnegie Mellon University (http://www.cmu.edu/computing/)." # # CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO # THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE # FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN # AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING # OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # # $Id: Makefile.in,v 1.20 2010/01/06 17:01:55 murch Exp $ # SUBDIRS = lib managesieve SCRIPTS = installsieve sieveshell # Makefile.PL doesn't make a depend rule. just make depend in these dirs DEPSUBDIRS = lib srcdir = @srcdir@ VPATH = @srcdir@ INSTALL = @INSTALL@ SHELL = /bin/sh @SET_MAKE@ prefix = @prefix@ exec_prefix = @exec_prefix@ cyrus_prefix = @cyrus_prefix@ # Note that we use the *dynamic* sasl libraries SASL_LIB=@LIB_DYN_SASL@ SASL_INC=@DYNSASLFLAGS@ OPENSSL_LIB=@OPENSSL_LIB@ OPENSSL_INC=@OPENSSL_INC@ BDB_LIB=@BDB_LIB@ BDB_INC=@BDB_INC@ LIB_RT=@LIB_RT@ ZLIB=@ZLIB@ CC=@CC@ PERL=@PERL@ all:: @for d in $(SUBDIRS); \ do \ (cd $$d; echo "### Making" all "in" `pwd`; \ if [ -f Makefile.PL -a ! -f Makefile ]; then \ LIB_RT="$(LIB_RT)" \ ZLIB="$(ZLIB)" \ BDB_LIB="$(BDB_LIB)" BDB_INC="$(BDB_INC)" \ OPENSSL_LIB="$(OPENSSL_LIB)" OPENSSL_INC="$(OPENSSL_INC)" \ SASL_LIB="$(SASL_LIB)" SASL_INC="$(SASL_INC)" CC="$(CC)" \ $(PERL) Makefile.PL PREFIX=$(prefix); \ fi; \ $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) all) || exit 1; \ done install:: for s in $(SCRIPTS); \ do \ $(INSTALL) -m 755 scripts/$$s.pl $(DESTDIR)$(exec_prefix)/bin/$$s ; \ done #xxx install scripts/* @for d in $(SUBDIRS); \ do \ (cd $$d; echo "### Making" install "in" `pwd`; \ $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) install) || exit 1; \ done clean:: @-for d in $(SUBDIRS); \ do \ (cd $$d; echo "### Making" clean "in" `pwd`; \ $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) clean ; \ echo "### Done with" `pwd`); \ done distclean:: @-for d in $(SUBDIRS); \ do \ (cd $$d; echo "### Making" clean "in" `pwd`; \ $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) distclean ; \ echo "### Done with" `pwd`); \ done rm -f Makefile Makefile.bak config.status config.log config.cache depend:: @for d in $(DEPSUBDIRS); \ do \ (cd $$d; echo "### Making" depend "in" `pwd`; \ $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) depend) || exit 1; \ done checkdepend:: depend:: echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep echo 'w' >>eddep cp Makefile Makefile.bak ed -s Makefile < eddep rm eddep echo '' >> Makefile echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile echo '# see make depend above' >> Makefile # DO NOT DELETE THIS LINE -- make depend uses it # The following rule ensures that "make depend" gets run at least # once before a "make all". The "depend" rule above removes # this rule from the Makefile the first time the "make depend" # has been run after the Makefile is generated by Configure checkdepend:: depend # IF YOU PUT STUFF HERE IT WILL GO AWAY # see make depend above cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/.cvsignore0000664000175000017500000000001112253670273020466 0ustar kenkenMakefile cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/scripts/0000775000175000017500000000000012253670273020165 5ustar kenkencyrus-imapd-2.4.17-caldav-beta9/perl/sieve/scripts/installsieve.pl0000664000175000017500000001115012253670273023222 0ustar kenken#! /bin/sh exec perl -x -S $0 ${1+"$@"} # -*-perl-*- #!perl -w # # Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # 3. The name "Carnegie Mellon University" must not be used to # endorse or promote products derived from this software without # prior written permission. For permission or any legal # details, please contact # Carnegie Mellon University # Center for Technology Transfer and Enterprise Creation # 4615 Forbes Avenue # Suite 302 # Pittsburgh, PA 15213 # (412) 268-7393, fax: (412) 268-7395 # innovation@andrew.cmu.edu # # 4. Redistributions of any form whatsoever must retain the following # acknowledgment: # "This product includes software developed by Computing Services # at Carnegie Mellon University (http://www.cmu.edu/computing/)." # # CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO # THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE # FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN # AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING # OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # # $Id: installsieve.pl,v 1.9 2010/01/06 17:01:57 murch Exp $ # use Cyrus::SIEVE::managesieve; use Getopt::Long; $username = ""; print "NOTE: This program is deprecated. Please use sieveshell\n"; print "\n"; $ret = GetOptions("v|views:s" => \$views, "l|list" => \$list, # "p|port:i" => \$port, "i|installs:s" => \$installs, "a|activates:s" => \$activates, "d|deletes:s" => \$deletes, # "m|mechanism:s" => \$mech, "g|gets:s" => \$gets, "u|username:s" => \$username, # "w|password:s" => \$pass ); if (!$ret || $#ARGV != 0) { show_help(); exit; } $acapserver = $ARGV[0]; sub list_cb { my($name, $isactive) = @_ ; print "$name "; if ($isactive == 1) { print " <- active script\n"; } else { print "\n"; } } sub prompt { my($type, $prompt) = @_ ; if (($type eq "username") && (defined $username)) { return $username; } elsif (($type eq "authname") && (defined $username)) { return $username; } elsif (($type eq "realm") && (defined $realm)) { return $realm; } print "$prompt: "; $b = ; chop($b); $b; } sub show_help { print "Usage:\n"; print " installsieve [options] \n"; print "\n"; print " -v view script\n"; print " -l list available scripts\n"; # print " -p port to connect to\n"; print " -i filename of script to install\n"; print " -a Set as the active script\n"; print " -d Delete script from server\n"; # print " -m Mechanism to use for authentication\n"; print " -g Get script and save to disk\n"; print " -u Userid/Authname to use\n"; # print " -w Specify password (Should only be used for automated scripts)\n"; print "\n"; } #main code my $obj = sieve_get_handle($acapserver,"prompt","prompt","prompt","prompt"); if (!defined $obj) { die "Unable to connect to server"; } if (defined $installs) { $ret = sieve_put_file($obj, $installs); if ($ret != 0) { print "upload failed\n"; } } if (defined $deletes) { $ret = sieve_delete($obj, $deletes); if ($ret != 0) { print "delete failed\n"; } } if (defined $activates) { $ret = sieve_activate($obj, $activates); if ($ret != 0) { print "activate failed\n"; } } if (defined $gets) { $str = ""; $ret = sieve_get($obj, $gets, $str); if ($ret != 0) { print "get failed\n"; } else { open (OUTPUT,">$gets") || die "Unable to open $gets"; print OUTPUT $str; close(OUTPUT); } } if (defined $views) { $str = ""; $ret = sieve_get($obj, $views, $str); if ($ret != 0) { print "get failed\n"; } else { # view print $str; } } if (defined $list) { $ret = sieve_list($obj, "list_cb"); if ($ret != 0) { print "List command failed\n"; } } cyrus-imapd-2.4.17-caldav-beta9/perl/sieve/scripts/sieveshell.pl0000664000175000017500000002115712253670273022673 0ustar kenken#! /bin/sh exec perl -x -S $0 ${1+"$@"} # -*-perl-*- #!perl -w # # Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # 3. The name "Carnegie Mellon University" must not be used to # endorse or promote products derived from this software without # prior written permission. For permission or any legal # details, please contact # Carnegie Mellon University # Center for Technology Transfer and Enterprise Creation # 4615 Forbes Avenue # Suite 302 # Pittsburgh, PA 15213 # (412) 268-7393, fax: (412) 268-7395 # innovation@andrew.cmu.edu # # 4. Redistributions of any form whatsoever must retain the following # acknowledgment: # "This product includes software developed by Computing Services # at Carnegie Mellon University (http://www.cmu.edu/computing/)." # # CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO # THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE # FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN # AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING # OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # # $Id: sieveshell.pl,v 1.26 2010/01/06 17:01:57 murch Exp $ # use Cyrus::SIEVE::managesieve; use Getopt::Long; use strict; use File::Temp qw/ tempfile /; use Pod::Usage; use Term::ReadLine; use POSIX qw(:sys_wait_h); my $puthelp = "put []\n" . " - upload script to server\n"; my $gethelp = "get []\n" . " - get script. if no filename display to stdout\n"; my $activatehelp = "activate - set a script as the active script\n"; my $deactivatehelp = "deactivate - deactivate all scripts\n"; my $deletehelp = "delete - delete script.\n"; my $username = $ENV{USER}; my $authname = $ENV{USER}; my $realm = ""; my $ex = ""; my $help = 0; my $man = 0; my $ret; GetOptions("a|authname:s" => \$authname, "u|username:s" => \$username, "r|realm:s" => \$realm, "e|exec:s" => \$ex, "help|?" => \$help, man => \$man) or pod2usage(2); pod2usage(1) if $help; pod2usage(-exitstatus => 0, -verbose => 2) if $man; if ($#ARGV != 0) { pod2usage("$0: need a server\n"); } my $acapserver = $ARGV[0]; my $filehandle; my $interactive; if (! $ex eq "") { $filehandle = tempfile(); if (!$filehandle) { die "unable to open tmp file: $?"; } print $filehandle $ex; seek $filehandle, 0, 0; # rewind file $interactive = 0; } else { $filehandle = *STDIN; $interactive = 1; } sub list_cb { my($name, $isactive) = @_ ; print "$name "; if ($isactive == 1) { print " <- active script\n"; } else { print "\n"; } } sub prompt { my($type, $prompt) = @_ ; if (($type eq "username") && (defined $username)) { return $username; } elsif (($type eq "authname") && (defined $authname)) { return $authname; } elsif (($type eq "realm") && (defined $realm)) { return $realm; } my $ostty; my $str = ""; chomp($ostty = `stty -g`); if ($type eq "password") { system "stty -echo -icanon min 1 time 0 2>/dev/null || " . "stty -echo cbreak"; $str = "\n"; } print "$prompt: "; $b = ; chop($b); print $str; system "stty $ostty"; return $b; } sub show_help { print "Usage:\n"; print " sieveshell [-u username] [-a authname] [-r realm] \n"; print "\n"; print "help - this screen\n"; print "list - list scripts on server\n"; print $puthelp; print $gethelp; print $deletehelp; print $activatehelp; print $deactivatehelp; print "quit - quit\n"; } # main code print "connecting to $acapserver\n"; my $obj = sieve_get_handle($acapserver, "prompt", "prompt", "prompt", "prompt"); if (!defined $obj) { die "unable to connect to server"; } my $term = Term::ReadLine->new("sieveshell"); $term->ornaments(0); while(defined($_ = ($interactive ? $term->readline('> ') : <$filehandle>))){ $term->addhistory($_); my @words = split ' ',$_; my $str; if ($#words < 0) { next; } if (($words[0] eq "put") || ($words[0] eq "p")) { if($#words == 1) { $ret = sieve_put_file($obj, $words[1]); } elsif ($#words == 2) { $ret = sieve_put_file_withdest($obj, $words[1], $words[2]); } else { print $puthelp; next; } if ($ret != 0) { my $errstr = sieve_get_error($obj); $errstr = "unknown error" if(!defined($errstr)); print "upload failed: $errstr\n"; } } elsif (($words[0] eq "list") || ($words[0] eq "l") || ($words[0] eq "ls")) { $ret = sieve_list($obj, "list_cb"); if ($ret != 0) { my $errstr = sieve_get_error($obj); $errstr = "unknown error" if(!defined($errstr)); print "list failed: $errstr\n"; } } elsif (($words[0] eq "activate") || ($words[0] eq "a")) { if ($#words != 1) { print $activatehelp; next; } $ret = sieve_activate($obj, $words[1]); if ($ret != 0) { my $errstr = sieve_get_error($obj); $errstr = "unknown error" if(!defined($errstr)); print "activate failed: $errstr\n"; } } elsif (($words[0] eq "deactivate") || ($words[0] eq "da")) { if ($#words != 0) { print $deactivatehelp; next; } $ret = sieve_activate($obj, ""); if ($ret != 0) { my $errstr = sieve_get_error($obj); $errstr = "unknown error" if(!defined($errstr)); print "deactivate failed: $errstr\n"; } } elsif (($words[0] eq "delete") || ($words[0] eq "d")) { if ($#words != 1) { print $deletehelp; next; } $ret = sieve_delete($obj, $words[1]); if ($ret != 0) { my $errstr = sieve_get_error($obj); $errstr = "unknown error" if(!defined($errstr)); print "delete failed: $errstr\n"; } } elsif (($words[0] eq "get") || ($words[0] eq "g")) { if ($#words != 1 && $#words != 2) { print $gethelp; next; } $str = ""; $ret = sieve_get($obj, $words[1], $str); if ($ret != 0) { my $errstr = sieve_get_error($obj); $errstr = "unknown error" if(!defined($errstr)); print "get failed: $errstr\n"; } else { if ($words[2]) { open (OUTPUT,">$words[2]") || die "Unable to open $words[2]"; print OUTPUT $str; close(OUTPUT); } else { print $str; } } } elsif (($words[0] eq "quit") || ($words[0] eq "q")) { sieve_logout($obj); exit 0; } elsif (($words[0] eq "help") || ($words[0] eq "?")) { show_help(); } else { print "Invalid command: $words[0]\n"; } } __END__ =head1 NAME sieveshell - remotely manipulate sieve scripts =head1 SYNOPSIS sieveshell [B<--user>=I] [B<--authname>=I] [B<--realm>=I] [B<--exec>=I