~ubuntu-branches/debian/lenny/netatalk/lenny

« back to all changes in this revision

Viewing changes to etc/uams/uams_dhx_passwd.c

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2005-10-07 13:46:11 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20051007134611-r07qa2g67xwkp2if
Tags: 2.0.3-1ubuntu1
* debian/netatalk.init
  - run cnid_metad if CNID_METAD_RUN=yes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: uams_dhx_passwd.c,v 1.16.2.1 2003/06/14 17:12:17 srittau Exp $
 
2
 * $Id: uams_dhx_passwd.c,v 1.18.6.6 2004/03/18 02:56:32 bfernhomberg Exp $
3
3
 *
4
4
 * Copyright (c) 1990,1993 Regents of The University of Michigan.
5
5
 * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu) 
10
10
#include "config.h"
11
11
#endif /* HAVE_CONFIG_H */
12
12
 
 
13
#ifdef NETBSD
 
14
#define _XOPEN_SOURCE 500 /* for crypt() */
 
15
#endif
 
16
#ifdef FREEBSD
 
17
#define _XOPEN_SOURCE /* for crypt() */
 
18
#endif
 
19
 
13
20
#include <stdio.h>
14
21
#include <stdlib.h>
15
22
#include <string.h>
16
23
#ifdef HAVE_UNISTD_H
17
24
#include <unistd.h>
18
25
#endif /* HAVE_UNISTD_H */
19
 
#ifndef NO_CRYPT_H
 
26
#ifdef HAVE_CRYPT_H
20
27
#include <crypt.h>
21
 
#endif /* ! NO_CRYPT_H */
 
28
#endif /* ! HAVE_CRYPT_H */
 
29
#ifdef HAVE_SYS_TIME_H
 
30
#include <sys/time.h>
 
31
#endif
 
32
#ifdef HAVE_TIME_H
 
33
#include <time.h>
 
34
#endif
22
35
#include <pwd.h>
23
 
#include <atalk/logger.h>
24
 
 
25
36
#ifdef SHADOWPW
26
37
#include <shadow.h>
27
38
#endif /* SHADOWPW */
28
 
 
29
 
#ifdef OPENSSL_DHX
 
39
#if defined(GNUTLS_DHX)
 
40
#include <gnutls/openssl.h>
 
41
#elif defined(OPENSSL_DHX)
30
42
#include <openssl/bn.h>
31
43
#include <openssl/dh.h>
32
44
#include <openssl/cast.h>
36
48
#include <cast.h>
37
49
#endif /* OPENSSL_DHX */
38
50
 
 
51
#include <atalk/logger.h>
39
52
#include <atalk/afp.h>
40
53
#include <atalk/uam.h>
41
54
 
61
74
#endif /* TRU64 */
62
75
 
63
76
/* dhx passwd */
64
 
static int passwd_login(void *obj, struct passwd **uam_pwd,
 
77
static int pwd_login(void *obj, char *username, int ulen, struct passwd **uam_pwd,
65
78
                        char *ibuf, int ibuflen,
66
79
                        char *rbuf, int *rbuflen)
67
80
{
74
87
#endif /* SHADOWPW */
75
88
    BIGNUM *bn, *gbn, *pbn;
76
89
    u_int16_t sessid;
77
 
    int len, i;
78
 
    char *name;
 
90
    int i;
79
91
    DH *dh;
80
92
 
81
93
#ifdef TRU64
87
99
 
88
100
    *rbuflen = 0;
89
101
 
90
 
    if (uam_afpserver_option(obj, UAM_OPTION_USERNAME, (void *) &name, &i) < 0)
91
 
      return AFPERR_PARAM;
92
 
 
93
102
#ifdef TRU64
94
103
    if( uam_afpserver_option( obj, UAM_OPTION_CLIENTNAME,
95
104
                              (void *) &clientname, NULL ) < 0 )
96
105
        return AFPERR_PARAM;
97
106
#endif /* TRU64 */
98
107
 
99
 
    len = (unsigned char) *ibuf++;
100
 
    if ( len + 1 > i ) {
101
 
        return( AFPERR_PARAM );
102
 
    }
103
 
 
104
 
    memcpy(name, ibuf, len );
105
 
    ibuf += len;
106
 
    name[ len ] = '\0';
107
 
    if ((unsigned long) ibuf & 1) /* padding */
108
 
      ++ibuf;
109
 
 
110
 
    if (( dhxpwd = uam_getname(name, i)) == NULL ) {
111
 
      return AFPERR_PARAM;
112
 
    }
113
 
 
114
 
    LOG(log_info, logtype_uams, "dhx login: %s", name);
 
108
    if (( dhxpwd = uam_getname(obj, username, ulen)) == NULL ) {
 
109
        return AFPERR_PARAM;
 
110
    }
 
111
    
 
112
    LOG(log_info, logtype_uams, "dhx login: %s", username);
115
113
    if (uam_checkuser(dhxpwd) < 0)
116
114
      return AFPERR_NOTAUTH;
117
115
 
118
116
#ifdef SHADOWPW
119
117
    if (( sp = getspnam( dhxpwd->pw_name )) == NULL ) {
120
 
        LOG(log_info, logtype_uams, "no shadow passwd entry for %s", name);
 
118
        LOG(log_info, logtype_uams, "no shadow passwd entry for %s", username);
121
119
        return AFPERR_NOTAUTH;
122
120
    }
123
121
    dhxpwd->pw_passwd = sp->sp_pwdp;
209
207
    return AFPERR_PARAM;
210
208
}
211
209
 
 
210
/* cleartxt login */
 
211
static int passwd_login(void *obj, struct passwd **uam_pwd,
 
212
                        char *ibuf, int ibuflen,
 
213
                        char *rbuf, int *rbuflen)
 
214
{
 
215
    char *username;
 
216
    int len, ulen;
 
217
 
 
218
    *rbuflen = 0;
 
219
 
 
220
    if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
 
221
                             (void *) &username, &ulen) < 0)
 
