~clint-fewbar/+junk/cyrus-sasl2-builddeb

« back to all changes in this revision

Viewing changes to lib/common.c

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý, Roberto C. Sanchez, Ondřej Surý
  • Date: 2011-05-25 21:57:11 UTC
  • mfrom: (2.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110525215711-rxf1c8j46ljimdj4
Tags: 2.1.24~rc1.dfsg1-1
[ Roberto C. Sanchez ]
* libsasl2-2.README.Debian: document that SASL logs debug messages by
  default, and how change/stop it (Closes: #590598)
* Bump Standards-Version to 3.9.2 (no changes)
* Remove Build-Depends on libopie-dev, which was removed
  (Closes: #622221)

[ Ondřej Surý ]
* Patch to support newer Berkeley DB (Closes: #621437)
* Remove /etc/sasldb2 in prerm remove if empty (Closes: #618885)
* Improve Berkeley DB upgrade code to note the used version in
  berkeley_db.active file and compare it with current version
* Convert debian/rules to debhelper7
* Update Vcs-* and Homepage fields
* Fix autoreconf by adding some recommended options to configure.in
  and Makefile.am
* Imported Upstream version 2.1.24~rc1.dfsg1
* Update patches to new release
* Update repack.sh
* Build against sqlite3 since upstream has a support for it
  (Closes: #444799)
* Fix FTBFS in LDAP plugin
* Don't use .la files to open plugins, just scan .so
* Set configdir to /etc/sasl2:/etc/sasl:/usr/lib/sasl2
  (Closes: #465569)
* Stop shipping .la and .a files for all modules (Closes: #516833)
* sasl2-bin can depend on generic db-util package now
* Add myself to uploaders
* Removed hardcoded -R option when searching for sqlite libraries
* Fix Sqlite3 FTBFS due missing link libraries in plugins/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* common.c - Functions that are common to server and clinet
2
2
 * Rob Siemborski
3
3
 * Tim Martin
4
 
 * $Id: common.c,v 1.114 2006/04/19 18:39:59 mel Exp $
 
4
 * $Id: common.c,v 1.124 2009/02/20 23:10:53 mel Exp $
5
5
 */
6
6
/* 
7
7
 * Copyright (c) 1998-2003 Carnegie Mellon University.  All rights reserved.
122
122
static char * default_plugin_path = NULL;
123
123
static char * default_conf_path = NULL;
124
124
 
 
125
static int _sasl_global_getopt(void *context,
 
126
                               const char *plugin_name,
 
127
                               const char *option,
 
128
                               const char ** result,
 
129
                               unsigned *len);
 
130
 
125
131
/* Intenal mutex functions do as little as possible (no thread protection) */
126
132
static void *sasl_mutex_alloc(void)
127
133
{
150
156
  &sasl_mutex_free
151
157
};
152
158
 
153
 
void sasl_set_mutex(sasl_mutex_alloc_t *n, sasl_mutex_lock_t *l,
154
 
                    sasl_mutex_unlock_t *u, sasl_mutex_free_t *d)
 
159
void sasl_set_mutex(sasl_mutex_alloc_t *n,
 
160
                    sasl_mutex_lock_t *l,
 
161
                    sasl_mutex_unlock_t *u,
 
162
                    sasl_mutex_free_t *d)
155
163
{
156
 
        /* Disallow mutex function changes once sasl_client_init
157
 
           and/or sasl_server_init is called */
158
 
        if (_sasl_server_cleanup_hook || _sasl_client_cleanup_hook) {
159
 
                return;
160
 
        }
 
164
    /* Disallow mutex function changes once sasl_client_init
 
165
       and/or sasl_server_init is called */
 
166
    if (_sasl_server_cleanup_hook || _sasl_client_cleanup_hook) {
 
167
        return;
 
168
    }
161
169
 
162
 
  _sasl_mutex_utils.alloc=n;
163
 
  _sasl_mutex_utils.lock=l;
164
 
  _sasl_mutex_utils.unlock=u;
165
 
  _sasl_mutex_utils.free=d;
 
170
    _sasl_mutex_utils.alloc=n;
 
171
    _sasl_mutex_utils.lock=l;
 
172
    _sasl_mutex_utils.unlock=u;
 
173
    _sasl_mutex_utils.free=d;
166
174
}
167
175
 
168
176
/* copy a string to malloced memory */
247
255
 
248
256
/* return the version of the cyrus sasl library as compiled,
249
257
 * using 32 bits: high byte is major version, second byte is minor version,
250
 
 * low 16 bits are step # */
 
258
 * low 16 bits are step #.
 
259
 * Patch version is not available using this function,
 
260
 * use sasl_version_info() instead.
 
261
 */
251
262
void sasl_version(const char **implementation, int *version) 
252
263
{
253
264
    if(implementation) *implementation = implementation_string;
391
402
                 const char **output,
392
403
                 unsigned *outputlen)
393
404
{
394
 
    int result;
 
405
    int result = SASL_OK;
395
406
    unsigned i;
396
407
    unsigned j;
397
408
    size_t total_size = 0;
504
515
               the conn->oparams.maxoutbuf buffer. */
505
516
            /* Note, if next_buf points to the very end of the IOV record,
506
517
               it will be reset to NULL below */
507
 
            next_buf = last_invec.iov_base + last_invec.iov_len;
 
518
            /* Note, that some platforms define iov_base as "void *",
 
519
               thus the typecase below */
 
520
            next_buf = (char *) last_invec.iov_base + last_invec.iov_len;
508
521
            /* Note - remainder_len is how many bytes left to be encoded in
509
522
               the current IOV slot. */
510
523
            remainder_len = (total_size + invec[i].iov_len) - conn->oparams.maxoutbuf;
520
533
 
521
534
                /* Note, if next_buf points to the very end of the IOV record,
522
535
                   it will be reset to NULL below */
523
 
                next_buf = last_invec.iov_base + last_invec.iov_len;
 
536
                /* Note, that some platforms define iov_base as "void *",
 
537
                   thus the typecase below */
 
538
                next_buf = (char *) last_invec.iov_base + last_invec.iov_len;
524
539
                remainder_len = remainder_len - conn->oparams.maxoutbuf;
525
540
 
526
541
                result = _sasl_encodev (conn,
652
667
  _sasl_allocation_utils.free=f;
653
668
}
654
669
 
655
 
void sasl_done(void)
 
670
void sasl_common_done(void)
656
671
{
657
 
    if (_sasl_server_cleanup_hook && _sasl_server_cleanup_hook() == SASL_OK) {
658
 
        _sasl_server_idle_hook = NULL;
659
 
        _sasl_server_cleanup_hook = NULL;
660
 
    }
661
 
    
662
 
    if (_sasl_client_cleanup_hook && _sasl_client_cleanup_hook() == SASL_OK) {
663
 
        _sasl_client_idle_hook = NULL;  
664
 
        _sasl_client_cleanup_hook = NULL;
665
 
    }
666
 
    
667
 
    if (_sasl_server_cleanup_hook || _sasl_client_cleanup_hook) {
668
 
        return;
669
 
    }
670
 
 
671
672
    /* NOTE - the caller will need to reinitialize the values,
672
673
       if it is going to call sasl_client_init/sasl_server_init again. */
673
674
    if (default_plugin_path != NULL) {
687
688
    
688
689
    _sasl_free_utils(&sasl_global_utils);
689
690
    
690
 
    if(global_mech_list) sasl_FREE(global_mech_list);
691
 
    global_mech_list = NULL;
 
691
    if (global_mech_list) {
 
692
        sasl_FREE(global_mech_list);
 
693
        global_mech_list = NULL;
 
694
    }
 
695
}
 
696
 
 
697
/* This function is for backward compatibility */
 
698
void sasl_done(void)
 
699
{
 
700
    if (_sasl_server_cleanup_hook && _sasl_server_cleanup_hook() == SASL_OK) {
 
701
        _sasl_server_idle_hook = NULL;
 
702
        _sasl_server_cleanup_hook = NULL;
 
703
    }
 
704
    
 
705
    if (_sasl_client_cleanup_hook && _sasl_client_cleanup_hook() == SASL_OK) {
 
706
        _sasl_client_idle_hook = NULL;  
 
707
        _sasl_client_cleanup_hook = NULL;
 
708
    }
 
709
    
 
710
    if (_sasl_server_cleanup_hook || _sasl_client_cleanup_hook) {
 
711
        return;
 
712
    }
 
713
 
 
714
    sasl_common_done();
692
715
}
693
716
 
694
717
/* fills in the base sasl_conn_t info */
749
772
 
750
773
  if(serverFQDN) {
751
774
      result = _sasl_strdup(serverFQDN, &conn->serverFQDN, NULL);
 
775
      sasl_strlower (conn->serverFQDN);
752
776
  } else if (conn->type == SASL_CONN_SERVER) {
753
777
      /* We can fake it because we *are* the server */
754
778
      char name[MAXHOSTNAMELEN];
755
779
      memset(name, 0, sizeof(name));
756
 
      gethostname(name, MAXHOSTNAMELEN);
 
780
      if (get_fqhostname (name, MAXHOSTNAMELEN, 0) != 0) {
 
781
        return (SASL_FAIL);
 
782
      }
757
783
      
758
784
      result = _sasl_strdup(name, &conn->serverFQDN, NULL);
759
785
  } else {
769
795
int _sasl_common_init(sasl_global_callbacks_t *global_callbacks)
770
796
{
771
797
    int result;
772
 
    
 
798
 
 
799
    /* The last specified global callback always wins */
 
800
    if (sasl_global_utils != NULL) {
 
801
        sasl_utils_t * global_utils = (sasl_utils_t *)sasl_global_utils;
 
802
        global_utils->getopt = &_sasl_global_getopt;
 
803
        global_utils->getopt_context = global_callbacks;
 
804
    }
 
805
 
 
806
    /* Do nothing if we are already initialized */
 
807
    if (free_mutex) {
 
808
        return SASL_OK;
 
809
    }
 
810
 
773
811
    /* Setup the global utilities */
774
812
    if(!sasl_global_utils) {
775
813
        sasl_global_utils = _sasl_alloc_utils(NULL, global_callbacks);
780
818
    result = sasl_canonuser_add_plugin("INTERNAL", internal_canonuser_init);
781
819
    if(result != SASL_OK) return result;    
782
820
 
783
 
    if (!free_mutex || free_mutex == 0x1)
 
821
    if (!free_mutex || free_mutex == 0x1) {
784
822
        free_mutex = sasl_MUTEX_ALLOC();
 
823
    }
785
824
    if (!free_mutex) return SASL_FAIL;
786
825
 
787
826
    return SASL_OK;
859
898
 * returns:
860
899
 *  SASL_OK       -- no error
861
900
 *  SASL_NOTDONE  -- property not available yet
862
 
 *  SASL_BADPARAM -- bad property number
 
901
 *  SASL_BADPARAM -- bad property number or SASL context is NULL
863
902
 */
864
903
int sasl_getprop(sasl_conn_t *conn, int propnum, const void **pvalue)
865
904
{
1263
1302
    case SASL_NOCHANGE:   return "requested change was not needed";
1264
1303
    case SASL_WEAKPASS:   return "passphrase is too weak for security policy";
1265
1304
    case SASL_NOUSERPASS: return "user supplied passwords are not permitted";
 
1305
    case SASL_NEED_OLD_PASSWD: return "sasl_setpass needs old password in order "
 
1306
                                "to perform password change";
 
1307
    case SASL_CONSTRAINT_VIOLAT: return "sasl_setpass can't store a property because "
 
1308
                                "of a constraint violation";
1266
1309
 
1267
1310
    default:   return "undefined error!";
1268
1311
    }
2257
2300
    }
2258
2301
 
2259
2302
    if(!olist) {
 
2303
        /* This is not going to be very useful */
2260
2304
        printf ("no olist");
2261
2305
        return SASL_FAIL;
2262
2306
    }