222
        return AFPERR_MISC;
 
223
 
 
224
    if (ibuflen <= 1) {
 
225
        return( AFPERR_PARAM );
 
226
    }
 
227
 
 
228
    len = (unsigned char) *ibuf++;
 
229
    ibuflen--;
 
230
    if (!len || len > ibuflen || len > ulen ) {
 
231
        return( AFPERR_PARAM );
 
232
    }
 
233
    memcpy(username, ibuf, len );
 
234
    ibuf += len;
 
235
    ibuflen -=len;
 
236
    username[ len ] = '\0';
 
237
 
 
238
    if ((unsigned long) ibuf & 1) { /* pad character */
 
239
        ++ibuf;
 
240
        ibuflen--;
 
241
    }
 
242
    return (pwd_login(obj, username, ulen, uam_pwd, ibuf, ibuflen, rbuf, rbuflen));
 
243
    
 
244
}
 
245
 
 
246
/* cleartxt login ext 
 
247
 * uname format :
 
248
    byte      3
 
249
    2 bytes   len (network order)
 
250
    len bytes utf8 name
 
251
*/
 
252
static int passwd_login_ext(void *obj, char *uname, struct passwd **uam_pwd,
 
253
                        char *ibuf, int ibuflen,
 
254
                        char *rbuf, int *rbuflen)
 
255
{
 
256
    char       *username;
 
257
    int        len, ulen;
 
258
    u_int16_t  temp16;
 
259
 
 
260
    *rbuflen = 0;
 
261
    
 
262
    if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
 
263
                             (void *) &username, &ulen) < 0)
 
264
        return AFPERR_MISC;
 
265
 
 
266
    if (*uname != 3)
 
267
        return AFPERR_PARAM;
 
268
    uname++;
 
269
    memcpy(&temp16, uname, sizeof(temp16));
 
270
    len = ntohs(temp16);
 
271
    if (!len || len > ulen ) {
 
272
        return( AFPERR_PARAM );
 
273
    }
 
274
    memcpy(username, uname +2, len );
 
275
    username[ len ] = '\0';
 
276
    return (pwd_login(obj, username, ulen, uam_pwd, ibuf, ibuflen, rbuf, rbuflen));
 
277
}
 
278
                        
212
279
static int passwd_logincont(void *obj, struct passwd **uam_pwd,
213
280
                            char *ibuf, int ibuflen, 
214
281
                            char *rbuf, int *rbuflen)
215
282
{
 
283
#ifdef SHADOWPW
 
284
    struct spwd *sp;
 
285
#endif /* SHADOWPW */
216
286
    unsigned char iv[] = "LWallace";
217
287
    BIGNUM *bn1, *bn2, *bn3;
218
288
    u_int16_t sessid;
219
289
    char *p;
 
290
    int err = AFPERR_NOTAUTH;
220
291
 
221
292
    *rbuflen = 0;
222
293
 
285
356
    memset(rbuf, 0, PASSWDLEN);
286
357
    if ( strcmp( p, dhxpwd->pw_passwd ) == 0 ) {
287
358
      *uam_pwd = dhxpwd;
288
 
      return AFP_OK;
289
 
    }
 
359
      err = AFP_OK;
 
360
    }
 
361
#ifdef SHADOWPW
 
362
    if (( sp = getspnam( dhxpwd->pw_name )) == NULL ) {
 
363
        LOG(log_info, logtype_uams, "no shadow passwd entry for %s", dhxpwd->pw_name);
 
364
        return (AFPERR_NOTAUTH);
 
365
    }
 
366
 
 
367
    /* check for expired password */
 
368
    if (sp && sp->sp_max != -1 && sp->sp_lstchg) {
 
369
        time_t now = time(NULL) / (60*60*24);
 
370
        int32_t expire_days = sp->sp_lstchg - now + sp->sp_max;
 
371
        if ( expire_days < 0 ) {
 
372
                LOG(log_info, logtype_uams, "password for user %s expired", dhxpwd->pw_name);
 
373
                err = AFPERR_PWDEXPR;
 
374
        }
 
375
    }
 
376
#endif /* SHADOWPW */
 
377
    return err;
290
378
#endif /* TRU64 */
291
379
 
292
380
    return AFPERR_NOTAUTH;
295
383
 
296
384
static int uam_setup(const char *path)
297
385
{
298
 
  if (uam_register(UAM_SERVER_LOGIN, path, "DHCAST128",
299
 
                   passwd_login, passwd_logincont, NULL) < 0)
 
386
  if (uam_register(UAM_SERVER_LOGIN_EXT, path, "DHCAST128",
 
387
                   passwd_login, passwd_logincont, NULL, passwd_login_ext) < 0)
300
388
    return -1;
301
389
  /*uam_register(UAM_SERVER_PRINTAUTH, path, "DHCAST128",
302
390
    passwd_printer);*/