From 1db2f6dcdd7ee7f6966a72c5aa1d49454e982b87 Mon Sep 17 00:00:00 2001 From: jmarcus Date: Mon, 3 Dec 2001 05:01:03 +0000 Subject: [PATCH] BIG commit to improve code style using astyle as well as fix up CNID DB so it might actually fair in production. Also, removed a compiler warning when an unsinged variable was being tested as being less than 0. --- etc/afpd/afp_asp.c | 262 ++-- etc/afpd/afp_config.c | 664 +++++----- etc/afpd/afp_config.h | 20 +- etc/afpd/afp_dsi.c | 392 +++--- etc/afpd/afp_options.c | 542 ++++----- etc/afpd/afs.c | 156 +-- etc/afpd/appl.c | 302 ++--- etc/afpd/auth.c | 452 +++---- etc/afpd/codepage.c | 316 ++--- etc/afpd/codepage.h | 4 +- etc/afpd/desktop.c | 834 ++++++------- etc/afpd/directory.c | 2342 ++++++++++++++++++------------------ etc/afpd/directory.h | 14 +- etc/afpd/enumerate.c | 434 +++---- etc/afpd/file.c | 1650 ++++++++++++------------- etc/afpd/file.h | 8 +- etc/afpd/filedir.c | 492 ++++---- etc/afpd/filedir.h | 14 +- etc/afpd/fork.c | 1466 +++++++++++----------- etc/afpd/fork.h | 16 +- etc/afpd/gettok.c | 178 +-- etc/afpd/globals.h | 54 +- etc/afpd/icon.h | 130 +- etc/afpd/main.c | 162 +-- etc/afpd/messages.c | 188 +-- etc/afpd/misc.h | 4 +- etc/afpd/nfsquota.c | 190 +-- etc/afpd/nls/makecode.c | 254 ++-- etc/afpd/nls/parsecode.c | 110 +- etc/afpd/ofork.c | 202 ++-- etc/afpd/parse_mtab.c | 264 ++-- etc/afpd/parse_mtab.h | 34 +- etc/afpd/passwd.c | 60 +- etc/afpd/quota.c | 274 ++--- etc/afpd/status.c | 368 +++--- etc/afpd/status.h | 4 +- etc/afpd/switch.c | 50 +- etc/afpd/test_parse_mtab.c | 86 +- etc/afpd/uam.c | 576 ++++----- etc/afpd/uam_auth.h | 38 +- etc/afpd/uid.c | 108 +- etc/afpd/uid.h | 6 +- etc/afpd/unix.c | 532 ++++---- etc/afpd/unix.h | 6 +- etc/afpd/volume.c | 1476 +++++++++++------------ etc/afpd/volume.h | 30 +- 46 files changed, 7883 insertions(+), 7881 deletions(-) diff --git a/etc/afpd/afp_asp.c b/etc/afpd/afp_asp.c index 89641691..98ff23fb 100644 --- a/etc/afpd/afp_asp.c +++ b/etc/afpd/afp_asp.c @@ -1,5 +1,5 @@ -/* - * $Id: afp_asp.c,v 1.6 2001-07-31 19:50:14 srittau Exp $ +/* + * $Id: afp_asp.c,v 1.6.2.1 2001-12-03 05:01:03 jmarcus Exp $ * * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu) * Copyright (c) 1990,1993 Regents of The University of Michigan. @@ -44,13 +44,13 @@ static AFPObj *child; static __inline__ void afp_asp_close(AFPObj *obj) { ASP asp = obj->handle; - + if (obj->logout) - (*obj->logout)(); + (*obj->logout)(); asp_close( asp ); syslog(LOG_INFO, "%.2fKB read, %.2fKB written", - asp->read_count / 1024.0, asp->write_count / 1024.0); + asp->read_count / 1024.0, asp->write_count / 1024.0); } static void afp_asp_die(const int sig) @@ -59,14 +59,14 @@ static void afp_asp_die(const int sig) asp_attention(asp, AFPATTN_SHUTDOWN); if ( asp_shutdown( asp ) < 0 ) { - syslog( LOG_ERR, "afp_die: asp_shutdown: %m" ); + syslog( LOG_ERR, "afp_die: asp_shutdown: %m" ); } afp_asp_close(child); if (sig == SIGTERM || sig == SIGALRM) - exit( 0 ); + exit( 0 ); else - exit(sig); + exit(sig); } static void afp_asp_timedown() @@ -76,15 +76,15 @@ static void afp_asp_timedown() /* shutdown and don't reconnect. server going down in 5 minutes. */ asp_attention(child->handle, AFPATTN_SHUTDOWN | AFPATTN_NORECONNECT | - AFPATTN_TIME(5)); + AFPATTN_TIME(5)); it.it_interval.tv_sec = 0; it.it_interval.tv_usec = 0; it.it_value.tv_sec = 300; it.it_value.tv_usec = 0; if ( setitimer( ITIMER_REAL, &it, 0 ) < 0 ) { - syslog( LOG_ERR, "afp_timedown: setitimer: %m" ); - afp_asp_die(1); + syslog( LOG_ERR, "afp_timedown: setitimer: %m" ); + afp_asp_die(1); } memset(&sv, 0, sizeof(sv)); @@ -92,8 +92,8 @@ static void afp_asp_timedown() sigemptyset( &sv.sa_mask ); sv.sa_flags = SA_RESTART; if ( sigaction( SIGALRM, &sv, 0 ) < 0 ) { - syslog( LOG_ERR, "afp_timedown: sigaction: %m" ); - afp_asp_die(1); + syslog( LOG_ERR, "afp_timedown: sigaction: %m" ); + afp_asp_die(1); } } @@ -115,139 +115,139 @@ void afp_over_asp(AFPObj *obj) sigemptyset( &action.sa_mask ); action.sa_flags = SA_RESTART; if ( sigaction( SIGHUP, &action, 0 ) < 0 ) { - syslog( LOG_ERR, "afp_over_asp: sigaction: %m" ); - afp_asp_die(1); + syslog( LOG_ERR, "afp_over_asp: sigaction: %m" ); + afp_asp_die(1); } action.sa_handler = afp_asp_die; sigemptyset( &action.sa_mask ); action.sa_flags = SA_RESTART; if ( sigaction( SIGTERM, &action, 0 ) < 0 ) { - syslog( LOG_ERR, "afp_over_asp: sigaction: %m" ); - afp_asp_die(1); + syslog( LOG_ERR, "afp_over_asp: sigaction: %m" ); + afp_asp_die(1); } syslog( LOG_INFO, "session from %u.%u:%u on %u.%u:%u", - ntohs( asp->asp_sat.sat_addr.s_net ), - asp->asp_sat.sat_addr.s_node, asp->asp_sat.sat_port, - ntohs( atp_sockaddr( asp->asp_atp )->sat_addr.s_net ), - atp_sockaddr( asp->asp_atp )->sat_addr.s_node, - atp_sockaddr( asp->asp_atp )->sat_port ); + ntohs( asp->asp_sat.sat_addr.s_net ), + asp->asp_sat.sat_addr.s_node, asp->asp_sat.sat_port, + ntohs( atp_sockaddr( asp->asp_atp )->sat_addr.s_net ), + atp_sockaddr( asp->asp_atp )->sat_addr.s_node, + atp_sockaddr( asp->asp_atp )->sat_port ); while ((reply = asp_getrequest(asp))) { - switch (reply) { - case ASPFUNC_CLOSE : - if (obj->options.authprintdir) { - char addr_filename[256]; - struct stat cap_st; - - sprintf(addr_filename, "%s/net%d.%dnode%d", obj->options.authprintdir, - ntohs( asp->asp_sat.sat_addr.s_net )/256, - ntohs( asp->asp_sat.sat_addr.s_net )%256, - asp->asp_sat.sat_addr.s_node ); - - if(stat(addr_filename, &cap_st) == 0) { - if(unlink(addr_filename) == 0) { - syslog(LOG_INFO, "removed %s", addr_filename); - } else { - syslog(LOG_INFO, "error removing %s: %m", addr_filename); - } - } else { - syslog(LOG_INFO, "error stat'ing %s: %m", addr_filename); - } - } - - afp_asp_close(obj); - syslog( LOG_INFO, "done" ); - - if ( obj->options.flags & OPTION_DEBUG ) { - printf( "done\n" ); - } - return; - break; - - case ASPFUNC_CMD : + switch (reply) { + case ASPFUNC_CLOSE : + if (obj->options.authprintdir) { + char addr_filename[256]; + struct stat cap_st; + + sprintf(addr_filename, "%s/net%d.%dnode%d", obj->options.authprintdir, + ntohs( asp->asp_sat.sat_addr.s_net )/256, + ntohs( asp->asp_sat.sat_addr.s_net )%256, + asp->asp_sat.sat_addr.s_node ); + + if(stat(addr_filename, &cap_st) == 0) { + if(unlink(addr_filename) == 0) { + syslog(LOG_INFO, "removed %s", addr_filename); + } else { + syslog(LOG_INFO, "error removing %s: %m", addr_filename); + } + } else { + syslog(LOG_INFO, "error stat'ing %s: %m", addr_filename); + } + } + + afp_asp_close(obj); + syslog( LOG_INFO, "done" ); + + if ( obj->options.flags & OPTION_DEBUG ) { + printf( "done\n" ); + } + return; + break; + + case ASPFUNC_CMD : #ifdef AFS - if ( writtenfork ) { - if ( flushfork( writtenfork ) < 0 ) { - syslog( LOG_ERR, "main flushfork: %m" ); - } - writtenfork = NULL; - } + if ( writtenfork ) { + if ( flushfork( writtenfork ) < 0 ) { + syslog( LOG_ERR, "main flushfork: %m" ); + } + writtenfork = NULL; + } #endif /* AFS */ - func = (u_char) asp->commands[0]; - if ( obj->options.flags & OPTION_DEBUG ) { - printf( "command: %d\n", func ); - bprint( asp->commands, asp->cmdlen ); - } - if ( afp_switch[ func ] != NULL ) { - /* - * The function called from afp_switch is expected to - * read its parameters out of buf, put its - * results in replybuf (updating rbuflen), and - * return an error code. - */ - asp->datalen = ASP_DATASIZ; - reply = (*afp_switch[ func ])(obj, - asp->commands, asp->cmdlen, - asp->data, &asp->datalen); - } else { - syslog( LOG_ERR, "bad function %X", func ); - asp->datalen = 0; - reply = AFPERR_NOOP; - } - if ( obj->options.flags & OPTION_DEBUG ) { - printf( "reply: %d, %d\n", reply, ccnt++ ); - bprint( asp->data, asp->datalen ); - } - - if ( asp_cmdreply( asp, reply ) < 0 ) { - syslog( LOG_ERR, "asp_cmdreply: %m" ); - afp_asp_die(1); - } - break; - - case ASPFUNC_WRITE : - func = (u_char) asp->commands[0]; - if ( obj->options.flags & OPTION_DEBUG ) { - printf( "(write) command: %d\n", func ); - bprint( asp->commands, asp->cmdlen ); - } - if ( afp_switch[ func ] != NULL ) { - asp->datalen = ASP_DATASIZ; - reply = (*afp_switch[ func ])(obj, - asp->commands, asp->cmdlen, - asp->data, &asp->datalen); - } else { - syslog( LOG_ERR, "(write) bad function %X", func ); - asp->datalen = 0; - reply = AFPERR_NOOP; - } - if ( obj->options.flags & OPTION_DEBUG ) { - printf( "(write) reply code: %d, %d\n", reply, ccnt++ ); - bprint( asp->data, asp->datalen ); - } - if ( asp_wrtreply( asp, reply ) < 0 ) { - syslog( LOG_ERR, "asp_wrtreply: %m" ); - afp_asp_die(1); - } - break; - default: - /* - * Bad asp packet. Probably should have asp filter them, - * since they are typically things like out-of-order packet. - */ - syslog( LOG_INFO, "main: asp_getrequest: %d", reply ); - break; - } - - if ( obj->options.flags & OPTION_DEBUG ) { + func = (u_char) asp->commands[0]; + if ( obj->options.flags & OPTION_DEBUG ) { + printf( "command: %d\n", func ); + bprint( asp->commands, asp->cmdlen ); + } + if ( afp_switch[ func ] != NULL ) { + /* + * The function called from afp_switch is expected to + * read its parameters out of buf, put its + * results in replybuf (updating rbuflen), and + * return an error code. + */ + asp->datalen = ASP_DATASIZ; + reply = (*afp_switch[ func ])(obj, + asp->commands, asp->cmdlen, + asp->data, &asp->datalen); + } else { + syslog( LOG_ERR, "bad function %X", func ); + asp->datalen = 0; + reply = AFPERR_NOOP; + } + if ( obj->options.flags & OPTION_DEBUG ) { + printf( "reply: %d, %d\n", reply, ccnt++ ); + bprint( asp->data, asp->datalen ); + } + + if ( asp_cmdreply( asp, reply ) < 0 ) { + syslog( LOG_ERR, "asp_cmdreply: %m" ); + afp_asp_die(1); + } + break; + + case ASPFUNC_WRITE : + func = (u_char) asp->commands[0]; + if ( obj->options.flags & OPTION_DEBUG ) { + printf( "(write) command: %d\n", func ); + bprint( asp->commands, asp->cmdlen ); + } + if ( afp_switch[ func ] != NULL ) { + asp->datalen = ASP_DATASIZ; + reply = (*afp_switch[ func ])(obj, + asp->commands, asp->cmdlen, + asp->data, &asp->datalen); + } else { + syslog( LOG_ERR, "(write) bad function %X", func ); + asp->datalen = 0; + reply = AFPERR_NOOP; + } + if ( obj->options.flags & OPTION_DEBUG ) { + printf( "(write) reply code: %d, %d\n", reply, ccnt++ ); + bprint( asp->data, asp->datalen ); + } + if ( asp_wrtreply( asp, reply ) < 0 ) { + syslog( LOG_ERR, "asp_wrtreply: %m" ); + afp_asp_die(1); + } + break; + default: + /* + * Bad asp packet. Probably should have asp filter them, + * since they are typically things like out-of-order packet. + */ + syslog( LOG_INFO, "main: asp_getrequest: %d", reply ); + break; + } + + if ( obj->options.flags & OPTION_DEBUG ) { #ifdef notdef - pdesc( stdout ); + pdesc( stdout ); #endif /* notdef */ - of_pforkdesc( stdout ); - fflush( stdout ); - } + of_pforkdesc( stdout ); + fflush( stdout ); + } } } diff --git a/etc/afpd/afp_config.c b/etc/afpd/afp_config.c index a084c730..240f5e42 100644 --- a/etc/afpd/afp_config.c +++ b/etc/afpd/afp_config.c @@ -1,5 +1,5 @@ -/* - * $Id: afp_config.c,v 1.7 2001-09-23 18:47:52 jmarcus Exp $ +/* + * $Id: afp_config.c,v 1.7.2.1 2001-12-03 05:01:03 jmarcus Exp $ * * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu) * All Rights Reserved. See COPYRIGHT. @@ -61,71 +61,71 @@ static char srvloc_url[512]; * garbage collection ... */ void configfree(AFPConfig *configs, const AFPConfig *config) { - AFPConfig *p, *q; + AFPConfig *p, *q; - for (p = configs; p; p = q) { - q = p->next; - if (p == config) - continue; + for (p = configs; p; p = q) { + q = p->next; + if (p == config) + continue; - /* do a little reference counting */ - if (--(*p->optcount) < 1) { - afp_options_free(&p->obj.options, p->defoptions); - free(p->optcount); - } + /* do a little reference counting */ + if (--(*p->optcount) < 1) { + afp_options_free(&p->obj.options, p->defoptions); + free(p->optcount); + } - switch (p->obj.proto) { + switch (p->obj.proto) { #ifndef NO_DDP - case AFPPROTO_ASP: - free(p->obj.Obj); - free(p->obj.Type); - free(p->obj.Zone); - atp_close(((ASP) p->obj.handle)->asp_atp); - free(p->obj.handle); - break; + case AFPPROTO_ASP: + free(p->obj.Obj); + free(p->obj.Type); + free(p->obj.Zone); + atp_close(((ASP) p->obj.handle)->asp_atp); + free(p->obj.handle); + break; #endif /* no afp/asp */ - case AFPPROTO_DSI: - close(p->fd); - free(p->obj.handle); - break; + case AFPPROTO_DSI: + close(p->fd); + free(p->obj.handle); + break; + } + free(p); } - free(p); - } } #ifdef USE_SRVLOC static void SRVLOC_callback(SLPHandle hslp, SLPError errcode, void *cookie) { - *(SLPError*)cookie = errcode; + *(SLPError*)cookie = errcode; } #endif /* USE_SRVLOC */ #ifdef USE_SRVLOC static void dsi_cleanup(const AFPConfig *config) { - SLPError err; - SLPError callbackerr; - SLPHandle hslp; - err = SLPOpen("en", SLP_FALSE, &hslp); - if (err != SLP_OK) { - syslog(LOG_ERR, "Error opening SRVLOC handle"); - goto srvloc_dereg_err; - } - - err = SLPDereg(hslp, - srvloc_url, - SRVLOC_callback, - &callbackerr); - if (err != SLP_OK) { - syslog(LOG_ERR, "Error unregistering %s from SRVLOC", srvloc_url); - goto srvloc_dereg_err; - } - - if (callbackerr != SLP_OK) { - syslog(LOG_ERR, "Error in callback while trying to unregister %s from SRVLOC (%i)", srvloc_url, callbackerr); - goto srvloc_dereg_err; - } - - srvloc_dereg_err: + SLPError err; + SLPError callbackerr; + SLPHandle hslp; + err = SLPOpen("en", SLP_FALSE, &hslp); + if (err != SLP_OK) { + syslog(LOG_ERR, "Error opening SRVLOC handle"); + goto srvloc_dereg_err; + } + + err = SLPDereg(hslp, + srvloc_url, + SRVLOC_callback, + &callbackerr); + if (err != SLP_OK) { + syslog(LOG_ERR, "Error unregistering %s from SRVLOC", srvloc_url); + goto srvloc_dereg_err; + } + + if (callbackerr != SLP_OK) { + syslog(LOG_ERR, "Error in callback while trying to unregister %s from SRVLOC (%i)", srvloc_url, callbackerr); + goto srvloc_dereg_err; + } + +srvloc_dereg_err: SLPClose(hslp); } #endif /* USE_SRVLOC */ @@ -133,343 +133,343 @@ static void dsi_cleanup(const AFPConfig *config) #ifndef NO_DDP static void asp_cleanup(const AFPConfig *config) { - nbp_unrgstr(config->obj.Obj, config->obj.Type, config->obj.Zone, - &config->obj.options.ddpaddr); + nbp_unrgstr(config->obj.Obj, config->obj.Type, config->obj.Zone, + &config->obj.options.ddpaddr); } /* these two are almost identical. it should be possible to collapse them * into one with minimal junk. */ -static int asp_start(AFPConfig *config, AFPConfig *configs, - server_child *server_children) +static int asp_start(AFPConfig *config, AFPConfig *configs, + server_child *server_children) { - ASP asp; - - if (!(asp = asp_getsession(config->obj.handle, server_children, - config->obj.options.tickleval))) { - syslog( LOG_ERR, "main: asp_getsession: %m" ); - exit( 1 ); - } - - if (asp->child) { - configfree(configs, config); /* free a bunch of stuff */ - afp_over_asp(&config->obj); - exit (0); - } - - return 0; + ASP asp; + + if (!(asp = asp_getsession(config->obj.handle, server_children, + config->obj.options.tickleval))) { + syslog( LOG_ERR, "main: asp_getsession: %m" ); + exit( 1 ); + } + + if (asp->child) { + configfree(configs, config); /* free a bunch of stuff */ + afp_over_asp(&config->obj); + exit (0); + } + + return 0; } #endif /* no afp/asp */ static int dsi_start(AFPConfig *config, AFPConfig *configs, - server_child *server_children) + server_child *server_children) { - DSI *dsi; - - if (!(dsi = dsi_getsession(config->obj.handle, server_children, - config->obj.options.tickleval))) { - syslog( LOG_ERR, "main: dsi_getsession: %m" ); - exit( 1 ); - } - - /* we've forked. */ - if (dsi->child) { - configfree(configs, config); - afp_over_dsi(&config->obj); /* start a session */ - exit (0); - } - - return 0; + DSI *dsi; + + if (!(dsi = dsi_getsession(config->obj.handle, server_children, + config->obj.options.tickleval))) { + syslog( LOG_ERR, "main: dsi_getsession: %m" ); + exit( 1 ); + } + + /* we've forked. */ + if (dsi->child) { + configfree(configs, config); + afp_over_dsi(&config->obj); /* start a session */ + exit (0); + } + + return 0; } #ifndef NO_DDP static AFPConfig *ASPConfigInit(const struct afp_options *options, - unsigned char *refcount) + unsigned char *refcount) { - AFPConfig *config; - ATP atp; - ASP asp; - char *Obj, *Type = "AFPServer", *Zone = "*"; - - if ((config = (AFPConfig *) calloc(1, sizeof(AFPConfig))) == NULL) - return NULL; - - if ((atp = atp_open(ATADDR_ANYPORT, &options->ddpaddr)) == NULL) { - syslog( LOG_ERR, "main: atp_open: %m"); - free(config); - return NULL; - } - - if ((asp = asp_init( atp )) == NULL) { - syslog( LOG_ERR, "main: asp_init: %m" ); - atp_close(atp); - free(config); - return NULL; - } - - /* register asp server */ - Obj = (char *) options->hostname; - if (nbp_name(options->server, &Obj, &Type, &Zone )) { - syslog( LOG_ERR, "main: can't parse %s", options->server ); - goto serv_free_return; - } - - /* dup Obj, Type and Zone as they get assigned to a single internal - * buffer by nbp_name */ - if ((config->obj.Obj = strdup(Obj)) == NULL) - goto serv_free_return; - - if ((config->obj.Type = strdup(Type)) == NULL) { - free(config->obj.Obj); - goto serv_free_return; - } - - if ((config->obj.Zone = strdup(Zone)) == NULL) { - free(config->obj.Obj); - free(config->obj.Type); - goto serv_free_return; - } - - /* make sure we're not registered */ - nbp_unrgstr(Obj, Type, Zone, &options->ddpaddr); - if (nbp_rgstr( atp_sockaddr( atp ), Obj, Type, Zone ) < 0 ) { - syslog( LOG_ERR, "Can't register %s:%s@%s", Obj, Type, Zone ); - free(config->obj.Obj); - free(config->obj.Type); - free(config->obj.Zone); - goto serv_free_return; - } - - syslog( LOG_INFO, "%s:%s@%s started on %u.%u:%u (%s)", Obj, Type, Zone, - ntohs( atp_sockaddr( atp )->sat_addr.s_net ), - atp_sockaddr( atp )->sat_addr.s_node, - atp_sockaddr( atp )->sat_port, VERSION ); - - config->fd = atp_fileno(atp); - config->obj.handle = asp; - config->obj.config = config; - config->obj.proto = AFPPROTO_ASP; - - memcpy(&config->obj.options, options, sizeof(struct afp_options)); - config->optcount = refcount; - (*refcount)++; - - config->server_start = asp_start; - config->server_cleanup = asp_cleanup; - - return config; + AFPConfig *config; + ATP atp; + ASP asp; + char *Obj, *Type = "AFPServer", *Zone = "*"; + + if ((config = (AFPConfig *) calloc(1, sizeof(AFPConfig))) == NULL) + return NULL; + + if ((atp = atp_open(ATADDR_ANYPORT, &options->ddpaddr)) == NULL) { + syslog( LOG_ERR, "main: atp_open: %m"); + free(config); + return NULL; + } + + if ((asp = asp_init( atp )) == NULL) { + syslog( LOG_ERR, "main: asp_init: %m" ); + atp_close(atp); + free(config); + return NULL; + } + + /* register asp server */ + Obj = (char *) options->hostname; + if (nbp_name(options->server, &Obj, &Type, &Zone )) { + syslog( LOG_ERR, "main: can't parse %s", options->server ); + goto serv_free_return; + } + + /* dup Obj, Type and Zone as they get assigned to a single internal + * buffer by nbp_name */ + if ((config->obj.Obj = strdup(Obj)) == NULL) + goto serv_free_return; + + if ((config->obj.Type = strdup(Type)) == NULL) { + free(config->obj.Obj); + goto serv_free_return; + } + + if ((config->obj.Zone = strdup(Zone)) == NULL) { + free(config->obj.Obj); + free(config->obj.Type); + goto serv_free_return; + } + + /* make sure we're not registered */ + nbp_unrgstr(Obj, Type, Zone, &options->ddpaddr); + if (nbp_rgstr( atp_sockaddr( atp ), Obj, Type, Zone ) < 0 ) { + syslog( LOG_ERR, "Can't register %s:%s@%s", Obj, Type, Zone ); + free(config->obj.Obj); + free(config->obj.Type); + free(config->obj.Zone); + goto serv_free_return; + } + + syslog( LOG_INFO, "%s:%s@%s started on %u.%u:%u (%s)", Obj, Type, Zone, + ntohs( atp_sockaddr( atp )->sat_addr.s_net ), + atp_sockaddr( atp )->sat_addr.s_node, + atp_sockaddr( atp )->sat_port, VERSION ); + + config->fd = atp_fileno(atp); + config->obj.handle = asp; + config->obj.config = config; + config->obj.proto = AFPPROTO_ASP; + + memcpy(&config->obj.options, options, sizeof(struct afp_options)); + config->optcount = refcount; + (*refcount)++; + + config->server_start = asp_start; + config->server_cleanup = asp_cleanup; + + return config; serv_free_return: - asp_close(asp); - free(config); - return NULL; + asp_close(asp); + free(config); + return NULL; } #endif /* no afp/asp */ static AFPConfig *DSIConfigInit(const struct afp_options *options, - unsigned char *refcount, - const dsi_proto protocol) + unsigned char *refcount, + const dsi_proto protocol) { - AFPConfig *config; - DSI *dsi; - char *p, *q; + AFPConfig *config; + DSI *dsi; + char *p, *q; #ifdef USE_SRVLOC - SLPError err; - SLPError callbackerr; - SLPHandle hslp; - struct servent *afpovertcp; + SLPError err; + SLPError callbackerr; + SLPHandle hslp; + struct servent *afpovertcp; #endif /* USE_SRVLOC */ - if ((config = (AFPConfig *) calloc(1, sizeof(AFPConfig))) == NULL) { - syslog( LOG_ERR, "DSIConfigInit: malloc(config): %m" ); - return NULL; - } + if ((config = (AFPConfig *) calloc(1, sizeof(AFPConfig))) == NULL) { + syslog( LOG_ERR, "DSIConfigInit: malloc(config): %m" ); + return NULL; + } - if ((dsi = dsi_init(protocol, "afpd", options->hostname, - options->ipaddr, options->port, - options->flags & OPTION_PROXY, - options->server_quantum)) == NULL) { - syslog( LOG_ERR, "main: dsi_init: %m" ); - free(config); - return NULL; - } - - if (options->flags & OPTION_PROXY) { - syslog(LOG_INFO, "ASIP proxy initialized for %s:%d (%s)", - inet_ntoa(dsi->server.sin_addr), ntohs(dsi->server.sin_port), - VERSION); - } else { - syslog(LOG_INFO, "ASIP started on %s:%d(%d) (%s)", - inet_ntoa(dsi->server.sin_addr), ntohs(dsi->server.sin_port), - dsi->serversock, VERSION); - } + if ((dsi = dsi_init(protocol, "afpd", options->hostname, + options->ipaddr, options->port, + options->flags & OPTION_PROXY, + options->server_quantum)) == NULL) { + syslog( LOG_ERR, "main: dsi_init: %m" ); + free(config); + return NULL; + } + + if (options->flags & OPTION_PROXY) { + syslog(LOG_INFO, "ASIP proxy initialized for %s:%d (%s)", + inet_ntoa(dsi->server.sin_addr), ntohs(dsi->server.sin_port), + VERSION); + } else { + syslog(LOG_INFO, "ASIP started on %s:%d(%d) (%s)", + inet_ntoa(dsi->server.sin_addr), ntohs(dsi->server.sin_port), + dsi->serversock, VERSION); + } #ifdef USE_SRVLOC - err = SLPOpen("en", SLP_FALSE, &hslp); - if (err != SLP_OK) { - syslog(LOG_ERR, "Error opening SRVLOC handle"); - goto srvloc_reg_err; - } - - /* XXX We don't want to tack on the port number if we don't have to. Why? - * Well, this seems to break MacOS < 10. If the user _really_ wants to - * use a non-default port, they can, but be aware, this server might not - * show up int the Network Browser. */ - afpovertcp = getservbyname("afpovertcp", "tcp"); - if (dsi->server.sin_port == afpovertcp->s_port) { - snprintf(srvloc_url, sizeof(srvloc_url), "afp://%s/?NAME=%s", inet_ntoa(dsi->server.sin_addr), options->hostname); - } - else { - snprintf(srvloc_url, sizeof(srvloc_url), "afp://%s:%d/?NAME=%s", inet_ntoa(dsi->server.sin_addr), ntohs(dsi->server.sin_port), options->hostname); - } - - err = SLPReg(hslp, - srvloc_url, - SLP_LIFETIME_MAXIMUM, - "", - "", - SLP_TRUE, - SRVLOC_callback, - &callbackerr); - if (err != SLP_OK) { - syslog(LOG_ERR, "Error registering %s with SRVLOC", srvloc_url); - goto srvloc_reg_err; - } - - if (callbackerr != SLP_OK) { - syslog(LOG_ERR, "Error in callback trying to register %s with SRVLOC", srvloc_url); - goto srvloc_reg_err; - } - - syslog(LOG_INFO, "Sucessfully registered %s with SRVLOC", srvloc_url); - - srvloc_reg_err: + err = SLPOpen("en", SLP_FALSE, &hslp); + if (err != SLP_OK) { + syslog(LOG_ERR, "Error opening SRVLOC handle"); + goto srvloc_reg_err; + } + + /* XXX We don't want to tack on the port number if we don't have to. Why? + * Well, this seems to break MacOS < 10. If the user _really_ wants to + * use a non-default port, they can, but be aware, this server might not + * show up int the Network Browser. */ + afpovertcp = getservbyname("afpovertcp", "tcp"); + if (dsi->server.sin_port == afpovertcp->s_port) { + snprintf(srvloc_url, sizeof(srvloc_url), "afp://%s/?NAME=%s", inet_ntoa(dsi->server.sin_addr), options->hostname); + } + else { + snprintf(srvloc_url, sizeof(srvloc_url), "afp://%s:%d/?NAME=%s", inet_ntoa(dsi->server.sin_addr), ntohs(dsi->server.sin_port), options->hostname); + } + + err = SLPReg(hslp, + srvloc_url, + SLP_LIFETIME_MAXIMUM, + "", + "", + SLP_TRUE, + SRVLOC_callback, + &callbackerr); + if (err != SLP_OK) { + syslog(LOG_ERR, "Error registering %s with SRVLOC", srvloc_url); + goto srvloc_reg_err; + } + + if (callbackerr != SLP_OK) { + syslog(LOG_ERR, "Error in callback trying to register %s with SRVLOC", srvloc_url); + goto srvloc_reg_err; + } + + syslog(LOG_INFO, "Sucessfully registered %s with SRVLOC", srvloc_url); + +srvloc_reg_err: SLPClose(hslp); #endif /* USE_SRVLOC */ - config->fd = dsi->serversock; - config->obj.handle = dsi; - config->obj.config = config; - config->obj.proto = AFPPROTO_DSI; + config->fd = dsi->serversock; + config->obj.handle = dsi; + config->obj.config = config; + config->obj.proto = AFPPROTO_DSI; + + memcpy(&config->obj.options, options, sizeof(struct afp_options)); + /* get rid of any appletalk info. we use the fact that the DSI + * stuff is done after the ASP stuff. */ + p = config->obj.options.server; + if (p && (q = strchr(p, ':'))) + *q = '\0'; - memcpy(&config->obj.options, options, sizeof(struct afp_options)); - /* get rid of any appletalk info. we use the fact that the DSI - * stuff is done after the ASP stuff. */ - p = config->obj.options.server; - if (p && (q = strchr(p, ':'))) - *q = '\0'; - - config->optcount = refcount; - (*refcount)++; + config->optcount = refcount; + (*refcount)++; - config->server_start = dsi_start; + config->server_start = dsi_start; #ifdef USE_SRVLOC - config->server_cleanup = dsi_cleanup; + config->server_cleanup = dsi_cleanup; #endif /* USE_SRVLOC */ - return config; + return config; } /* allocate server configurations. this should really store the last * entry in config->last or something like that. that would make * supporting multiple dsi transports easier. */ static AFPConfig *AFPConfigInit(const struct afp_options *options, - const struct afp_options *defoptions) + const struct afp_options *defoptions) { - AFPConfig *config = NULL, *next = NULL; - unsigned char *refcount; + AFPConfig *config = NULL, *next = NULL; + unsigned char *refcount; - if ((refcount = (unsigned char *) - calloc(1, sizeof(unsigned char))) == NULL) { - syslog( LOG_ERR, "AFPConfigInit: calloc(refcount): %m" ); - return NULL; - } + if ((refcount = (unsigned char *) + calloc(1, sizeof(unsigned char))) == NULL) { + syslog( LOG_ERR, "AFPConfigInit: calloc(refcount): %m" ); + return NULL; + } #ifndef NO_DDP - /* handle asp transports */ - if ((options->transports & AFPTRANS_DDP) && - (config = ASPConfigInit(options, refcount))) - config->defoptions = defoptions; + /* handle asp transports */ + if ((options->transports & AFPTRANS_DDP) && + (config = ASPConfigInit(options, refcount))) + config->defoptions = defoptions; #endif /* NO_DDP */ - /* handle dsi transports and dsi proxies. we only proxy - * for DSI connections. */ - - /* this should have something like the following: - * for (i=mindsi; i < maxdsi; i++) - * if (options->transports & (1 << i) && - * (next = DSIConfigInit(options, refcount, i))) - * next->defoptions = defoptions; - */ - if ((options->transports & AFPTRANS_TCP) && - (((options->flags & OPTION_PROXY) == 0) || - ((options->flags & OPTION_PROXY) && config)) - && (next = DSIConfigInit(options, refcount, DSI_TCPIP))) - next->defoptions = defoptions; - - /* load in all the authentication modules. we can load the same - things multiple times if necessary. however, loading different - things with the same names will cause complaints. by not loading - in any uams with proxies, we prevent ddp connections from succeeding. - */ - auth_load(options->uampath, options->uamlist); - - /* this should be able to accept multiple dsi transports. i think - * the only thing that gets affected is the net addresses. */ - status_init(config, next, options); - - /* attach dsi config to tail of asp config */ - if (config) { - config->next = next; - return config; - } - - return next; + /* handle dsi transports and dsi proxies. we only proxy + * for DSI connections. */ + + /* this should have something like the following: + * for (i=mindsi; i < maxdsi; i++) + * if (options->transports & (1 << i) && + * (next = DSIConfigInit(options, refcount, i))) + * next->defoptions = defoptions; + */ + if ((options->transports & AFPTRANS_TCP) && + (((options->flags & OPTION_PROXY) == 0) || + ((options->flags & OPTION_PROXY) && config)) + && (next = DSIConfigInit(options, refcount, DSI_TCPIP))) + next->defoptions = defoptions; + + /* load in all the authentication modules. we can load the same + things multiple times if necessary. however, loading different + things with the same names will cause complaints. by not loading + in any uams with proxies, we prevent ddp connections from succeeding. + */ + auth_load(options->uampath, options->uamlist); + + /* this should be able to accept multiple dsi transports. i think + * the only thing that gets affected is the net addresses. */ + status_init(config, next, options); + + /* attach dsi config to tail of asp config */ + if (config) { + config->next = next; + return config; + } + + return next; } /* fill in the appropriate bits for each interface */ AFPConfig *configinit(struct afp_options *cmdline) { - FILE *fp; - char buf[LINESIZE + 1], *p, have_option = 0; - struct afp_options options; - AFPConfig *config, *first = NULL; - - /* if config file doesn't exist, load defaults */ - if ((fp = fopen(cmdline->configfile, "r")) == NULL) - return AFPConfigInit(cmdline, cmdline); - - /* scan in the configuration file */ - while (!feof(fp)) { - if (!fgets(buf, sizeof(buf), fp) || buf[0] == '#') - continue; - - /* a little pre-processing to get rid of spaces and end-of-lines */ - p = buf; - while (p && isspace(*p)) - p++; - if (!p || (*p == '\0')) - continue; - - have_option = 1; - - memcpy(&options, cmdline, sizeof(options)); - if (!afp_options_parseline(p, &options)) - continue; - - /* this should really get a head and a tail to simplify things. */ - if (!first) { - if ((first = AFPConfigInit(&options, cmdline))) - config = first->next ? first->next : first; - } else if ((config->next = AFPConfigInit(&options, cmdline))) { - config = config->next->next ? config->next->next : config->next; + FILE *fp; + char buf[LINESIZE + 1], *p, have_option = 0; + struct afp_options options; + AFPConfig *config, *first = NULL; + + /* if config file doesn't exist, load defaults */ + if ((fp = fopen(cmdline->configfile, "r")) == NULL) + return AFPConfigInit(cmdline, cmdline); + + /* scan in the configuration file */ + while (!feof(fp)) { + if (!fgets(buf, sizeof(buf), fp) || buf[0] == '#') + continue; + + /* a little pre-processing to get rid of spaces and end-of-lines */ + p = buf; + while (p && isspace(*p)) + p++; + if (!p || (*p == '\0')) + continue; + + have_option = 1; + + memcpy(&options, cmdline, sizeof(options)); + if (!afp_options_parseline(p, &options)) + continue; + + /* this should really get a head and a tail to simplify things. */ + if (!first) { + if ((first = AFPConfigInit(&options, cmdline))) + config = first->next ? first->next : first; + } else if ((config->next = AFPConfigInit(&options, cmdline))) { + config = config->next->next ? config->next->next : config->next; + } } - } - fclose(fp); + fclose(fp); - if (!have_option) - return AFPConfigInit(cmdline, cmdline); + if (!have_option) + return AFPConfigInit(cmdline, cmdline); - return first; + return first; } diff --git a/etc/afpd/afp_config.h b/etc/afpd/afp_config.h index 20e629a7..26586545 100644 --- a/etc/afpd/afp_config.h +++ b/etc/afpd/afp_config.h @@ -1,5 +1,5 @@ /* - * $Id: afp_config.h,v 1.2 2001-06-20 18:33:04 rufustfirefly Exp $ + * $Id: afp_config.h,v 1.2.2.1 2001-12-03 05:01:03 jmarcus Exp $ */ #ifndef AFPD_CONFIG_H @@ -14,15 +14,15 @@ #include "globals.h" typedef struct AFPConfig { - AFPObj obj; - int fd, statuslen; - unsigned char *optcount; - char status[ATP_MAXDATA]; - const void *defoptions, *signature; - int (*server_start) __P((struct AFPConfig *, struct AFPConfig *, - server_child *)); - void (*server_cleanup) __P((const struct AFPConfig *)); - struct AFPConfig *next; + AFPObj obj; + int fd, statuslen; + unsigned char *optcount; + char status[ATP_MAXDATA]; + const void *defoptions, *signature; + int (*server_start) __P((struct AFPConfig *, struct AFPConfig *, + server_child *)); + void (*server_cleanup) __P((const struct AFPConfig *)); + struct AFPConfig *next; } AFPConfig; extern AFPConfig *configinit __P((struct afp_options *)); diff --git a/etc/afpd/afp_dsi.c b/etc/afpd/afp_dsi.c index 98ae7fc9..b5e67301 100644 --- a/etc/afpd/afp_dsi.c +++ b/etc/afpd/afp_dsi.c @@ -1,5 +1,5 @@ -/* - * $Id: afp_dsi.c,v 1.9 2001-11-14 21:45:12 srittau Exp $ +/* + * $Id: afp_dsi.c,v 1.9.2.1 2001-12-03 05:01:03 jmarcus Exp $ * * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu) * Copyright (c) 1990,1993 Regents of The University of Michigan. @@ -44,8 +44,8 @@ extern struct oforks *writtenfork; #define CHILD_RUNNING (1 << 1) static struct { - AFPObj *obj; - unsigned char tickle, flags; + AFPObj *obj; + unsigned char tickle, flags; } child; @@ -54,14 +54,14 @@ static __inline__ void afp_dsi_close(AFPObj *obj) DSI *dsi = obj->handle; if (obj->logout) - (*obj->logout)(); - + (*obj->logout)(); + dsi_close(dsi); /* UAM had syslog control; afpd needs to reassert itself */ openlog( "afpd", LOG_NDELAY|LOG_PID, LOG_DAEMON); syslog(LOG_INFO, "%.2fKB read, %.2fKB written", - dsi->read_count/1024.0, dsi->write_count/1024.0); + dsi->read_count/1024.0, dsi->write_count/1024.0); } /* a little bit of code duplication. */ @@ -70,13 +70,13 @@ static void afp_dsi_die(int sig) dsi_attention(child.obj->handle, AFPATTN_SHUTDOWN); afp_dsi_close(child.obj); if (sig) /* if no signal, assume dieing because logins are disabled & - don't log it (maintenance mode)*/ - syslog (LOG_INFO, "Connection terminated"); + don't log it (maintenance mode)*/ + syslog (LOG_INFO, "Connection terminated"); if (sig == SIGTERM || sig == SIGALRM) { - exit( 0 ); + exit( 0 ); } else { - exit(sig); + exit(sig); } } @@ -89,15 +89,15 @@ static void afp_dsi_timedown() /* shutdown and don't reconnect. server going down in 5 minutes. */ setmessage("The server is going down for maintenance."); dsi_attention(child.obj->handle, AFPATTN_SHUTDOWN | AFPATTN_NORECONNECT | - AFPATTN_MESG | AFPATTN_TIME(5)); + AFPATTN_MESG | AFPATTN_TIME(5)); it.it_interval.tv_sec = 0; it.it_interval.tv_usec = 0; it.it_value.tv_sec = 300; it.it_value.tv_usec = 0; if ( setitimer( ITIMER_REAL, &it, 0 ) < 0 ) { - syslog( LOG_ERR, "afp_timedown: setitimer: %s", strerror(errno) ); - afp_dsi_die(1); + syslog( LOG_ERR, "afp_timedown: setitimer: %s", strerror(errno) ); + afp_dsi_die(1); } memset(&sv, 0, sizeof(sv)); @@ -107,213 +107,213 @@ static void afp_dsi_timedown() sigaddset(&sv.sa_mask, SIGTERM); sv.sa_flags = SA_RESTART; if ( sigaction( SIGALRM, &sv, 0 ) < 0 ) { - syslog( LOG_ERR, "afp_timedown: sigaction: %s", strerror(errno) ); - afp_dsi_die(1); + syslog( LOG_ERR, "afp_timedown: sigaction: %s", strerror(errno) ); + afp_dsi_die(1); } } #ifdef SERVERTEXT static void afp_dsi_getmesg (int sig) { - readmessage(); - dsi_attention(child.obj->handle, AFPATTN_MESG | AFPATTN_TIME(5)); + readmessage(); + dsi_attention(child.obj->handle, AFPATTN_MESG | AFPATTN_TIME(5)); } #endif /* SERVERTEXT */ static void alarm_handler() { - /* if we're in the midst of processing something, - don't die. we'll allow 3 missed tickles before we die (2 minutes) */ - if ((child.flags & CHILD_RUNNING) || (child.tickle++ < 4)) { - dsi_tickle(child.obj->handle); - } else { /* didn't receive a tickle. close connection */ - syslog(LOG_ERR, "afp_alarm: child timed out"); - afp_dsi_die(1); - } + /* if we're in the midst of processing something, + don't die. we'll allow 3 missed tickles before we die (2 minutes) */ + if ((child.flags & CHILD_RUNNING) || (child.tickle++ < 4)) { + dsi_tickle(child.obj->handle); + } else { /* didn't receive a tickle. close connection */ + syslog(LOG_ERR, "afp_alarm: child timed out"); + afp_dsi_die(1); + } } /* afp over dsi. this never returns. */ void afp_over_dsi(AFPObj *obj) { - DSI *dsi = (DSI *) obj->handle; - u_int32_t err, cmd; - u_int8_t function; - struct sigaction action; - - obj->exit = afp_dsi_die; - obj->reply = (int (*)()) dsi_cmdreply; - obj->attention = (int (*)(void *, AFPUserBytes)) dsi_attention; - - child.obj = obj; - child.tickle = child.flags = 0; - - /* install SIGTERM and SIGHUP */ - memset(&action, 0, sizeof(action)); - action.sa_handler = afp_dsi_timedown; - sigemptyset( &action.sa_mask ); - sigaddset(&action.sa_mask, SIGALRM); - sigaddset(&action.sa_mask, SIGTERM); - action.sa_flags = SA_RESTART; - if ( sigaction( SIGHUP, &action, 0 ) < 0 ) { - syslog( LOG_ERR, "afp_over_dsi: sigaction: %s", strerror(errno) ); - afp_dsi_die(1); - } - - action.sa_handler = afp_dsi_die; - sigemptyset( &action.sa_mask ); - sigaddset(&action.sa_mask, SIGALRM); - sigaddset(&action.sa_mask, SIGHUP); - action.sa_flags = SA_RESTART; - if ( sigaction( SIGTERM, &action, 0 ) < 0 ) { - syslog( LOG_ERR, "afp_over_dsi: sigaction: %s", strerror(errno) ); - afp_dsi_die(1); - } + DSI *dsi = (DSI *) obj->handle; + u_int32_t err, cmd; + u_int8_t function; + struct sigaction action; + + obj->exit = afp_dsi_die; + obj->reply = (int (*)()) dsi_cmdreply; + obj->attention = (int (*)(void *, AFPUserBytes)) dsi_attention; + + child.obj = obj; + child.tickle = child.flags = 0; + + /* install SIGTERM and SIGHUP */ + memset(&action, 0, sizeof(action)); + action.sa_handler = afp_dsi_timedown; + sigemptyset( &action.sa_mask ); + sigaddset(&action.sa_mask, SIGALRM); + sigaddset(&action.sa_mask, SIGTERM); + action.sa_flags = SA_RESTART; + if ( sigaction( SIGHUP, &action, 0 ) < 0 ) { + syslog( LOG_ERR, "afp_over_dsi: sigaction: %s", strerror(errno) ); + afp_dsi_die(1); + } + + action.sa_handler = afp_dsi_die; + sigemptyset( &action.sa_mask ); + sigaddset(&action.sa_mask, SIGALRM); + sigaddset(&action.sa_mask, SIGHUP); + action.sa_flags = SA_RESTART; + if ( sigaction( SIGTERM, &action, 0 ) < 0 ) { + syslog( LOG_ERR, "afp_over_dsi: sigaction: %s", strerror(errno) ); + afp_dsi_die(1); + } #ifdef SERVERTEXT - /* Added for server message support */ - action.sa_handler = afp_dsi_getmesg; - sigemptyset( &action.sa_mask ); - sigaddset(&action.sa_mask, SIGUSR2); - action.sa_flags = SA_RESTART; - if ( sigaction( SIGUSR2, &action, 0) < 0 ) { - syslog( LOG_ERR, "afp_over_dsi: sigaction: %s", strerror(errno) ); - afp_dsi_die(1); - } + /* Added for server message support */ + action.sa_handler = afp_dsi_getmesg; + sigemptyset( &action.sa_mask ); + sigaddset(&action.sa_mask, SIGUSR2); + action.sa_flags = SA_RESTART; + if ( sigaction( SIGUSR2, &action, 0) < 0 ) { + syslog( LOG_ERR, "afp_over_dsi: sigaction: %s", strerror(errno) ); + afp_dsi_die(1); + } #endif /* SERVERTEXT */ - /* tickle handler */ - action.sa_handler = alarm_handler; - sigemptyset(&action.sa_mask); - sigaddset(&action.sa_mask, SIGHUP); - sigaddset(&action.sa_mask, SIGTERM); - action.sa_flags = SA_RESTART; - if ((sigaction(SIGALRM, &action, NULL) < 0) || - (setitimer(ITIMER_REAL, &dsi->timer, NULL) < 0)) { - afp_dsi_die(1); - } - - /* get stuck here until the end */ - while ((cmd = dsi_receive(dsi))) { - child.tickle = 0; - - if (cmd == DSIFUNC_TICKLE) { - /* so we don't get killed on the client side. */ - if (child.flags & CHILD_DIE) - dsi_tickle(dsi); - continue; - } else if (!(child.flags & CHILD_DIE)) /* reset tickle timer */ - setitimer(ITIMER_REAL, &dsi->timer, NULL); - - switch(cmd) { - case DSIFUNC_CLOSE: - afp_dsi_close(obj); - syslog(LOG_INFO, "done"); - if (obj->options.flags & OPTION_DEBUG ) - printf("done\n"); - return; - break; - - case DSIFUNC_CMD: + /* tickle handler */ + action.sa_handler = alarm_handler; + sigemptyset(&action.sa_mask); + sigaddset(&action.sa_mask, SIGHUP); + sigaddset(&action.sa_mask, SIGTERM); + action.sa_flags = SA_RESTART; + if ((sigaction(SIGALRM, &action, NULL) < 0) || + (setitimer(ITIMER_REAL, &dsi->timer, NULL) < 0)) { + afp_dsi_die(1); + } + + /* get stuck here until the end */ + while ((cmd = dsi_receive(dsi))) { + child.tickle = 0; + + if (cmd == DSIFUNC_TICKLE) { + /* so we don't get killed on the client side. */ + if (child.flags & CHILD_DIE) + dsi_tickle(dsi); + continue; + } else if (!(child.flags & CHILD_DIE)) /* reset tickle timer */ + setitimer(ITIMER_REAL, &dsi->timer, NULL); + + switch(cmd) { + case DSIFUNC_CLOSE: + afp_dsi_close(obj); + syslog(LOG_INFO, "done"); + if (obj->options.flags & OPTION_DEBUG ) + printf("done\n"); + return; + break; + + case DSIFUNC_CMD: #ifdef AFS - if ( writtenfork ) { - if ( flushfork( writtenfork ) < 0 ) { - syslog( LOG_ERR, "main flushfork: %s", strerror(errno) ); - } - writtenfork = NULL; - } + if ( writtenfork ) { + if ( flushfork( writtenfork ) < 0 ) { + syslog( LOG_ERR, "main flushfork: %s", strerror(errno) ); + } + writtenfork = NULL; + } #endif /* AFS */ - function = (u_char) dsi->commands[0]; - if (obj->options.flags & OPTION_DEBUG ) { - printf("command: %d\n", function); - bprint(dsi->commands, dsi->cmdlen); - } - - /* send off an afp command. in a couple cases, we take advantage - * of the fact that we're a stream-based protocol. */ - if (afp_switch[function]) { - dsi->datalen = DSI_DATASIZ; - child.flags |= CHILD_RUNNING; - err = (*afp_switch[function])(obj, - dsi->commands, dsi->cmdlen, - dsi->data, &dsi->datalen); - child.flags &= ~CHILD_RUNNING; - } else { - syslog(LOG_ERR, "bad function %X", function); - dsi->datalen = 0; - err = AFPERR_NOOP; - } - - /* single shot toggle that gets set by dsi_readinit. */ - if (dsi->noreply) { - dsi->noreply = 0; - break; - } - - if (obj->options.flags & OPTION_DEBUG ) { - printf( "reply: %d, %d\n", err, dsi->clientID); - bprint(dsi->data, dsi->datalen); - } - - if (!dsi_cmdreply(dsi, err)) { - syslog(LOG_ERR, "dsi_cmdreply(%d): %s", dsi->socket, strerror(errno) ); - afp_dsi_die(1); - } - break; - - case DSIFUNC_WRITE: /* FPWrite and FPAddIcon */ - function = (u_char) dsi->commands[0]; - if ( obj->options.flags & OPTION_DEBUG ) { - printf("(write) command: %d, %d\n", function, dsi->cmdlen); - bprint(dsi->commands, dsi->cmdlen); - } - - if ( afp_switch[ function ] != NULL ) { - dsi->datalen = DSI_DATASIZ; - child.flags |= CHILD_RUNNING; - err = (*afp_switch[function])(obj, dsi->commands, dsi->cmdlen, - dsi->data, &dsi->datalen); - child.flags &= ~CHILD_RUNNING; - } else { - syslog( LOG_ERR, "(write) bad function %x", function); - dsi->datalen = 0; - err = AFPERR_NOOP; - } - - if (obj->options.flags & OPTION_DEBUG ) { - printf( "(write) reply code: %d, %d\n", err, dsi->clientID); - bprint(dsi->data, dsi->datalen); - } - - if (!dsi_wrtreply(dsi, err)) { - syslog( LOG_ERR, "dsi_wrtreply: %s", strerror(errno) ); - afp_dsi_die(1); - } - break; - - case DSIFUNC_ATTN: /* attention replies */ - continue; - break; - - /* error. this usually implies a mismatch of some kind - * between server and client. if things are correct, - * we need to flush the rest of the packet if necessary. */ - default: - syslog(LOG_INFO,"afp_dsi: spurious command %d", cmd); - dsi_writeinit(dsi, dsi->data, DSI_DATASIZ); - dsi_writeflush(dsi); - break; - } - - if ( obj->options.flags & OPTION_DEBUG ) { + function = (u_char) dsi->commands[0]; + if (obj->options.flags & OPTION_DEBUG ) { + printf("command: %d\n", function); + bprint(dsi->commands, dsi->cmdlen); + } + + /* send off an afp command. in a couple cases, we take advantage + * of the fact that we're a stream-based protocol. */ + if (afp_switch[function]) { + dsi->datalen = DSI_DATASIZ; + child.flags |= CHILD_RUNNING; + err = (*afp_switch[function])(obj, + dsi->commands, dsi->cmdlen, + dsi->data, &dsi->datalen); + child.flags &= ~CHILD_RUNNING; + } else { + syslog(LOG_ERR, "bad function %X", function); + dsi->datalen = 0; + err = AFPERR_NOOP; + } + + /* single shot toggle that gets set by dsi_readinit. */ + if (dsi->noreply) { + dsi->noreply = 0; + break; + } + + if (obj->options.flags & OPTION_DEBUG ) { + printf( "reply: %d, %d\n", err, dsi->clientID); + bprint(dsi->data, dsi->datalen); + } + + if (!dsi_cmdreply(dsi, err)) { + syslog(LOG_ERR, "dsi_cmdreply(%d): %s", dsi->socket, strerror(errno) ); + afp_dsi_die(1); + } + break; + + case DSIFUNC_WRITE: /* FPWrite and FPAddIcon */ + function = (u_char) dsi->commands[0]; + if ( obj->options.flags & OPTION_DEBUG ) { + printf("(write) command: %d, %d\n", function, dsi->cmdlen); + bprint(dsi->commands, dsi->cmdlen); + } + + if ( afp_switch[ function ] != NULL ) { + dsi->datalen = DSI_DATASIZ; + child.flags |= CHILD_RUNNING; + err = (*afp_switch[function])(obj, dsi->commands, dsi->cmdlen, + dsi->data, &dsi->datalen); + child.flags &= ~CHILD_RUNNING; + } else { + syslog( LOG_ERR, "(write) bad function %x", function); + dsi->datalen = 0; + err = AFPERR_NOOP; + } + + if (obj->options.flags & OPTION_DEBUG ) { + printf( "(write) reply code: %d, %d\n", err, dsi->clientID); + bprint(dsi->data, dsi->datalen); + } + + if (!dsi_wrtreply(dsi, err)) { + syslog( LOG_ERR, "dsi_wrtreply: %s", strerror(errno) ); + afp_dsi_die(1); + } + break; + + case DSIFUNC_ATTN: /* attention replies */ + continue; + break; + + /* error. this usually implies a mismatch of some kind + * between server and client. if things are correct, + * we need to flush the rest of the packet if necessary. */ + default: + syslog(LOG_INFO,"afp_dsi: spurious command %d", cmd); + dsi_writeinit(dsi, dsi->data, DSI_DATASIZ); + dsi_writeflush(dsi); + break; + } + + if ( obj->options.flags & OPTION_DEBUG ) { #ifdef notdef - pdesc( stdout ); + pdesc( stdout ); #endif /* notdef */ - of_pforkdesc( stdout ); - fflush( stdout ); + of_pforkdesc( stdout ); + fflush( stdout ); + } } - } - /* error */ - afp_dsi_die(1); + /* error */ + afp_dsi_die(1); } diff --git a/etc/afpd/afp_options.c b/etc/afpd/afp_options.c index 706edea3..5da26aae 100644 --- a/etc/afpd/afp_options.c +++ b/etc/afpd/afp_options.c @@ -1,5 +1,5 @@ -/* - * $Id: afp_options.c,v 1.13 2001-10-23 13:44:37 rufustfirefly Exp $ +/* + * $Id: afp_options.c,v 1.13.2.1 2001-12-03 05:01:03 jmarcus Exp $ * * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu) * Copyright (c) 1990,1993 Regents of The University of Michigan. @@ -69,82 +69,82 @@ char *strchr (), *strrchr (); * non-optimal. */ static char *getoption(char *buf, const char *option) { - static char string[LENGTH + 1]; - char *end; - int len; - - if (option && (buf = strstr(buf, option))) - buf = strpbrk(buf, " \t"); - - while (buf && isspace(*buf)) - buf++; - - if (!buf) - return NULL; - - /* search for any quoted stuff */ - if (*buf == '"' && (end = strchr(buf + 1, '"'))) { - buf++; - len = MIN(end - buf, LENGTH); - } else if ((end = strpbrk(buf, " \t\n"))) /* option or eoln */ - len = MIN(end - buf, LENGTH); - else - len = MIN(strlen(buf), LENGTH); - - strncpy(string, buf, len); - string[len] = '\0'; - return string; + static char string[LENGTH + 1]; + char *end; + int len; + + if (option && (buf = strstr(buf, option))) + buf = strpbrk(buf, " \t"); + + while (buf && isspace(*buf)) + buf++; + + if (!buf) + return NULL; + + /* search for any quoted stuff */ + if (*buf == '"' && (end = strchr(buf + 1, '"'))) { + buf++; + len = MIN(end - buf, LENGTH); + } else if ((end = strpbrk(buf, " \t\n"))) /* option or eoln */ + len = MIN(end - buf, LENGTH); + else + len = MIN(strlen(buf), LENGTH); + + strncpy(string, buf, len); + string[len] = '\0'; + return string; } /* get rid of any allocated afp_option buffers. */ -void afp_options_free(struct afp_options *opt, - const struct afp_options *save) +void afp_options_free(struct afp_options *opt, + const struct afp_options *save) { - if (opt->defaultvol && (opt->defaultvol != save->defaultvol)) - free(opt->defaultvol); - if (opt->systemvol && (opt->systemvol != save->systemvol)) - free(opt->systemvol); - if (opt->loginmesg && (opt->loginmesg != save->loginmesg)) - free(opt->loginmesg); - if (opt->guest && (opt->guest != save->guest)) - free(opt->guest); - if (opt->server && (opt->server != save->server)) - free(opt->server); - if (opt->ipaddr && (opt->ipaddr != save->ipaddr)) - free(opt->ipaddr); - if (opt->fqdn && (opt->fqdn != save->fqdn)) - free(opt->fqdn); - if (opt->uampath && (opt->uampath != save->uampath)) - free(opt->uampath); - if (opt->uamlist && (opt->uamlist != save->uamlist)) - free(opt->uamlist); - if (opt->nlspath && (opt->nlspath != save->nlspath)) - free(opt->nlspath); - if (opt->passwdfile && (opt->passwdfile != save->passwdfile)) - free(opt->passwdfile); + if (opt->defaultvol && (opt->defaultvol != save->defaultvol)) + free(opt->defaultvol); + if (opt->systemvol && (opt->systemvol != save->systemvol)) + free(opt->systemvol); + if (opt->loginmesg && (opt->loginmesg != save->loginmesg)) + free(opt->loginmesg); + if (opt->guest && (opt->guest != save->guest)) + free(opt->guest); + if (opt->server && (opt->server != save->server)) + free(opt->server); + if (opt->ipaddr && (opt->ipaddr != save->ipaddr)) + free(opt->ipaddr); + if (opt->fqdn && (opt->fqdn != save->fqdn)) + free(opt->fqdn); + if (opt->uampath && (opt->uampath != save->uampath)) + free(opt->uampath); + if (opt->uamlist && (opt->uamlist != save->uamlist)) + free(opt->uamlist); + if (opt->nlspath && (opt->nlspath != save->nlspath)) + free(opt->nlspath); + if (opt->passwdfile && (opt->passwdfile != save->passwdfile)) + free(opt->passwdfile); } /* initialize options */ void afp_options_init(struct afp_options *options) { - memset(options, 0, sizeof(struct afp_options)); - options->connections = 20; - options->pidfile = _PATH_AFPDLOCK; - options->defaultvol = _PATH_AFPDDEFVOL; - options->systemvol = _PATH_AFPDSYSVOL; - options->configfile = _PATH_AFPDCONF; - options->nlspath = _PATH_AFPDNLSPATH; - options->uampath = _PATH_AFPDUAMPATH; - options->uamlist = "uams_clrtxt.so,uams_dhx.so"; - options->guest = "nobody"; - options->loginmesg = ""; - options->transports = AFPTRANS_ALL; - options->passwdfile = _PATH_AFPDPWFILE; - options->tickleval = 30; - options->authprintdir = NULL; - options->umask = 0; + memset(options, 0, sizeof(struct afp_options)); + options->connections = 20; + options->pidfile = _PATH_AFPDLOCK; + options->defaultvol = _PATH_AFPDDEFVOL; + options->systemvol = _PATH_AFPDSYSVOL; + options->configfile = _PATH_AFPDCONF; + options->nlspath = _PATH_AFPDNLSPATH; + options->uampath = _PATH_AFPDUAMPATH; + options->uamlist = "uams_clrtxt.so,uams_dhx.so"; + options->guest = "nobody"; + options->loginmesg = ""; + options->transports = AFPTRANS_ALL; + options->passwdfile = _PATH_AFPDPWFILE; + options->tickleval = 30; + options->authprintdir = NULL; + options->umask = 0; #ifdef ADMIN_GRP - options->admingid = 0; + options->admingid = 0; #endif /* ADMIN_GRP */ } @@ -158,232 +158,232 @@ void afp_options_init(struct afp_options *options) */ int afp_options_parseline(char *buf, struct afp_options *options) { - char *c, *opt; - - /* handle server */ - if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c))) - options->server = opt; - - /* parse toggles */ - if (strstr(buf, " -nodebug")) - options->flags &= ~OPTION_DEBUG; - - if (strstr(buf, " -nouservolfirst")) - options->flags &= ~OPTION_USERVOLFIRST; - if (strstr(buf, " -uservolfirst")) - options->flags |= OPTION_USERVOLFIRST; - if (strstr(buf, " -nouservol")) - options->flags |= OPTION_NOUSERVOL; - if (strstr(buf, " -uservol")) - options->flags &= ~OPTION_NOUSERVOL; - if (strstr(buf, " -proxy")) - options->flags |= OPTION_PROXY; - if (strstr(buf, " -noicon")) - options->flags &= ~OPTION_CUSTOMICON; - if (strstr(buf, " -icon")) - options->flags |= OPTION_CUSTOMICON; - - /* passwd bits */ - if (strstr(buf, " -nosavepassword")) - options->passwdbits |= PASSWD_NOSAVE; - if (strstr(buf, " -savepassword")) - options->passwdbits &= ~PASSWD_NOSAVE; - if (strstr(buf, " -nosetpassword")) - options->passwdbits &= ~PASSWD_SET; - if (strstr(buf, " -setpassword")) - options->passwdbits |= PASSWD_SET; - - /* transports */ - if (strstr(buf, " -transall")) - options->transports = AFPTRANS_ALL; - if (strstr(buf, " -notransall")) - options->transports = AFPTRANS_NONE; - if (strstr(buf, " -tcp")) - options->transports |= AFPTRANS_TCP; - if (strstr(buf, " -notcp")) - options->transports &= ~AFPTRANS_TCP; - if (strstr(buf, " -ddp")) - options->transports |= AFPTRANS_DDP; - if (strstr(buf, " -noddp")) - options->transports &= ~AFPTRANS_DDP; - - /* figure out options w/ values. currently, this will ignore the setting - * if memory is lacking. */ - if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c))) - options->defaultvol = opt; - if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c))) - options->systemvol = opt; - if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c))) - options->loginmesg = opt; - if ((c = getoption(buf, "-guestname")) && (opt = strdup(c))) - options->guest = opt; - if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c))) - options->passwdfile = opt; - if ((c = getoption(buf, "-passwdminlen"))) - options->passwdminlen = MIN(1, atoi(c)); - if ((c = getoption(buf, "-loginmaxfail"))) - options->loginmaxfail = atoi(c); - if ((c = getoption(buf, "-tickleval"))) - options->tickleval = atoi(c); - - if ((c = getoption(buf, "-server_quantum"))) - options->server_quantum = strtoul(c, NULL, 0); + char *c, *opt; + + /* handle server */ + if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c))) + options->server = opt; + + /* parse toggles */ + if (strstr(buf, " -nodebug")) + options->flags &= ~OPTION_DEBUG; + + if (strstr(buf, " -nouservolfirst")) + options->flags &= ~OPTION_USERVOLFIRST; + if (strstr(buf, " -uservolfirst")) + options->flags |= OPTION_USERVOLFIRST; + if (strstr(buf, " -nouservol")) + options->flags |= OPTION_NOUSERVOL; + if (strstr(buf, " -uservol")) + options->flags &= ~OPTION_NOUSERVOL; + if (strstr(buf, " -proxy")) + options->flags |= OPTION_PROXY; + if (strstr(buf, " -noicon")) + options->flags &= ~OPTION_CUSTOMICON; + if (strstr(buf, " -icon")) + options->flags |= OPTION_CUSTOMICON; + + /* passwd bits */ + if (strstr(buf, " -nosavepassword")) + options->passwdbits |= PASSWD_NOSAVE; + if (strstr(buf, " -savepassword")) + options->passwdbits &= ~PASSWD_NOSAVE; + if (strstr(buf, " -nosetpassword")) + options->passwdbits &= ~PASSWD_SET; + if (strstr(buf, " -setpassword")) + options->passwdbits |= PASSWD_SET; + + /* transports */ + if (strstr(buf, " -transall")) + options->transports = AFPTRANS_ALL; + if (strstr(buf, " -notransall")) + options->transports = AFPTRANS_NONE; + if (strstr(buf, " -tcp")) + options->transports |= AFPTRANS_TCP; + if (strstr(buf, " -notcp")) + options->transports &= ~AFPTRANS_TCP; + if (strstr(buf, " -ddp")) + options->transports |= AFPTRANS_DDP; + if (strstr(buf, " -noddp")) + options->transports &= ~AFPTRANS_DDP; + + /* figure out options w/ values. currently, this will ignore the setting + * if memory is lacking. */ + if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c))) + options->defaultvol = opt; + if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c))) + options->systemvol = opt; + if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c))) + options->loginmesg = opt; + if ((c = getoption(buf, "-guestname")) && (opt = strdup(c))) + options->guest = opt; + if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c))) + options->passwdfile = opt; + if ((c = getoption(buf, "-passwdminlen"))) + options->passwdminlen = MIN(1, atoi(c)); + if ((c = getoption(buf, "-loginmaxfail"))) + options->loginmaxfail = atoi(c); + if ((c = getoption(buf, "-tickleval"))) + options->tickleval = atoi(c); + + if ((c = getoption(buf, "-server_quantum"))) + options->server_quantum = strtoul(c, NULL, 0); #ifdef ADMIN_GRP - if ((c = getoption(buf, "-admingroup"))) { - struct group *gr = getgrnam(c); - if (gr != NULL) { - options->admingid = gr->gr_gid; + if ((c = getoption(buf, "-admingroup"))) { + struct group *gr = getgrnam(c); + if (gr != NULL) { + options->admingid = gr->gr_gid; + } } - } #endif /* ADMIN_GRP */ - if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c))) - options->authprintdir = opt; - if ((c = getoption(buf, "-uampath")) && (opt = strdup(c))) - options->uampath = opt; - if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c))) - options->uamlist = opt; - if ((c = getoption(buf, "-nlspath")) && (opt = strdup(c))) - options->nlspath = opt; - - if ((c = getoption(buf, "-ipaddr"))) { - struct in_addr inaddr; - if (inet_aton(c, &inaddr) && (opt = strdup(c))) { - if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET)) - syslog(LOG_INFO, "WARNING: can't find %s\n", opt); - options->ipaddr = opt; + if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c))) + options->authprintdir = opt; + if ((c = getoption(buf, "-uampath")) && (opt = strdup(c))) + options->uampath = opt; + if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c))) + options->uamlist = opt; + if ((c = getoption(buf, "-nlspath")) && (opt = strdup(c))) + options->nlspath = opt; + + if ((c = getoption(buf, "-ipaddr"))) { + struct in_addr inaddr; + if (inet_aton(c, &inaddr) && (opt = strdup(c))) { + if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET)) + syslog(LOG_INFO, "WARNING: can't find %s\n", opt); + options->ipaddr = opt; + } } - } - - if ((c = getoption(buf, "-port"))) - options->port = atoi(c); - if ((c = getoption(buf, "-ddpaddr"))) - atalk_aton(c, &options->ddpaddr); - - /* do a little checking for the domain name. */ - if ((c = getoption(buf, "-fqdn"))) { - char *p = strchr(c, ':'); - if (p) - *p = '\0'; - if (gethostbyname(c)) { - if (p) - *p = ':'; - if ((opt = strdup(c))) - options->fqdn = opt; + + if ((c = getoption(buf, "-port"))) + options->port = atoi(c); + if ((c = getoption(buf, "-ddpaddr"))) + atalk_aton(c, &options->ddpaddr); + + /* do a little checking for the domain name. */ + if ((c = getoption(buf, "-fqdn"))) { + char *p = strchr(c, ':'); + if (p) + *p = '\0'; + if (gethostbyname(c)) { + if (p) + *p = ':'; + if ((opt = strdup(c))) + options->fqdn = opt; + } } - } - return 1; + return 1; } int afp_options_parse(int ac, char **av, struct afp_options *options) { - extern char *optarg; - extern int optind; - - char *p; - char *tmp; /* Used for error checking the result of strtol */ - int c, err = 0; - - if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) { - perror( "gethostname" ); - return 0; - } + extern char *optarg; + extern int optind; + + char *p; + char *tmp; /* Used for error checking the result of strtol */ + int c, err = 0; + + if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) { + perror( "gethostname" ); + return 0; + } if (( p = strchr(options->hostname, '.' )) != 0 ) { - *p = '\0'; + *p = '\0'; } if (( p = strrchr( av[ 0 ], '/' )) == NULL ) { - p = av[ 0 ]; + p = av[ 0 ]; } else { - p++; + p++; } while (( c = getopt( ac, av, OPTIONS )) != EOF ) { - switch ( c ) { - case 'd' : - options->flags |= OPTION_DEBUG; - break; - case 'n' : - options->server = optarg; - break; - case 'f' : - options->defaultvol = optarg; - break; - case 's' : - options->systemvol = optarg; - break; - case 'u' : - options->flags |= OPTION_USERVOLFIRST; - break; - case 'c' : - options->connections = atoi( optarg ); - break; - case 'g' : - options->guest = optarg; - break; - - case 'P' : - options->pidfile = optarg; - break; - - case 'p': - options->passwdbits |= PASSWD_NOSAVE; - break; - case 't': - options->passwdbits |= PASSWD_SET; - break; - - case 'D': - options->transports &= ~AFPTRANS_DDP; - break; - case 'S': - options->port = atoi(optarg); - break; - case 'T': - options->transports &= ~AFPTRANS_TCP; - break; - case 'L': - options->loginmesg = optarg; - break; - case 'F': - options->configfile = optarg; - break; - case 'U': - options->uamlist = optarg; - break; - case 'v': /* version */ - printf( "afpd (version %s)\n", VERSION ); - exit ( 1 ); - break; - case 'I': - options->flags |= OPTION_CUSTOMICON; - break; - case 'm': - options->umask = strtol(optarg, &tmp, 8); - if ((options->umask < 0) || (options->umask > 0777)) { - fprintf(stderr, "%s: out of range umask setting provided\n", p); - err++; - } - if (tmp[0] != '\0') { - fprintf(stderr, "%s: invalid characters in umask setting provided\n", p); - err++; - } - break; - default : - err++; - } + switch ( c ) { + case 'd' : + options->flags |= OPTION_DEBUG; + break; + case 'n' : + options->server = optarg; + break; + case 'f' : + options->defaultvol = optarg; + break; + case 's' : + options->systemvol = optarg; + break; + case 'u' : + options->flags |= OPTION_USERVOLFIRST; + break; + case 'c' : + options->connections = atoi( optarg ); + break; + case 'g' : + options->guest = optarg; + break; + + case 'P' : + options->pidfile = optarg; + break; + + case 'p': + options->passwdbits |= PASSWD_NOSAVE; + break; + case 't': + options->passwdbits |= PASSWD_SET; + break; + + case 'D': + options->transports &= ~AFPTRANS_DDP; + break; + case 'S': + options->port = atoi(optarg); + break; + case 'T': + options->transports &= ~AFPTRANS_TCP; + break; + case 'L': + options->loginmesg = optarg; + break; + case 'F': + options->configfile = optarg; + break; + case 'U': + options->uamlist = optarg; + break; + case 'v': /* version */ + printf( "afpd (version %s)\n", VERSION ); + exit ( 1 ); + break; + case 'I': + options->flags |= OPTION_CUSTOMICON; + break; + case 'm': + options->umask = strtol(optarg, &tmp, 8); + if ((options->umask > 0777)) { + fprintf(stderr, "%s: out of range umask setting provided\n", p); + err++; + } + if (tmp[0] != '\0') { + fprintf(stderr, "%s: invalid characters in umask setting provided\n", p); + err++; + } + break; + default : + err++; + } } if ( err || optind != ac ) { - fprintf( stderr, - "Usage:\t%s [ -dpDTIt ] [ -n nbpname ] [ -f defvols ] \ -[ -P pidfile ] [ -s sysvols ] \n", p ); - fprintf( stderr, - "\t[ -u ] [ -c maxconn ] [ -g guest ] \ -[ -S port ] [ -L loginmesg ] [ -F configfile ] [ -U uamlist ]\n" ); - return 0; + fprintf( stderr, + "Usage:\t%s [ -dpDTIt ] [ -n nbpname ] [ -f defvols ] \ + [ -P pidfile ] [ -s sysvols ] \n", p ); + fprintf( stderr, + "\t[ -u ] [ -c maxconn ] [ -g guest ] \ + [ -S port ] [ -L loginmesg ] [ -F configfile ] [ -U uamlist ]\n" ); + return 0; } #ifdef ultrix diff --git a/etc/afpd/afs.c b/etc/afpd/afs.c index 169804f1..8d914124 100644 --- a/etc/afpd/afs.c +++ b/etc/afpd/afs.c @@ -1,5 +1,5 @@ /* - * $Id: afs.c,v 1.4 2001-06-20 18:33:04 rufustfirefly Exp $ + * $Id: afs.c,v 1.4.2.1 2001-12-03 05:01:03 jmarcus Exp $ * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. */ @@ -28,9 +28,9 @@ #include "misc.h" afs_getvolspace( vol, bfree, btotal, bsize ) - struct vol *vol; - VolSpace *bfree, *btotal; - u_int32_t *bsize; +struct vol *vol; +VolSpace *bfree, *btotal; +u_int32_t *bsize; { struct ViceIoctl vi; struct VolumeStatus *vs; @@ -41,26 +41,26 @@ afs_getvolspace( vol, bfree, btotal, bsize ) vi.out_size = sizeof( venuspace ); vi.out = venuspace; if ( pioctl( vol->v_path, VIOCGETVOLSTAT, &vi, 1 ) < 0 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } vs = (struct VolumeStatus *)venuspace; if ( vs->PartBlocksAvail > 0 ) { - if ( vs->MaxQuota != 0 ) { + if ( vs->MaxQuota != 0 ) { #define min(x,y) (((x)<(y))?(x):(y)) - free = min( vs->MaxQuota - vs->BlocksInUse, vs->PartBlocksAvail ); - } else { - free = vs->PartBlocksAvail; - } + free = min( vs->MaxQuota - vs->BlocksInUse, vs->PartBlocksAvail ); + } else { + free = vs->PartBlocksAvail; + } } else { - free = 0; + free = 0; } if ( vs->MaxQuota != 0 ) { - total = free + vs->BlocksInUse; + total = free + vs->BlocksInUse; } else { - total = vs->PartMaxBlocks; + total = vs->PartMaxBlocks; } *bsize = 1024; @@ -71,9 +71,9 @@ afs_getvolspace( vol, bfree, btotal, bsize ) } afp_getdiracl(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct ViceIoctl vi; struct vol *vol; @@ -86,32 +86,32 @@ afp_getdiracl(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( short ); if (( vol = getvolbyvid( vid )) == NULL ) { - *rbuflen = 0; - return( AFPERR_PARAM ); + *rbuflen = 0; + return( AFPERR_PARAM ); } memcpy( &did, ibuf, sizeof( did )); ibuf += sizeof( int ); if (( dir = dirsearch( vol, did )) == NULL ) { - *rbuflen = 0; - return( AFPERR_NOOBJ ); + *rbuflen = 0; + return( AFPERR_NOOBJ ); } if (( path = cname( vol, dir, &ibuf )) == NULL ) { - *rbuflen = 0; - return( AFPERR_NOOBJ ); + *rbuflen = 0; + return( AFPERR_NOOBJ ); } if ( *path != '\0' ) { - *rbuflen = 0; - return( AFPERR_BITMAP ); + *rbuflen = 0; + return( AFPERR_BITMAP ); } vi.in_size = 0; vi.out_size = *rbuflen; vi.out = rbuf; if ( pioctl( ".", VIOCGETAL, &vi, 1 ) < 0 ) { - *rbuflen = 0; - return( AFPERR_PARAM ); + *rbuflen = 0; + return( AFPERR_PARAM ); } *rbuflen = strlen( vi.out ) + 1; return( AFP_OK ); @@ -124,26 +124,26 @@ afp_getdiracl(obj, ibuf, ibuflen, rbuf, rbuflen ) * estimate permission, a la mdw. */ afsmode( path, ma, dir ) - char *path; - struct maccess *ma; - struct dir *dir; +char *path; +struct maccess *ma; +struct dir *dir; { struct ViceIoctl vi; char buf[ 1024 ]; if (( dir->d_flags & DIRF_FSMASK ) == DIRF_NOFS ) { - vi.in_size = 0; - vi.out_size = sizeof( buf ); - vi.out = buf; - if ( pioctl( path, VIOCGETAL, &vi, 1 ) < 0 ) { - dir->d_flags |= DIRF_UFS; - } else { - dir->d_flags |= DIRF_AFS; - } + vi.in_size = 0; + vi.out_size = sizeof( buf ); + vi.out = buf; + if ( pioctl( path, VIOCGETAL, &vi, 1 ) < 0 ) { + dir->d_flags |= DIRF_UFS; + } else { + dir->d_flags |= DIRF_AFS; + } } if (( dir->d_flags & DIRF_FSMASK ) != DIRF_AFS ) { - return; + return; } accessmode( upath, &ma, dir ); @@ -156,9 +156,9 @@ extern struct dir *curdir; * cmd | 0 | vid | did | pathtype | pathname | 0 | acl */ afp_setdiracl(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct ViceIoctl vi; struct vol *vol; @@ -173,28 +173,28 @@ afp_setdiracl(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( short ); if (( vol = getvolbyvid( vid )) == NULL ) { - *rbuflen = 0; - return( AFPERR_PARAM ); + *rbuflen = 0; + return( AFPERR_PARAM ); } memcpy( &did, ibuf, sizeof( did )); ibuf += sizeof( int ); if (( dir = dirsearch( vol, did )) == NULL ) { - *rbuflen = 0; - return( AFPERR_NOOBJ ); + *rbuflen = 0; + return( AFPERR_NOOBJ ); } if (( path = cname( vol, dir, &ibuf )) == NULL ) { - *rbuflen = 0; - return( AFPERR_NOOBJ ); + *rbuflen = 0; + return( AFPERR_NOOBJ ); } if ( *path != '\0' ) { - *rbuflen = 0; - return( AFPERR_BITMAP ); + *rbuflen = 0; + return( AFPERR_BITMAP ); } if ((int)ibuf & 1 ) { - ibuf++; + ibuf++; } vi.in_size = iend - ibuf; @@ -202,12 +202,12 @@ afp_setdiracl(obj, ibuf, ibuflen, rbuf, rbuflen ) vi.out_size = 0; if ( pioctl( ".", VIOCSETAL, &vi, 1 ) < 0 ) { - *rbuflen = 0; - return( AFPERR_PARAM ); + *rbuflen = 0; + return( AFPERR_PARAM ); } pioctl( ".AppleDouble", VIOCSETAL, &vi, 1 ); if ( curdir->d_did == DIRDID_ROOT ) { - pioctl( ".AppleDesktop", VIOCSETAL, &vi, 1 ); + pioctl( ".AppleDesktop", VIOCSETAL, &vi, 1 ); } return( AFP_OK ); @@ -225,9 +225,9 @@ extern C_Block seskey; extern Key_schedule seskeysched; afp_afschangepw(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { char name[ MAXKTCNAMELEN ], instance[ MAXKTCNAMELEN ]; char realm[ MAXKTCREALMLEN ]; @@ -246,30 +246,30 @@ afp_afschangepw(obj, ibuf, ibuflen, rbuf, rbuflen ) ka_ParseLoginName( ibuf, name, instance, realm ); ucase( realm ); if ( *realm == '\0' ) { - if ( krb_get_lrealm( realm, 1 ) != KSUCCESS ) { - syslog( LOG_ERR, "krb_get_lrealm failed" ); - return( AFPERR_BADUAM ); - } + if ( krb_get_lrealm( realm, 1 ) != KSUCCESS ) { + syslog( LOG_ERR, "krb_get_lrealm failed" ); + return( AFPERR_BADUAM ); + } } if ( strlen( name ) < 2 || strlen( name ) > 18 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } ibuf += len; memcpy( &clen, ibuf, sizeof( clen )); clen = ntohs( clen ); if ( clen % 8 != 0 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } ibuf += sizeof( short ); pcbc_encrypt((C_Block *)ibuf, (C_Block *)ibuf, - clen, seskeysched, seskey, DES_DECRYPT ); + clen, seskeysched, seskey, DES_DECRYPT ); len = (unsigned char) *ibuf++; if ( len > 8 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memset( oldpw, 0, sizeof( oldpw )); memcpy( oldpw, ibuf, len ); @@ -278,7 +278,7 @@ afp_afschangepw(obj, ibuf, ibuflen, rbuf, rbuflen ) len = (unsigned char) *ibuf++; if ( len > 8 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memset( newpw, 0, sizeof( newpw )); memcpy( newpw, ibuf, len ); @@ -286,7 +286,7 @@ afp_afschangepw(obj, ibuf, ibuflen, rbuf, rbuflen ) newpw[ len ] = '\0'; syslog( LOG_INFO, - "changing password for <%s>.<%s>@<%s>", name, instance, realm ); + "changing password for <%s>.<%s>@<%s>", name, instance, realm ); ka_StringToKey( oldpw, realm, &oldkey ); memset( oldpw, 0, sizeof( oldpw )); @@ -296,25 +296,25 @@ afp_afschangepw(obj, ibuf, ibuflen, rbuf, rbuflen ) rc = ka_GetAdminToken( name, instance, realm, &oldkey, 60, &adtok, 0 ); memset( &oldkey, 0, sizeof( oldkey )); switch ( rc ) { - case 0: - break; - case KABADREQUEST: - memset( &newkey, 0, sizeof( newkey )); - return( AFPERR_NOTAUTH ); - default: - memset( &newkey, 0, sizeof( newkey )); - return( AFPERR_BADUAM ); + case 0: + break; + case KABADREQUEST: + memset( &newkey, 0, sizeof( newkey )); + return( AFPERR_NOTAUTH ); + default: + memset( &newkey, 0, sizeof( newkey )); + return( AFPERR_BADUAM ); } if ( ka_AuthServerConn( realm, KA_MAINTENANCE_SERVICE, &adtok, &conn ) - != 0 ) { - memset( &newkey, 0, sizeof( newkey )); - return( AFPERR_BADUAM ); + != 0 ) { + memset( &newkey, 0, sizeof( newkey )); + return( AFPERR_BADUAM ); } rc = ka_ChangePassword( name, instance, conn, 0, &newkey ); memset( &newkey, 0, sizeof( newkey )); if ( rc != 0 ) { - return( AFPERR_BADUAM ); + return( AFPERR_BADUAM ); } syslog( LOG_DEBUG, "password changed succeeded" ); diff --git a/etc/afpd/appl.c b/etc/afpd/appl.c index d14935bb..cd3b7b68 100644 --- a/etc/afpd/appl.c +++ b/etc/afpd/appl.c @@ -1,5 +1,5 @@ /* - * $Id: appl.c,v 1.3 2001-06-20 18:33:04 rufustfirefly Exp $ + * $Id: appl.c,v 1.3.2.1 2001-12-03 05:01:03 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -38,53 +38,53 @@ static struct savedt sa = { { 0, 0, 0, 0 }, -1, 0 }; static __inline__ int pathcmp( p, plen, q, qlen ) - char *p; - int plen; - char *q; - int qlen; +char *p; +int plen; +char *q; +int qlen; { return (( plen == qlen && memcmp( p, q, plen ) == 0 ) ? 0 : 1 ); } static int applopen( vol, creator, flags, mode ) - struct vol *vol; - u_char creator[ 4 ]; +struct vol *vol; +u_char creator[ 4 ]; { char *dtf, *adt, *adts; if ( sa.sdt_fd != -1 ) { - if ( !(flags & ( O_RDWR | O_WRONLY )) && - memcmp( sa.sdt_creator, creator, sizeof( CreatorType )) == 0 && - sa.sdt_vid == vol->v_vid ) { - return( AFP_OK ); - } - close( sa.sdt_fd ); - sa.sdt_fd = -1; + if ( !(flags & ( O_RDWR | O_WRONLY )) && + memcmp( sa.sdt_creator, creator, sizeof( CreatorType )) == 0 && + sa.sdt_vid == vol->v_vid ) { + return( AFP_OK ); + } + close( sa.sdt_fd ); + sa.sdt_fd = -1; } dtf = dtfile( vol, creator, ".appl" ); if (( sa.sdt_fd = open( dtf, flags, ad_mode( dtf, mode ))) < 0 ) { - if ( errno == ENOENT && ( flags & O_CREAT )) { - if (( adts = strrchr( dtf, '/' )) == NULL ) { - return( AFPERR_PARAM ); - } - *adts = '\0'; - if (( adt = strrchr( dtf, '/' )) == NULL ) { - return( AFPERR_PARAM ); - } - *adt = '\0'; - (void) ad_mkdir( dtf, DIRBITS | 0777 ); - *adt = '/'; - (void) ad_mkdir( dtf, DIRBITS | 0777 ); - *adts = '/'; - - if (( sa.sdt_fd = open( dtf, flags, ad_mode( dtf, mode ))) < 0 ) { - return( AFPERR_PARAM ); - } - } else { - return( AFPERR_PARAM ); - } + if ( errno == ENOENT && ( flags & O_CREAT )) { + if (( adts = strrchr( dtf, '/' )) == NULL ) { + return( AFPERR_PARAM ); + } + *adts = '\0'; + if (( adt = strrchr( dtf, '/' )) == NULL ) { + return( AFPERR_PARAM ); + } + *adt = '\0'; + (void) ad_mkdir( dtf, DIRBITS | 0777 ); + *adt = '/'; + (void) ad_mkdir( dtf, DIRBITS | 0777 ); + *adts = '/'; + + if (( sa.sdt_fd = open( dtf, flags, ad_mode( dtf, mode ))) < 0 ) { + return( AFPERR_PARAM ); + } + } else { + return( AFPERR_PARAM ); + } } memcpy( sa.sdt_creator, creator, sizeof( CreatorType )); sa.sdt_vid = vol->v_vid; @@ -96,10 +96,10 @@ static int applopen( vol, creator, flags, mode ) * copy appls to new file, deleting any matching (old) appl entries */ static int copyapplfile( sfd, dfd, mpath, mplen ) - int sfd; - int dfd; - char *mpath; - u_short mplen; +int sfd; +int dfd; +char *mpath; +u_short mplen; { int cc; char *p; @@ -108,20 +108,20 @@ static int copyapplfile( sfd, dfd, mpath, mplen ) char buf[ MAXPATHLEN ]; while (( cc = read( sfd, buf, sizeof(appltag) + sizeof( u_short ))) > 0 ) { - p = buf + sizeof(appltag); - memcpy( &len, p, sizeof(len)); - len = ntohs( len ); - p += sizeof( len ); - if (( cc = read( sa.sdt_fd, p, len )) < len ) { - break; - } - if ( pathcmp( mpath, mplen, p, len ) != 0 ) { - p += len; - if ( write( dfd, buf, p - buf ) != p - buf ) { - cc = -1; - break; - } - } + p = buf + sizeof(appltag); + memcpy( &len, p, sizeof(len)); + len = ntohs( len ); + p += sizeof( len ); + if (( cc = read( sa.sdt_fd, p, len )) < len ) { + break; + } + if ( pathcmp( mpath, mplen, p, len ) != 0 ) { + p += len; + if ( write( dfd, buf, p - buf ) != p - buf ) { + cc = -1; + break; + } + } } return( cc ); } @@ -140,10 +140,10 @@ static int copyapplfile( sfd, dfd, mpath, mplen ) */ static char * makemacpath( mpath, mpathlen, dir, path ) - char *mpath; - int mpathlen; - struct dir *dir; - char *path; +char *mpath; +int mpathlen; +struct dir *dir; +char *path; { char *p; @@ -152,22 +152,22 @@ makemacpath( mpath, mpathlen, dir, path ) strncpy( p, path, strlen( path )); while ( dir->d_parent != NULL ) { - p -= strlen( dir->d_name ) + 1; - strcpy( p, dir->d_name ); - dir = dir->d_parent; + p -= strlen( dir->d_name ) + 1; + strcpy( p, dir->d_name ); + dir = dir->d_parent; } - return( p ); + return( p ); } int afp_addappl(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol; struct dir *dir; - int tfd, cc; + int tfd, cc; u_int32_t did; u_int16_t vid, mplen; char *path, *dtf, *p, *mp; @@ -181,13 +181,13 @@ int afp_addappl(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memcpy( &did, ibuf, sizeof( did )); ibuf += sizeof( did ); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } memcpy( creator, ibuf, sizeof( creator )); @@ -197,23 +197,23 @@ int afp_addappl(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( appltag ); if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ( *path == '\0' ) { - return( AFPERR_BADTYPE ); + return( AFPERR_BADTYPE ); } if ( applopen( vol, creator, O_RDWR|O_CREAT, 0666 ) != AFP_OK ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if ( lseek( sa.sdt_fd, 0L, SEEK_SET ) < 0 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } dtf = dtfile( vol, creator, ".appl.temp" ); tempfile = obj->oldtmp; strcpy( tempfile, dtf ); if (( tfd = open( tempfile, O_RDWR|O_CREAT, 0666 )) < 0 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } mpath = obj->newtmp; mp = makemacpath( mpath, AFPOBJ_TMPSIZ, curdir, path ); @@ -228,8 +228,8 @@ int afp_addappl(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy(p, appltag, sizeof( appltag )); cc = mpath + AFPOBJ_TMPSIZ - p; if ( write( tfd, p, cc ) != cc ) { - unlink( tempfile ); - return( AFPERR_PARAM ); + unlink( tempfile ); + return( AFPERR_PARAM ); } cc = copyapplfile( sa.sdt_fd, tfd, mp, mplen ); close( tfd ); @@ -237,19 +237,19 @@ int afp_addappl(obj, ibuf, ibuflen, rbuf, rbuflen ) sa.sdt_fd = -1; if ( cc < 0 ) { - unlink( tempfile ); - return( AFPERR_PARAM ); + unlink( tempfile ); + return( AFPERR_PARAM ); } if ( rename( tempfile, dtfile( vol, creator, ".appl" )) < 0 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } return( AFP_OK ); } int afp_rmvappl(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol; struct dir *dir; @@ -266,36 +266,36 @@ int afp_rmvappl(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memcpy( &did, ibuf, sizeof( did )); ibuf += sizeof( did ); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } memcpy( creator, ibuf, sizeof( creator )); ibuf += sizeof( creator ); if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ( *path == '.' ) { - return( AFPERR_BADTYPE ); + return( AFPERR_BADTYPE ); } if ( applopen( vol, creator, O_RDWR, 0666 ) != AFP_OK ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ( lseek( sa.sdt_fd, 0L, SEEK_SET ) < 0 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } dtf = dtfile( vol, creator, ".appl.temp" ); tempfile = obj->oldtmp; strcpy( tempfile, dtf ); if (( tfd = open( tempfile, O_RDWR|O_CREAT, 0666 )) < 0 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } mpath = obj->newtmp; mp = makemacpath( mpath, AFPOBJ_TMPSIZ, curdir, path ); @@ -306,19 +306,19 @@ int afp_rmvappl(obj, ibuf, ibuflen, rbuf, rbuflen ) sa.sdt_fd = -1; if ( cc < 0 ) { - unlink( tempfile ); - return( AFPERR_PARAM ); + unlink( tempfile ); + return( AFPERR_PARAM ); } if ( rename( tempfile, dtfile( vol, creator, ".appl" )) < 0 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } return( AFP_OK ); } int afp_getappl(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct stat st; struct vol *vol; @@ -334,8 +334,8 @@ int afp_getappl(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - *rbuflen = 0; - return( AFPERR_PARAM ); + *rbuflen = 0; + return( AFPERR_PARAM ); } memcpy( creator, ibuf, sizeof( creator )); @@ -345,44 +345,44 @@ int afp_getappl(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( aindex ); aindex = ntohs( aindex ); if ( aindex ) { /* index 0 == index 1 */ - --aindex; + --aindex; } - + memcpy( &bitmap, ibuf, sizeof( bitmap )); bitmap = ntohs( bitmap ); ibuf += sizeof( bitmap ); if ( applopen( vol, creator, O_RDONLY, 0666 ) != AFP_OK ) { - *rbuflen = 0; - return( AFPERR_NOITEM ); + *rbuflen = 0; + return( AFPERR_NOITEM ); } if ( aindex < sa.sdt_index ) { - if ( lseek( sa.sdt_fd, 0L, SEEK_SET ) < 0 ) { - *rbuflen = 0; - return( AFPERR_PARAM ); - } - sa.sdt_index = 0; + if ( lseek( sa.sdt_fd, 0L, SEEK_SET ) < 0 ) { + *rbuflen = 0; + return( AFPERR_PARAM ); + } + sa.sdt_index = 0; } /* position to correct spot within appl file */ buf = obj->oldtmp; while (( cc = read( sa.sdt_fd, buf, sizeof( appltag ) - + sizeof( u_short ))) > 0 ) { - p = buf + sizeof( appltag ); - memcpy( &len, p, sizeof( len )); - len = ntohs( len ); - p += sizeof( u_short ); - if (( cc = read( sa.sdt_fd, p, len )) < len ) { - break; - } - if ( sa.sdt_index == aindex ) { - break; - } - sa.sdt_index++; + + sizeof( u_short ))) > 0 ) { + p = buf + sizeof( appltag ); + memcpy( &len, p, sizeof( len )); + len = ntohs( len ); + p += sizeof( u_short ); + if (( cc = read( sa.sdt_fd, p, len )) < len ) { + break; + } + if ( sa.sdt_index == aindex ) { + break; + } + sa.sdt_index++; } if ( cc <= 0 || sa.sdt_index != aindex ) { - *rbuflen = 0; - return( AFPERR_NOITEM ); + *rbuflen = 0; + return( AFPERR_NOITEM ); } sa.sdt_index++; @@ -396,33 +396,33 @@ int afp_getappl(obj, ibuf, ibuflen, rbuf, rbuflen ) #define hextoint( c ) ( isdigit( c ) ? c - '0' : c + 10 - 'a' ) #define islxdigit(x) (!isupper(x)&&isxdigit(x)) - char utomname[ MAXPATHLEN + 1]; - char *u, *m; - int i, h; - - u = p; - m = utomname; - i = len; - while ( i ) { - if ( *u == ':' && *(u+1) != '\0' && islxdigit( *(u+1)) && - *(u+2) != '\0' && islxdigit( *(u+2))) { - ++u, --i; - h = hextoint( *u ) << 4; - ++u, --i; - h |= hextoint( *u ); - *m++ = h; - } else { - *m++ = *u; - } - ++u, --i; - } - - len = m - utomname; - p = utomname; - - if ( p[ len - 1 ] == '\0' ) { - len--; - } + char utomname[ MAXPATHLEN + 1]; + char *u, *m; + int i, h; + + u = p; + m = utomname; + i = len; + while ( i ) { + if ( *u == ':' && *(u+1) != '\0' && islxdigit( *(u+1)) && + *(u+2) != '\0' && islxdigit( *(u+2))) { + ++u, --i; + h = hextoint( *u ) << 4; + ++u, --i; + h |= hextoint( *u ); + *m++ = h; + } else { + *m++ = *u; + } + ++u, --i; + } + + len = m - utomname; + p = utomname; + + if ( p[ len - 1 ] == '\0' ) { + len--; + } } #endif /* APPLCNAME */ @@ -435,19 +435,19 @@ int afp_getappl(obj, ibuf, ibuflen, rbuf, rbuflen ) q = cbuf; if (( p = cname( vol, vol->v_dir, &q )) == NULL ) { - *rbuflen = 0; - return( AFPERR_NOITEM ); + *rbuflen = 0; + return( AFPERR_NOITEM ); } if ( stat( mtoupath(vol, p), &st ) < 0 ) { - *rbuflen = 0; - return( AFPERR_NOITEM ); + *rbuflen = 0; + return( AFPERR_NOITEM ); } buflen = *rbuflen - sizeof( bitmap ) - sizeof( appltag ); if ( getfilparams(vol, bitmap, p, curdir, &st, rbuf + sizeof( bitmap ) + - sizeof( appltag ), &buflen ) != AFP_OK ) { - *rbuflen = 0; - return( AFPERR_BITMAP ); + sizeof( appltag ), &buflen ) != AFP_OK ) { + *rbuflen = 0; + return( AFPERR_BITMAP ); } *rbuflen = buflen + sizeof( bitmap ) + sizeof( appltag ); diff --git a/etc/afpd/auth.c b/etc/afpd/auth.c index 1c6f592b..032359e2 100644 --- a/etc/afpd/auth.c +++ b/etc/afpd/auth.c @@ -1,5 +1,5 @@ /* - * $Id: auth.c,v 1.19 2001-11-10 17:51:10 srittau Exp $ + * $Id: auth.c,v 1.19.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -68,23 +68,23 @@ int ngroups; * These numbers are scattered throughout the code. */ static struct afp_versions afp_versions[] = { - { "AFPVersion 1.1", 11 }, - { "AFPVersion 2.0", 20 }, - { "AFPVersion 2.1", 21 }, - { "AFP2.2", 22 } -}; + { "AFPVersion 1.1", 11 }, + { "AFPVersion 2.0", 20 }, + { "AFPVersion 2.1", 21 }, + { "AFP2.2", 22 } + }; static struct uam_mod uam_modules = {NULL, NULL, &uam_modules, &uam_modules}; static struct uam_obj uam_login = {"", "", 0, {{NULL}}, &uam_login, - &uam_login}; -static struct uam_obj uam_changepw = {"", "", 0, {{NULL}}, &uam_changepw, - &uam_changepw}; + &uam_login}; +static struct uam_obj uam_changepw = {"", "", 0, {{NULL}}, &uam_changepw, + &uam_changepw}; static struct uam_obj *afp_uam = NULL; void status_versions( data ) - char *data; +char *data; { char *start = data; u_int16_t status; @@ -95,10 +95,10 @@ void status_versions( data ) data += ntohs( status ); *data++ = num; for ( i = 0; i < num; i++ ) { - len = strlen( afp_versions[ i ].av_name ); - *data++ = len; - memcpy( data, afp_versions[ i ].av_name , len ); - data += len; + len = strlen( afp_versions[ i ].av_name ); + *data++ = len; + memcpy( data, afp_versions[ i ].av_name , len ); + data += len; } status = htons( data - start ); memcpy(start + AFPSTATUS_UAMSOFF, &status, sizeof(status)); @@ -114,20 +114,20 @@ void status_uams(char *data, const char *authlist) memcpy(&status, start + AFPSTATUS_UAMSOFF, sizeof(status)); uams = &uam_login; while ((uams = uams->uam_prev) != &uam_login) { - if (strstr(authlist, uams->uam_path)) - num++; + if (strstr(authlist, uams->uam_path)) + num++; } data += ntohs( status ); *data++ = num; while ((uams = uams->uam_prev) != &uam_login) { - if (strstr(authlist, uams->uam_path)) { - syslog(LOG_INFO, "uam: \"%s\" available", uams->uam_name); - len = strlen( uams->uam_name); - *data++ = len; - memcpy( data, uams->uam_name, len ); - data += len; - } + if (strstr(authlist, uams->uam_path)) { + syslog(LOG_INFO, "uam: \"%s\" available", uams->uam_name); + len = strlen( uams->uam_name); + *data++ = len; + memcpy( data, uams->uam_name, len ); + data += len; + } } /* icon offset */ @@ -139,13 +139,13 @@ void status_uams(char *data, const char *authlist) * by the afp_* functions. */ static int send_reply(const AFPObj *obj, const int err) { - if ((err == AFP_OK) || (err == AFPERR_AUTHCONT)) - return err; + if ((err == AFP_OK) || (err == AFPERR_AUTHCONT)) + return err; - obj->reply(obj->handle, err); - obj->exit(0); + obj->reply(obj->handle, err); + obj->exit(0); - return AFP_OK; + return AFP_OK; } static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void)) @@ -158,55 +158,55 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void)) openlog( "afpd", LOG_NDELAY|LOG_PID, LOG_DAEMON); if ( pwd->pw_uid == 0 ) { /* don't allow root login */ - syslog( LOG_ERR, "login: root login denied!" ); - return AFPERR_NOTAUTH; + syslog( LOG_ERR, "login: root login denied!" ); + return AFPERR_NOTAUTH; } syslog( LOG_INFO, "login %s (uid %d, gid %d)", pwd->pw_name, - pwd->pw_uid, pwd->pw_gid ); + pwd->pw_uid, pwd->pw_gid ); if (obj->proto == AFPPROTO_ASP) { - ASP asp = obj->handle; - int addr_net = ntohs( asp->asp_sat.sat_addr.s_net ); - int addr_node = asp->asp_sat.sat_addr.s_node; - - if (obj->options.authprintdir) { - if(addr_net && addr_node) { /* Do we have a valid Appletalk address? */ - char nodename[256]; - FILE *fp; - struct stat stat_buf; - - sprintf(nodename, "%s/net%d.%dnode%d", obj->options.authprintdir, - addr_net / 256, addr_net % 256, addr_node); - syslog (LOG_INFO, "registering %s (uid %d) on %u.%u as %s", - pwd->pw_name, pwd->pw_uid, addr_net, addr_node, nodename); - - if (stat(nodename, &stat_buf) == 0) { /* file exists */ - if (S_ISREG(stat_buf.st_mode)) { /* normal file */ - unlink(nodename); - fp = fopen(nodename, "w"); - fprintf(fp, "%s\n", pwd->pw_name); - fclose(fp); - chown( nodename, pwd->pw_uid, -1 ); - } else { /* somebody is messing with us */ - syslog( LOG_ERR, "print authfile %s is not a normal file, it will not be modified", nodename ); - } - } else { /* file 'nodename' does not exist */ - fp = fopen(nodename, "w"); - fprintf(fp, "%s\n", pwd->pw_name); - fclose(fp); - chown( nodename, pwd->pw_uid, -1 ); - } - } /* if (addr_net && addr_node ) */ - } /* if (options->authprintdir) */ + ASP asp = obj->handle; + int addr_net = ntohs( asp->asp_sat.sat_addr.s_net ); + int addr_node = asp->asp_sat.sat_addr.s_node; + + if (obj->options.authprintdir) { + if(addr_net && addr_node) { /* Do we have a valid Appletalk address? */ + char nodename[256]; + FILE *fp; + struct stat stat_buf; + + sprintf(nodename, "%s/net%d.%dnode%d", obj->options.authprintdir, + addr_net / 256, addr_net % 256, addr_node); + syslog (LOG_INFO, "registering %s (uid %d) on %u.%u as %s", + pwd->pw_name, pwd->pw_uid, addr_net, addr_node, nodename); + + if (stat(nodename, &stat_buf) == 0) { /* file exists */ + if (S_ISREG(stat_buf.st_mode)) { /* normal file */ + unlink(nodename); + fp = fopen(nodename, "w"); + fprintf(fp, "%s\n", pwd->pw_name); + fclose(fp); + chown( nodename, pwd->pw_uid, -1 ); + } else { /* somebody is messing with us */ + syslog( LOG_ERR, "print authfile %s is not a normal file, it will not be modified", nodename ); + } + } else { /* file 'nodename' does not exist */ + fp = fopen(nodename, "w"); + fprintf(fp, "%s\n", pwd->pw_name); + fclose(fp); + chown( nodename, pwd->pw_uid, -1 ); + } + } /* if (addr_net && addr_node ) */ + } /* if (options->authprintdir) */ } /* if (obj->proto == AFPPROTO_ASP) */ if (initgroups( pwd->pw_name, pwd->pw_gid ) < 0) { #ifdef RUN_AS_USER - syslog(LOG_INFO, "running with uid %d", geteuid()); + syslog(LOG_INFO, "running with uid %d", geteuid()); #else /* RUN_AS_USER */ - syslog(LOG_ERR, "login: %s", strerror(errno)); - return AFPERR_BADUAM; + syslog(LOG_ERR, "login: %s", strerror(errno)); + return AFPERR_BADUAM; #endif /* RUN_AS_USER */ } @@ -214,17 +214,17 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void)) /* Basically if the user is in the admin group, we stay root */ if (( ngroups = getgroups( NGROUPS, groups )) < 0 ) { - syslog( LOG_ERR, "login: getgroups: %s", strerror(errno) ); - return AFPERR_BADUAM; + syslog( LOG_ERR, "login: getgroups: %s", strerror(errno) ); + return AFPERR_BADUAM; } #ifdef ADMIN_GRP #ifdef DEBUG syslog(LOG_INFO, "obj->options.admingid == %d", obj->options.admingid); #endif /* DEBUG */ if (obj->options.admingid != 0) { - int i; - for (i = 0; i < ngroups; i++) { - if (groups[i] == obj->options.admingid) admin = 1; + int i; + for (i = 0; i < ngroups; i++) { + if (groups[i] == obj->options.admingid) admin = 1; } } if (admin) syslog( LOG_INFO, "admin login -- %s", pwd->pw_name ); @@ -266,20 +266,20 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void)) } } #else /* TRU64 */ - if (setegid( pwd->pw_gid ) < 0 || seteuid( pwd->pw_uid ) < 0) { - syslog( LOG_ERR, "login: %s", strerror(errno) ); - return AFPERR_BADUAM; - } + if (setegid( pwd->pw_gid ) < 0 || seteuid( pwd->pw_uid ) < 0) { + syslog( LOG_ERR, "login: %s", strerror(errno) ); + return AFPERR_BADUAM; + } #endif /* TRU64 */ - /* There's probably a better way to do this, but for now, we just - play root */ + /* There's probably a better way to do this, but for now, we just + play root */ #ifdef ADMIN_GRP if (admin) uuid = 0; else #endif /* ADMIN_GRP */ - uuid = pwd->pw_uid; + uuid = pwd->pw_uid; afp_switch = postauth_switch; obj->logout = logout; @@ -288,75 +288,75 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void)) } int afp_login(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct passwd *pwd = NULL; int len, i, num; *rbuflen = 0; - if ( nologin & 1) - return send_reply(obj, AFPERR_SHUTDOWN ); + if ( nologin & 1) + return send_reply(obj, AFPERR_SHUTDOWN ); ibuf++; len = (unsigned char) *ibuf++; num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ]); for ( i = 0; i < num; i++ ) { - if ( strncmp( ibuf, afp_versions[ i ].av_name , len ) == 0 ) { - afp_version = afp_versions[ i ].av_number; - break; - } + if ( strncmp( ibuf, afp_versions[ i ].av_name , len ) == 0 ) { + afp_version = afp_versions[ i ].av_number; + break; + } } if ( i == num ) /* An inappropo version */ - return send_reply(obj, AFPERR_BADVERS ); + return send_reply(obj, AFPERR_BADVERS ); ibuf += len; len = (unsigned char) *ibuf++; if ((afp_uam = auth_uamfind(UAM_SERVER_LOGIN, ibuf, len)) == NULL) - return send_reply(obj, AFPERR_BADUAM); + return send_reply(obj, AFPERR_BADUAM); ibuf += len; i = afp_uam->u.uam_login.login(obj, &pwd, ibuf, ibuflen, rbuf, rbuflen); - if (i || !pwd) - return send_reply(obj, i); + if (i || !pwd) + return send_reply(obj, i); return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout)); } int afp_logincont(obj, ibuf, ibuflen, rbuf, rbuflen) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct passwd *pwd = NULL; int err; if ( afp_uam == NULL || afp_uam->u.uam_login.logincont == NULL ) { - *rbuflen = 0; - return send_reply(obj, AFPERR_NOTAUTH ); + *rbuflen = 0; + return send_reply(obj, AFPERR_NOTAUTH ); } ibuf += 2; err = afp_uam->u.uam_login.logincont(obj, &pwd, ibuf, ibuflen, - rbuf, rbuflen); + rbuf, rbuflen); if (err || !pwd) - return send_reply(obj, err); + return send_reply(obj, err); return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout)); } int afp_logout(obj, ibuf, ibuflen, rbuf, rbuflen) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { - syslog(LOG_INFO, "logout %s", obj->username); - obj->exit(0); - return AFP_OK; + syslog(LOG_INFO, "logout %s", obj->username); + obj->exit(0); + return AFP_OK; } @@ -367,78 +367,78 @@ int afp_logout(obj, ibuf, ibuflen, rbuf, rbuflen) * it off to the uam. */ int afp_changepw(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { - char username[MACFILELEN + 1], *start = ibuf; - struct uam_obj *uam; - struct passwd *pwd; - int len; + char username[MACFILELEN + 1], *start = ibuf; + struct uam_obj *uam; + struct passwd *pwd; + int len; - *rbuflen = 0; - ibuf += 2; + *rbuflen = 0; + ibuf += 2; - /* make sure we can deal w/ this uam */ - len = (unsigned char) *ibuf++; - if ((uam = auth_uamfind(UAM_SERVER_CHANGEPW, ibuf, len)) == NULL) - return AFPERR_BADUAM; + /* make sure we can deal w/ this uam */ + len = (unsigned char) *ibuf++; + if ((uam = auth_uamfind(UAM_SERVER_CHANGEPW, ibuf, len)) == NULL) + return AFPERR_BADUAM; - ibuf += len; - if ((len + 1) & 1) /* pad byte */ - ibuf++; + ibuf += len; + if ((len + 1) & 1) /* pad byte */ + ibuf++; - len = (unsigned char) *ibuf++; - if ( len > sizeof(username) - 1) { - return AFPERR_PARAM; - } - memcpy(username, ibuf, len); - username[ len ] = '\0'; - ibuf += len; - if ((len + 1) & 1) /* pad byte */ - ibuf++; - - syslog(LOG_INFO, "changing password for <%s>", username); - - if (( pwd = uam_getname( username, sizeof(username))) == NULL ) - return AFPERR_PARAM; - - /* send it off to the uam. we really don't use ibuflen right now. */ - ibuflen -= (ibuf - start); - len = uam->u.uam_changepw(obj, username, pwd, ibuf, ibuflen, - rbuf, rbuflen); - syslog(LOG_INFO, "password change %s.", - (len == AFPERR_AUTHCONT) ? "continued" : - (len ? "failed" : "succeeded")); - return len; + len = (unsigned char) *ibuf++; + if ( len > sizeof(username) - 1) { + return AFPERR_PARAM; + } + memcpy(username, ibuf, len); + username[ len ] = '\0'; + ibuf += len; + if ((len + 1) & 1) /* pad byte */ + ibuf++; + + syslog(LOG_INFO, "changing password for <%s>", username); + + if (( pwd = uam_getname( username, sizeof(username))) == NULL ) + return AFPERR_PARAM; + + /* send it off to the uam. we really don't use ibuflen right now. */ + ibuflen -= (ibuf - start); + len = uam->u.uam_changepw(obj, username, pwd, ibuf, ibuflen, + rbuf, rbuflen); + syslog(LOG_INFO, "password change %s.", + (len == AFPERR_AUTHCONT) ? "continued" : + (len ? "failed" : "succeeded")); + return len; } /* FPGetUserInfo */ int afp_getuserinfo(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { u_int8_t thisuser; u_int32_t id; u_int16_t bitmap; - + *rbuflen = 0; ibuf++; thisuser = *ibuf++; ibuf += sizeof(id); /* userid is not used in AFP 2.0 */ memcpy(&bitmap, ibuf, sizeof(bitmap)); bitmap = ntohs(bitmap); - - /* deal with error cases. we don't have to worry about + + /* deal with error cases. we don't have to worry about * AFPERR_ACCESS or AFPERR_NOITEM as geteuid and getegid always * succeed. */ - if (!thisuser) - return AFPERR_PARAM; + if (!thisuser) + return AFPERR_PARAM; if ((bitmap & USERIBIT_ALL) != bitmap) - return AFPERR_BITMAP; - + return AFPERR_BITMAP; + /* copy the bitmap back to reply buffer */ memcpy(rbuf, ibuf, sizeof(bitmap)); rbuf += sizeof(bitmap); @@ -446,21 +446,21 @@ int afp_getuserinfo(obj, ibuf, ibuflen, rbuf, rbuflen ) /* copy the user/group info */ if (bitmap & USERIBIT_USER) { - id = htonl(geteuid()); - memcpy(rbuf, &id, sizeof(id)); - rbuf += sizeof(id); - *rbuflen += sizeof(id); + id = htonl(geteuid()); + memcpy(rbuf, &id, sizeof(id)); + rbuf += sizeof(id); + *rbuflen += sizeof(id); } - + if (bitmap & USERIBIT_GROUP) { - id = htonl(getegid()); - memcpy(rbuf, &id, sizeof(id)); - rbuf += sizeof(id); - *rbuflen += sizeof(id); + id = htonl(getegid()); + memcpy(rbuf, &id, sizeof(id)); + rbuf += sizeof(id); + *rbuflen += sizeof(id); } - + return AFP_OK; -} +} #define UAM_LIST(type) (((type) == UAM_SERVER_LOGIN) ? &uam_login : \ (((type) == UAM_SERVER_CHANGEPW) ? \ @@ -468,88 +468,88 @@ int afp_getuserinfo(obj, ibuf, ibuflen, rbuf, rbuflen ) /* just do a linked list search. this could be sped up with a hashed * list, but i doubt anyone's going to have enough uams to matter. */ -struct uam_obj *auth_uamfind(const int type, const char *name, - const int len) +struct uam_obj *auth_uamfind(const int type, const char *name, + const int len) { - struct uam_obj *prev, *start; + struct uam_obj *prev, *start; - if (!name || !(start = UAM_LIST(type))) - return NULL; + if (!name || !(start = UAM_LIST(type))) + return NULL; - prev = start; - while ((prev = prev->uam_prev) != start) - if (strndiacasecmp(prev->uam_name, name, len) == 0) - return prev; + prev = start; + while ((prev = prev->uam_prev) != start) + if (strndiacasecmp(prev->uam_name, name, len) == 0) + return prev; - return NULL; + return NULL; } int auth_register(const int type, struct uam_obj *uam) { - struct uam_obj *start; + struct uam_obj *start; - if (!uam || !uam->uam_name || (*uam->uam_name == '\0')) - return -1; + if (!uam || !uam->uam_name || (*uam->uam_name == '\0')) + return -1; - if (!(start = UAM_LIST(type))) - return 0; /* silently fail */ + if (!(start = UAM_LIST(type))) + return 0; /* silently fail */ - uam_attach(start, uam); - return 0; + uam_attach(start, uam); + return 0; } /* load all of the modules */ int auth_load(const char *path, const char *list) { - char name[MAXPATHLEN + 1], buf[MAXPATHLEN + 1], *p; - struct uam_mod *mod; - struct stat st; - int len; - - if (!path || !list || (len = strlen(path)) > sizeof(name) - 2) - return -1; - - strncpy(buf, list, sizeof(buf)); - if ((p = strtok(buf, ",")) == NULL) - return -1; - - strcpy(name, path); - if (name[len - 1] != '/') { - strcat(name, "/"); - len++; - } - - while (p) { - strncpy(name + len, p, sizeof(name) - len); - syslog(LOG_DEBUG, "uam: loading (%s)", name); - /* - if ((stat(name, &st) == 0) && (mod = uam_load(name, p))) { - */ - if (stat(name, &st) == 0) { - if ((mod = uam_load(name, p))) { - uam_attach(&uam_modules, mod); - syslog(LOG_INFO, "uam: %s loaded", p); - } else { - syslog(LOG_INFO, "uam: %s load failure",p); - } - } else { - syslog(LOG_INFO, "uam: uam not found (status=%d)", stat(name, &st)); + char name[MAXPATHLEN + 1], buf[MAXPATHLEN + 1], *p; + struct uam_mod *mod; + struct stat st; + int len; + + if (!path || !list || (len = strlen(path)) > sizeof(name) - 2) + return -1; + + strncpy(buf, list, sizeof(buf)); + if ((p = strtok(buf, ",")) == NULL) + return -1; + + strcpy(name, path); + if (name[len - 1] != '/') { + strcat(name, "/"); + len++; } - p = strtok(NULL, ","); - } - return 0; + while (p) { + strncpy(name + len, p, sizeof(name) - len); + syslog(LOG_DEBUG, "uam: loading (%s)", name); + /* + if ((stat(name, &st) == 0) && (mod = uam_load(name, p))) { + */ + if (stat(name, &st) == 0) { + if ((mod = uam_load(name, p))) { + uam_attach(&uam_modules, mod); + syslog(LOG_INFO, "uam: %s loaded", p); + } else { + syslog(LOG_INFO, "uam: %s load failure",p); + } + } else { + syslog(LOG_INFO, "uam: uam not found (status=%d)", stat(name, &st)); + } + p = strtok(NULL, ","); + } + + return 0; } /* get rid of all of the uams */ void auth_unload() { - struct uam_mod *mod, *prev, *start = &uam_modules; - - prev = start->uam_prev; - while ((mod = prev) != start) { - prev = prev->uam_prev; - uam_detach(mod); - uam_unload(mod); - } + struct uam_mod *mod, *prev, *start = &uam_modules; + + prev = start->uam_prev; + while ((mod = prev) != start) { + prev = prev->uam_prev; + uam_detach(mod); + uam_unload(mod); + } } diff --git a/etc/afpd/codepage.c b/etc/afpd/codepage.c index c8b7eb11..f04068a5 100644 --- a/etc/afpd/codepage.c +++ b/etc/afpd/codepage.c @@ -1,5 +1,5 @@ /* - * $Id: codepage.c,v 1.5 2001-06-20 18:33:04 rufustfirefly Exp $ + * $Id: codepage.c,v 1.5.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 2000 Adrian Sun * All Rights Reserved. See COPYRIGHT. @@ -60,42 +60,42 @@ /* search for stuff */ #if 0 static __inline__ unsigned char *codepage_find(struct codepage *page, - unsigned char *from) + unsigned char *from) { } #endif static int add_code(struct codepage *page, unsigned char *from, - unsigned char *to) + unsigned char *to) { #if 0 - union codepage_val *ptr; + union codepage_val *ptr; #endif /* 0 */ - if (page->quantum < 1) /* no quantum given. don't do anything */ - return 1; + if (page->quantum < 1) /* no quantum given. don't do anything */ + return 1; - if (page->quantum == 1) { - page->map[*from].value = *to; - return 0; - } + if (page->quantum == 1) { + page->map[*from].value = *to; + return 0; + } #if 0 - if (ptr = codepage_find(page->map, from)) { - - } else { - unsigned char *space; - ptr = map[*from].hash; - - space = (unsigned char *) malloc(sizeof(unsigned char)*quantum); - if (!ptr->from) { + if (ptr = codepage_find(page->map, from)) { + } else { + unsigned char *space; + ptr = map[*from].hash; + + space = (unsigned char *) malloc(sizeof(unsigned char)*quantum); + if (!ptr->from) { + } else { + } + + map[*from].hash } - - map[*from].hash - } #endif /* 0 */ - return 0; + return 0; } static struct codepage *init_codepage(const int quantum) @@ -104,12 +104,12 @@ static struct codepage *init_codepage(const int quantum) cp = (struct codepage *) malloc(sizeof(struct codepage)); if (!cp) - return NULL; + return NULL; if ((cp->map = (union codepage_val *) - calloc(MAPSIZE, sizeof(union codepage_val))) == NULL) { - free(cp); - return NULL; + calloc(MAPSIZE, sizeof(union codepage_val))) == NULL) { + free(cp); + return NULL; } cp->quantum = quantum; @@ -119,27 +119,27 @@ static struct codepage *init_codepage(const int quantum) static void free_codepage(struct codepage *cp) { - int i; - - if (!cp) - return; - - if (cp->map) { - if (cp->quantum > 1) { - /* deal with any linked lists that may exist */ - for (i = 0; i < MAPSIZE; i++) { - struct codepage_hash *ptr, *h; - - h = &cp->map[i].hash; /* we don't free this one */ - while ((ptr = h->prev) != h) { - CP_REMOVE(ptr); - free(ptr); - } - } + int i; + + if (!cp) + return; + + if (cp->map) { + if (cp->quantum > 1) { + /* deal with any linked lists that may exist */ + for (i = 0; i < MAPSIZE; i++) { + struct codepage_hash *ptr, *h; + + h = &cp->map[i].hash; /* we don't free this one */ + while ((ptr = h->prev) != h) { + CP_REMOVE(ptr); + free(ptr); + } + } + } + free(cp->map); } - free(cp->map); - } - free(cp); + free(cp); } @@ -149,28 +149,28 @@ static void free_codepage(struct codepage *cp) * for double-byte mappings, we just use the table as a hash lookup. * if we don't match, we don't convert. */ -int codepage_init(struct vol *vol, const int rules, - const int quantum) +int codepage_init(struct vol *vol, const int rules, + const int quantum) { - if ((rules & CODEPAGE_RULE_UTOM) && !vol->v_utompage) { - vol->v_utompage = init_codepage(quantum); - if (!vol->v_utompage) - goto err_utompage; - } - - if ((rules & CODEPAGE_RULE_MTOU) && !vol->v_mtoupage) { - vol->v_mtoupage = init_codepage(quantum); - if (!vol->v_mtoupage) { - goto err_mtoupage; + if ((rules & CODEPAGE_RULE_UTOM) && !vol->v_utompage) { + vol->v_utompage = init_codepage(quantum); + if (!vol->v_utompage) + goto err_utompage; } - } - if ((rules & CODEPAGE_RULE_BADU) && !vol->v_badumap) { - vol->v_badumap = init_codepage(quantum); - if (!vol->v_badumap) - goto err_mtoupage; - } - return 0; + if ((rules & CODEPAGE_RULE_MTOU) && !vol->v_mtoupage) { + vol->v_mtoupage = init_codepage(quantum); + if (!vol->v_mtoupage) { + goto err_mtoupage; + } + } + + if ((rules & CODEPAGE_RULE_BADU) && !vol->v_badumap) { + vol->v_badumap = init_codepage(quantum); + if (!vol->v_badumap) + goto err_mtoupage; + } + return 0; err_mtoupage: free_codepage(vol->v_mtoupage); @@ -184,109 +184,109 @@ err_utompage: void codepage_free(struct vol *vol) { - if (vol->v_utompage) { - free_codepage(vol->v_utompage); - vol->v_utompage = NULL; - } + if (vol->v_utompage) { + free_codepage(vol->v_utompage); + vol->v_utompage = NULL; + } - if (vol->v_mtoupage) { - free_codepage(vol->v_mtoupage); - vol->v_mtoupage = NULL; - } + if (vol->v_mtoupage) { + free_codepage(vol->v_mtoupage); + vol->v_mtoupage = NULL; + } - if (vol->v_badumap) { - free_codepage(vol->v_badumap); - vol->v_badumap = NULL; - } + if (vol->v_badumap) { + free_codepage(vol->v_badumap); + vol->v_badumap = NULL; + } } int codepage_read(struct vol *vol, const char *path) { - unsigned char buf[CODEPAGE_FILE_HEADER_SIZE], *cur; - u_int16_t id; - int fd, i, quantum, rules; - - if ((fd = open(path, O_RDONLY)) < 0) { - syslog(LOG_ERR, "%s: failed to open codepage", path); - return -1; - } - - /* Read the codepage file header. */ - if(read(fd, buf, sizeof(buf)) != sizeof(buf)) { - syslog( LOG_ERR, "%s: failed to read codepage header", path); - goto codepage_fail; - } - - /* Check the file id */ - cur = buf; - memcpy(&id, cur, sizeof(id)); - cur += sizeof(id); - id = ntohs(id); - if (id != CODEPAGE_FILE_ID) { - syslog( LOG_ERR, "%s: not a codepage", path); - goto codepage_fail; - } - - /* check the version number */ - if (*cur++ != CODEPAGE_FILE_VERSION) { - syslog( LOG_ERR, "%s: codepage version not supported", path); - goto codepage_fail; - } - - /* ignore namelen */ - cur++; - - /* find out the data quantum size. default to 1 if nothing's given. */ - quantum = *cur ? *cur : 1; - cur++; - - /* rules used in this file. */ - rules = *cur++; - - if (codepage_init(vol, rules, quantum) < 0) { - syslog( LOG_ERR, "%s: Unable to allocate memory", path); - goto codepage_fail; - } - - /* offset to data */ - - /* skip to the start of the data */ - memcpy(&id, cur , sizeof(id)); - id = ntohs(id); - lseek(fd, id, SEEK_SET); - - /* mtoupage is the the equivalent of samba's unix2dos. utompage is - * the equivalent of dos2unix. it's a little confusing due to a - * desire to match up with mtoupath and utompath. - * NOTE: we allow codepages to specify 7-bit mappings if they want. - */ - i = 1 + 2*quantum; - while (read(fd, buf, i) == i) { - if (*buf & CODEPAGE_RULE_MTOU) { - if (add_code(vol->v_mtoupage, buf + 1, buf + 1 + quantum) < 0) { - syslog(LOG_ERR, "unable to allocate memory for mtoupage"); - break; - } + unsigned char buf[CODEPAGE_FILE_HEADER_SIZE], *cur; + u_int16_t id; + int fd, i, quantum, rules; + + if ((fd = open(path, O_RDONLY)) < 0) { + syslog(LOG_ERR, "%s: failed to open codepage", path); + return -1; } - if (*buf & CODEPAGE_RULE_UTOM) { - if (add_code(vol->v_utompage, buf + 1 + quantum, buf + 1) < 0) { - syslog(LOG_ERR, "unable to allocate memory for utompage"); - break; - } + /* Read the codepage file header. */ + if(read(fd, buf, sizeof(buf)) != sizeof(buf)) { + syslog( LOG_ERR, "%s: failed to read codepage header", path); + goto codepage_fail; } - - /* we only look at the first character here. if we need to - * do so, we can always use the quantum to expand the - * available flags. */ - if (*buf & CODEPAGE_RULE_BADU) - vol->v_badumap->map[*(buf + 1)].value = *(buf + 1 + quantum); - } - close(fd); - return 0; + + /* Check the file id */ + cur = buf; + memcpy(&id, cur, sizeof(id)); + cur += sizeof(id); + id = ntohs(id); + if (id != CODEPAGE_FILE_ID) { + syslog( LOG_ERR, "%s: not a codepage", path); + goto codepage_fail; + } + + /* check the version number */ + if (*cur++ != CODEPAGE_FILE_VERSION) { + syslog( LOG_ERR, "%s: codepage version not supported", path); + goto codepage_fail; + } + + /* ignore namelen */ + cur++; + + /* find out the data quantum size. default to 1 if nothing's given. */ + quantum = *cur ? *cur : 1; + cur++; + + /* rules used in this file. */ + rules = *cur++; + + if (codepage_init(vol, rules, quantum) < 0) { + syslog( LOG_ERR, "%s: Unable to allocate memory", path); + goto codepage_fail; + } + + /* offset to data */ + + /* skip to the start of the data */ + memcpy(&id, cur , sizeof(id)); + id = ntohs(id); + lseek(fd, id, SEEK_SET); + + /* mtoupage is the the equivalent of samba's unix2dos. utompage is + * the equivalent of dos2unix. it's a little confusing due to a + * desire to match up with mtoupath and utompath. + * NOTE: we allow codepages to specify 7-bit mappings if they want. + */ + i = 1 + 2*quantum; + while (read(fd, buf, i) == i) { + if (*buf & CODEPAGE_RULE_MTOU) { + if (add_code(vol->v_mtoupage, buf + 1, buf + 1 + quantum) < 0) { + syslog(LOG_ERR, "unable to allocate memory for mtoupage"); + break; + } + } + + if (*buf & CODEPAGE_RULE_UTOM) { + if (add_code(vol->v_utompage, buf + 1 + quantum, buf + 1) < 0) { + syslog(LOG_ERR, "unable to allocate memory for utompage"); + break; + } + } + + /* we only look at the first character here. if we need to + * do so, we can always use the quantum to expand the + * available flags. */ + if (*buf & CODEPAGE_RULE_BADU) + vol->v_badumap->map[*(buf + 1)].value = *(buf + 1 + quantum); + } + close(fd); + return 0; codepage_fail: - close(fd); - return -1; + close(fd); + return -1; } diff --git a/etc/afpd/codepage.h b/etc/afpd/codepage.h index 598623a8..ed3b5820 100644 --- a/etc/afpd/codepage.h +++ b/etc/afpd/codepage.h @@ -1,11 +1,11 @@ /* - * $Id: codepage.h,v 1.2 2001-06-20 18:33:04 rufustfirefly Exp $ + * $Id: codepage.h,v 1.2.2.1 2001-12-03 05:01:04 jmarcus Exp $ */ #ifndef AFPD_CODEPAGE_H #define AFPD_CODEPAGE_H 1 -/* +/* * header of a codepage -- * file magic: 2 bytes * file version: 1 byte diff --git a/etc/afpd/desktop.c b/etc/afpd/desktop.c index 6e1a53f3..59961e6c 100644 --- a/etc/afpd/desktop.c +++ b/etc/afpd/desktop.c @@ -1,5 +1,5 @@ /* - * $Id: desktop.c,v 1.7 2001-09-21 17:39:22 jmarcus Exp $ + * $Id: desktop.c,v 1.7.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * See COPYRIGHT. */ @@ -42,9 +42,9 @@ #include "desktop.h" int afp_opendt(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol; u_int16_t vid; @@ -53,8 +53,8 @@ int afp_opendt(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof(vid)); if (( vol = getvolbyvid( vid )) == NULL ) { - *rbuflen = 0; - return( AFPERR_PARAM ); + *rbuflen = 0; + return( AFPERR_PARAM ); } memcpy( rbuf, &vid, sizeof(vid)); @@ -63,9 +63,9 @@ int afp_opendt(obj, ibuf, ibuflen, rbuf, rbuflen ) } int afp_closedt(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { *rbuflen = 0; return( AFP_OK ); @@ -74,44 +74,44 @@ int afp_closedt(obj, ibuf, ibuflen, rbuf, rbuflen ) struct savedt si = { { 0, 0, 0, 0 }, -1, 0 }; static int iconopen( vol, creator, flags, mode ) - struct vol *vol; - u_char creator[ 4 ]; +struct vol *vol; +u_char creator[ 4 ]; { char *dtf, *adt, *adts; if ( si.sdt_fd != -1 ) { - if ( memcmp( si.sdt_creator, creator, sizeof( CreatorType )) == 0 && - si.sdt_vid == vol->v_vid ) { - return 0; - } - close( si.sdt_fd ); - si.sdt_fd = -1; + if ( memcmp( si.sdt_creator, creator, sizeof( CreatorType )) == 0 && + si.sdt_vid == vol->v_vid ) { + return 0; + } + close( si.sdt_fd ); + si.sdt_fd = -1; } dtf = dtfile( vol, creator, ".icon" ); if (( si.sdt_fd = open( dtf, flags, ad_mode( dtf, mode ))) < 0 ) { - if ( errno == ENOENT && ( flags & O_CREAT )) { - if (( adts = strrchr( dtf, '/' )) == NULL ) { - return -1; - } - *adts = '\0'; - if (( adt = strrchr( dtf, '/' )) == NULL ) { - return -1; - } - *adt = '\0'; - (void) ad_mkdir( dtf, DIRBITS | 0777 ); - *adt = '/'; - (void) ad_mkdir( dtf, DIRBITS | 0777 ); - *adts = '/'; - - if (( si.sdt_fd = open( dtf, flags, ad_mode( dtf, mode ))) < 0 ) { - syslog( LOG_ERR, "iconopen: open %s: %s", dtf, strerror(errno) ); - return -1; - } - } else { - return -1; - } + if ( errno == ENOENT && ( flags & O_CREAT )) { + if (( adts = strrchr( dtf, '/' )) == NULL ) { + return -1; + } + *adts = '\0'; + if (( adt = strrchr( dtf, '/' )) == NULL ) { + return -1; + } + *adt = '\0'; + (void) ad_mkdir( dtf, DIRBITS | 0777 ); + *adt = '/'; + (void) ad_mkdir( dtf, DIRBITS | 0777 ); + *adts = '/'; + + if (( si.sdt_fd = open( dtf, flags, ad_mode( dtf, mode ))) < 0 ) { + syslog( LOG_ERR, "iconopen: open %s: %s", dtf, strerror(errno) ); + return -1; + } + } else { + return -1; + } } memcpy( si.sdt_creator, creator, sizeof( CreatorType )); @@ -121,9 +121,9 @@ static int iconopen( vol, creator, flags, mode ) } int afp_addicon(obj, ibuf, ibuflen, rbuf, rbuflen) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol; struct iovec iov[ 2 ]; @@ -139,41 +139,41 @@ int afp_addicon(obj, ibuf, ibuflen, rbuf, rbuflen) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - cc = AFPERR_PARAM; - goto addicon_err; + cc = AFPERR_PARAM; + goto addicon_err; } - + memcpy( fcreator, ibuf, sizeof( fcreator )); ibuf += sizeof( fcreator ); - + memcpy( &ftype, ibuf, sizeof( ftype )); ibuf += sizeof( ftype ); - + itype = (unsigned char) *ibuf; ibuf += 2; - + memcpy( &itag, ibuf, sizeof( itag )); ibuf += sizeof( itag ); - + memcpy( &bsize, ibuf, sizeof( bsize )); bsize = ntohs( bsize ); - + if ( si.sdt_fd != -1 ) { - (void)close( si.sdt_fd ); - si.sdt_fd = -1; + (void)close( si.sdt_fd ); + si.sdt_fd = -1; } if (iconopen( vol, fcreator, O_RDWR|O_CREAT, 0666 ) < 0) { - cc = AFPERR_NOITEM; - goto addicon_err; + cc = AFPERR_NOITEM; + goto addicon_err; } if (lseek( si.sdt_fd, (off_t) 0L, SEEK_SET ) < 0) { close(si.sdt_fd); - si.sdt_fd = -1; - syslog( LOG_ERR, "afp_addicon: lseek: %s", strerror(errno) ); - cc = AFPERR_PARAM; - goto addicon_err; + si.sdt_fd = -1; + syslog( LOG_ERR, "afp_addicon: lseek: %s", strerror(errno) ); + cc = AFPERR_PARAM; + goto addicon_err; } /* @@ -191,110 +191,110 @@ int afp_addicon(obj, ibuf, ibuflen, rbuf, rbuflen) memcpy( p, &bsize, sizeof( bsize )); bsize = ntohs( bsize ); while (( cc = read( si.sdt_fd, irh, sizeof( irh ))) > 0 ) { - memcpy( &rsize, irh + 10, sizeof( rsize )); - rsize = ntohs( rsize ); - /* - * Is this our set of headers? - */ - if ( memcmp( irh, imh, sizeof( irh ) - sizeof( u_short )) == 0 ) { - /* - * Is the size correct? - */ - if ( bsize != rsize ) - cc = AFPERR_ITYPE; - break; - } - - if ( lseek( si.sdt_fd, (off_t) rsize, SEEK_CUR ) < 0 ) { - syslog( LOG_ERR, "afp_addicon: lseek: %s", strerror(errno) ); - cc = AFPERR_PARAM; - } - } - + memcpy( &rsize, irh + 10, sizeof( rsize )); + rsize = ntohs( rsize ); + /* + * Is this our set of headers? + */ + if ( memcmp( irh, imh, sizeof( irh ) - sizeof( u_short )) == 0 ) { + /* + * Is the size correct? + */ + if ( bsize != rsize ) + cc = AFPERR_ITYPE; + break; + } + + if ( lseek( si.sdt_fd, (off_t) rsize, SEEK_CUR ) < 0 ) { + syslog( LOG_ERR, "afp_addicon: lseek: %s", strerror(errno) ); + cc = AFPERR_PARAM; + } + } + /* * Some error occurred, return. */ addicon_err: if ( cc < 0 ) { - syslog( LOG_ERR, "afp_addicon: %s", strerror(errno) ); - if (obj->proto == AFPPROTO_DSI) { - dsi_writeinit(obj->handle, rbuf, buflen); - dsi_writeflush(obj->handle); - } - return cc; + syslog( LOG_ERR, "afp_addicon: %s", strerror(errno) ); + if (obj->proto == AFPPROTO_DSI) { + dsi_writeinit(obj->handle, rbuf, buflen); + dsi_writeflush(obj->handle); + } + return cc; } switch (obj->proto) { #ifndef NO_DDP case AFPPROTO_ASP: - buflen = bsize; - if ((asp_wrtcont(obj->handle, rbuf, &buflen) < 0) || buflen != bsize) - return( AFPERR_PARAM ); - - if (obj->options.flags & OPTION_DEBUG) { - printf("(write) len: %d\n", buflen); - bprint(rbuf, buflen); - } - - /* - * We're at the end of the file, add the headers, etc. */ - if ( cc == 0 ) { - iov[ 0 ].iov_base = (caddr_t)imh; - iov[ 0 ].iov_len = sizeof( imh ); - iov[ 1 ].iov_base = rbuf; - iov[ 1 ].iov_len = bsize; - iovcnt = 2; - } - - /* - * We found an icon to replace. - */ - if ( cc > 0 ) { - iov[ 0 ].iov_base = rbuf; - iov[ 0 ].iov_len = bsize; - iovcnt = 1; - } - - if ( writev( si.sdt_fd, iov, iovcnt ) < 0 ) { - syslog( LOG_ERR, "afp_addicon: writev: %s", strerror(errno) ); - return( AFPERR_PARAM ); - } - break; + buflen = bsize; + if ((asp_wrtcont(obj->handle, rbuf, &buflen) < 0) || buflen != bsize) + return( AFPERR_PARAM ); + + if (obj->options.flags & OPTION_DEBUG) { + printf("(write) len: %d\n", buflen); + bprint(rbuf, buflen); + } + + /* + * We're at the end of the file, add the headers, etc. */ + if ( cc == 0 ) { + iov[ 0 ].iov_base = (caddr_t)imh; + iov[ 0 ].iov_len = sizeof( imh ); + iov[ 1 ].iov_base = rbuf; + iov[ 1 ].iov_len = bsize; + iovcnt = 2; + } + + /* + * We found an icon to replace. + */ + if ( cc > 0 ) { + iov[ 0 ].iov_base = rbuf; + iov[ 0 ].iov_len = bsize; + iovcnt = 1; + } + + if ( writev( si.sdt_fd, iov, iovcnt ) < 0 ) { + syslog( LOG_ERR, "afp_addicon: writev: %s", strerror(errno) ); + return( AFPERR_PARAM ); + } + break; #endif /* no afp/asp */ - case AFPPROTO_DSI: - { - DSI *dsi = obj->handle; - - iovcnt = dsi_writeinit(dsi, rbuf, buflen); - - /* add headers at end of file */ - if ((cc == 0) && (write(si.sdt_fd, imh, sizeof(imh)) < 0)) { - syslog(LOG_ERR, "afp_addicon: write: %s", strerror(errno)); - dsi_writeflush(dsi); - return AFPERR_PARAM; - } - - if ((cc = write(si.sdt_fd, rbuf, iovcnt)) < 0) { - syslog(LOG_ERR, "afp_addicon: write: %s", strerror(errno)); - dsi_writeflush(dsi); - return AFPERR_PARAM; - } - - while ((iovcnt = dsi_write(dsi, rbuf, buflen))) { - if ( obj->options.flags & OPTION_DEBUG ) { - printf("(write) command cont'd: %d\n", iovcnt); - bprint(rbuf, iovcnt); - } - - if ((cc = write(si.sdt_fd, rbuf, iovcnt)) < 0) { - syslog(LOG_ERR, "afp_addicon: write: %s", strerror(errno)); - dsi_writeflush(dsi); - return AFPERR_PARAM; - } - } - } - break; + case AFPPROTO_DSI: + { + DSI *dsi = obj->handle; + + iovcnt = dsi_writeinit(dsi, rbuf, buflen); + + /* add headers at end of file */ + if ((cc == 0) && (write(si.sdt_fd, imh, sizeof(imh)) < 0)) { + syslog(LOG_ERR, "afp_addicon: write: %s", strerror(errno)); + dsi_writeflush(dsi); + return AFPERR_PARAM; + } + + if ((cc = write(si.sdt_fd, rbuf, iovcnt)) < 0) { + syslog(LOG_ERR, "afp_addicon: write: %s", strerror(errno)); + dsi_writeflush(dsi); + return AFPERR_PARAM; + } + + while ((iovcnt = dsi_write(dsi, rbuf, buflen))) { + if ( obj->options.flags & OPTION_DEBUG ) { + printf("(write) command cont'd: %d\n", iovcnt); + bprint(rbuf, iovcnt); + } + + if ((cc = write(si.sdt_fd, rbuf, iovcnt)) < 0) { + syslog(LOG_ERR, "afp_addicon: write: %s", strerror(errno)); + dsi_writeflush(dsi); + return AFPERR_PARAM; + } + } + } + break; } close( si.sdt_fd ); @@ -307,44 +307,44 @@ u_char ucreator[] = { 'U', 'N', 'I', 'X' }; u_char utype[] = { 'T', 'E', 'X', 'T' }; short usize = 256; u_char uicon[] = { -0x1F, 0xFF, 0xFC, 0x00, 0x10, 0x00, 0x06, 0x00, -0x10, 0x00, 0x05, 0x00, 0x10, 0x00, 0x04, 0x80, -0x10, 0x00, 0x04, 0x40, 0x10, 0x00, 0x04, 0x20, -0x10, 0x00, 0x07, 0xF0, 0x10, 0x00, 0x00, 0x10, -0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, -0x10, 0x00, 0x00, 0x10, 0x10, 0x80, 0x02, 0x10, -0x11, 0x80, 0x03, 0x10, 0x12, 0x80, 0x02, 0x90, -0x12, 0x80, 0x02, 0x90, 0x14, 0x80, 0x02, 0x50, -0x14, 0x87, 0xC2, 0x50, 0x14, 0x58, 0x34, 0x50, -0x14, 0x20, 0x08, 0x50, 0x12, 0x16, 0xD0, 0x90, -0x11, 0x01, 0x01, 0x10, 0x12, 0x80, 0x02, 0x90, -0x12, 0x9C, 0x72, 0x90, 0x14, 0x22, 0x88, 0x50, -0x14, 0x41, 0x04, 0x50, 0x14, 0x49, 0x24, 0x50, -0x14, 0x55, 0x54, 0x50, 0x14, 0x5D, 0x74, 0x50, -0x14, 0x5D, 0x74, 0x50, 0x12, 0x49, 0x24, 0x90, -0x12, 0x22, 0x88, 0x90, 0x1F, 0xFF, 0xFF, 0xF0, -0x1F, 0xFF, 0xFC, 0x00, 0x1F, 0xFF, 0xFE, 0x00, -0x1F, 0xFF, 0xFF, 0x00, 0x1F, 0xFF, 0xFF, 0x80, -0x1F, 0xFF, 0xFF, 0xC0, 0x1F, 0xFF, 0xFF, 0xE0, -0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, -0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, -0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, -0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, -0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, -0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, -0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, -0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, -0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, -0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, -0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, -0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, -0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, + 0x1F, 0xFF, 0xFC, 0x00, 0x10, 0x00, 0x06, 0x00, + 0x10, 0x00, 0x05, 0x00, 0x10, 0x00, 0x04, 0x80, + 0x10, 0x00, 0x04, 0x40, 0x10, 0x00, 0x04, 0x20, + 0x10, 0x00, 0x07, 0xF0, 0x10, 0x00, 0x00, 0x10, + 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, + 0x10, 0x00, 0x00, 0x10, 0x10, 0x80, 0x02, 0x10, + 0x11, 0x80, 0x03, 0x10, 0x12, 0x80, 0x02, 0x90, + 0x12, 0x80, 0x02, 0x90, 0x14, 0x80, 0x02, 0x50, + 0x14, 0x87, 0xC2, 0x50, 0x14, 0x58, 0x34, 0x50, + 0x14, 0x20, 0x08, 0x50, 0x12, 0x16, 0xD0, 0x90, + 0x11, 0x01, 0x01, 0x10, 0x12, 0x80, 0x02, 0x90, + 0x12, 0x9C, 0x72, 0x90, 0x14, 0x22, 0x88, 0x50, + 0x14, 0x41, 0x04, 0x50, 0x14, 0x49, 0x24, 0x50, + 0x14, 0x55, 0x54, 0x50, 0x14, 0x5D, 0x74, 0x50, + 0x14, 0x5D, 0x74, 0x50, 0x12, 0x49, 0x24, 0x90, + 0x12, 0x22, 0x88, 0x90, 0x1F, 0xFF, 0xFF, 0xF0, + 0x1F, 0xFF, 0xFC, 0x00, 0x1F, 0xFF, 0xFE, 0x00, + 0x1F, 0xFF, 0xFF, 0x00, 0x1F, 0xFF, 0xFF, 0x80, + 0x1F, 0xFF, 0xFF, 0xC0, 0x1F, 0xFF, 0xFF, 0xE0, + 0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, + 0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, + 0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, + 0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, + 0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, + 0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, + 0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, + 0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, + 0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, + 0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, + 0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, + 0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, + 0x1F, 0xFF, 0xFF, 0xF0, 0x1F, 0xFF, 0xFF, 0xF0, }; int afp_geticoninfo(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol; u_char fcreator[ 4 ], ih[ 12 ]; @@ -356,7 +356,7 @@ int afp_geticoninfo(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memcpy( fcreator, ibuf, sizeof( fcreator )); @@ -365,60 +365,60 @@ int afp_geticoninfo(obj, ibuf, ibuflen, rbuf, rbuflen ) iindex = ntohs( iindex ); if ( memcmp( fcreator, ucreator, sizeof( ucreator )) == 0 ) { - if ( iindex > 1 ) { - return( AFPERR_NOITEM ); - } - memcpy( ih, utag, sizeof( utag )); - memcpy( ih + sizeof( utag ), utype, sizeof( utype )); - *( ih + sizeof( utag ) + sizeof( utype )) = 1; - *( ih + sizeof( utag ) + sizeof( utype ) + 1 ) = 0; - memcpy( ih + sizeof( utag ) + sizeof( utype ) + 2, &usize, - sizeof( usize )); - memcpy( rbuf, ih, sizeof( ih )); - *rbuflen = sizeof( ih ); - return( AFP_OK ); + if ( iindex > 1 ) { + return( AFPERR_NOITEM ); + } + memcpy( ih, utag, sizeof( utag )); + memcpy( ih + sizeof( utag ), utype, sizeof( utype )); + *( ih + sizeof( utag ) + sizeof( utype )) = 1; + *( ih + sizeof( utag ) + sizeof( utype ) + 1 ) = 0; + memcpy( ih + sizeof( utag ) + sizeof( utype ) + 2, &usize, + sizeof( usize )); + memcpy( rbuf, ih, sizeof( ih )); + *rbuflen = sizeof( ih ); + return( AFP_OK ); } if ( iconopen( vol, fcreator, O_RDONLY, 0 ) < 0) { - return( AFPERR_NOITEM ); + return( AFPERR_NOITEM ); } if ( iindex < si.sdt_index ) { - if ( lseek( si.sdt_fd, (off_t) 0L, SEEK_SET ) < 0 ) { - return( AFPERR_PARAM ); - } - si.sdt_index = 1; + if ( lseek( si.sdt_fd, (off_t) 0L, SEEK_SET ) < 0 ) { + return( AFPERR_PARAM ); + } + si.sdt_index = 1; } /* * Position to the correct spot. */ for (;;) { - if ( read( si.sdt_fd, ih, sizeof( ih )) != sizeof( ih )) { - close( si.sdt_fd ); - si.sdt_fd = -1; - return( AFPERR_NOITEM ); - } - memcpy( &bsize, ih + 10, sizeof( bsize )); - bsize = ntohs(bsize); - if ( lseek( si.sdt_fd, (off_t) bsize, SEEK_CUR ) < 0 ) { - syslog( LOG_ERR, "afp_iconinfo: lseek: %s", strerror(errno) ); - return( AFPERR_PARAM ); - } - if ( si.sdt_index == iindex ) { - memcpy( rbuf, ih, sizeof( ih )); - *rbuflen = sizeof( ih ); - return( AFP_OK ); - } - si.sdt_index++; + if ( read( si.sdt_fd, ih, sizeof( ih )) != sizeof( ih )) { + close( si.sdt_fd ); + si.sdt_fd = -1; + return( AFPERR_NOITEM ); + } + memcpy( &bsize, ih + 10, sizeof( bsize )); + bsize = ntohs(bsize); + if ( lseek( si.sdt_fd, (off_t) bsize, SEEK_CUR ) < 0 ) { + syslog( LOG_ERR, "afp_iconinfo: lseek: %s", strerror(errno) ); + return( AFPERR_PARAM ); + } + if ( si.sdt_index == iindex ) { + memcpy( rbuf, ih, sizeof( ih )); + *rbuflen = sizeof( ih ); + return( AFP_OK ); + } + si.sdt_index++; } } int afp_geticon(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol; off_t offset; @@ -433,7 +433,7 @@ int afp_geticon(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memcpy( fcreator, ibuf, sizeof( fcreator )); @@ -446,50 +446,50 @@ int afp_geticon(obj, ibuf, ibuflen, rbuf, rbuflen ) bsize = ntohs( bsize ); if ( memcmp( fcreator, ucreator, sizeof( ucreator )) == 0 && - memcmp( ftype, utype, sizeof( utype )) == 0 && - itype == 1 && - bsize <= usize ) { - memcpy( rbuf, uicon, bsize); - *rbuflen = bsize; - return( AFP_OK ); + memcmp( ftype, utype, sizeof( utype )) == 0 && + itype == 1 && + bsize <= usize ) { + memcpy( rbuf, uicon, bsize); + *rbuflen = bsize; + return( AFP_OK ); } if ( iconopen( vol, fcreator, O_RDONLY, 0 ) < 0) { - return( AFPERR_NOITEM ); + return( AFPERR_NOITEM ); } if ( lseek( si.sdt_fd, (off_t) 0L, SEEK_SET ) < 0 ) { - close(si.sdt_fd); - si.sdt_fd = -1; - syslog(LOG_ERR, "afp_geticon: lseek: %s", strerror(errno)); - return( AFPERR_PARAM ); + close(si.sdt_fd); + si.sdt_fd = -1; + syslog(LOG_ERR, "afp_geticon: lseek: %s", strerror(errno)); + return( AFPERR_PARAM ); } si.sdt_index = 1; offset = 0; while (( rc = read( si.sdt_fd, ih, sizeof( ih ))) > 0 ) { - si.sdt_index++; - offset += sizeof(ih); - if ( memcmp( ih + sizeof( int ), ftype, sizeof( ftype )) == 0 && - *(ih + sizeof( int ) + sizeof( ftype )) == itype ) { - break; - } - memcpy( &rsize, ih + 10, sizeof( rsize )); - rsize = ntohs( rsize ); - if ( lseek( si.sdt_fd, (off_t) rsize, SEEK_CUR ) < 0 ) { - syslog( LOG_ERR, "afp_geticon: lseek: %s", strerror(errno) ); - return( AFPERR_PARAM ); - } - offset += rsize; + si.sdt_index++; + offset += sizeof(ih); + if ( memcmp( ih + sizeof( int ), ftype, sizeof( ftype )) == 0 && + *(ih + sizeof( int ) + sizeof( ftype )) == itype ) { + break; + } + memcpy( &rsize, ih + 10, sizeof( rsize )); + rsize = ntohs( rsize ); + if ( lseek( si.sdt_fd, (off_t) rsize, SEEK_CUR ) < 0 ) { + syslog( LOG_ERR, "afp_geticon: lseek: %s", strerror(errno) ); + return( AFPERR_PARAM ); + } + offset += rsize; } if ( rc < 0 ) { syslog(LOG_ERR, "afp_geticon: read: %s", strerror(errno)); - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if ( rc == 0 ) { - return( AFPERR_NOITEM ); + return( AFPERR_NOITEM ); } memcpy( &rsize, ih + 10, sizeof( rsize )); @@ -498,70 +498,70 @@ int afp_geticon(obj, ibuf, ibuflen, rbuf, rbuflen ) rc = min( bsize, rsize ); if ((obj->proto == AFPPROTO_DSI) && (buflen < rc)) { - DSI *dsi = obj->handle; - struct stat st; - off_t size; - - size = (fstat(si.sdt_fd, &st) < 0) ? 0 : st.st_size; - if (size < rc + offset) { - return AFPERR_PARAM; - } - - if ((*rbuflen = dsi_readinit(dsi, rbuf, buflen, rc, AFP_OK)) < 0) - goto geticon_exit; - - /* do to the streaming nature, we have to exit if we encounter - * a problem. much confusion results otherwise. */ - while (*rbuflen > 0) { + DSI *dsi = obj->handle; + struct stat st; + off_t size; + + size = (fstat(si.sdt_fd, &st) < 0) ? 0 : st.st_size; + if (size < rc + offset) { + return AFPERR_PARAM; + } + + if ((*rbuflen = dsi_readinit(dsi, rbuf, buflen, rc, AFP_OK)) < 0) + goto geticon_exit; + + /* do to the streaming nature, we have to exit if we encounter + * a problem. much confusion results otherwise. */ + while (*rbuflen > 0) { #if defined(SENDFILE_FLAVOR_LINUX) || defined(SENDFILE_FLAVOR_BSD) - if (!obj->options.flags & OPTION_DEBUG) { + if (!obj->options.flags & OPTION_DEBUG) { #ifdef SENDFILE_FLAVOR_LINUX - if (sendfile(dsi->socket, si.sdt_fd, &offset, dsi->datasize) < 0) - goto geticon_exit; + if (sendfile(dsi->socket, si.sdt_fd, &offset, dsi->datasize) < 0) + goto geticon_exit; #endif /* SENDFILE_FLAVOR_LINUX */ - + #ifdef SENDFILE_FLAVOR_BSD - if (sendfile(si.sdt_fd, dsi->socket, offset, rc, NULL, NULL, 0) < 0) - goto geticon_exit; + if (sendfile(si.sdt_fd, dsi->socket, offset, rc, NULL, NULL, 0) < 0) + goto geticon_exit; #endif /* SENDFILE_FLAVOR_BSD */ - - goto geticon_done; - } + + goto geticon_done; + } #endif /* SENDFILE_FLAVOR_LINUX || SENDFILE_FLAVOR_BSD */ - buflen = read(si.sdt_fd, rbuf, *rbuflen); - if (buflen < 0) - goto geticon_exit; + buflen = read(si.sdt_fd, rbuf, *rbuflen); + if (buflen < 0) + goto geticon_exit; + + if (obj->options.flags & OPTION_DEBUG) { + printf( "(read) reply: %d, %d\n", buflen, dsi->clientID); + bprint(rbuf, buflen); + } - if (obj->options.flags & OPTION_DEBUG) { - printf( "(read) reply: %d, %d\n", buflen, dsi->clientID); - bprint(rbuf, buflen); - } - - /* dsi_read() also returns buffer size of next allocation */ - buflen = dsi_read(dsi, rbuf, buflen); /* send it off */ - if (buflen < 0) - goto geticon_exit; + /* dsi_read() also returns buffer size of next allocation */ + buflen = dsi_read(dsi, rbuf, buflen); /* send it off */ + if (buflen < 0) + goto geticon_exit; - *rbuflen = buflen; - } + *rbuflen = buflen; + } geticon_done: - dsi_readdone(dsi); - return AFP_OK; - + dsi_readdone(dsi); + return AFP_OK; + geticon_exit: - syslog(LOG_INFO, "afp_geticon: %s", strerror(errno)); - dsi_readdone(dsi); - obj->exit(1); - return AFP_OK; + syslog(LOG_INFO, "afp_geticon: %s", strerror(errno)); + dsi_readdone(dsi); + obj->exit(1); + return AFP_OK; } else { - if ( read( si.sdt_fd, rbuf, rc ) < rc ) { - return( AFPERR_PARAM ); - } - *rbuflen = rc; - return AFP_OK; + if ( read( si.sdt_fd, rbuf, rc ) < rc ) { + return( AFPERR_PARAM ); + } + *rbuflen = rc; + return AFP_OK; } } @@ -576,24 +576,24 @@ char *dtfile(const struct vol *vol, u_char creator[], char *ext ) strcpy( path, vol->v_path ); strcat( path, "/.AppleDesktop/" ); for ( p = path; *p != '\0'; p++ ) - ; + ; if ( !isprint( creator[ 0 ] ) || creator[ 0 ] == '/' ) { - *p++ = hexdig[ ( creator[ 0 ] & 0xf0 ) >> 4 ]; - *p++ = hexdig[ creator[ 0 ] & 0x0f ]; + *p++ = hexdig[ ( creator[ 0 ] & 0xf0 ) >> 4 ]; + *p++ = hexdig[ creator[ 0 ] & 0x0f ]; } else { - *p++ = creator[ 0 ]; + *p++ = creator[ 0 ]; } *p++ = '/'; for ( i = 0; i < sizeof( CreatorType ); i++ ) { - if ( !isprint( creator[ i ] ) || creator[ i ] == '/' ) { - *p++ = hexdig[ ( creator[ i ] & 0xf0 ) >> 4 ]; - *p++ = hexdig[ creator[ i ] & 0x0f ]; - } else { - *p++ = creator[ i ]; - } + if ( !isprint( creator[ i ] ) || creator[ i ] == '/' ) { + *p++ = hexdig[ ( creator[ i ] & 0xf0 ) >> 4 ]; + *p++ = hexdig[ creator[ i ] & 0x0f ]; + } else { + *p++ = creator[ i ]; + } } *p = '\0'; strcat( path, ext ); @@ -607,47 +607,47 @@ char *mtoupath(const struct vol *vol, char *mpath) unsigned char *m, *u; int i = 0; - if ( *mpath == '\0' ) { - return( "." ); + if ( mpath == NULL || *mpath == '\0' ) { + return( "." ); } m = mpath; u = upath; while ( *m != '\0' ) { /* handle case conversion first */ - if (vol->v_casefold & AFPVOL_MTOUUPPER) - *m = diatoupper( *m ); + if (vol->v_casefold & AFPVOL_MTOUUPPER) + *m = diatoupper( *m ); else if (vol->v_casefold & AFPVOL_MTOULOWER) - *m = diatolower( *m ); - - /* we have a code page. we only use the ascii range - * if we have map ascii specified. */ + *m = diatolower( *m ); + + /* we have a code page. we only use the ascii range + * if we have map ascii specified. */ #if 1 - if (vol->v_mtoupage && ((*m & 0x80) || - vol->v_flags & AFPVOL_MAPASCII)) { - *u = vol->v_mtoupage->map[*m].value; - } else + if (vol->v_mtoupage && ((*m & 0x80) || + vol->v_flags & AFPVOL_MAPASCII)) { + *u = vol->v_mtoupage->map[*m].value; + } else #endif /* 1 */ #if AD_VERSION == AD_VERSION1 - if ((((vol->v_flags & AFPVOL_NOHEX) == 0) && - (!isascii(*m) || *m == '/')) || - (((vol->v_flags & AFPVOL_USEDOTS) == 0) && - ( i == 0 && (*m == '.' )))) { + if ((((vol->v_flags & AFPVOL_NOHEX) == 0) && + (!isascii(*m) || *m == '/')) || + (((vol->v_flags & AFPVOL_USEDOTS) == 0) && + ( i == 0 && (*m == '.' )))) { #else /* AD_VERSION == AD_VERSION1 */ - if ((((vol->v_flags & AFPVOL_NOHEX) == 0) && - (!isprint(*m) || *m == '/')) || - (((vol->v_flags & AFPVOL_USEDOTS) == 0) && - ( i == 0 && (*m == '.' )))) { + if ((((vol->v_flags & AFPVOL_NOHEX) == 0) && + (!isprint(*m) || *m == '/')) || + (((vol->v_flags & AFPVOL_USEDOTS) == 0) && + ( i == 0 && (*m == '.' )))) { #endif /* AD_VERSION == AD_VERSION1 */ - /* do hex conversion. */ - *u++ = ':'; - *u++ = hexdig[ ( *m & 0xf0 ) >> 4 ]; - *u = hexdig[ *m & 0x0f ]; - } else - *u = *m; - u++; - i++; - m++; + /* do hex conversion. */ + *u++ = ':'; + *u++ = hexdig[ ( *m & 0xf0 ) >> 4 ]; + *u = hexdig[ *m & 0x0f ]; + } else + *u = *m; + u++; + i++; + m++; } *u = '\0'; @@ -670,37 +670,37 @@ char *utompath(const struct vol *vol, char *upath) /* we have a code page */ #if 1 if (vol->v_utompage && ((*u > 0x7F) || - (vol->v_flags & AFPVOL_MAPASCII))) { - *m = vol->v_utompage->map[*u].value; - } else + (vol->v_flags & AFPVOL_MAPASCII))) { + *m = vol->v_utompage->map[*u].value; + } else #endif /* 1 */ - if ( *u == ':' && *(u+1) != '\0' && islxdigit( *(u+1)) && - *(u+2) != '\0' && islxdigit( *(u+2))) { - ++u; - h = hextoint( *u ) << 4; - ++u; - h |= hextoint( *u ); - *m = h; - } else - *m = *u; - - /* handle case conversion */ + if ( *u == ':' && *(u+1) != '\0' && islxdigit( *(u+1)) && + *(u+2) != '\0' && islxdigit( *(u+2))) { + ++u; + h = hextoint( *u ) << 4; + ++u; + h |= hextoint( *u ); + *m = h; + } else + *m = *u; + + /* handle case conversion */ if (vol->v_casefold & AFPVOL_UTOMLOWER) - *m = diatolower( *m ); - else if (vol->v_casefold & AFPVOL_UTOMUPPER) - *m = diatoupper( *m ); + *m = diatolower( *m ); + else if (vol->v_casefold & AFPVOL_UTOMUPPER) + *m = diatoupper( *m ); - u++; - m++; + u++; + m++; } *m = '\0'; return( mpath ); } int afp_addcomment(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct adouble ad, *adp; struct vol *vol; @@ -717,46 +717,46 @@ int afp_addcomment(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memcpy( &did, ibuf, sizeof( did )); ibuf += sizeof( did ); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ((u_long)ibuf & 1 ) { - ibuf++; + ibuf++; } clen = (u_char)*ibuf++; clen = min( clen, 199 ); if ((*path == '\0') || !(of = of_findname(vol, curdir, path))) { - memset(&ad, 0, sizeof(ad)); - adp = &ad; + memset(&ad, 0, sizeof(ad)); + adp = &ad; } else - adp = of->of_ad; - if (ad_open( mtoupath( vol, path ), vol_noadouble(vol) | - (( *path == '\0' ) ? ADFLAGS_HF|ADFLAGS_DIR : ADFLAGS_HF), - O_RDWR|O_CREAT, 0666, adp) < 0 ) { - return( AFPERR_ACCESS ); + adp = of->of_ad; + if (ad_open( mtoupath( vol, path ), vol_noadouble(vol) | + (( *path == '\0' ) ? ADFLAGS_HF|ADFLAGS_DIR : ADFLAGS_HF), + O_RDWR|O_CREAT, 0666, adp) < 0 ) { + return( AFPERR_ACCESS ); } if ( ad_getoflags( adp, ADFLAGS_HF ) & O_CREAT ) { - if ( *path == '\0' ) { - name = curdir->d_name; - } else { - name = path; - } - ad_setentrylen( adp, ADEID_NAME, strlen( name )); - memcpy( ad_entry( adp, ADEID_NAME ), name, - ad_getentrylen( adp, ADEID_NAME )); + if ( *path == '\0' ) { + name = curdir->d_name; + } else { + name = path; + } + ad_setentrylen( adp, ADEID_NAME, strlen( name )); + memcpy( ad_entry( adp, ADEID_NAME ), name, + ad_getentrylen( adp, ADEID_NAME )); } ad_setentrylen( adp, ADEID_COMMENT, clen ); @@ -767,9 +767,9 @@ int afp_addcomment(obj, ibuf, ibuflen, rbuf, rbuflen ) } int afp_getcomment(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct adouble ad, *adp; struct vol *vol; @@ -785,51 +785,51 @@ int afp_getcomment(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memcpy( &did, ibuf, sizeof( did )); ibuf += sizeof( did ); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ((*path == '\0') || !(of = of_findname(vol, curdir, path))) { - memset(&ad, 0, sizeof(ad)); - adp = &ad; + memset(&ad, 0, sizeof(ad)); + adp = &ad; } else - adp = of->of_ad; - if ( ad_open( mtoupath( vol, path ), - (( *path == '\0' ) ? ADFLAGS_HF|ADFLAGS_DIR : ADFLAGS_HF), - O_RDONLY, 0666, adp) < 0 ) { - return( AFPERR_NOITEM ); + adp = of->of_ad; + if ( ad_open( mtoupath( vol, path ), + (( *path == '\0' ) ? ADFLAGS_HF|ADFLAGS_DIR : ADFLAGS_HF), + O_RDONLY, 0666, adp) < 0 ) { + return( AFPERR_NOITEM ); } /* * Make sure the AD file is not bogus. */ if ( ad_getentrylen( adp, ADEID_COMMENT ) < 0 || - ad_getentrylen( adp, ADEID_COMMENT ) > 199 ) { - ad_close( adp, ADFLAGS_HF ); - return( AFPERR_NOITEM ); + ad_getentrylen( adp, ADEID_COMMENT ) > 199 ) { + ad_close( adp, ADFLAGS_HF ); + return( AFPERR_NOITEM ); } *rbuf++ = ad_getentrylen( adp, ADEID_COMMENT ); - memcpy( rbuf, ad_entry( adp, ADEID_COMMENT ), - ad_getentrylen( adp, ADEID_COMMENT )); + memcpy( rbuf, ad_entry( adp, ADEID_COMMENT ), + ad_getentrylen( adp, ADEID_COMMENT )); *rbuflen = ad_getentrylen( adp, ADEID_COMMENT ) + 1; ad_close( adp, ADFLAGS_HF ); return( AFP_OK ); } int afp_rmvcomment(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct adouble ad, *adp; struct vol *vol; @@ -845,35 +845,35 @@ int afp_rmvcomment(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memcpy( &did, ibuf, sizeof( did )); ibuf += sizeof( did ); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ((*path == '\0') || !(of = of_findname(vol, curdir, path))) { - memset(&ad, 0, sizeof(ad)); - adp = &ad; + memset(&ad, 0, sizeof(ad)); + adp = &ad; } else - adp = of->of_ad; - if ( ad_open( mtoupath( vol, path ), - (( *path == '\0' ) ? ADFLAGS_HF|ADFLAGS_DIR : ADFLAGS_HF), - O_RDWR, 0, adp) < 0 ) { - switch ( errno ) { - case ENOENT : - return( AFPERR_NOITEM ); - case EACCES : - return( AFPERR_ACCESS ); - default : - return( AFPERR_PARAM ); - } + adp = of->of_ad; + if ( ad_open( mtoupath( vol, path ), + (( *path == '\0' ) ? ADFLAGS_HF|ADFLAGS_DIR : ADFLAGS_HF), + O_RDWR, 0, adp) < 0 ) { + switch ( errno ) { + case ENOENT : + return( AFPERR_NOITEM ); + case EACCES : + return( AFPERR_ACCESS ); + default : + return( AFPERR_PARAM ); + } } ad_setentrylen( adp, ADEID_COMMENT, 0 ); diff --git a/etc/afpd/directory.c b/etc/afpd/directory.c index 86f9b257..d7e7f4be 100644 --- a/etc/afpd/directory.c +++ b/etc/afpd/directory.c @@ -1,5 +1,5 @@ /* - * $Id: directory.c,v 1.19 2001-10-03 19:51:04 jmarcus Exp $ + * $Id: directory.c,v 1.19.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -66,9 +66,9 @@ struct dir *curdir; #define SENTINEL (&sentinel) static struct dir sentinel = { SENTINEL, SENTINEL, NULL, DIRTREE_COLOR_BLACK, - NULL, NULL, NULL, NULL, NULL, 0, 0, NULL }; + NULL, NULL, NULL, NULL, NULL, 0, 0, NULL }; static struct dir rootpar = { SENTINEL, SENTINEL, NULL, 0, - NULL, NULL, NULL, NULL, NULL, 0, 0, NULL }; + NULL, NULL, NULL, NULL, NULL, 0, 0, NULL }; /* (from IM: Toolbox Essentials) * dirFinderInfo (DInfo) fields: @@ -91,13 +91,13 @@ static struct dir rootpar = { SENTINEL, SENTINEL, NULL, 0, * redid did assignment for directories. now we use red-black trees. * how exciting. */ - struct dir * -dirsearch( vol, did ) - const struct vol *vol; - u_int32_t did; +struct dir * + dirsearch( vol, did ) + const struct vol *vol; +u_int32_t did; { struct dir *dir; - + /* check for 0 did */ if (!did) @@ -105,16 +105,16 @@ dirsearch( vol, did ) if ( did == DIRDID_ROOT_PARENT ) { if (!rootpar.d_did) - rootpar.d_did = DIRDID_ROOT_PARENT; - rootpar.d_child = vol->v_dir; - return( &rootpar ); + rootpar.d_did = DIRDID_ROOT_PARENT; + rootpar.d_child = vol->v_dir; + return( &rootpar ); } dir = vol->v_root; while ( dir != SENTINEL ) { - if (dir->d_did == did) - return dir->d_name ? dir : NULL; - dir = (dir->d_did > did) ? dir->d_left : dir->d_right; + if (dir->d_did == did) + return dir->d_name ? dir : NULL; + dir = (dir->d_did > did) ? dir->d_left : dir->d_right; } return NULL; } @@ -122,134 +122,134 @@ dirsearch( vol, did ) /* rotate the tree to the left */ static void dir_leftrotate(vol, dir) - struct vol *vol; - struct dir *dir; +struct vol *vol; +struct dir *dir; { struct dir *right = dir->d_right; /* whee. move the right's left tree into dir's right tree */ - dir->d_right = right->d_left; + dir->d_right = right->d_left; if (right->d_left != SENTINEL) - right->d_left->d_back = dir; + right->d_left->d_back = dir; if (right != SENTINEL) { - right->d_back = dir->d_back; - right->d_left = dir; + right->d_back = dir->d_back; + right->d_left = dir; } if (!dir->d_back) /* no parent. move the right tree to the top. */ - vol->v_root = right; + vol->v_root = right; else if (dir == dir->d_back->d_left) /* we were on the left */ - dir->d_back->d_left = right; + dir->d_back->d_left = right; else - dir->d_back->d_right = right; /* we were on the right */ - + dir->d_back->d_right = right; /* we were on the right */ + /* re-insert dir on the left tree */ if (dir != SENTINEL) - dir->d_back = right; + dir->d_back = right; } /* rotate the tree to the right */ static void dir_rightrotate(vol, dir) - struct vol *vol; - struct dir *dir; +struct vol *vol; +struct dir *dir; { struct dir *left = dir->d_left; /* whee. move the left's right tree into dir's left tree */ - dir->d_left = left->d_right; + dir->d_left = left->d_right; if (left->d_right != SENTINEL) - left->d_right->d_back = dir; + left->d_right->d_back = dir; if (left != SENTINEL) { - left->d_back = dir->d_back; - left->d_right = dir; + left->d_back = dir->d_back; + left->d_right = dir; } if (!dir->d_back) /* no parent. move the left tree to the top. */ - vol->v_root = left; + vol->v_root = left; else if (dir == dir->d_back->d_right) /* we were on the right */ - dir->d_back->d_right = left; + dir->d_back->d_right = left; else - dir->d_back->d_left = left; /* we were on the left */ - + dir->d_back->d_left = left; /* we were on the left */ + /* re-insert dir on the right tree */ if (dir != SENTINEL) - dir->d_back = left; + dir->d_back = left; } #if 0 /* recolor after a removal */ static struct dir *dir_rmrecolor(vol, dir) - struct vol *vol; - struct dir *dir; + struct vol *vol; +struct dir *dir; { - struct dir *leaf; - - while ((dir != vol->v_root) && (dir->d_color == DIRTREE_COLOR_BLACK)) { - /* are we on the left tree? */ - if (dir == dir->d_back->d_left) { - leaf = dir->d_back->d_right; /* get right side */ - if (leaf->d_color == DIRTREE_COLOR_RED) { - /* we're red. we need to change to black. */ - leaf->d_color = DIRTREE_COLOR_BLACK; - dir->d_back->d_color = DIRTREE_COLOR_RED; - dir_leftrotate(vol, dir->d_back); - leaf = dir->d_back->d_right; - } - - /* right leaf has black end nodes */ - if ((leaf->d_left->d_color == DIRTREE_COLOR_BLACK) && - (leaf->d_right->d_color = DIRTREE_COLOR_BLACK)) { - leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */ - dir = dir->d_back; /* ascend */ - } else { - if (leaf->d_right->d_color == DIRTREE_COLOR_BLACK) { - leaf->d_left->d_color = DIRTREE_COLOR_BLACK; - leaf->d_color = DIRTREE_COLOR_RED; - dir_rightrotate(vol, leaf); - leaf = dir->d_back->d_right; - } - leaf->d_color = dir->d_back->d_color; - dir->d_back->d_color = DIRTREE_COLOR_BLACK; - leaf->d_right->d_color = DIRTREE_COLOR_BLACK; - dir_leftrotate(vol, dir->d_back); - dir = vol->v_root; - } - } else { /* right tree */ - leaf = dir->d_back->d_left; /* left tree */ - if (leaf->d_color == DIRTREE_COLOR_RED) { - leaf->d_color = DIRTREE_COLOR_BLACK; - dir->d_back->d_color = DIRTREE_COLOR_RED; - dir_rightrotate(vol, dir->d_back); - leaf = dir->d_back->d_left; - } - - /* left leaf has black end nodes */ - if ((leaf->d_right->d_color == DIRTREE_COLOR_BLACK) && - (leaf->d_left->d_color = DIRTREE_COLOR_BLACK)) { - leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */ - dir = dir->d_back; /* ascend */ - } else { - if (leaf->d_left->d_color == DIRTREE_COLOR_BLACK) { - leaf->d_right->d_color = DIRTREE_COLOR_BLACK; - leaf->d_color = DIRTREE_COLOR_RED; - dir_leftrotate(vol, leaf); - leaf = dir->d_back->d_left; - } - leaf->d_color = dir->d_back->d_color; - dir->d_back->d_color = DIRTREE_COLOR_BLACK; - leaf->d_left->d_color = DIRTREE_COLOR_BLACK; - dir_rightrotate(vol, dir->d_back); - dir = vol->v_root; - } - } - } - dir->d_color = DIRTREE_COLOR_BLACK; - - return dir; + struct dir *leaf; + + while ((dir != vol->v_root) && (dir->d_color == DIRTREE_COLOR_BLACK)) { + /* are we on the left tree? */ + if (dir == dir->d_back->d_left) { + leaf = dir->d_back->d_right; /* get right side */ + if (leaf->d_color == DIRTREE_COLOR_RED) { + /* we're red. we need to change to black. */ + leaf->d_color = DIRTREE_COLOR_BLACK; + dir->d_back->d_color = DIRTREE_COLOR_RED; + dir_leftrotate(vol, dir->d_back); + leaf = dir->d_back->d_right; + } + + /* right leaf has black end nodes */ + if ((leaf->d_left->d_color == DIRTREE_COLOR_BLACK) && + (leaf->d_right->d_color = DIRTREE_COLOR_BLACK)) { + leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */ + dir = dir->d_back; /* ascend */ + } else { + if (leaf->d_right->d_color == DIRTREE_COLOR_BLACK) { + leaf->d_left->d_color = DIRTREE_COLOR_BLACK; + leaf->d_color = DIRTREE_COLOR_RED; + dir_rightrotate(vol, leaf); + leaf = dir->d_back->d_right; + } + leaf->d_color = dir->d_back->d_color; + dir->d_back->d_color = DIRTREE_COLOR_BLACK; + leaf->d_right->d_color = DIRTREE_COLOR_BLACK; + dir_leftrotate(vol, dir->d_back); + dir = vol->v_root; + } + } else { /* right tree */ + leaf = dir->d_back->d_left; /* left tree */ + if (leaf->d_color == DIRTREE_COLOR_RED) { + leaf->d_color = DIRTREE_COLOR_BLACK; + dir->d_back->d_color = DIRTREE_COLOR_RED; + dir_rightrotate(vol, dir->d_back); + leaf = dir->d_back->d_left; + } + + /* left leaf has black end nodes */ + if ((leaf->d_right->d_color == DIRTREE_COLOR_BLACK) && + (leaf->d_left->d_color = DIRTREE_COLOR_BLACK)) { + leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */ + dir = dir->d_back; /* ascend */ + } else { + if (leaf->d_left->d_color == DIRTREE_COLOR_BLACK) { + leaf->d_right->d_color = DIRTREE_COLOR_BLACK; + leaf->d_color = DIRTREE_COLOR_RED; + dir_leftrotate(vol, leaf); + leaf = dir->d_back->d_left; + } + leaf->d_color = dir->d_back->d_color; + dir->d_back->d_color = DIRTREE_COLOR_BLACK; + leaf->d_left->d_color = DIRTREE_COLOR_BLACK; + dir_rightrotate(vol, dir->d_back); + dir = vol->v_root; + } + } + } + dir->d_color = DIRTREE_COLOR_BLACK; + + return dir; } #endif /* 0 */ @@ -258,8 +258,8 @@ static struct dir *dir_rmrecolor(vol, dir) * different. actually, it has to worry about a bunch of things that * insertion doesn't care about. */ static void dir_remove( vol, dir ) - struct vol *vol; - struct dir *dir; +struct vol *vol; +struct dir *dir; { #ifdef REMOVE_NODES struct ofork *of, *last; @@ -269,7 +269,7 @@ static void dir_remove( vol, dir ) if (!dir || (dir == SENTINEL)) return; -/* i'm not sure if it really helps to delete stuff. */ + /* i'm not sure if it really helps to delete stuff. */ #ifndef REMOVE_NODES free(dir->d_name); dir->d_name = NULL; @@ -277,80 +277,80 @@ static void dir_remove( vol, dir ) /* go searching for a node with at most one child */ if ((dir->d_left == SENTINEL) || (dir->d_right == SENTINEL)) { - node = dir; + node = dir; } else { - node = dir->d_right; - while (node->d_left != SENTINEL) - node = node->d_left; + node = dir->d_right; + while (node->d_left != SENTINEL) + node = node->d_left; } - + /* get that child */ leaf = (node->d_left != SENTINEL) ? node->d_left : node->d_right; /* detach node */ leaf->d_back = node->d_back; if (!node->d_back) { - vol->v_root = leaf; + vol->v_root = leaf; } else if (node == node->d_back->d_left) { /* left tree */ - node->d_back->d_left = leaf; + node->d_back->d_left = leaf; } else { - node->d_back->d_right = leaf; + node->d_back->d_right = leaf; } /* we want to free node, but we also want to free the data in dir. - * currently, that's d_name and the directory traversal bits. - * we just copy the necessary bits and then fix up all the - * various pointers to the directory. needless to say, there are - * a bunch of places that store the directory struct. */ + * currently, that's d_name and the directory traversal bits. + * we just copy the necessary bits and then fix up all the + * various pointers to the directory. needless to say, there are + * a bunch of places that store the directory struct. */ if (node != dir) { - struct dir save, *tmp; - - memcpy(&save, dir, sizeof(save)); - memcpy(dir, node, sizeof(struct dir)); - - /* restore the red-black bits */ - dir->d_left = save.d_left; - dir->d_right = save.d_right; - dir->d_back = save.d_back; - dir->d_color = save.d_color; - - if (node == vol->v_dir) {/* we may need to fix up this pointer */ - vol->v_dir = dir; - rootpar.d_child = vol->v_dir; - } else { - /* if we aren't the root directory, we have parents and - * siblings to worry about */ - if (dir->d_parent->d_child == node) - dir->d_parent->d_child = dir; - dir->d_next->d_prev = dir; - dir->d_prev->d_next = dir; - } - - /* fix up children. */ - tmp = dir->d_child; - while (tmp) { - tmp->d_parent = dir; - tmp = (tmp == dir->d_child->d_prev) ? NULL : tmp->d_next; - } - - if (node == curdir) /* another pointer to fixup */ - curdir = dir; - - /* we also need to fix up oforks. bleah */ - if ((of = dir->d_ofork)) { - last = of->of_d_prev; - while (of) { - of->of_dir = dir; - of = (last == of) ? NULL : of->of_d_next; - } - } - - /* set the node's d_name */ - node->d_name = save.d_name; + struct dir save, *tmp; + + memcpy(&save, dir, sizeof(save)); + memcpy(dir, node, sizeof(struct dir)); + + /* restore the red-black bits */ + dir->d_left = save.d_left; + dir->d_right = save.d_right; + dir->d_back = save.d_back; + dir->d_color = save.d_color; + + if (node == vol->v_dir) {/* we may need to fix up this pointer */ + vol->v_dir = dir; + rootpar.d_child = vol->v_dir; + } else { + /* if we aren't the root directory, we have parents and + * siblings to worry about */ + if (dir->d_parent->d_child == node) + dir->d_parent->d_child = dir; + dir->d_next->d_prev = dir; + dir->d_prev->d_next = dir; + } + + /* fix up children. */ + tmp = dir->d_child; + while (tmp) { + tmp->d_parent = dir; + tmp = (tmp == dir->d_child->d_prev) ? NULL : tmp->d_next; + } + + if (node == curdir) /* another pointer to fixup */ + curdir = dir; + + /* we also need to fix up oforks. bleah */ + if ((of = dir->d_ofork)) { + last = of->of_d_prev; + while (of) { + of->of_dir = dir; + of = (last == of) ? NULL : of->of_d_next; + } + } + + /* set the node's d_name */ + node->d_name = save.d_name; } if (node->d_color == DIRTREE_COLOR_BLACK) - dir_rmrecolor(vol, leaf); + dir_rmrecolor(vol, leaf); free(node->d_name); free(node); #endif /* ! REMOVE_NODES */ @@ -358,28 +358,28 @@ static void dir_remove( vol, dir ) static struct dir *dir_insert(vol, dir) - const struct vol *vol; - struct dir *dir; + const struct vol *vol; +struct dir *dir; { struct dir *pdir; pdir = vol->v_root; while (pdir->d_did != dir->d_did ) { - if ( pdir->d_did > dir->d_did ) { - if ( pdir->d_left == SENTINEL ) { - pdir->d_left = dir; - dir->d_back = pdir; - return NULL; - } - pdir = pdir->d_left; - } else { - if ( pdir->d_right == SENTINEL ) { - pdir->d_right = dir; - dir->d_back = pdir; - return NULL; - } - pdir = pdir->d_right; - } + if ( pdir->d_did > dir->d_did ) { + if ( pdir->d_left == SENTINEL ) { + pdir->d_left = dir; + dir->d_back = pdir; + return NULL; + } + pdir = pdir->d_left; + } else { + if ( pdir->d_right == SENTINEL ) { + pdir->d_right = dir; + dir->d_back = pdir; + return NULL; + } + pdir = pdir->d_right; + } } return pdir; } @@ -391,29 +391,29 @@ static struct dir *dir_insert(vol, dir) */ static struct dir * -extenddir( vol, dir, path ) - struct vol *vol; - struct dir *dir; - char *path; + extenddir( vol, dir, path ) + struct vol *vol; +struct dir *dir; +char *path; { char *p; struct stat st; p = mtoupath(vol, path ); if ( stat( p, &st ) != 0 ) { - return( NULL ); + return( NULL ); } if (!S_ISDIR(st.st_mode)) { - return( NULL ); + return( NULL ); } if (( dir = adddir( vol, dir, path, strlen( path ), p, strlen(p), - &st)) == NULL ) { - return( NULL ); + &st)) == NULL ) { + return( NULL ); } if ( movecwd( vol, dir ) < 0 ) { - return( NULL ); + return( NULL ); } return( dir ); @@ -421,150 +421,150 @@ extenddir( vol, dir, path ) static int deletedir(char *dir) { - char path[MAXPATHLEN + 1]; - DIR *dp; - struct dirent *de; - struct stat st; - int len, err; - - if ((len = strlen(dir)) > sizeof(path)) - return AFPERR_PARAM; - - /* already gone */ - if ((dp = opendir(dir)) == NULL) - return AFP_OK; + char path[MAXPATHLEN + 1]; + DIR *dp; + struct dirent *de; + struct stat st; + int len, err; - strcpy(path, dir); - strcat(path, "/"); - len++; - while ((de = readdir(dp))) { - /* skip this and previous directory */ - if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) - continue; - - strncpy(path + len, de->d_name, sizeof(path) - len); - if (stat(path, &st) == 0) { - if (S_ISDIR(st.st_mode)) { - if ((err = deletedir(path)) < 0) { - closedir(dp); - return err; - } - } else if (unlink(path) < 0) { - switch (errno) { - case ENOENT : - continue; /* somebody went and deleted it behind our backs. */ - case EROFS: - err = AFPERR_VLOCK; - case EPERM: - case EACCES : - err = AFPERR_ACCESS; - default : - err = AFPERR_PARAM; - } - closedir(dp); - return err; - } - } - } - closedir(dp); - - /* okay. the directory is empty. delete it. note: we already got rid - of .AppleDouble. */ - if (rmdir(dir) < 0) { - switch ( errno ) { - case ENOENT : - break; - case ENOTEMPTY : /* should never happen */ - return( AFPERR_DIRNEMPT ); - case EPERM: - case EACCES : - return( AFPERR_ACCESS ); - case EROFS: - return AFPERR_VLOCK; - default : - return( AFPERR_PARAM ); + if ((len = strlen(dir)) > sizeof(path)) + return AFPERR_PARAM; + + /* already gone */ + if ((dp = opendir(dir)) == NULL) + return AFP_OK; + + strcpy(path, dir); + strcat(path, "/"); + len++; + while ((de = readdir(dp))) { + /* skip this and previous directory */ + if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) + continue; + + strncpy(path + len, de->d_name, sizeof(path) - len); + if (stat(path, &st) == 0) { + if (S_ISDIR(st.st_mode)) { + if ((err = deletedir(path)) < 0) { + closedir(dp); + return err; + } + } else if (unlink(path) < 0) { + switch (errno) { + case ENOENT : + continue; /* somebody went and deleted it behind our backs. */ + case EROFS: + err = AFPERR_VLOCK; + case EPERM: + case EACCES : + err = AFPERR_ACCESS; + default : + err = AFPERR_PARAM; + } + closedir(dp); + return err; + } + } + } + closedir(dp); + + /* okay. the directory is empty. delete it. note: we already got rid + of .AppleDouble. */ + if (rmdir(dir) < 0) { + switch ( errno ) { + case ENOENT : + break; + case ENOTEMPTY : /* should never happen */ + return( AFPERR_DIRNEMPT ); + case EPERM: + case EACCES : + return( AFPERR_ACCESS ); + case EROFS: + return AFPERR_VLOCK; + default : + return( AFPERR_PARAM ); + } } - } - return AFP_OK; + return AFP_OK; } /* do a recursive copy. */ static int copydir(char *src, char *dst, int noadouble) { - char spath[MAXPATHLEN + 1], dpath[MAXPATHLEN + 1]; - DIR *dp; - struct dirent *de; - struct stat st; - struct utimbuf ut; - int slen, dlen, err; - - /* doesn't exist or the path is too long. */ - if (((slen = strlen(src)) > sizeof(spath) - 2) || - ((dlen = strlen(dst)) > sizeof(dpath) - 2) || - ((dp = opendir(src)) == NULL)) - return AFPERR_PARAM; - - /* try to create the destination directory */ - if (ad_mkdir(dst, DIRBITS | 0777) < 0) { - closedir(dp); - switch ( errno ) { - case ENOENT : - return( AFPERR_NOOBJ ); - case EROFS : - return( AFPERR_VLOCK ); - case EPERM: - case EACCES : - return( AFPERR_ACCESS ); - case EEXIST : - return( AFPERR_EXIST ); - case ENOSPC : - case EDQUOT : - return( AFPERR_DFULL ); - default : - return( AFPERR_PARAM ); - } - } - - /* set things up to copy */ - strcpy(spath, src); - strcat(spath, "/"); - slen++; - strcpy(dpath, dst); - strcat(dpath, "/"); - dlen++; - err = AFP_OK; - while ((de = readdir(dp))) { - /* skip this and previous directory */ - if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) - continue; - - strncpy(spath + slen, de->d_name, sizeof(spath) - slen); - if (stat(spath, &st) == 0) { - strncpy(dpath + dlen, de->d_name, sizeof(dpath) - dlen); - - if (S_ISDIR(st.st_mode)) { - if ((err = copydir(spath, dpath, noadouble)) < 0) - goto copydir_done; - } else if ((err = copyfile(spath, dpath, NULL, noadouble)) < 0) { - goto copydir_done; - - } else { - /* keep the same time stamp. */ - ut.actime = ut.modtime = st.st_mtime; - utime(dpath, &ut); - } - } - } - - /* keep the same time stamp. */ - if (stat(src, &st) == 0) { - ut.actime = ut.modtime = st.st_mtime; - utime(dst, &ut); - } + char spath[MAXPATHLEN + 1], dpath[MAXPATHLEN + 1]; + DIR *dp; + struct dirent *de; + struct stat st; + struct utimbuf ut; + int slen, dlen, err; + + /* doesn't exist or the path is too long. */ + if (((slen = strlen(src)) > sizeof(spath) - 2) || + ((dlen = strlen(dst)) > sizeof(dpath) - 2) || + ((dp = opendir(src)) == NULL)) + return AFPERR_PARAM; + + /* try to create the destination directory */ + if (ad_mkdir(dst, DIRBITS | 0777) < 0) { + closedir(dp); + switch ( errno ) { + case ENOENT : + return( AFPERR_NOOBJ ); + case EROFS : + return( AFPERR_VLOCK ); + case EPERM: + case EACCES : + return( AFPERR_ACCESS ); + case EEXIST : + return( AFPERR_EXIST ); + case ENOSPC : + case EDQUOT : + return( AFPERR_DFULL ); + default : + return( AFPERR_PARAM ); + } + } + + /* set things up to copy */ + strcpy(spath, src); + strcat(spath, "/"); + slen++; + strcpy(dpath, dst); + strcat(dpath, "/"); + dlen++; + err = AFP_OK; + while ((de = readdir(dp))) { + /* skip this and previous directory */ + if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) + continue; + + strncpy(spath + slen, de->d_name, sizeof(spath) - slen); + if (stat(spath, &st) == 0) { + strncpy(dpath + dlen, de->d_name, sizeof(dpath) - dlen); + + if (S_ISDIR(st.st_mode)) { + if ((err = copydir(spath, dpath, noadouble)) < 0) + goto copydir_done; + } else if ((err = copyfile(spath, dpath, NULL, noadouble)) < 0) { + goto copydir_done; + + } else { + /* keep the same time stamp. */ + ut.actime = ut.modtime = st.st_mtime; + utime(dpath, &ut); + } + } + } + + /* keep the same time stamp. */ + if (stat(src, &st) == 0) { + ut.actime = ut.modtime = st.st_mtime; + utime(dst, &ut); + } copydir_done: - closedir(dp); - return err; + closedir(dp); + return err; } @@ -572,57 +572,57 @@ copydir_done: /* NOTE: we start off with at least one node (the root directory). */ struct dir *dirinsert( vol, dir ) - struct vol *vol; - struct dir *dir; + struct vol *vol; +struct dir *dir; { struct dir *node; if ((node = dir_insert(vol, dir))) - return node; + return node; /* recolor the tree. the current node is red. */ dir->d_color = DIRTREE_COLOR_RED; /* parent of this node has to be black. if the parent node * is red, then we have a grandparent. */ - while ((dir != vol->v_root) && - (dir->d_back->d_color == DIRTREE_COLOR_RED)) { - /* are we on the left tree? */ - if (dir->d_back == dir->d_back->d_back->d_left) { - node = dir->d_back->d_back->d_right; /* get the right node */ - if (node->d_color == DIRTREE_COLOR_RED) { - /* we're red. we need to change to black. */ - dir->d_back->d_color = DIRTREE_COLOR_BLACK; - node->d_color = DIRTREE_COLOR_BLACK; - dir->d_back->d_back->d_color = DIRTREE_COLOR_RED; - dir = dir->d_back->d_back; /* finished. go up. */ - } else { - if (dir == dir->d_back->d_right) { - dir = dir->d_back; - dir_leftrotate(vol, dir); - } - dir->d_back->d_color = DIRTREE_COLOR_BLACK; - dir->d_back->d_back->d_color = DIRTREE_COLOR_RED; - dir_rightrotate(vol, dir->d_back->d_back); - } - } else { - node = dir->d_back->d_back->d_left; - if (node->d_color == DIRTREE_COLOR_RED) { - /* we're red. we need to change to black. */ - dir->d_back->d_color = DIRTREE_COLOR_BLACK; - node->d_color = DIRTREE_COLOR_BLACK; - dir->d_back->d_back->d_color = DIRTREE_COLOR_RED; - dir = dir->d_back->d_back; /* finished. ascend */ - } else { - if (dir == dir->d_back->d_left) { - dir = dir->d_back; - dir_rightrotate(vol, dir); - } - dir->d_back->d_color = DIRTREE_COLOR_BLACK; - dir->d_back->d_back->d_color = DIRTREE_COLOR_RED; - dir_leftrotate(vol, dir->d_back->d_back); - } - } + while ((dir != vol->v_root) && + (dir->d_back->d_color == DIRTREE_COLOR_RED)) { + /* are we on the left tree? */ + if (dir->d_back == dir->d_back->d_back->d_left) { + node = dir->d_back->d_back->d_right; /* get the right node */ + if (node->d_color == DIRTREE_COLOR_RED) { + /* we're red. we need to change to black. */ + dir->d_back->d_color = DIRTREE_COLOR_BLACK; + node->d_color = DIRTREE_COLOR_BLACK; + dir->d_back->d_back->d_color = DIRTREE_COLOR_RED; + dir = dir->d_back->d_back; /* finished. go up. */ + } else { + if (dir == dir->d_back->d_right) { + dir = dir->d_back; + dir_leftrotate(vol, dir); + } + dir->d_back->d_color = DIRTREE_COLOR_BLACK; + dir->d_back->d_back->d_color = DIRTREE_COLOR_RED; + dir_rightrotate(vol, dir->d_back->d_back); + } + } else { + node = dir->d_back->d_back->d_left; + if (node->d_color == DIRTREE_COLOR_RED) { + /* we're red. we need to change to black. */ + dir->d_back->d_color = DIRTREE_COLOR_BLACK; + node->d_color = DIRTREE_COLOR_BLACK; + dir->d_back->d_back->d_color = DIRTREE_COLOR_RED; + dir = dir->d_back->d_back; /* finished. ascend */ + } else { + if (dir == dir->d_back->d_left) { + dir = dir->d_back; + dir_rightrotate(vol, dir); + } + dir->d_back->d_color = DIRTREE_COLOR_BLACK; + dir->d_back->d_back->d_color = DIRTREE_COLOR_RED; + dir_leftrotate(vol, dir->d_back->d_back); + } + } } vol->v_root->d_color = DIRTREE_COLOR_BLACK; @@ -632,50 +632,50 @@ struct dir *dirinsert( vol, dir ) /* free everything down. we don't bother to recolor as this is only * called to free the entire tree */ void dirfree( dir ) - struct dir *dir; +struct dir *dir; { if (!dir || (dir == SENTINEL)) - return; + return; if ( dir->d_left != SENTINEL ) { - dirfree( dir->d_left ); + dirfree( dir->d_left ); } if ( dir->d_right != SENTINEL ) { - dirfree( dir->d_right ); + dirfree( dir->d_right ); } if (dir != SENTINEL) { - free( dir->d_name ); - free( dir ); + free( dir->d_name ); + free( dir ); } } struct dir *dirnew(const int len) { - struct dir *dir; - - dir = (struct dir *) calloc(1, sizeof( struct dir )); - if (!dir) - return NULL; - - if ((dir->d_name = (char *) malloc(sizeof(char)*len)) == NULL) { - free(dir); - return NULL; - } - - dir->d_left = dir->d_right = SENTINEL; - dir->d_next = dir->d_prev = dir; - return dir; + struct dir *dir; + + dir = (struct dir *) calloc(1, sizeof( struct dir )); + if (!dir) + return NULL; + + if ((dir->d_name = (char *) malloc(sizeof(char)*len)) == NULL) { + free(dir); + return NULL; + } + + dir->d_left = dir->d_right = SENTINEL; + dir->d_next = dir->d_prev = dir; + return dir; } /* XXX: this needs to be changed to handle path types */ - char * +char * cname( vol, dir, cpath ) - const struct vol *vol; - struct dir *dir; - char **cpath; +const struct vol *vol; +struct dir *dir; +char **cpath; { struct dir *cdir; static char path[ MAXPATHLEN + 1]; @@ -685,95 +685,95 @@ cname( vol, dir, cpath ) data = *cpath; if ( *data++ != 2 ) { /* path type */ - return( NULL ); + return( NULL ); } len = (unsigned char) *data++; *cpath += len + 2; *path = '\0'; for ( ;; ) { - if ( len == 0 ) { - if ( !extend && movecwd( vol, dir ) < 0 ) { - return( NULL ); - } - return( path ); - } - - if ( *data == '\0' ) { - data++; - len--; - } - - while ( *data == '\0' && len > 0 ) { - if ( dir->d_parent == NULL ) { - return( NULL ); - } - dir = dir->d_parent; - data++; - len--; - } - - /* would this be faster with strlen + strncpy? */ - p = path; - while ( *data != '\0' && len > 0 ) { - *p++ = *data++; - len--; - } - - /* short cut bits by chopping off a trailing \0. this also - makes the traversal happy w/ filenames at the end of the - cname. */ - if (len == 1) - len--; + if ( len == 0 ) { + if ( !extend && movecwd( vol, dir ) < 0 ) { + return( NULL ); + } + return( path ); + } + + if ( *data == '\0' ) { + data++; + len--; + } + + while ( *data == '\0' && len > 0 ) { + if ( dir->d_parent == NULL ) { + return( NULL ); + } + dir = dir->d_parent; + data++; + len--; + } + + /* would this be faster with strlen + strncpy? */ + p = path; + while ( *data != '\0' && len > 0 ) { + *p++ = *data++; + len--; + } + + /* short cut bits by chopping off a trailing \0. this also + makes the traversal happy w/ filenames at the end of the + cname. */ + if (len == 1) + len--; #ifdef notdef - /* - * Dung Nguyen - * - * AFPD cannot handle paths with "::" if the "::" notation is - * not at the beginning of the path. The following path will not - * be interpreted correctly: - * - * :a:b:::c: (directory c at the same level as directory a) */ - if ( len > 0 ) { - data++; - len--; - } + /* + * Dung Nguyen + * + * AFPD cannot handle paths with "::" if the "::" notation is + * not at the beginning of the path. The following path will not + * be interpreted correctly: + * + * :a:b:::c: (directory c at the same level as directory a) */ + if ( len > 0 ) { + data++; + len--; + } #endif /* notdef */ - *p = '\0'; - - if ( p != path ) { /* we got something */ - if ( !extend ) { - cdir = dir->d_child; - while (cdir) { - if ( strcasecmp( cdir->d_name, path ) == 0 ) { - break; - } - cdir = (cdir == dir->d_child->d_prev) ? NULL : - cdir->d_next; - } - if ( cdir == NULL ) { - ++extend; - if ( movecwd( vol, dir ) < 0 ) { - return( NULL ); - } - cdir = extenddir( vol, dir, path ); - } - - } else { - cdir = extenddir( vol, dir, path ); - } - - if ( cdir == NULL ) { - if ( len > 0 ) { - return( NULL ); - } - - } else { - dir = cdir; - *path = '\0'; - } - } + *p = '\0'; + + if ( p != path ) { /* we got something */ + if ( !extend ) { + cdir = dir->d_child; + while (cdir) { + if ( strcasecmp( cdir->d_name, path ) == 0 ) { + break; + } + cdir = (cdir == dir->d_child->d_prev) ? NULL : + cdir->d_next; + } + if ( cdir == NULL ) { + ++extend; + if ( movecwd( vol, dir ) < 0 ) { + return( NULL ); + } + cdir = extenddir( vol, dir, path ); + } + + } else { + cdir = extenddir( vol, dir, path ); + } + + if ( cdir == NULL ) { + if ( len > 0 ) { + return( NULL ); + } + + } else { + dir = cdir; + *path = '\0'; + } + } } } @@ -781,8 +781,8 @@ cname( vol, dir, cpath ) * Move curdir to dir, with a possible chdir() */ int movecwd( vol, dir) - const struct vol *vol; - struct dir *dir; +const struct vol *vol; +struct dir *dir; { char path[MAXPATHLEN + 1]; struct dir *d; @@ -790,39 +790,39 @@ int movecwd( vol, dir) int n; if ( dir == curdir ) { - return( 0 ); + return( 0 ); } if ( dir->d_did == DIRDID_ROOT_PARENT) { - return( -1 ); + return( -1 ); } p = path + sizeof(path) - 1; *p-- = '\0'; *p = '.'; for ( d = dir; d->d_parent != NULL && d != curdir; d = d->d_parent ) { - *--p = '/'; - u = mtoupath(vol, d->d_name ); - n = strlen( u ); - p -= n; - strncpy( p, u, n ); + *--p = '/'; + u = mtoupath(vol, d->d_name ); + n = strlen( u ); + p -= n; + strncpy( p, u, n ); } if ( d != curdir ) { - *--p = '/'; - n = strlen( vol->v_path ); - p -= n; - strncpy( p, vol->v_path, n ); + *--p = '/'; + n = strlen( vol->v_path ); + p -= n; + strncpy( p, vol->v_path, n ); } if ( chdir( p ) < 0 ) { - return( -1 ); + return( -1 ); } curdir = dir; return( 0 ); } int getdirparams(const struct vol *vol, - u_int16_t bitmap, - char *upath, struct dir *dir, struct stat *st, - char *buf, int *buflen ) + u_int16_t bitmap, + char *upath, struct dir *dir, struct stat *st, + char *buf, int *buflen ) { struct maccess ma; struct adouble ad; @@ -844,192 +844,192 @@ int getdirparams(const struct vol *vol, set_uidgid ( vol ); #endif /* FORCE_UIDGID */ - if ( ad_open( upath, ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY, - DIRBITS | 0777, &ad) < 0 ) { - isad = 0; - } + if ( ad_open( upath, ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY, + DIRBITS | 0777, &ad) < 0 ) { + isad = 0; + } data = buf; while ( bitmap != 0 ) { - while (( bitmap & 1 ) == 0 ) { - bitmap = bitmap>>1; - bit++; - } - - switch ( bit ) { - case DIRPBIT_ATTR : - if ( isad ) { - ad_getattr(&ad, &ashort); - } else if (*upath == '.' && strcmp(upath, ".") && - strcmp(upath, "..")) { - ashort = htons(ATTRBIT_INVISIBLE); - } else - ashort = 0; - memcpy( data, &ashort, sizeof( ashort )); - data += sizeof( ashort ); - break; - - case DIRPBIT_PDID : - if ( dir->d_did == DIRDID_ROOT) { - aint = DIRDID_ROOT_PARENT; - } else if (dir->d_did == DIRDID_ROOT_PARENT) { - aint = 0; - } else { - aint = dir->d_parent->d_did; - } - memcpy( data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case DIRPBIT_CDATE : - if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0)) - aint = AD_DATE_FROM_UNIX(st->st_mtime); - memcpy( data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case DIRPBIT_MDATE : - aint = AD_DATE_FROM_UNIX(st->st_mtime); - memcpy( data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case DIRPBIT_BDATE : - if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0)) - aint = AD_DATE_START; - memcpy( data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case DIRPBIT_FINFO : - if ( isad ) { - memcpy( data, ad_entry( &ad, ADEID_FINDERI ), 32 ); - } else { /* no appledouble */ - memset( data, 0, 32 ); - /* set default view -- this also gets done in ad_open() */ - ashort = htons(FINDERINFO_CLOSEDVIEW); - memcpy(data + FINDERINFO_FRVIEWOFF, &ashort, sizeof(ashort)); - - /* dot files are by default invisible */ - if (*upath == '.' && strcmp(upath, ".") && - strcmp(upath, "..")) { - ashort = htons(FINDERINFO_INVISIBLE); - memcpy(data + FINDERINFO_FRFLAGOFF, - &ashort, sizeof(ashort)); - } - } - data += 32; - break; - - case DIRPBIT_LNAME : - if (dir->d_name) /* root of parent can have a null name */ - nameoff = data; - else - memset(data, 0, sizeof(u_int16_t)); - data += sizeof( u_int16_t ); - break; - - case DIRPBIT_SNAME : - memset(data, 0, sizeof(u_int16_t)); - data += sizeof( u_int16_t ); - break; - - case DIRPBIT_DID : - memcpy( data, &dir->d_did, sizeof( aint )); - data += sizeof( aint ); - break; - - case DIRPBIT_OFFCNT : - ashort = 0; - /* this needs to handle current directory access rights */ - if ((dp = opendir( upath ))) { - while (( de = readdir( dp )) != NULL ) { - if (!strcmp(de->d_name, "..") || !strcmp(de->d_name, ".")) - continue; - - if (!validupath(vol, de->d_name)) - continue; - - /* check for vetoed filenames */ - if (veto_file(vol->v_veto, de->d_name)) - continue; - - /* now check against too long a filename */ - if (strlen(utompath(vol, de->d_name)) > MACFILELEN) - continue; - - ashort++; - } - closedir( dp ); - } - ashort = htons( ashort ); - memcpy( data, &ashort, sizeof( ashort )); - data += sizeof( ashort ); - break; - - case DIRPBIT_UID : - aint = htonl(st->st_uid); - memcpy( data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case DIRPBIT_GID : - aint = htonl(st->st_gid); - memcpy( data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case DIRPBIT_ACCESS : - utommode( st, &ma ); + while (( bitmap & 1 ) == 0 ) { + bitmap = bitmap>>1; + bit++; + } + + switch ( bit ) { + case DIRPBIT_ATTR : + if ( isad ) { + ad_getattr(&ad, &ashort); + } else if (*upath == '.' && strcmp(upath, ".") && + strcmp(upath, "..")) { + ashort = htons(ATTRBIT_INVISIBLE); + } else + ashort = 0; + memcpy( data, &ashort, sizeof( ashort )); + data += sizeof( ashort ); + break; + + case DIRPBIT_PDID : + if ( dir->d_did == DIRDID_ROOT) { + aint = DIRDID_ROOT_PARENT; + } else if (dir->d_did == DIRDID_ROOT_PARENT) { + aint = 0; + } else { + aint = dir->d_parent->d_did; + } + memcpy( data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case DIRPBIT_CDATE : + if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0)) + aint = AD_DATE_FROM_UNIX(st->st_mtime); + memcpy( data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case DIRPBIT_MDATE : + aint = AD_DATE_FROM_UNIX(st->st_mtime); + memcpy( data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case DIRPBIT_BDATE : + if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0)) + aint = AD_DATE_START; + memcpy( data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case DIRPBIT_FINFO : + if ( isad ) { + memcpy( data, ad_entry( &ad, ADEID_FINDERI ), 32 ); + } else { /* no appledouble */ + memset( data, 0, 32 ); + /* set default view -- this also gets done in ad_open() */ + ashort = htons(FINDERINFO_CLOSEDVIEW); + memcpy(data + FINDERINFO_FRVIEWOFF, &ashort, sizeof(ashort)); + + /* dot files are by default invisible */ + if (*upath == '.' && strcmp(upath, ".") && + strcmp(upath, "..")) { + ashort = htons(FINDERINFO_INVISIBLE); + memcpy(data + FINDERINFO_FRFLAGOFF, + &ashort, sizeof(ashort)); + } + } + data += 32; + break; + + case DIRPBIT_LNAME : + if (dir->d_name) /* root of parent can have a null name */ + nameoff = data; + else + memset(data, 0, sizeof(u_int16_t)); + data += sizeof( u_int16_t ); + break; + + case DIRPBIT_SNAME : + memset(data, 0, sizeof(u_int16_t)); + data += sizeof( u_int16_t ); + break; + + case DIRPBIT_DID : + memcpy( data, &dir->d_did, sizeof( aint )); + data += sizeof( aint ); + break; + + case DIRPBIT_OFFCNT : + ashort = 0; + /* this needs to handle current directory access rights */ + if ((dp = opendir( upath ))) { + while (( de = readdir( dp )) != NULL ) { + if (!strcmp(de->d_name, "..") || !strcmp(de->d_name, ".")) + continue; + + if (!validupath(vol, de->d_name)) + continue; + + /* check for vetoed filenames */ + if (veto_file(vol->v_veto, de->d_name)) + continue; + + /* now check against too long a filename */ + if (strlen(utompath(vol, de->d_name)) > MACFILELEN) + continue; + + ashort++; + } + closedir( dp ); + } + ashort = htons( ashort ); + memcpy( data, &ashort, sizeof( ashort )); + data += sizeof( ashort ); + break; + + case DIRPBIT_UID : + aint = htonl(st->st_uid); + memcpy( data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case DIRPBIT_GID : + aint = htonl(st->st_gid); + memcpy( data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case DIRPBIT_ACCESS : + utommode( st, &ma ); #ifndef SENDFILE_FLAVOR_LINUX /* ignore this section if it's linux */ #ifdef HAVE_ACCESS - accessmode( upath, &ma, dir ); + accessmode( upath, &ma, dir ); #endif /* HAVE_ACCESS */ #endif /* SENDFILE_FLAVOR_LINUX */ #ifdef AFS /* If only AFS defined, access() works only for AFS filesystems */ - afsmode( upath, &ma, dir ); + afsmode( upath, &ma, dir ); #endif /* AFS */ - *data++ = ma.ma_user; - *data++ = ma.ma_world; - *data++ = ma.ma_group; - *data++ = ma.ma_owner; - break; - - /* Client has requested the ProDOS information block. - Just pass back the same basic block for all - directories. */ - case DIRPBIT_PDINFO : /* ProDOS Info Block */ - *data++ = 0x0f; - *data++ = 0; - ashort = htons( 0x0200 ); - memcpy( data, &ashort, sizeof( ashort )); - data += sizeof( ashort ); - memset( data, 0, sizeof( ashort )); - data += sizeof( ashort ); - break; - - default : - if ( isad ) { - ad_close( &ad, ADFLAGS_HF ); - } + *data++ = ma.ma_user; + *data++ = ma.ma_world; + *data++ = ma.ma_group; + *data++ = ma.ma_owner; + break; + + /* Client has requested the ProDOS information block. + Just pass back the same basic block for all + directories. */ + case DIRPBIT_PDINFO : /* ProDOS Info Block */ + *data++ = 0x0f; + *data++ = 0; + ashort = htons( 0x0200 ); + memcpy( data, &ashort, sizeof( ashort )); + data += sizeof( ashort ); + memset( data, 0, sizeof( ashort )); + data += sizeof( ashort ); + break; + + default : + if ( isad ) { + ad_close( &ad, ADFLAGS_HF ); + } #ifdef FORCE_UIDGID restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_BITMAP ); - } - bitmap = bitmap>>1; - bit++; + return( AFPERR_BITMAP ); + } + bitmap = bitmap>>1; + bit++; } if ( nameoff ) { ashort = htons( data - buf ); - memcpy( nameoff, &ashort, sizeof( ashort )); + memcpy( nameoff, &ashort, sizeof( ashort )); + + if ((aint = strlen( dir->d_name )) > MACFILELEN) + aint = MACFILELEN; - if ((aint = strlen( dir->d_name )) > MACFILELEN) - aint = MACFILELEN; - - *data++ = aint; - memcpy( data, dir->d_name, aint ); - data += aint; + *data++ = aint; + memcpy( data, dir->d_name, aint ); + data += aint; } if ( isad ) { ad_close( &ad, ADFLAGS_HF ); @@ -1039,9 +1039,9 @@ int getdirparams(const struct vol *vol, } int afp_setdirparams(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol; struct dir *dir; @@ -1056,7 +1056,7 @@ int afp_setdirparams(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (vol->v_flags & AFPVOL_RO) @@ -1066,7 +1066,7 @@ int afp_setdirparams(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( int ); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } memcpy( &bitmap, ibuf, sizeof( bitmap )); @@ -1074,24 +1074,24 @@ int afp_setdirparams(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( bitmap ); if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } /* * If ibuf is odd, make it even. */ if ((u_long)ibuf & 1 ) { - ibuf++; + ibuf++; } if (( rc = setdirparams(vol, path, bitmap, ibuf )) == AFP_OK ) { - setvoltime(obj, vol ); + setvoltime(obj, vol ); } return( rc ); } int setdirparams(const struct vol *vol, - char *path, u_int16_t bitmap, char *buf ) + char *path, u_int16_t bitmap, char *buf ) { struct maccess ma; struct adouble ad; @@ -1111,273 +1111,273 @@ int setdirparams(const struct vol *vol, #ifdef FORCE_UIDGID save_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - if (ad_open( upath, vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR, - O_RDWR|O_CREAT, 0666, &ad) < 0) { - /* - * Check to see what we're trying to set. If it's anything - * but ACCESS, UID, or GID, give an error. If it's any of those - * three, we don't need the ad to be open, so just continue. - * - * note: we also don't need to worry about mdate. also, be quiet - * if we're using the noadouble option. - */ - if (!vol_noadouble(vol) && (bitmap & - ~((1<d_name )); - memcpy( ad_entry( &ad, ADEID_NAME ), curdir->d_name, - ad_getentrylen( &ad, ADEID_NAME )); - } + /* + * Check to see if a create was necessary. If it was, we'll want + * to set our name, etc. + */ + if ( ad_getoflags( &ad, ADFLAGS_HF ) & O_CREAT ) { + ad_setentrylen( &ad, ADEID_NAME, strlen( curdir->d_name )); + memcpy( ad_entry( &ad, ADEID_NAME ), curdir->d_name, + ad_getentrylen( &ad, ADEID_NAME )); + } } while ( bitmap != 0 ) { - while (( bitmap & 1 ) == 0 ) { - bitmap = bitmap>>1; - bit++; - } - - switch( bit ) { - case DIRPBIT_ATTR : - if (isad) { - memcpy( &ashort, buf, sizeof( ashort )); - ad_getattr(&ad, &bshort); - if ( ntohs( ashort ) & ATTRBIT_SETCLR ) { - bshort |= htons( ntohs( ashort ) & ~ATTRBIT_SETCLR ); - } else { - bshort &= ~ashort; - } - ad_setattr(&ad, bshort); - } - buf += sizeof( ashort ); - break; - - case DIRPBIT_CDATE : - if (isad) { - memcpy(&aint, buf, sizeof(aint)); - ad_setdate(&ad, AD_DATE_CREATE, aint); - } - buf += sizeof( aint ); - break; - - case DIRPBIT_MDATE : - memcpy(&aint, buf, sizeof(aint)); - if (isad) - ad_setdate(&ad, AD_DATE_MODIFY, aint); - ut.actime = ut.modtime = AD_DATE_TO_UNIX(aint); - utime(upath, &ut); - buf += sizeof( aint ); - break; - - case DIRPBIT_BDATE : - if (isad) { - memcpy(&aint, buf, sizeof(aint)); - ad_setdate(&ad, AD_DATE_BACKUP, aint); - } - buf += sizeof( aint ); - break; - - case DIRPBIT_FINFO : - /* - * Alright, we admit it, this is *really* sick! - * The 4 bytes that we don't copy, when we're dealing - * with the root of a volume, are the directory's - * location information. This eliminates that annoying - * behavior one sees when mounting above another mount - * point. - */ - if (isad) { - if ( curdir->d_did == DIRDID_ROOT ) { - memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 10 ); - memcpy( ad_entry( &ad, ADEID_FINDERI ) + 14, buf + 14, 18 ); - } else { - memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 32 ); - } - } - buf += 32; - break; - - case DIRPBIT_UID : /* What kind of loser mounts as root? */ - memcpy( &aint, buf, sizeof(aint)); - buf += sizeof( aint ); - if ( (curdir->d_did == DIRDID_ROOT) && - (setdeskowner( ntohl(aint), -1 ) < 0)) { - switch ( errno ) { - case EPERM : - case EACCES : - err = AFPERR_ACCESS; - goto setdirparam_done; - break; - case EROFS : - err = AFPERR_VLOCK; - goto setdirparam_done; - break; - default : - syslog( LOG_ERR, "setdirparam: setdeskowner: %s", - strerror(errno) ); - if (!isad) { - err = AFPERR_PARAM; - goto setdirparam_done; - } - break; - } - } - if ( setdirowner( ntohl(aint), -1, vol_noadouble(vol) ) < 0 ) { - switch ( errno ) { - case EPERM : - case EACCES : - err = AFPERR_ACCESS; - goto setdirparam_done; - break; - case EROFS : - err = AFPERR_VLOCK; - goto setdirparam_done; - break; - default : - syslog( LOG_ERR, "setdirparam: setdirowner: %s", - strerror(errno) ); - break; - } - } - break; - case DIRPBIT_GID : - memcpy( &aint, buf, sizeof( aint )); - buf += sizeof( aint ); - if (curdir->d_did == DIRDID_ROOT) - setdeskowner( -1, ntohl(aint) ); + while (( bitmap & 1 ) == 0 ) { + bitmap = bitmap>>1; + bit++; + } + + switch( bit ) { + case DIRPBIT_ATTR : + if (isad) { + memcpy( &ashort, buf, sizeof( ashort )); + ad_getattr(&ad, &bshort); + if ( ntohs( ashort ) & ATTRBIT_SETCLR ) { + bshort |= htons( ntohs( ashort ) & ~ATTRBIT_SETCLR ); + } else { + bshort &= ~ashort; + } + ad_setattr(&ad, bshort); + } + buf += sizeof( ashort ); + break; + + case DIRPBIT_CDATE : + if (isad) { + memcpy(&aint, buf, sizeof(aint)); + ad_setdate(&ad, AD_DATE_CREATE, aint); + } + buf += sizeof( aint ); + break; + + case DIRPBIT_MDATE : + memcpy(&aint, buf, sizeof(aint)); + if (isad) + ad_setdate(&ad, AD_DATE_MODIFY, aint); + ut.actime = ut.modtime = AD_DATE_TO_UNIX(aint); + utime(upath, &ut); + buf += sizeof( aint ); + break; + + case DIRPBIT_BDATE : + if (isad) { + memcpy(&aint, buf, sizeof(aint)); + ad_setdate(&ad, AD_DATE_BACKUP, aint); + } + buf += sizeof( aint ); + break; + + case DIRPBIT_FINFO : + /* + * Alright, we admit it, this is *really* sick! + * The 4 bytes that we don't copy, when we're dealing + * with the root of a volume, are the directory's + * location information. This eliminates that annoying + * behavior one sees when mounting above another mount + * point. + */ + if (isad) { + if ( curdir->d_did == DIRDID_ROOT ) { + memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 10 ); + memcpy( ad_entry( &ad, ADEID_FINDERI ) + 14, buf + 14, 18 ); + } else { + memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 32 ); + } + } + buf += 32; + break; + + case DIRPBIT_UID : /* What kind of loser mounts as root? */ + memcpy( &aint, buf, sizeof(aint)); + buf += sizeof( aint ); + if ( (curdir->d_did == DIRDID_ROOT) && + (setdeskowner( ntohl(aint), -1 ) < 0)) { + switch ( errno ) { + case EPERM : + case EACCES : + err = AFPERR_ACCESS; + goto setdirparam_done; + break; + case EROFS : + err = AFPERR_VLOCK; + goto setdirparam_done; + break; + default : + syslog( LOG_ERR, "setdirparam: setdeskowner: %s", + strerror(errno) ); + if (!isad) { + err = AFPERR_PARAM; + goto setdirparam_done; + } + break; + } + } + if ( setdirowner( ntohl(aint), -1, vol_noadouble(vol) ) < 0 ) { + switch ( errno ) { + case EPERM : + case EACCES : + err = AFPERR_ACCESS; + goto setdirparam_done; + break; + case EROFS : + err = AFPERR_VLOCK; + goto setdirparam_done; + break; + default : + syslog( LOG_ERR, "setdirparam: setdirowner: %s", + strerror(errno) ); + break; + } + } + break; + case DIRPBIT_GID : + memcpy( &aint, buf, sizeof( aint )); + buf += sizeof( aint ); + if (curdir->d_did == DIRDID_ROOT) + setdeskowner( -1, ntohl(aint) ); #if 0 /* don't error if we can't set the desktop owner. */ - switch ( errno ) { - case EPERM : - case EACCES : - err = AFPERR_ACCESS; - goto setdirparam_done; - break; - case EROFS : - err = AFPERR_VLOCK; - goto setdirparam_done; - break; - default : - syslog( LOG_ERR, "setdirparam: setdeskowner: %m" ); - if (!isad) { - err = AFPERR_PARAM; - goto setdirparam_done; - } - break; - } + switch ( errno ) { + case EPERM : + case EACCES : + err = AFPERR_ACCESS; + goto setdirparam_done; + break; + case EROFS : + err = AFPERR_VLOCK; + goto setdirparam_done; + break; + default : + syslog( LOG_ERR, "setdirparam: setdeskowner: %m" ); + if (!isad) { + err = AFPERR_PARAM; + goto setdirparam_done; + } + break; + } #endif /* 0 */ - if ( setdirowner( -1, ntohl(aint), vol_noadouble(vol) ) < 0 ) { - switch ( errno ) { - case EPERM : - case EACCES : - err = AFPERR_ACCESS; - goto setdirparam_done; - break; - case EROFS : - err = AFPERR_VLOCK; - goto setdirparam_done; - break; - default : - syslog( LOG_ERR, "setdirparam: setdirowner: %s", - strerror(errno) ); - break; - } - } - break; - - case DIRPBIT_ACCESS : - ma.ma_user = *buf++; - ma.ma_world = *buf++; - ma.ma_group = *buf++; - ma.ma_owner = *buf++; - - if (curdir->d_did == DIRDID_ROOT) - setdeskmode(mtoumode( &ma )); + if ( setdirowner( -1, ntohl(aint), vol_noadouble(vol) ) < 0 ) { + switch ( errno ) { + case EPERM : + case EACCES : + err = AFPERR_ACCESS; + goto setdirparam_done; + break; + case EROFS : + err = AFPERR_VLOCK; + goto setdirparam_done; + break; + default : + syslog( LOG_ERR, "setdirparam: setdirowner: %s", + strerror(errno) ); + break; + } + } + break; + + case DIRPBIT_ACCESS : + ma.ma_user = *buf++; + ma.ma_world = *buf++; + ma.ma_group = *buf++; + ma.ma_owner = *buf++; + + if (curdir->d_did == DIRDID_ROOT) + setdeskmode(mtoumode( &ma )); #if 0 /* don't error if we can't set the desktop mode */ - switch ( errno ) { - case EPERM : - case EACCES : - err = AFPERR_ACCESS; - goto setdirparam_done; - case EROFS : - err = AFPERR_VLOCK; - goto setdirparam_done; - default : - syslog( LOG_ERR, "setdirparam: setdeskmode: %s", - strerror(errno) ); - break; - err = AFPERR_PARAM; - goto setdirparam_done; - } - } + switch ( errno ) { + case EPERM : + case EACCES : + err = AFPERR_ACCESS; + goto setdirparam_done; + case EROFS : + err = AFPERR_VLOCK; + goto setdirparam_done; + default : + syslog( LOG_ERR, "setdirparam: setdeskmode: %s", + strerror(errno) ); + break; + err = AFPERR_PARAM; + goto setdirparam_done; + } + } #endif /* 0 */ - if ( setdirmode( mtoumode( &ma ), vol_noadouble(vol), - (vol->v_flags & AFPVOL_DROPBOX)) < 0 ) { - switch ( errno ) { - case EPERM : - case EACCES : - err = AFPERR_ACCESS; - goto setdirparam_done; - case EROFS : - err = AFPERR_VLOCK; - goto setdirparam_done; - default : - syslog( LOG_ERR, "setdirparam: setdirmode: %s", - strerror(errno) ); - err = AFPERR_PARAM; - goto setdirparam_done; - } - } - break; - - /* Ignore what the client thinks we should do to the - ProDOS information block. Skip over the data and - report nothing amiss. */ - case DIRPBIT_PDINFO : - buf += 6; - break; - - default : - err = AFPERR_BITMAP; - goto setdirparam_done; - break; - } - - bitmap = bitmap>>1; - bit++; + if ( setdirmode( mtoumode( &ma ), vol_noadouble(vol), + (vol->v_flags & AFPVOL_DROPBOX)) < 0 ) { + switch ( errno ) { + case EPERM : + case EACCES : + err = AFPERR_ACCESS; + goto setdirparam_done; + case EROFS : + err = AFPERR_VLOCK; + goto setdirparam_done; + default : + syslog( LOG_ERR, "setdirparam: setdirmode: %s", + strerror(errno) ); + err = AFPERR_PARAM; + goto setdirparam_done; + } + } + break; + + /* Ignore what the client thinks we should do to the + ProDOS information block. Skip over the data and + report nothing amiss. */ + case DIRPBIT_PDINFO : + buf += 6; + break; + + default : + err = AFPERR_BITMAP; + goto setdirparam_done; + break; } + bitmap = bitmap>>1; + bit++; +} + setdirparam_done: - if ( isad ) { - ad_flush( &ad, ADFLAGS_HF ); - ad_close( &ad, ADFLAGS_HF ); - } +if ( isad ) { + ad_flush( &ad, ADFLAGS_HF ); + ad_close( &ad, ADFLAGS_HF ); +} #ifdef FORCE_UIDGID - restore_uidgid ( &uidgid ); +restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return err; +return err; } int afp_createdir(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct adouble ad; struct stat st; @@ -1398,7 +1398,7 @@ int afp_createdir(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (vol->v_flags & AFPVOL_RO) @@ -1407,32 +1407,32 @@ int afp_createdir(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &did, ibuf, sizeof( did )); ibuf += sizeof( did ); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if (( path = cname( vol, dir, &ibuf )) == NULL ) { - switch( errno ) { - case EACCES: - return( AFPERR_ACCESS ); - case EEXIST: - return( AFPERR_EXIST ); - default: - return( AFPERR_NOOBJ ); - } + switch( errno ) { + case EACCES: + return( AFPERR_ACCESS ); + case EEXIST: + return( AFPERR_EXIST ); + default: + return( AFPERR_NOOBJ ); + } } /* check for illegal bits */ - if ((vol->v_flags & AFPVOL_MSWINDOWS) && - strpbrk(path, MSWINDOWS_BADCHARS)) + if ((vol->v_flags & AFPVOL_MSWINDOWS) && + strpbrk(path, MSWINDOWS_BADCHARS)) return AFPERR_PARAM; upath = mtoupath(vol, path); if ((vol->v_flags & AFPVOL_NOHEX) && strchr(upath, '/')) - return AFPERR_PARAM; + return AFPERR_PARAM; if (!validupath(vol, upath)) - return AFPERR_EXIST; + return AFPERR_EXIST; /* check for vetoed filenames */ if (veto_file(vol->v_veto, upath)) @@ -1447,59 +1447,59 @@ int afp_createdir(obj, ibuf, ibuflen, rbuf, rbuflen ) #ifdef FORCE_UIDGID restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - switch ( errno ) { - case ENOENT : - return( AFPERR_NOOBJ ); - case EROFS : - return( AFPERR_VLOCK ); - case EACCES : - return( AFPERR_ACCESS ); - case EEXIST : - return( AFPERR_EXIST ); - case ENOSPC : - case EDQUOT : - return( AFPERR_DFULL ); - default : - return( AFPERR_PARAM ); - } + switch ( errno ) { + case ENOENT : + return( AFPERR_NOOBJ ); + case EROFS : + return( AFPERR_VLOCK ); + case EACCES : + return( AFPERR_ACCESS ); + case EEXIST : + return( AFPERR_EXIST ); + case ENOSPC : + case EDQUOT : + return( AFPERR_DFULL ); + default : + return( AFPERR_PARAM ); + } } if (stat(upath, &st) < 0) { #ifdef FORCE_UIDGID - restore_uidgid ( &uidgid ); + restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return AFPERR_MISC; - } + return AFPERR_MISC; + } if ((dir = adddir( vol, curdir, path, strlen( path ), upath, - strlen(upath), &st)) == NULL) { + strlen(upath), &st)) == NULL) { #ifdef FORCE_UIDGID - restore_uidgid ( &uidgid ); + restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return AFPERR_MISC; - } + return AFPERR_MISC; + } if ( movecwd( vol, dir ) < 0 ) { #ifdef FORCE_UIDGID - restore_uidgid ( &uidgid ); + restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memset(&ad, 0, sizeof(ad)); if (ad_open( "", vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR, - O_RDWR|O_CREAT, 0666, &ad ) < 0) { - if (vol_noadouble(vol)) - goto createdir_done; + O_RDWR|O_CREAT, 0666, &ad ) < 0) { + if (vol_noadouble(vol)) + goto createdir_done; #ifdef FORCE_UIDGID - restore_uidgid ( &uidgid ); + restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_ACCESS ); + return( AFPERR_ACCESS ); } - + ad_setentrylen( &ad, ADEID_NAME, strlen( path )); - memcpy( ad_entry( &ad, ADEID_NAME ), path, - ad_getentrylen( &ad, ADEID_NAME )); + memcpy( ad_entry( &ad, ADEID_NAME ), path, + ad_getentrylen( &ad, ADEID_NAME )); ad_flush( &ad, ADFLAGS_HF ); ad_close( &ad, ADFLAGS_HF ); @@ -1515,9 +1515,9 @@ createdir_done: int renamedir(src, dst, dir, newparent, newname, noadouble) - char *src, *dst, *newname; - struct dir *dir, *newparent; - const int noadouble; +char *src, *dst, *newname; +struct dir *dir, *newparent; +const int noadouble; { struct adouble ad; struct dir *parent; @@ -1526,45 +1526,45 @@ int renamedir(src, dst, dir, newparent, newname, noadouble) /* existence check moved to afp_moveandrename */ if ( rename( src, dst ) < 0 ) { - switch ( errno ) { - case ENOENT : - return( AFPERR_NOOBJ ); - case EACCES : - return( AFPERR_ACCESS ); - case EROFS: - return AFPERR_VLOCK; - case EINVAL: - /* tried to move directory into a subdirectory of itself */ - return AFPERR_CANTMOVE; - case EXDEV: - /* this needs to copy and delete. bleah. that means we have - * to deal with entire directory hierarchies. */ - if ((err = copydir(src, dst, noadouble)) < 0) { - deletedir(dst); - return err; - } - if ((err = deletedir(src)) < 0) - return err; + switch ( errno ) { + case ENOENT : + return( AFPERR_NOOBJ ); + case EACCES : + return( AFPERR_ACCESS ); + case EROFS: + return AFPERR_VLOCK; + case EINVAL: + /* tried to move directory into a subdirectory of itself */ + return AFPERR_CANTMOVE; + case EXDEV: + /* this needs to copy and delete. bleah. that means we have + * to deal with entire directory hierarchies. */ + if ((err = copydir(src, dst, noadouble)) < 0) { + deletedir(dst); + return err; + } + if ((err = deletedir(src)) < 0) + return err; break; - default : - return( AFPERR_PARAM ); - } + default : + return( AFPERR_PARAM ); + } } memset(&ad, 0, sizeof(ad)); if ( ad_open( dst, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR, 0, &ad) < 0 ) { - switch ( errno ) { - case ENOENT : - if (noadouble) { - len = strlen(newname); - goto renamedir_done; - } - return( AFPERR_NOOBJ ); - case EACCES : - return( AFPERR_ACCESS ); - default : - return( AFPERR_PARAM ); - } + switch ( errno ) { + case ENOENT : + if (noadouble) { + len = strlen(newname); + goto renamedir_done; + } + return( AFPERR_NOOBJ ); + case EACCES : + return( AFPERR_ACCESS ); + default : + return( AFPERR_PARAM ); + } } len = strlen( newname ); ad_setentrylen( &ad, ADEID_NAME, len ); @@ -1574,17 +1574,17 @@ int renamedir(src, dst, dir, newparent, newname, noadouble) renamedir_done: if ((buf = (char *) realloc( dir->d_name, len + 1 )) == NULL ) { - syslog( LOG_ERR, "renamedir: realloc: %s", strerror(errno) ); - return AFPERR_MISC; + syslog( LOG_ERR, "renamedir: realloc: %s", strerror(errno) ); + return AFPERR_MISC; } dir->d_name = buf; strcpy( dir->d_name, newname ); if (( parent = dir->d_parent ) == NULL ) { - return( AFP_OK ); + return( AFP_OK ); } if ( parent == newparent ) { - return( AFP_OK ); + return( AFP_OK ); } /* detach from old parent and add to new one. */ @@ -1597,9 +1597,9 @@ renamedir_done: #define DOT_APPLEDOUBLE_LEN 13 /* delete an empty directory */ int deletecurdir( vol, path, pathlen ) - const struct vol *vol; - char *path; - int pathlen; +const struct vol *vol; +char *path; +int pathlen; { struct dirent *de; struct stat st; @@ -1612,11 +1612,11 @@ int deletecurdir( vol, path, pathlen ) #endif /* FORCE_UIDGID */ if ( curdir->d_parent == NULL ) { - return( AFPERR_ACCESS ); + return( AFPERR_ACCESS ); } if ( curdir->d_child != NULL ) { - return( AFPERR_DIRNEMPT ); + return( AFPERR_DIRNEMPT ); } fdir = curdir; @@ -1629,155 +1629,155 @@ int deletecurdir( vol, path, pathlen ) /* delete stray .AppleDouble files. this happens to get .Parent files as well. */ if ((dp = opendir(".AppleDouble"))) { - strcpy(path, ".AppleDouble/"); - while ((de = readdir(dp))) { - /* skip this and previous directory */ - if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) - continue; - - /* bail if the file exists in the current directory. - * note: this will not fail with dangling symlinks */ - if (stat(de->d_name, &st) == 0) { - closedir(dp); + strcpy(path, ".AppleDouble/"); + while ((de = readdir(dp))) { + /* skip this and previous directory */ + if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) + continue; + + /* bail if the file exists in the current directory. + * note: this will not fail with dangling symlinks */ + if (stat(de->d_name, &st) == 0) { + closedir(dp); #ifdef FORCE_UIDGID - restore_uidgid ( &uidgid ); + restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return AFPERR_DIRNEMPT; - } - - strcpy(path + DOT_APPLEDOUBLE_LEN, de->d_name); - if (unlink(path) < 0) { - closedir(dp); - switch (errno) { - case EPERM: - case EACCES : + return AFPERR_DIRNEMPT; + } + + strcpy(path + DOT_APPLEDOUBLE_LEN, de->d_name); + if (unlink(path) < 0) { + closedir(dp); + switch (errno) { + case EPERM: + case EACCES : #ifdef FORCE_UIDGID - restore_uidgid ( &uidgid ); + restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_ACCESS ); - case EROFS: + return( AFPERR_ACCESS ); + case EROFS: #ifdef FORCE_UIDGID - restore_uidgid ( &uidgid ); + restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return AFPERR_VLOCK; - case ENOENT : - continue; - default : + return AFPERR_VLOCK; + case ENOENT : + continue; + default : #ifdef FORCE_UIDGID - restore_uidgid ( &uidgid ); + restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_PARAM ); - } - } - } - closedir(dp); + return( AFPERR_PARAM ); + } + } + } + closedir(dp); } - + if ( rmdir( ".AppleDouble" ) < 0 ) { - switch ( errno ) { - case ENOENT : - break; - case ENOTEMPTY : + switch ( errno ) { + case ENOENT : + break; + case ENOTEMPTY : #ifdef FORCE_UIDGID restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_DIRNEMPT ); - case EROFS: + return( AFPERR_DIRNEMPT ); + case EROFS: #ifdef FORCE_UIDGID restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return AFPERR_VLOCK; - case EPERM: - case EACCES : + return AFPERR_VLOCK; + case EPERM: + case EACCES : #ifdef FORCE_UIDGID restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_ACCESS ); - default : + return( AFPERR_ACCESS ); + default : #ifdef FORCE_UIDGID restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_PARAM ); - } + return( AFPERR_PARAM ); + } } /* now get rid of dangling symlinks */ if ((dp = opendir("."))) { - while ((de = readdir(dp))) { - /* skip this and previous directory */ - if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) - continue; + while ((de = readdir(dp))) { + /* skip this and previous directory */ + if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) + continue; - /* bail if it's not a symlink */ - if ((lstat(de->d_name, &st) == 0) && !S_ISLNK(st.st_mode)) { + /* bail if it's not a symlink */ + if ((lstat(de->d_name, &st) == 0) && !S_ISLNK(st.st_mode)) { #ifdef FORCE_UIDGID - restore_uidgid ( &uidgid ); + restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return AFPERR_DIRNEMPT; - } + return AFPERR_DIRNEMPT; + } - if (unlink(de->d_name) < 0) { - switch (errno) { - case EPERM: - case EACCES : + if (unlink(de->d_name) < 0) { + switch (errno) { + case EPERM: + case EACCES : #ifdef FORCE_UIDGID - restore_uidgid ( &uidgid ); + restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_ACCESS ); - case EROFS: + return( AFPERR_ACCESS ); + case EROFS: #ifdef FORCE_UIDGID - restore_uidgid ( &uidgid ); + restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return AFPERR_VLOCK; - case ENOENT : - continue; - default : + return AFPERR_VLOCK; + case ENOENT : + continue; + default : #ifdef FORCE_UIDGID - restore_uidgid ( &uidgid ); + restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_PARAM ); - } - } - } - closedir(dp); + return( AFPERR_PARAM ); + } + } + } + closedir(dp); } if ( movecwd( vol, curdir->d_parent ) < 0 ) { #ifdef FORCE_UIDGID restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ( rmdir(mtoupath(vol, fdir->d_name)) < 0 ) { - switch ( errno ) { - case ENOENT : + switch ( errno ) { + case ENOENT : #ifdef FORCE_UIDGID restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_NOOBJ ); - case ENOTEMPTY : + return( AFPERR_NOOBJ ); + case ENOTEMPTY : #ifdef FORCE_UIDGID restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_DIRNEMPT ); - case EPERM: - case EACCES : + return( AFPERR_DIRNEMPT ); + case EPERM: + case EACCES : #ifdef FORCE_UIDGID restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_ACCESS ); - case EROFS: + return( AFPERR_ACCESS ); + case EROFS: #ifdef FORCE_UIDGID restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return AFPERR_VLOCK; - default : + return AFPERR_VLOCK; + default : #ifdef FORCE_UIDGID restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_PARAM ); - } + return( AFPERR_PARAM ); + } } dirchildremove(curdir, fdir); @@ -1793,9 +1793,9 @@ int deletecurdir( vol, path, pathlen ) } int afp_mapid(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct passwd *pw; struct group *gr; @@ -1810,47 +1810,47 @@ int afp_mapid(obj, ibuf, ibuflen, rbuf, rbuflen ) id = ntohl(id); if ( id != 0 ) { - switch ( sfunc ) { - case 1 : - if (( pw = getpwuid( id )) == NULL ) { - *rbuflen = 0; - return( AFPERR_NOITEM ); - } - name = pw->pw_name; - break; - - case 2 : - if (( gr = (struct group *)getgrgid( id )) == NULL ) { - *rbuflen = 0; - return( AFPERR_NOITEM ); - } - name = gr->gr_name; - break; - - default : - *rbuflen = 0; - return( AFPERR_PARAM ); - } - - len = strlen( name ); + switch ( sfunc ) { + case 1 : + if (( pw = getpwuid( id )) == NULL ) { + *rbuflen = 0; + return( AFPERR_NOITEM ); + } + name = pw->pw_name; + break; + + case 2 : + if (( gr = (struct group *)getgrgid( id )) == NULL ) { + *rbuflen = 0; + return( AFPERR_NOITEM ); + } + name = gr->gr_name; + break; + + default : + *rbuflen = 0; + return( AFPERR_PARAM ); + } + + len = strlen( name ); } else { - len = 0; - name = NULL; + len = 0; + name = NULL; } *rbuf++ = len; if ( len > 0 ) { - memcpy( rbuf, name, len ); + memcpy( rbuf, name, len ); } *rbuflen = len + 1; return( AFP_OK ); } int afp_mapname(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct passwd *pw; struct group *gr; @@ -1863,28 +1863,28 @@ int afp_mapname(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf[ len ] = '\0'; if ( len != 0 ) { - switch ( sfunc ) { - case 3 : - if (( pw = (struct passwd *)getpwnam( ibuf )) == NULL ) { - *rbuflen = 0; - return( AFPERR_NOITEM ); - } - id = pw->pw_uid; - break; - - case 4 : - if (( gr = (struct group *)getgrnam( ibuf )) == NULL ) { - *rbuflen = 0; - return( AFPERR_NOITEM ); - } - id = gr->gr_gid; - break; - default : - *rbuflen = 0; - return( AFPERR_PARAM ); - } + switch ( sfunc ) { + case 3 : + if (( pw = (struct passwd *)getpwnam( ibuf )) == NULL ) { + *rbuflen = 0; + return( AFPERR_NOITEM ); + } + id = pw->pw_uid; + break; + + case 4 : + if (( gr = (struct group *)getgrnam( ibuf )) == NULL ) { + *rbuflen = 0; + return( AFPERR_NOITEM ); + } + id = gr->gr_gid; + break; + default : + *rbuflen = 0; + return( AFPERR_PARAM ); + } } else { - id = 0; + id = 0; } id = htonl(id); memcpy( rbuf, &id, sizeof( id )); @@ -1894,9 +1894,9 @@ int afp_mapname(obj, ibuf, ibuflen, rbuf, rbuflen ) /* variable DID support */ int afp_closedir(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { #if 0 struct vol *vol; @@ -1905,22 +1905,22 @@ int afp_closedir(obj, ibuf, ibuflen, rbuf, rbuflen ) u_int32_t did; #endif /* 0 */ - *rbuflen = 0; + *rbuflen = 0; - /* do nothing as dids are static for the life of the process. */ + /* do nothing as dids are static for the life of the process. */ #if 0 ibuf += 2; memcpy(&vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memcpy( &did, ibuf, sizeof( did )); ibuf += sizeof( did ); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } /* dir_remove -- deletedid */ @@ -1931,9 +1931,9 @@ int afp_closedir(obj, ibuf, ibuflen, rbuf, rbuflen ) /* did creation gets done automatically */ int afp_opendir(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol; struct dir *dir, *parentdir; @@ -1954,39 +1954,39 @@ int afp_opendir(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memcpy(&did, ibuf, sizeof(did)); ibuf += sizeof(did); if (( parentdir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if (( path = cname( vol, parentdir, &ibuf )) == NULL ) { - switch( errno ) { - case EACCES: - return( AFPERR_ACCESS ); - default: - return( AFPERR_NOOBJ ); - } + switch( errno ) { + case EACCES: + return( AFPERR_ACCESS ); + default: + return( AFPERR_NOOBJ ); + } } /* see if we already have the directory. */ upath = mtoupath(vol, path); if ( stat( upath, &st ) < 0 ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } dir = parentdir->d_child; while (dir) { - if (strdiacasecmp(dir->d_name, path) == 0) { - memcpy(rbuf, &dir->d_did, sizeof(dir->d_did)); - *rbuflen = sizeof(dir->d_did); - return AFP_OK; - } - dir = (dir == parentdir->d_child->d_prev) ? NULL : dir->d_next; + if (strdiacasecmp(dir->d_name, path) == 0) { + memcpy(rbuf, &dir->d_did, sizeof(dir->d_did)); + *rbuflen = sizeof(dir->d_did); + return AFP_OK; + } + dir = (dir == parentdir->d_child->d_prev) ? NULL : dir->d_next; } #ifdef FORCE_UIDGID @@ -1995,13 +1995,13 @@ int afp_opendir(obj, ibuf, ibuflen, rbuf, rbuflen ) #endif /* FORCE_UIDGID */ /* we don't already have a did. add one in. */ - if ((dir = adddir(vol, parentdir, path, strlen(path), - upath, strlen(upath), &st)) == NULL) { + if ((dir = adddir(vol, parentdir, path, strlen(path), + upath, strlen(upath), &st)) == NULL) { #ifdef FORCE_UIDGID - restore_uidgid ( &uidgid ); + restore_uidgid ( &uidgid ); #endif /* FORCE_UIDGID */ - return AFPERR_MISC; - } + return AFPERR_MISC; + } memcpy(rbuf, &dir->d_did, sizeof(dir->d_did)); *rbuflen = sizeof(dir->d_did); diff --git a/etc/afpd/directory.h b/etc/afpd/directory.h index 6de12aba..f622851c 100644 --- a/etc/afpd/directory.h +++ b/etc/afpd/directory.h @@ -1,5 +1,5 @@ /* - * $Id: directory.h,v 1.2 2001-06-20 18:33:04 rufustfirefly Exp $ + * $Id: directory.h,v 1.2.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1991 Regents of The University of Michigan. * All Rights Reserved. @@ -147,19 +147,19 @@ extern struct dir *dirnew __P((const int)); extern void dirfree __P((struct dir *)); extern struct dir *dirsearch __P((const struct vol *, u_int32_t)); extern struct dir *adddir __P((struct vol *, struct dir *, char *, - int, char *, int, struct stat *)); + int, char *, int, struct stat *)); extern struct dir *dirinsert __P((struct vol *, struct dir *)); -extern int movecwd __P((const struct vol *, struct dir *)); +extern int movecwd __P((const struct vol *, struct dir *)); extern int deletecurdir __P((const struct vol *, char *, int)); extern char *cname __P((const struct vol *, struct dir *, - char **)); + char **)); extern mode_t mtoumode __P((struct maccess *)); extern void utommode __P((struct stat *, struct maccess *)); extern int getdirparams __P((const struct vol *, u_int16_t, char *, - struct dir *, struct stat *, char *, int *)); + struct dir *, struct stat *, char *, int *)); extern int setdirparams __P((const struct vol *, char *, u_int16_t, char *)); -extern int renamedir __P((char *, char *, struct dir *, - struct dir *, char *, const int)); +extern int renamedir __P((char *, char *, struct dir *, + struct dir *, char *, const int)); /* FP functions */ diff --git a/etc/afpd/enumerate.c b/etc/afpd/enumerate.c index 667b37be..46163347 100644 --- a/etc/afpd/enumerate.c +++ b/etc/afpd/enumerate.c @@ -1,5 +1,5 @@ /* - * $Id: enumerate.c,v 1.9 2001-09-04 13:52:45 rufustfirefly Exp $ + * $Id: enumerate.c,v 1.9.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -39,12 +39,12 @@ #endif /* DID_MTAB */ struct dir * -adddir( vol, dir, name, namlen, upath, upathlen, st ) - struct vol *vol; - struct dir *dir; - char *name, *upath; - int namlen, upathlen; - struct stat *st; + adddir( vol, dir, name, namlen, upath, upathlen, st ) + struct vol *vol; +struct dir *dir; +char *name, *upath; +int namlen, upathlen; +struct stat *st; { struct dir *cdir, *edir; #if AD_VERSION > AD_VERSION1 @@ -56,8 +56,8 @@ adddir( vol, dir, name, namlen, upath, upathlen, st ) #endif /* USE_LASTDID */ if ((cdir = dirnew(namlen + 1)) == NULL) { - syslog( LOG_ERR, "adddir: malloc: %s", strerror(errno) ); - return NULL; + syslog( LOG_ERR, "adddir: malloc: %s", strerror(errno) ); + return NULL; } strcpy( cdir->d_name, name ); cdir->d_name[namlen] = '\0'; @@ -69,23 +69,23 @@ adddir( vol, dir, name, namlen, upath, upathlen, st ) memset(&ad, 0, sizeof(ad)); if (ad_open(upath, ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY, 0, &ad) >= 0) { /* if we can parse the AppleDouble header, retrieve the DID entry into cdir->d_did */ - memcpy(&cdir->d_did, ad_entry(&ad, ADEID_DID), sizeof(cdir->d_did)); - ad_close(&ad, ADFLAGS_HF); - } + memcpy(&cdir->d_did, ad_entry(&ad, ADEID_DID), sizeof(cdir->d_did)); + ad_close(&ad, ADFLAGS_HF); + } #endif /* AD_VERSION */ #ifdef CNID_DB - /* add to cnid db */ + /* add to cnid db */ cdir->d_did = cnid_add(vol->v_db, st, dir->d_did, upath, - upathlen, cdir->d_did); + upathlen, cdir->d_did); #endif /* CNID_DB */ - if (cdir->d_did == 0) { + if (cdir->d_did == 0) { #ifdef USE_LASTDID /* last way of doing DIDs */ - cdir->d_did = htonl( vol->v_lastdid++ ); + cdir->d_did = htonl( vol->v_lastdid++ ); #else /* USE_LASTDID */ - lstp = lstat(upath, &lst) < 0 ? st : &lst; + lstp = lstat(upath, &lst) < 0 ? st : &lst; #ifdef DID_MTAB /* mtab way of doing DIDs */ cdir->d_did = htonl( afpd_st_cnid ( lstp ) ); @@ -97,17 +97,19 @@ adddir( vol, dir, name, namlen, upath, upathlen, st ) } if ((edir = dirinsert( vol, cdir ))) { - if (edir->d_name) { - if (strcmp(edir->d_name, cdir->d_name)) { - syslog(LOG_INFO, "WARNING: DID conflict for '%s' and '%s'. Are these the same file?", edir->d_name, cdir->d_name); - } - free(cdir->d_name); - free(cdir); - return edir; - } - edir->d_name = cdir->d_name; - free(cdir); - cdir = edir; +#ifndef CNID_DB + if (edir->d_name) { + if (strcmp(edir->d_name, cdir->d_name)) { + syslog(LOG_INFO, "WARNING: DID conflict for '%s' and '%s'. Are these the same file?", edir->d_name, cdir->d_name); + } + free(cdir->d_name); + free(cdir); + return edir; + } +#endif /* CNID_DB */ + edir->d_name = cdir->d_name; + free(cdir); + cdir = edir; } /* parent/child directories */ @@ -131,9 +133,9 @@ struct savedir { #define SDBUFBRK 1024 int afp_enumerate(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct stat st; static struct savedir sd = { 0, 0, 0, NULL, NULL, 0 }; @@ -147,12 +149,12 @@ int afp_enumerate(obj, ibuf, ibuflen, rbuf, rbuflen ) u_int16_t sindex, maxsz, sz = 0; if ( sd.sd_buflen == 0 ) { - if (( sd.sd_buf = (char *)malloc( SDBUFBRK )) == NULL ) { - syslog( LOG_ERR, "afp_enumerate: malloc: %s", strerror(errno) ); - *rbuflen = 0; - return AFPERR_MISC; - } - sd.sd_buflen = SDBUFBRK; + if (( sd.sd_buf = (char *)malloc( SDBUFBRK )) == NULL ) { + syslog( LOG_ERR, "afp_enumerate: malloc: %s", strerror(errno) ); + *rbuflen = 0; + return AFPERR_MISC; + } + sd.sd_buflen = SDBUFBRK; } ibuf += 2; @@ -161,16 +163,16 @@ int afp_enumerate(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - *rbuflen = 0; - return( AFPERR_PARAM ); + *rbuflen = 0; + return( AFPERR_PARAM ); } memcpy( &did, ibuf, sizeof( did )); ibuf += sizeof( did ); if (( dir = dirsearch( vol, did )) == NULL ) { - *rbuflen = 0; - return( AFPERR_NODIR ); + *rbuflen = 0; + return( AFPERR_NODIR ); } memcpy( &fbitmap, ibuf, sizeof( fbitmap )); @@ -183,11 +185,11 @@ int afp_enumerate(obj, ibuf, ibuflen, rbuf, rbuflen ) /* check for proper bitmaps -- the stuff in comments is for * variable directory ids. */ - if (!(fbitmap || dbitmap) - /*|| (fbitmap & (1 << FILPBIT_PDID)) || - (dbitmap & (1 << DIRPBIT_PDID))*/) { - *rbuflen = 0; - return AFPERR_BITMAP; + if (!(fbitmap || dbitmap) + /*|| (fbitmap & (1 << FILPBIT_PDID)) || + (dbitmap & (1 << DIRPBIT_PDID))*/) { + *rbuflen = 0; + return AFPERR_BITMAP; } memcpy( &reqcnt, ibuf, sizeof( reqcnt )); @@ -203,8 +205,8 @@ int afp_enumerate(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( maxsz ); if (( path = cname( vol, dir, &ibuf )) == NULL ) { - *rbuflen = 0; - return( AFPERR_NODIR ); + *rbuflen = 0; + return( AFPERR_NODIR ); } data = rbuf + 3 * sizeof( u_int16_t ); sz = 3 * sizeof( u_int16_t ); @@ -215,184 +217,184 @@ int afp_enumerate(obj, ibuf, ibuflen, rbuf, rbuflen ) * The end is indicated by a len of 0. */ if ( sindex == 1 || curdir->d_did != sd.sd_did || vid != sd.sd_vid ) { - sd.sd_last = sd.sd_buf; - - if (( dp = opendir( mtoupath(vol, path ))) == NULL ) { - *rbuflen = 0; - return (errno == ENOTDIR) ? AFPERR_BADTYPE : AFPERR_NODIR; - } - - end = sd.sd_buf + sd.sd_buflen; - for ( de = readdir( dp ); de != NULL; de = readdir( dp )) { - if (!strcmp(de->d_name, "..") || !strcmp(de->d_name, ".")) - continue; - - if (!(validupath(vol, de->d_name))) - continue; - - /* check for vetoed filenames */ - if (veto_file(vol->v_veto, de->d_name)) - continue; - - /* now check against too big a file */ - if (strlen(utompath(vol, de->d_name)) > MACFILELEN) - continue; - - len = strlen(de->d_name); - *(sd.sd_last)++ = len; - - if ( sd.sd_last + len + 2 > end ) { - char *buf; - - start = sd.sd_buf; - if ((buf = (char *) realloc( sd.sd_buf, sd.sd_buflen + - SDBUFBRK )) == NULL ) { - syslog( LOG_ERR, "afp_enumerate: realloc: %s", - strerror(errno) ); - closedir(dp); - *rbuflen = 0; - return AFPERR_MISC; - } - sd.sd_buf = buf; - sd.sd_buflen += SDBUFBRK; - sd.sd_last = ( sd.sd_last - start ) + sd.sd_buf; - end = sd.sd_buf + sd.sd_buflen; - } - - memcpy( sd.sd_last, de->d_name, len + 1 ); - sd.sd_last += len + 1; - } - *sd.sd_last = 0; - - sd.sd_last = sd.sd_buf; - sd.sd_sindex = 1; - - closedir( dp ); - sd.sd_vid = vid; - sd.sd_did = did; + sd.sd_last = sd.sd_buf; + + if (( dp = opendir( mtoupath(vol, path ))) == NULL ) { + *rbuflen = 0; + return (errno == ENOTDIR) ? AFPERR_BADTYPE : AFPERR_NODIR; + } + + end = sd.sd_buf + sd.sd_buflen; + for ( de = readdir( dp ); de != NULL; de = readdir( dp )) { + if (!strcmp(de->d_name, "..") || !strcmp(de->d_name, ".")) + continue; + + if (!(validupath(vol, de->d_name))) + continue; + + /* check for vetoed filenames */ + if (veto_file(vol->v_veto, de->d_name)) + continue; + + /* now check against too big a file */ + if (strlen(utompath(vol, de->d_name)) > MACFILELEN) + continue; + + len = strlen(de->d_name); + *(sd.sd_last)++ = len; + + if ( sd.sd_last + len + 2 > end ) { + char *buf; + + start = sd.sd_buf; + if ((buf = (char *) realloc( sd.sd_buf, sd.sd_buflen + + SDBUFBRK )) == NULL ) { + syslog( LOG_ERR, "afp_enumerate: realloc: %s", + strerror(errno) ); + closedir(dp); + *rbuflen = 0; + return AFPERR_MISC; + } + sd.sd_buf = buf; + sd.sd_buflen += SDBUFBRK; + sd.sd_last = ( sd.sd_last - start ) + sd.sd_buf; + end = sd.sd_buf + sd.sd_buflen; + } + + memcpy( sd.sd_last, de->d_name, len + 1 ); + sd.sd_last += len + 1; + } + *sd.sd_last = 0; + + sd.sd_last = sd.sd_buf; + sd.sd_sindex = 1; + + closedir( dp ); + sd.sd_vid = vid; + sd.sd_did = did; } /* * Position sd_last as dictated by sindex. */ if ( sindex < sd.sd_sindex ) { - sd.sd_sindex = 1; - sd.sd_last = sd.sd_buf; + sd.sd_sindex = 1; + sd.sd_last = sd.sd_buf; } while ( sd.sd_sindex < sindex ) { - len = *(sd.sd_last)++; - if ( len == 0 ) { - sd.sd_did = -1; /* invalidate sd struct to force re-read */ - *rbuflen = 0; - return( AFPERR_NOOBJ ); - } - sd.sd_last += len + 1; - sd.sd_sindex++; + len = *(sd.sd_last)++; + if ( len == 0 ) { + sd.sd_did = -1; /* invalidate sd struct to force re-read */ + *rbuflen = 0; + return( AFPERR_NOOBJ ); + } + sd.sd_last += len + 1; + sd.sd_sindex++; } while (( len = *(sd.sd_last)) != 0 ) { - /* - * If we've got all we need, send it. - */ - if ( actcnt == reqcnt ) { - break; - } - - /* - * Save the start position, in case we exceed the buffer - * limitation, and have to back up one. - */ - start = sd.sd_last; - sd.sd_last++; - - if ( stat( sd.sd_last, &st ) < 0 ) { - syslog( LOG_DEBUG, "afp_enumerate: stat %s: %s", - sd.sd_last, strerror(errno) ); - sd.sd_last += len + 1; - continue; - } - - /* - * If a fil/dir is not a dir, it's a file. This is slightly - * inaccurate, since that means /dev/null is a file, /dev/printer - * is a file, etc. - */ - if ( S_ISDIR(st.st_mode)) { - if ( dbitmap == 0 ) { - sd.sd_last += len + 1; - continue; - } - path = utompath(vol, sd.sd_last); - dir = curdir->d_child; - while (dir) { - if ( strcmp( dir->d_name, path ) == 0 ) { - break; - } - dir = (dir == curdir->d_child->d_prev) ? NULL : dir->d_next; - } - if (!dir && ((dir = adddir( vol, curdir, path, strlen( path ), - sd.sd_last, len, &st)) == NULL)) { - *rbuflen = 0; - return AFPERR_MISC; - } - - - if (( ret = getdirparams(vol, dbitmap, sd.sd_last, dir, - &st, data + 2 * sizeof( u_char ), &esz )) != AFP_OK ) { - *rbuflen = 0; - return( ret ); - } - - } else { - if ( fbitmap == 0 ) { - sd.sd_last += len + 1; - continue; - } - - if (( ret = getfilparams(vol, fbitmap, utompath(vol, sd.sd_last), - curdir, &st, data + 2 * sizeof( u_char ), &esz )) != - AFP_OK ) { - *rbuflen = 0; - return( ret ); - } - } - - /* - * Make sure entry is an even length, possibly with a null - * byte on the end. - */ - if ( esz & 1 ) { - *(data + 2 * sizeof( u_char ) + esz ) = '\0'; - esz++; - } - - /* - * Check if we've exceeded the size limit. - */ - if ( maxsz < sz + esz + 2 * sizeof( u_char )) { - if (first) { /* maxsz can't hold a single reply */ - *rbuflen = 0; - return AFPERR_PARAM; - } - sd.sd_last = start; - break; - } - - if (first) - first = 0; - - sz += esz + 2 * sizeof( u_char ); - *data++ = esz + 2 * sizeof( u_char ); - *data++ = S_ISDIR(st.st_mode) ? FILDIRBIT_ISDIR : FILDIRBIT_ISFILE; - data += esz; - actcnt++; - sd.sd_last += len + 1; + /* + * If we've got all we need, send it. + */ + if ( actcnt == reqcnt ) { + break; + } + + /* + * Save the start position, in case we exceed the buffer + * limitation, and have to back up one. + */ + start = sd.sd_last; + sd.sd_last++; + + if ( stat( sd.sd_last, &st ) < 0 ) { + syslog( LOG_DEBUG, "afp_enumerate: stat %s: %s", + sd.sd_last, strerror(errno) ); + sd.sd_last += len + 1; + continue; + } + + /* + * If a fil/dir is not a dir, it's a file. This is slightly + * inaccurate, since that means /dev/null is a file, /dev/printer + * is a file, etc. + */ + if ( S_ISDIR(st.st_mode)) { + if ( dbitmap == 0 ) { + sd.sd_last += len + 1; + continue; + } + path = utompath(vol, sd.sd_last); + dir = curdir->d_child; + while (dir) { + if ( strcmp( dir->d_name, path ) == 0 ) { + break; + } + dir = (dir == curdir->d_child->d_prev) ? NULL : dir->d_next; + } + if (!dir && ((dir = adddir( vol, curdir, path, strlen( path ), + sd.sd_last, len, &st)) == NULL)) { + *rbuflen = 0; + return AFPERR_MISC; + } + + + if (( ret = getdirparams(vol, dbitmap, sd.sd_last, dir, + &st, data + 2 * sizeof( u_char ), &esz )) != AFP_OK ) { + *rbuflen = 0; + return( ret ); + } + + } else { + if ( fbitmap == 0 ) { + sd.sd_last += len + 1; + continue; + } + + if (( ret = getfilparams(vol, fbitmap, utompath(vol, sd.sd_last), + curdir, &st, data + 2 * sizeof( u_char ), &esz )) != + AFP_OK ) { + *rbuflen = 0; + return( ret ); + } + } + + /* + * Make sure entry is an even length, possibly with a null + * byte on the end. + */ + if ( esz & 1 ) { + *(data + 2 * sizeof( u_char ) + esz ) = '\0'; + esz++; + } + + /* + * Check if we've exceeded the size limit. + */ + if ( maxsz < sz + esz + 2 * sizeof( u_char )) { + if (first) { /* maxsz can't hold a single reply */ + *rbuflen = 0; + return AFPERR_PARAM; + } + sd.sd_last = start; + break; + } + + if (first) + first = 0; + + sz += esz + 2 * sizeof( u_char ); + *data++ = esz + 2 * sizeof( u_char ); + *data++ = S_ISDIR(st.st_mode) ? FILDIRBIT_ISDIR : FILDIRBIT_ISFILE; + data += esz; + actcnt++; + sd.sd_last += len + 1; } if ( actcnt == 0 ) { - *rbuflen = 0; - sd.sd_did = -1; /* invalidate sd struct to force re-read */ - return( AFPERR_NOOBJ ); + *rbuflen = 0; + sd.sd_did = -1; /* invalidate sd struct to force re-read */ + return( AFPERR_NOOBJ ); } sd.sd_sindex = sindex + actcnt; @@ -415,8 +417,8 @@ int afp_enumerate(obj, ibuf, ibuflen, rbuf, rbuflen ) /* why is this here? well, FPCatSearch is essentially an FPEnumerate * with filters. */ -int afp_catsearch(AFPObj *obj, char *ibuf, int ibuflen, - char *rbuf, int *rbuflen) +int afp_catsearch(AFPObj *obj, char *ibuf, int ibuflen, + char *rbuf, int *rbuflen) { struct vol *vol; u_int16_t vid; @@ -427,7 +429,7 @@ int afp_catsearch(AFPObj *obj, char *ibuf, int ibuflen, *rbuflen = 0; if ((vol = getvolbyvid(vid)) == NULL) - return AFPERR_PARAM; + return AFPERR_PARAM; /* the ritual: * do a breadth-first search of directories: @@ -444,4 +446,4 @@ int afp_catsearch(AFPObj *obj, char *ibuf, int ibuflen, /* eof when done */ return AFPERR_EOF; -} +} diff --git a/etc/afpd/file.c b/etc/afpd/file.c index e6a4d833..18354314 100644 --- a/etc/afpd/file.c +++ b/etc/afpd/file.c @@ -1,5 +1,5 @@ /* - * $Id: file.c,v 1.29 2001-09-06 20:00:59 rufustfirefly Exp $ + * $Id: file.c,v 1.29.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -90,15 +90,15 @@ char *strchr (), *strrchr (); const u_char ufinderi[] = { 'T', 'E', 'X', 'T', 'U', 'N', 'I', 'X', - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int getfilparams(struct vol *vol, - u_int16_t bitmap, - char *path, struct dir *dir, struct stat *st, - char *buf, int *buflen ) + u_int16_t bitmap, + char *path, struct dir *dir, struct stat *st, + char *buf, int *buflen ) { #ifndef USE_LASTDID struct stat hst, lst, *lstp; @@ -120,236 +120,236 @@ int getfilparams(struct vol *vol, upath = mtoupath(vol, path); if ((of = of_findname(vol, curdir, path))) { - adp = of->of_ad; + adp = of->of_ad; } else { - memset(&ad, 0, sizeof(ad)); - adp = &ad; + memset(&ad, 0, sizeof(ad)); + adp = &ad; } if ( ad_open( upath, ADFLAGS_HF, O_RDONLY, 0, adp) < 0 ) { - isad = 0; + isad = 0; } else if ( fstat( ad_hfileno( adp ), &hst ) < 0 ) { - syslog( LOG_ERR, "getfilparams fstat: %s", strerror(errno) ); + syslog( LOG_ERR, "getfilparams fstat: %s", strerror(errno) ); } data = buf; while ( bitmap != 0 ) { - while (( bitmap & 1 ) == 0 ) { - bitmap = bitmap>>1; - bit++; - } - - switch ( bit ) { - case FILPBIT_ATTR : - if ( isad ) { - ad_getattr(adp, &ashort); - } else if (*upath == '.') { - ashort = htons(ATTRBIT_INVISIBLE); - } else - ashort = 0; - memcpy(data, &ashort, sizeof( ashort )); - data += sizeof( u_short ); - break; - - case FILPBIT_PDID : - memcpy(data, &dir->d_did, sizeof( u_int32_t )); - data += sizeof( u_int32_t ); - break; - - case FILPBIT_CDATE : - if (!isad || (ad_getdate(adp, AD_DATE_CREATE, &aint) < 0)) - aint = AD_DATE_FROM_UNIX(st->st_mtime); - memcpy(data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case FILPBIT_MDATE : - if ( isad && (ad_getdate(adp, AD_DATE_MODIFY, &aint) == 0)) { - if ((st->st_mtime > AD_DATE_TO_UNIX(aint)) && - (hst.st_mtime < st->st_mtime)) { - aint = AD_DATE_FROM_UNIX(st->st_mtime); - } - } else { - aint = AD_DATE_FROM_UNIX(st->st_mtime); - } - memcpy(data, &aint, sizeof( int )); - data += sizeof( int ); - break; - - case FILPBIT_BDATE : - if (!isad || (ad_getdate(adp, AD_DATE_BACKUP, &aint) < 0)) - aint = AD_DATE_START; - memcpy(data, &aint, sizeof( int )); - data += sizeof( int ); - break; - - case FILPBIT_FINFO : - if (isad) - memcpy(data, ad_entry(adp, ADEID_FINDERI), 32); - else { - memcpy(data, ufinderi, 32); - if (*upath == '.') { /* make it invisible */ - ashort = htons(FINDERINFO_INVISIBLE); - memcpy(data + FINDERINFO_FRFLAGOFF, &ashort, sizeof(ashort)); - } - } - - if ((!isad || (memcmp(ad_entry(adp, ADEID_FINDERI), - ufinderi, 8 ) == 0)) && - (em = getextmap( path ))) { - memcpy(data, em->em_type, sizeof( em->em_type )); - memcpy(data + 4, em->em_creator, sizeof(em->em_creator)); - } - data += 32; - break; - - case FILPBIT_LNAME : - nameoff = data; - data += sizeof( u_int16_t ); - break; - - case FILPBIT_SNAME : - memset(data, 0, sizeof(u_int16_t)); - data += sizeof( u_int16_t ); - break; - - case FILPBIT_FNUM : - aint = 0; + while (( bitmap & 1 ) == 0 ) { + bitmap = bitmap>>1; + bit++; + } + + switch ( bit ) { + case FILPBIT_ATTR : + if ( isad ) { + ad_getattr(adp, &ashort); + } else if (*upath == '.') { + ashort = htons(ATTRBIT_INVISIBLE); + } else + ashort = 0; + memcpy(data, &ashort, sizeof( ashort )); + data += sizeof( u_short ); + break; + + case FILPBIT_PDID : + memcpy(data, &dir->d_did, sizeof( u_int32_t )); + data += sizeof( u_int32_t ); + break; + + case FILPBIT_CDATE : + if (!isad || (ad_getdate(adp, AD_DATE_CREATE, &aint) < 0)) + aint = AD_DATE_FROM_UNIX(st->st_mtime); + memcpy(data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case FILPBIT_MDATE : + if ( isad && (ad_getdate(adp, AD_DATE_MODIFY, &aint) == 0)) { + if ((st->st_mtime > AD_DATE_TO_UNIX(aint)) && + (hst.st_mtime < st->st_mtime)) { + aint = AD_DATE_FROM_UNIX(st->st_mtime); + } + } else { + aint = AD_DATE_FROM_UNIX(st->st_mtime); + } + memcpy(data, &aint, sizeof( int )); + data += sizeof( int ); + break; + + case FILPBIT_BDATE : + if (!isad || (ad_getdate(adp, AD_DATE_BACKUP, &aint) < 0)) + aint = AD_DATE_START; + memcpy(data, &aint, sizeof( int )); + data += sizeof( int ); + break; + + case FILPBIT_FINFO : + if (isad) + memcpy(data, ad_entry(adp, ADEID_FINDERI), 32); + else { + memcpy(data, ufinderi, 32); + if (*upath == '.') { /* make it invisible */ + ashort = htons(FINDERINFO_INVISIBLE); + memcpy(data + FINDERINFO_FRFLAGOFF, &ashort, sizeof(ashort)); + } + } + + if ((!isad || (memcmp(ad_entry(adp, ADEID_FINDERI), + ufinderi, 8 ) == 0)) && + (em = getextmap( path ))) { + memcpy(data, em->em_type, sizeof( em->em_type )); + memcpy(data + 4, em->em_creator, sizeof(em->em_creator)); + } + data += 32; + break; + + case FILPBIT_LNAME : + nameoff = data; + data += sizeof( u_int16_t ); + break; + + case FILPBIT_SNAME : + memset(data, 0, sizeof(u_int16_t)); + data += sizeof( u_int16_t ); + break; + + case FILPBIT_FNUM : + aint = 0; #if AD_VERSION > AD_VERSION1 - /* look in AD v2 header */ - if (isad) - memcpy(&aint, ad_entry(adp, ADEID_DID), sizeof(aint)); + /* look in AD v2 header */ + if (isad) + memcpy(&aint, ad_entry(adp, ADEID_DID), sizeof(aint)); #endif /* AD_VERSION > AD_VERSION1 */ #ifdef CNID_DB - aint = cnid_add(vol->v_db, st, dir->d_did, upath, - strlen(upath), aint); + aint = cnid_add(vol->v_db, st, dir->d_did, upath, + strlen(upath), aint); #endif /* CNID_DB */ - if (aint == 0) { - /* - * What a fucking mess. First thing: DID and FNUMs are - * in the same space for purposes of enumerate (and several - * other wierd places). While we consider this Apple's bug, - * this is the work-around: In order to maintain constant and - * unique DIDs and FNUMs, we monotonically generate the DIDs - * during the session, and derive the FNUMs from the filesystem. - * Since the DIDs are small, we insure that the FNUMs are fairly - * large by setting thier high bits to the device number. - * - * AFS already does something very similar to this for the - * inode number, so we don't repeat the procedure. - * - * new algorithm: - * due to complaints over did's being non-persistent, - * here's the current hack to provide semi-persistent - * did's: - * 1) we reserve the first bit for file ids. - * 2) the next 7 bits are for the device. - * 3) the remaining 24 bits are for the inode. - * - * both the inode and device information are actually hashes - * that are then truncated to the requisite bit length. - * - * it should be okay to use lstat to deal with symlinks. - */ + if (aint == 0) { + /* + * What a fucking mess. First thing: DID and FNUMs are + * in the same space for purposes of enumerate (and several + * other wierd places). While we consider this Apple's bug, + * this is the work-around: In order to maintain constant and + * unique DIDs and FNUMs, we monotonically generate the DIDs + * during the session, and derive the FNUMs from the filesystem. + * Since the DIDs are small, we insure that the FNUMs are fairly + * large by setting thier high bits to the device number. + * + * AFS already does something very similar to this for the + * inode number, so we don't repeat the procedure. + * + * new algorithm: + * due to complaints over did's being non-persistent, + * here's the current hack to provide semi-persistent + * did's: + * 1) we reserve the first bit for file ids. + * 2) the next 7 bits are for the device. + * 3) the remaining 24 bits are for the inode. + * + * both the inode and device information are actually hashes + * that are then truncated to the requisite bit length. + * + * it should be okay to use lstat to deal with symlinks. + */ #ifdef USE_LASTDID - aint = htonl(( st->st_dev << 16 ) | (st->st_ino & 0x0000ffff)); + aint = htonl(( st->st_dev << 16 ) | (st->st_ino & 0x0000ffff)); #else /* USE_LASTDID */ - lstp = lstat(upath, &lst) < 0 ? st : &lst; + lstp = lstat(upath, &lst) < 0 ? st : &lst; #ifdef DID_MTAB - aint = htonl( afpd_st_cnid ( lstp ) ); + aint = htonl( afpd_st_cnid ( lstp ) ); #else /* DID_MTAB */ - aint = htonl(CNID(lstp, 1)); + aint = htonl(CNID(lstp, 1)); #endif /* DID_MTAB */ #endif /* USE_LASTDID */ - } - - memcpy(data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case FILPBIT_DFLEN : - aint = htonl( st->st_size ); - memcpy(data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case FILPBIT_RFLEN : - if ( isad ) { - aint = htonl( ad_getentrylen( adp, ADEID_RFORK )); - } else { - aint = 0; - } - memcpy(data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - /* Current client needs ProDOS info block for this file. - Use simple heuristic and let the Mac "type" string tell - us what the PD file code should be. Everything gets a - subtype of 0x0000 unless the original value was hashed - to "pXYZ" when we created it. See IA, Ver 2. - */ - case FILPBIT_PDINFO : - if ( isad ) { - memcpy(fdType, ad_entry( adp, ADEID_FINDERI ), 4 ); - - if ( memcmp( fdType, "TEXT", 4 ) == 0 ) { - achar = '\x04'; - ashort = 0x0000; - } - else if ( memcmp( fdType, "PSYS", 4 ) == 0 ) { - achar = '\xff'; - ashort = 0x0000; - } - else if ( memcmp( fdType, "PS16", 4 ) == 0 ) { - achar = '\xb3'; - ashort = 0x0000; - } - else if ( memcmp( fdType, "BINA", 4 ) == 0 ) { - achar = '\x00'; - ashort = 0x0000; - } - else if ( fdType[0] == 'p' ) { - achar = fdType[1]; - ashort = (fdType[2] * 256) + fdType[3]; - } - else { - achar = '\x00'; - ashort = 0x0000; - } - } - else { - achar = '\x00'; - ashort = 0x0000; - } - - *data++ = achar; - *data++ = 0; - memcpy(data, &ashort, sizeof( ashort )); - data += sizeof( ashort ); - memset(data, 0, sizeof( ashort )); - data += sizeof( ashort ); - break; - - default : - if ( isad ) { - ad_close( adp, ADFLAGS_HF ); - } - return( AFPERR_BITMAP ); - } - bitmap = bitmap>>1; - bit++; + } + + memcpy(data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case FILPBIT_DFLEN : + aint = htonl( st->st_size ); + memcpy(data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case FILPBIT_RFLEN : + if ( isad ) { + aint = htonl( ad_getentrylen( adp, ADEID_RFORK )); + } else { + aint = 0; + } + memcpy(data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + /* Current client needs ProDOS info block for this file. + Use simple heuristic and let the Mac "type" string tell + us what the PD file code should be. Everything gets a + subtype of 0x0000 unless the original value was hashed + to "pXYZ" when we created it. See IA, Ver 2. + */ + case FILPBIT_PDINFO : + if ( isad ) { + memcpy(fdType, ad_entry( adp, ADEID_FINDERI ), 4 ); + + if ( memcmp( fdType, "TEXT", 4 ) == 0 ) { + achar = '\x04'; + ashort = 0x0000; + } + else if ( memcmp( fdType, "PSYS", 4 ) == 0 ) { + achar = '\xff'; + ashort = 0x0000; + } + else if ( memcmp( fdType, "PS16", 4 ) == 0 ) { + achar = '\xb3'; + ashort = 0x0000; + } + else if ( memcmp( fdType, "BINA", 4 ) == 0 ) { + achar = '\x00'; + ashort = 0x0000; + } + else if ( fdType[0] == 'p' ) { + achar = fdType[1]; + ashort = (fdType[2] * 256) + fdType[3]; + } + else { + achar = '\x00'; + ashort = 0x0000; + } + } + else { + achar = '\x00'; + ashort = 0x0000; + } + + *data++ = achar; + *data++ = 0; + memcpy(data, &ashort, sizeof( ashort )); + data += sizeof( ashort ); + memset(data, 0, sizeof( ashort )); + data += sizeof( ashort ); + break; + + default : + if ( isad ) { + ad_close( adp, ADFLAGS_HF ); + } + return( AFPERR_BITMAP ); + } + bitmap = bitmap>>1; + bit++; } if ( nameoff ) { - ashort = htons( data - buf ); - memcpy(nameoff, &ashort, sizeof( ashort )); - if ((aint = strlen( path )) > MACFILELEN) - aint = MACFILELEN; - *data++ = aint; - memcpy(data, path, aint ); - data += aint; + ashort = htons( data - buf ); + memcpy(nameoff, &ashort, sizeof( ashort )); + if ((aint = strlen( path )) > MACFILELEN) + aint = MACFILELEN; + *data++ = aint; + memcpy(data, path, aint ); + data += aint; } if ( isad ) { ad_close( adp, ADFLAGS_HF ); @@ -364,9 +364,9 @@ int getfilparams(struct vol *vol, } int afp_createfile(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct stat st; struct adouble ad, *adp; @@ -377,7 +377,7 @@ int afp_createfile(obj, ibuf, ibuflen, rbuf, rbuflen ) int creatf, did, openf, retvalue = AFP_OK; u_int16_t vid; #ifdef FORCE_UIDGID - uidgidset *uidgid; + uidgidset *uidgid; #endif /* FORCE_UIDGID */ #ifdef DEBUG @@ -392,7 +392,7 @@ int afp_createfile(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (vol->v_flags & AFPVOL_RO) @@ -402,86 +402,86 @@ int afp_createfile(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( did ); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } - if ((vol->v_flags & AFPVOL_MSWINDOWS) && - strpbrk(path, MSWINDOWS_BADCHARS)) + if ((vol->v_flags & AFPVOL_MSWINDOWS) && + strpbrk(path, MSWINDOWS_BADCHARS)) return AFPERR_PARAM; upath = mtoupath(vol, path); if ((vol->v_flags & AFPVOL_NOHEX) && strchr(upath, '/')) - return AFPERR_PARAM; + return AFPERR_PARAM; if (!validupath(vol, upath)) - return AFPERR_EXIST; + return AFPERR_EXIST; /* check for vetoed filenames */ if (veto_file(vol->v_veto, upath)) return AFPERR_EXIST; if ((of = of_findname(vol, curdir, path))) { - adp = of->of_ad; + adp = of->of_ad; } else { - memset(&ad, 0, sizeof(ad)); - adp = &ad; + memset(&ad, 0, sizeof(ad)); + adp = &ad; } if ( creatf) { /* on a hard create, fail if file exists and is open */ if ((stat(upath, &st) == 0) && of) - return AFPERR_BUSY; - openf = O_RDWR|O_CREAT|O_TRUNC; + return AFPERR_BUSY; + openf = O_RDWR|O_CREAT|O_TRUNC; } else { - openf = O_RDWR|O_CREAT|O_EXCL; + openf = O_RDWR|O_CREAT|O_EXCL; } #ifdef FORCE_UIDGID - /* preserve current euid, egid */ - save_uidgid ( uidgid ); + /* preserve current euid, egid */ + save_uidgid ( uidgid ); - /* perform all switching of users */ - set_uidgid ( vol ); + /* perform all switching of users */ + set_uidgid ( vol ); #endif /* FORCE_UIDGID */ if ( ad_open( upath, vol_noadouble(vol)|ADFLAGS_DF|ADFLAGS_HF, - openf, 0666, adp) < 0 ) { - switch ( errno ) { - case EEXIST : + openf, 0666, adp) < 0 ) { + switch ( errno ) { + case EEXIST : #ifdef FORCE_UIDGID - /* bring everything back to old euid, egid */ - restore_uidgid ( uidgid ); + /* bring everything back to old euid, egid */ + restore_uidgid ( uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_EXIST ); - case EACCES : + return( AFPERR_EXIST ); + case EACCES : #ifdef FORCE_UIDGID - /* bring everything back to old euid, egid */ - restore_uidgid ( uidgid ); + /* bring everything back to old euid, egid */ + restore_uidgid ( uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_ACCESS ); + return( AFPERR_ACCESS ); case ENOENT: - /* on noadouble volumes, just creating the data fork is ok */ - if (vol_noadouble(vol) && (stat(upath, &st) == 0)) - goto createfile_done; - /* fallthrough */ - default : + /* on noadouble volumes, just creating the data fork is ok */ + if (vol_noadouble(vol) && (stat(upath, &st) == 0)) + goto createfile_done; + /* fallthrough */ + default : #ifdef FORCE_UIDGID - /* bring everything back to old euid, egid */ - restore_uidgid ( uidgid ); + /* bring everything back to old euid, egid */ + restore_uidgid ( uidgid ); #endif /* FORCE_UIDGID */ - return( AFPERR_PARAM ); - } + return( AFPERR_PARAM ); + } } ad_setentrylen( adp, ADEID_NAME, strlen( path )); memcpy(ad_entry( adp, ADEID_NAME ), path, - ad_getentrylen( adp, ADEID_NAME )); + ad_getentrylen( adp, ADEID_NAME )); ad_flush( adp, ADFLAGS_DF|ADFLAGS_HF ); ad_close( adp, ADFLAGS_DF|ADFLAGS_HF ); @@ -489,7 +489,7 @@ createfile_done: #ifdef DROPKLUDGE if (vol->v_flags & AFPVOL_DROPBOX) { - retvalue = matchfile2dirperms(upath, vol, did); + retvalue = matchfile2dirperms(upath, vol, did); } #endif /* DROPKLUDGE */ @@ -500,17 +500,17 @@ createfile_done: #endif /* DEBUG */ #ifdef FORCE_UIDGID - /* bring everything back to old euid, egid */ - restore_uidgid ( uidgid ); + /* bring everything back to old euid, egid */ + restore_uidgid ( uidgid ); #endif /* FORCE_UIDGID */ return (retvalue); } int afp_setfilparams(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol; struct dir *dir; @@ -528,7 +528,7 @@ int afp_setfilparams(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy(&vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (vol->v_flags & AFPVOL_RO) @@ -537,7 +537,7 @@ int afp_setfilparams(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy(&did, ibuf, sizeof( did )); ibuf += sizeof( did ); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } memcpy(&bitmap, ibuf, sizeof( bitmap )); @@ -545,15 +545,15 @@ int afp_setfilparams(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( bitmap ); if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ((u_long)ibuf & 1 ) { - ibuf++; + ibuf++; } if (( rc = setfilparams(vol, path, bitmap, ibuf )) == AFP_OK ) { - setvoltime(obj, vol ); + setvoltime(obj, vol ); } #ifdef DEBUG @@ -565,7 +565,7 @@ int afp_setfilparams(obj, ibuf, ibuflen, rbuf, rbuflen ) int setfilparams(struct vol *vol, - char *path, u_int16_t bitmap, char *buf ) + char *path, u_int16_t bitmap, char *buf ) { struct adouble ad, *adp; struct ofork *of; @@ -578,9 +578,9 @@ int setfilparams(struct vol *vol, struct utimbuf ut; #ifdef FORCE_UIDGID - uidgidset *uidgid; + uidgidset *uidgid; - uidgid = malloc(sizeof(uidgidset)); + uidgid = malloc(sizeof(uidgidset)); #endif /* FORCE_UIDGID */ #ifdef DEBUG @@ -589,144 +589,144 @@ int setfilparams(struct vol *vol, upath = mtoupath(vol, path); if ((of = of_findname(vol, curdir, path))) { - adp = of->of_ad; + adp = of->of_ad; } else { - memset(&ad, 0, sizeof(ad)); - adp = &ad; + memset(&ad, 0, sizeof(ad)); + adp = &ad; } #ifdef FORCE_UIDGID - save_uidgid ( uidgid ); - set_uidgid ( vol ); + save_uidgid ( uidgid ); + set_uidgid ( vol ); #endif /* FORCE_UIDGID */ - if (ad_open( upath, vol_noadouble(vol) | ADFLAGS_HF, - O_RDWR|O_CREAT, 0666, adp) < 0) { - /* for some things, we don't need an adouble header */ - if (bitmap & ~(1<>1; - bit++; - } - - switch( bit ) { - case FILPBIT_ATTR : - memcpy(&ashort, buf, sizeof( ashort )); - ad_getattr(adp, &bshort); - if ( ntohs( ashort ) & ATTRBIT_SETCLR ) { - bshort |= htons( ntohs( ashort ) & ~ATTRBIT_SETCLR ); - } else { - bshort &= ~ashort; - } - ad_setattr(adp, bshort); - buf += sizeof( ashort ); - break; - - case FILPBIT_CDATE : - memcpy(&aint, buf, sizeof(aint)); - ad_setdate(adp, AD_DATE_CREATE, aint); - buf += sizeof( aint ); - break; - - case FILPBIT_MDATE : - memcpy(&aint, buf, sizeof( aint )); - if (isad) - ad_setdate(adp, AD_DATE_MODIFY, aint); - ut.actime = ut.modtime = AD_DATE_TO_UNIX(aint); - utime(upath, &ut); - buf += sizeof( aint ); - break; - - case FILPBIT_BDATE : - memcpy(&aint, buf, sizeof(aint)); - ad_setdate(adp, AD_DATE_BACKUP, aint); - buf += sizeof( aint ); - break; - - case FILPBIT_FINFO : - if ((memcmp( ad_entry( adp, ADEID_FINDERI ), ufinderi, 8 ) == 0) - && (em = getextmap( path )) && - (memcmp(buf, em->em_type, sizeof( em->em_type )) == 0) && - (memcmp(buf + 4, em->em_creator, - sizeof( em->em_creator )) == 0)) { - memcpy(buf, ufinderi, 8 ); - } - memcpy(ad_entry( adp, ADEID_FINDERI ), buf, 32 ); - buf += 32; - break; - - /* Client needs to set the ProDOS file info for this file. - Use defined strings for the simple cases, and convert - all else into pXYY per Inside Appletalk. Always set - the creator as "pdos". */ - case FILPBIT_PDINFO : - achar = *buf; - buf += 2; - memcpy(&ashort, buf, sizeof( ashort )); - ashort = ntohs( ashort ); - buf += 2; - - switch ( (unsigned int) achar ) - { - case 0x04 : - fdType = ( u_char *) "TEXT"; - break; - - case 0xff : - fdType = ( u_char *) "PSYS"; - break; - - case 0xb3 : - fdType = ( u_char *) "PS16"; - break; - - case 0x00 : - fdType = ( u_char *) "BINA"; - break; - - default : - xyy[0] = ( u_char ) 'p'; - xyy[1] = achar; - xyy[2] = ( u_char ) ( ashort >> 8 ) & 0xff; - xyy[3] = ( u_char ) ashort & 0xff; - fdType = xyy; - break; - } - - memcpy(ad_entry( adp, ADEID_FINDERI ), fdType, 4 ); - memcpy(ad_entry( adp, ADEID_FINDERI ) + 4, "pdos", 4 ); - break; - - - default : - err = AFPERR_BITMAP; - goto setfilparam_done; - } - - bitmap = bitmap>>1; - bit++; + while (( bitmap & 1 ) == 0 ) { + bitmap = bitmap>>1; + bit++; + } + + switch( bit ) { + case FILPBIT_ATTR : + memcpy(&ashort, buf, sizeof( ashort )); + ad_getattr(adp, &bshort); + if ( ntohs( ashort ) & ATTRBIT_SETCLR ) { + bshort |= htons( ntohs( ashort ) & ~ATTRBIT_SETCLR ); + } else { + bshort &= ~ashort; + } + ad_setattr(adp, bshort); + buf += sizeof( ashort ); + break; + + case FILPBIT_CDATE : + memcpy(&aint, buf, sizeof(aint)); + ad_setdate(adp, AD_DATE_CREATE, aint); + buf += sizeof( aint ); + break; + + case FILPBIT_MDATE : + memcpy(&aint, buf, sizeof( aint )); + if (isad) + ad_setdate(adp, AD_DATE_MODIFY, aint); + ut.actime = ut.modtime = AD_DATE_TO_UNIX(aint); + utime(upath, &ut); + buf += sizeof( aint ); + break; + + case FILPBIT_BDATE : + memcpy(&aint, buf, sizeof(aint)); + ad_setdate(adp, AD_DATE_BACKUP, aint); + buf += sizeof( aint ); + break; + + case FILPBIT_FINFO : + if ((memcmp( ad_entry( adp, ADEID_FINDERI ), ufinderi, 8 ) == 0) + && (em = getextmap( path )) && + (memcmp(buf, em->em_type, sizeof( em->em_type )) == 0) && + (memcmp(buf + 4, em->em_creator, + sizeof( em->em_creator )) == 0)) { + memcpy(buf, ufinderi, 8 ); + } + memcpy(ad_entry( adp, ADEID_FINDERI ), buf, 32 ); + buf += 32; + break; + + /* Client needs to set the ProDOS file info for this file. + Use defined strings for the simple cases, and convert + all else into pXYY per Inside Appletalk. Always set + the creator as "pdos". */ + case FILPBIT_PDINFO : + achar = *buf; + buf += 2; + memcpy(&ashort, buf, sizeof( ashort )); + ashort = ntohs( ashort ); + buf += 2; + + switch ( (unsigned int) achar ) + { + case 0x04 : + fdType = ( u_char *) "TEXT"; + break; + + case 0xff : + fdType = ( u_char *) "PSYS"; + break; + + case 0xb3 : + fdType = ( u_char *) "PS16"; + break; + + case 0x00 : + fdType = ( u_char *) "BINA"; + break; + + default : + xyy[0] = ( u_char ) 'p'; + xyy[1] = achar; + xyy[2] = ( u_char ) ( ashort >> 8 ) & 0xff; + xyy[3] = ( u_char ) ashort & 0xff; + fdType = xyy; + break; + } + + memcpy(ad_entry( adp, ADEID_FINDERI ), fdType, 4 ); + memcpy(ad_entry( adp, ADEID_FINDERI ) + 4, "pdos", 4 ); + break; + + + default : + err = AFPERR_BITMAP; + goto setfilparam_done; + } + + bitmap = bitmap>>1; + bit++; } setfilparam_done: if (isad) { - ad_flush( adp, ADFLAGS_HF ); - ad_close( adp, ADFLAGS_HF ); + ad_flush( adp, ADFLAGS_HF ); + ad_close( adp, ADFLAGS_HF ); #ifdef FORCE_UIDGID - restore_uidgid ( uidgid ); + restore_uidgid ( uidgid ); #endif /* FORCE_UIDGID */ } @@ -745,8 +745,8 @@ setfilparam_done: * will break. */ int renamefile(src, dst, newname, noadouble ) - char *src, *dst, *newname; - const int noadouble; +char *src, *dst, *newname; +const int noadouble; { struct adouble ad; char adsrc[ MAXPATHLEN + 1]; @@ -766,23 +766,23 @@ int renamefile(src, dst, newname, noadouble ) #endif /* DEBUG */ if ( rename( src, dst ) < 0 ) { - switch ( errno ) { - case ENOENT : - return( AFPERR_NOOBJ ); - case EPERM: - case EACCES : - return( AFPERR_ACCESS ); - case EROFS: - return AFPERR_VLOCK; - case EXDEV : /* Cross device move -- try copy */ - if (( rc = copyfile(src, dst, newname, noadouble )) != AFP_OK ) { - deletefile( dst ); - return( rc ); - } - return deletefile( src ); - default : - return( AFPERR_PARAM ); - } + switch ( errno ) { + case ENOENT : + return( AFPERR_NOOBJ ); + case EPERM: + case EACCES : + return( AFPERR_ACCESS ); + case EROFS: + return AFPERR_VLOCK; + case EXDEV : /* Cross device move -- try copy */ + if (( rc = copyfile(src, dst, newname, noadouble )) != AFP_OK ) { + deletefile( dst ); + return( rc ); + } + return deletefile( src ); + default : + return( AFPERR_PARAM ); + } } strcpy( adsrc, ad_path( src, 0 )); @@ -791,39 +791,39 @@ rename_retry: if (rename( adsrc, ad_path( dst, 0 )) < 0 ) { struct stat st; - switch ( errno ) { - case ENOENT : - /* check for a source appledouble header. if it exists, make - * a dest appledouble directory and do the rename again. */ - memset(&ad, 0, sizeof(ad)); - if (rc || stat(adsrc, &st) || - (ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad) < 0)) - return AFP_OK; - rc++; - ad_close(&ad, ADFLAGS_HF); - goto rename_retry; - case EPERM: - case EACCES : - return( AFPERR_ACCESS ); - case EROFS: - return AFPERR_VLOCK; - default : - return( AFPERR_PARAM ); - } + switch ( errno ) { + case ENOENT : + /* check for a source appledouble header. if it exists, make + * a dest appledouble directory and do the rename again. */ + memset(&ad, 0, sizeof(ad)); + if (rc || stat(adsrc, &st) || + (ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad) < 0)) + return AFP_OK; + rc++; + ad_close(&ad, ADFLAGS_HF); + goto rename_retry; + case EPERM: + case EACCES : + return( AFPERR_ACCESS ); + case EROFS: + return AFPERR_VLOCK; + default : + return( AFPERR_PARAM ); + } } memset(&ad, 0, sizeof(ad)); if ( ad_open( dst, ADFLAGS_HF, O_RDWR, 0666, &ad) < 0 ) { - switch ( errno ) { - case ENOENT : - return( AFPERR_NOOBJ ); - case EACCES : - return( AFPERR_ACCESS ); - case EROFS: - return AFPERR_VLOCK; - default : - return( AFPERR_PARAM ); - } + switch ( errno ) { + case ENOENT : + return( AFPERR_NOOBJ ); + case EACCES : + return( AFPERR_ACCESS ); + case EROFS: + return AFPERR_VLOCK; + default : + return( AFPERR_PARAM ); + } } len = strlen( newname ); @@ -840,9 +840,9 @@ rename_retry: } int afp_copyfile(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol; struct dir *dir; @@ -861,13 +861,13 @@ int afp_copyfile(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy(&svid, ibuf, sizeof( svid )); ibuf += sizeof( svid ); if (( vol = getvolbyvid( svid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memcpy(&sdid, ibuf, sizeof( sdid )); ibuf += sizeof( sdid ); if (( dir = dirsearch( vol, sdid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memcpy(&dvid, ibuf, sizeof( dvid )); @@ -876,10 +876,10 @@ int afp_copyfile(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( ddid ); if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ( *path == '\0' ) { - return( AFPERR_BADTYPE ); + return( AFPERR_BADTYPE ); } /* don't allow copies when the file is open. @@ -888,50 +888,50 @@ int afp_copyfile(obj, ibuf, ibuflen, rbuf, rbuflen ) * and locks need to stay coherent. as a result, * we just balk if the file is opened already. */ if (of_findname(vol, curdir, path)) - return AFPERR_DENYCONF; - + return AFPERR_DENYCONF; + newname = obj->newtmp; strcpy( newname, path ); p = ctoupath( vol, curdir, newname ); if (( vol = getvolbyvid( dvid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (vol->v_flags & AFPVOL_RO) return AFPERR_VLOCK; if (( dir = dirsearch( vol, ddid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ( *path != '\0' ) { - return( AFPERR_BADTYPE ); + return( AFPERR_BADTYPE ); } /* one of the handful of places that knows about the path type */ if ( *ibuf++ != 2 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (( plen = (unsigned char)*ibuf++ ) != 0 ) { - strncpy( newname, ibuf, plen ); - newname[ plen ] = '\0'; + strncpy( newname, ibuf, plen ); + newname[ plen ] = '\0'; } - if ( (err = copyfile(p, mtoupath(vol, newname ), newname, - vol_noadouble(vol))) < 0 ) { - return err; + if ( (err = copyfile(p, mtoupath(vol, newname ), newname, + vol_noadouble(vol))) < 0 ) { + return err; } setvoltime(obj, vol ); #ifdef DROPKLUDGE if (vol->v_flags & AFPVOL_DROPBOX) { - retvalue=matchfile2dirperms(newname, vol, sdid); + retvalue=matchfile2dirperms(newname, vol, sdid); } #endif /* DROPKLUDGE */ @@ -944,44 +944,44 @@ int afp_copyfile(obj, ibuf, ibuflen, rbuf, rbuflen ) static __inline__ int copy_all(const int dfd, const void *buf, - size_t buflen) + size_t buflen) { - ssize_t cc; + ssize_t cc; #ifdef DEBUG - syslog(LOG_INFO, "begin copy_all:"); + syslog(LOG_INFO, "begin copy_all:"); #endif /* DEBUG */ - while (buflen > 0) { - if ((cc = write(dfd, buf, buflen)) < 0) { - switch (errno) { - case EINTR: - continue; - case EDQUOT: - case EFBIG: - case ENOSPC: - return AFPERR_DFULL; - case EROFS: - return AFPERR_VLOCK; - default: - return AFPERR_PARAM; - } - } - buflen -= cc; - } + while (buflen > 0) { + if ((cc = write(dfd, buf, buflen)) < 0) { + switch (errno) { + case EINTR: + continue; + case EDQUOT: + case EFBIG: + case ENOSPC: + return AFPERR_DFULL; + case EROFS: + return AFPERR_VLOCK; + default: + return AFPERR_PARAM; + } + } + buflen -= cc; + } #ifdef DEBUG - syslog(LOG_INFO, "end copy_all:"); + syslog(LOG_INFO, "end copy_all:"); #endif /* DEBUG */ - return AFP_OK; + return AFP_OK; } /* XXX: this needs to use ad_open and ad_lock. so, we need to * pass in vol and path */ int copyfile(src, dst, newname, noadouble ) - char *src, *dst, *newname; - const int noadouble; +char *src, *dst, *newname; +const int noadouble; { struct adouble ad; struct stat st; @@ -993,163 +993,163 @@ int copyfile(src, dst, newname, noadouble ) syslog(LOG_INFO, "begin copyfile:"); #endif /* DEBUG */ - if (newname) { - if ((sfd = open( ad_path( src, ADFLAGS_HF ), O_RDONLY, 0 )) < 0 ) { - switch ( errno ) { - case ENOENT : - break; /* just copy the data fork */ - case EACCES : - return( AFPERR_ACCESS ); - default : - return( AFPERR_PARAM ); - } - } else { - if (( dfd = open( ad_path( dst, ADFLAGS_HF ), O_WRONLY|O_CREAT, - ad_mode( ad_path( dst, ADFLAGS_HF ), 0666 ))) < 0 ) { - close( sfd ); - switch ( errno ) { - case ENOENT : - return( AFPERR_NOOBJ ); - case EACCES : - return( AFPERR_ACCESS ); - case EROFS: - return AFPERR_VLOCK; - default : - return( AFPERR_PARAM ); - } - } - - /* copy the file */ + if (newname) { + if ((sfd = open( ad_path( src, ADFLAGS_HF ), O_RDONLY, 0 )) < 0 ) { + switch ( errno ) { + case ENOENT : + break; /* just copy the data fork */ + case EACCES : + return( AFPERR_ACCESS ); + default : + return( AFPERR_PARAM ); + } + } else { + if (( dfd = open( ad_path( dst, ADFLAGS_HF ), O_WRONLY|O_CREAT, + ad_mode( ad_path( dst, ADFLAGS_HF ), 0666 ))) < 0 ) { + close( sfd ); + switch ( errno ) { + case ENOENT : + return( AFPERR_NOOBJ ); + case EACCES : + return( AFPERR_ACCESS ); + case EROFS: + return AFPERR_VLOCK; + default : + return( AFPERR_PARAM ); + } + } + + /* copy the file */ #ifdef SENDFILE_FLAVOR_LINUX - if (fstat(sfd, &st) == 0) { - if ((cc = sendfile(dfd, sfd, NULL, st.st_size)) < 0) { - switch (errno) { - case EDQUOT: - case EFBIG: - case ENOSPC: - err = AFPERR_DFULL; - break; - case EROFS: - err = AFPERR_VLOCK; - break; - default: - err = AFPERR_PARAM; - } - } - goto copyheader_done; - } + if (fstat(sfd, &st) == 0) { + if ((cc = sendfile(dfd, sfd, NULL, st.st_size)) < 0) { + switch (errno) { + case EDQUOT: + case EFBIG: + case ENOSPC: + err = AFPERR_DFULL; + break; + case EROFS: + err = AFPERR_VLOCK; + break; + default: + err = AFPERR_PARAM; + } + } + goto copyheader_done; + } #endif /* SENDFILE_FLAVOR_LINUX */ - while (1) { - if ((cc = read(sfd, filebuf, sizeof(filebuf))) < 0) { - if (errno == EINTR) - continue; - err = AFPERR_PARAM; - break; - } - - if (!cc || ((err = copy_all(dfd, filebuf, cc)) < 0)) - break; - } + while (1) { + if ((cc = read(sfd, filebuf, sizeof(filebuf))) < 0) { + if (errno == EINTR) + continue; + err = AFPERR_PARAM; + break; + } + + if (!cc || ((err = copy_all(dfd, filebuf, cc)) < 0)) + break; + } copyheader_done: - close(sfd); - close(dfd); - if (err < 0) { - unlink(ad_path(dst, ADFLAGS_HF)); - return err; - } - } + close(sfd); + close(dfd); + if (err < 0) { + unlink(ad_path(dst, ADFLAGS_HF)); + return err; + } + } } /* data fork copying */ if (( sfd = open( src, O_RDONLY, 0 )) < 0 ) { - switch ( errno ) { - case ENOENT : - return( AFPERR_NOOBJ ); - case EACCES : - return( AFPERR_ACCESS ); - default : - return( AFPERR_PARAM ); - } + switch ( errno ) { + case ENOENT : + return( AFPERR_NOOBJ ); + case EACCES : + return( AFPERR_ACCESS ); + default : + return( AFPERR_PARAM ); + } } if (( dfd = open( dst, O_WRONLY|O_CREAT, ad_mode( dst, 0666 ))) < 0 ) { - close( sfd ); - switch ( errno ) { - case ENOENT : - return( AFPERR_NOOBJ ); - case EACCES : - return( AFPERR_ACCESS ); - case EROFS: - return AFPERR_VLOCK; - default : - return( AFPERR_PARAM ); - } + close( sfd ); + switch ( errno ) { + case ENOENT : + return( AFPERR_NOOBJ ); + case EACCES : + return( AFPERR_ACCESS ); + case EROFS: + return AFPERR_VLOCK; + default : + return( AFPERR_PARAM ); + } } #ifdef SENDFILE_FLAVOR_LINUX if (fstat(sfd, &st) == 0) { - if ((cc = sendfile(dfd, sfd, NULL, st.st_size)) < 0) { - switch (errno) { - case EDQUOT: - case EFBIG: - case ENOSPC: - err = AFPERR_DFULL; - break; - default: - err = AFPERR_PARAM; - } - } - goto copydata_done; + if ((cc = sendfile(dfd, sfd, NULL, st.st_size)) < 0) { + switch (errno) { + case EDQUOT: + case EFBIG: + case ENOSPC: + err = AFPERR_DFULL; + break; + default: + err = AFPERR_PARAM; + } + } + goto copydata_done; } #endif /* SENDFILE_FLAVOR_LINUX */ while (1) { - if ((cc = read( sfd, filebuf, sizeof( filebuf ))) < 0) { - if (errno == EINTR) - continue; - - err = AFPERR_PARAM; - break; - } - - if (!cc || ((err = copy_all(dfd, filebuf, cc)) < 0)) { - break; - } - } - + if ((cc = read( sfd, filebuf, sizeof( filebuf ))) < 0) { + if (errno == EINTR) + continue; + + err = AFPERR_PARAM; + break; + } + + if (!cc || ((err = copy_all(dfd, filebuf, cc)) < 0)) { + break; + } + } + copydata_done: close(sfd); close(dfd); if (err < 0) { - unlink(ad_path(dst, ADFLAGS_HF)); - unlink(dst); - return err; + unlink(ad_path(dst, ADFLAGS_HF)); + unlink(dst); + return err; } if (newname) { - memset(&ad, 0, sizeof(ad)); - if ( ad_open( dst, noadouble | ADFLAGS_HF, O_RDWR|O_CREAT, - 0666, &ad) < 0 ) { - switch ( errno ) { - case ENOENT : - return noadouble ? AFP_OK : AFPERR_NOOBJ; - case EACCES : - return( AFPERR_ACCESS ); - case EROFS: - return AFPERR_VLOCK; - default : - return( AFPERR_PARAM ); - } - } - - len = strlen( newname ); - ad_setentrylen( &ad, ADEID_NAME, len ); - memcpy(ad_entry( &ad, ADEID_NAME ), newname, len ); - ad_flush( &ad, ADFLAGS_HF ); - ad_close( &ad, ADFLAGS_HF ); - } - + memset(&ad, 0, sizeof(ad)); + if ( ad_open( dst, noadouble | ADFLAGS_HF, O_RDWR|O_CREAT, + 0666, &ad) < 0 ) { + switch ( errno ) { + case ENOENT : + return noadouble ? AFP_OK : AFPERR_NOOBJ; + case EACCES : + return( AFPERR_ACCESS ); + case EROFS: + return AFPERR_VLOCK; + default : + return( AFPERR_PARAM ); + } + } + + len = strlen( newname ); + ad_setentrylen( &ad, ADEID_NAME, len ); + memcpy(ad_entry( &ad, ADEID_NAME ), newname, len ); + ad_flush( &ad, ADFLAGS_HF ); + ad_close( &ad, ADFLAGS_HF ); + } + #ifdef DEBUG syslog(LOG_INFO, "end copyfile:"); #endif /* DEBUG */ @@ -1159,7 +1159,7 @@ copydata_done: int deletefile( file ) - char *file; +char *file; { struct adouble ad; int adflags, err = AFP_OK; @@ -1171,104 +1171,104 @@ int deletefile( file ) #endif /* DEBUG */ while(1) { - /* - * If can't open read/write then try again read-only. If it's open - * read-only, we must do a read lock instead of a write lock. - */ - /* try to open both at once */ - adflags = ADFLAGS_DF|ADFLAGS_HF; - memset(&ad, 0, sizeof(ad)); - if ( ad_open( file, adflags, openmode, 0, &ad ) < 0 ) { - switch (errno) { - case ENOENT: - adflags = ADFLAGS_DF; - /* that failed. now try to open just the data fork */ - memset(&ad, 0, sizeof(ad)); - if ( ad_open( file, adflags, openmode, 0, &ad ) < 0 ) { - switch (errno) { - case ENOENT: - return AFPERR_NOOBJ; - case EACCES: - if(openmode == O_RDWR) { - openmode = O_RDONLY; - locktype = ADLOCK_RD; - continue; - } else { - return AFPERR_ACCESS; - } - case EROFS: - return AFPERR_VLOCK; - default: - return AFPERR_PARAM; - } - } - break; - - case EACCES: - if(openmode == O_RDWR) { - openmode = O_RDONLY; - locktype = ADLOCK_RD; - continue; - } else { - return AFPERR_ACCESS; - } - case EROFS: - return AFPERR_VLOCK; - default: - return( AFPERR_PARAM ); - } - } - break; /* from the while */ + /* + * If can't open read/write then try again read-only. If it's open + * read-only, we must do a read lock instead of a write lock. + */ + /* try to open both at once */ + adflags = ADFLAGS_DF|ADFLAGS_HF; + memset(&ad, 0, sizeof(ad)); + if ( ad_open( file, adflags, openmode, 0, &ad ) < 0 ) { + switch (errno) { + case ENOENT: + adflags = ADFLAGS_DF; + /* that failed. now try to open just the data fork */ + memset(&ad, 0, sizeof(ad)); + if ( ad_open( file, adflags, openmode, 0, &ad ) < 0 ) { + switch (errno) { + case ENOENT: + return AFPERR_NOOBJ; + case EACCES: + if(openmode == O_RDWR) { + openmode = O_RDONLY; + locktype = ADLOCK_RD; + continue; + } else { + return AFPERR_ACCESS; + } + case EROFS: + return AFPERR_VLOCK; + default: + return AFPERR_PARAM; + } + } + break; + + case EACCES: + if(openmode == O_RDWR) { + openmode = O_RDONLY; + locktype = ADLOCK_RD; + continue; + } else { + return AFPERR_ACCESS; + } + case EROFS: + return AFPERR_VLOCK; + default: + return( AFPERR_PARAM ); + } + } + break; /* from the while */ } if ((adflags & ADFLAGS_HF) && - (ad_tmplock(&ad, ADEID_RFORK, locktype, 0, 0) < 0 )) { - ad_close( &ad, adflags ); - return( AFPERR_BUSY ); + (ad_tmplock(&ad, ADEID_RFORK, locktype, 0, 0) < 0 )) { + ad_close( &ad, adflags ); + return( AFPERR_BUSY ); } if (ad_tmplock( &ad, ADEID_DFORK, locktype, 0, 0 ) < 0) { - err = AFPERR_BUSY; - goto delete_unlock; + err = AFPERR_BUSY; + goto delete_unlock; } if ( unlink( ad_path( file, ADFLAGS_HF )) < 0 ) { - switch ( errno ) { - case EPERM: - case EACCES : - err = AFPERR_ACCESS; - goto delete_unlock; - case EROFS: - err = AFPERR_VLOCK; - goto delete_unlock; - case ENOENT : - break; - default : - err = AFPERR_PARAM; + switch ( errno ) { + case EPERM: + case EACCES : + err = AFPERR_ACCESS; + goto delete_unlock; + case EROFS: + err = AFPERR_VLOCK; goto delete_unlock; - } + case ENOENT : + break; + default : + err = AFPERR_PARAM; + goto delete_unlock; + } } if ( unlink( file ) < 0 ) { - switch ( errno ) { - case EPERM: - case EACCES : - err = AFPERR_ACCESS; - break; - case EROFS: - err = AFPERR_VLOCK; - break; - case ENOENT : - break; - default : - err = AFPERR_PARAM; - break; - } + switch ( errno ) { + case EPERM: + case EACCES : + err = AFPERR_ACCESS; + break; + case EROFS: + err = AFPERR_VLOCK; + break; + case ENOENT : + break; + default : + err = AFPERR_PARAM; + break; + } } delete_unlock: if (adflags & ADFLAGS_HF) - ad_tmplock(&ad, ADEID_RFORK, ADLOCK_CLR, 0, 0); + ad_tmplock(&ad, ADEID_RFORK, ADLOCK_CLR, 0, 0); ad_tmplock(&ad, ADEID_DFORK, ADLOCK_CLR, 0, 0); ad_close( &ad, adflags ); @@ -1283,9 +1283,9 @@ delete_unlock: #ifdef CNID_DB /* return a file id */ int afp_createid(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct stat st; struct adouble ad; @@ -1307,7 +1307,7 @@ int afp_createid(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof(vid); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM); + return( AFPERR_PARAM); } if (vol->v_flags & AFPVOL_RO) @@ -1317,48 +1317,48 @@ int afp_createid(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof(did); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if ( *path == '\0' ) { - return( AFPERR_BADTYPE ); + return( AFPERR_BADTYPE ); } upath = mtoupath(vol, path); if (stat(upath, &st) < 0) { - switch (errno) { - case EPERM: - case EACCES: - return AFPERR_ACCESS; - case ENOENT: - return AFPERR_NOOBJ; - default: - return AFPERR_PARAM; - } + switch (errno) { + case EPERM: + case EACCES: + return AFPERR_ACCESS; + case ENOENT: + return AFPERR_NOOBJ; + default: + return AFPERR_PARAM; + } } if (id = cnid_lookup(vol->v_db, &st, did, upath, len = strlen(upath))) { - memcpy(rbuf, &id, sizeof(id)); - *rbuflen = sizeof(id); - return AFPERR_EXISTID; + memcpy(rbuf, &id, sizeof(id)); + *rbuflen = sizeof(id); + return AFPERR_EXISTID; } #if AD_VERSION > AD_VERSION1 memset(&ad, 0, sizeof(ad)); if (ad_open( upath, ADFLAGS_HF, O_RDONLY, 0, &ad ) >= 0) { - memcpy(&id, ad_entry(&ad, ADEID_DID), sizeof(id)); - ad_close(&ad, ADFLAGS_HF); + memcpy(&id, ad_entry(&ad, ADEID_DID), sizeof(id)); + ad_close(&ad, ADFLAGS_HF); } #endif /* AD_VERSION > AD_VERSION1 */ if (id = cnid_add(vol->v_db, &st, did, upath, len, id)) { - memcpy(rbuf, &id, sizeof(id)); - *rbuflen = sizeof(id); - return AFP_OK; + memcpy(rbuf, &id, sizeof(id)); + *rbuflen = sizeof(id); + return AFP_OK; } #ifdef DEBUG @@ -1367,23 +1367,23 @@ int afp_createid(obj, ibuf, ibuflen, rbuf, rbuflen ) switch (errno) { case EROFS: - return AFPERR_VLOCK; - break; + return AFPERR_VLOCK; + break; case EPERM: case EACCES: - return AFPERR_ACCESS; - break; + return AFPERR_ACCESS; + break; default: - syslog(LOG_ERR, "afp_createid: cnid_add: %m"); - return AFPERR_PARAM; + syslog(LOG_ERR, "afp_createid: cnid_add: %m"); + return AFPERR_PARAM; } } /* resolve a file id */ int afp_resolveid(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct stat st; struct vol *vol; @@ -1404,42 +1404,42 @@ int afp_resolveid(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof(vid); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM); + return( AFPERR_PARAM); } memcpy(&id, ibuf, sizeof( id )); ibuf += sizeof(id); if ((upath = cnid_resolve(vol->v_db, &id)) == NULL) { - return AFPERR_BADID; + return AFPERR_BADID; } if (( dir = dirsearch( vol, id )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if ((movecwd(vol, dir) < 0) || (stat(upath, &st) < 0)) { - switch (errno) { - case EACCES: - case EPERM: - return AFPERR_ACCESS; - case ENOENT: - return AFPERR_NOID; - default: - return AFPERR_PARAM; - } + switch (errno) { + case EACCES: + case EPERM: + return AFPERR_ACCESS; + case ENOENT: + return AFPERR_NOID; + default: + return AFPERR_PARAM; + } } /* directories are bad */ if (S_ISDIR(st.st_mode)) - return AFPERR_BADTYPE; + return AFPERR_BADTYPE; memcpy(&bitmap, ibuf, sizeof(bitmap)); bitmap = ntohs( bitmap ); if ((err = getfilparams(vol, bitmap, utompath(vol, upath), curdir, &st, - rbuf + sizeof(bitmap), &buflen)) != AFP_OK) - return err; + rbuf + sizeof(bitmap), &buflen)) != AFP_OK) + return err; *rbuflen = buflen + sizeof(bitmap); memcpy(rbuf, ibuf, sizeof(bitmap)); @@ -1452,9 +1452,9 @@ int afp_resolveid(obj, ibuf, ibuflen, rbuf, rbuflen ) } int afp_deleteid(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct stat st; struct vol *vol; @@ -1475,7 +1475,7 @@ int afp_deleteid(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof(vid); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM); + return( AFPERR_PARAM); } if (vol->v_flags & AFPVOL_RO) @@ -1485,42 +1485,42 @@ int afp_deleteid(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof(id); if ((upath = cnid_resolve(vol->v_db, &id)) == NULL) { - return AFPERR_NOID; + return AFPERR_NOID; } if (( dir = dirsearch( vol, id )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } err = AFP_OK; if ((movecwd(vol, dir) < 0) || (stat(upath, &st) < 0)) { - switch (errno) { - case EACCES: - case EPERM: - return AFPERR_ACCESS; - case ENOENT: - /* still try to delete the id */ - err = AFPERR_NOOBJ; - break; - default: - return AFPERR_PARAM; - } + switch (errno) { + case EACCES: + case EPERM: + return AFPERR_ACCESS; + case ENOENT: + /* still try to delete the id */ + err = AFPERR_NOOBJ; + break; + default: + return AFPERR_PARAM; + } } /* directories are bad */ if (S_ISDIR(st.st_mode)) - return AFPERR_BADTYPE; + return AFPERR_BADTYPE; if (cnid_delete(vol->v_db, id)) { - switch (errno) { - case EROFS: - return AFPERR_VLOCK; - case EPERM: - case EACCES: - return AFPERR_ACCESS; - default: - return AFPERR_PARAM; - } + switch (errno) { + case EROFS: + return AFPERR_VLOCK; + case EPERM: + case EACCES: + return AFPERR_ACCESS; + default: + return AFPERR_PARAM; + } } #ifdef DEBUG @@ -1534,9 +1534,9 @@ int afp_deleteid(obj, ibuf, ibuflen, rbuf, rbuflen ) #define APPLETEMP ".AppleTempXXXXXX" int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct stat srcst, destst; struct vol *vol; @@ -1561,7 +1561,7 @@ int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof(vid); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM); + return( AFPERR_PARAM); } if (vol->v_flags & AFPVOL_RO) @@ -1575,28 +1575,28 @@ int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen ) /* source file */ if ((dir = dirsearch( vol, sid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if ( *path == '\0' ) { - return( AFPERR_BADTYPE ); + return( AFPERR_BADTYPE ); } upath = mtoupath(vol, path); if (stat(upath, &srcst) < 0) { - switch (errno) { - case ENOENT: - return AFPERR_NOID; - case EPERM: - case EACCES: - return AFPERR_ACCESS; - default: - return AFPERR_PARAM; - } + switch (errno) { + case ENOENT: + return AFPERR_NOID; + case EPERM: + case EACCES: + return AFPERR_ACCESS; + default: + return AFPERR_PARAM; + } } /* save some stuff */ @@ -1611,43 +1611,43 @@ int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen ) * it. */ #ifdef CNID_DB sid = cnid_lookup(vol->v_db, &srcst, sdir->d_did, supath, - slen = strlen(supath)); + slen = strlen(supath)); #endif /* CNID_DB */ if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if ( *path == '\0' ) { - return( AFPERR_BADTYPE ); + return( AFPERR_BADTYPE ); } /* FPExchangeFiles is the only call that can return the SameObj * error */ if ((curdir == sdir) && strcmp(spath, path) == 0) - return AFPERR_SAMEOBJ; + return AFPERR_SAMEOBJ; upath = mtoupath(vol, path); if (stat(upath, &destst) < 0) { - switch (errno) { - case ENOENT: - return AFPERR_NOID; - case EPERM: - case EACCES: - return AFPERR_ACCESS; - default: - return AFPERR_PARAM; - } + switch (errno) { + case ENOENT: + return AFPERR_NOID; + case EPERM: + case EACCES: + return AFPERR_ACCESS; + default: + return AFPERR_PARAM; + } } #ifdef CNID_DB /* look for destination id. */ did = cnid_lookup(vol->v_db, &destst, curdir->d_did, upath, - dlen = strlen(upath)); + dlen = strlen(upath)); #endif /* CNID_DB */ /* construct a temp name. @@ -1655,50 +1655,50 @@ int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen ) * will also be inaccessible from AFP. */ memcpy(temp, APPLETEMP, sizeof(APPLETEMP)); if (!mktemp(temp)) - return AFPERR_MISC; + return AFPERR_MISC; /* now, quickly rename the file. we error if we can't. */ if ((err = renamefile(p, temp, temp, vol_noadouble(vol))) < 0) - goto err_exchangefile; + goto err_exchangefile; of_rename(vol, sdir, spath, curdir, temp); /* rename destination to source */ if ((err = renamefile(path, p, spath, vol_noadouble(vol))) < 0) - goto err_src_to_tmp; + goto err_src_to_tmp; of_rename(vol, curdir, path, sdir, spath); /* rename temp to destination */ - if ((err = renamefile(temp, upath, path, vol_noadouble(vol))) < 0) - goto err_dest_to_src; + if ((err = renamefile(temp, upath, path, vol_noadouble(vol))) < 0) + goto err_dest_to_src; of_rename(vol, curdir, temp, curdir, path); - + #ifdef CNID_DB /* id's need switching. src -> dest and dest -> src. */ if (sid && (cnid_update(vol->v_db, sid, &destst, curdir->d_did, - upath, dlen) < 0)) { - switch (errno) { - case EPERM: - case EACCES: - err = AFPERR_ACCESS; - default: - err = AFPERR_PARAM; - } - goto err_temp_to_dest; + upath, dlen) < 0)) { + switch (errno) { + case EPERM: + case EACCES: + err = AFPERR_ACCESS; + default: + err = AFPERR_PARAM; + } + goto err_temp_to_dest; } if (did && (cnid_update(vol->v_db, did, &srcst, sdir->d_did, - supath, slen) < 0)) { - switch (errno) { - case EPERM: - case EACCES: - err = AFPERR_ACCESS; - default: - err = AFPERR_PARAM; - } - - if (sid) - cnid_update(vol->v_db, sid, &srcst, sdir->d_did, supath, slen); - goto err_temp_to_dest; + supath, slen) < 0)) { + switch (errno) { + case EPERM: + case EACCES: + err = AFPERR_ACCESS; + default: + err = AFPERR_PARAM; + } + + if (sid) + cnid_update(vol->v_db, sid, &srcst, sdir->d_did, supath, slen); + goto err_temp_to_dest; } #endif /* CNID_DB */ diff --git a/etc/afpd/file.h b/etc/afpd/file.h index e0dde7af..bcce9eea 100644 --- a/etc/afpd/file.h +++ b/etc/afpd/file.h @@ -1,5 +1,5 @@ /* - * $Id: file.h,v 1.3 2001-08-14 14:00:10 rufustfirefly Exp $ + * $Id: file.h,v 1.3.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1991 Regents of The University of Michigan. * All Rights Reserved. @@ -74,9 +74,9 @@ struct extmap { extern struct extmap *extmap; extern struct extmap *getextmap __P((const char *)); -extern int getfilparams __P((struct vol *, u_int16_t, char *, - struct dir *, struct stat *, char *buf, - int *)); +extern int getfilparams __P((struct vol *, u_int16_t, char *, + struct dir *, struct stat *, char *buf, + int *)); extern int setfilparams __P((struct vol *, char *, u_int16_t, char *)); extern int renamefile __P((char *, char *, char *, const int)); extern int copyfile __P((char *, char *, char *, const int)); diff --git a/etc/afpd/filedir.c b/etc/afpd/filedir.c index c8c80118..b8204d0b 100644 --- a/etc/afpd/filedir.c +++ b/etc/afpd/filedir.c @@ -1,5 +1,5 @@ /* - * $Id: filedir.c,v 1.15 2001-10-23 13:44:37 rufustfirefly Exp $ + * $Id: filedir.c,v 1.15.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -56,14 +56,14 @@ char *strchr (), *strrchr (); #include "filedir.h" int matchfile2dirperms(upath, vol, did) - /* Since it's kinda' big; I decided against an - inline function */ - char *upath; - struct vol *vol; - int did; - /* The below code changes the way file ownership is determined in the name of - fixing dropboxes. It has known security problem. See the netatalk FAQ for - more information */ +/* Since it's kinda' big; I decided against an +inline function */ +char *upath; +struct vol *vol; +int did; +/* The below code changes the way file ownership is determined in the name of +fixing dropboxes. It has known security problem. See the netatalk FAQ for +more information */ { struct stat st, sb; struct dir *dir; @@ -75,69 +75,69 @@ int matchfile2dirperms(upath, vol, did) #endif /* DEBUG */ if (stat(upath, &st ) < 0) - syslog(LOG_ERR, "Could not stat %s: %s", upath, strerror(errno)); + syslog(LOG_ERR, "Could not stat %s: %s", upath, strerror(errno)); strcpy (adpath, "./.AppleDouble/"); strcat (adpath, upath); if (( dir = dirsearch( vol, did )) == NULL ) { - syslog (LOG_ERR, "matchfile2dirperms: Unable to get directory info."); - return( AFPERR_NOOBJ ); + syslog (LOG_ERR, "matchfile2dirperms: Unable to get directory info."); + return( AFPERR_NOOBJ ); } else if (stat(".", &sb) < 0) { - syslog (LOG_ERR, - "matchfile2dirperms: Error checking directory \"%s\": %s", - dir->d_name, strerror(errno)); + syslog (LOG_ERR, + "matchfile2dirperms: Error checking directory \"%s\": %s", + dir->d_name, strerror(errno)); return(AFPERR_NOOBJ ); - } + } else { - uid=geteuid(); - if ( uid != sb.st_uid ) + uid=geteuid(); + if ( uid != sb.st_uid ) { - seteuid(0); - if (lchown(upath, sb.st_uid, sb.st_gid) < 0) - { - syslog (LOG_ERR, - "matchfile2dirperms: Error changing owner/gid of %s: %s", - upath, strerror(errno)); - return (AFPERR_ACCESS); - } - if (chmod(upath,(st.st_mode&0777&~default_options.umask)| S_IRGRP| S_IROTH) < 0) - { - syslog (LOG_ERR, - "matchfile2dirperms: Error adding file read permissions: %s", - strerror(errno)); - return (AFPERR_ACCESS); - } + seteuid(0); + if (lchown(upath, sb.st_uid, sb.st_gid) < 0) + { + syslog (LOG_ERR, + "matchfile2dirperms: Error changing owner/gid of %s: %s", + upath, strerror(errno)); + return (AFPERR_ACCESS); + } + if (chmod(upath,(st.st_mode&0777&~default_options.umask)| S_IRGRP| S_IROTH) < 0) + { + syslog (LOG_ERR, + "matchfile2dirperms: Error adding file read permissions: %s", + strerror(errno)); + return (AFPERR_ACCESS); + } #ifdef DEBUG - else - syslog (LOG_INFO, - "matchfile2dirperms: Added S_IRGRP and S_IROTH: %s", - strerror(errno)); + else + syslog (LOG_INFO, + "matchfile2dirperms: Added S_IRGRP and S_IROTH: %s", + strerror(errno)); #endif /* DEBUG */ - if (lchown(adpath, sb.st_uid, sb.st_gid) < 0) - { - syslog (LOG_ERR, - "matchfile2dirperms: Error changing AppleDouble owner/gid %s: %s", - adpath, strerror(errno)); - return (AFPERR_ACCESS); - } - if (chmod(adpath, (st.st_mode&0777&~default_options.umask)| S_IRGRP| S_IROTH) < 0) - { - syslog (LOG_ERR, - "matchfile2dirperms: Error adding AD file read permissions: %s", - strerror(errno)); - return (AFPERR_ACCESS); - } + if (lchown(adpath, sb.st_uid, sb.st_gid) < 0) + { + syslog (LOG_ERR, + "matchfile2dirperms: Error changing AppleDouble owner/gid %s: %s", + adpath, strerror(errno)); + return (AFPERR_ACCESS); + } + if (chmod(adpath, (st.st_mode&0777&~default_options.umask)| S_IRGRP| S_IROTH) < 0) + { + syslog (LOG_ERR, + "matchfile2dirperms: Error adding AD file read permissions: %s", + strerror(errno)); + return (AFPERR_ACCESS); + } #ifdef DEBUG - else - syslog (LOG_INFO, - "matchfile2dirperms: Added S_IRGRP and S_IROTH to AD: %s", - strerror(errno)); + else + syslog (LOG_INFO, + "matchfile2dirperms: Added S_IRGRP and S_IROTH to AD: %s", + strerror(errno)); #endif /* DEBUG */ - } + } #ifdef DEBUG else - syslog (LOG_INFO, - "matchfile2dirperms: No ownership change necessary."); + syslog (LOG_INFO, + "matchfile2dirperms: No ownership change necessary."); #endif /* DEBUG */ } /* end else if stat success */ seteuid(uid); /* Restore process ownership to normal */ @@ -148,12 +148,12 @@ int matchfile2dirperms(upath, vol, did) return (AFP_OK); } - + int afp_getfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct stat st; struct vol *vol; @@ -173,14 +173,14 @@ int afp_getfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memcpy( &did, ibuf, sizeof( did )); ibuf += sizeof( did ); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } memcpy( &fbitmap, ibuf, sizeof( fbitmap )); @@ -191,30 +191,30 @@ int afp_getfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( dbitmap ); if (( path = cname( vol, dir, &ibuf )) == NULL) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ( stat( mtoupath(vol, path ), &st ) < 0 ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } buflen = 0; if (S_ISDIR(st.st_mode)) { - if (dbitmap) { - ret = getdirparams(vol, dbitmap, ".", curdir, - &st, rbuf + 3 * sizeof( u_int16_t ), &buflen ); - if (ret != AFP_OK ) - return( ret ); - } + if (dbitmap) { + ret = getdirparams(vol, dbitmap, ".", curdir, + &st, rbuf + 3 * sizeof( u_int16_t ), &buflen ); + if (ret != AFP_OK ) + return( ret ); + } /* this is a directory */ - *(rbuf + 2 * sizeof( u_int16_t )) = (char) FILDIRBIT_ISDIR; + *(rbuf + 2 * sizeof( u_int16_t )) = (char) FILDIRBIT_ISDIR; } else { - if (fbitmap && ( ret = getfilparams(vol, fbitmap, path, curdir, &st, - rbuf + 3 * sizeof( u_int16_t ), &buflen )) != AFP_OK ) { - return( ret ); - } + if (fbitmap && ( ret = getfilparams(vol, fbitmap, path, curdir, &st, + rbuf + 3 * sizeof( u_int16_t ), &buflen )) != AFP_OK ) { + return( ret ); + } /* this is a file */ - *(rbuf + 2 * sizeof( u_int16_t )) = FILDIRBIT_ISFILE; + *(rbuf + 2 * sizeof( u_int16_t )) = FILDIRBIT_ISFILE; } *rbuflen = buflen + 3 * sizeof( u_int16_t ); fbitmap = htons( fbitmap ); @@ -233,9 +233,9 @@ int afp_getfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen ) } int afp_setfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct stat st; struct vol *vol; @@ -254,7 +254,7 @@ int afp_setfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (vol->v_flags & AFPVOL_RO) @@ -264,7 +264,7 @@ int afp_setfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( did); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } memcpy( &bitmap, ibuf, sizeof( bitmap )); @@ -272,27 +272,27 @@ int afp_setfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( bitmap ); if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ( stat( mtoupath(vol, path ), &st ) < 0 ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } /* * If ibuf is odd, make it even. */ if ((u_long)ibuf & 1 ) { - ibuf++; + ibuf++; } if (S_ISDIR(st.st_mode)) { - rc = setdirparams(vol, path, bitmap, ibuf ); + rc = setdirparams(vol, path, bitmap, ibuf ); } else { - rc = setfilparams(vol, path, bitmap, ibuf ); + rc = setfilparams(vol, path, bitmap, ibuf ); } if ( rc == AFP_OK ) { - setvoltime(obj, vol ); + setvoltime(obj, vol ); } #ifdef DEBUG @@ -303,9 +303,9 @@ int afp_setfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen ) } int afp_rename(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct adouble ad; struct stat st; @@ -330,7 +330,7 @@ int afp_rename(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (vol->v_flags & AFPVOL_RO) @@ -339,34 +339,34 @@ int afp_rename(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &did, ibuf, sizeof( did )); ibuf += sizeof( did ); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } /* another place where we know about the path type */ if ( *ibuf++ != 2 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } plen = (unsigned char) *ibuf++; *( ibuf + plen ) = '\0'; if ( *path == '\0' ) { if ( curdir->d_parent == NULL ) { /* root directory */ - return( AFPERR_NORENAME ); - } - odir = curdir; - path = curdir->d_name; - if ( movecwd( vol, curdir->d_parent ) < 0 ) { - return( AFPERR_NOOBJ ); - } + return( AFPERR_NORENAME ); + } + odir = curdir; + path = curdir->d_name; + if ( movecwd( vol, curdir->d_parent ) < 0 ) { + return( AFPERR_NOOBJ ); + } } #ifdef notdef if ( strcasecmp( path, ibuf ) == 0 ) { - return( AFP_OK ); + return( AFP_OK ); } #endif /* notdef */ @@ -379,18 +379,18 @@ int afp_rename(obj, ibuf, ibuflen, rbuf, rbuflen ) return AFP_OK; /* check for illegal characters */ - if ((vol->v_flags & AFPVOL_MSWINDOWS) && - strpbrk(ibuf, MSWINDOWS_BADCHARS)) + if ((vol->v_flags & AFPVOL_MSWINDOWS) && + strpbrk(ibuf, MSWINDOWS_BADCHARS)) return AFPERR_PARAM; newpath = obj->oldtmp; strcpy( newpath, mtoupath(vol, ibuf )); if ((vol->v_flags & AFPVOL_NOHEX) && strchr(newpath, '/')) - return AFPERR_PARAM; + return AFPERR_PARAM; if (!validupath(vol, newpath)) - return AFPERR_EXIST; + return AFPERR_EXIST; /* check for vetoed filenames */ if (veto_file(vol->v_veto, newpath)) @@ -399,7 +399,7 @@ int afp_rename(obj, ibuf, ibuflen, rbuf, rbuflen ) /* the strdiacasecmp deals with case-insensitive, case preserving filesystems */ if (stat( newpath, &st ) == 0 && strdiacasecmp(path, ibuf)) - return( AFPERR_EXIST ); + return( AFPERR_EXIST ); upath = mtoupath(vol, path); @@ -408,62 +408,62 @@ int afp_rename(obj, ibuf, ibuflen, rbuf, rbuflen ) #endif /* CNID_DB */ if ( rename( upath, newpath ) < 0 ) { - switch ( errno ) { - case ENOENT : - return( AFPERR_NOOBJ ); - case EACCES : - return( AFPERR_ACCESS ); - default : - return( AFPERR_PARAM ); - } + switch ( errno ) { + case ENOENT : + return( AFPERR_NOOBJ ); + case EACCES : + return( AFPERR_ACCESS ); + default : + return( AFPERR_PARAM ); + } } #ifdef CNID_DB if (stat(newpath, &st) < 0) /* this shouldn't fail */ - return AFPERR_MISC; + return AFPERR_MISC; cnid_update(vol->v_db, id, &st, curdir->d_did, newpath, strlen(newpath)); #endif /* CNID_DB */ if ( !odir ) { newadpath = obj->newtmp; - strcpy( newadpath, ad_path( newpath, 0 )); - if ( rename( ad_path( upath, 0 ), newadpath ) < 0 ) { - if ( errno == ENOENT ) { /* no adouble header file */ - if (( unlink( newadpath ) < 0 ) && ( errno != ENOENT )) { - return( AFPERR_PARAM ); - } - goto out; - } - return( AFPERR_PARAM ); - } - - memset(&ad, 0, sizeof(ad)); - if ( ad_open( newpath, ADFLAGS_HF, O_RDWR|O_CREAT, 0666, - &ad) < 0 ) { - return( AFPERR_PARAM ); - } + strcpy( newadpath, ad_path( newpath, 0 )); + if ( rename( ad_path( upath, 0 ), newadpath ) < 0 ) { + if ( errno == ENOENT ) { /* no adouble header file */ + if (( unlink( newadpath ) < 0 ) && ( errno != ENOENT )) { + return( AFPERR_PARAM ); + } + goto out; + } + return( AFPERR_PARAM ); + } + + memset(&ad, 0, sizeof(ad)); + if ( ad_open( newpath, ADFLAGS_HF, O_RDWR|O_CREAT, 0666, + &ad) < 0 ) { + return( AFPERR_PARAM ); + } } else { int isad = 1; - memset(&ad, 0, sizeof(ad)); - if ( ad_open( newpath, vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR, - O_RDWR|O_CREAT, 0666, &ad) < 0 ) { - if (!((errno == ENOENT) && vol_noadouble(vol))) - return( AFPERR_PARAM ); - isad = 0; - } - if ((buf = realloc( odir->d_name, plen + 1 )) == NULL ) { - syslog( LOG_ERR, "afp_rename: realloc: %s", strerror(errno) ); - if (isad) { - ad_flush(&ad, ADFLAGS_HF); /* in case of create */ - ad_close(&ad, ADFLAGS_HF); - } - return AFPERR_MISC; - } - odir->d_name = buf; - strcpy( odir->d_name, ibuf ); - if (!isad) - goto out; + memset(&ad, 0, sizeof(ad)); + if ( ad_open( newpath, vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR, + O_RDWR|O_CREAT, 0666, &ad) < 0 ) { + if (!((errno == ENOENT) && vol_noadouble(vol))) + return( AFPERR_PARAM ); + isad = 0; + } + if ((buf = realloc( odir->d_name, plen + 1 )) == NULL ) { + syslog( LOG_ERR, "afp_rename: realloc: %s", strerror(errno) ); + if (isad) { + ad_flush(&ad, ADFLAGS_HF); /* in case of create */ + ad_close(&ad, ADFLAGS_HF); + } + return AFPERR_MISC; + } + odir->d_name = buf; + strcpy( odir->d_name, ibuf ); + if (!isad) + goto out; } ad_setentrylen( &ad, ADEID_NAME, plen ); @@ -476,7 +476,7 @@ out: /* if it's still open, rename the ofork as well. */ if (of_rename(vol, curdir, path, curdir, ibuf) < 0) - return AFPERR_MISC; + return AFPERR_MISC; #ifdef DEBUG syslog(LOG_INFO, "end afp_rename:"); @@ -487,9 +487,9 @@ out: int afp_delete(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol; struct dir *dir; @@ -507,7 +507,7 @@ int afp_delete(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (vol->v_flags & AFPVOL_RO) @@ -516,25 +516,25 @@ int afp_delete(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &did, ibuf, sizeof( did )); ibuf += sizeof( int ); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ( *path == '\0' ) { - rc = deletecurdir( vol, obj->oldtmp, AFPOBJ_TMPSIZ); + rc = deletecurdir( vol, obj->oldtmp, AFPOBJ_TMPSIZ); } else if (of_findname(vol, curdir, path)) { rc = AFPERR_BUSY; } else if ((rc = deletefile( upath = mtoupath(vol, path ))) == AFP_OK) { #ifdef CNID_DB /* get rid of entry */ cnid_t id = cnid_get(vol->v_db, curdir->d_did, upath, strlen(upath)); - cnid_delete(vol->v_db, id); + cnid_delete(vol->v_db, id); #endif /* CNID_DB */ } if ( rc == AFP_OK ) { - setvoltime(obj, vol ); + setvoltime(obj, vol ); } #ifdef DEBUG @@ -545,9 +545,9 @@ int afp_delete(obj, ibuf, ibuflen, rbuf, rbuflen ) } char *ctoupath( vol, dir, name ) - const struct vol *vol; - struct dir *dir; - char *name; +const struct vol *vol; +struct dir *dir; +char *name; { struct dir *d; static char path[ MAXPATHLEN + 1]; @@ -561,11 +561,11 @@ char *ctoupath( vol, dir, name ) p -= len; strncpy( p, u, len ); for ( d = dir; d->d_parent; d = d->d_parent ) { - *--p = '/'; - u = mtoupath(vol, d->d_name ); - len = strlen( u ); - p -= len; - strncpy( p, u, len ); + *--p = '/'; + u = mtoupath(vol, d->d_name ); + len = strlen( u ); + p -= len; + strncpy( p, u, len ); } *--p = '/'; len = strlen( vol->v_path ); @@ -577,15 +577,15 @@ char *ctoupath( vol, dir, name ) int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol; struct dir *sdir, *ddir, *odir = NULL; struct stat st; char *oldname, *newname; - char *path, *p, *upath; + char *path, *p, *upath; int did, rc; int plen; u_int16_t vid; @@ -606,7 +606,7 @@ int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &vid, ibuf, sizeof( vid )); ibuf += sizeof( vid ); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (vol->v_flags & AFPVOL_RO) @@ -616,7 +616,7 @@ int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy( &did, ibuf, sizeof( did )); ibuf += sizeof( int ); if (( sdir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memcpy( &did, ibuf, sizeof( did )); @@ -624,7 +624,7 @@ int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen ) /* source pathname */ if (( path = cname( vol, sdir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } sdir = curdir; @@ -632,20 +632,20 @@ int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen ) oldname = obj->oldtmp; if ( *path != '\0' ) { /* not a directory */ - strcpy(newname, path); - strcpy(oldname, path); /* an extra copy for of_rename */ + strcpy(newname, path); + strcpy(oldname, path); /* an extra copy for of_rename */ #ifdef CNID_DB - p = mtoupath(vol, path); - id = cnid_get(vol->v_db, sdir->d_did, p, strlen(p)); + p = mtoupath(vol, path); + id = cnid_get(vol->v_db, sdir->d_did, p, strlen(p)); #endif /* CNID_DB */ - p = ctoupath( vol, sdir, newname ); + p = ctoupath( vol, sdir, newname ); } else { - odir = curdir; - strcpy( newname, odir->d_name ); - strcpy(oldname, odir->d_name); - p = ctoupath( vol, odir->d_parent, newname ); + odir = curdir; + strcpy( newname, odir->d_name ); + strcpy(oldname, odir->d_name); + p = ctoupath( vol, odir->d_parent, newname ); #ifdef CNID_DB - id = curdir->d_did; /* we already have the CNID */ + id = curdir->d_did; /* we already have the CNID */ #endif /* CNID_DB */ } /* @@ -654,37 +654,37 @@ int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen ) /* get the destination directory */ if (( ddir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (( path = cname( vol, ddir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ( *path != '\0' ) { - return( AFPERR_BADTYPE ); + return( AFPERR_BADTYPE ); } /* one more place where we know about path type */ if ( *ibuf++ != 2 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (( plen = (unsigned char)*ibuf++ ) != 0 ) { - strncpy( newname, ibuf, plen ); - newname[ plen ] = '\0'; + strncpy( newname, ibuf, plen ); + newname[ plen ] = '\0'; } /* check for illegal characters */ - if ((vol->v_flags & AFPVOL_MSWINDOWS) && - strpbrk(newname, MSWINDOWS_BADCHARS)) + if ((vol->v_flags & AFPVOL_MSWINDOWS) && + strpbrk(newname, MSWINDOWS_BADCHARS)) return AFPERR_PARAM; upath = mtoupath(vol, newname); if ((vol->v_flags & AFPVOL_NOHEX) && strchr(upath, '/')) - return AFPERR_PARAM; + return AFPERR_PARAM; if (!validupath(vol, upath)) - return AFPERR_EXIST; + return AFPERR_EXIST; /* check for vetoed filenames */ if (veto_file(vol->v_veto, upath)) @@ -692,32 +692,32 @@ int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen ) /* source == destination. we just silently accept this. */ if (curdir == sdir) { - if (strcmp(oldname, newname) == 0) - return AFP_OK; - - /* deal with case insensitive, case-preserving filesystems. */ - if ((stat(upath, &st) == 0) && strdiacasecmp(oldname, newname)) - return AFPERR_EXIST; - + if (strcmp(oldname, newname) == 0) + return AFP_OK; + + /* deal with case insensitive, case-preserving filesystems. */ + if ((stat(upath, &st) == 0) && strdiacasecmp(oldname, newname)) + return AFPERR_EXIST; + } else if (stat(upath, &st ) == 0) - return( AFPERR_EXIST ); - + return( AFPERR_EXIST ); + if ( !odir ) { - if (of_findname(vol, curdir, newname)) { - rc = AFPERR_BUSY; - } else if ((rc = renamefile( p, upath, newname, - vol_noadouble(vol) )) == AFP_OK) { - /* if it's still open, rename the ofork as well. */ - rc = of_rename(vol, sdir, oldname, curdir, newname); - } + if (of_findname(vol, curdir, newname)) { + rc = AFPERR_BUSY; + } else if ((rc = renamefile( p, upath, newname, + vol_noadouble(vol) )) == AFP_OK) { + /* if it's still open, rename the ofork as well. */ + rc = of_rename(vol, sdir, oldname, curdir, newname); + } } else { - rc = renamedir(p, upath, odir, curdir, newname, vol_noadouble(vol)); + rc = renamedir(p, upath, odir, curdir, newname, vol_noadouble(vol)); } #ifdef DROPKLUDGE if (vol->v_flags & AFPVOL_DROPBOX) { if (retvalue=matchfile2dirperms (newname, vol, did) != AFP_OK) { - return retvalue; + return retvalue; } } #endif /* DROPKLUDGE */ @@ -726,12 +726,12 @@ int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen ) #ifdef CNID_DB /* renaming may have moved the file/dir across a filesystem */ if (stat(upath, &st) < 0) - return AFPERR_MISC; + return AFPERR_MISC; - /* fix up the catalog entry */ - cnid_update(vol->v_db, id, &st, curdir->d_did, upath, strlen(upath)); + /* fix up the catalog entry */ + cnid_update(vol->v_db, id, &st, curdir->d_did, upath, strlen(upath)); #endif /* CNID_DB */ - setvoltime(obj, vol ); + setvoltime(obj, vol ); } #ifdef DEBUG @@ -748,32 +748,32 @@ int veto_file(const char*veto_str, const char*path) * otherwise, 0 is returned. */ { - int i; /* index to veto_str */ - int j; /* index to path */ + int i; /* index to veto_str */ + int j; /* index to path */ - if ((veto_str == NULL) || (path == NULL)) - return 0; -/* -#ifdef DEBUG - syslog(LOG_DEBUG, "veto_file \"%s\", \"%s\"", veto_str, path); -#endif -*/ - for(i=0, j=0; veto_str[i] != '\0'; i++) { - if (veto_str[i] == '/') { - if ((j>0) && (path[j] == '\0')) - return 1; - j = 0; - } else { - if (veto_str[i] != path[j]) { - while ((veto_str[i] != '/') - && (veto_str[i] != '\0')) - i++; - j = 0; - continue; - } - j++; - } - } - return 0; + if ((veto_str == NULL) || (path == NULL)) + return 0; + /* + #ifdef DEBUG + syslog(LOG_DEBUG, "veto_file \"%s\", \"%s\"", veto_str, path); + #endif + */ + for(i=0, j=0; veto_str[i] != '\0'; i++) { + if (veto_str[i] == '/') { + if ((j>0) && (path[j] == '\0')) + return 1; + j = 0; + } else { + if (veto_str[i] != path[j]) { + while ((veto_str[i] != '/') + && (veto_str[i] != '\0')) + i++; + j = 0; + continue; + } + j++; + } + } + return 0; } diff --git a/etc/afpd/filedir.h b/etc/afpd/filedir.h index a0061c28..14868dbf 100644 --- a/etc/afpd/filedir.h +++ b/etc/afpd/filedir.h @@ -1,5 +1,5 @@ /* - * $Id: filedir.h,v 1.5 2001-10-23 13:44:37 rufustfirefly Exp $ + * $Id: filedir.h,v 1.5.2.1 2001-12-03 05:01:04 jmarcus Exp $ */ #ifndef AFPD_FILEDIR_H @@ -12,8 +12,8 @@ extern struct afp_options default_options; -extern char *ctoupath __P((const struct vol *, struct dir *, - char *)); +extern char *ctoupath __P((const struct vol *, struct dir *, + char *)); extern int veto_file __P((const char *veto_str, const char *path)); /* FP functions */ @@ -21,9 +21,9 @@ extern int matchfile2dirperms __P((char *, struct vol *, int)); extern int afp_moveandrename __P((AFPObj *, char *, int, char *, int *)); extern int afp_rename __P((AFPObj *, char *, int, char *, int *)); extern int afp_delete __P((AFPObj *, char *, int, char *, int *)); -extern int afp_getfildirparams __P((AFPObj *, char *, int, char *, - int *)); -extern int afp_setfildirparams __P((AFPObj *, char *, int, char *, - int *)); +extern int afp_getfildirparams __P((AFPObj *, char *, int, char *, + int *)); +extern int afp_setfildirparams __P((AFPObj *, char *, int, char *, + int *)); #endif diff --git a/etc/afpd/fork.c b/etc/afpd/fork.c index 50104555..b1024875 100644 --- a/etc/afpd/fork.c +++ b/etc/afpd/fork.c @@ -1,5 +1,5 @@ /* - * $Id: fork.c,v 1.11 2001-11-16 11:11:00 srittau Exp $ + * $Id: fork.c,v 1.11.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -52,11 +52,11 @@ struct ofork *writtenfork; static int getforkparams(ofork, bitmap, buf, buflen, attrbits ) - struct ofork *ofork; - u_int16_t bitmap; - char *buf; - int *buflen; - const u_int16_t attrbits; +struct ofork *ofork; +u_int16_t bitmap; +char *buf; +int *buflen; +const u_int16_t attrbits; { struct stat st; struct extmap *em; @@ -66,171 +66,171 @@ static int getforkparams(ofork, bitmap, buf, buflen, attrbits ) u_int16_t ashort; if ( ad_hfileno( ofork->of_ad ) == -1 ) { - isad = 0; + isad = 0; } else { - aint = ad_getentrylen( ofork->of_ad, ADEID_RFORK ); - if ( ad_refresh( ofork->of_ad ) < 0 ) { - syslog( LOG_ERR, "getforkparams: ad_refresh: %s", strerror(errno) ); - return( AFPERR_PARAM ); - } - /* See afp_closefork() for why this is bad */ - ad_setentrylen( ofork->of_ad, ADEID_RFORK, aint ); + aint = ad_getentrylen( ofork->of_ad, ADEID_RFORK ); + if ( ad_refresh( ofork->of_ad ) < 0 ) { + syslog( LOG_ERR, "getforkparams: ad_refresh: %s", strerror(errno) ); + return( AFPERR_PARAM ); + } + /* See afp_closefork() for why this is bad */ + ad_setentrylen( ofork->of_ad, ADEID_RFORK, aint ); } /* can only get the length of the opened fork */ if (((bitmap & (1<of_flags & AFPFORK_RSRC)) || - ((bitmap & (1<of_flags & AFPFORK_DATA))) { - return( AFPERR_BITMAP ); + ((bitmap & (1<of_flags & AFPFORK_DATA))) { + return( AFPERR_BITMAP ); } if ( bitmap & ( 1<of_vol, ofork->of_name); - if ( ad_dfileno( ofork->of_ad ) == -1 ) { - if ( stat( upath, &st ) < 0 ) - return( AFPERR_NOOBJ ); - } else { - if ( fstat( ad_dfileno( ofork->of_ad ), &st ) < 0 ) { - return( AFPERR_BITMAP ); - } - } + if ( ad_dfileno( ofork->of_ad ) == -1 ) { + if ( stat( upath, &st ) < 0 ) + return( AFPERR_NOOBJ ); + } else { + if ( fstat( ad_dfileno( ofork->of_ad ), &st ) < 0 ) { + return( AFPERR_BITMAP ); + } + } } data = buf; while ( bitmap != 0 ) { - while (( bitmap & 1 ) == 0 ) { - bitmap = bitmap>>1; - bit++; - } - - switch ( bit ) { - case FILPBIT_ATTR : - if ( isad ) { - ad_getattr(ofork->of_ad, &ashort); - } else { - ashort = 0; - } - if (attrbits) - ashort = htons(ntohs(ashort) | attrbits); - memcpy(data, &ashort, sizeof( ashort )); - data += sizeof( ashort ); - break; - - case FILPBIT_PDID : - memcpy(data, &ofork->of_dir->d_did, sizeof( aint )); - data += sizeof( aint ); - break; - - case FILPBIT_CDATE : - if (!isad || - (ad_getdate(ofork->of_ad, AD_DATE_CREATE, &aint) < 0)) - aint = AD_DATE_FROM_UNIX(st.st_mtime); - memcpy(data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case FILPBIT_MDATE : - if (!isad || - (ad_getdate(ofork->of_ad, AD_DATE_MODIFY, &aint) < 0) || - (AD_DATE_TO_UNIX(aint) < st.st_mtime)) - aint = AD_DATE_FROM_UNIX(st.st_mtime); - memcpy(data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case FILPBIT_BDATE : - if (!isad || - (ad_getdate(ofork->of_ad, AD_DATE_BACKUP, &aint) < 0)) - aint = AD_DATE_START; - memcpy(data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case FILPBIT_FINFO : - memcpy(data, isad ? - (void *) ad_entry(ofork->of_ad, ADEID_FINDERI) : - (void *) ufinderi, 32); - if ( !isad || - memcmp( ad_entry( ofork->of_ad, ADEID_FINDERI ), - ufinderi, 8 ) == 0 ) { - memcpy(data, ufinderi, 8 ); - if (( em = getextmap( ofork->of_name )) != NULL ) { - memcpy(data, em->em_type, sizeof( em->em_type )); - memcpy(data + 4, em->em_creator, - sizeof( em->em_creator )); - } - } - data += 32; - break; - - case FILPBIT_LNAME : - nameoff = data; - data += sizeof(u_int16_t); - break; - - case FILPBIT_SNAME : - memset(data, 0, sizeof(u_int16_t)); - data += sizeof(u_int16_t); - break; - - case FILPBIT_FNUM : - aint = 0; + while (( bitmap & 1 ) == 0 ) { + bitmap = bitmap>>1; + bit++; + } + + switch ( bit ) { + case FILPBIT_ATTR : + if ( isad ) { + ad_getattr(ofork->of_ad, &ashort); + } else { + ashort = 0; + } + if (attrbits) + ashort = htons(ntohs(ashort) | attrbits); + memcpy(data, &ashort, sizeof( ashort )); + data += sizeof( ashort ); + break; + + case FILPBIT_PDID : + memcpy(data, &ofork->of_dir->d_did, sizeof( aint )); + data += sizeof( aint ); + break; + + case FILPBIT_CDATE : + if (!isad || + (ad_getdate(ofork->of_ad, AD_DATE_CREATE, &aint) < 0)) + aint = AD_DATE_FROM_UNIX(st.st_mtime); + memcpy(data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case FILPBIT_MDATE : + if (!isad || + (ad_getdate(ofork->of_ad, AD_DATE_MODIFY, &aint) < 0) || + (AD_DATE_TO_UNIX(aint) < st.st_mtime)) + aint = AD_DATE_FROM_UNIX(st.st_mtime); + memcpy(data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case FILPBIT_BDATE : + if (!isad || + (ad_getdate(ofork->of_ad, AD_DATE_BACKUP, &aint) < 0)) + aint = AD_DATE_START; + memcpy(data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case FILPBIT_FINFO : + memcpy(data, isad ? + (void *) ad_entry(ofork->of_ad, ADEID_FINDERI) : + (void *) ufinderi, 32); + if ( !isad || + memcmp( ad_entry( ofork->of_ad, ADEID_FINDERI ), + ufinderi, 8 ) == 0 ) { + memcpy(data, ufinderi, 8 ); + if (( em = getextmap( ofork->of_name )) != NULL ) { + memcpy(data, em->em_type, sizeof( em->em_type )); + memcpy(data + 4, em->em_creator, + sizeof( em->em_creator )); + } + } + data += 32; + break; + + case FILPBIT_LNAME : + nameoff = data; + data += sizeof(u_int16_t); + break; + + case FILPBIT_SNAME : + memset(data, 0, sizeof(u_int16_t)); + data += sizeof(u_int16_t); + break; + + case FILPBIT_FNUM : + aint = 0; #if AD_VERSION > AD_VERSION1 - /* look in AD v2 header */ - if (isad) - memcpy(&aint, ad_entry(ofork->of_ad, ADEID_DID), sizeof(aint)); + /* look in AD v2 header */ + if (isad) + memcpy(&aint, ad_entry(ofork->of_ad, ADEID_DID), sizeof(aint)); #endif /* AD_VERSION > AD_VERSION1 */ #ifdef CNID_DB - aint = cnid_add(ofork->of_vol->v_db, &st, - ofork->of_dir->d_did, - upath, strlen(upath), aint); + aint = cnid_add(ofork->of_vol->v_db, &st, + ofork->of_dir->d_did, + upath, strlen(upath), aint); #endif /* CNID_DB */ - if (aint == 0) { + if (aint == 0) { #ifdef AFS - aint = st.st_ino; + aint = st.st_ino; #else /* AFS */ - aint = ( st.st_dev << 16 ) | ( st.st_ino & 0x0000ffff ); + aint = ( st.st_dev << 16 ) | ( st.st_ino & 0x0000ffff ); #endif /* AFS */ - } - - memcpy(data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case FILPBIT_DFLEN : - aint = htonl( st.st_size ); - memcpy(data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case FILPBIT_RFLEN : - if ( isad ) { - aint = htonl( ad_getentrylen( ofork->of_ad, ADEID_RFORK )); - } else { - aint = 0; - } - memcpy(data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - default : - return( AFPERR_BITMAP ); - } - bitmap = bitmap>>1; - bit++; + } + + memcpy(data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case FILPBIT_DFLEN : + aint = htonl( st.st_size ); + memcpy(data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case FILPBIT_RFLEN : + if ( isad ) { + aint = htonl( ad_getentrylen( ofork->of_ad, ADEID_RFORK )); + } else { + aint = 0; + } + memcpy(data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + default : + return( AFPERR_BITMAP ); + } + bitmap = bitmap>>1; + bit++; } if ( nameoff ) { - ashort = htons( data - buf ); - memcpy(nameoff, &ashort, sizeof( ashort )); - aint = strlen( ofork->of_name ); - aint = ( aint > MACFILELEN ) ? MACFILELEN : aint; - *data++ = aint; - memcpy(data, ofork->of_name, aint ); - data += aint; + ashort = htons( data - buf ); + memcpy(nameoff, &ashort, sizeof( ashort )); + aint = strlen( ofork->of_name ); + aint = ( aint > MACFILELEN ) ? MACFILELEN : aint; + *data++ = aint; + memcpy(data, ofork->of_name, aint ); + data += aint; } *buflen = data - buf; @@ -238,9 +238,9 @@ static int getforkparams(ofork, bitmap, buf, buflen, attrbits ) } int afp_openfork(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol; struct dir *dir; @@ -249,7 +249,7 @@ int afp_openfork(obj, ibuf, ibuflen, rbuf, rbuflen ) int buflen, ret, adflags, eid, lockop; u_int32_t did; u_int16_t vid, bitmap, access, ofrefnum, attrbits = 0; - char fork, *path, *upath; + char fork, *path, *upath; ibuf++; fork = *ibuf++; @@ -258,14 +258,14 @@ int afp_openfork(obj, ibuf, ibuflen, rbuf, rbuflen ) *rbuflen = 0; if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } memcpy(&did, ibuf, sizeof( did )); ibuf += sizeof( int ); if (( dir = dirsearch( vol, did )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } memcpy(&bitmap, ibuf, sizeof( bitmap )); @@ -280,141 +280,141 @@ int afp_openfork(obj, ibuf, ibuflen, rbuf, rbuflen ) } if (( path = cname( vol, dir, &ibuf )) == NULL ) { - return( AFPERR_NOOBJ ); + return( AFPERR_NOOBJ ); } if ( fork == OPENFORK_DATA ) { - eid = ADEID_DFORK; - adflags = ADFLAGS_DF|ADFLAGS_HF; + eid = ADEID_DFORK; + adflags = ADFLAGS_DF|ADFLAGS_HF; } else { eid = ADEID_RFORK; - adflags = ADFLAGS_HF; + adflags = ADFLAGS_HF; } - + /* XXX: this probably isn't the best way to do this. the already open bits should really be set if the fork is opened by any program, not just this one. however, that's problematic to do if we can't write lock files somewhere. opened is also passed to ad_open so that we can keep file locks together. */ if ((opened = of_findname(vol, curdir, path))) { - attrbits = ((opened->of_flags & AFPFORK_RSRC) ? ATTRBIT_ROPEN : 0) | - ((opened->of_flags & AFPFORK_DATA) ? ATTRBIT_DOPEN : 0); - adsame = opened->of_ad; + attrbits = ((opened->of_flags & AFPFORK_RSRC) ? ATTRBIT_ROPEN : 0) | + ((opened->of_flags & AFPFORK_DATA) ? ATTRBIT_DOPEN : 0); + adsame = opened->of_ad; } if (( ofork = of_alloc(vol, curdir, path, &ofrefnum, eid, - adsame)) == NULL ) { - return( AFPERR_NFILE ); + adsame)) == NULL ) { + return( AFPERR_NFILE ); } - if (access & OPENACC_WR) { - /* try opening in read-write mode */ - upath = mtoupath(vol, path); - ret = AFPERR_NOOBJ; - if (ad_open(upath, adflags, O_RDWR, 0, ofork->of_ad) < 0) { - switch ( errno ) { - case EROFS: - ret = AFPERR_VLOCK; - case EACCES: - goto openfork_err; - - break; - case ENOENT: - { - struct stat st; - - /* see if client asked for the data fork */ - if (fork == OPENFORK_DATA) { - if (ad_open(upath, ADFLAGS_DF, O_RDWR, 0, ofork->of_ad) < 0) { - goto openfork_err; - } - adflags = ADFLAGS_DF; - - } else if (stat(upath, &st) == 0) { - /* here's the deal. we only try to create the resource - * fork if the user wants to open it for write acess. */ - if (ad_open(upath, adflags, O_RDWR | O_CREAT, 0666, ofork->of_ad) < 0) - goto openfork_err; - } else - goto openfork_err; - } - break; - case EMFILE : - case ENFILE : - ret = AFPERR_NFILE; - goto openfork_err; - break; - case EISDIR : - ret = AFPERR_BADTYPE; - goto openfork_err; - break; - default: - syslog( LOG_ERR, "afp_openfork: ad_open: %s", strerror(errno) ); - ret = AFPERR_PARAM; - goto openfork_err; - break; - } - } - } else { - /* try opening in read-only mode */ - upath = mtoupath(vol, path); - ret = AFPERR_NOOBJ; - if (ad_open(upath, adflags, O_RDONLY, 0, ofork->of_ad) < 0) { - switch ( errno ) { - case EROFS: - ret = AFPERR_VLOCK; - case EACCES: - /* check for a read-only data fork */ - if ((adflags != ADFLAGS_HF) && - (ad_open(upath, ADFLAGS_DF, O_RDONLY, 0, ofork->of_ad) < 0)) - goto openfork_err; - - adflags = ADFLAGS_DF; - break; - case ENOENT: - { - struct stat st; - - /* see if client asked for the data fork */ - if (fork == OPENFORK_DATA) { - if (ad_open(upath, ADFLAGS_DF, O_RDONLY, 0, ofork->of_ad) < 0) { - goto openfork_err; - } - adflags = ADFLAGS_DF; - - } else if (stat(upath, &st) != 0) { - goto openfork_err; - } - } - break; - case EMFILE : - case ENFILE : - ret = AFPERR_NFILE; - goto openfork_err; - break; - case EISDIR : - ret = AFPERR_BADTYPE; - goto openfork_err; - break; - default: - syslog( LOG_ERR, "afp_openfork: ad_open: %s", strerror(errno) ); - goto openfork_err; - break; - } - } + if (access & OPENACC_WR) { + /* try opening in read-write mode */ + upath = mtoupath(vol, path); + ret = AFPERR_NOOBJ; + if (ad_open(upath, adflags, O_RDWR, 0, ofork->of_ad) < 0) { + switch ( errno ) { + case EROFS: + ret = AFPERR_VLOCK; + case EACCES: + goto openfork_err; + + break; + case ENOENT: + { + struct stat st; + + /* see if client asked for the data fork */ + if (fork == OPENFORK_DATA) { + if (ad_open(upath, ADFLAGS_DF, O_RDWR, 0, ofork->of_ad) < 0) { + goto openfork_err; + } + adflags = ADFLAGS_DF; + + } else if (stat(upath, &st) == 0) { + /* here's the deal. we only try to create the resource + * fork if the user wants to open it for write acess. */ + if (ad_open(upath, adflags, O_RDWR | O_CREAT, 0666, ofork->of_ad) < 0) + goto openfork_err; + } else + goto openfork_err; + } + break; + case EMFILE : + case ENFILE : + ret = AFPERR_NFILE; + goto openfork_err; + break; + case EISDIR : + ret = AFPERR_BADTYPE; + goto openfork_err; + break; + default: + syslog( LOG_ERR, "afp_openfork: ad_open: %s", strerror(errno) ); + ret = AFPERR_PARAM; + goto openfork_err; + break; + } + } + } else { + /* try opening in read-only mode */ + upath = mtoupath(vol, path); + ret = AFPERR_NOOBJ; + if (ad_open(upath, adflags, O_RDONLY, 0, ofork->of_ad) < 0) { + switch ( errno ) { + case EROFS: + ret = AFPERR_VLOCK; + case EACCES: + /* check for a read-only data fork */ + if ((adflags != ADFLAGS_HF) && + (ad_open(upath, ADFLAGS_DF, O_RDONLY, 0, ofork->of_ad) < 0)) + goto openfork_err; + + adflags = ADFLAGS_DF; + break; + case ENOENT: + { + struct stat st; + + /* see if client asked for the data fork */ + if (fork == OPENFORK_DATA) { + if (ad_open(upath, ADFLAGS_DF, O_RDONLY, 0, ofork->of_ad) < 0) { + goto openfork_err; + } + adflags = ADFLAGS_DF; + + } else if (stat(upath, &st) != 0) { + goto openfork_err; + } + } + break; + case EMFILE : + case ENFILE : + ret = AFPERR_NFILE; + goto openfork_err; + break; + case EISDIR : + ret = AFPERR_BADTYPE; + goto openfork_err; + break; + default: + syslog( LOG_ERR, "afp_openfork: ad_open: %s", strerror(errno) ); + goto openfork_err; + break; + } + } } if ((adflags & ADFLAGS_HF) && - (ad_getoflags( ofork->of_ad, ADFLAGS_HF ) & O_CREAT)) { - ad_setentrylen( ofork->of_ad, ADEID_NAME, strlen( path )); - memcpy(ad_entry( ofork->of_ad, ADEID_NAME ), path, - ad_getentrylen( ofork->of_ad, ADEID_NAME )); - ad_flush( ofork->of_ad, adflags ); + (ad_getoflags( ofork->of_ad, ADFLAGS_HF ) & O_CREAT)) { + ad_setentrylen( ofork->of_ad, ADEID_NAME, strlen( path )); + memcpy(ad_entry( ofork->of_ad, ADEID_NAME ), path, + ad_getentrylen( ofork->of_ad, ADEID_NAME )); + ad_flush( ofork->of_ad, adflags ); } if (( ret = getforkparams(ofork, bitmap, rbuf + 2 * sizeof( u_int16_t ), - &buflen, attrbits )) != AFP_OK ) { - ad_close( ofork->of_ad, adflags ); - goto openfork_err; + &buflen, attrbits )) != AFP_OK ) { + ad_close( ofork->of_ad, adflags ); + goto openfork_err; } *rbuflen = buflen + 2 * sizeof( u_int16_t ); @@ -437,64 +437,64 @@ int afp_openfork(obj, ibuf, ibuflen, rbuf, rbuflen ) /* don't try to lock non-existent rforks. */ if ((eid == ADEID_DFORK) || (ad_hfileno(ofork->of_ad) != -1)) { - /* try to see if we have access. */ - ret = 0; - if (access & OPENACC_WR) { - ofork->of_flags |= AFPFORK_ACCWR; - ret = ad_lock(ofork->of_ad, eid, ADLOCK_RD | ADLOCK_FILELOCK, - AD_FILELOCK_WR, 1, ofrefnum); - } - - if (!ret && (access & OPENACC_RD)) { - ofork->of_flags |= AFPFORK_ACCRD; - ret = ad_lock(ofork->of_ad, eid, ADLOCK_RD | ADLOCK_FILELOCK, - AD_FILELOCK_RD, 1, ofrefnum); - } - - /* can we access the fork? */ - if (ret < 0) { - ad_close( ofork->of_ad, adflags ); - of_dealloc( ofork ); - ofrefnum = 0; - memcpy(rbuf, &ofrefnum, sizeof(ofrefnum)); - return (AFPERR_DENYCONF); - } - - /* now try to set the deny lock. if the fork is open for read or - * write, a read lock will already have been set. otherwise, we upgrade - * our lock to a write lock. - * - * NOTE: we can't write lock a read-only file. on those, we just - * make sure that we have a read lock set. that way, we at least prevent - * someone else from really setting a deny read/write on the file. */ - lockop = (ad_getoflags(ofork->of_ad, eid) & O_RDWR) ? - ADLOCK_WR : ADLOCK_RD; - ret = (access & OPENACC_DWR) ? ad_lock(ofork->of_ad, eid, - lockop | ADLOCK_FILELOCK | - ADLOCK_UPGRADE, AD_FILELOCK_WR, 1, - ofrefnum) : 0; - if (!ret && (access & OPENACC_DRD)) - ret = ad_lock(ofork->of_ad, eid, lockop | ADLOCK_FILELOCK | - ADLOCK_UPGRADE, AD_FILELOCK_RD, 1, ofrefnum); - - if (ret < 0) { - ret = errno; - ad_close( ofork->of_ad, adflags ); - of_dealloc( ofork ); - switch (ret) { - case EAGAIN: /* return data anyway */ - case EACCES: - case EINVAL: - ofrefnum = 0; - memcpy(rbuf, &ofrefnum, sizeof(ofrefnum)); - return( AFPERR_DENYCONF ); - break; - default: - *rbuflen = 0; - syslog( LOG_ERR, "afp_openfork: ad_lock: %s", strerror(errno) ); - return( AFPERR_PARAM ); - } - } + /* try to see if we have access. */ + ret = 0; + if (access & OPENACC_WR) { + ofork->of_flags |= AFPFORK_ACCWR; + ret = ad_lock(ofork->of_ad, eid, ADLOCK_RD | ADLOCK_FILELOCK, + AD_FILELOCK_WR, 1, ofrefnum); + } + + if (!ret && (access & OPENACC_RD)) { + ofork->of_flags |= AFPFORK_ACCRD; + ret = ad_lock(ofork->of_ad, eid, ADLOCK_RD | ADLOCK_FILELOCK, + AD_FILELOCK_RD, 1, ofrefnum); + } + + /* can we access the fork? */ + if (ret < 0) { + ad_close( ofork->of_ad, adflags ); + of_dealloc( ofork ); + ofrefnum = 0; + memcpy(rbuf, &ofrefnum, sizeof(ofrefnum)); + return (AFPERR_DENYCONF); + } + + /* now try to set the deny lock. if the fork is open for read or + * write, a read lock will already have been set. otherwise, we upgrade + * our lock to a write lock. + * + * NOTE: we can't write lock a read-only file. on those, we just + * make sure that we have a read lock set. that way, we at least prevent + * someone else from really setting a deny read/write on the file. */ + lockop = (ad_getoflags(ofork->of_ad, eid) & O_RDWR) ? + ADLOCK_WR : ADLOCK_RD; + ret = (access & OPENACC_DWR) ? ad_lock(ofork->of_ad, eid, + lockop | ADLOCK_FILELOCK | + ADLOCK_UPGRADE, AD_FILELOCK_WR, 1, + ofrefnum) : 0; + if (!ret && (access & OPENACC_DRD)) + ret = ad_lock(ofork->of_ad, eid, lockop | ADLOCK_FILELOCK | + ADLOCK_UPGRADE, AD_FILELOCK_RD, 1, ofrefnum); + + if (ret < 0) { + ret = errno; + ad_close( ofork->of_ad, adflags ); + of_dealloc( ofork ); + switch (ret) { + case EAGAIN: /* return data anyway */ + case EACCES: + case EINVAL: + ofrefnum = 0; + memcpy(rbuf, &ofrefnum, sizeof(ofrefnum)); + return( AFPERR_DENYCONF ); + break; + default: + *rbuflen = 0; + syslog( LOG_ERR, "afp_openfork: ad_lock: %s", strerror(errno) ); + return( AFPERR_PARAM ); + } + } } memcpy(rbuf, &ofrefnum, sizeof(ofrefnum)); @@ -503,14 +503,14 @@ int afp_openfork(obj, ibuf, ibuflen, rbuf, rbuflen ) openfork_err: of_dealloc( ofork ); if (errno == EACCES) - return (access & OPENACC_WR) ? AFPERR_LOCK : AFPERR_ACCESS; + return (access & OPENACC_WR) ? AFPERR_LOCK : AFPERR_ACCESS; return ret; } int afp_setforkparams(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct ofork *ofork; int32_t size; @@ -528,8 +528,8 @@ int afp_setforkparams(obj, ibuf, ibuflen, rbuf, rbuflen ) *rbuflen = 0; if (( ofork = of_find( ofrefnum )) == NULL ) { - syslog( LOG_ERR, "afp_setforkparams: of_find: %s", strerror(errno) ); - return( AFPERR_PARAM ); + syslog( LOG_ERR, "afp_setforkparams: of_find: %s", strerror(errno) ); + return( AFPERR_PARAM ); } if (ofork->of_vol->v_flags & AFPVOL_RO) @@ -540,51 +540,51 @@ int afp_setforkparams(obj, ibuf, ibuflen, rbuf, rbuflen ) if (size < 0) return AFPERR_PARAM; - + if ((bitmap == (1<of_flags & AFPFORK_DATA)) { - err = ad_dtruncate( ofork->of_ad, size ); - if (err < 0) - goto afp_setfork_err; + err = ad_dtruncate( ofork->of_ad, size ); + if (err < 0) + goto afp_setfork_err; } else if ((bitmap == (1<of_flags & AFPFORK_RSRC)) { - ad_refresh( ofork->of_ad ); - err = ad_rtruncate(ofork->of_ad, size); - if (err < 0) - goto afp_setfork_err; - - if (ad_flush( ofork->of_ad, ADFLAGS_HF ) < 0) { - syslog( LOG_ERR, "afp_setforkparams: ad_flush: %s", - strerror(errno) ); - return( AFPERR_PARAM ); - } + (ofork->of_flags & AFPFORK_RSRC)) { + ad_refresh( ofork->of_ad ); + err = ad_rtruncate(ofork->of_ad, size); + if (err < 0) + goto afp_setfork_err; + + if (ad_flush( ofork->of_ad, ADFLAGS_HF ) < 0) { + syslog( LOG_ERR, "afp_setforkparams: ad_flush: %s", + strerror(errno) ); + return( AFPERR_PARAM ); + } } else - return AFPERR_BITMAP; + return AFPERR_BITMAP; #ifdef AFS if ( flushfork( ofork ) < 0 ) { - syslog( LOG_ERR, "afp_setforkparams: flushfork: %s", strerror(errno) ); + syslog( LOG_ERR, "afp_setforkparams: flushfork: %s", strerror(errno) ); } #endif /* AFS */ return( AFP_OK ); afp_setfork_err: - if (err == -2) - return AFPERR_LOCK; + if (err == -2) + return AFPERR_LOCK; else { - switch (errno) { - case EROFS: - return AFPERR_VLOCK; - case EPERM: - case EACCES: - return AFPERR_ACCESS; - case EDQUOT: - case EFBIG: - case ENOSPC: - return AFPERR_DFULL; - default: - return AFPERR_PARAM; - } + switch (errno) { + case EROFS: + return AFPERR_VLOCK; + case EPERM: + case EACCES: + return AFPERR_ACCESS; + case EDQUOT: + case EFBIG: + case ENOSPC: + return AFPERR_DFULL; + default: + return AFPERR_PARAM; + } } } @@ -597,9 +597,9 @@ afp_setfork_err: #define ENDBIT(a) ((a) & 0x80) #define UNLOCKBIT(a) ((a) & 0x01) int afp_bytelock(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct ofork *ofork; int32_t offset, length; @@ -617,15 +617,15 @@ int afp_bytelock(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof(ofrefnum); if (( ofork = of_find( ofrefnum )) == NULL ) { - syslog( LOG_ERR, "afp_bytelock: of_find: %s", strerror(errno) ); - return( AFPERR_PARAM ); + syslog( LOG_ERR, "afp_bytelock: of_find: %s", strerror(errno) ); + return( AFPERR_PARAM ); } if ( ofork->of_flags & AFPFORK_DATA) { - eid = ADEID_DFORK; + eid = ADEID_DFORK; } else if (ofork->of_flags & AFPFORK_RSRC) { - eid = ADEID_RFORK; - } else + eid = ADEID_RFORK; + } else return AFPERR_PARAM; memcpy(&offset, ibuf, sizeof( offset )); @@ -634,43 +634,43 @@ int afp_bytelock(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy(&length, ibuf, sizeof( length )); length = ntohl(length); - if (length == 0xFFFFFFFF) - length = BYTELOCK_MAX; + if (length == 0xFFFFFFFF) + length = BYTELOCK_MAX; else if (length <= 0) { - return AFPERR_PARAM; - } else if ((length >= AD_FILELOCK_BASE) && - (ad_hfileno(ofork->of_ad) == -1)) - return AFPERR_LOCK; + return AFPERR_PARAM; + } else if ((length >= AD_FILELOCK_BASE) && + (ad_hfileno(ofork->of_ad) == -1)) + return AFPERR_LOCK; - if (ENDBIT(flags)) - offset += ad_size(ofork->of_ad, eid); + if (ENDBIT(flags)) + offset += ad_size(ofork->of_ad, eid); if (offset < 0) /* error if we have a negative offset */ - return AFPERR_PARAM; + return AFPERR_PARAM; /* if the file is a read-only file, we use read locks instead of * write locks. that way, we can prevent anyone from initiating * a write lock. */ - if (ad_lock(ofork->of_ad, eid, UNLOCKBIT(flags) ? ADLOCK_CLR : - ((ad_getoflags(ofork->of_ad, eid) & O_RDWR) ? - ADLOCK_WR : ADLOCK_RD), offset, length, - ofork->of_refnum) < 0) { - switch (errno) { - case EACCES: - case EAGAIN: - return UNLOCKBIT(flags) ? AFPERR_NORANGE : AFPERR_LOCK; - break; - case ENOLCK: - return AFPERR_NLOCK; - break; - case EINVAL: - return UNLOCKBIT(flags) ? AFPERR_NORANGE : AFPERR_RANGEOVR; - break; - case EBADF: - default: - return AFPERR_PARAM; - break; - } + if (ad_lock(ofork->of_ad, eid, UNLOCKBIT(flags) ? ADLOCK_CLR : + ((ad_getoflags(ofork->of_ad, eid) & O_RDWR) ? + ADLOCK_WR : ADLOCK_RD), offset, length, + ofork->of_refnum) < 0) { + switch (errno) { + case EACCES: + case EAGAIN: + return UNLOCKBIT(flags) ? AFPERR_NORANGE : AFPERR_LOCK; + break; + case ENOLCK: + return AFPERR_NLOCK; + break; + case EINVAL: + return UNLOCKBIT(flags) ? AFPERR_NORANGE : AFPERR_RANGEOVR; + break; + case EBADF: + default: + return AFPERR_PARAM; + break; + } } offset = htonl(offset); @@ -682,44 +682,44 @@ int afp_bytelock(obj, ibuf, ibuflen, rbuf, rbuflen ) static __inline__ int crlf( of ) - struct ofork *of; +struct ofork *of; { struct extmap *em; if ( ad_hfileno( of->of_ad ) == -1 || - memcmp( ufinderi, ad_entry( of->of_ad, ADEID_FINDERI ), - 8) == 0 ) { - if (( em = getextmap( of->of_name )) == NULL || - memcmp( "TEXT", em->em_type, sizeof( em->em_type )) == 0 ) { - return( 1 ); - } else { - return( 0 ); - } + memcmp( ufinderi, ad_entry( of->of_ad, ADEID_FINDERI ), + 8) == 0 ) { + if (( em = getextmap( of->of_name )) == NULL || + memcmp( "TEXT", em->em_type, sizeof( em->em_type )) == 0 ) { + return( 1 ); + } else { + return( 0 ); + } } else { - if ( memcmp( ufinderi, - ad_entry( of->of_ad, ADEID_FINDERI ), 4 ) == 0 ) { - return( 1 ); - } else { - return( 0 ); - } + if ( memcmp( ufinderi, + ad_entry( of->of_ad, ADEID_FINDERI ), 4 ) == 0 ) { + return( 1 ); + } else { + return( 0 ); + } } } static __inline__ ssize_t read_file(struct ofork *ofork, int eid, - int offset, u_char nlmask, - u_char nlchar, char *rbuf, - int *rbuflen, const int xlate) -{ + int offset, u_char nlmask, + u_char nlchar, char *rbuf, + int *rbuflen, const int xlate) +{ ssize_t cc; int eof = 0; char *p, *q; cc = ad_read(ofork->of_ad, eid, offset, rbuf, *rbuflen); if ( cc < 0 ) { - syslog( LOG_ERR, "afp_read: ad_read: %s", strerror(errno) ); - *rbuflen = 0; - return( AFPERR_PARAM ); + syslog( LOG_ERR, "afp_read: ad_read: %s", strerror(errno) ); + *rbuflen = 0; + return( AFPERR_PARAM ); } if ( cc < *rbuflen ) { eof = 1; @@ -729,42 +729,42 @@ static __inline__ ssize_t read_file(struct ofork *ofork, int eid, * Do Newline check. */ if ( nlmask != 0 ) { - for ( p = rbuf, q = p + cc; p < q; ) { - if (( *p++ & nlmask ) == nlchar ) { - break; - } - } - if ( p != q ) { - cc = p - rbuf; - eof = 0; - } + for ( p = rbuf, q = p + cc; p < q; ) { + if (( *p++ & nlmask ) == nlchar ) { + break; + } + } + if ( p != q ) { + cc = p - rbuf; + eof = 0; + } } /* * If this file is of type TEXT, then swap \012 to \015. */ if (xlate) { - for ( p = rbuf, q = p + cc; p < q; p++ ) { - if ( *p == '\012' ) { - *p = '\015'; - } else if ( *p == '\015' ) { - *p = '\012'; - } - - } + for ( p = rbuf, q = p + cc; p < q; p++ ) { + if ( *p == '\012' ) { + *p = '\015'; + } else if ( *p == '\015' ) { + *p = '\012'; + } + + } } *rbuflen = cc; if ( eof ) { - return( AFPERR_EOF ); + return( AFPERR_EOF ); } return AFP_OK; } int afp_read(obj, ibuf, ibuflen, rbuf, rbuflen) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct ofork *ofork; off_t size; @@ -778,14 +778,14 @@ int afp_read(obj, ibuf, ibuflen, rbuf, rbuflen) ibuf += sizeof( u_short ); if (( ofork = of_find( ofrefnum )) == NULL ) { - syslog( LOG_ERR, "afp_read: of_find: %s", strerror(errno) ); - err = AFPERR_PARAM; - goto afp_read_err; + syslog( LOG_ERR, "afp_read: of_find: %s", strerror(errno) ); + err = AFPERR_PARAM; + goto afp_read_err; } if ((ofork->of_flags & AFPFORK_ACCRD) == 0) { - err = AFPERR_ACCESS; - goto afp_read_err; + err = AFPERR_ACCESS; + goto afp_read_err; } memcpy(&offset, ibuf, sizeof( offset )); @@ -802,119 +802,119 @@ int afp_read(obj, ibuf, ibuflen, rbuf, rbuflen) * bit: if (afp_version == 11 && !(nlmask == 0xFF || !nlmask)) */ if (reqcount < 0 || offset < 0) { - err = AFPERR_PARAM; - goto afp_read_err; + err = AFPERR_PARAM; + goto afp_read_err; } if ( ofork->of_flags & AFPFORK_DATA) { - eid = ADEID_DFORK; - xlate = (ofork->of_vol->v_flags & AFPVOL_CRLF) ? crlf(ofork) : 0; + eid = ADEID_DFORK; + xlate = (ofork->of_vol->v_flags & AFPVOL_CRLF) ? crlf(ofork) : 0; } else if (ofork->of_flags & AFPFORK_RSRC) { - eid = ADEID_RFORK; + eid = ADEID_RFORK; } else { /* fork wasn't opened. this should never really happen. */ err = AFPERR_ACCESS; - goto afp_read_err; + goto afp_read_err; } /* zero request count */ if (!reqcount) { - err = AFP_OK; - goto afp_read_err; + err = AFP_OK; + goto afp_read_err; } /* reqcount isn't always truthful. we need to deal with that. */ if ((size = ad_size(ofork->of_ad, eid)) == 0) { - err = AFPERR_EOF; - goto afp_read_err; + err = AFPERR_EOF; + goto afp_read_err; } saveoff = offset; if (ad_tmplock(ofork->of_ad, eid, ADLOCK_RD, saveoff, reqcount) < 0) { - err = AFPERR_LOCK; - goto afp_read_err; - } + err = AFPERR_LOCK; + goto afp_read_err; + } #define min(a,b) ((a)<(b)?(a):(b)) *rbuflen = min( reqcount, *rbuflen ); err = read_file(ofork, eid, offset, nlmask, nlchar, rbuf, rbuflen, - xlate); - if (err < 0) - goto afp_read_done; + xlate); + if (err < 0) + goto afp_read_done; /* dsi can stream requests. we can only do this if we're not checking * for an end-of-line character. oh well. */ if ((obj->proto == AFPPROTO_DSI) && (*rbuflen < reqcount) && !nlmask) { - DSI *dsi = obj->handle; - - /* subtract off the offset */ - size -= offset; - if (reqcount > size) { - reqcount = size; - err = AFPERR_EOF; - } - - if (obj->options.flags & OPTION_DEBUG) { - printf( "(read) reply: %d/%d, %d\n", *rbuflen, - reqcount, dsi->clientID); - bprint(rbuf, *rbuflen); - } - - offset += *rbuflen; - - /* dsi_readinit() returns size of next read buffer. by this point, - * we know that we're sending some data. if we fail, something - * horrible happened. */ - if ((*rbuflen = dsi_readinit(dsi, rbuf, *rbuflen, reqcount, err)) < 0) - goto afp_read_exit; - - /* due to the nature of afp packets, we have to exit if we get - an error. we can't do this with translation on. */ + DSI *dsi = obj->handle; + + /* subtract off the offset */ + size -= offset; + if (reqcount > size) { + reqcount = size; + err = AFPERR_EOF; + } + + if (obj->options.flags & OPTION_DEBUG) { + printf( "(read) reply: %d/%d, %d\n", *rbuflen, + reqcount, dsi->clientID); + bprint(rbuf, *rbuflen); + } + + offset += *rbuflen; + + /* dsi_readinit() returns size of next read buffer. by this point, + * we know that we're sending some data. if we fail, something + * horrible happened. */ + if ((*rbuflen = dsi_readinit(dsi, rbuf, *rbuflen, reqcount, err)) < 0) + goto afp_read_exit; + + /* due to the nature of afp packets, we have to exit if we get + an error. we can't do this with translation on. */ #ifdef HAVE_SENDFILE_READ - if (!(xlate || (obj->options.flags & OPTION_DEBUG))) { - if (ad_readfile(ofork->of_ad, eid, dsi->socket, offset, - dsi->datasize) < 0) { - if (errno == EINVAL) - goto afp_read_loop; - else { - syslog(LOG_ERR, "afp_read: ad_readfile: %s", strerror(errno)); - goto afp_read_exit; - } - } - - dsi_readdone(dsi); - goto afp_read_done; - } + if (!(xlate || (obj->options.flags & OPTION_DEBUG))) { + if (ad_readfile(ofork->of_ad, eid, dsi->socket, offset, + dsi->datasize) < 0) { + if (errno == EINVAL) + goto afp_read_loop; + else { + syslog(LOG_ERR, "afp_read: ad_readfile: %s", strerror(errno)); + goto afp_read_exit; + } + } + + dsi_readdone(dsi); + goto afp_read_done; + } afp_read_loop: #endif /* HAVE_SENDFILE_READ */ - /* fill up our buffer. */ - while (*rbuflen > 0) { - cc = read_file(ofork, eid, offset, nlmask, nlchar, rbuf, - rbuflen, xlate); - if (cc < 0) - goto afp_read_exit; - - offset += *rbuflen; - if (obj->options.flags & OPTION_DEBUG) { - printf( "(read) reply: %d, %d\n", *rbuflen, dsi->clientID); - bprint(rbuf, *rbuflen); - } - - /* dsi_read() also returns buffer size of next allocation */ - cc = dsi_read(dsi, rbuf, *rbuflen); /* send it off */ - if (cc < 0) - goto afp_read_exit; - *rbuflen = cc; - } - dsi_readdone(dsi); - goto afp_read_done; + /* fill up our buffer. */ + while (*rbuflen > 0) { + cc = read_file(ofork, eid, offset, nlmask, nlchar, rbuf, + rbuflen, xlate); + if (cc < 0) + goto afp_read_exit; + + offset += *rbuflen; + if (obj->options.flags & OPTION_DEBUG) { + printf( "(read) reply: %d, %d\n", *rbuflen, dsi->clientID); + bprint(rbuf, *rbuflen); + } + + /* dsi_read() also returns buffer size of next allocation */ + cc = dsi_read(dsi, rbuf, *rbuflen); /* send it off */ + if (cc < 0) + goto afp_read_exit; + *rbuflen = cc; + } + dsi_readdone(dsi); + goto afp_read_done; afp_read_exit: - syslog(LOG_ERR, "afp_read: %s", strerror(errno)); - dsi_readdone(dsi); - ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount); - obj->exit(1); + syslog(LOG_ERR, "afp_read: %s", strerror(errno)); + dsi_readdone(dsi); + ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount); + obj->exit(1); } afp_read_done: @@ -927,9 +927,9 @@ afp_read_err: } int afp_flush(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol; u_int16_t vid; @@ -939,7 +939,7 @@ int afp_flush(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy(&vid, ibuf, sizeof(vid)); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } of_flush(vol); @@ -947,9 +947,9 @@ int afp_flush(obj, ibuf, ibuflen, rbuf, rbuflen ) } int afp_flushfork(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct ofork *ofork; u_int16_t ofrefnum; @@ -959,12 +959,12 @@ int afp_flushfork(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy(&ofrefnum, ibuf, sizeof( ofrefnum )); if (( ofork = of_find( ofrefnum )) == NULL ) { - syslog( LOG_ERR, "afp_flushfork: of_find: %s", strerror(errno) ); - return( AFPERR_PARAM ); + syslog( LOG_ERR, "afp_flushfork: of_find: %s", strerror(errno) ); + return( AFPERR_PARAM ); } if ( flushfork( ofork ) < 0 ) { - syslog( LOG_ERR, "afp_flushfork: %s", strerror(errno) ); + syslog( LOG_ERR, "afp_flushfork: %s", strerror(errno) ); } return( AFP_OK ); @@ -972,61 +972,61 @@ int afp_flushfork(obj, ibuf, ibuflen, rbuf, rbuflen ) /* this is very similar to closefork */ int flushfork( ofork ) - struct ofork *ofork; +struct ofork *ofork; { struct timeval tv; int len, err = 0, doflush = 0; if ( ad_dfileno( ofork->of_ad ) != -1 && - fsync( ad_dfileno( ofork->of_ad )) < 0 ) { - syslog( LOG_ERR, "flushfork: dfile(%d) %s", - ad_dfileno(ofork->of_ad), strerror(errno) ); - err = -1; + fsync( ad_dfileno( ofork->of_ad )) < 0 ) { + syslog( LOG_ERR, "flushfork: dfile(%d) %s", + ad_dfileno(ofork->of_ad), strerror(errno) ); + err = -1; } if ( ad_hfileno( ofork->of_ad ) != -1 ) { /* read in the rfork length */ - len = ad_getentrylen(ofork->of_ad, ADEID_RFORK); - ad_refresh(ofork->of_ad); + len = ad_getentrylen(ofork->of_ad, ADEID_RFORK); + ad_refresh(ofork->of_ad); - /* set the date if we're dirty */ + /* set the date if we're dirty */ if ((ofork->of_flags & AFPFORK_DIRTY) && - (gettimeofday(&tv, NULL) == 0)) { - ad_setdate(ofork->of_ad, AD_DATE_MODIFY|AD_DATE_UNIX, tv.tv_sec); - ofork->of_flags &= ~AFPFORK_DIRTY; - doflush++; - } - - /* if we're actually flushing this fork, make sure to set the - * length. otherwise, just use the stored length */ - if ((ofork->of_flags & AFPFORK_RSRC) && - (len != ad_getentrylen(ofork->of_ad, ADEID_RFORK))) { - ad_setentrylen(ofork->of_ad, ADEID_RFORK, len); - doflush++; - } - - - /* flush the header (if it is a resource fork) */ - if (ofork->of_flags & AFPFORK_RSRC) - if (doflush && (ad_flush(ofork->of_ad, ADFLAGS_HF) < 0)) - err = -1; - - if (fsync( ad_hfileno( ofork->of_ad )) < 0) - err = -1; - - if (err < 0) - syslog( LOG_ERR, "flushfork: hfile(%d) %s", - ad_hfileno(ofork->of_ad), strerror(errno) ); + (gettimeofday(&tv, NULL) == 0)) { + ad_setdate(ofork->of_ad, AD_DATE_MODIFY|AD_DATE_UNIX, tv.tv_sec); + ofork->of_flags &= ~AFPFORK_DIRTY; + doflush++; + } + + /* if we're actually flushing this fork, make sure to set the + * length. otherwise, just use the stored length */ + if ((ofork->of_flags & AFPFORK_RSRC) && + (len != ad_getentrylen(ofork->of_ad, ADEID_RFORK))) { + ad_setentrylen(ofork->of_ad, ADEID_RFORK, len); + doflush++; + } + + + /* flush the header (if it is a resource fork) */ + if (ofork->of_flags & AFPFORK_RSRC) + if (doflush && (ad_flush(ofork->of_ad, ADFLAGS_HF) < 0)) + err = -1; + + if (fsync( ad_hfileno( ofork->of_ad )) < 0) + err = -1; + + if (err < 0) + syslog( LOG_ERR, "flushfork: hfile(%d) %s", + ad_hfileno(ofork->of_ad), strerror(errno) ); } return( err ); } int afp_closefork(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct ofork *ofork; struct timeval tv; @@ -1038,44 +1038,44 @@ int afp_closefork(obj, ibuf, ibuflen, rbuf, rbuflen ) memcpy(&ofrefnum, ibuf, sizeof( ofrefnum )); if (( ofork = of_find( ofrefnum )) == NULL ) { - syslog( LOG_ERR, "afp_closefork: of_find: %s", strerror(errno) ); - return( AFPERR_PARAM ); + syslog( LOG_ERR, "afp_closefork: of_find: %s", strerror(errno) ); + return( AFPERR_PARAM ); } adflags = 0; if ((ofork->of_flags & AFPFORK_DATA) && - (ad_dfileno( ofork->of_ad ) != -1)) { - adflags |= ADFLAGS_DF; + (ad_dfileno( ofork->of_ad ) != -1)) { + adflags |= ADFLAGS_DF; } if ( ad_hfileno( ofork->of_ad ) != -1 ) { - adflags |= ADFLAGS_HF; - - aint = ad_getentrylen( ofork->of_ad, ADEID_RFORK ); - ad_refresh( ofork->of_ad ); - if ((ofork->of_flags & AFPFORK_DIRTY) && - (gettimeofday(&tv, NULL) == 0)) { - ad_setdate(ofork->of_ad, AD_DATE_MODIFY | AD_DATE_UNIX, - tv.tv_sec); - doflush++; - } - - /* - * Only set the rfork's length if we're closing the rfork. - */ - if ((ofork->of_flags & AFPFORK_RSRC) && aint != - ad_getentrylen( ofork->of_ad, ADEID_RFORK )) { - ad_setentrylen( ofork->of_ad, ADEID_RFORK, aint ); - doflush++; - } - if ( doflush ) { - ad_flush( ofork->of_ad, adflags ); - } + adflags |= ADFLAGS_HF; + + aint = ad_getentrylen( ofork->of_ad, ADEID_RFORK ); + ad_refresh( ofork->of_ad ); + if ((ofork->of_flags & AFPFORK_DIRTY) && + (gettimeofday(&tv, NULL) == 0)) { + ad_setdate(ofork->of_ad, AD_DATE_MODIFY | AD_DATE_UNIX, + tv.tv_sec); + doflush++; + } + + /* + * Only set the rfork's length if we're closing the rfork. + */ + if ((ofork->of_flags & AFPFORK_RSRC) && aint != + ad_getentrylen( ofork->of_ad, ADEID_RFORK )) { + ad_setentrylen( ofork->of_ad, ADEID_RFORK, aint ); + doflush++; + } + if ( doflush ) { + ad_flush( ofork->of_ad, adflags ); + } } if ( ad_close( ofork->of_ad, adflags ) < 0 ) { - syslog( LOG_ERR, "afp_closefork: ad_close: %s", strerror(errno) ); - return( AFPERR_PARAM ); + syslog( LOG_ERR, "afp_closefork: ad_close: %s", strerror(errno) ); + return( AFPERR_PARAM ); } of_dealloc( ofork ); @@ -1084,8 +1084,8 @@ int afp_closefork(obj, ibuf, ibuflen, rbuf, rbuflen ) static __inline__ ssize_t write_file(struct ofork *ofork, int eid, - off_t offset, char *rbuf, - size_t rbuflen, const int xlate) + off_t offset, char *rbuf, + size_t rbuflen, const int xlate) { char *p, *q; ssize_t cc; @@ -1094,28 +1094,28 @@ static __inline__ ssize_t write_file(struct ofork *ofork, int eid, * If this file is of type TEXT, swap \015 to \012. */ if (xlate) { - for ( p = rbuf, q = p + rbuflen; p < q; p++ ) { - if ( *p == '\015' ) { - *p = '\012'; - } else if ( *p == '\012' ) { - *p = '\015'; - } - } + for ( p = rbuf, q = p + rbuflen; p < q; p++ ) { + if ( *p == '\015' ) { + *p = '\012'; + } else if ( *p == '\012' ) { + *p = '\015'; + } + } } - if (( cc = ad_write(ofork->of_ad, eid, offset, 0, - rbuf, rbuflen)) < 0 ) { - switch ( errno ) { - case EDQUOT : - case EFBIG : - case ENOSPC : - return( AFPERR_DFULL ); - default : - syslog( LOG_ERR, "afp_write: ad_write: %s", strerror(errno) ); - return( AFPERR_PARAM ); - } + if (( cc = ad_write(ofork->of_ad, eid, offset, 0, + rbuf, rbuflen)) < 0 ) { + switch ( errno ) { + case EDQUOT : + case EFBIG : + case ENOSPC : + return( AFPERR_DFULL ); + default : + syslog( LOG_ERR, "afp_write: ad_write: %s", strerror(errno) ); + return( AFPERR_PARAM ); + } } - + return cc; } @@ -1123,9 +1123,9 @@ static __inline__ ssize_t write_file(struct ofork *ofork, int eid, * the client may have sent us a bunch of data that's not reflected * in reqcount et al. */ int afp_write(obj, ibuf, ibuflen, rbuf, rbuflen) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct ofork *ofork; int32_t offset, saveoff, reqcount; @@ -1147,14 +1147,14 @@ int afp_write(obj, ibuf, ibuflen, rbuf, rbuflen) ibuf += sizeof( reqcount ); if (( ofork = of_find( ofrefnum )) == NULL ) { - syslog( LOG_ERR, "afp_write: of_find: %s", strerror(errno) ); - err = AFPERR_PARAM; - goto afp_write_err; + syslog( LOG_ERR, "afp_write: of_find: %s", strerror(errno) ); + err = AFPERR_PARAM; + goto afp_write_err; } if ((ofork->of_flags & AFPFORK_ACCWR) == 0) { - err = AFPERR_ACCESS; - goto afp_write_err; + err = AFPERR_ACCESS; + goto afp_write_err; } #ifdef AFS @@ -1162,41 +1162,41 @@ int afp_write(obj, ibuf, ibuflen, rbuf, rbuflen) #endif /* AFS */ if ( ofork->of_flags & AFPFORK_DATA) { - eid = ADEID_DFORK; - xlate = (ofork->of_vol->v_flags & AFPVOL_CRLF) ? crlf(ofork) : 0; + eid = ADEID_DFORK; + xlate = (ofork->of_vol->v_flags & AFPVOL_CRLF) ? crlf(ofork) : 0; } else if (ofork->of_flags & AFPFORK_RSRC) { - eid = ADEID_RFORK; + eid = ADEID_RFORK; } else { err = AFPERR_ACCESS; /* should never happen */ - goto afp_write_err; + goto afp_write_err; } - if (endflag) - offset += ad_size(ofork->of_ad, eid); - + if (endflag) + offset += ad_size(ofork->of_ad, eid); + /* handle bogus parameters */ if (reqcount < 0 || offset < 0) { - err = AFPERR_PARAM; - goto afp_write_err; + err = AFPERR_PARAM; + goto afp_write_err; } /* offset can overflow on 64-bit capable filesystems. * report disk full if that's going to happen. */ if (offset + reqcount < 0) { - err = AFPERR_DFULL; - goto afp_write_err; + err = AFPERR_DFULL; + goto afp_write_err; } if (!reqcount) { /* handle request counts of 0 */ - err = AFP_OK; - offset = htonl(offset); - memcpy(rbuf, &offset, sizeof(offset)); - goto afp_write_err; + err = AFP_OK; + offset = htonl(offset); + memcpy(rbuf, &offset, sizeof(offset)); + goto afp_write_err; } saveoff = offset; - if (ad_tmplock(ofork->of_ad, eid, ADLOCK_WR, saveoff, - reqcount) < 0) { + if (ad_tmplock(ofork->of_ad, eid, ADLOCK_WR, saveoff, + reqcount) < 0) { err = AFPERR_LOCK; goto afp_write_err; } @@ -1205,94 +1205,94 @@ int afp_write(obj, ibuf, ibuflen, rbuf, rbuflen) switch (obj->proto) { #ifndef NO_DDP case AFPPROTO_ASP: - if (asp_wrtcont(obj->handle, rbuf, rbuflen) < 0) { - *rbuflen = 0; - syslog( LOG_ERR, "afp_write: asp_wrtcont: %s", strerror(errno) ); - return( AFPERR_PARAM ); - } - - if (obj->options.flags & OPTION_DEBUG) { - printf("(write) len: %d\n", *rbuflen); - bprint(rbuf, *rbuflen); - } - - if ((cc = write_file(ofork, eid, offset, rbuf, *rbuflen, - xlate)) < 0) { - *rbuflen = 0; - ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount); - return cc; - } - offset += cc; - break; + if (asp_wrtcont(obj->handle, rbuf, rbuflen) < 0) { + *rbuflen = 0; + syslog( LOG_ERR, "afp_write: asp_wrtcont: %s", strerror(errno) ); + return( AFPERR_PARAM ); + } + + if (obj->options.flags & OPTION_DEBUG) { + printf("(write) len: %d\n", *rbuflen); + bprint(rbuf, *rbuflen); + } + + if ((cc = write_file(ofork, eid, offset, rbuf, *rbuflen, + xlate)) < 0) { + *rbuflen = 0; + ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount); + return cc; + } + offset += cc; + break; #endif /* no afp/asp */ case AFPPROTO_DSI: - { - DSI *dsi = obj->handle; - - /* find out what we have already and write it out. */ - cc = dsi_writeinit(dsi, rbuf, *rbuflen); - if (!cc || - (cc = write_file(ofork, eid, offset, rbuf, cc, xlate)) < 0) { - dsi_writeflush(dsi); - *rbuflen = 0; - ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount); - return cc; - } - offset += cc; - + { + DSI *dsi = obj->handle; + + /* find out what we have already and write it out. */ + cc = dsi_writeinit(dsi, rbuf, *rbuflen); + if (!cc || + (cc = write_file(ofork, eid, offset, rbuf, cc, xlate)) < 0) { + dsi_writeflush(dsi); + *rbuflen = 0; + ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount); + return cc; + } + offset += cc; + #if 0 /*def HAVE_SENDFILE_WRITE*/ - if (!(xlate || obj->options.flags & OPTION_DEBUG)) { - if ((cc = ad_writefile(ofork->of_ad, eid, dsi->socket, - offset, dsi->datasize)) < 0) { - switch (errno) { - case EDQUOT : - case EFBIG : - case ENOSPC : - cc = AFPERR_DFULL; - break; - default : - syslog( LOG_ERR, "afp_write: ad_writefile: %s", strerror(errno) ); - goto afp_write_loop; - } - dsi_writeflush(dsi); - *rbuflen = 0; - ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, - reqcount); - return cc; - } - - offset += cc; - goto afp_write_done; - } + if (!(xlate || obj->options.flags & OPTION_DEBUG)) { + if ((cc = ad_writefile(ofork->of_ad, eid, dsi->socket, + offset, dsi->datasize)) < 0) { + switch (errno) { + case EDQUOT : + case EFBIG : + case ENOSPC : + cc = AFPERR_DFULL; + break; + default : + syslog( LOG_ERR, "afp_write: ad_writefile: %s", strerror(errno) ); + goto afp_write_loop; + } + dsi_writeflush(dsi); + *rbuflen = 0; + ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, + reqcount); + return cc; + } + + offset += cc; + goto afp_write_done; + } #endif /* 0, was HAVE_SENDFILE_WRITE */ - /* loop until everything gets written. currently - * dsi_write handles the end case by itself. */ + /* loop until everything gets written. currently + * dsi_write handles the end case by itself. */ afp_write_loop: - while ((cc = dsi_write(dsi, rbuf, *rbuflen))) { - if ( obj->options.flags & OPTION_DEBUG ) { - printf("(write) command cont'd: %d\n", cc); - bprint(rbuf, cc); - } - - if ((cc = write_file(ofork, eid, offset, rbuf, cc, xlate)) < 0) { - dsi_writeflush(dsi); - *rbuflen = 0; - ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, - reqcount); - return cc; - } - offset += cc; - } - } - break; + while ((cc = dsi_write(dsi, rbuf, *rbuflen))) { + if ( obj->options.flags & OPTION_DEBUG ) { + printf("(write) command cont'd: %d\n", cc); + bprint(rbuf, cc); + } + + if ((cc = write_file(ofork, eid, offset, rbuf, cc, xlate)) < 0) { + dsi_writeflush(dsi); + *rbuflen = 0; + ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, + reqcount); + return cc; + } + offset += cc; + } + } + break; } afp_write_done: ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount); - if ( ad_hfileno( ofork->of_ad ) != -1 ) - ofork->of_flags |= AFPFORK_DIRTY; + if ( ad_hfileno( ofork->of_ad ) != -1 ) + ofork->of_flags |= AFPFORK_DIRTY; offset = htonl( offset ); #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG) @@ -1305,8 +1305,8 @@ afp_write_done: afp_write_err: if (obj->proto == AFPPROTO_DSI) { - dsi_writeinit(obj->handle, rbuf, *rbuflen); - dsi_writeflush(obj->handle); + dsi_writeinit(obj->handle, rbuf, *rbuflen); + dsi_writeflush(obj->handle); } *rbuflen = (err == AFP_OK) ? sizeof(offset) : 0; @@ -1315,9 +1315,9 @@ afp_write_err: int afp_getforkparams(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct ofork *ofork; int buflen, ret; @@ -1332,13 +1332,13 @@ int afp_getforkparams(obj, ibuf, ibuflen, rbuf, rbuflen ) *rbuflen = 0; if (( ofork = of_find( ofrefnum )) == NULL ) { - syslog( LOG_ERR, "afp_getforkparams: of_find: %s", strerror(errno) ); - return( AFPERR_PARAM ); + syslog( LOG_ERR, "afp_getforkparams: of_find: %s", strerror(errno) ); + return( AFPERR_PARAM ); } if (( ret = getforkparams( ofork, bitmap, - rbuf + sizeof( u_short ), &buflen, 0 )) != AFP_OK ) { - return( ret ); + rbuf + sizeof( u_short ), &buflen, 0 )) != AFP_OK ) { + return( ret ); } *rbuflen = buflen + sizeof( u_short ); diff --git a/etc/afpd/fork.h b/etc/afpd/fork.h index f1cfca51..0bf29200 100644 --- a/etc/afpd/fork.h +++ b/etc/afpd/fork.h @@ -1,5 +1,5 @@ /* - * $Id: fork.h,v 1.2 2001-06-20 18:33:04 rufustfirefly Exp $ + * $Id: fork.h,v 1.2.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -45,16 +45,16 @@ struct ofork { #define AFPFORK_ACCMASK (AFPFORK_ACCRD | AFPFORK_ACCWR) /* in ofork.c */ -extern struct ofork *of_alloc __P((struct vol *, struct dir *, - char *, u_int16_t *, const int, - struct adouble *)); +extern struct ofork *of_alloc __P((struct vol *, struct dir *, + char *, u_int16_t *, const int, + struct adouble *)); extern void of_dealloc __P((struct ofork *)); extern struct ofork *of_find __P((const u_int16_t)); extern struct ofork *of_findname __P((const struct vol *, const struct dir *, - const char *)); -extern int of_rename __P((const struct vol *, - struct dir *, const char *, - struct dir *, const char *)); + const char *)); +extern int of_rename __P((const struct vol *, + struct dir *, const char *, + struct dir *, const char *)); extern int of_flush __P((const struct vol *)); extern void of_pforkdesc __P((FILE *)); diff --git a/etc/afpd/gettok.c b/etc/afpd/gettok.c index 2dd55a0d..6e3fccfb 100644 --- a/etc/afpd/gettok.c +++ b/etc/afpd/gettok.c @@ -1,5 +1,5 @@ /* - * $Id: gettok.c,v 1.4 2001-09-06 20:00:59 rufustfirefly Exp $ + * $Id: gettok.c,v 1.4.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1994 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -35,8 +35,8 @@ static char *l_curr; static char *l_end; void initline( len, line ) - int len; - char *line; +int len; +char *line; { l_curr = line; l_end = line + len; @@ -46,10 +46,10 @@ void initline( len, line ) #define ST_WORD 1 #define ST_BEGIN 2 - int +int parseline( len, token ) - int len; - char *token; +int len; +char *token; { char *p, *e; int state; @@ -59,59 +59,59 @@ parseline( len, token ) e = token + len; for (;;) { - if ( l_curr > l_end ) { /* end of line */ - *token = '\0'; - return( -1 ); - } - - switch ( *l_curr ) { - case '"' : - if ( state == ST_QUOTE ) { - state = ST_WORD; - } else { - state = ST_QUOTE; - } - break; - - case '\0' : - case '\t' : - case '\n' : - case ' ' : - if ( state == ST_WORD ) { - *p = '\0'; - return( p - token ); - } - if ( state != ST_QUOTE ) { - break; - } - /* FALL THROUGH */ - - default : - if ( state == ST_BEGIN ) { - state = ST_WORD; - } - if ( p > e ) { /* end of token */ - *token = '\0'; - return( -1 ); - } - *p++ = *l_curr; - break; - } - - l_curr++; + if ( l_curr > l_end ) { /* end of line */ + *token = '\0'; + return( -1 ); + } + + switch ( *l_curr ) { + case '"' : + if ( state == ST_QUOTE ) { + state = ST_WORD; + } else { + state = ST_QUOTE; + } + break; + + case '\0' : + case '\t' : + case '\n' : + case ' ' : + if ( state == ST_WORD ) { + *p = '\0'; + return( p - token ); + } + if ( state != ST_QUOTE ) { + break; + } + /* FALL THROUGH */ + + default : + if ( state == ST_BEGIN ) { + state = ST_WORD; + } + if ( p > e ) { /* end of token */ + *token = '\0'; + return( -1 ); + } + *p++ = *l_curr; + break; + } + + l_curr++; } } #ifdef notdef void parseline( token, user ) - char *token, *user; +char *token, *user; { char *p = pos, *t = token, *u, *q, buf[ MAXPATHLEN ]; struct passwd *pwent; int quoted = 0; while ( isspace( *p )) { - p++; + p++; } /* @@ -119,25 +119,25 @@ void parseline( token, user ) * don't return any more tokens. */ if ( *p == '\0' || *p == '#' ) { - *token = '\0'; - return; + *token = '\0'; + return; } if ( *p == '"' ) { - p++; - quoted = 1; + p++; + quoted = 1; } while ( *p != '\0' && ( quoted || !isspace( *p ))) { - if ( *p == '"' ) { - if ( quoted ) { - *t = '\0'; - break; - } - quoted = 1; - p++; - } else { - *t++ = *p++; - } + if ( *p == '"' ) { + if ( quoted ) { + *t = '\0'; + break; + } + quoted = 1; + p++; + } else { + *t++ = *p++; + } } pos = p; *t = '\0'; @@ -146,37 +146,37 @@ void parseline( token, user ) * We got to the end of the line without closing an open quote */ if ( *p == '\0' && quoted ) { - *token = '\0'; - return; + *token = '\0'; + return; } t = token; if ( *t == '~' ) { - t++; - if ( *t == '\0' || *t == '/' ) { - u = user; - if ( *t == '/' ) { - t++; - } - } else { - u = t; - if (( q = strchr( t, '/' )) == NULL ) { - t = ""; - } else { - *q = '\0'; - t = q + 1; - } - } - if ( u == NULL || ( pwent = getpwnam( u )) == NULL ) { - *token = '\0'; - return; - } - strcpy( buf, pwent->pw_dir ); - if ( *t != '\0' ) { - strcat( buf, "/" ); - strcat( buf, t ); - } - strcpy( token, buf ); + t++; + if ( *t == '\0' || *t == '/' ) { + u = user; + if ( *t == '/' ) { + t++; + } + } else { + u = t; + if (( q = strchr( t, '/' )) == NULL ) { + t = ""; + } else { + *q = '\0'; + t = q + 1; + } + } + if ( u == NULL || ( pwent = getpwnam( u )) == NULL ) { + *token = '\0'; + return; + } + strcpy( buf, pwent->pw_dir ); + if ( *t != '\0' ) { + strcat( buf, "/" ); + strcat( buf, t ); + } + strcpy( token, buf ); } return; } diff --git a/etc/afpd/globals.h b/etc/afpd/globals.h index e254547c..75fd1ef5 100644 --- a/etc/afpd/globals.h +++ b/etc/afpd/globals.h @@ -1,5 +1,5 @@ /* - * $Id: globals.h,v 1.6 2001-10-23 13:44:37 rufustfirefly Exp $ + * $Id: globals.h,v 1.6.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -40,36 +40,36 @@ /* a couple of these options could get stuck in unions to save * space. */ struct afp_options { - int connections, port, transports, tickleval, flags; - unsigned char passwdbits, passwdminlen, loginmaxfail; - u_int32_t server_quantum; - char hostname[MAXHOSTNAMELEN + 1], *server, *ipaddr, *configfile; - struct at_addr ddpaddr; - char *uampath, *nlspath, *fqdn; - char *pidfile, *defaultvol, *systemvol; - char *guest, *loginmesg, *keyfile, *passwdfile; - char *uamlist; - char *authprintdir; - mode_t umask; + int connections, port, transports, tickleval, flags; + unsigned char passwdbits, passwdminlen, loginmaxfail; + u_int32_t server_quantum; + char hostname[MAXHOSTNAMELEN + 1], *server, *ipaddr, *configfile; + struct at_addr ddpaddr; + char *uampath, *nlspath, *fqdn; + char *pidfile, *defaultvol, *systemvol; + char *guest, *loginmesg, *keyfile, *passwdfile; + char *uamlist; + char *authprintdir; + mode_t umask; #ifdef ADMIN_GRP - gid_t admingid; + gid_t admingid; #endif /* ADMIN_GRP */ }; #define AFPOBJ_TMPSIZ (MAXPATHLEN) typedef struct AFPObj { - int proto; - unsigned long servernum; - void *handle, *config; - struct afp_options options; - char *Obj, *Type, *Zone; - char username[MACFILELEN + 1]; - void (*logout)(void), (*exit)(int); - int (*reply)(void *, int); - int (*attention)(void *, AFPUserBytes); - /* to prevent confusion, only use these in afp_* calls */ - char oldtmp[AFPOBJ_TMPSIZ + 1], newtmp[AFPOBJ_TMPSIZ + 1]; - void *uam_cookie; /* cookie for uams */ + int proto; + unsigned long servernum; + void *handle, *config; + struct afp_options options; + char *Obj, *Type, *Zone; + char username[MACFILELEN + 1]; + void (*logout)(void), (*exit)(int); + int (*reply)(void *, int); + int (*attention)(void *, AFPUserBytes); + /* to prevent confusion, only use these in afp_* calls */ + char oldtmp[AFPOBJ_TMPSIZ + 1], newtmp[AFPOBJ_TMPSIZ + 1]; + void *uam_cookie; /* cookie for uams */ } AFPObj; extern int afp_version; @@ -81,8 +81,8 @@ extern char getwdbuf[]; extern void afp_options_init __P((struct afp_options *)); extern int afp_options_parse __P((int, char **, struct afp_options *)); extern int afp_options_parseline __P((char *, struct afp_options *)); -extern void afp_options_free __P((struct afp_options *, - const struct afp_options *)); +extern void afp_options_free __P((struct afp_options *, + const struct afp_options *)); extern void setmessage __P((const char *)); extern void readmessage __P((void)); diff --git a/etc/afpd/icon.h b/etc/afpd/icon.h index d7d01ba0..c75b4588 100644 --- a/etc/afpd/icon.h +++ b/etc/afpd/icon.h @@ -1,5 +1,5 @@ /* - * $Id: icon.h,v 1.2 2001-06-20 18:33:04 rufustfirefly Exp $ + * $Id: icon.h,v 1.2.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1994 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -12,73 +12,73 @@ #include "globals.h" const unsigned char apple_atalk_icon[] = { /* default appletalk icon */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x9F, 0xE0, - 0x00, 0x04, 0x50, 0x30, 0x00, 0x08, 0x30, 0x28, - 0x00, 0x10, 0x10, 0x3C, 0x07, 0xA0, 0x08, 0x04, - 0x18, 0x7F, 0x04, 0x04, 0x10, 0x00, 0x82, 0x04, - 0x10, 0x00, 0x81, 0x04, 0x10, 0x00, 0x82, 0x04, - 0x10, 0x00, 0x84, 0x04, 0x10, 0x00, 0x88, 0x04, - 0x10, 0x00, 0x90, 0x04, 0x10, 0x00, 0xB0, 0x04, - 0x10, 0x00, 0xD0, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, - 0x40, 0x00, 0x00, 0x02, 0x3F, 0xFF, 0xFF, 0xFC, - 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, - 0x00, 0x00, 0x0F, 0x80, 0x00, 0x00, 0x08, 0x80, - 0x00, 0x00, 0x08, 0x80, 0x00, 0x00, 0x0F, 0x80, - 0x00, 0x00, 0x0A, 0x80, 0xBF, 0xFF, 0xF2, 0x74, - 0x00, 0x00, 0x05, 0x00, 0xBF, 0xFF, 0xF8, 0xF4, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x9F, 0xE0, - 0x00, 0x07, 0xDF, 0xF0, 0x00, 0x0F, 0xFF, 0xF8, - 0x00, 0x1F, 0xFF, 0xFC, 0x07, 0xBF, 0xFF, 0xFC, - 0x1F, 0xFF, 0xFF, 0xFC, 0x1F, 0xFF, 0xFF, 0xFC, - 0x1F, 0xFF, 0xFF, 0xFC, 0x1F, 0xFF, 0xFF, 0xFC, - 0x1F, 0xFF, 0xFF, 0xFC, 0x1F, 0xFF, 0xFF, 0xFC, - 0x1F, 0xFF, 0xFF, 0xFC, 0x1F, 0xFF, 0xFF, 0xFC, - 0x1F, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, - 0x7F, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xFC, - 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, - 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, - 0x00, 0x00, 0x0F, 0x80, 0x00, 0x00, 0x0F, 0x80, - 0x00, 0x00, 0x0F, 0x80, 0x00, 0x00, 0x0F, 0x80, - 0x00, 0x00, 0x0F, 0x80, 0xBF, 0xFF, 0xFF, 0xF4, - 0xBF, 0xFF, 0xFD, 0xF4, 0xBF, 0xFF, 0xF8, 0xF4 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x9F, 0xE0, + 0x00, 0x04, 0x50, 0x30, 0x00, 0x08, 0x30, 0x28, + 0x00, 0x10, 0x10, 0x3C, 0x07, 0xA0, 0x08, 0x04, + 0x18, 0x7F, 0x04, 0x04, 0x10, 0x00, 0x82, 0x04, + 0x10, 0x00, 0x81, 0x04, 0x10, 0x00, 0x82, 0x04, + 0x10, 0x00, 0x84, 0x04, 0x10, 0x00, 0x88, 0x04, + 0x10, 0x00, 0x90, 0x04, 0x10, 0x00, 0xB0, 0x04, + 0x10, 0x00, 0xD0, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, + 0x40, 0x00, 0x00, 0x02, 0x3F, 0xFF, 0xFF, 0xFC, + 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x05, 0x00, + 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, + 0x00, 0x00, 0x0F, 0x80, 0x00, 0x00, 0x08, 0x80, + 0x00, 0x00, 0x08, 0x80, 0x00, 0x00, 0x0F, 0x80, + 0x00, 0x00, 0x0A, 0x80, 0xBF, 0xFF, 0xF2, 0x74, + 0x00, 0x00, 0x05, 0x00, 0xBF, 0xFF, 0xF8, 0xF4, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x9F, 0xE0, + 0x00, 0x07, 0xDF, 0xF0, 0x00, 0x0F, 0xFF, 0xF8, + 0x00, 0x1F, 0xFF, 0xFC, 0x07, 0xBF, 0xFF, 0xFC, + 0x1F, 0xFF, 0xFF, 0xFC, 0x1F, 0xFF, 0xFF, 0xFC, + 0x1F, 0xFF, 0xFF, 0xFC, 0x1F, 0xFF, 0xFF, 0xFC, + 0x1F, 0xFF, 0xFF, 0xFC, 0x1F, 0xFF, 0xFF, 0xFC, + 0x1F, 0xFF, 0xFF, 0xFC, 0x1F, 0xFF, 0xFF, 0xFC, + 0x1F, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, + 0x7F, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xFC, + 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, + 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, + 0x00, 0x00, 0x0F, 0x80, 0x00, 0x00, 0x0F, 0x80, + 0x00, 0x00, 0x0F, 0x80, 0x00, 0x00, 0x0F, 0x80, + 0x00, 0x00, 0x0F, 0x80, 0xBF, 0xFF, 0xFF, 0xF4, + 0xBF, 0xFF, 0xFD, 0xF4, 0xBF, 0xFF, 0xF8, 0xF4 }; const unsigned char apple_tcp_icon[] = { /* default asip icon */ - 0x30, 0x00, 0x8f, 0xf8, 0xcc, 0x01, 0x48, 0x0c, - 0xb3, 0x32, 0x28, 0x0a, 0x8c, 0xcc, 0x7c, 0x0f, - 0x83, 0x02, 0xff, 0x01, 0x80, 0xc3, 0xc3, 0x81, - 0x80, 0x33, 0xe3, 0xc1, 0x80, 0x0b, 0xd3, 0xc1, - 0x80, 0x0b, 0xb1, 0x61, 0x80, 0x0b, 0xe0, 0xe1, - 0x80, 0x0b, 0xe1, 0xe1, 0x80, 0x0b, 0xd1, 0xe1, - 0xc0, 0x0a, 0xc0, 0xe1, 0x70, 0x0b, 0x78, 0xc1, - 0x1c, 0x0b, 0x79, 0xc1, 0x17, 0x0b, 0x33, 0xff, - 0x21, 0xcb, 0xff, 0xc4, 0x40, 0x7f, 0xff, 0x02, - 0x80, 0x1e, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, - 0x80, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x02, 0x80, 0x00, 0x00, 0x02, 0x80, 0x00, - 0x00, 0x07, 0xc0, 0x00, 0x00, 0x04, 0x40, 0x00, - 0x00, 0x04, 0x40, 0x00, 0x00, 0x07, 0xc0, 0x00, - 0x00, 0x05, 0x40, 0x00, 0x0f, 0xf9, 0x3f, 0xfc, - 0x00, 0x02, 0x80, 0x00, 0x0f, 0xfc, 0x7f, 0xfc, - 0x30, 0x00, 0x8f, 0xf8, 0xfc, 0x01, 0xcf, 0xfc, - 0xff, 0x33, 0xef, 0xfe, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, - 0x1f, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, - 0x3f, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xfe, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x03, 0x80, 0x00, 0x00, 0x03, 0x80, 0x00, - 0x00, 0x07, 0xc0, 0x00, 0x00, 0x07, 0xc0, 0x00, - 0x00, 0x07, 0xc0, 0x00, 0x00, 0x07, 0xc0, 0x00, - 0x00, 0x07, 0xc0, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x3f, 0xfe, 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff + 0x30, 0x00, 0x8f, 0xf8, 0xcc, 0x01, 0x48, 0x0c, + 0xb3, 0x32, 0x28, 0x0a, 0x8c, 0xcc, 0x7c, 0x0f, + 0x83, 0x02, 0xff, 0x01, 0x80, 0xc3, 0xc3, 0x81, + 0x80, 0x33, 0xe3, 0xc1, 0x80, 0x0b, 0xd3, 0xc1, + 0x80, 0x0b, 0xb1, 0x61, 0x80, 0x0b, 0xe0, 0xe1, + 0x80, 0x0b, 0xe1, 0xe1, 0x80, 0x0b, 0xd1, 0xe1, + 0xc0, 0x0a, 0xc0, 0xe1, 0x70, 0x0b, 0x78, 0xc1, + 0x1c, 0x0b, 0x79, 0xc1, 0x17, 0x0b, 0x33, 0xff, + 0x21, 0xcb, 0xff, 0xc4, 0x40, 0x7f, 0xff, 0x02, + 0x80, 0x1e, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, + 0x80, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x02, 0x80, 0x00, 0x00, 0x02, 0x80, 0x00, + 0x00, 0x07, 0xc0, 0x00, 0x00, 0x04, 0x40, 0x00, + 0x00, 0x04, 0x40, 0x00, 0x00, 0x07, 0xc0, 0x00, + 0x00, 0x05, 0x40, 0x00, 0x0f, 0xf9, 0x3f, 0xfc, + 0x00, 0x02, 0x80, 0x00, 0x0f, 0xfc, 0x7f, 0xfc, + 0x30, 0x00, 0x8f, 0xf8, 0xfc, 0x01, 0xcf, 0xfc, + 0xff, 0x33, 0xef, 0xfe, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, + 0x1f, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, + 0x3f, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xfe, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x03, 0x80, 0x00, 0x00, 0x03, 0x80, 0x00, + 0x00, 0x07, 0xc0, 0x00, 0x00, 0x07, 0xc0, 0x00, + 0x00, 0x07, 0xc0, 0x00, 0x00, 0x07, 0xc0, 0x00, + 0x00, 0x07, 0xc0, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x3f, 0xfe, 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff }; #if defined( ultrix ) diff --git a/etc/afpd/main.c b/etc/afpd/main.c index b71c45a2..eb416cc4 100644 --- a/etc/afpd/main.c +++ b/etc/afpd/main.c @@ -1,5 +1,5 @@ /* - * $Id: main.c,v 1.12 2001-10-23 13:44:37 rufustfirefly Exp $ + * $Id: main.c,v 1.12.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -71,15 +71,15 @@ static fd_set save_rfds; #ifdef TRU64 void afp_get_cmdline( int *ac, char ***av) { - *ac = argc; - *av = argv; + *ac = argc; + *av = argv; } #endif /* TRU64 */ static void afp_exit(const int i) { - server_unlock(default_options.pidfile); - exit(i); + server_unlock(default_options.pidfile); + exit(i); } static void afp_goaway(int sig) @@ -90,58 +90,58 @@ static void afp_goaway(int sig) dsi_kill(sig); switch( sig ) { case SIGTERM : - syslog( LOG_INFO, "shutting down on signal %d", sig ); - break; + syslog( LOG_INFO, "shutting down on signal %d", sig ); + break; case SIGHUP : - /* w/ a configuration file, we can force a re-read if we want */ - nologin++; - if ((nologin + 1) & 1) { - AFPConfig *config; - - syslog(LOG_INFO, "re-reading configuration file"); - for (config = configs; config; config = config->next) - if (config->server_cleanup) - config->server_cleanup(config); - - configfree(configs, NULL); - if (!(configs = configinit(&default_options))) { - syslog(LOG_ERR, "config re-read: no servers configured"); - afp_exit(1); - } - FD_ZERO(&save_rfds); - for (config = configs; config; config = config->next) { - if (config->fd < 0) - continue; - FD_SET(config->fd, &save_rfds); - } - } else { - syslog(LOG_INFO, "disallowing logins"); - auth_unload(); - } - break; + /* w/ a configuration file, we can force a re-read if we want */ + nologin++; + if ((nologin + 1) & 1) { + AFPConfig *config; + + syslog(LOG_INFO, "re-reading configuration file"); + for (config = configs; config; config = config->next) + if (config->server_cleanup) + config->server_cleanup(config); + + configfree(configs, NULL); + if (!(configs = configinit(&default_options))) { + syslog(LOG_ERR, "config re-read: no servers configured"); + afp_exit(1); + } + FD_ZERO(&save_rfds); + for (config = configs; config; config = config->next) { + if (config->fd < 0) + continue; + FD_SET(config->fd, &save_rfds); + } + } else { + syslog(LOG_INFO, "disallowing logins"); + auth_unload(); + } + break; default : - syslog( LOG_ERR, "afp_goaway: bad signal" ); + syslog( LOG_ERR, "afp_goaway: bad signal" ); } if ( sig == SIGTERM ) { - AFPConfig *config; - - for (config = configs; config; config = config->next) - if (config->server_cleanup) - config->server_cleanup(config); + AFPConfig *config; - afp_exit(0); + for (config = configs; config; config = config->next) + if (config->server_cleanup) + config->server_cleanup(config); + + afp_exit(0); } return; } static void child_handler() { - server_child_handler(server_children); + server_child_handler(server_children); } int main( ac, av ) - int ac; - char **av; +int ac; +char **av; { AFPConfig *config; fd_set rfds; @@ -158,18 +158,18 @@ int main( ac, av ) afp_options_init(&default_options); if (!afp_options_parse(ac, av, &default_options)) - exit(1); + exit(1); umask( default_options.umask ); - - switch(server_lock("afpd", default_options.pidfile, - default_options.flags & OPTION_DEBUG)) { + + switch(server_lock("afpd", default_options.pidfile, + default_options.flags & OPTION_DEBUG)) { case -1: /* error */ - exit(1); + exit(1); case 0: /* child */ - break; + break; default: /* server */ - exit(0); + exit(0); } #ifdef DID_MTAB @@ -181,18 +181,18 @@ int main( ac, av ) * as afp_goaway references stuff from here. * XXX: this should really be setup after the initial connections. */ if (!(server_children = server_child_alloc(default_options.connections, - CHILD_NFORKS))) { - syslog( LOG_ERR, "main: server_child alloc: %s", strerror(errno) ); - afp_exit(1); + CHILD_NFORKS))) { + syslog( LOG_ERR, "main: server_child alloc: %s", strerror(errno) ); + afp_exit(1); } - + memset(&sv, 0, sizeof(sv)); sv.sa_handler = child_handler; sigemptyset( &sv.sa_mask ); sv.sa_flags = SA_RESTART; if ( sigaction( SIGCHLD, &sv, 0 ) < 0 ) { - syslog( LOG_ERR, "main: sigaction: %s", strerror(errno) ); - afp_exit(1); + syslog( LOG_ERR, "main: sigaction: %s", strerror(errno) ); + afp_exit(1); } sv.sa_handler = afp_goaway; @@ -201,14 +201,14 @@ int main( ac, av ) sigaddset(&sv.sa_mask, SIGTERM); sv.sa_flags = SA_RESTART; if ( sigaction( SIGHUP, &sv, 0 ) < 0 ) { - syslog( LOG_ERR, "main: sigaction: %s", strerror(errno) ); - afp_exit(1); + syslog( LOG_ERR, "main: sigaction: %s", strerror(errno) ); + afp_exit(1); } if ( sigaction( SIGTERM, &sv, 0 ) < 0 ) { - syslog( LOG_ERR, "main: sigaction: %s", strerror(errno) ); - afp_exit(1); + syslog( LOG_ERR, "main: sigaction: %s", strerror(errno) ); + afp_exit(1); } - + /* afpd.conf: not in config file: lockfile, connections, configfile * preference: command-line provides defaults. * config file over-writes defaults. @@ -222,19 +222,19 @@ int main( ac, av ) sigaddset(&sigs, SIGTERM); sigprocmask(SIG_BLOCK, &sigs, NULL); if (!(configs = configinit(&default_options))) { - syslog(LOG_ERR, "main: no servers configured: %s\n", strerror(errno)); - afp_exit(1); + syslog(LOG_ERR, "main: no servers configured: %s\n", strerror(errno)); + afp_exit(1); } sigprocmask(SIG_UNBLOCK, &sigs, NULL); /* watch atp and dsi sockets. */ FD_ZERO(&save_rfds); for (config = configs; config; config = config->next) { - if (config->fd < 0) /* for proxies */ - continue; - FD_SET(config->fd, &save_rfds); + if (config->fd < 0) /* for proxies */ + continue; + FD_SET(config->fd, &save_rfds); } - + /* wait for an appleshare connection. parent remains in the loop * while the children get handled by afp_over_{asp,dsi}. this is * currently vulnerable to a denial-of-service attack if a @@ -242,20 +242,20 @@ int main( ac, av ) * afterwards. establishing timeouts for logins is a possible * solution. */ while (1) { - rfds = save_rfds; - if (select(FD_SETSIZE, &rfds, NULL, NULL, NULL) < 0) { - if (errno == EINTR) - continue; - syslog(LOG_ERR, "main: can't wait for input: %s", strerror(errno)); - break; - } - - for (config = configs; config; config = config->next) { - if (config->fd < 0) - continue; - if (FD_ISSET(config->fd, &rfds)) - config->server_start(config, configs, server_children); - } + rfds = save_rfds; + if (select(FD_SETSIZE, &rfds, NULL, NULL, NULL) < 0) { + if (errno == EINTR) + continue; + syslog(LOG_ERR, "main: can't wait for input: %s", strerror(errno)); + break; + } + + for (config = configs; config; config = config->next) { + if (config->fd < 0) + continue; + if (FD_ISSET(config->fd, &rfds)) + config->server_start(config, configs, server_children); + } } return 0; diff --git a/etc/afpd/messages.c b/etc/afpd/messages.c index 9f84b76d..eb62369a 100644 --- a/etc/afpd/messages.c +++ b/etc/afpd/messages.c @@ -1,5 +1,5 @@ -/* - * $Id: messages.c,v 1.9 2001-06-20 18:33:04 rufustfirefly Exp $ +/* + * $Id: messages.c,v 1.9.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu) * All Rights Reserved. See COPYRIGHT. @@ -26,116 +26,116 @@ static char servermesg[MAXMESGSIZE] = ""; void setmessage(const char *message) { - strncpy(servermesg, message, MAXMESGSIZE); + strncpy(servermesg, message, MAXMESGSIZE); } void readmessage(void) { -/* Read server message from file defined as SERVERTEXT */ + /* Read server message from file defined as SERVERTEXT */ #ifdef SERVERTEXT - FILE *message; - char * filename; - int i, rc; - static int c; - uid_t euid; + FILE *message; + char * filename; + int i, rc; + static int c; + uid_t euid; - i=0; - // Construct file name SERVERTEXT/message.[pid] - filename=malloc(sizeof(SERVERTEXT)+15); - sprintf(filename, "%s/message.%d", SERVERTEXT, getpid()); + i=0; + // Construct file name SERVERTEXT/message.[pid] + filename=malloc(sizeof(SERVERTEXT)+15); + sprintf(filename, "%s/message.%d", SERVERTEXT, getpid()); #ifdef DEBUG - syslog (LOG_DEBUG, "Reading file %s ", filename); + syslog (LOG_DEBUG, "Reading file %s ", filename); #endif /* DEBUG */ - - message=fopen(filename, "r"); - if (message==NULL) { - syslog (LOG_INFO, "Unable to open file %s", filename); - sprintf(filename, "%s/message", SERVERTEXT); - message=fopen(filename, "r"); - } - - /* if either message.pid or message exists */ - if (message!=NULL) { - /* added while loop to get characters and put in servermesg */ - while ((( c=fgetc(message)) != EOF) && (i < (MAXMESGSIZE - 1))) { - if ( c == '\n') c = ' '; - servermesg[i++] = c; - } - servermesg[i] = 0; - - /* cleanup */ - fclose(message); - - /* Save effective uid and switch to root to delete file. */ - /* Delete will probably fail otherwise, but let's try anyways */ - euid = geteuid(); - if (seteuid(0) < 0) { - syslog(LOG_ERR, "Could not switch back to root: %m"); - } - - rc = unlink(filename); - /* Drop privs again, failing this is very bad */ - if (seteuid(euid) < 0) { - syslog(LOG_ERR, "Could not switch back to uid %d: %m", euid); + message=fopen(filename, "r"); + if (message==NULL) { + syslog (LOG_INFO, "Unable to open file %s", filename); + sprintf(filename, "%s/message", SERVERTEXT); + message=fopen(filename, "r"); } - if (rc < 0) { - syslog (LOG_ERR, "Error deleting %s: %m", filename); - } + /* if either message.pid or message exists */ + if (message!=NULL) { + /* added while loop to get characters and put in servermesg */ + while ((( c=fgetc(message)) != EOF) && (i < (MAXMESGSIZE - 1))) { + if ( c == '\n') c = ' '; + servermesg[i++] = c; + } + servermesg[i] = 0; + + /* cleanup */ + fclose(message); + + /* Save effective uid and switch to root to delete file. */ + /* Delete will probably fail otherwise, but let's try anyways */ + euid = geteuid(); + if (seteuid(0) < 0) { + syslog(LOG_ERR, "Could not switch back to root: %m"); + } + + rc = unlink(filename); + + /* Drop privs again, failing this is very bad */ + if (seteuid(euid) < 0) { + syslog(LOG_ERR, "Could not switch back to uid %d: %m", euid); + } + + if (rc < 0) { + syslog (LOG_ERR, "Error deleting %s: %m", filename); + } #ifdef DEBUG - else { - syslog (LOG_INFO, "Deleted %s", filename); - } + else { + syslog (LOG_INFO, "Deleted %s", filename); + } - syslog (LOG_INFO, "Set server message to \"%s\"", servermesg); + syslog (LOG_INFO, "Set server message to \"%s\"", servermesg); #endif /* DEBUG */ - } - free(filename); + } + free(filename); #endif /* SERVERTEXT */ } int afp_getsrvrmesg(obj, ibuf, ibuflen, rbuf, rbuflen) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { - char *message; - u_int16_t type, bitmap; - - memcpy(&type, ibuf + 2, sizeof(type)); - memcpy(&bitmap, ibuf + 4, sizeof(bitmap)); - - switch (ntohs(type)) { - case AFPMESG_LOGIN: /* login */ - message = obj->options.loginmesg; - break; - case AFPMESG_SERVER: /* server */ - message = servermesg; - break; - default: - *rbuflen = 0; - return AFPERR_BITMAP; - } - - /* output format: - * message type: 2 bytes - * bitmap: 2 bytes - * message length: 1 byte - * message: up to 199 bytes - */ - memcpy(rbuf, &type, sizeof(type)); - rbuf += sizeof(type); - memcpy(rbuf, &bitmap, sizeof(bitmap)); - rbuf += sizeof(bitmap); - *rbuflen = strlen(message); - if (*rbuflen > MAXMESGSIZE) - *rbuflen = MAXMESGSIZE; - *rbuf++ = *rbuflen; - memcpy(rbuf, message, *rbuflen); - - *rbuflen += 5; - - return AFP_OK; + char *message; + u_int16_t type, bitmap; + + memcpy(&type, ibuf + 2, sizeof(type)); + memcpy(&bitmap, ibuf + 4, sizeof(bitmap)); + + switch (ntohs(type)) { + case AFPMESG_LOGIN: /* login */ + message = obj->options.loginmesg; + break; + case AFPMESG_SERVER: /* server */ + message = servermesg; + break; + default: + *rbuflen = 0; + return AFPERR_BITMAP; + } + + /* output format: + * message type: 2 bytes + * bitmap: 2 bytes + * message length: 1 byte + * message: up to 199 bytes + */ + memcpy(rbuf, &type, sizeof(type)); + rbuf += sizeof(type); + memcpy(rbuf, &bitmap, sizeof(bitmap)); + rbuf += sizeof(bitmap); + *rbuflen = strlen(message); + if (*rbuflen > MAXMESGSIZE) + *rbuflen = MAXMESGSIZE; + *rbuf++ = *rbuflen; + memcpy(rbuf, message, *rbuflen); + + *rbuflen += 5; + + return AFP_OK; } diff --git a/etc/afpd/misc.h b/etc/afpd/misc.h index 2ff92171..9600b402 100644 --- a/etc/afpd/misc.h +++ b/etc/afpd/misc.h @@ -1,5 +1,5 @@ -/* - * $Id: misc.h,v 1.2 2001-06-20 18:33:04 rufustfirefly Exp $ +/* + * $Id: misc.h,v 1.2.2.1 2001-12-03 05:01:04 jmarcus Exp $ */ #ifndef AFPD_MISC_H diff --git a/etc/afpd/nfsquota.c b/etc/afpd/nfsquota.c index 213eaf54..7bdd9e7c 100644 --- a/etc/afpd/nfsquota.c +++ b/etc/afpd/nfsquota.c @@ -1,5 +1,5 @@ /* - * $Id: nfsquota.c,v 1.4 2001-09-06 20:00:59 rufustfirefly Exp $ + * $Id: nfsquota.c,v 1.4.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * parts of this are lifted from the bsd quota program and are * therefore under the following copyright: @@ -55,43 +55,43 @@ char *strchr (), *strrchr (); #ifndef NO_QUOTA_SUPPORT /* lifted (with modifications) from the bsd quota program */ -static int +static int callaurpc(vol, prognum, versnum, procnum, inproc, in, outproc, out) - struct vol *vol; - u_long prognum, versnum, procnum; - xdrproc_t inproc, outproc; - char *in, *out; +struct vol *vol; +u_long prognum, versnum, procnum; +xdrproc_t inproc, outproc; +char *in, *out; { - enum clnt_stat clnt_stat; - struct timeval tottimeout; - - if (!vol->v_nfsclient) { - struct hostent *hp; - struct sockaddr_in server_addr; - struct timeval timeout; - int socket = RPC_ANYSOCK; - - if ((hp = gethostbyname(vol->v_gvs)) == NULL) - return ((int) RPC_UNKNOWNHOST); - timeout.tv_usec = 0; - timeout.tv_sec = 6; - memcpy(&server_addr.sin_addr, hp->h_addr, hp->h_length); - server_addr.sin_family = AF_INET; - server_addr.sin_port = 0; - - if ((vol->v_nfsclient = (void *) - clntudp_create(&server_addr, prognum, versnum, - timeout, &socket)) == NULL) - return ((int) rpc_createerr.cf_stat); - - ((CLIENT *) vol->v_nfsclient)->cl_auth = authunix_create_default(); - } - - tottimeout.tv_sec = 10; - tottimeout.tv_usec = 0; - clnt_stat = clnt_call((CLIENT *) vol->v_nfsclient, procnum, - inproc, in, outproc, out, tottimeout); - return ((int) clnt_stat); + enum clnt_stat clnt_stat; + struct timeval tottimeout; + + if (!vol->v_nfsclient) { + struct hostent *hp; + struct sockaddr_in server_addr; + struct timeval timeout; + int socket = RPC_ANYSOCK; + + if ((hp = gethostbyname(vol->v_gvs)) == NULL) + return ((int) RPC_UNKNOWNHOST); + timeout.tv_usec = 0; + timeout.tv_sec = 6; + memcpy(&server_addr.sin_addr, hp->h_addr, hp->h_length); + server_addr.sin_family = AF_INET; + server_addr.sin_port = 0; + + if ((vol->v_nfsclient = (void *) + clntudp_create(&server_addr, prognum, versnum, + timeout, &socket)) == NULL) + return ((int) rpc_createerr.cf_stat); + + ((CLIENT *) vol->v_nfsclient)->cl_auth = authunix_create_default(); + } + + tottimeout.tv_sec = 10; + tottimeout.tv_usec = 0; + clnt_stat = clnt_call((CLIENT *) vol->v_nfsclient, procnum, + inproc, in, outproc, out, tottimeout); + return ((int) clnt_stat); } @@ -105,83 +105,83 @@ callaurpc(vol, prognum, versnum, procnum, inproc, in, outproc, out) #endif /* USE_OLD_RQUOTA */ int getnfsquota(const struct vol *vol, const int uid, const u_int32_t bsize, - struct dqblk *dqp) + struct dqblk *dqp) { - struct getquota_args gq_args; - struct getquota_rslt gq_rslt; - struct timeval tv; - char *hostpath; - - /* figure out the host and path */ - if ((hostpath = strchr(vol->v_gvs, ':')) == NULL) { - syslog(LOG_ERR, "can't find hostname for %s", vol->v_gvs); - return AFPERR_PARAM; - } - - if (*(hostpath + 1) != '/') - return AFPERR_PARAM; + struct getquota_args gq_args; + struct getquota_rslt gq_rslt; + struct timeval tv; + char *hostpath; - /* separate host from hostpath */ - *hostpath = '\0'; - - gq_args.gqa_pathp = hostpath + 1; - gq_args.gqa_uid = uid; - - if(callaurpc(vol, RQUOTAPROG, RQUOTAVERS, RQUOTAPROC_GETQUOTA, - (xdrproc_t) xdr_getquota_args, (char *) &gq_args, - (xdrproc_t) xdr_getquota_rslt, (char *) &gq_rslt) != 0) { - syslog(LOG_INFO, "nfsquota: can't retrieve nfs quota information. \ -make sure that rpc.rquotad is running on %s.", vol->v_gvs); - *hostpath = ':'; - return AFPERR_PARAM; - } - - switch (gq_rslt.GQR_STATUS) { - case Q_NOQUOTA: - break; + /* figure out the host and path */ + if ((hostpath = strchr(vol->v_gvs, ':')) == NULL) { + syslog(LOG_ERR, "can't find hostname for %s", vol->v_gvs); + return AFPERR_PARAM; + } + + if (*(hostpath + 1) != '/') + return AFPERR_PARAM; + + /* separate host from hostpath */ + *hostpath = '\0'; - case Q_EPERM: - syslog(LOG_ERR, "nfsquota: quota permission error, host: %s\n", - vol->v_gvs); - break; + gq_args.gqa_pathp = hostpath + 1; + gq_args.gqa_uid = uid; - case Q_OK: /* we only copy the bits that we need. */ - gettimeofday(&tv, NULL); + if(callaurpc(vol, RQUOTAPROG, RQUOTAVERS, RQUOTAPROC_GETQUOTA, + (xdrproc_t) xdr_getquota_args, (char *) &gq_args, + (xdrproc_t) xdr_getquota_rslt, (char *) &gq_rslt) != 0) { + syslog(LOG_INFO, "nfsquota: can't retrieve nfs quota information. \ + make sure that rpc.rquotad is running on %s.", vol->v_gvs); + *hostpath = ':'; + return AFPERR_PARAM; + } + + switch (gq_rslt.GQR_STATUS) { + case Q_NOQUOTA: + break; + + case Q_EPERM: + syslog(LOG_ERR, "nfsquota: quota permission error, host: %s\n", + vol->v_gvs); + break; + + case Q_OK: /* we only copy the bits that we need. */ + gettimeofday(&tv, NULL); #ifdef __svr4__ - /* why doesn't using bsize work? */ + /* why doesn't using bsize work? */ #define NFS_BSIZE (gq_rslt.GQR_RQUOTA.rq_bsize / DEV_BSIZE) #else /* __svr4__ */ - /* NOTE: linux' rquotad program doesn't currently report the - * correct rq_bsize. */ + /* NOTE: linux' rquotad program doesn't currently report the + * correct rq_bsize. */ #define NFS_BSIZE (gq_rslt.GQR_RQUOTA.rq_bsize / bsize) #endif /* __svr4__ */ - dqp->dqb_bhardlimit = - gq_rslt.GQR_RQUOTA.rq_bhardlimit*NFS_BSIZE; - dqp->dqb_bsoftlimit = - gq_rslt.GQR_RQUOTA.rq_bsoftlimit*NFS_BSIZE; - dqp->dqb_curblocks = - gq_rslt.GQR_RQUOTA.rq_curblocks*NFS_BSIZE; + dqp->dqb_bhardlimit = + gq_rslt.GQR_RQUOTA.rq_bhardlimit*NFS_BSIZE; + dqp->dqb_bsoftlimit = + gq_rslt.GQR_RQUOTA.rq_bsoftlimit*NFS_BSIZE; + dqp->dqb_curblocks = + gq_rslt.GQR_RQUOTA.rq_curblocks*NFS_BSIZE; #ifdef ultrix - dqp->dqb_bwarn = gq_rslt.GQR_RQUOTA.rq_btimeleft; + dqp->dqb_bwarn = gq_rslt.GQR_RQUOTA.rq_btimeleft; #else /* ultrix */ - dqp->dqb_btimelimit = - tv.tv_sec + gq_rslt.GQR_RQUOTA.rq_btimeleft; + dqp->dqb_btimelimit = + tv.tv_sec + gq_rslt.GQR_RQUOTA.rq_btimeleft; #endif /* ultrix */ - *hostpath = ':'; - return AFP_OK; - break; + *hostpath = ':'; + return AFP_OK; + break; - default: - syslog(LOG_INFO, "bad rpc result, host: %s\n", vol->v_gvs); - break; - } + default: + syslog(LOG_INFO, "bad rpc result, host: %s\n", vol->v_gvs); + break; + } - *hostpath = ':'; - return AFPERR_PARAM; + *hostpath = ':'; + return AFPERR_PARAM; } #endif /* ! NO_QUOTA_SUPPORT */ diff --git a/etc/afpd/nls/makecode.c b/etc/afpd/nls/makecode.c index 2121ee35..bc8dcb81 100644 --- a/etc/afpd/nls/makecode.c +++ b/etc/afpd/nls/makecode.c @@ -1,5 +1,5 @@ /* - * $Id: makecode.c,v 1.4 2001-06-11 17:35:55 rufustfirefly Exp $ + * $Id: makecode.c,v 1.4.2.1 2001-12-03 05:01:05 jmarcus Exp $ * * quick-and-dirty way of creating code pages */ @@ -17,152 +17,152 @@ /* map of cp10000 (mac roman) to iso-latin-1 */ static const unsigned char mac_to_isolatin1_map[] = { -0xC4, 0xC5, 0xC7, 0xC9, 0xD1, 0xD6, 0xDC, 0xE1, -0xE0, 0xE2, 0xE4, 0xE3, 0xE5, 0xE7, 0xE9, 0xE8, -0xEA, 0xEB, 0xED, 0xEC, 0xEE, 0xEF, 0xF1, 0xF3, -0xF2, 0xF4, 0xF6, 0xF5, 0xFA, 0xF9, 0xFB, 0xFC, -0x00, 0xB0, 0xA2, 0xA3, 0xA7, 0xB7, 0xB6, 0xDF, -0xAE, 0xA9, 0x00, 0xB4, 0xA8, 0x00, 0xC6, 0xD8, -0x00, 0xB1, 0x00, 0x00, 0xA5, 0xB5, 0xF0, 0x00, -0x00, 0x00, 0x00, 0xAA, 0xBA, 0x00, 0xE6, 0xF8, -0xBF, 0xA1, 0xAC, 0x00, 0x00, 0x00, 0x00, 0xAB, -0xBB, 0x00, 0xA0, 0xC0, 0xC3, 0xD5, 0x00, 0x00, -0xAD, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF7, 0x00, -0xFF, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xB8, 0x00, 0x00, 0xC2, 0xCA, 0xC1, -0xCB, 0xC8, 0xCD, 0xCE, 0xCF, 0xCC, 0xD3, 0xD4, -0x00, 0xD2, 0xDA, 0xDB, 0xD9 -/*, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00 */ + 0xC4, 0xC5, 0xC7, 0xC9, 0xD1, 0xD6, 0xDC, 0xE1, + 0xE0, 0xE2, 0xE4, 0xE3, 0xE5, 0xE7, 0xE9, 0xE8, + 0xEA, 0xEB, 0xED, 0xEC, 0xEE, 0xEF, 0xF1, 0xF3, + 0xF2, 0xF4, 0xF6, 0xF5, 0xFA, 0xF9, 0xFB, 0xFC, + 0x00, 0xB0, 0xA2, 0xA3, 0xA7, 0xB7, 0xB6, 0xDF, + 0xAE, 0xA9, 0x00, 0xB4, 0xA8, 0x00, 0xC6, 0xD8, + 0x00, 0xB1, 0x00, 0x00, 0xA5, 0xB5, 0xF0, 0x00, + 0x00, 0x00, 0x00, 0xAA, 0xBA, 0x00, 0xE6, 0xF8, + 0xBF, 0xA1, 0xAC, 0x00, 0x00, 0x00, 0x00, 0xAB, + 0xBB, 0x00, 0xA0, 0xC0, 0xC3, 0xD5, 0x00, 0x00, + 0xAD, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF7, 0x00, + 0xFF, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xB8, 0x00, 0x00, 0xC2, 0xCA, 0xC1, + 0xCB, 0xC8, 0xCD, 0xCE, 0xCF, 0xCC, 0xD3, 0xD4, + 0x00, 0xD2, 0xDA, 0xDB, 0xD9 + /*, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00 */ }; /* map of cp10000 (mac roman) to iso-latin-1 adapted */ static const unsigned char mac_to_isolatin1_adapted_map[] = { -0xC4, 0xC5, 0xC7, 0xC9, 0xD1, 0xD6, 0xDC, 0xE1, -0xE0, 0xE2, 0xE4, 0xE3, 0xE5, 0xE7, 0xE9, 0xE8, -0xEA, 0xEB, 0xED, 0xEC, 0xEE, 0xEF, 0xF1, 0xF3, -0xF2, 0xF4, 0xF6, 0xF5, 0xFA, 0xF9, 0xFB, 0xFC, -0x00, 0xB0, 0xA2, 0xA3, 0xA7, 0xB7, 0xB6, 0xDF, -0xAE, 0xA9, 0xFE, 0xB4, 0xA8, 0x00, 0xC6, 0xD8, -0x00, 0xB1, 0x00, 0x00, 0xA5, 0xB5, 0xF0, 0x00, -0x00, 0x00, 0x00, 0xAA, 0xBA, 0x00, 0xE6, 0xF8, -0xBF, 0xA1, 0xAC, 0x00, 0xFD, 0x00, 0x00, 0xAB, -0xBB, 0x00, 0xA0, 0xC0, 0xC3, 0xD5, 0x00, 0x00, -0xAD, 0xAF, 0xB2, 0xB3, 0xDD, 0xDE, 0xF7, 0xB0, -0xFF, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xB8, 0x00, 0x00, 0xC2, 0xCA, 0xC1, -0xCB, 0xC8, 0xCD, 0xCE, 0xCF, 0xCC, 0xD3, 0xD4, -0x00, 0xD2, 0xDA, 0xDB, 0xD9 -/*, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00 */ + 0xC4, 0xC5, 0xC7, 0xC9, 0xD1, 0xD6, 0xDC, 0xE1, + 0xE0, 0xE2, 0xE4, 0xE3, 0xE5, 0xE7, 0xE9, 0xE8, + 0xEA, 0xEB, 0xED, 0xEC, 0xEE, 0xEF, 0xF1, 0xF3, + 0xF2, 0xF4, 0xF6, 0xF5, 0xFA, 0xF9, 0xFB, 0xFC, + 0x00, 0xB0, 0xA2, 0xA3, 0xA7, 0xB7, 0xB6, 0xDF, + 0xAE, 0xA9, 0xFE, 0xB4, 0xA8, 0x00, 0xC6, 0xD8, + 0x00, 0xB1, 0x00, 0x00, 0xA5, 0xB5, 0xF0, 0x00, + 0x00, 0x00, 0x00, 0xAA, 0xBA, 0x00, 0xE6, 0xF8, + 0xBF, 0xA1, 0xAC, 0x00, 0xFD, 0x00, 0x00, 0xAB, + 0xBB, 0x00, 0xA0, 0xC0, 0xC3, 0xD5, 0x00, 0x00, + 0xAD, 0xAF, 0xB2, 0xB3, 0xDD, 0xDE, 0xF7, 0xB0, + 0xFF, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xB8, 0x00, 0x00, 0xC2, 0xCA, 0xC1, + 0xCB, 0xC8, 0xCD, 0xCE, 0xCF, 0xCC, 0xD3, 0xD4, + 0x00, 0xD2, 0xDA, 0xDB, 0xD9 + /*, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00 */ }; /* Map of CP10000 (Mac Roman) to MSDOS CP 437 */ static const unsigned char mac_to_cp437_map[] = { -0x8e, 0x8f, 0x80, 0x90, 0xa5, 0x99, 0x9a, 0xa0, -0x85, 0x83, 0x84, 0xe0, 0x86, 0x87, 0x82, 0x8a, -0x88, 0x89, 0xa1, 0x8d, 0x8c, 0x8b, 0xa4, 0xa2, -0x95, 0x93, 0x94, 0xe5, 0xa3, 0x97, 0x96, 0x81, -0xc5, 0xf8, 0x9b, 0x9c, 0xb6, 0xf9, 0xb8, 0xe1, -0xc9, 0xe9, 0xcb, 0xd9, 0xc0, 0xd8, 0x92, 0xe8, -0xec, 0xf1, 0xf3, 0xf2, 0x9d, 0xe6, 0xeb, 0xe4, -0xef, 0xe3, 0xf4, 0xa6, 0xa7, 0xea, 0x91, 0xed, -0xa8, 0xad, 0xaa, 0xfb, 0x9f, 0xf7, 0xdd, 0xae, -0xaf, 0xb0, 0xff, 0xd6, 0xd2, 0xb1, 0xb2, 0xb7, -0xb4, 0xc4, 0xb5, 0xb9, 0xba, 0xbb, 0xf6, 0xbc, -0x98, 0xbd, 0xf5, 0xfe, 0xbe, 0xbf, 0xc1, 0xc2, -0xce, 0xfa, 0xc3, 0xc6, 0xc7, 0xc8, 0xee, 0xca, -0xcc, 0xcd, 0xb3, 0xd7, 0xcf, 0xd0, 0xd1, 0xd3, -0xdb, 0xda, 0xa9, 0xab, 0xac, 0xd4, 0xd5, 0xdc, -0xde, 0xdf, 0xfc, 0xfd, 0xe7, 0xe2, 0xf0, 0x9e + 0x8e, 0x8f, 0x80, 0x90, 0xa5, 0x99, 0x9a, 0xa0, + 0x85, 0x83, 0x84, 0xe0, 0x86, 0x87, 0x82, 0x8a, + 0x88, 0x89, 0xa1, 0x8d, 0x8c, 0x8b, 0xa4, 0xa2, + 0x95, 0x93, 0x94, 0xe5, 0xa3, 0x97, 0x96, 0x81, + 0xc5, 0xf8, 0x9b, 0x9c, 0xb6, 0xf9, 0xb8, 0xe1, + 0xc9, 0xe9, 0xcb, 0xd9, 0xc0, 0xd8, 0x92, 0xe8, + 0xec, 0xf1, 0xf3, 0xf2, 0x9d, 0xe6, 0xeb, 0xe4, + 0xef, 0xe3, 0xf4, 0xa6, 0xa7, 0xea, 0x91, 0xed, + 0xa8, 0xad, 0xaa, 0xfb, 0x9f, 0xf7, 0xdd, 0xae, + 0xaf, 0xb0, 0xff, 0xd6, 0xd2, 0xb1, 0xb2, 0xb7, + 0xb4, 0xc4, 0xb5, 0xb9, 0xba, 0xbb, 0xf6, 0xbc, + 0x98, 0xbd, 0xf5, 0xfe, 0xbe, 0xbf, 0xc1, 0xc2, + 0xce, 0xfa, 0xc3, 0xc6, 0xc7, 0xc8, 0xee, 0xca, + 0xcc, 0xcd, 0xb3, 0xd7, 0xcf, 0xd0, 0xd1, 0xd3, + 0xdb, 0xda, 0xa9, 0xab, 0xac, 0xd4, 0xd5, 0xdc, + 0xde, 0xdf, 0xfc, 0xfd, 0xe7, 0xe2, 0xf0, 0x9e }; /* Map of CP10000 (Mac Roman) to MSDOS CP 850 */ static const unsigned char mac_to_cp850_map[] = { -0x8e, 0x8f, 0x80, 0x90, 0xa5, 0x99, 0x9a, 0xa0, -0x85, 0x83, 0x84, 0xc6, 0x86, 0x87, 0x82, 0x8a, -0x88, 0x89, 0xa1, 0x8d, 0x8c, 0x8b, 0xa4, 0xa2, -0x95, 0x93, 0x94, 0xe4, 0xa3, 0x97, 0x96, 0x81, -0xc5, 0xf8, 0xbd, 0x9c, 0xf5, 0xb0, 0xf4, 0xe1, -0xa9, 0xb8, 0xb1, 0xef, 0xf9, 0xca, 0x92, 0x9d, -0xb2, 0xf1, 0xb3, 0xb4, 0xbe, 0xe6, 0xd0, 0xba, -0xbb, 0xcb, 0xdd, 0xa6, 0xa7, 0xbc, 0x91, 0x9b, -0xa8, 0xad, 0xaa, 0xd9, 0x9f, 0xf2, 0xfe, 0xae, -0xaf, 0xdc, 0xff, 0xb7, 0xc7, 0xe5, 0xc0, 0xc1, -0xc2, 0xc4, 0xc3, 0x9e, 0xab, 0xac, 0xf6, 0xbf, -0x98, 0xed, 0xc8, 0xcf, 0xc9, 0xcc, 0xcd, 0xce, -0xd1, 0xfa, 0xd5, 0xda, 0xdb, 0xb6, 0xd2, 0xb5, -0xd3, 0xd4, 0xd6, 0xd7, 0xd8, 0xde, 0xe0, 0xe2, -0xf0, 0xe3, 0xe9, 0xea, 0xeb, 0xfb, 0xdf, 0xe7, -0xee, 0xe8, 0xec, 0xf3, 0xf7, 0xfc, 0xfd, 0xb9 + 0x8e, 0x8f, 0x80, 0x90, 0xa5, 0x99, 0x9a, 0xa0, + 0x85, 0x83, 0x84, 0xc6, 0x86, 0x87, 0x82, 0x8a, + 0x88, 0x89, 0xa1, 0x8d, 0x8c, 0x8b, 0xa4, 0xa2, + 0x95, 0x93, 0x94, 0xe4, 0xa3, 0x97, 0x96, 0x81, + 0xc5, 0xf8, 0xbd, 0x9c, 0xf5, 0xb0, 0xf4, 0xe1, + 0xa9, 0xb8, 0xb1, 0xef, 0xf9, 0xca, 0x92, 0x9d, + 0xb2, 0xf1, 0xb3, 0xb4, 0xbe, 0xe6, 0xd0, 0xba, + 0xbb, 0xcb, 0xdd, 0xa6, 0xa7, 0xbc, 0x91, 0x9b, + 0xa8, 0xad, 0xaa, 0xd9, 0x9f, 0xf2, 0xfe, 0xae, + 0xaf, 0xdc, 0xff, 0xb7, 0xc7, 0xe5, 0xc0, 0xc1, + 0xc2, 0xc4, 0xc3, 0x9e, 0xab, 0xac, 0xf6, 0xbf, + 0x98, 0xed, 0xc8, 0xcf, 0xc9, 0xcc, 0xcd, 0xce, + 0xd1, 0xfa, 0xd5, 0xda, 0xdb, 0xb6, 0xd2, 0xb5, + 0xd3, 0xd4, 0xd6, 0xd7, 0xd8, 0xde, 0xe0, 0xe2, + 0xf0, 0xe3, 0xe9, 0xea, 0xeb, 0xfb, 0xdf, 0xe7, + 0xee, 0xe8, 0xec, 0xf3, 0xf7, 0xfc, 0xfd, 0xb9 }; struct mac_code { - char *m_name; - const unsigned char *m_map; - u_int16_t m_len; - const char *m_id; + char *m_name; + const unsigned char *m_map; + u_int16_t m_len; + const char *m_id; }; static struct mac_code names[] = { - {"maccode.437", mac_to_cp437_map, sizeof(mac_to_cp437_map), "cp437"}, - {"maccode.850", mac_to_cp850_map, sizeof(mac_to_cp850_map), "cp850"}, - {"maccode.iso8859-1", mac_to_isolatin1_map, sizeof(mac_to_isolatin1_map), "iso8859-1"}, - {"maccode.iso8859-1.adapted", mac_to_isolatin1_adapted_map, sizeof(mac_to_isolatin1_adapted_map), "iso8859-1-adapted"}, - {NULL, NULL, 0, NULL} -}; + {"maccode.437", mac_to_cp437_map, sizeof(mac_to_cp437_map), "cp437"}, + {"maccode.850", mac_to_cp850_map, sizeof(mac_to_cp850_map), "cp850"}, + {"maccode.iso8859-1", mac_to_isolatin1_map, sizeof(mac_to_isolatin1_map), "iso8859-1"}, + {"maccode.iso8859-1.adapted", mac_to_isolatin1_adapted_map, sizeof(mac_to_isolatin1_adapted_map), "iso8859-1-adapted"}, + {NULL, NULL, 0, NULL} + }; int main(int argc, char **argv) { - unsigned char buf[CODEPAGE_FILE_HEADER_SIZE]; - u_int16_t id; - int i, j; - FILE *fp; - - for (i = 0; names[i].m_name; i++) { - if ((fp = fopen(names[i].m_name, "w")) == NULL) { - fprintf(stderr, "can't open %s\n", names[i].m_name); - continue; - } - - memset(buf, 0, CODEPAGE_FILE_HEADER_SIZE); - - id = htons(CODEPAGE_FILE_ID); /* file id */ - memcpy(buf, &id, sizeof(id)); - *(buf + 2) = CODEPAGE_FILE_VERSION; /* version */ - if ((j = strlen(names[i].m_id)) & 1) /* pad to even boundary */ - j++; - *(buf + 3) = j; /* length of name */ - - *(buf + 4) = 1; /* default quantum. this should be modified to - * deal with multibyte characters */ - - /* rules */ - *(buf + 5) = CODEPAGE_RULE_MTOU | CODEPAGE_RULE_UTOM; - - /* offset to data */ - id = htons(CODEPAGE_FILE_HEADER_SIZE + j); - memcpy(buf + 6, &id, sizeof(id)); - - /* size of data */ - id = htons(names[i].m_len); - memcpy(buf + 8, &id, sizeof(id)); - - /* write it out */ - fwrite(buf, CODEPAGE_FILE_HEADER_SIZE, 1, fp); - - /* we either keep or drop the null byte to keep the name on an - even boundary */ - fwrite(names[i].m_id, j, 1, fp); - - /* we typically only map characters > 0x7F */ - for (j = 0; j < names[i].m_len; j++) { - buf[0] = CODEPAGE_RULE_MTOU | CODEPAGE_RULE_UTOM; - buf[1] = j + 0x80; - buf[2] = names[i].m_map[j]; - fwrite(buf, 3, 1, fp); + unsigned char buf[CODEPAGE_FILE_HEADER_SIZE]; + u_int16_t id; + int i, j; + FILE *fp; + + for (i = 0; names[i].m_name; i++) { + if ((fp = fopen(names[i].m_name, "w")) == NULL) { + fprintf(stderr, "can't open %s\n", names[i].m_name); + continue; + } + + memset(buf, 0, CODEPAGE_FILE_HEADER_SIZE); + + id = htons(CODEPAGE_FILE_ID); /* file id */ + memcpy(buf, &id, sizeof(id)); + *(buf + 2) = CODEPAGE_FILE_VERSION; /* version */ + if ((j = strlen(names[i].m_id)) & 1) /* pad to even boundary */ + j++; + *(buf + 3) = j; /* length of name */ + + *(buf + 4) = 1; /* default quantum. this should be modified to + * deal with multibyte characters */ + + /* rules */ + *(buf + 5) = CODEPAGE_RULE_MTOU | CODEPAGE_RULE_UTOM; + + /* offset to data */ + id = htons(CODEPAGE_FILE_HEADER_SIZE + j); + memcpy(buf + 6, &id, sizeof(id)); + + /* size of data */ + id = htons(names[i].m_len); + memcpy(buf + 8, &id, sizeof(id)); + + /* write it out */ + fwrite(buf, CODEPAGE_FILE_HEADER_SIZE, 1, fp); + + /* we either keep or drop the null byte to keep the name on an + even boundary */ + fwrite(names[i].m_id, j, 1, fp); + + /* we typically only map characters > 0x7F */ + for (j = 0; j < names[i].m_len; j++) { + buf[0] = CODEPAGE_RULE_MTOU | CODEPAGE_RULE_UTOM; + buf[1] = j + 0x80; + buf[2] = names[i].m_map[j]; + fwrite(buf, 3, 1, fp); + } + fclose(fp); } - fclose(fp); - } - return 0; + return 0; } diff --git a/etc/afpd/nls/parsecode.c b/etc/afpd/nls/parsecode.c index 025c0e03..dcb1bf5a 100644 --- a/etc/afpd/nls/parsecode.c +++ b/etc/afpd/nls/parsecode.c @@ -8,70 +8,70 @@ int main(int argc, char **argv) { - unsigned char name[255 + 1], buf[CODEPAGE_FILE_HEADER_SIZE]; - unsigned char quantum, rules; - u_int16_t id; - FILE *fp; + unsigned char name[255 + 1], buf[CODEPAGE_FILE_HEADER_SIZE]; + unsigned char quantum, rules; + u_int16_t id; + FILE *fp; - if (argc != 2) { - fprintf(stderr, "%s \n", *argv); - return -1; - } - - if ((fp = fopen(argv[1], "r")) == NULL) { - fprintf(stderr, "%s: can't open file.\n", *argv); - return -1; - } + if (argc != 2) { + fprintf(stderr, "%s \n", *argv); + return -1; + } + + if ((fp = fopen(argv[1], "r")) == NULL) { + fprintf(stderr, "%s: can't open file.\n", *argv); + return -1; + } - if (fread(buf, CODEPAGE_FILE_HEADER_SIZE, 1, fp) != 1) { - fprintf(stderr, "%s: can't get header.\n", *argv); - goto fail_end; - } + if (fread(buf, CODEPAGE_FILE_HEADER_SIZE, 1, fp) != 1) { + fprintf(stderr, "%s: can't get header.\n", *argv); + goto fail_end; + } - /* id */ - memcpy(&id, buf, sizeof(id)); - id = ntohs(id); - if (id != CODEPAGE_FILE_ID) { - fprintf(stderr, "%s: wrong file type.\n", *argv); - goto fail_end; - } + /* id */ + memcpy(&id, buf, sizeof(id)); + id = ntohs(id); + if (id != CODEPAGE_FILE_ID) { + fprintf(stderr, "%s: wrong file type.\n", *argv); + goto fail_end; + } - /* version */ - if (*(buf + 2) != CODEPAGE_FILE_VERSION) { - fprintf(stderr, "%s: wrong file version.\n", *argv); - goto fail_end; - } - - /* size of name */ - id = *(buf + 3); + /* version */ + if (*(buf + 2) != CODEPAGE_FILE_VERSION) { + fprintf(stderr, "%s: wrong file version.\n", *argv); + goto fail_end; + } - /* quantum and rules */ - quantum = *(buf + 4); - rules = *(buf + 5); + /* size of name */ + id = *(buf + 3); - fread(name, id, 1, fp); - if (name[id - 1] != '\0') /* name isn't null-padded */ - name[id] = '\0'; - printf("codepage: %s [", name); + /* quantum and rules */ + quantum = *(buf + 4); + rules = *(buf + 5); - /* move to the data */ - memcpy(&id, buf + 6, sizeof(id)); - id = ntohs(id); - fseek(fp, id, SEEK_SET); + fread(name, id, 1, fp); + if (name[id - 1] != '\0') /* name isn't null-padded */ + name[id] = '\0'; + printf("codepage: %s [", name); - /* size of data */ - memcpy(&id, buf + 8, sizeof(id)); - id = ntohs(id); - printf("size=%d]\n", id); - printf("---------\n"); + /* move to the data */ + memcpy(&id, buf + 6, sizeof(id)); + id = ntohs(id); + fseek(fp, id, SEEK_SET); - while (fread(buf, 1 + 2*quantum, 1, fp) == 1) { - printf("0x%02x: 0x%02X 0x%02X\n", buf[0], buf[1], buf[1 + quantum]); - } - fclose(fp); - return 0; + /* size of data */ + memcpy(&id, buf + 8, sizeof(id)); + id = ntohs(id); + printf("size=%d]\n", id); + printf("---------\n"); + + while (fread(buf, 1 + 2*quantum, 1, fp) == 1) { + printf("0x%02x: 0x%02X 0x%02X\n", buf[0], buf[1], buf[1 + quantum]); + } + fclose(fp); + return 0; fail_end: - fclose(fp); - return -1; + fclose(fp); + return -1; } diff --git a/etc/afpd/ofork.c b/etc/afpd/ofork.c index 82c6c9f4..14adc995 100644 --- a/etc/afpd/ofork.c +++ b/etc/afpd/ofork.c @@ -1,5 +1,5 @@ /* - * $Id: ofork.c,v 1.5 2001-08-15 01:37:34 srittau Exp $ + * $Id: ofork.c,v 1.5.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1996 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -37,46 +37,46 @@ static u_short lastrefnum = 0; /* OR some of each character for the hash*/ static __inline__ unsigned long hashfn(const char *name) { - unsigned long i = 0; + unsigned long i = 0; - while (*name) { - i = ((i << 4) | (8*sizeof(i) - 4)) ^ *name++; - } - return i & (OFORK_HASHSIZE - 1); + while (*name) { + i = ((i << 4) | (8*sizeof(i) - 4)) ^ *name++; + } + return i & (OFORK_HASHSIZE - 1); } static __inline__ void of_hash(struct ofork *of) { - struct ofork **table; + struct ofork **table; - table = &ofork_table[hashfn(of->of_name)]; - if ((of->next = *table) != NULL) - (*table)->prevp = &of->next; - *table = of; - of->prevp = table; + table = &ofork_table[hashfn(of->of_name)]; + if ((of->next = *table) != NULL) + (*table)->prevp = &of->next; + *table = of; + of->prevp = table; } static __inline__ void of_unhash(struct ofork *of) { - if (of->prevp) { - if (of->next) - of->next->prevp = of->prevp; - *(of->prevp) = of->next; - } + if (of->prevp) { + if (of->next) + of->next->prevp = of->prevp; + *(of->prevp) = of->next; + } } void of_pforkdesc( f ) - FILE *f; +FILE *f; { u_short ofrefnum; if (!oforks) - return; + return; for ( ofrefnum = 0; ofrefnum < nforks; ofrefnum++ ) { - if ( oforks[ ofrefnum ] != NULL ) { - fprintf( f, "%hu <%s>\n", ofrefnum, oforks[ ofrefnum ]->of_name); - } + if ( oforks[ ofrefnum ] != NULL ) { + fprintf( f, "%hu <%s>\n", ofrefnum, oforks[ ofrefnum ]->of_name); + } } } @@ -85,60 +85,60 @@ int of_flush(const struct vol *vol) u_int16_t refnum; if (!oforks) - return 0; + return 0; for ( refnum = 0; refnum < nforks; refnum++ ) { - if (oforks[ refnum ] != NULL && (oforks[refnum]->of_vol == vol) && - flushfork( oforks[ refnum ] ) < 0 ) { - syslog( LOG_ERR, "of_flush: %s", strerror(errno) ); - } + if (oforks[ refnum ] != NULL && (oforks[refnum]->of_vol == vol) && + flushfork( oforks[ refnum ] ) < 0 ) { + syslog( LOG_ERR, "of_flush: %s", strerror(errno) ); + } } return( 0 ); } int of_rename(vol, olddir, oldpath, newdir, newpath) - const struct vol *vol; - struct dir *olddir, *newdir; - const char *oldpath, *newpath; +const struct vol *vol; +struct dir *olddir, *newdir; +const char *oldpath, *newpath; { - struct ofork *of, *next, *d_ofork; - - next = ofork_table[hashfn(oldpath)]; - while ((of = next)) { - next = next->next; /* so we can unhash and still be all right. */ - - if ((vol == of->of_vol) && (olddir == of->of_dir) && - (strcmp(of->of_name, oldpath) == 0)) { - of_unhash(of); - strncpy( of->of_name, newpath, of->of_namelen); - of->of_d_prev->of_d_next = of->of_d_prev; - of->of_d_next->of_d_prev = of->of_d_next; - of->of_dir = newdir; - if (!(d_ofork = newdir->d_ofork)) { - newdir->d_ofork = of; - of->of_d_next = of->of_d_prev = of; - } else { - of->of_d_next = d_ofork; - of->of_d_prev = d_ofork->of_d_prev; - of->of_d_prev->of_d_next = of; - d_ofork->of_d_prev = of; - } - of_hash(of); + struct ofork *of, *next, *d_ofork; + + next = ofork_table[hashfn(oldpath)]; + while ((of = next)) { + next = next->next; /* so we can unhash and still be all right. */ + + if ((vol == of->of_vol) && (olddir == of->of_dir) && + (strcmp(of->of_name, oldpath) == 0)) { + of_unhash(of); + strncpy( of->of_name, newpath, of->of_namelen); + of->of_d_prev->of_d_next = of->of_d_prev; + of->of_d_next->of_d_prev = of->of_d_next; + of->of_dir = newdir; + if (!(d_ofork = newdir->d_ofork)) { + newdir->d_ofork = of; + of->of_d_next = of->of_d_prev = of; + } else { + of->of_d_next = d_ofork; + of->of_d_prev = d_ofork->of_d_prev; + of->of_d_prev->of_d_next = of; + d_ofork->of_d_prev = of; + } + of_hash(of); + } } - } - return AFP_OK; + return AFP_OK; } - struct ofork * -of_alloc(vol, dir, path, ofrefnum, eid, ad) - struct vol *vol; - struct dir *dir; - char *path; - u_int16_t *ofrefnum; - const int eid; - struct adouble *ad; +struct ofork * + of_alloc(vol, dir, path, ofrefnum, eid, ad) + struct vol *vol; +struct dir *dir; +char *path; +u_int16_t *ofrefnum; +const int eid; +struct adouble *ad; { struct ofork *of, *d_ofork; u_int16_t refnum, of_refnum; @@ -146,27 +146,27 @@ of_alloc(vol, dir, path, ofrefnum, eid, ad) int i; if (!oforks) { - nforks = (getdtablesize() - 10) / 2; - oforks = (struct ofork **) calloc(nforks, sizeof(struct ofork *)); - if (!oforks) - return NULL; + nforks = (getdtablesize() - 10) / 2; + oforks = (struct ofork **) calloc(nforks, sizeof(struct ofork *)); + if (!oforks) + return NULL; } for ( refnum = lastrefnum++, i = 0; i < nforks; i++, refnum++ ) { - if ( oforks[ refnum % nforks ] == NULL ) { - break; - } + if ( oforks[ refnum % nforks ] == NULL ) { + break; + } } if ( i == nforks ) { syslog(LOG_ERR, "of_alloc: maximum number of forks exceeded."); - return( NULL ); + return( NULL ); } of_refnum = refnum % nforks; if (( oforks[ of_refnum ] = - (struct ofork *)malloc( sizeof( struct ofork ))) == NULL ) { - syslog( LOG_ERR, "of_alloc: malloc: %s", strerror(errno) ); - return NULL; + (struct ofork *)malloc( sizeof( struct ofork ))) == NULL ) { + syslog( LOG_ERR, "of_alloc: malloc: %s", strerror(errno) ); + return NULL; } of = oforks[of_refnum]; @@ -193,26 +193,26 @@ of_alloc(vol, dir, path, ofrefnum, eid, ad) of->of_dir = dir; if (!(d_ofork = dir->d_ofork)) { - dir->d_ofork = of; - of->of_d_next = of->of_d_prev = of; + dir->d_ofork = of; + of->of_d_next = of->of_d_prev = of; } else { - of->of_d_next = d_ofork; - of->of_d_prev = d_ofork->of_d_prev; - d_ofork->of_d_prev->of_d_next = of; - d_ofork->of_d_prev = of; + of->of_d_next = d_ofork; + of->of_d_prev = d_ofork->of_d_prev; + d_ofork->of_d_prev->of_d_next = of; + d_ofork->of_d_prev = of; } - /* here's the deal: we allocate enough for the standard mac file length. + /* here's the deal: we allocate enough for the standard mac file length. * in the future, we'll reallocate in fairly large jumps in case * of long unicode names */ if (( of->of_name =(char *)malloc(MACFILELEN + 1)) == - NULL ) { - syslog( LOG_ERR, "of_alloc: malloc: %s", strerror(errno) ); - if (!ad) - free(of->of_ad); - free(of); - oforks[ of_refnum ] = NULL; - return NULL; + NULL ) { + syslog( LOG_ERR, "of_alloc: malloc: %s", strerror(errno) ); + if (!ad) + free(of->of_ad); + free(of); + oforks[ of_refnum ] = NULL; + return NULL; } strncpy( of->of_name, path, of->of_namelen = MACFILELEN + 1); *ofrefnum = refnum; @@ -220,30 +220,30 @@ of_alloc(vol, dir, path, ofrefnum, eid, ad) of_hash(of); if (eid == ADEID_DFORK) - of->of_flags = AFPFORK_DATA; + of->of_flags = AFPFORK_DATA; else - of->of_flags = AFPFORK_RSRC; + of->of_flags = AFPFORK_RSRC; return( of ); } struct ofork *of_find(const u_int16_t ofrefnum ) { - if (!oforks) - return NULL; + if (!oforks || !nforks) + return NULL; return( oforks[ ofrefnum % nforks ] ); } struct ofork * -of_findname(const struct vol *vol, const struct dir *dir, const char *name) + of_findname(const struct vol *vol, const struct dir *dir, const char *name) { struct ofork *of; for (of = ofork_table[hashfn(name)]; of; of = of->next) { - if ((vol == of->of_vol) && (dir == of->of_dir) && - (strcmp(of->of_name, name) == 0)) - return of; + if ((vol == of->of_vol) && (dir == of->of_dir) && + (strcmp(of->of_name, name) == 0)) + return of; } return NULL; @@ -251,10 +251,10 @@ of_findname(const struct vol *vol, const struct dir *dir, const char *name) void of_dealloc( of ) - struct ofork *of; +struct ofork *of; { if (!oforks) - return; + return; of_unhash(of); @@ -262,7 +262,7 @@ void of_dealloc( of ) of->of_d_prev->of_d_next = of->of_d_next; of->of_d_next->of_d_prev = of->of_d_prev; if (of->of_dir->d_ofork == of) { - of->of_dir->d_ofork = (of == of->of_d_next) ? NULL : of->of_d_next; + of->of_dir->d_ofork = (of == of->of_d_next) ? NULL : of->of_d_next; } oforks[ of->of_refnum ] = NULL; @@ -272,9 +272,9 @@ void of_dealloc( of ) of->of_ad->ad_refcount--; if ( of->of_ad->ad_refcount <= 0) { - free( of->of_ad); + free( of->of_ad); } else {/* someone's still using it. just free this user's locks */ - ad_unlock(of->of_ad, of->of_refnum); + ad_unlock(of->of_ad, of->of_refnum); } free( of ); diff --git a/etc/afpd/parse_mtab.c b/etc/afpd/parse_mtab.c index 3375c64f..b1bb9bfb 100644 --- a/etc/afpd/parse_mtab.c +++ b/etc/afpd/parse_mtab.c @@ -1,5 +1,5 @@ /* - * $Id: parse_mtab.c,v 1.4 2001-09-06 20:00:59 rufustfirefly Exp $ + * $Id: parse_mtab.c,v 1.4.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * afpd_mtab_parse & support. -- rgr, 9-Apr-01. */ @@ -42,152 +42,152 @@ char *strchr (), *strrchr (); static int ceil_log_2 __P((int n)) - /* Return the number of bits required to represent n. Only works for - positive n. */ +/* Return the number of bits required to represent n. Only works for +positive n. */ { - int n_bits = 0; + int n_bits = 0; - while (n) { - n >>= 1; - n_bits += 1; - } - return(n_bits); + while (n) { + n >>= 1; + n_bits += 1; + } + return(n_bits); } unsigned int afpd_st_cnid __P((struct stat *st)) - /* Given a stat structure, look up the device in afpd_mount_table, and - compute and return a CNID. */ +/* Given a stat structure, look up the device in afpd_mount_table, and + compute and return a CNID. */ { - int id; - struct afpd_mtab_entry *entry; - - if (afpd_mount_table != NULL) { - for (id = 0; id < afpd_mount_table->size; id++) { - entry = afpd_mount_table->table[id]; - if (entry != NULL - && entry->dev_major == major(st->st_dev) - && entry->dev_minor == minor(st->st_dev)) { - return(entry->bit_value | st->st_ino); - } + int id; + struct afpd_mtab_entry *entry; + + if (afpd_mount_table != NULL) { + for (id = 0; id < afpd_mount_table->size; id++) { + entry = afpd_mount_table->table[id]; + if (entry != NULL + && entry->dev_major == major(st->st_dev) + && entry->dev_minor == minor(st->st_dev)) { + return(entry->bit_value | st->st_ino); + } + } } - } - /* Fallback. */ - return(st->st_ino); + /* Fallback. */ + return(st->st_ino); } struct afpd_mount_table * -afpd_mtab_parse __P((char *file_name)) - /* Parse the given mtab file, returning a new afpd_mount_table structure. - Also saves it in the afpd_mount_table static variable for use by the - afpd_st_cnid function. Returns NULL if it encounters an error. - - [It would be great if this could generate a warning for any device that - allows more inodes than we can allocate bits for. -- rgr, 9-Apr-01.] - */ + afpd_mtab_parse __P((char *file_name)) + /* Parse the given mtab file, returning a new afpd_mount_table structure. + Also saves it in the afpd_mount_table static variable for use by the + afpd_st_cnid function. Returns NULL if it encounters an error. + + [It would be great if this could generate a warning for any device that + allows more inodes than we can allocate bits for. -- rgr, 9-Apr-01.] + */ { - struct afpd_mtab_entry *entries[MAX_AFPD_MTAB_ENTRIES]; /* temp */ - int id, max_id = 0, n_errors = 0; - struct stat st; - char line[1000], *p, *index_tok, *dev_tok, *mount_tok; - int line_number = 0; /* one-based */ - FILE *f = fopen(file_name, "r"); - - if (f == NULL) { - fprintf(stderr, "Error: Can't open %s: code %d\n", - file_name, errno); - return(NULL); - } - for (id = 0; id < MAX_AFPD_MTAB_ENTRIES; id++) - entries[id] = NULL; - while (fgets(line, sizeof(line), f) != NULL) { - line_number++; - /* flush comment */ - if ((p = strchr(line, '#')) != NULL) - *p = '\0'; - /* get fields */ - index_tok = strtok(line, MTAB_DELIM_CHARS); - dev_tok = strtok(NULL, MTAB_DELIM_CHARS); - mount_tok = strtok(NULL, MTAB_DELIM_CHARS); - if (mount_tok == NULL) { - /* [warning here if index_tok nonempty? -- rgr, 9-Apr-01.] */ - } - else if (id = strtol(index_tok, &p, 10), - *p != '\0') { - fprintf(stderr, "afpd:%s:%d: Non-integer device index value '%s'.\n", - file_name, line_number, index_tok); - n_errors++; - } - else if (id < 1 || id > MAX_AFPD_MTAB_ENTRIES) { - fprintf(stderr, - "afpd:%s:%d: Expected an integer from 1 to %d, but got '%s'.\n", - file_name, line_number, MAX_AFPD_MTAB_ENTRIES-1, index_tok); - n_errors++; - } - else if (entries[id] != NULL) { - /* not unique. */ - fprintf(stderr, - "afpd:%s:%d: Id %d is already taken for %s.\n", - file_name, line_number, id, entries[id]->device); - n_errors++; + struct afpd_mtab_entry *entries[MAX_AFPD_MTAB_ENTRIES]; /* temp */ + int id, max_id = 0, n_errors = 0; + struct stat st; + char line[1000], *p, *index_tok, *dev_tok, *mount_tok; + int line_number = 0; /* one-based */ + FILE *f = fopen(file_name, "r"); + + if (f == NULL) { + fprintf(stderr, "Error: Can't open %s: code %d\n", + file_name, errno); + return(NULL); } - else if (stat(dev_tok, &st) != 0) { - fprintf(stderr, "afpd:%s:%d: Can't stat '%s': code %d\n", - file_name, line_number, dev_tok, errno); - n_errors++; - } - else if (! S_ISBLK(st.st_mode)) { - fprintf(stderr, "afpd:%s:%d: '%s' is not a block device.\n", - file_name, line_number, dev_tok); - n_errors++; + for (id = 0; id < MAX_AFPD_MTAB_ENTRIES; id++) + entries[id] = NULL; + while (fgets(line, sizeof(line), f) != NULL) { + line_number++; + /* flush comment */ + if ((p = strchr(line, '#')) != NULL) + *p = '\0'; + /* get fields */ + index_tok = strtok(line, MTAB_DELIM_CHARS); + dev_tok = strtok(NULL, MTAB_DELIM_CHARS); + mount_tok = strtok(NULL, MTAB_DELIM_CHARS); + if (mount_tok == NULL) { + /* [warning here if index_tok nonempty? -- rgr, 9-Apr-01.] */ + } + else if (id = strtol(index_tok, &p, 10), + *p != '\0') { + fprintf(stderr, "afpd:%s:%d: Non-integer device index value '%s'.\n", + file_name, line_number, index_tok); + n_errors++; + } + else if (id < 1 || id > MAX_AFPD_MTAB_ENTRIES) { + fprintf(stderr, + "afpd:%s:%d: Expected an integer from 1 to %d, but got '%s'.\n", + file_name, line_number, MAX_AFPD_MTAB_ENTRIES-1, index_tok); + n_errors++; + } + else if (entries[id] != NULL) { + /* not unique. */ + fprintf(stderr, + "afpd:%s:%d: Id %d is already taken for %s.\n", + file_name, line_number, id, entries[id]->device); + n_errors++; + } + else if (stat(dev_tok, &st) != 0) { + fprintf(stderr, "afpd:%s:%d: Can't stat '%s': code %d\n", + file_name, line_number, dev_tok, errno); + n_errors++; + } + else if (! S_ISBLK(st.st_mode)) { + fprintf(stderr, "afpd:%s:%d: '%s' is not a block device.\n", + file_name, line_number, dev_tok); + n_errors++; + } + else { + /* make a new entry */ + struct afpd_mtab_entry *entry + = (struct afpd_mtab_entry *) malloc(sizeof(struct afpd_mtab_entry)); + + entry->id = id; + entry->dev_major = major(st.st_rdev); + entry->dev_minor = minor(st.st_rdev); + COPY_STRING(entry->device, dev_tok); + COPY_STRING(entry->mount_point, mount_tok); + entries[id] = entry; + if (id > max_id) + max_id = id; + } + } /* next line */ + + fclose(f); +if (n_errors) { + fprintf(stderr, "Got %d errors while reading %s; exiting.\n", + n_errors, file_name); + return(NULL); } else { - /* make a new entry */ - struct afpd_mtab_entry *entry - = (struct afpd_mtab_entry *) malloc(sizeof(struct afpd_mtab_entry)); - - entry->id = id; - entry->dev_major = major(st.st_rdev); - entry->dev_minor = minor(st.st_rdev); - COPY_STRING(entry->device, dev_tok); - COPY_STRING(entry->mount_point, mount_tok); - entries[id] = entry; - if (id > max_id) - max_id = id; - } - } /* next line */ - - fclose(f); - if (n_errors) { - fprintf(stderr, "Got %d errors while reading %s; exiting.\n", - n_errors, file_name); - return(NULL); - } - else { - /* make the table. */ - struct afpd_mount_table *mount_table /* return value */ - = (struct afpd_mount_table *) malloc(sizeof(struct afpd_mount_table)); - int n_bits = ceil_log_2(max_id); - int table_size; - struct afpd_mtab_entry **new_entries; - - if (n_bits < AFPD_MTAB_MIN_DEV_BITS) - n_bits = AFPD_MTAB_MIN_DEV_BITS; - table_size = 1 << n_bits; - new_entries = (struct afpd_mtab_entry **) - malloc(table_size*sizeof(struct afpd_mtab_entry *)); - mount_table->size = table_size; - mount_table->bits = n_bits; - mount_table->shift = AFPD_MTAB_DEV_AND_INODE_BITS-n_bits; - for (id = 0; id < table_size; id++) { - if (entries[id] != NULL) - entries[id]->bit_value = entries[id]->id << mount_table->shift; - new_entries[id] = entries[id]; + /* make the table. */ + struct afpd_mount_table *mount_table /* return value */ + = (struct afpd_mount_table *) malloc(sizeof(struct afpd_mount_table)); + int n_bits = ceil_log_2(max_id); + int table_size; + struct afpd_mtab_entry **new_entries; + + if (n_bits < AFPD_MTAB_MIN_DEV_BITS) + n_bits = AFPD_MTAB_MIN_DEV_BITS; + table_size = 1 << n_bits; + new_entries = (struct afpd_mtab_entry **) + malloc(table_size*sizeof(struct afpd_mtab_entry *)); + mount_table->size = table_size; + mount_table->bits = n_bits; + mount_table->shift = AFPD_MTAB_DEV_AND_INODE_BITS-n_bits; +for (id = 0; id < table_size; id++) { + if (entries[id] != NULL) + entries[id]->bit_value = entries[id]->id << mount_table->shift; + new_entries[id] = entries[id]; + } + mount_table->table = new_entries; + + afpd_mount_table = mount_table; + return(mount_table); } - mount_table->table = new_entries; - - afpd_mount_table = mount_table; - return(mount_table); - } } diff --git a/etc/afpd/parse_mtab.h b/etc/afpd/parse_mtab.h index b410251b..4254ddd0 100644 --- a/etc/afpd/parse_mtab.h +++ b/etc/afpd/parse_mtab.h @@ -1,5 +1,5 @@ /* - * $Id: parse_mtab.h,v 1.3 2001-06-19 18:04:39 rufustfirefly Exp $ + * $Id: parse_mtab.h,v 1.3.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * header for afpd_mtab_parse, afpd_st_cnid */ @@ -14,32 +14,32 @@ #define AFPD_MTAB_MIN_DEV_BITS 3 struct afpd_mtab_entry { - /* Description of one partition. */ - int id; /* unique index (a small integer) */ - int dev_major, dev_minor; /* device numbers */ - int bit_value; /* preshifted device index field */ - char *device; /* device name string (for debugging) */ - char *mount_point; /* mounted directory (for debugging) */ + /* Description of one partition. */ + int id; /* unique index (a small integer) */ + int dev_major, dev_minor; /* device numbers */ + int bit_value; /* preshifted device index field */ + char *device; /* device name string (for debugging) */ + char *mount_point; /* mounted directory (for debugging) */ }; struct afpd_mount_table { - /* Description of all partitions. */ - int size; /* length of entries array, a power of 2 */ - int bits; /* number of bits, log2(size) */ - unsigned int shift; /* amount by which to shift into CNID device field */ - struct afpd_mtab_entry **table; /* index -> entry map vector, some - entries may be null */ + /* Description of all partitions. */ + int size; /* length of entries array, a power of 2 */ + int bits; /* number of bits, log2(size) */ + unsigned int shift; /* amount by which to shift into CNID device field */ + struct afpd_mtab_entry **table; /* index -> entry map vector, some + entries may be null */ }; /* global mount table; afpd_st_cnid uses this to lookup the right entry. */ static struct afpd_mount_table *afpd_mount_table = NULL; extern -unsigned int -afpd_st_cnid __P((struct stat *st)); + unsigned int + afpd_st_cnid __P((struct stat *st)); extern -struct afpd_mount_table * -afpd_mtab_parse __P((char *file_name)); + struct afpd_mount_table * + afpd_mtab_parse __P((char *file_name)); #endif /* not _parse_mtab_h */ diff --git a/etc/afpd/passwd.c b/etc/afpd/passwd.c index 951d8add..82d260e1 100644 --- a/etc/afpd/passwd.c +++ b/etc/afpd/passwd.c @@ -1,5 +1,5 @@ /* - * $Id: passwd.c,v 1.4 2001-09-06 20:00:59 rufustfirefly Exp $ + * $Id: passwd.c,v 1.4.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1991 Regents of The University of Michigan. * All Rights Reserved. @@ -57,8 +57,8 @@ char *strchr (), *strrchr (); extern int r_errno; afs_changepw( ibuf, ibuflen, rbuf, rbuflen ) - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { char cell[ MAXCELLCHARS ], name[ 20 ], oldpw[ 10 ], newpw[ 10 ]; char *p; @@ -68,61 +68,61 @@ afs_changepw( ibuf, ibuflen, rbuf, rbuflen ) len = (unsigned char )*ibuf++; ibuf[ len ] = '\0'; if (( p = strchr( ibuf, '@' )) != NULL ) { - *p++ = '\0'; - strcpy( cell, p ); - ucase( cell ); + *p++ = '\0'; + strcpy( cell, p ); + ucase( cell ); } else { - if ( GetLocalCellName() != CCONF_SUCCESS ) { - *rbuflen = 0; - return( AFPERR_BADUAM ); - } - strcpy( cell, LclCellName ); + if ( GetLocalCellName() != CCONF_SUCCESS ) { + *rbuflen = 0; + return( AFPERR_BADUAM ); + } + strcpy( cell, LclCellName ); } if ( strlen( ibuf ) > 20 ) { - *rbuflen = 0; - return( AFPERR_PARAM ); + *rbuflen = 0; + return( AFPERR_PARAM ); } strcpy( name, ibuf ); ibuf += len; if (U_InitRPC() != 0) { - *rbuflen = 0; - return( AFPERR_BADUAM ); + *rbuflen = 0; + return( AFPERR_BADUAM ); } memcpy( &clen, ibuf, sizeof( clen )); ibuf += sizeof( short ); pcbc_encrypt((C_Block *)ibuf, (C_Block *)ibuf, - clen, seskeysched, seskey, 0 ); + clen, seskeysched, seskey, 0 ); len = (unsigned char) *ibuf++; if ( len > 9 ) { - *rbuflen = 0; - return( AFPERR_PARAM ); + *rbuflen = 0; + return( AFPERR_PARAM ); } memcpy( oldpw, ibuf, len ); oldpw[ len ] = '\0'; len = (unsigned char) *ibuf++; if ( len > 9 ) { - *rbuflen = 0; - return( AFPERR_PARAM ); + *rbuflen = 0; + return( AFPERR_PARAM ); } memcpy( newpw, ibuf, len ); newpw[ len ] = '\0'; rc = U_CellChangePassword( name, newpw, name, oldpw, cell ) != 0 ) { - if ( rc != 0 ) { - *rbuflen = 0; - if ( rc < 0 && r_errno = R_ERROR ) { - return( AFPERR_NOTAUTH ); - } else { - return( AFPERR_BADUAM ); - } - } + if ( rc != 0 ) { + *rbuflen = 0; + if ( rc < 0 && r_errno = R_ERROR ) { + return( AFPERR_NOTAUTH ); + } else { + return( AFPERR_BADUAM ); + } + } - return( AFP_OK ); -} + return( AFP_OK ); + } diff --git a/etc/afpd/quota.c b/etc/afpd/quota.c index e8f2fe9d..d3a9d6a3 100644 --- a/etc/afpd/quota.c +++ b/etc/afpd/quota.c @@ -1,5 +1,5 @@ /* - * $Id: quota.c,v 1.11 2001-09-06 20:00:59 rufustfirefly Exp $ + * $Id: quota.c,v 1.11.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -48,7 +48,7 @@ char *strchr (), *strrchr (); #ifdef NEED_QUOTACTL_WRAPPER int quotactl(int cmd, const char *special, int id, caddr_t addr) { - return syscall(__NR_quotactl, cmd, special, id, addr); + return syscall(__NR_quotactl, cmd, special, id, addr); } #endif /* NEED_QUOTACTL_WRAPPER */ @@ -60,8 +60,8 @@ int quotactl(int cmd, const char *special, int id, caddr_t addr) */ static char * mountp( file, nfs) - char *file; - int *nfs; +char *file; +int *nfs; { struct stat sb; FILE *mtab; @@ -69,29 +69,29 @@ mountp( file, nfs) static struct mnttab mnt; if ( stat( file, &sb ) < 0 ) { - return( NULL ); + return( NULL ); } devno = sb.st_dev; if (( mtab = fopen( "/etc/mnttab", "r" )) == NULL ) { - return( NULL ); + return( NULL ); } while ( getmntent( mtab, &mnt ) == 0 ) { - /* local fs */ - if ( (stat( mnt.mnt_special, &sb ) == 0) && (devno == sb.st_rdev)) { - fclose( mtab ); - return mnt.mnt_mountp; - } - - /* check for nfs. we probably should use - * strcmp(mnt.mnt_fstype, MNTTYPE_NFS), but that's not as fast. */ - if ((stat(mnt.mnt_mountp, &sb) == 0) && (devno == sb.st_dev) && - strchr(mnt.mnt_special, ':')) { - *nfs = 1; - fclose( mtab ); - return mnt.mnt_special; - } + /* local fs */ + if ( (stat( mnt.mnt_special, &sb ) == 0) && (devno == sb.st_rdev)) { + fclose( mtab ); + return mnt.mnt_mountp; + } + + /* check for nfs. we probably should use + * strcmp(mnt.mnt_fstype, MNTTYPE_NFS), but that's not as fast. */ + if ((stat(mnt.mnt_mountp, &sb) == 0) && (devno == sb.st_dev) && + strchr(mnt.mnt_special, ':')) { + *nfs = 1; + fclose( mtab ); + return mnt.mnt_special; + } } fclose( mtab ); @@ -101,25 +101,25 @@ mountp( file, nfs) #else /* __svr4__ */ #ifdef ultrix /* - * Return the block-special device name associated with the filesystem - * on which "file" resides. Returns NULL on failure. - */ +* Return the block-special device name associated with the filesystem +* on which "file" resides. Returns NULL on failure. +*/ static char * special( file, nfs ) - char *file; - int *nfs; +char *file; +int *nfs; { static struct fs_data fsd; if ( getmnt(0, &fsd, 0, STAT_ONE, file ) < 0 ) { - syslog(LOG_INFO, "special: getmnt %s: %m", file ); - return( NULL ); + syslog(LOG_INFO, "special: getmnt %s: %m", file ); + return( NULL ); } /* XXX: does this really detect an nfs mounted fs? */ if (strchr(fsd.fd_req.devname, ':')) - *nfs = 1; + *nfs = 1; return( fsd.fd_req.devname ); } @@ -128,18 +128,18 @@ special( file, nfs ) static char * special( file, nfs ) - char *file; - int *nfs; +char *file; +int *nfs; { static struct statfs sfs; if ( statfs( file, &sfs ) < 0 ) { - return( NULL ); + return( NULL ); } /* XXX: make sure this really detects an nfs mounted fs */ if (strchr(sfs.f_mntfromname, ':')) - *nfs = 1; + *nfs = 1; return( sfs.f_mntfromname ); } @@ -147,8 +147,8 @@ special( file, nfs ) static char * special( file, nfs ) - char *file; - int *nfs; +char *file; +int *nfs; { struct stat sb; FILE *mtab; @@ -156,29 +156,29 @@ special( file, nfs ) struct mntent *mnt; if ( stat( file, &sb ) < 0 ) { - return( NULL ); + return( NULL ); } devno = sb.st_dev; if (( mtab = setmntent( "/etc/mtab", "r" )) == NULL ) { - return( NULL ); + return( NULL ); } while (( mnt = getmntent( mtab )) != NULL ) { - /* check for local fs */ - if ( (stat( mnt->mnt_fsname, &sb ) == 0) && devno == sb.st_rdev) { - endmntent( mtab ); - return( mnt->mnt_fsname ); - } - - /* check for an nfs mount entry. the alternative is to use - * strcmp(mnt->mnt_type, MNTTYPE_NFS) instead of the strchr. */ - if ((stat(mnt->mnt_dir, &sb) == 0) && (devno == sb.st_dev) && - strchr(mnt->mnt_fsname, ':')) { - *nfs = 1; - endmntent( mtab ); - return( mnt->mnt_fsname ); - } + /* check for local fs */ + if ( (stat( mnt->mnt_fsname, &sb ) == 0) && devno == sb.st_rdev) { + endmntent( mtab ); + return( mnt->mnt_fsname ); + } + + /* check for an nfs mount entry. the alternative is to use + * strcmp(mnt->mnt_type, MNTTYPE_NFS) instead of the strchr. */ + if ((stat(mnt->mnt_dir, &sb) == 0) && (devno == sb.st_dev) && + strchr(mnt->mnt_fsname, ':')) { + *nfs = 1; + endmntent( mtab ); + return( mnt->mnt_fsname ); + } } endmntent( mtab ); @@ -191,9 +191,9 @@ special( file, nfs ) static int getfsquota(vol, uid, dq) - struct vol *vol; - const int uid; - struct dqblk *dq; +struct vol *vol; +const int uid; +struct dqblk *dq; { #ifdef __svr4__ struct quotctl qc; @@ -202,13 +202,13 @@ static int getfsquota(vol, uid, dq) qc.uid = uid; qc.addr = (caddr_t)dq; if ( ioctl( vol->v_qfd, Q_QUOTACTL, &qc ) < 0 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } #else /* __svr4__ */ #ifdef ultrix if ( quota( Q_GETDLIM, uid, vol->v_gvs, dq ) != 0 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } #else /* ultrix */ @@ -222,41 +222,41 @@ static int getfsquota(vol, uid, dq) #ifndef TRU64 /* for group quotas. we only use these if the user belongs - * to one group. */ + * to one group. */ struct dqblk dqg; memset(&dqg, 0, sizeof(dqg)); #endif /* TRU64 */ #ifdef BSD4_4 - if ( quotactl( vol->v_gvs, QCMD(Q_GETQUOTA,USRQUOTA), - uid, (char *)dq ) != 0 ) { - return( AFPERR_PARAM ); + if ( quotactl( vol->v_gvs, QCMD(Q_GETQUOTA,USRQUOTA), + uid, (char *)dq ) != 0 ) { + return( AFPERR_PARAM ); } - if (ngroups == 1) - quotactl(vol->v_gvs, QCMD(Q_GETQUOTA, GRPQUOTA), - groups[0], (char *) &dqg); - + if (ngroups == 1) + quotactl(vol->v_gvs, QCMD(Q_GETQUOTA, GRPQUOTA), + groups[0], (char *) &dqg); + #elif defined(TRU64) - if ( seteuid( getuid() ) == 0 ) { - if ( quotactl( vol->v_path, QCMD(Q_GETQUOTA, USRQUOTA), - uid, (char *)dq ) != 0 ) { - seteuid( uid ); - return ( AFPERR_PARAM ); - } - seteuid( uid ); - } + if ( seteuid( getuid() ) == 0 ) { + if ( quotactl( vol->v_path, QCMD(Q_GETQUOTA, USRQUOTA), + uid, (char *)dq ) != 0 ) { + seteuid( uid ); + return ( AFPERR_PARAM ); + } + seteuid( uid ); + } #else /* BSD4_4 */ if ( quotactl(QCMD(Q_GETQUOTA, USRQUOTA), vol->v_gvs, uid, - (caddr_t) dq ) != 0 ) { - return( AFPERR_PARAM ); + (caddr_t) dq ) != 0 ) { + return( AFPERR_PARAM ); } - if (ngroups == 1) - quotactl(QCMD(Q_GETQUOTA, GRPQUOTA), vol->v_gvs, - groups[0], (char *) &dqg); + if (ngroups == 1) + quotactl(QCMD(Q_GETQUOTA, GRPQUOTA), vol->v_gvs, + groups[0], (char *) &dqg); #endif /* BSD4_4 */ #ifndef TRU64 @@ -264,22 +264,22 @@ static int getfsquota(vol, uid, dq) /* max(user blocks, group blocks) */ if (dqg.dqb_curblocks && (dq->dqb_curblocks < dqg.dqb_curblocks)) - dq->dqb_curblocks = dqg.dqb_curblocks; - + dq->dqb_curblocks = dqg.dqb_curblocks; + /* min(user limit, group limit) */ if (dqg.dqb_bhardlimit && (!dq->dqb_bhardlimit || - (dq->dqb_bhardlimit > dqg.dqb_bhardlimit))) - dq->dqb_bhardlimit = dqg.dqb_bhardlimit; + (dq->dqb_bhardlimit > dqg.dqb_bhardlimit))) + dq->dqb_bhardlimit = dqg.dqb_bhardlimit; /* ditto */ if (dqg.dqb_bsoftlimit && (!dq->dqb_bsoftlimit || - (dq->dqb_bsoftlimit > dqg.dqb_bsoftlimit))) - dq->dqb_bsoftlimit = dqg.dqb_bsoftlimit; + (dq->dqb_bsoftlimit > dqg.dqb_bsoftlimit))) + dq->dqb_bsoftlimit = dqg.dqb_bsoftlimit; /* ditto */ if (dqg.dqb_btimelimit && (!dq->dqb_btimelimit || - (dq->dqb_btimelimit > dqg.dqb_btimelimit))) - dq->dqb_btimelimit = dqg.dqb_btimelimit; + (dq->dqb_btimelimit > dqg.dqb_btimelimit))) + dq->dqb_btimelimit = dqg.dqb_btimelimit; #endif /* TRU64 */ @@ -291,9 +291,9 @@ static int getfsquota(vol, uid, dq) static int getquota( vol, dq, bsize) - struct vol *vol; - struct dqblk *dq; - const u_int32_t bsize; +struct vol *vol; +struct dqblk *dq; +const u_int32_t bsize; { char *p; @@ -301,65 +301,65 @@ static int getquota( vol, dq, bsize) char buf[ MAXPATHLEN + 1]; if ( vol->v_qfd == -1 && vol->v_gvs == NULL) { - if (( p = mountp( vol->v_path, &vol->v_nfs)) == NULL ) { - syslog( LOG_INFO, "getquota: mountp %s fails", vol->v_path ); - return( AFPERR_PARAM ); - } - - if (vol->v_nfs) { - if (( vol->v_gvs = (char *)malloc( strlen( p ) + 1 )) == NULL ) { - syslog( LOG_ERR, "getquota: malloc: %m" ); - return AFPERR_MISC; - } - strcpy( vol->v_gvs, p ); - - } else { - sprintf( buf, "%s/quotas", p ); - if (( vol->v_qfd = open( buf, O_RDONLY, 0 )) < 0 ) { - syslog( LOG_INFO, "open %s: %m", buf ); - return( AFPERR_PARAM ); - } - } - + if (( p = mountp( vol->v_path, &vol->v_nfs)) == NULL ) { + syslog( LOG_INFO, "getquota: mountp %s fails", vol->v_path ); + return( AFPERR_PARAM ); + } + + if (vol->v_nfs) { + if (( vol->v_gvs = (char *)malloc( strlen( p ) + 1 )) == NULL ) { + syslog( LOG_ERR, "getquota: malloc: %m" ); + return AFPERR_MISC; + } + strcpy( vol->v_gvs, p ); + + } else { + sprintf( buf, "%s/quotas", p ); + if (( vol->v_qfd = open( buf, O_RDONLY, 0 )) < 0 ) { + syslog( LOG_INFO, "open %s: %m", buf ); + return( AFPERR_PARAM ); + } + } + } #else if ( vol->v_gvs == NULL ) { - if (( p = special( vol->v_path, &vol->v_nfs )) == NULL ) { - syslog( LOG_INFO, "getquota: special %s fails", vol->v_path ); - return( AFPERR_PARAM ); - } - - if (( vol->v_gvs = (char *)malloc( strlen( p ) + 1 )) == NULL ) { - syslog( LOG_ERR, "getquota: malloc: %m" ); - return AFPERR_MISC; - } - strcpy( vol->v_gvs, p ); + if (( p = special( vol->v_path, &vol->v_nfs )) == NULL ) { + syslog( LOG_INFO, "getquota: special %s fails", vol->v_path ); + return( AFPERR_PARAM ); + } + + if (( vol->v_gvs = (char *)malloc( strlen( p ) + 1 )) == NULL ) { + syslog( LOG_ERR, "getquota: malloc: %m" ); + return AFPERR_MISC; + } + strcpy( vol->v_gvs, p ); } #endif - return vol->v_nfs ? getnfsquota(vol, uuid, bsize, dq) : - getfsquota(vol, uuid, dq); + return vol->v_nfs ? getnfsquota(vol, uuid, bsize, dq) : + getfsquota(vol, uuid, dq); } static int overquota( dqblk ) - struct dqblk *dqblk; +struct dqblk *dqblk; { struct timeval tv; if ( dqblk->dqb_curblocks < dqblk->dqb_bsoftlimit ) { - return( 0 ); + return( 0 ); } #ifdef ultrix if ( dqblk->dqb_bwarn ) { - return( 0 ); + return( 0 ); } #else /* ultrix */ if ( gettimeofday( &tv, 0 ) < 0 ) { - syslog( LOG_ERR, "overquota: gettimeofday: %m" ); - return( AFPERR_PARAM ); + syslog( LOG_ERR, "overquota: gettimeofday: %m" ); + return( AFPERR_PARAM ); } if ( !dqblk->dqb_btimelimit || dqblk->dqb_btimelimit > tv.tv_sec ) { - return( 0 ); + return( 0 ); } #endif /* ultrix */ return( 1 ); @@ -383,7 +383,7 @@ static int overquota( dqblk ) #define dbtob(a) ((a) << 10) #endif -/* i do the cast to VolSpace here to make sure that 64-bit shifts +/* i do the cast to VolSpace here to make sure that 64-bit shifts work */ #ifdef HAVE_2ARG_DBTOB #define tobytes(a, b) dbtob((VolSpace) (a), (VolSpace) (b)) @@ -391,27 +391,27 @@ static int overquota( dqblk ) #define tobytes(a, b) dbtob((VolSpace) (a)) #endif int uquota_getvolspace( vol, bfree, btotal, bsize) - const struct vol *vol; - VolSpace *bfree, *btotal; - const u_int32_t bsize; +const struct vol *vol; +VolSpace *bfree, *btotal; +const u_int32_t bsize; { struct dqblk dqblk; if (getquota( vol, &dqblk, bsize) != 0 ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } /* no limit set for this user. it might be set in the future. */ if (dqblk.dqb_bsoftlimit == 0 && dqblk.dqb_bhardlimit == 0) { - *btotal = *bfree = ~((VolSpace) 0); + *btotal = *bfree = ~((VolSpace) 0); } else if ( overquota( &dqblk )) { - *btotal = tobytes( dqblk.dqb_bhardlimit, bsize ); - *bfree = tobytes( dqblk.dqb_bhardlimit, bsize ) - - tobytes( dqblk.dqb_curblocks, bsize ); + *btotal = tobytes( dqblk.dqb_bhardlimit, bsize ); + *bfree = tobytes( dqblk.dqb_bhardlimit, bsize ) - + tobytes( dqblk.dqb_curblocks, bsize ); } else { - *btotal = tobytes( dqblk.dqb_bsoftlimit, bsize ); - *bfree = tobytes( dqblk.dqb_bsoftlimit, bsize ) - - tobytes( dqblk.dqb_curblocks, bsize ); + *btotal = tobytes( dqblk.dqb_bsoftlimit, bsize ); + *bfree = tobytes( dqblk.dqb_bsoftlimit, bsize ) - + tobytes( dqblk.dqb_curblocks, bsize ); } return( AFP_OK ); diff --git a/etc/afpd/status.c b/etc/afpd/status.c index b222f509..83d3f1cd 100644 --- a/etc/afpd/status.c +++ b/etc/afpd/status.c @@ -1,5 +1,5 @@ /* - * $Id: status.c,v 1.4 2001-08-15 01:37:34 srittau Exp $ + * $Id: status.c,v 1.4.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -35,20 +35,20 @@ #include "icon.h" static void status_flags(char *data, const int ipok, - const unsigned char passwdbits) + const unsigned char passwdbits) { u_int16_t status; status = AFPSRVRINFO_COPY; if (passwdbits & PASSWD_SET) /* some uams may not allow this. */ - status |= AFPSRVRINFO_PASSWD; + status |= AFPSRVRINFO_PASSWD; if (passwdbits & PASSWD_NOSAVE) - status |= AFPSRVRINFO_NOSAVEPASSWD; + status |= AFPSRVRINFO_NOSAVEPASSWD; status |= AFPSRVRINFO_SRVSIGNATURE; /* only advertise tcp/ip if we have a valid address */ if (ipok) - status |= AFPSRVRINFO_TCPIP; - status |= AFPSRVRINFO_SRVMSGS; + status |= AFPSRVRINFO_TCPIP; + status |= AFPSRVRINFO_SRVMSGS; status |= AFPSRVRINFO_SRVNOTIFY; status |= AFPSRVRINFO_FASTBOZO; status = htons(status); @@ -72,10 +72,10 @@ static int status_server(char *data, const char *server) *data++ = len; memcpy( data, Obj, len ); if ((len + 1) & 1) /* pad server name and length byte to even boundary */ - len++; + len++; data += len; - /* make room for signature and net address offset. save location of + /* make room for signature and net address offset. save location of * signature offset. * * NOTE: technically, we don't need to reserve space for the @@ -113,79 +113,79 @@ static void status_machine(char *data) /* server signature is a 16-byte quantity */ -static u_int16_t status_signature(char *data, int *servoffset, DSI *dsi, - const char *hostname) +static u_int16_t status_signature(char *data, int *servoffset, DSI *dsi, + const char *hostname) { - char *status; - int i; - u_int16_t offset, sigoff; - long hostid; - static int id = 0; + char *status; + int i; + u_int16_t offset, sigoff; + long hostid; + static int id = 0; #ifdef BSD4_4 - int mib[2]; - size_t len; + int mib[2]; + size_t len; #endif /* BSD4_4 */ - status = data; + status = data; - /* get server signature offset */ - memcpy(&offset, data + *servoffset, sizeof(offset)); - sigoff = offset = ntohs(offset); + /* get server signature offset */ + memcpy(&offset, data + *servoffset, sizeof(offset)); + sigoff = offset = ntohs(offset); - /* jump to server signature offset */ - data += offset; + /* jump to server signature offset */ + data += offset; - /* 16-byte signature consists of copies of the hostid */ + /* 16-byte signature consists of copies of the hostid */ #if defined(BSD4_4) && defined(USE_GETHOSTID) - mib[0] = CTL_KERN; - mib[1] = KERN_HOSTID; - len = sizeof(hostid); - sysctl(mib, 2, &hostid, &len, NULL, 0); + mib[0] = CTL_KERN; + mib[1] = KERN_HOSTID; + len = sizeof(hostid); + sysctl(mib, 2, &hostid, &len, NULL, 0); #else /* BSD4_4 && USE_GETHOSTID */ - hostid = gethostid(); + hostid = gethostid(); #endif /* BSD4_4 && USE_GETHOSTID */ - if (!hostid) { - if (dsi) - hostid = dsi->server.sin_addr.s_addr; - else { - struct hostent *host; - - if ((host = gethostbyname(hostname))) - hostid = ((struct in_addr *) host->h_addr)->s_addr; + if (!hostid) { + if (dsi) + hostid = dsi->server.sin_addr.s_addr; + else { + struct hostent *host; + + if ((host = gethostbyname(hostname))) + hostid = ((struct in_addr *) host->h_addr)->s_addr; + } } - } - - /* it turns out that a server signature screws up separate - * servers running on the same machine. to work around that, - * i add in an increment */ - hostid += id; - id++; - for (i = 0; i < 16; i += sizeof(hostid)) { - memcpy(data, &hostid, sizeof(hostid)); - data += sizeof(hostid); - } - - /* calculate net address offset */ - *servoffset += sizeof(offset); - offset = htons(data - status); - memcpy(status + *servoffset, &offset, sizeof(offset)); - return sigoff; + + /* it turns out that a server signature screws up separate + * servers running on the same machine. to work around that, + * i add in an increment */ + hostid += id; + id++; + for (i = 0; i < 16; i += sizeof(hostid)) { + memcpy(data, &hostid, sizeof(hostid)); + data += sizeof(hostid); + } + + /* calculate net address offset */ + *servoffset += sizeof(offset); + offset = htons(data - status); + memcpy(status + *servoffset, &offset, sizeof(offset)); + return sigoff; } -static int status_netaddress(char *data, const int servoffset, - const ASP asp, const DSI *dsi, - const char *fqdn) +static int status_netaddress(char *data, const int servoffset, + const ASP asp, const DSI *dsi, + const char *fqdn) { char *begin; u_int16_t offset; - + begin = data; /* get net address offset */ memcpy(&offset, data + servoffset, sizeof(offset)); data += ntohs(offset); - /* format: + /* format: Address count (byte) len (byte = sizeof(length + address type + address) address type (byte, ip address = 0x01, ip + port = 0x02, @@ -200,49 +200,49 @@ static int status_netaddress(char *data, const int servoffset, /* handle DNS names */ if (fqdn) { - int len = strlen(fqdn) + 2; - *data++ = len; - *data++ = 0x04; - memcpy(data, fqdn, len); - data += len; + int len = strlen(fqdn) + 2; + *data++ = len; + *data++ = 0x04; + memcpy(data, fqdn, len); + data += len; } /* ip address */ if (dsi) { - const struct sockaddr_in *inaddr = &dsi->server; - - if (inaddr->sin_port == htons(DSI_AFPOVERTCP_PORT)) { - *data++ = 6; /* length */ - *data++ = 0x01; /* basic ip address */ - memcpy(data, &inaddr->sin_addr.s_addr, - sizeof(inaddr->sin_addr.s_addr)); - data += sizeof(inaddr->sin_addr.s_addr); - } else { - /* ip address + port */ - *data++ = 8; - *data++ = 0x02; /* ip address with port */ - memcpy(data, &inaddr->sin_addr.s_addr, - sizeof(inaddr->sin_addr.s_addr)); - data += sizeof(inaddr->sin_addr.s_addr); - memcpy(data, &inaddr->sin_port, sizeof(inaddr->sin_port)); - data += sizeof(inaddr->sin_port); - } + const struct sockaddr_in *inaddr = &dsi->server; + + if (inaddr->sin_port == htons(DSI_AFPOVERTCP_PORT)) { + *data++ = 6; /* length */ + *data++ = 0x01; /* basic ip address */ + memcpy(data, &inaddr->sin_addr.s_addr, + sizeof(inaddr->sin_addr.s_addr)); + data += sizeof(inaddr->sin_addr.s_addr); + } else { + /* ip address + port */ + *data++ = 8; + *data++ = 0x02; /* ip address with port */ + memcpy(data, &inaddr->sin_addr.s_addr, + sizeof(inaddr->sin_addr.s_addr)); + data += sizeof(inaddr->sin_addr.s_addr); + memcpy(data, &inaddr->sin_port, sizeof(inaddr->sin_port)); + data += sizeof(inaddr->sin_port); + } } #ifndef NO_DDP if (asp) { - const struct sockaddr_at *ddpaddr = atp_sockaddr(asp->asp_atp); - - /* ddp address */ - *data++ = 6; - *data++ = 0x03; /* ddp address */ - memcpy(data, &ddpaddr->sat_addr.s_net, sizeof(ddpaddr->sat_addr.s_net)); - data += sizeof(ddpaddr->sat_addr.s_net); - memcpy(data, &ddpaddr->sat_addr.s_node, - sizeof(ddpaddr->sat_addr.s_node)); - data += sizeof(ddpaddr->sat_addr.s_node); - memcpy(data, &ddpaddr->sat_port, sizeof(ddpaddr->sat_port)); - data += sizeof(ddpaddr->sat_port); + const struct sockaddr_at *ddpaddr = atp_sockaddr(asp->asp_atp); + + /* ddp address */ + *data++ = 6; + *data++ = 0x03; /* ddp address */ + memcpy(data, &ddpaddr->sat_addr.s_net, sizeof(ddpaddr->sat_addr.s_net)); + data += sizeof(ddpaddr->sat_addr.s_net); + memcpy(data, &ddpaddr->sat_addr.s_node, + sizeof(ddpaddr->sat_addr.s_node)); + data += sizeof(ddpaddr->sat_addr.s_node); + memcpy(data, &ddpaddr->sat_port, sizeof(ddpaddr->sat_port)); + data += sizeof(ddpaddr->sat_port); } #endif /* ! NO_DDP */ @@ -251,8 +251,8 @@ static int status_netaddress(char *data, const int servoffset, } /* returns actual offset to signature */ -static void status_icon(char *data, const char *icondata, - const int iconlen, const int sigoffset) +static void status_icon(char *data, const char *icondata, + const int iconlen, const int sigoffset) { char *start = data; char *sigdata = data + sigoffset; @@ -260,112 +260,112 @@ static void status_icon(char *data, const char *icondata, memcpy(&status, start + AFPSTATUS_ICONOFF, sizeof(status)); if ( icondata == NULL ) { - ret = status; - memset(start + AFPSTATUS_ICONOFF, 0, sizeof(status)); + ret = status; + memset(start + AFPSTATUS_ICONOFF, 0, sizeof(status)); } else { - data += ntohs( status ); - memcpy( data, icondata, iconlen); - data += iconlen; - ret = htons(data - start); + data += ntohs( status ); + memcpy( data, icondata, iconlen); + data += iconlen; + ret = htons(data - start); } - + /* put in signature offset */ if (sigoffset) - memcpy(sigdata, &ret, sizeof(ret)); + memcpy(sigdata, &ret, sizeof(ret)); } void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig, - const struct afp_options *options) + const struct afp_options *options) { - ASP asp; - DSI *dsi; - char *status; - int c, sigoff; - - if (!(aspconfig || dsiconfig) || !options) - return; - - if (aspconfig) { - asp = aspconfig->obj.handle; - status = aspconfig->status; - } else - asp = NULL; - - if (dsiconfig) { - dsi = dsiconfig->obj.handle; - if (!aspconfig) - status = dsiconfig->status; - } else - dsi = NULL; - - /* - * These routines must be called in order -- earlier calls - * set the offsets for later calls. - * - * using structs is a bad idea, but that's what the original code - * does. solaris, in fact, will segfault with them. so, now - * we just use the powers of #defines and memcpy. - * - * reply block layout (offsets are 16-bit quantities): - * machine type offset -> AFP version count offset -> - * UAM count offset -> vol icon/mask offset -> flags -> - * - * server name [padded to even boundary] -> signature offset -> - * network address offset -> - * - * at the appropriate offsets: - * machine type, afp versions, uams, server signature - * (16-bytes), network addresses, volume icon/mask - */ - - status_flags(status, options->fqdn || - (dsiconfig && dsi->server.sin_addr.s_addr), - options->passwdbits); - /* returns offset to signature offset */ - c = status_server(status, options->server ? options->server : - options->hostname); - status_machine(status); - status_versions(status); - status_uams(status, options->uamlist); - if (options->flags & OPTION_CUSTOMICON) - status_icon(status, icon, sizeof(icon), c); - else - status_icon(status, apple_atalk_icon, sizeof(apple_atalk_icon), c); - - sigoff = status_signature(status, &c, dsi, options->hostname); - - /* returns length */ - c = status_netaddress(status, c, asp, dsi, options->fqdn); + ASP asp; + DSI *dsi; + char *status; + int c, sigoff; + + if (!(aspconfig || dsiconfig) || !options) + return; + + if (aspconfig) { + asp = aspconfig->obj.handle; + status = aspconfig->status; + } else + asp = NULL; + + if (dsiconfig) { + dsi = dsiconfig->obj.handle; + if (!aspconfig) + status = dsiconfig->status; + } else + dsi = NULL; + + /* + * These routines must be called in order -- earlier calls + * set the offsets for later calls. + * + * using structs is a bad idea, but that's what the original code + * does. solaris, in fact, will segfault with them. so, now + * we just use the powers of #defines and memcpy. + * + * reply block layout (offsets are 16-bit quantities): + * machine type offset -> AFP version count offset -> + * UAM count offset -> vol icon/mask offset -> flags -> + * + * server name [padded to even boundary] -> signature offset -> + * network address offset -> + * + * at the appropriate offsets: + * machine type, afp versions, uams, server signature + * (16-bytes), network addresses, volume icon/mask + */ + + status_flags(status, options->fqdn || + (dsiconfig && dsi->server.sin_addr.s_addr), + options->passwdbits); + /* returns offset to signature offset */ + c = status_server(status, options->server ? options->server : + options->hostname); + status_machine(status); + status_versions(status); + status_uams(status, options->uamlist); + if (options->flags & OPTION_CUSTOMICON) + status_icon(status, icon, sizeof(icon), c); + else + status_icon(status, apple_atalk_icon, sizeof(apple_atalk_icon), c); + + sigoff = status_signature(status, &c, dsi, options->hostname); + + /* returns length */ + c = status_netaddress(status, c, asp, dsi, options->fqdn); #ifndef NO_DDP - if (aspconfig) { - asp_setstatus(asp, status, c); - aspconfig->signature = status + sigoff; - aspconfig->statuslen = c; - } + if (aspconfig) { + asp_setstatus(asp, status, c); + aspconfig->signature = status + sigoff; + aspconfig->statuslen = c; + } #endif /* ! NO_DDP */ - if (dsiconfig) { - if (aspconfig) { /* copy to dsiconfig */ - memcpy(dsiconfig->status, status, ATP_MAXDATA); - status = dsiconfig->status; + if (dsiconfig) { + if (aspconfig) { /* copy to dsiconfig */ + memcpy(dsiconfig->status, status, ATP_MAXDATA); + status = dsiconfig->status; + } + + if ((options->flags & OPTION_CUSTOMICON) == 0) { + status_icon(status, apple_tcp_icon, sizeof(apple_tcp_icon), 0); + } + dsi_setstatus(dsi, status, c); + dsiconfig->signature = status + sigoff; + dsiconfig->statuslen = c; } - - if ((options->flags & OPTION_CUSTOMICON) == 0) { - status_icon(status, apple_tcp_icon, sizeof(apple_tcp_icon), 0); - } - dsi_setstatus(dsi, status, c); - dsiconfig->signature = status + sigoff; - dsiconfig->statuslen = c; - } } /* this is the same as asp/dsi_getstatus */ int afp_getsrvrinfo(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { AFPConfig *config = obj->config; diff --git a/etc/afpd/status.h b/etc/afpd/status.h index a0b5282e..409355bc 100644 --- a/etc/afpd/status.h +++ b/etc/afpd/status.h @@ -1,5 +1,5 @@ /* - * $Id: status.h,v 1.4 2001-08-15 01:37:34 srittau Exp $ + * $Id: status.h,v 1.4.2.1 2001-12-03 05:01:04 jmarcus Exp $ */ #ifndef AFPD_STATUS_H @@ -30,7 +30,7 @@ extern void status_versions __P((char * /*status*/)); extern void status_uams __P((char * /*status*/, const char * /*authlist*/)); extern void status_init __P((AFPConfig *, AFPConfig *, - const struct afp_options *)); + const struct afp_options *)); extern int afp_getsrvrinfo __P((AFPObj *, char *, int, char *, int *)); #endif diff --git a/etc/afpd/switch.c b/etc/afpd/switch.c index 84cc5a7f..ab6917f5 100644 --- a/etc/afpd/switch.c +++ b/etc/afpd/switch.c @@ -1,5 +1,5 @@ /* - * $Id: switch.c,v 1.3 2001-06-20 18:33:04 rufustfirefly Exp $ + * $Id: switch.c,v 1.3.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1991 Regents of The University of Michigan. * All Rights Reserved. @@ -48,9 +48,9 @@ #include "misc.h" static int afp_null(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { syslog( LOG_INFO, "afp_null handle %d", *ibuf ); *rbuflen = 0; @@ -140,7 +140,7 @@ int (*postauth_switch[])() = { afp_logout, afp_mapid, afp_mapname, afp_moveandrename, /* 16 - 23 */ afp_openvol, afp_opendir, afp_openfork, afp_read, afp_rename, afp_setdirparams, afp_setfilparams, afp_setforkparams, - /* 24 - 31 */ + /* 24 - 31 */ afp_setvolparams, afp_write, afp_getfildirparams, afp_setfildirparams, afp_changepw, afp_getuserinfo, afp_getsrvrmesg, afp_createid, /* 32 - 39 */ afp_deleteid, afp_resolveid, afp_exchangefiles, afp_null /*afp_catsearch*/, @@ -203,26 +203,26 @@ int (*postauth_switch[])() = { /* add a new function if it's specified. return the old function in * "old" if there's a pointer there. */ int uam_afpserver_action(const int id, const int which, - int (**new)(), int (**old)()) + int (**new)(), int (**old)()) { - switch (which) { - case UAM_AFPSERVER_PREAUTH: - if (old) - *old = preauth_switch[id]; - if (new) - preauth_switch[id] = *new; - break; - case UAM_AFPSERVER_POSTAUTH: - if (old) - *old = postauth_switch[id]; - if (new) - postauth_switch[id] = *new; - break; - default: - syslog(LOG_DEBUG, "uam_afpserver_action: unknown switch %d[%d]", - which, id); - return -1; - } + switch (which) { + case UAM_AFPSERVER_PREAUTH: + if (old) + *old = preauth_switch[id]; + if (new) + preauth_switch[id] = *new; + break; + case UAM_AFPSERVER_POSTAUTH: + if (old) + *old = postauth_switch[id]; + if (new) + postauth_switch[id] = *new; + break; + default: + syslog(LOG_DEBUG, "uam_afpserver_action: unknown switch %d[%d]", + which, id); + return -1; + } - return 0; + return 0; } diff --git a/etc/afpd/test_parse_mtab.c b/etc/afpd/test_parse_mtab.c index ffa95138..4d8cc30d 100644 --- a/etc/afpd/test_parse_mtab.c +++ b/etc/afpd/test_parse_mtab.c @@ -1,5 +1,5 @@ /* - * $Id: test_parse_mtab.c,v 1.3 2001-07-31 19:50:14 srittau Exp $ + * $Id: test_parse_mtab.c,v 1.3.2.1 2001-12-03 05:01:04 jmarcus Exp $ * test driver for the afpd_mtab_parse fn. -- rgr, 9-Apr-01. */ @@ -34,50 +34,50 @@ int main(int argc, char **argv) { - char *file_name = "afpd.mtab"; - struct afpd_mount_table *table = NULL; - int arg = 1; + char *file_name = "afpd.mtab"; + struct afpd_mount_table *table = NULL; + int arg = 1; - if (argc >= 3 && strcmp(argv[1], "-f") == 0) { - file_name = argv[2]; - arg += 2; - } - if (arg < argc && argv[arg][0] == '-') { - /* either they don't understand, or they must be asking for help anyway. */ - fprintf(stderr, "Usage: %s [-f file-name] [file . . . ]\n", - argv[0]); - exit(1); - } - table = afpd_mtab_parse(file_name); - if (table != NULL) { - struct stat st; - int id, count = 0; + if (argc >= 3 && strcmp(argv[1], "-f") == 0) { + file_name = argv[2]; + arg += 2; + } + if (arg < argc && argv[arg][0] == '-') { + /* either they don't understand, or they must be asking for help anyway. */ + fprintf(stderr, "Usage: %s [-f file-name] [file . . . ]\n", + argv[0]); + exit(1); + } + table = afpd_mtab_parse(file_name); + if (table != NULL) { + struct stat st; + int id, count = 0; - fprintf(stderr, "File %s: Field width %d, shift %d.\n", - file_name, table->bits, table->shift); - for (id = 0; id < table->size; id++) { - struct afpd_mtab_entry *entry = table->table[id]; + fprintf(stderr, "File %s: Field width %d, shift %d.\n", + file_name, table->bits, table->shift); + for (id = 0; id < table->size; id++) { + struct afpd_mtab_entry *entry = table->table[id]; - if (entry != NULL) { - fprintf(stderr, " Id %d -> device %s (%d,%d) on %s -> bits 0x%08x.\n", - id, entry->device, entry->dev_major, entry->dev_minor, - entry->mount_point, entry->bit_value); - count++; - } - } - fprintf(stderr, "%d entries used out of a maximum of %d (1..%d).\n", - count, table->size-1, table->size-1); - for (; arg < argc; arg++) { - if (lstat(argv[arg], &st) != 0) { - fprintf(stderr, "Can't lstat '%s': code %d\n", - argv[arg], errno); - } - else { - fprintf(stderr, "File %s, device (%d,%d), inode %ld, CNID 0x%08x.\n", - argv[arg], major(st.st_dev), minor(st.st_dev), st.st_ino, - CNID(&st, S_ISDIR(st.st_mode) ? 1 : 0)); - } + if (entry != NULL) { + fprintf(stderr, " Id %d -> device %s (%d,%d) on %s -> bits 0x%08x.\n", + id, entry->device, entry->dev_major, entry->dev_minor, + entry->mount_point, entry->bit_value); + count++; + } + } + fprintf(stderr, "%d entries used out of a maximum of %d (1..%d).\n", + count, table->size-1, table->size-1); + for (; arg < argc; arg++) { + if (lstat(argv[arg], &st) != 0) { + fprintf(stderr, "Can't lstat '%s': code %d\n", + argv[arg], errno); + } + else { + fprintf(stderr, "File %s, device (%d,%d), inode %ld, CNID 0x%08x.\n", + argv[arg], major(st.st_dev), minor(st.st_dev), st.st_ino, + CNID(&st, S_ISDIR(st.st_mode) ? 1 : 0)); + } + } } - } - return(0); + return(0); } diff --git a/etc/afpd/uam.c b/etc/afpd/uam.c index f0d2ea6b..6635d828 100644 --- a/etc/afpd/uam.c +++ b/etc/afpd/uam.c @@ -1,5 +1,5 @@ /* - * $Id: uam.c,v 1.15 2001-11-13 15:01:38 rufustfirefly Exp $ + * $Id: uam.c,v 1.15.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu) * All Rights Reserved. See COPYRIGHT. @@ -66,53 +66,53 @@ char *strchr (), *strrchr (); /* uam_load. uams must have a uam_setup function. */ struct uam_mod *uam_load(const char *path, const char *name) { - char buf[MAXPATHLEN + 1], *p; - struct uam_mod *mod; - void *module; + char buf[MAXPATHLEN + 1], *p; + struct uam_mod *mod; + void *module; - if ((module = mod_open(path)) == NULL) { - syslog(LOG_ERR, "uam_load(%s): failed to load: %s", name, mod_error()); - return NULL; - } - - if ((mod = (struct uam_mod *) malloc(sizeof(struct uam_mod))) == NULL) { - syslog(LOG_ERR, "uam_load(%s): malloc failed", name); - goto uam_load_fail; - } - - strncpy(buf, name, sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - if ((p = strchr(buf, '.'))) - *p = '\0'; - if ((mod->uam_fcn = mod_symbol(module, buf)) == NULL) { - syslog(LOG_ERR, "uam_load(%s): mod_symbol error for symbol %s", - name, - buf); - goto uam_load_err; - } - - if (mod->uam_fcn->uam_type != UAM_MODULE_SERVER) { - syslog(LOG_ERR, "uam_load(%s): attempted to load a non-server module", - name); - goto uam_load_err; - } - - /* version check would go here */ - - if (!mod->uam_fcn->uam_setup || - ((*mod->uam_fcn->uam_setup)(name) < 0)) { - syslog(LOG_ERR, "uam_load(%s): uam_setup failed", name); - goto uam_load_err; - } - - mod->uam_module = module; - return mod; + if ((module = mod_open(path)) == NULL) { + syslog(LOG_ERR, "uam_load(%s): failed to load: %s", name, mod_error()); + return NULL; + } + + if ((mod = (struct uam_mod *) malloc(sizeof(struct uam_mod))) == NULL) { + syslog(LOG_ERR, "uam_load(%s): malloc failed", name); + goto uam_load_fail; + } + + strncpy(buf, name, sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + if ((p = strchr(buf, '.'))) + *p = '\0'; + if ((mod->uam_fcn = mod_symbol(module, buf)) == NULL) { + syslog(LOG_ERR, "uam_load(%s): mod_symbol error for symbol %s", + name, + buf); + goto uam_load_err; + } + + if (mod->uam_fcn->uam_type != UAM_MODULE_SERVER) { + syslog(LOG_ERR, "uam_load(%s): attempted to load a non-server module", + name); + goto uam_load_err; + } + + /* version check would go here */ + + if (!mod->uam_fcn->uam_setup || + ((*mod->uam_fcn->uam_setup)(name) < 0)) { + syslog(LOG_ERR, "uam_load(%s): uam_setup failed", name); + goto uam_load_err; + } + + mod->uam_module = module; + return mod; uam_load_err: - free(mod); + free(mod); uam_load_fail: - mod_close(module); - return NULL; + mod_close(module); + return NULL; } /* unload the module. we check for a cleanup function, but we don't @@ -120,10 +120,10 @@ uam_load_fail: */ void uam_unload(struct uam_mod *mod) { - if (mod->uam_fcn->uam_cleanup) - (*mod->uam_fcn->uam_cleanup)(); - mod_close(mod->uam_module); - free(mod); + if (mod->uam_fcn->uam_cleanup) + (*mod->uam_fcn->uam_cleanup)(); + mod_close(mod->uam_module); + free(mod); } /* -- client-side uam functions -- */ @@ -131,296 +131,296 @@ void uam_unload(struct uam_mod *mod) /* set up stuff for this uam. */ int uam_register(const int type, const char *path, const char *name, ...) { - va_list ap; - struct uam_obj *uam; - - if (!name) - return -1; - - /* see if it already exists. */ - if ((uam = auth_uamfind(type, name, strlen(name)))) { - if (strcmp(uam->uam_path, path)) { - /* it exists, but it's not the same module. */ - syslog(LOG_ERR, "uam_register: \"%s\" already loaded by %s", - name, path); - return -1; + va_list ap; + struct uam_obj *uam; + + if (!name) + return -1; + + /* see if it already exists. */ + if ((uam = auth_uamfind(type, name, strlen(name)))) { + if (strcmp(uam->uam_path, path)) { + /* it exists, but it's not the same module. */ + syslog(LOG_ERR, "uam_register: \"%s\" already loaded by %s", + name, path); + return -1; + } + uam->uam_count++; + return 0; } + + /* allocate space for uam */ + if ((uam = calloc(1, sizeof(struct uam_obj))) == NULL) + return -1; + + uam->uam_name = name; + uam->uam_path = strdup(path); uam->uam_count++; - return 0; - } - - /* allocate space for uam */ - if ((uam = calloc(1, sizeof(struct uam_obj))) == NULL) - return -1; - - uam->uam_name = name; - uam->uam_path = strdup(path); - uam->uam_count++; - - va_start(ap, name); - switch (type) { - case UAM_SERVER_LOGIN: /* expect three arguments */ - uam->u.uam_login.login = va_arg(ap, void *); - uam->u.uam_login.logincont = va_arg(ap, void *); - uam->u.uam_login.logout = va_arg(ap, void *); - break; - case UAM_SERVER_CHANGEPW: /* one argument */ - uam->u.uam_changepw = va_arg(ap, void *); - break; - case UAM_SERVER_PRINTAUTH: /* x arguments */ - default: - break; - } - va_end(ap); - - /* attach to other uams */ - if (auth_register(type, uam) < 0) { - free(uam->uam_path); - free(uam); - return -1; - } - return 0; + va_start(ap, name); + switch (type) { + case UAM_SERVER_LOGIN: /* expect three arguments */ + uam->u.uam_login.login = va_arg(ap, void *); + uam->u.uam_login.logincont = va_arg(ap, void *); + uam->u.uam_login.logout = va_arg(ap, void *); + break; + case UAM_SERVER_CHANGEPW: /* one argument */ + uam->u.uam_changepw = va_arg(ap, void *); + break; + case UAM_SERVER_PRINTAUTH: /* x arguments */ + default: + break; + } + va_end(ap); + + /* attach to other uams */ + if (auth_register(type, uam) < 0) { + free(uam->uam_path); + free(uam); + return -1; + } + + return 0; } void uam_unregister(const int type, const char *name) { - struct uam_obj *uam; + struct uam_obj *uam; - if (!name) - return; + if (!name) + return; - uam = auth_uamfind(type, name, strlen(name)); - if (!uam || --uam->uam_count > 0) - return; + uam = auth_uamfind(type, name, strlen(name)); + if (!uam || --uam->uam_count > 0) + return; - auth_unregister(uam); - free(uam->uam_path); - free(uam); + auth_unregister(uam); + free(uam->uam_path); + free(uam); } /* --- helper functions for plugin uams --- */ struct passwd *uam_getname(char *name, const int len) { - struct passwd *pwent; - char *user; - int i; + struct passwd *pwent; + char *user; + int i; - if ((pwent = getpwnam(name))) - return pwent; + if ((pwent = getpwnam(name))) + return pwent; #ifndef NO_REAL_USER_NAME - for (i = 0; i < len; i++) - name[i] = tolower(name[i]); - - setpwent(); - while ((pwent = getpwent())) { - if ((user = strchr(pwent->pw_gecos, ','))) - *user = '\0'; - user = pwent->pw_gecos; - - /* check against both the gecos and the name fields. the user - * might have just used a different capitalization. */ - if ((strncasecmp(user, name, len) == 0) || - (strncasecmp(pwent->pw_name, name, len) == 0)) { - strncpy(name, pwent->pw_name, len); - name[len - 1] = '\0'; - break; + for (i = 0; i < len; i++) + name[i] = tolower(name[i]); + + setpwent(); + while ((pwent = getpwent())) { + if ((user = strchr(pwent->pw_gecos, ','))) + *user = '\0'; + user = pwent->pw_gecos; + + /* check against both the gecos and the name fields. the user + * might have just used a different capitalization. */ + if ((strncasecmp(user, name, len) == 0) || + (strncasecmp(pwent->pw_name, name, len) == 0)) { + strncpy(name, pwent->pw_name, len); + name[len - 1] = '\0'; + break; + } } - } - endpwent(); + endpwent(); #endif /* ! NO_REAL_USER_NAME */ - /* os x server doesn't keep anything useful if we do getpwent */ - return pwent ? getpwnam(name) : NULL; + /* os x server doesn't keep anything useful if we do getpwent */ + return pwent ? getpwnam(name) : NULL; } int uam_checkuser(const struct passwd *pwd) { - const char *p; + const char *p; - if (!pwd || !pwd->pw_shell || (*pwd->pw_shell == '\0')) - return -1; + if (!pwd || !pwd->pw_shell || (*pwd->pw_shell == '\0')) + return -1; - while ((p = getusershell())) { - if ( strcmp( p, pwd->pw_shell ) == 0 ) - break; - } - endusershell(); + while ((p = getusershell())) { + if ( strcmp( p, pwd->pw_shell ) == 0 ) + break; + } + endusershell(); #ifndef DISABLE_SHELLCHECK - if (!p) { - syslog( LOG_INFO, "illegal shell %s for %s", pwd->pw_shell, pwd->pw_name); - return -1; - } + if (!p) { + syslog( LOG_INFO, "illegal shell %s for %s", pwd->pw_shell, pwd->pw_name); + return -1; + } #endif /* DISABLE_SHELLCHECK */ - return 0; + return 0; } /* afp-specific functions */ int uam_afpserver_option(void *private, const int what, void *option, - int *len) + int *len) { - AFPObj *obj = private; - char **buf = (char **) option; /* most of the options are this */ - int32_t result; - int fd; - - if (!obj || !option) - return -1; - - switch (what) { - case UAM_OPTION_USERNAME: - *buf = (void *) obj->username; - if (len) - *len = sizeof(obj->username) - 1; - break; - - case UAM_OPTION_GUEST: - *buf = (void *) obj->options.guest; - if (len) - *len = strlen(obj->options.guest); - break; - - case UAM_OPTION_PASSWDOPT: - if (!len) - return -1; - - switch (*len) { - case UAM_PASSWD_FILENAME: - *buf = (void *) obj->options.passwdfile; - *len = strlen(obj->options.passwdfile); - break; - - case UAM_PASSWD_MINLENGTH: - *((int *) option) = obj->options.passwdminlen; - *len = sizeof(obj->options.passwdminlen); - break; - - case UAM_PASSWD_MAXFAIL: - *((int *) option) = obj->options.loginmaxfail; - *len = sizeof(obj->options.loginmaxfail); - break; - - case UAM_PASSWD_EXPIRETIME: /* not implemented */ +AFPObj *obj = private; + char **buf = (char **) option; /* most of the options are this */ + int32_t result; + int fd; + + if (!obj || !option) + return -1; + + switch (what) { + case UAM_OPTION_USERNAME: + *buf = (void *) obj->username; + if (len) + *len = sizeof(obj->username) - 1; + break; + + case UAM_OPTION_GUEST: + *buf = (void *) obj->options.guest; + if (len) + *len = strlen(obj->options.guest); + break; + + case UAM_OPTION_PASSWDOPT: + if (!len) + return -1; + + switch (*len) { + case UAM_PASSWD_FILENAME: + *buf = (void *) obj->options.passwdfile; + *len = strlen(obj->options.passwdfile); + break; + + case UAM_PASSWD_MINLENGTH: + *((int *) option) = obj->options.passwdminlen; + *len = sizeof(obj->options.passwdminlen); + break; + + case UAM_PASSWD_MAXFAIL: + *((int *) option) = obj->options.loginmaxfail; + *len = sizeof(obj->options.loginmaxfail); + break; + + case UAM_PASSWD_EXPIRETIME: /* not implemented */ + default: + return -1; + break; + } + break; + + case UAM_OPTION_SIGNATURE: + *buf = (void *) (((AFPConfig *)obj->config)->signature); + if (len) + *len = 16; + break; + + case UAM_OPTION_RANDNUM: /* returns a random number in 4-byte units. */ + if (!len || (*len < 0) || (*len % sizeof(result))) + return -1; + + /* construct a random number */ + if ((fd = open("/dev/urandom", O_RDONLY)) < 0) { + struct timeval tv; + struct timezone tz; + char *randnum = (char *) option; + int i; + + if (gettimeofday(&tv, &tz) < 0) + return -1; + srandom(tv.tv_sec + (unsigned long) obj + (unsigned long) obj->handle); + for (i = 0; i < *len; i += sizeof(result)) { + result = random(); + memcpy(randnum + i, &result, sizeof(result)); + } + } else { + result = read(fd, option, *len); + close(fd); + if (result < 0) + return -1; + } + break; + + case UAM_OPTION_HOSTNAME: + *buf = (void *) obj->options.hostname; + if (len) + *len = strlen(obj->options.hostname); + break; + + case UAM_OPTION_PROTOCOL: + *buf = (void *) obj->proto; + break; + case UAM_OPTION_CLIENTNAME: + { + struct DSI *dsi = obj->handle; + struct hostent *hp; + + hp = gethostbyaddr( (char *) &dsi->client.sin_addr, + sizeof( struct in_addr ), + dsi->client.sin_family ); + if( hp ) + *buf = (void *) hp->h_name; + else + *buf = (void *) inet_ntoa( dsi->client.sin_addr ); + } + break; + case UAM_OPTION_COOKIE: + /* it's up to the uam to actually store something useful here. + * this just passes back a handle to the cookie. the uam side + * needs to do something like **buf = (void *) cookie to store + * the cookie. */ + *buf = (void *) &obj->uam_cookie; + break; + default: - return -1; - break; - } - break; - - case UAM_OPTION_SIGNATURE: - *buf = (void *) (((AFPConfig *)obj->config)->signature); - if (len) - *len = 16; - break; - - case UAM_OPTION_RANDNUM: /* returns a random number in 4-byte units. */ - if (!len || (*len < 0) || (*len % sizeof(result))) - return -1; - - /* construct a random number */ - if ((fd = open("/dev/urandom", O_RDONLY)) < 0) { - struct timeval tv; - struct timezone tz; - char *randnum = (char *) option; - int i; - - if (gettimeofday(&tv, &tz) < 0) - return -1; - srandom(tv.tv_sec + (unsigned long) obj + (unsigned long) obj->handle); - for (i = 0; i < *len; i += sizeof(result)) { - result = random(); - memcpy(randnum + i, &result, sizeof(result)); - } - } else { - result = read(fd, option, *len); - close(fd); - if (result < 0) - return -1; + return -1; + break; } - break; - - case UAM_OPTION_HOSTNAME: - *buf = (void *) obj->options.hostname; - if (len) - *len = strlen(obj->options.hostname); - break; - - case UAM_OPTION_PROTOCOL: - *buf = (void *) obj->proto; - break; - case UAM_OPTION_CLIENTNAME: - { - struct DSI *dsi = obj->handle; - struct hostent *hp; - - hp = gethostbyaddr( (char *) &dsi->client.sin_addr, - sizeof( struct in_addr ), - dsi->client.sin_family ); - if( hp ) - *buf = (void *) hp->h_name; - else - *buf = (void *) inet_ntoa( dsi->client.sin_addr ); - } - break; - case UAM_OPTION_COOKIE: - /* it's up to the uam to actually store something useful here. - * this just passes back a handle to the cookie. the uam side - * needs to do something like **buf = (void *) cookie to store - * the cookie. */ - *buf = (void *) &obj->uam_cookie; - break; - - default: - return -1; - break; - } - - return 0; + + return 0; } -/* if we need to maintain a connection, this is how we do it. +/* if we need to maintain a connection, this is how we do it. * because an action pointer gets passed in, we can stream * DSI connections */ -int uam_afp_read(void *handle, char *buf, int *buflen, - int (*action)(void *, void *, const int)) +int uam_afp_read(void *handle, char *buf, int *buflen, + int (*action)(void *, void *, const int)) { - AFPObj *obj = handle; - int len; + AFPObj *obj = handle; + int len; - if (!obj) - return AFPERR_PARAM; + if (!obj) + return AFPERR_PARAM; - switch (obj->proto) { + switch (obj->proto) { case AFPPROTO_ASP: - if ((len = asp_wrtcont(obj->handle, buf, buflen )) < 0) - goto uam_afp_read_err; - return action(handle, buf, *buflen); - break; + if ((len = asp_wrtcont(obj->handle, buf, buflen )) < 0) + goto uam_afp_read_err; + return action(handle, buf, *buflen); + break; case AFPPROTO_DSI: - len = dsi_writeinit(obj->handle, buf, *buflen); - if (!len || ((len = action(handle, buf, len)) < 0)) { - dsi_writeflush(obj->handle); - goto uam_afp_read_err; - } - - while ((len = (dsi_write(obj->handle, buf, *buflen)))) { - if ((len = action(handle, buf, len)) < 0) { - dsi_writeflush(obj->handle); - goto uam_afp_read_err; - } - } - break; - } - return 0; + len = dsi_writeinit(obj->handle, buf, *buflen); + if (!len || ((len = action(handle, buf, len)) < 0)) { + dsi_writeflush(obj->handle); + goto uam_afp_read_err; + } + + while ((len = (dsi_write(obj->handle, buf, *buflen)))) { + if ((len = action(handle, buf, len)) < 0) { + dsi_writeflush(obj->handle); + goto uam_afp_read_err; + } + } + break; + } + return 0; uam_afp_read_err: - *buflen = 0; - return len; + *buflen = 0; + return len; } #ifdef TRU64 @@ -433,5 +433,5 @@ void uam_afp_getcmdline( int *ac, char ***av ) /* --- papd-specific functions (just placeholders) --- */ void append(void *pf, char *data, int len) { - return; + return; } diff --git a/etc/afpd/uam_auth.h b/etc/afpd/uam_auth.h index 6e5b3c29..2026ae44 100644 --- a/etc/afpd/uam_auth.h +++ b/etc/afpd/uam_auth.h @@ -1,5 +1,5 @@ /* - * $Id: uam_auth.h,v 1.2 2001-06-20 18:33:04 rufustfirefly Exp $ + * $Id: uam_auth.h,v 1.2.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu) * All Rights Reserved. See COPYRIGHT. @@ -17,27 +17,27 @@ #include "globals.h" struct uam_mod { - void *uam_module; - struct uam_export *uam_fcn; - struct uam_mod *uam_prev, *uam_next; + void *uam_module; + struct uam_export *uam_fcn; + struct uam_mod *uam_prev, *uam_next; }; struct uam_obj { - const char *uam_name; /* authentication method */ - char *uam_path; /* where it's located */ - int uam_count; - union { - struct { - int (*login) __P((void *, struct passwd **, - char *, int, char *, int *)); - int (*logincont) __P((void *, struct passwd **, char *, - int, char *, int *)); - void (*logout) __P((void)); - } uam_login; - int (*uam_changepw) __P((void *, char *, struct passwd *, char *, - int, char *, int *)); - } u; - struct uam_obj *uam_prev, *uam_next; + const char *uam_name; /* authentication method */ + char *uam_path; /* where it's located */ + int uam_count; + union { + struct { + int (*login) __P((void *, struct passwd **, + char *, int, char *, int *)); + int (*logincont) __P((void *, struct passwd **, char *, + int, char *, int *)); + void (*logout) __P((void)); + } uam_login; + int (*uam_changepw) __P((void *, char *, struct passwd *, char *, + int, char *, int *)); + } u; + struct uam_obj *uam_prev, *uam_next; }; #define uam_attach(a, b) do { \ diff --git a/etc/afpd/uid.c b/etc/afpd/uid.c index 9287d69f..3758f4d5 100644 --- a/etc/afpd/uid.c +++ b/etc/afpd/uid.c @@ -1,5 +1,5 @@ /* - * $Id: uid.c,v 1.5 2001-06-27 14:53:16 rufustfirefly Exp $ + * $Id: uid.c,v 1.5.2.1 2001-12-03 05:01:04 jmarcus Exp $ * code: jeff@univrel.pr.uconn.edu * * These functions are abstracted here, so that all calls for resolving @@ -28,89 +28,89 @@ #endif /* HAVE_UNISTD_H */ void save_uidgid ( pair ) - uidgidset **pair; +uidgidset **pair; { - /* allocate the memory */ - pair = malloc ( sizeof ( uidgidset ) ); + /* allocate the memory */ + pair = malloc ( sizeof ( uidgidset ) ); - /* then assign the values */ - (*pair)->uid = geteuid (); - (*pair)->gid = getegid (); + /* then assign the values */ + (*pair)->uid = geteuid (); + (*pair)->gid = getegid (); } /* end function void save_uidgid ( pair ) */ void restore_uidgid ( pair ) - uidgidset **pair; +uidgidset **pair; { - if ( seteuid ( (*pair)->uid ) < 0 ) - syslog ( LOG_ERR, "restore_uidgid: unable to seteuid '%s': %m", - (*pair)->uid ); - if ( setegid ( (*pair)->gid ) < 0 ) - syslog ( LOG_ERR, "restore_uidgid: unable to setegid '%s': %m", - (*pair)->gid ); + if ( seteuid ( (*pair)->uid ) < 0 ) + syslog ( LOG_ERR, "restore_uidgid: unable to seteuid '%s': %m", + (*pair)->uid ); + if ( setegid ( (*pair)->gid ) < 0 ) + syslog ( LOG_ERR, "restore_uidgid: unable to setegid '%s': %m", + (*pair)->gid ); } /* end function void restore_uidgid ( pair ) */ void set_uidgid ( this_volume ) - const struct vol *this_volume; +const struct vol *this_volume; { - int uid, gid; /* derived ones go in here */ - - /* check to see if we have to switch users */ - if ( uid = user_to_uid ( (this_volume)->v_forceuid ) ) { - if ( seteuid ( uid ) < 0 ) - syslog ( LOG_ERR, "set_uidgid: unable to seteuid '%s': %m", - (this_volume)->v_forceuid ); - } /* end of checking for (this_volume)->v_forceuid */ - - /* check to see if we have to switch groups */ - if ( gid = group_to_gid ( (this_volume)->v_forcegid ) ) { - if ( seteuid ( gid ) < 0 ) - syslog ( LOG_ERR, "set_uidgid: unable to setegid '%s': %m", - (this_volume)->v_forcegid ); - } /* end of checking for (this_volume)->v_forcegid */ + int uid, gid; /* derived ones go in here */ + + /* check to see if we have to switch users */ + if ( uid = user_to_uid ( (this_volume)->v_forceuid ) ) { + if ( seteuid ( uid ) < 0 ) + syslog ( LOG_ERR, "set_uidgid: unable to seteuid '%s': %m", + (this_volume)->v_forceuid ); + } /* end of checking for (this_volume)->v_forceuid */ + + /* check to see if we have to switch groups */ + if ( gid = group_to_gid ( (this_volume)->v_forcegid ) ) { + if ( seteuid ( gid ) < 0 ) + syslog ( LOG_ERR, "set_uidgid: unable to setegid '%s': %m", + (this_volume)->v_forcegid ); + } /* end of checking for (this_volume)->v_forcegid */ } /* end function void set_uidgid ( username, group ) */ int user_to_uid ( username ) - char *username; +char *username; { - struct passwd *this_passwd; + struct passwd *this_passwd; - /* free memory for pointer */ - this_passwd = malloc ( sizeof ( struct passwd ) ); + /* free memory for pointer */ + this_passwd = malloc ( sizeof ( struct passwd ) ); - /* check for anything */ - if ( strlen ( username ) < 1 ) return 0; + /* check for anything */ + if ( strlen ( username ) < 1 ) return 0; - /* grab the /etc/passwd record relating to username */ - this_passwd = getpwnam ( username ); + /* grab the /etc/passwd record relating to username */ + this_passwd = getpwnam ( username ); - /* return false if there is no structure returned */ - if (this_passwd == NULL) return 0; + /* return false if there is no structure returned */ + if (this_passwd == NULL) return 0; - /* return proper uid */ - return this_passwd->pw_uid; + /* return proper uid */ + return this_passwd->pw_uid; } /* end function int user_to_uid ( username ) */ int group_to_gid ( group ) - char *group; +char *group; { - struct group *this_group; + struct group *this_group; - /* free memory for pointer */ - this_group = malloc ( sizeof ( struct group ) ); + /* free memory for pointer */ + this_group = malloc ( sizeof ( struct group ) ); - /* check for anything */ - if ( strlen ( group ) < 1 ) return 0; + /* check for anything */ + if ( strlen ( group ) < 1 ) return 0; - /* grab the /etc/groups record relating to group */ - this_group = getgrnam ( group ); + /* grab the /etc/groups record relating to group */ + this_group = getgrnam ( group ); - /* return false if there is no structure returned */ - if (this_group == NULL) return 0; + /* return false if there is no structure returned */ + if (this_group == NULL) return 0; - /* return proper gid */ - return this_group->gr_gid; + /* return proper gid */ + return this_group->gr_gid; } /* end function int group_to_gid ( group ) */ diff --git a/etc/afpd/uid.h b/etc/afpd/uid.h index 859b4a55..82e527e7 100644 --- a/etc/afpd/uid.h +++ b/etc/afpd/uid.h @@ -1,5 +1,5 @@ /* - * $Id: uid.h,v 1.4 2001-08-15 01:13:25 samnoble Exp $ + * $Id: uid.h,v 1.4.2.1 2001-12-03 05:01:04 jmarcus Exp $ * code: jeff@univrel.pr.uconn.edu */ @@ -13,8 +13,8 @@ /* set up a structure for this */ typedef struct uidgidset_t { - uid_t uid; - gid_t gid; + uid_t uid; + gid_t gid; } uidgidset; /* functions to save and restore uid/gid pairs */ diff --git a/etc/afpd/unix.c b/etc/afpd/unix.c index 6546ef52..e9ec3193 100644 --- a/etc/afpd/unix.c +++ b/etc/afpd/unix.c @@ -1,5 +1,5 @@ /* - * $Id: unix.c,v 1.24 2001-10-23 13:44:37 rufustfirefly Exp $ + * $Id: unix.c,v 1.24.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -49,22 +49,22 @@ char *strchr (), *strrchr (); * Get the free space on a partition. */ int ustatfs_getvolspace( vol, bfree, btotal, bsize ) - const struct vol *vol; - VolSpace *bfree, *btotal; - u_int32_t *bsize; +const struct vol *vol; +VolSpace *bfree, *btotal; +u_int32_t *bsize; { - VolSpace maxVolSpace = (~(VolSpace)0); - + VolSpace maxVolSpace = (~(VolSpace)0); + #ifdef ultrix struct fs_data sfs; #else /*ultrix*/ struct statfs sfs; #endif /*ultrix*/ - + if ( statfs( vol->v_path, &sfs ) < 0 ) { - syslog(LOG_ERR, "ustatfs_getvolspace unable to stat %s", vol->v_path); - return( AFPERR_PARAM ); + syslog(LOG_ERR, "ustatfs_getvolspace unable to stat %s", vol->v_path); + return( AFPERR_PARAM ); } #ifdef ultrix @@ -82,11 +82,11 @@ int ustatfs_getvolspace( vol, bfree, btotal, bsize ) } #ifdef ultrix - *btotal = (VolSpace) - ( sfs.fd_req.btot - ( sfs.fd_req.bfree - sfs.fd_req.bfreen )); + *btotal = (VolSpace) + ( sfs.fd_req.btot - ( sfs.fd_req.bfree - sfs.fd_req.bfreen )); #else /* !ultrix */ - *btotal = (VolSpace) - ( sfs.f_blocks - ( sfs.f_bfree - sfs.f_bavail )); + *btotal = (VolSpace) + ( sfs.f_blocks - ( sfs.f_bfree - sfs.f_bavail )); #endif /* ultrix */ /* see similar block above comments */ @@ -100,7 +100,7 @@ int ustatfs_getvolspace( vol, bfree, btotal, bsize ) } static __inline__ int utombits( bits ) - mode_t bits; +mode_t bits; { int mbits; @@ -108,15 +108,15 @@ static __inline__ int utombits( bits ) mbits |= ( bits & ( S_IREAD >> 6 )) ? (AR_UREAD | AR_USEARCH) : 0; mbits |= ( bits & ( S_IWRITE >> 6 )) ? AR_UWRITE : 0; -/* Do we really need this? - mbits |= ( bits & ( S_IEXEC >> 6) ) ? AR_USEARCH : 0; */ + /* Do we really need this? + mbits |= ( bits & ( S_IEXEC >> 6) ) ? AR_USEARCH : 0; */ return( mbits ); } void utommode( stat, ma ) - struct stat *stat; - struct maccess *ma; +struct stat *stat; +struct maccess *ma; { mode_t mode; @@ -131,11 +131,11 @@ void utommode( stat, ma ) ma->ma_owner = utombits( mode ); if ( (uuid == stat->st_uid) || (uuid == 0)) { - ma->ma_user = ma->ma_owner | AR_UOWN; + ma->ma_user = ma->ma_owner | AR_UOWN; } else if ( gmem( stat->st_gid )) { - ma->ma_user = ma->ma_group; + ma->ma_user = ma->ma_group; } else { - ma->ma_user = ma->ma_world; + ma->ma_user = ma->ma_world; } /* @@ -144,7 +144,7 @@ void utommode( stat, ma ) * only write permission. What were the things? */ if ( ma->ma_user & AR_UWRITE ) { - ma->ma_user |= AR_UOWN; + ma->ma_user |= AR_UOWN; } } @@ -154,48 +154,48 @@ void utommode( stat, ma ) * estimate permission, a la mdw. */ void accessmode( path, ma, dir ) - char *path; - struct maccess *ma; - struct dir *dir; +char *path; +struct maccess *ma; +struct dir *dir; { if ( access( path, R_OK|W_OK|X_OK ) == 0 ) { - ma->ma_user = AR_UREAD|AR_UWRITE|AR_USEARCH|AR_UOWN; - ma->ma_owner = AR_UREAD|AR_UWRITE|AR_USEARCH; + ma->ma_user = AR_UREAD|AR_UWRITE|AR_USEARCH|AR_UOWN; + ma->ma_owner = AR_UREAD|AR_UWRITE|AR_USEARCH; } else if ( access( path, R_OK|X_OK ) == 0 ) { - ma->ma_user = AR_UREAD|AR_USEARCH; - ma->ma_owner = AR_UREAD|AR_USEARCH; + ma->ma_user = AR_UREAD|AR_USEARCH; + ma->ma_owner = AR_UREAD|AR_USEARCH; } else { - ma->ma_user = ma->ma_owner = 0; - if ( access( path, R_OK ) == 0 ) { - ma->ma_user |= AR_UREAD; - ma->ma_owner |= AR_UREAD; - } - if ( access( path, X_OK ) == 0 ) { - ma->ma_user |= AR_USEARCH; - ma->ma_owner |= AR_USEARCH; - } - if ( access( path, W_OK ) == 0 ) { - ma->ma_user |= AR_UWRITE|AR_UOWN; - ma->ma_owner |= AR_UWRITE; - } + ma->ma_user = ma->ma_owner = 0; + if ( access( path, R_OK ) == 0 ) { + ma->ma_user |= AR_UREAD; + ma->ma_owner |= AR_UREAD; + } + if ( access( path, X_OK ) == 0 ) { + ma->ma_user |= AR_USEARCH; + ma->ma_owner |= AR_USEARCH; + } + if ( access( path, W_OK ) == 0 ) { + ma->ma_user |= AR_UWRITE|AR_UOWN; + ma->ma_owner |= AR_UWRITE; + } } } int gmem( gid ) - const gid_t gid; +const gid_t gid; { int i; for ( i = 0; i < ngroups; i++ ) { - if ( groups[ i ] == gid ) { - return( 1 ); - } + if ( groups[ i ] == gid ) { + return( 1 ); + } } return( 0 ); } static __inline__ mode_t mtoubits( bits ) - u_char bits; +u_char bits; { mode_t mode; @@ -203,14 +203,14 @@ static __inline__ mode_t mtoubits( bits ) mode |= ( bits & AR_UREAD ) ? ( (S_IREAD | S_IEXEC) >> 6 ) : 0; mode |= ( bits & AR_UWRITE ) ? ( (S_IWRITE | S_IEXEC) >> 6 ) : 0; -/* I don't think there's a way to set the SEARCH bit by itself on a Mac - mode |= ( bits & AR_USEARCH ) ? ( S_IEXEC >> 6 ) : 0; */ + /* I don't think there's a way to set the SEARCH bit by itself on a Mac + mode |= ( bits & AR_USEARCH ) ? ( S_IEXEC >> 6 ) : 0; */ return( mode ); } mode_t mtoumode( ma ) - struct maccess *ma; +struct maccess *ma; { mode_t mode; @@ -227,57 +227,57 @@ mode_t mtoumode( ma ) } inline int stickydirmode(name, mode, dropbox) - char * name; - const mode_t mode; - const int dropbox; +char * name; +const mode_t mode; +const int dropbox; { - int retval; + int retval; #ifdef DROPKLUDGE - int uid; + int uid; #endif /* DROPKLUDGE */ - -/* Turn on the sticky bit if this is a drop box, also turn off the setgid bit */ - retval=0; + + /* Turn on the sticky bit if this is a drop box, also turn off the setgid bit */ + retval=0; #ifdef DROPKLUDGE - if (dropbox) { - if (mode & S_IWOTH) { - if (mode & S_IROTH); - else { /* if S_IWOTH and not S_IROTH */ - uid=geteuid(); - if ( seteuid(0) < 0) { - syslog( LOG_ERR, "stickydirmode: unable to seteuid root: %m"); - } - if ( retval=chmod( name, ( (DIRBITS | mode | S_ISVTX) & 0777 & ~default_options.umask) ) < 0) { - syslog( LOG_ERR, "stickydirmode: chmod \"%s\": %m", name ); - return(AFPERR_ACCESS); - } else { + if (dropbox) { + if (mode & S_IWOTH) { + if (mode & S_IROTH); + else { /* if S_IWOTH and not S_IROTH */ + uid=geteuid(); + if ( seteuid(0) < 0) { + syslog( LOG_ERR, "stickydirmode: unable to seteuid root: %m"); + } + if ( retval=chmod( name, ( (DIRBITS | mode | S_ISVTX) & 0777 & ~default_options.umask) ) < 0) { + syslog( LOG_ERR, "stickydirmode: chmod \"%s\": %m", name ); + return(AFPERR_ACCESS); + } else { #ifdef DEBUG - syslog( LOG_INFO, "stickydirmode: (debug) chmod \"%s\": %m", name ); + syslog( LOG_INFO, "stickydirmode: (debug) chmod \"%s\": %m", name ); #endif /* DEBUG */ - seteuid(uid); - } /* end getting retval */ - } /* end if not & S_IROTH */ - } else { /* end if S_IWOTH and not S_IROTH */ + seteuid(uid); + } /* end getting retval */ + } /* end if not & S_IROTH */ + } else { /* end if S_IWOTH and not S_IROTH */ #endif /* DROPKLUDGE */ - /* - * Ignore EPERM errors: We may be dealing with a directory that is - * group writable, in which case chmod will fail. - */ - if ( (chmod( name, (DIRBITS | mode) & 0777 & ~default_options.umask ) < 0) && errno != EPERM) { - syslog( LOG_ERR, "stickydirmode: chmod \"%s\": %s", - name, strerror(errno) ); - retval = -1; - } + /* + * Ignore EPERM errors: We may be dealing with a directory that is + * group writable, in which case chmod will fail. + */ + if ( (chmod( name, (DIRBITS | mode) & 0777 & ~default_options.umask ) < 0) && errno != EPERM) { + syslog( LOG_ERR, "stickydirmode: chmod \"%s\": %s", + name, strerror(errno) ); + retval = -1; + } #ifdef DROPKLUDGE - } /* end if not mode */ - } /* end checking for "dropbox" */ + } /* end if not mode */ + } /* end checking for "dropbox" */ #endif /* DROPKLUDGE */ - return retval; + return retval; } int setdeskmode( mode ) - const mode_t mode; +const mode_t mode; { char wd[ MAXPATHLEN + 1]; struct stat st; @@ -286,76 +286,76 @@ int setdeskmode( mode ) DIR *desk, *sub; if ( getcwd( wd , MAXPATHLEN) == NULL ) { - return( -1 ); + return( -1 ); } if ( chdir( ".AppleDesktop" ) < 0 ) { - return( -1 ); + return( -1 ); } if (( desk = opendir( "." )) == NULL ) { - if ( chdir( wd ) < 0 ) { - syslog( LOG_ERR, "setdeskmode: chdir %s: %s", wd, strerror(errno) ); - } - return( -1 ); + if ( chdir( wd ) < 0 ) { + syslog( LOG_ERR, "setdeskmode: chdir %s: %s", wd, strerror(errno) ); + } + return( -1 ); } for ( deskp = readdir( desk ); deskp != NULL; deskp = readdir( desk )) { - if ( strcmp( deskp->d_name, "." ) == 0 || - strcmp( deskp->d_name, ".." ) == 0 || strlen( deskp->d_name ) > 2 ) { - continue; - } - strcpy( modbuf, deskp->d_name ); - strcat( modbuf, "/" ); - m = strchr( modbuf, '\0' ); - if (( sub = opendir( deskp->d_name )) == NULL ) { - continue; - } - for ( subp = readdir( sub ); subp != NULL; subp = readdir( sub )) { - if ( strcmp( subp->d_name, "." ) == 0 || - strcmp( subp->d_name, ".." ) == 0 ) { - continue; - } - *m = '\0'; - strcat( modbuf, subp->d_name ); - /* XXX: need to preserve special modes */ - if (stat(modbuf, &st) < 0) { - syslog( LOG_ERR, "setdeskmode: stat %s: %s", - modbuf, strerror(errno) ); - continue; - } - - if (S_ISDIR(st.st_mode)) { - if ( chmod( modbuf, (DIRBITS | mode) & 0777 & ~default_options.umask ) < 0 && errno != EPERM ) { - syslog( LOG_ERR, "setdeskmode: chmod %s: %s", - modbuf, strerror(errno) ); - } - } else if ( chmod( modbuf, mode & 0777 & ~default_options.umask ) < 0 && errno != EPERM ) { - syslog( LOG_ERR, "setdeskmode: chmod %s: %s", - modbuf, strerror(errno) ); - } - - } - closedir( sub ); - /* XXX: need to preserve special modes */ - if ( chmod( deskp->d_name, (DIRBITS | mode) & 0777 & ~default_options.umask ) < 0 && errno != EPERM ) { - syslog( LOG_ERR, "setdeskmode: chmod %s: %s", - deskp->d_name, strerror(errno) ); - } + if ( strcmp( deskp->d_name, "." ) == 0 || + strcmp( deskp->d_name, ".." ) == 0 || strlen( deskp->d_name ) > 2 ) { + continue; + } + strcpy( modbuf, deskp->d_name ); + strcat( modbuf, "/" ); + m = strchr( modbuf, '\0' ); + if (( sub = opendir( deskp->d_name )) == NULL ) { + continue; + } + for ( subp = readdir( sub ); subp != NULL; subp = readdir( sub )) { + if ( strcmp( subp->d_name, "." ) == 0 || + strcmp( subp->d_name, ".." ) == 0 ) { + continue; + } + *m = '\0'; + strcat( modbuf, subp->d_name ); + /* XXX: need to preserve special modes */ + if (stat(modbuf, &st) < 0) { + syslog( LOG_ERR, "setdeskmode: stat %s: %s", + modbuf, strerror(errno) ); + continue; + } + + if (S_ISDIR(st.st_mode)) { + if ( chmod( modbuf, (DIRBITS | mode) & 0777 & ~default_options.umask ) < 0 && errno != EPERM ) { + syslog( LOG_ERR, "setdeskmode: chmod %s: %s", + modbuf, strerror(errno) ); + } + } else if ( chmod( modbuf, mode & 0777 & ~default_options.umask ) < 0 && errno != EPERM ) { + syslog( LOG_ERR, "setdeskmode: chmod %s: %s", + modbuf, strerror(errno) ); + } + + } + closedir( sub ); + /* XXX: need to preserve special modes */ + if ( chmod( deskp->d_name, (DIRBITS | mode) & 0777 & ~default_options.umask ) < 0 && errno != EPERM ) { + syslog( LOG_ERR, "setdeskmode: chmod %s: %s", + deskp->d_name, strerror(errno) ); + } } closedir( desk ); if ( chdir( wd ) < 0 ) { - syslog( LOG_ERR, "setdeskmode: chdir %s: %s", wd, strerror(errno) ); - return -1; + syslog( LOG_ERR, "setdeskmode: chdir %s: %s", wd, strerror(errno) ); + return -1; } /* XXX: need to preserve special modes */ if ( chmod( ".AppleDesktop", (DIRBITS | mode) & 0777 & ~default_options.umask ) < 0 && errno != EPERM ) { - syslog( LOG_ERR, "setdeskmode: chmod .AppleDesktop: %s", strerror(errno) ); + syslog( LOG_ERR, "setdeskmode: chmod .AppleDesktop: %s", strerror(errno) ); } return( 0 ); } int setdirmode( mode, noadouble, dropbox ) - const mode_t mode; - const int noadouble; - const int dropbox; +const mode_t mode; +const int noadouble; +const int dropbox; { char buf[ MAXPATHLEN + 1]; struct stat st; @@ -364,75 +364,75 @@ int setdirmode( mode, noadouble, dropbox ) DIR *dir; if (( dir = opendir( "." )) == NULL ) { - syslog( LOG_ERR, "setdirmode: opendir .: %s", strerror(errno) ); - return( -1 ); + syslog( LOG_ERR, "setdirmode: opendir .: %s", strerror(errno) ); + return( -1 ); } for ( dirp = readdir( dir ); dirp != NULL; dirp = readdir( dir )) { - if ( *dirp->d_name == '.' ) { - continue; - } - if ( stat( dirp->d_name, &st ) < 0 ) { - syslog( LOG_ERR, "setdirmode: stat %s: %s", - dirp->d_name, strerror(errno) ); - continue; - } - - if (S_ISREG(st.st_mode)) { - /* XXX: need to preserve special modes */ - if (S_ISDIR(st.st_mode)) { - if (stickydirmode(dirp->d_name, DIRBITS | mode, dropbox) < 0) - return (-1); - } else if (stickydirmode(dirp->d_name, mode, dropbox) < 0) - return (-1); - } + if ( *dirp->d_name == '.' ) { + continue; + } + if ( stat( dirp->d_name, &st ) < 0 ) { + syslog( LOG_ERR, "setdirmode: stat %s: %s", + dirp->d_name, strerror(errno) ); + continue; + } + + if (S_ISREG(st.st_mode)) { + /* XXX: need to preserve special modes */ + if (S_ISDIR(st.st_mode)) { + if (stickydirmode(dirp->d_name, DIRBITS | mode, dropbox) < 0) + return (-1); + } else if (stickydirmode(dirp->d_name, mode, dropbox) < 0) + return (-1); + } } closedir( dir ); if (( dir = opendir( ".AppleDouble" )) == NULL ) { if (noadouble) - goto setdirmode_noadouble; - syslog( LOG_ERR, "setdirmode: opendir .AppleDouble: %s", strerror(errno) ); - return( -1 ); + goto setdirmode_noadouble; + syslog( LOG_ERR, "setdirmode: opendir .AppleDouble: %s", strerror(errno) ); + return( -1 ); } strcpy( buf, ".AppleDouble" ); strcat( buf, "/" ); m = strchr( buf, '\0' ); for ( dirp = readdir( dir ); dirp != NULL; dirp = readdir( dir )) { - if ( strcmp( dirp->d_name, "." ) == 0 || - strcmp( dirp->d_name, ".." ) == 0 ) { - continue; - } - *m = '\0'; - strcat( buf, dirp->d_name ); - - if ( stat( buf, &st ) < 0 ) { - syslog( LOG_ERR, "setdirmode: stat %s: %s", buf, strerror(errno) ); - continue; - } - - if (S_ISDIR(st.st_mode)) { - stickydirmode( buf, DIRBITS | mode, dropbox ); - } else - stickydirmode( buf, mode, dropbox ); + if ( strcmp( dirp->d_name, "." ) == 0 || + strcmp( dirp->d_name, ".." ) == 0 ) { + continue; + } + *m = '\0'; + strcat( buf, dirp->d_name ); + + if ( stat( buf, &st ) < 0 ) { + syslog( LOG_ERR, "setdirmode: stat %s: %s", buf, strerror(errno) ); + continue; + } + + if (S_ISDIR(st.st_mode)) { + stickydirmode( buf, DIRBITS | mode, dropbox ); + } else + stickydirmode( buf, mode, dropbox ); } /* end for */ closedir( dir ); /* XXX: use special bits to tag directory permissions */ - + /* XXX: need to preserve special modes */ if ( stickydirmode(".AppleDouble", DIRBITS | mode, dropbox) < 0 ) - return( -1 ); + return( -1 ); setdirmode_noadouble: /* XXX: need to preserve special modes */ if ( stickydirmode(".", DIRBITS | mode, dropbox) < 0 ) - return( -1 ); + return( -1 ); return( 0 ); } int setdeskowner( uid, gid ) - const uid_t uid; - const gid_t gid; +const uid_t uid; +const gid_t gid; { char wd[ MAXPATHLEN + 1]; char modbuf[12 + 1], *m; @@ -440,57 +440,57 @@ int setdeskowner( uid, gid ) DIR *desk, *sub; if ( getcwd( wd, MAXPATHLEN ) == NULL ) { - return( -1 ); + return( -1 ); } if ( chdir( ".AppleDesktop" ) < 0 ) { - return( -1 ); + return( -1 ); } if (( desk = opendir( "." )) == NULL ) { - if ( chdir( wd ) < 0 ) { - syslog( LOG_ERR, "setdeskowner: chdir %s: %s", wd, strerror(errno) ); - } - return( -1 ); + if ( chdir( wd ) < 0 ) { + syslog( LOG_ERR, "setdeskowner: chdir %s: %s", wd, strerror(errno) ); + } + return( -1 ); } for ( deskp = readdir( desk ); deskp != NULL; deskp = readdir( desk )) { - if ( strcmp( deskp->d_name, "." ) == 0 || - strcmp( deskp->d_name, ".." ) == 0 || - strlen( deskp->d_name ) > 2 ) { - continue; - } - strcpy( modbuf, deskp->d_name ); - strcat( modbuf, "/" ); - m = strchr( modbuf, '\0' ); - if (( sub = opendir( deskp->d_name )) == NULL ) { - continue; - } - for ( subp = readdir( sub ); subp != NULL; subp = readdir( sub )) { - if ( strcmp( subp->d_name, "." ) == 0 || - strcmp( subp->d_name, ".." ) == 0 ) { - continue; - } - *m = '\0'; - strcat( modbuf, subp->d_name ); - /* XXX: add special any uid, ignore group bits */ - if ( chown( modbuf, uid, gid ) < 0 && errno != EPERM ) { - syslog( LOG_ERR, "setdeskown: chown %s: %s", - modbuf, strerror(errno) ); - } - } - closedir( sub ); - /* XXX: add special any uid, ignore group bits */ - if ( chown( deskp->d_name, uid, gid ) < 0 && errno != EPERM ) { - syslog( LOG_ERR, "setdeskowner: chown %s: %s", - deskp->d_name, strerror(errno) ); - } + if ( strcmp( deskp->d_name, "." ) == 0 || + strcmp( deskp->d_name, ".." ) == 0 || + strlen( deskp->d_name ) > 2 ) { + continue; + } + strcpy( modbuf, deskp->d_name ); + strcat( modbuf, "/" ); + m = strchr( modbuf, '\0' ); + if (( sub = opendir( deskp->d_name )) == NULL ) { + continue; + } + for ( subp = readdir( sub ); subp != NULL; subp = readdir( sub )) { + if ( strcmp( subp->d_name, "." ) == 0 || + strcmp( subp->d_name, ".." ) == 0 ) { + continue; + } + *m = '\0'; + strcat( modbuf, subp->d_name ); + /* XXX: add special any uid, ignore group bits */ + if ( chown( modbuf, uid, gid ) < 0 && errno != EPERM ) { + syslog( LOG_ERR, "setdeskown: chown %s: %s", + modbuf, strerror(errno) ); + } + } + closedir( sub ); + /* XXX: add special any uid, ignore group bits */ + if ( chown( deskp->d_name, uid, gid ) < 0 && errno != EPERM ) { + syslog( LOG_ERR, "setdeskowner: chown %s: %s", + deskp->d_name, strerror(errno) ); + } } closedir( desk ); if ( chdir( wd ) < 0 ) { - syslog( LOG_ERR, "setdeskowner: chdir %s: %s", wd, strerror(errno) ); - return -1; + syslog( LOG_ERR, "setdeskowner: chdir %s: %s", wd, strerror(errno) ); + return -1; } if ( chown( ".AppleDesktop", uid, gid ) < 0 && errno != EPERM ) { - syslog( LOG_ERR, "setdeskowner: chown .AppleDesktop: %s", - strerror(errno) ); + syslog( LOG_ERR, "setdeskowner: chown .AppleDesktop: %s", + strerror(errno) ); } return( 0 ); } @@ -501,9 +501,9 @@ int setdeskowner( uid, gid ) * into the unix permission scheme. we can get around this by * co-opting some bits. */ int setdirowner( uid, gid, noadouble ) - const uid_t uid; - const gid_t gid; - const int noadouble; +const uid_t uid; +const gid_t gid; +const int noadouble; { char buf[ MAXPATHLEN + 1]; struct stat st; @@ -512,46 +512,46 @@ int setdirowner( uid, gid, noadouble ) DIR *dir; if (( dir = opendir( "." )) == NULL ) { - return( -1 ); + return( -1 ); } for ( dirp = readdir( dir ); dirp != NULL; dirp = readdir( dir )) { - if ( *dirp->d_name == '.' ) { - continue; - }; - if ( stat( dirp->d_name, &st ) < 0 ) { - syslog( LOG_ERR, "setdirowner: stat %s: %s", - dirp->d_name, strerror(errno) ); - continue; - } - if (( st.st_mode & S_IFMT ) == S_IFREG ) { - if ( chown( dirp->d_name, uid, gid ) < 0 && errno != EPERM ) { - syslog( LOG_DEBUG, "setdirowner: chown %s: %s", - dirp->d_name, strerror(errno) ); - /* return ( -1 ); Sometimes this is okay */ - } - } + if ( *dirp->d_name == '.' ) { + continue; + }; + if ( stat( dirp->d_name, &st ) < 0 ) { + syslog( LOG_ERR, "setdirowner: stat %s: %s", + dirp->d_name, strerror(errno) ); + continue; + } + if (( st.st_mode & S_IFMT ) == S_IFREG ) { + if ( chown( dirp->d_name, uid, gid ) < 0 && errno != EPERM ) { + syslog( LOG_DEBUG, "setdirowner: chown %s: %s", + dirp->d_name, strerror(errno) ); + /* return ( -1 ); Sometimes this is okay */ + } + } } closedir( dir ); if (( dir = opendir( ".AppleDouble" )) == NULL ) { - if (noadouble) - goto setdirowner_noadouble; - return( -1 ); + if (noadouble) + goto setdirowner_noadouble; + return( -1 ); } strcpy( buf, ".AppleDouble" ); strcat( buf, "/" ); m = strchr( buf, '\0' ); for ( dirp = readdir( dir ); dirp != NULL; dirp = readdir( dir )) { - if ( strcmp( dirp->d_name, "." ) == 0 || - strcmp( dirp->d_name, ".." ) == 0 ) { - continue; - } - *m = '\0'; - strcat( buf, dirp->d_name ); - if ( chown( buf, uid, gid ) < 0 && errno != EPERM ) { - syslog( LOG_DEBUG, "setdirowner: chown %d/%d %s: %s", - uid, gid, buf, strerror(errno) ); - /* return ( -1 ); Sometimes this is okay */ - } + if ( strcmp( dirp->d_name, "." ) == 0 || + strcmp( dirp->d_name, ".." ) == 0 ) { + continue; + } + *m = '\0'; + strcat( buf, dirp->d_name ); + if ( chown( buf, uid, gid ) < 0 && errno != EPERM ) { + syslog( LOG_DEBUG, "setdirowner: chown %d/%d %s: %s", + uid, gid, buf, strerror(errno) ); + /* return ( -1 ); Sometimes this is okay */ + } } closedir( dir ); @@ -559,24 +559,24 @@ int setdirowner( uid, gid, noadouble ) * We cheat: we know that chown doesn't do anything. */ if ( stat( ".AppleDouble", &st ) < 0 ) { - syslog( LOG_ERR, "setdirowner: stat .AppleDouble: %s", strerror(errno) ); - return( -1 ); + syslog( LOG_ERR, "setdirowner: stat .AppleDouble: %s", strerror(errno) ); + return( -1 ); } if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && - errno != EPERM ) { - syslog( LOG_DEBUG, "setdirowner: chown %d/%d .AppleDouble: %s", - uid, gid, strerror(errno) ); - /* return ( -1 ); Sometimes this is okay */ + errno != EPERM ) { + syslog( LOG_DEBUG, "setdirowner: chown %d/%d .AppleDouble: %s", + uid, gid, strerror(errno) ); + /* return ( -1 ); Sometimes this is okay */ } setdirowner_noadouble: if ( stat( ".", &st ) < 0 ) { - return( -1 ); + return( -1 ); } if ( gid && gid != st.st_gid && chown( ".", uid, gid ) < 0 && - errno != EPERM ) { + errno != EPERM ) { syslog( LOG_DEBUG, "setdirowner: chown %d/%d .: %s", - uid, gid, strerror(errno) ); + uid, gid, strerror(errno) ); } return( 0 ); diff --git a/etc/afpd/unix.h b/etc/afpd/unix.h index fedf1357..71a2c175 100644 --- a/etc/afpd/unix.h +++ b/etc/afpd/unix.h @@ -1,5 +1,5 @@ /* - * $Id: unix.h,v 1.8 2001-10-23 13:44:37 rufustfirefly Exp $ + * $Id: unix.h,v 1.8.2.1 2001-12-03 05:01:04 jmarcus Exp $ */ #ifndef AFPD_UNIX_H @@ -85,10 +85,10 @@ typedef int mode_t; #endif /* _IBMR2 */ extern int getnfsquota __P((const struct vol *, const int, const u_int32_t, - struct dqblk *)); + struct dqblk *)); extern int uquota_getvolspace __P((const struct vol *, VolSpace *, VolSpace *, - const u_int32_t)); + const u_int32_t)); #endif /* NO_QUOTA_SUPPORT */ extern struct afp_options default_options; diff --git a/etc/afpd/volume.c b/etc/afpd/volume.c index cba8cb5c..cce2f999 100644 --- a/etc/afpd/volume.c +++ b/etc/afpd/volume.c @@ -1,5 +1,5 @@ /* - * $Id: volume.c,v 1.14 2001-11-14 21:34:37 srittau Exp $ + * $Id: volume.c,v 1.14.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -92,15 +92,15 @@ static struct extmap *extmap = NULL, *defextmap = NULL; #define VOLOPT_FLAGS 7 /* various flags */ #define VOLOPT_DBPATH 8 /* path to database */ #define VOLOPT_MAPCHARS 9 /* does mtou and utom mappings. syntax: - m and u can be double-byte hex - strings if necessary. - m=u -> map both ways - m>u -> map m to u - m map u to m - !u -> make u illegal always - ~u -> make u illegal only as the first - part of a double-byte character. - */ +m and u can be double-byte hex +strings if necessary. +m=u -> map both ways + m>u -> map m to u + m map u to m + !u -> make u illegal always + ~u -> make u illegal only as the first + part of a double-byte character. + */ #define VOLOPT_VETO 10 /* list of veto filespec */ #ifdef FORCE_UIDGID @@ -116,27 +116,27 @@ static struct extmap *extmap = NULL, *defextmap = NULL; #define VOLPASSLEN 8 #define VOLOPT_DEFAULT ":DEFAULT:" #define VOLOPT_DEFAULT_LEN 9 -struct vol_option { - char *c_value; - int i_value; -}; + struct vol_option { + char *c_value; + int i_value; + }; static __inline__ void volfree(struct vol_option *options, - const struct vol_option *save) + const struct vol_option *save) { - int i; + int i; - if (save) { - for (i = 0; i < VOLOPT_MAX; i++) { - if (options[i].c_value && (options[i].c_value != save[i].c_value)) - free(options[i].c_value); - } - } else { - for (i = 0; i < VOLOPT_MAX; i++) { - if (options[i].c_value) - free(options[i].c_value); + if (save) { + for (i = 0; i < VOLOPT_MAX; i++) { + if (options[i].c_value && (options[i].c_value != save[i].c_value)) + free(options[i].c_value); + } + } else { + for (i = 0; i < VOLOPT_MAX; i++) { + if (options[i].c_value) + free(options[i].c_value); + } } - } } @@ -152,110 +152,110 @@ static __inline__ void volfree(struct vol_option *options, * $$ -> $ */ #define is_var(a, b) (strncmp((a), (b), 2) == 0) -static void volxlate(AFPObj *obj, char *dest, int destlen, - char *src, struct passwd *pwd, char *path) +static void volxlate(AFPObj *obj, char *dest, int destlen, + char *src, struct passwd *pwd, char *path) { - char *p, *q; - int len; - - strncpy(dest, src, destlen); - if ((p = strchr(src, '$')) == NULL) /* nothing to do */ - return; - - /* first part of the path. just forward to the next variable. */ - len = MIN(p - src, destlen); - if (len > 0) { - destlen -= len; - dest += len; - } - - while (p && destlen > 0) { - /* now figure out what the variable is */ - q = NULL; - if (is_var(p, "$c")) { - if (obj->proto == AFPPROTO_ASP) { - ASP asp = obj->handle; - - len = sprintf(dest, "%u.%u", ntohs(asp->asp_sat.sat_addr.s_net), - asp->asp_sat.sat_addr.s_node); - dest += len; - destlen -= len; - - } else if (obj->proto == AFPPROTO_DSI) { - DSI *dsi = obj->handle; - - len = sprintf(dest, "%s:%u", inet_ntoa(dsi->client.sin_addr), - ntohs(dsi->client.sin_port)); - dest += len; - destlen -= len; - } - } else if (is_var(p, "$f")) { - if ((q = strchr(pwd->pw_gecos, ','))) - *q = '\0'; - q = pwd->pw_gecos; - } else if (is_var(p, "$g")) { - struct group *grp = getgrgid(pwd->pw_gid); - if (grp) - q = grp->gr_name; - } else if (is_var(p, "$h")) { - q = obj->options.hostname; - } else if (is_var(p, "$s")) { - if (obj->Obj) - q = obj->Obj; - else if (obj->options.server) { - q = obj->options.server; - } else - q = obj->options.hostname; - } else if (is_var(p, "$u")) { - q = obj->username; - } else if (is_var(p, "$v")) { - if (path) { - struct adouble ad; - - memset(&ad, 0, sizeof(ad)); - if (ad_open(path, ADFLAGS_HF, O_RDONLY, 0, &ad) < 0) - goto no_volname; - - if ((len = MIN(ad_getentrylen(&ad, ADEID_NAME), destlen)) > 0) { - memcpy(dest, ad_entry(&ad, ADEID_NAME), len); - ad_close(&ad, ADFLAGS_HF); - dest += len; - destlen -= len; - } else { - ad_close(&ad, ADFLAGS_HF); -no_volname: /* simple basename */ - if ((q = strrchr(path, '/')) == NULL) - q = path; - else if (*(q + 1) != '\0') - q++; - } - } - } else if (is_var(p, "$z")) { - q = obj->Zone; - } else if (is_var(p, "$$")) { - q = "$"; - } else - q = p; - - /* copy the stuff over. if we don't understand something that we - * should, just skip it over. */ - if (q) { - len = MIN(p == q ? 2 : strlen(q), destlen); - strncpy(dest, q, len); - dest += len; - destlen -= len; - } + char *p, *q; + int len; + + strncpy(dest, src, destlen); + if ((p = strchr(src, '$')) == NULL) /* nothing to do */ + return; - /* stuff up to next $ */ - src = p + 2; - p = strchr(src, '$'); - len = p ? MIN(p - src, destlen) : destlen; + /* first part of the path. just forward to the next variable. */ + len = MIN(p - src, destlen); if (len > 0) { - strncpy(dest, src, len); - dest += len; - destlen -= len; + destlen -= len; + dest += len; + } + + while (p && destlen > 0) { + /* now figure out what the variable is */ + q = NULL; + if (is_var(p, "$c")) { + if (obj->proto == AFPPROTO_ASP) { + ASP asp = obj->handle; + + len = sprintf(dest, "%u.%u", ntohs(asp->asp_sat.sat_addr.s_net), + asp->asp_sat.sat_addr.s_node); + dest += len; + destlen -= len; + + } else if (obj->proto == AFPPROTO_DSI) { + DSI *dsi = obj->handle; + + len = sprintf(dest, "%s:%u", inet_ntoa(dsi->client.sin_addr), + ntohs(dsi->client.sin_port)); + dest += len; + destlen -= len; + } + } else if (is_var(p, "$f")) { + if ((q = strchr(pwd->pw_gecos, ','))) + *q = '\0'; + q = pwd->pw_gecos; + } else if (is_var(p, "$g")) { + struct group *grp = getgrgid(pwd->pw_gid); + if (grp) + q = grp->gr_name; + } else if (is_var(p, "$h")) { + q = obj->options.hostname; + } else if (is_var(p, "$s")) { + if (obj->Obj) + q = obj->Obj; + else if (obj->options.server) { + q = obj->options.server; + } else + q = obj->options.hostname; + } else if (is_var(p, "$u")) { + q = obj->username; + } else if (is_var(p, "$v")) { + if (path) { + struct adouble ad; + + memset(&ad, 0, sizeof(ad)); + if (ad_open(path, ADFLAGS_HF, O_RDONLY, 0, &ad) < 0) + goto no_volname; + + if ((len = MIN(ad_getentrylen(&ad, ADEID_NAME), destlen)) > 0) { + memcpy(dest, ad_entry(&ad, ADEID_NAME), len); + ad_close(&ad, ADFLAGS_HF); + dest += len; + destlen -= len; + } else { + ad_close(&ad, ADFLAGS_HF); +no_volname: /* simple basename */ + if ((q = strrchr(path, '/')) == NULL) + q = path; + else if (*(q + 1) != '\0') + q++; + } + } + } else if (is_var(p, "$z")) { + q = obj->Zone; + } else if (is_var(p, "$$")) { + q = "$"; + } else + q = p; + + /* copy the stuff over. if we don't understand something that we + * should, just skip it over. */ + if (q) { + len = MIN(p == q ? 2 : strlen(q), destlen); + strncpy(dest, q, len); + dest += len; + destlen -= len; + } + + /* stuff up to next $ */ + src = p + 2; + p = strchr(src, '$'); + len = p ? MIN(p - src, destlen) : destlen; + if (len > 0) { + strncpy(dest, src, len); + dest += len; + destlen -= len; + } } - } } /* to make sure that val is valid, make sure to select an opt that @@ -264,149 +264,149 @@ no_volname: /* simple basename */ static __inline__ char *get_codepage_path(const char *path, const char *name) { - char *page; - int len; - - if (path) { - page = (char *) malloc((len = strlen(path)) + strlen(name) + 2); - if (page) { - strcpy(page, path); - if (path[len - 1] != '/') /* add a / */ - strcat(page, "/"); - strcat(page, name); + char *page; + int len; + + if (path) { + page = (char *) malloc((len = strlen(path)) + strlen(name) + 2); + if (page) { + strcpy(page, path); + if (path[len - 1] != '/') /* add a / */ + strcat(page, "/"); + strcat(page, name); + } + } else { + page = strdup(name); } - } else { - page = strdup(name); - } - /* debug: show which codepage directory we are using */ - syslog(LOG_DEBUG, "using codepage directory: %s", page); + /* debug: show which codepage directory we are using */ + syslog(LOG_DEBUG, "using codepage directory: %s", page); - return page; + return page; } /* handle all the options. tmp can't be NULL. */ -static void volset(struct vol_option *options, char *volname, int vlen, - const char *nlspath, const char *tmp) +static void volset(struct vol_option *options, char *volname, int vlen, + const char *nlspath, const char *tmp) { - char *val; - - val = strchr(tmp, ':'); - if (optionok(tmp, "allow:", val)) { - if (options[VOLOPT_ALLOW].c_value) - free(options[VOLOPT_ALLOW].c_value); - options[VOLOPT_ALLOW].c_value = strdup(val + 1); - - } else if (optionok(tmp, "deny:", val)) { - if (options[VOLOPT_DENY].c_value) - free(options[VOLOPT_DENY].c_value); - options[VOLOPT_DENY].c_value = strdup(val + 1); - - } else if (optionok(tmp, "rwlist:", val)) { - if (options[VOLOPT_RWLIST].c_value) - free(options[VOLOPT_RWLIST].c_value); - options[VOLOPT_RWLIST].c_value = strdup(val + 1); - - } else if (optionok(tmp, "rolist:", val)) { - if (options[VOLOPT_ROLIST].c_value) - free(options[VOLOPT_ROLIST].c_value); - options[VOLOPT_ROLIST].c_value = strdup(val + 1); - - } else if (optionok(tmp, "codepage:", val)) { - if (options[VOLOPT_CODEPAGE].c_value) - free(options[VOLOPT_CODEPAGE].c_value); - options[VOLOPT_CODEPAGE].c_value = get_codepage_path(nlspath, val + 1); - - } else if (optionok(tmp, "veto:", val)) { - if (options[VOLOPT_VETO].c_value) - free(options[VOLOPT_VETO].c_value); - options[VOLOPT_VETO].c_value = strdup(val + 1); - - } else if (optionok(tmp, "casefold:", val)) { - if (strcasecmp(val + 1, "tolower") == 0) - options[VOLOPT_CASEFOLD].i_value = AFPVOL_UMLOWER; - else if (strcasecmp(val + 1, "toupper") == 0) - options[VOLOPT_CASEFOLD].i_value = AFPVOL_UMUPPER; - else if (strcasecmp(val + 1, "xlatelower") == 0) - options[VOLOPT_CASEFOLD].i_value = AFPVOL_UUPPERMLOWER; - else if (strcasecmp(val + 1, "xlateupper") == 0) - options[VOLOPT_CASEFOLD].i_value = AFPVOL_ULOWERMUPPER; - - } else if (optionok(tmp, "options:", val)) { - char *p; - - if ((p = strtok(val + 1, ",")) == NULL) /* nothing */ - return; - - while (p) { - if (strcasecmp(p, "prodos") == 0) - options[VOLOPT_FLAGS].i_value |= AFPVOL_A2VOL; - else if (strcasecmp(p, "mswindows") == 0) { - options[VOLOPT_FLAGS].i_value |= AFPVOL_MSWINDOWS; - if (!options[VOLOPT_CODEPAGE].c_value) - options[VOLOPT_CODEPAGE].c_value = - get_codepage_path(nlspath, MSWINDOWS_CODEPAGE); - - } else if (strcasecmp(p, "crlf") == 0) - options[VOLOPT_FLAGS].i_value |= AFPVOL_CRLF; - else if (strcasecmp(p, "noadouble") == 0) - options[VOLOPT_FLAGS].i_value |= AFPVOL_NOADOUBLE; - else if (strcasecmp(p, "ro") == 0) - options[VOLOPT_FLAGS].i_value |= AFPVOL_RO; - else if (strcasecmp(p, "nohex") == 0) - options[VOLOPT_FLAGS].i_value |= AFPVOL_NOHEX; - else if (strcasecmp(p, "usedots") == 0) - options[VOLOPT_FLAGS].i_value |= AFPVOL_USEDOTS; - else if (strcasecmp(p, "limitsize") == 0) - options[VOLOPT_FLAGS].i_value |= AFPVOL_LIMITSIZE; - /* support for either "dropbox" or "dropkludge" */ - else if (strcasecmp(p, "dropbox") == 0) - options[VOLOPT_FLAGS].i_value |= AFPVOL_DROPBOX; - else if (strcasecmp(p, "dropkludge") == 0) - options[VOLOPT_FLAGS].i_value |= AFPVOL_DROPBOX; - - p = strtok(NULL, ","); - } + char *val; + + val = strchr(tmp, ':'); + if (optionok(tmp, "allow:", val)) { + if (options[VOLOPT_ALLOW].c_value) + free(options[VOLOPT_ALLOW].c_value); + options[VOLOPT_ALLOW].c_value = strdup(val + 1); + + } else if (optionok(tmp, "deny:", val)) { + if (options[VOLOPT_DENY].c_value) + free(options[VOLOPT_DENY].c_value); + options[VOLOPT_DENY].c_value = strdup(val + 1); + + } else if (optionok(tmp, "rwlist:", val)) { + if (options[VOLOPT_RWLIST].c_value) + free(options[VOLOPT_RWLIST].c_value); + options[VOLOPT_RWLIST].c_value = strdup(val + 1); + + } else if (optionok(tmp, "rolist:", val)) { + if (options[VOLOPT_ROLIST].c_value) + free(options[VOLOPT_ROLIST].c_value); + options[VOLOPT_ROLIST].c_value = strdup(val + 1); + + } else if (optionok(tmp, "codepage:", val)) { + if (options[VOLOPT_CODEPAGE].c_value) + free(options[VOLOPT_CODEPAGE].c_value); + options[VOLOPT_CODEPAGE].c_value = get_codepage_path(nlspath, val + 1); + + } else if (optionok(tmp, "veto:", val)) { + if (options[VOLOPT_VETO].c_value) + free(options[VOLOPT_VETO].c_value); + options[VOLOPT_VETO].c_value = strdup(val + 1); + + } else if (optionok(tmp, "casefold:", val)) { + if (strcasecmp(val + 1, "tolower") == 0) + options[VOLOPT_CASEFOLD].i_value = AFPVOL_UMLOWER; + else if (strcasecmp(val + 1, "toupper") == 0) + options[VOLOPT_CASEFOLD].i_value = AFPVOL_UMUPPER; + else if (strcasecmp(val + 1, "xlatelower") == 0) + options[VOLOPT_CASEFOLD].i_value = AFPVOL_UUPPERMLOWER; + else if (strcasecmp(val + 1, "xlateupper") == 0) + options[VOLOPT_CASEFOLD].i_value = AFPVOL_ULOWERMUPPER; + + } else if (optionok(tmp, "options:", val)) { + char *p; + + if ((p = strtok(val + 1, ",")) == NULL) /* nothing */ + return; + + while (p) { + if (strcasecmp(p, "prodos") == 0) + options[VOLOPT_FLAGS].i_value |= AFPVOL_A2VOL; + else if (strcasecmp(p, "mswindows") == 0) { + options[VOLOPT_FLAGS].i_value |= AFPVOL_MSWINDOWS; + if (!options[VOLOPT_CODEPAGE].c_value) + options[VOLOPT_CODEPAGE].c_value = + get_codepage_path(nlspath, MSWINDOWS_CODEPAGE); + + } else if (strcasecmp(p, "crlf") == 0) + options[VOLOPT_FLAGS].i_value |= AFPVOL_CRLF; + else if (strcasecmp(p, "noadouble") == 0) + options[VOLOPT_FLAGS].i_value |= AFPVOL_NOADOUBLE; + else if (strcasecmp(p, "ro") == 0) + options[VOLOPT_FLAGS].i_value |= AFPVOL_RO; + else if (strcasecmp(p, "nohex") == 0) + options[VOLOPT_FLAGS].i_value |= AFPVOL_NOHEX; + else if (strcasecmp(p, "usedots") == 0) + options[VOLOPT_FLAGS].i_value |= AFPVOL_USEDOTS; + else if (strcasecmp(p, "limitsize") == 0) + options[VOLOPT_FLAGS].i_value |= AFPVOL_LIMITSIZE; + /* support for either "dropbox" or "dropkludge" */ + else if (strcasecmp(p, "dropbox") == 0) + options[VOLOPT_FLAGS].i_value |= AFPVOL_DROPBOX; + else if (strcasecmp(p, "dropkludge") == 0) + options[VOLOPT_FLAGS].i_value |= AFPVOL_DROPBOX; + + p = strtok(NULL, ","); + } #ifdef CNID_DB - } else if (optionok(tmp, "dbpath:", val)) { - if (options[VOLOPT_DBPATH].c_value) - free(options[VOLOPT_DBPATH].c_value); + } else if (optionok(tmp, "dbpath:", val)) { + if (options[VOLOPT_DBPATH].c_value) + free(options[VOLOPT_DBPATH].c_value); - options[VOLOPT_DBPATH].c_value = strdup(val + 1); + options[VOLOPT_DBPATH].c_value = strdup(val + 1); #endif /* CNID_DB */ - } else if (optionok(tmp, "mapchars:",val)) { - if (options[VOLOPT_MAPCHARS].c_value) - free(options[VOLOPT_MAPCHARS].c_value); - options[VOLOPT_MAPCHARS].c_value = strdup(val + 1); + } else if (optionok(tmp, "mapchars:",val)) { + if (options[VOLOPT_MAPCHARS].c_value) + free(options[VOLOPT_MAPCHARS].c_value); + options[VOLOPT_MAPCHARS].c_value = strdup(val + 1); - } else if (optionok(tmp, "password:", val)) { - if (options[VOLOPT_PASSWORD].c_value) - free(options[VOLOPT_PASSWORD].c_value); - options[VOLOPT_PASSWORD].c_value = strdup(val + 1); + } else if (optionok(tmp, "password:", val)) { + if (options[VOLOPT_PASSWORD].c_value) + free(options[VOLOPT_PASSWORD].c_value); + options[VOLOPT_PASSWORD].c_value = strdup(val + 1); #ifdef FORCE_UIDGID - /* this code allows forced uid/gid per volume settings */ - } else if (optionok(tmp, "forceuid:", val)) { - if (options[VOLOPT_FORCEUID].c_value) - free(options[VOLOPT_FORCEUID].c_value); - options[VOLOPT_FORCEUID].c_value = strdup(val + 1); - } else if (optionok(tmp, "forcegid:", val)) { - if (options[VOLOPT_FORCEGID].c_value) - free(options[VOLOPT_FORCEGID].c_value); - options[VOLOPT_FORCEGID].c_value = strdup(val + 1); + /* this code allows forced uid/gid per volume settings */ + } else if (optionok(tmp, "forceuid:", val)) { + if (options[VOLOPT_FORCEUID].c_value) + free(options[VOLOPT_FORCEUID].c_value); + options[VOLOPT_FORCEUID].c_value = strdup(val + 1); + } else if (optionok(tmp, "forcegid:", val)) { + if (options[VOLOPT_FORCEGID].c_value) + free(options[VOLOPT_FORCEGID].c_value); + options[VOLOPT_FORCEGID].c_value = strdup(val + 1); #endif /* FORCE_UIDGID */ - } else if (val) { - /* ignore unknown options */ - syslog(LOG_DEBUG, "ignoring unknown volume option: %s", tmp); + } else if (val) { + /* ignore unknown options */ + syslog(LOG_DEBUG, "ignoring unknown volume option: %s", tmp); - } else { - /* we'll assume it's a volume name. */ - strncpy(volname, tmp, vlen); - } + } else { + /* we'll assume it's a volume name. */ + strncpy(volname, tmp, vlen); + } } static int creatvol(const char *path, char *name, struct vol_option *options) @@ -416,43 +416,43 @@ static int creatvol(const char *path, char *name, struct vol_option *options) if ( name == NULL || *name == '\0' ) { if ((name = strrchr( path, '/' )) == NULL) { - return -1; /* Obviously not a fully qualified path */ - } + return -1; /* Obviously not a fully qualified path */ + } - /* if you wish to share /, you need to specify a name. */ - if (*++name == '\0') - return -1; + /* if you wish to share /, you need to specify a name. */ + if (*++name == '\0') + return -1; } for ( volume = volumes; volume; volume = volume->v_next ) { - if ( strcasecmp( volume->v_name, name ) == 0 ) { - return -1; /* Won't be able to access it, anyway... */ - } + if ( strcasecmp( volume->v_name, name ) == 0 ) { + return -1; /* Won't be able to access it, anyway... */ + } } vlen = strlen( name ); if ( vlen > AFPVOL_NAMELEN ) { - vlen = AFPVOL_NAMELEN; - name[AFPVOL_NAMELEN] = '\0'; + vlen = AFPVOL_NAMELEN; + name[AFPVOL_NAMELEN] = '\0'; } if (( volume = - (struct vol *)calloc(1, sizeof( struct vol ))) == NULL ) { - syslog( LOG_ERR, "creatvol: malloc: %s", strerror(errno) ); - return -1; + (struct vol *)calloc(1, sizeof( struct vol ))) == NULL ) { + syslog( LOG_ERR, "creatvol: malloc: %s", strerror(errno) ); + return -1; } if (( volume->v_name = - (char *)malloc( vlen + 1 )) == NULL ) { - syslog( LOG_ERR, "creatvol: malloc: %s", strerror(errno) ); - free(volume); - return -1; + (char *)malloc( vlen + 1 )) == NULL ) { + syslog( LOG_ERR, "creatvol: malloc: %s", strerror(errno) ); + free(volume); + return -1; } if (( volume->v_path = - (char *)malloc( strlen( path ) + 1 )) == NULL ) { - syslog( LOG_ERR, "creatvol: malloc: %s", strerror(errno) ); - free(volume->v_name); - free(volume); - return -1; + (char *)malloc( strlen( path ) + 1 )) == NULL ) { + syslog( LOG_ERR, "creatvol: malloc: %s", strerror(errno) ); + free(volume->v_name); + free(volume); + return -1; } strcpy( volume->v_name, name); @@ -466,40 +466,40 @@ static int creatvol(const char *path, char *name, struct vol_option *options) /* handle options */ if (options) { - /* should we casefold? */ - volume->v_casefold = options[VOLOPT_CASEFOLD].i_value; + /* should we casefold? */ + volume->v_casefold = options[VOLOPT_CASEFOLD].i_value; - /* shift in some flags */ - volume->v_flags = options[VOLOPT_FLAGS].i_value; + /* shift in some flags */ + volume->v_flags = options[VOLOPT_FLAGS].i_value; - /* read in the code pages */ - if (options[VOLOPT_CODEPAGE].c_value) - codepage_read(volume, options[VOLOPT_CODEPAGE].c_value); + /* read in the code pages */ + if (options[VOLOPT_CODEPAGE].c_value) + codepage_read(volume, options[VOLOPT_CODEPAGE].c_value); - if (options[VOLOPT_PASSWORD].c_value) - volume->v_password = strdup(options[VOLOPT_PASSWORD].c_value); + if (options[VOLOPT_PASSWORD].c_value) + volume->v_password = strdup(options[VOLOPT_PASSWORD].c_value); - if (options[VOLOPT_VETO].c_value) - volume->v_veto = strdup(options[VOLOPT_VETO].c_value); + if (options[VOLOPT_VETO].c_value) + volume->v_veto = strdup(options[VOLOPT_VETO].c_value); #ifdef CNID_DB - if (options[VOLOPT_DBPATH].c_value) - volume->v_dbpath = strdup(options[VOLOPT_DBPATH].c_value); + if (options[VOLOPT_DBPATH].c_value) + volume->v_dbpath = strdup(options[VOLOPT_DBPATH].c_value); #endif /* CNID_DB */ #ifdef FORCE_UIDGID - if (options[VOLOPT_FORCEUID].c_value) { - volume->v_forceuid = strdup(options[VOLOPT_FORCEUID].c_value); - } else { - volume->v_forceuid = NULL; /* set as null so as to return 0 later on */ - } + if (options[VOLOPT_FORCEUID].c_value) { + volume->v_forceuid = strdup(options[VOLOPT_FORCEUID].c_value); + } else { + volume->v_forceuid = NULL; /* set as null so as to return 0 later on */ + } - if (options[VOLOPT_FORCEGID].c_value) { - volume->v_forcegid = strdup(options[VOLOPT_FORCEGID].c_value); - } else { - volume->v_forcegid = NULL; /* set as null so as to return 0 later on */ - } + if (options[VOLOPT_FORCEGID].c_value) { + volume->v_forcegid = strdup(options[VOLOPT_FORCEGID].c_value); + } else { + volume->v_forcegid = NULL; /* set as null so as to return 0 later on */ + } #endif /* FORCE_UIDGID */ @@ -511,29 +511,29 @@ static int creatvol(const char *path, char *name, struct vol_option *options) } static char *myfgets( buf, size, fp ) - char *buf; - int size; - FILE *fp; +char *buf; +int size; +FILE *fp; { char *p; int c; p = buf; while ((( c = getc( fp )) != EOF ) && ( size > 0 )) { - if ( c == '\n' || c == '\r' ) { - *p++ = '\n'; - break; - } else { - *p++ = c; - } - size--; + if ( c == '\n' || c == '\r' ) { + *p++ = '\n'; + break; + } else { + *p++ = c; + } + size--; } if ( p == buf ) { - return( NULL ); + return( NULL ); } else { - *p = '\0'; - return( buf ); + *p = '\0'; + return( buf ); } } @@ -549,70 +549,70 @@ static char *myfgets( buf, size, fp ) * 1: in list */ static int accessvol(args, name) - const char *args; - const char *name; +const char *args; +const char *name; { char buf[MAXPATHLEN + 1], *p; struct group *gr; if (!args) - return -1; + return -1; strncpy(buf, args, sizeof(buf)); if ((p = strtok(buf, ",")) == NULL) /* nothing, return okay */ - return -1; + return -1; while (p) { - if (*p == '@') { /* it's a group */ - if ((gr = getgrnam(p + 1)) && gmem(gr->gr_gid)) - return 1; - } else if (strcmp(p, name) == 0) /* it's a user name */ - return 1; - p = strtok(NULL, ","); + if (*p == '@') { /* it's a group */ + if ((gr = getgrnam(p + 1)) && gmem(gr->gr_gid)) + return 1; + } else if (strcmp(p, name) == 0) /* it's a user name */ + return 1; + p = strtok(NULL, ","); } return 0; } static void setextmap( ext, type, creator, user) - char *ext, *type, *creator; - int user; +char *ext, *type, *creator; +int user; { struct extmap *em; for ( em = extmap; em; em = em->em_next ) { - if ( strdiacasecmp( em->em_ext, ext ) == 0 ) { - break; - } + if ( strdiacasecmp( em->em_ext, ext ) == 0 ) { + break; + } } if ( em == NULL ) { - if (( em = - (struct extmap *)malloc( sizeof( struct extmap ))) == NULL ) { - syslog( LOG_ERR, "setextmap: malloc: %s", strerror(errno) ); - return; - } - em->em_next = extmap; - extmap = em; + if (( em = + (struct extmap *)malloc( sizeof( struct extmap ))) == NULL ) { + syslog( LOG_ERR, "setextmap: malloc: %s", strerror(errno) ); + return; + } + em->em_next = extmap; + extmap = em; } else if ( !user ) { - return; + return; } strcpy( em->em_ext, ext ); if ( *type == '\0' ) { - memcpy(em->em_type, "????", sizeof( em->em_type )); + memcpy(em->em_type, "????", sizeof( em->em_type )); } else { - memcpy(em->em_type, type, sizeof( em->em_type )); + memcpy(em->em_type, type, sizeof( em->em_type )); } if ( *creator == '\0' ) { - memcpy(em->em_creator, "UNIX", sizeof( em->em_creator )); + memcpy(em->em_creator, "UNIX", sizeof( em->em_creator )); } else { - memcpy(em->em_creator, creator, sizeof( em->em_creator )); + memcpy(em->em_creator, creator, sizeof( em->em_creator )); } if ( strcmp( ext, "." ) == 0 ) { - defextmap = em; + defextmap = em; } } @@ -628,15 +628,15 @@ static void setextmap( ext, type, creator, user) * TYPE [CREATOR] */ static int readvolfile(obj, p1, p2, user, pwent) - AFPObj *obj; - char *p1, *p2; - int user; - struct passwd *pwent; +AFPObj *obj; +char *p1, *p2; +int user; +struct passwd *pwent; { FILE *fp; char path[ MAXPATHLEN + 1], tmp[ MAXPATHLEN + 1], - volname[ AFPVOL_NAMELEN + 1 ], buf[ BUFSIZ ], - type[ 5 ], creator[ 5 ]; + volname[ AFPVOL_NAMELEN + 1 ], buf[ BUFSIZ ], + type[ 5 ], creator[ 5 ]; char *u, *p; struct passwd *pw; struct vol_option options[VOLOPT_NUM], save_options[VOLOPT_NUM]; @@ -647,130 +647,130 @@ static int readvolfile(obj, p1, p2, user, pwent) strcpy( path, p1 ); if ( p2 != NULL ) { - strcat( path, "/" ); - strcat( path, p2 ); + strcat( path, "/" ); + strcat( path, p2 ); } if (( fp = fopen( path, "r" )) == NULL ) { - return( -1 ); + return( -1 ); } - + memset(save_options, 0, sizeof(save_options)); while ( myfgets( buf, sizeof( buf ), fp ) != NULL ) { - initline( strlen( buf ), buf ); - parseline( sizeof( path ) - 1, path ); - switch ( *path ) { - case '\0' : - case '#' : - continue; - - case ':': - /* change the default options for this file */ - if (strncmp(path, VOLOPT_DEFAULT, VOLOPT_DEFAULT_LEN) == 0) { - *tmp = '\0'; - for (i = 0; i < VOLOPT_NUM; i++) { - if (parseline( sizeof( path ) - VOLOPT_DEFAULT_LEN - 1, - path + VOLOPT_DEFAULT_LEN) < 0) - break; - volset(save_options, tmp, sizeof(tmp) - 1, - obj->options.nlspath, path + VOLOPT_DEFAULT_LEN); - } - } - break; - - case '~' : - if (( p = strchr( path, '/' )) != NULL ) { - *p++ = '\0'; - } - u = path; - u++; - if ( *u == '\0' ) { - u = obj->username; - } - if ( u == NULL || *u == '\0' || ( pw = getpwnam( u )) == NULL ) { - continue; - } - strcpy( tmp, pw->pw_dir ); - if ( p != NULL && *p != '\0' ) { - strcat( tmp, "/" ); - strcat( tmp, p ); - } - /* fall through */ - - case '/' : - /* send path through variable substitution */ - if (*path != '~') /* need to copy path to tmp */ - strcpy(tmp, path); - if (!pwent) - pwent = getpwnam(obj->username); - volxlate(obj, path, sizeof(path) - 1, tmp, pwent, NULL); - - /* this is sort of braindead. basically, i want to be - * able to specify things in any order, but i don't want to - * re-write everything. - * - * currently we have 11 options: - * volname - * codepage:x - * casefold:x - * allow:x,y,@z - * deny:x,y,@z - * rwlist:x,y,@z - * rolist:x,y,@z - * options:prodos,crlf,noadouble,ro - * dbpath:x - * password:x - * namemask:x,y,!z (not implemented yet) - */ - memcpy(options, save_options, sizeof(options)); - *volname = '\0'; - - /* read in up to 11 possible options */ - for (i = 0; i < VOLOPT_NUM; i++) { - if (parseline( sizeof( tmp ) - 1, tmp ) < 0) - break; - - volset(options, volname, sizeof(volname) - 1, - obj->options.nlspath, tmp); - } - - /* check allow/deny lists: - allow -> either no list (-1), or in list (1) - deny -> either no list (-1), or not in list (0) */ - if (accessvol(options[VOLOPT_ALLOW].c_value, obj->username) && - (accessvol(options[VOLOPT_DENY].c_value, obj->username) < 1)) { - - /* handle read-only behaviour. semantics: - * 1) neither the rolist nor the rwlist exist -> rw - * 2) rolist exists -> ro if user is in it. - * 3) rwlist exists -> ro unless user is in it. */ - if (((options[VOLOPT_FLAGS].i_value & AFPVOL_RO) == 0) && - ((accessvol(options[VOLOPT_ROLIST].c_value, - obj->username) == 1) || - !accessvol(options[VOLOPT_RWLIST].c_value, - obj->username))) - options[VOLOPT_FLAGS].i_value |= AFPVOL_RO; - - /* do variable substitution */ - volxlate(obj, tmp, sizeof(tmp) - 1, volname, pwent, path); - creatvol(path, tmp, options); - } - volfree(options, save_options); - break; - - case '.' : - parseline( sizeof( type ) - 1, type ); - parseline( sizeof( creator ) - 1, creator ); - setextmap( path, type, creator, user); - break; - - default : - break; - } + initline( strlen( buf ), buf ); + parseline( sizeof( path ) - 1, path ); + switch ( *path ) { + case '\0' : + case '#' : + continue; + + case ':': + /* change the default options for this file */ + if (strncmp(path, VOLOPT_DEFAULT, VOLOPT_DEFAULT_LEN) == 0) { + *tmp = '\0'; + for (i = 0; i < VOLOPT_NUM; i++) { + if (parseline( sizeof( path ) - VOLOPT_DEFAULT_LEN - 1, + path + VOLOPT_DEFAULT_LEN) < 0) + break; + volset(save_options, tmp, sizeof(tmp) - 1, + obj->options.nlspath, path + VOLOPT_DEFAULT_LEN); + } + } + break; + + case '~' : + if (( p = strchr( path, '/' )) != NULL ) { + *p++ = '\0'; + } + u = path; + u++; + if ( *u == '\0' ) { + u = obj->username; + } + if ( u == NULL || *u == '\0' || ( pw = getpwnam( u )) == NULL ) { + continue; + } + strcpy( tmp, pw->pw_dir ); + if ( p != NULL && *p != '\0' ) { + strcat( tmp, "/" ); + strcat( tmp, p ); + } + /* fall through */ + + case '/' : + /* send path through variable substitution */ + if (*path != '~') /* need to copy path to tmp */ + strcpy(tmp, path); + if (!pwent) + pwent = getpwnam(obj->username); + volxlate(obj, path, sizeof(path) - 1, tmp, pwent, NULL); + + /* this is sort of braindead. basically, i want to be + * able to specify things in any order, but i don't want to + * re-write everything. + * + * currently we have 11 options: + * volname + * codepage:x + * casefold:x + * allow:x,y,@z + * deny:x,y,@z + * rwlist:x,y,@z + * rolist:x,y,@z + * options:prodos,crlf,noadouble,ro + * dbpath:x + * password:x + * namemask:x,y,!z (not implemented yet) + */ + memcpy(options, save_options, sizeof(options)); + *volname = '\0'; + + /* read in up to 11 possible options */ + for (i = 0; i < VOLOPT_NUM; i++) { + if (parseline( sizeof( tmp ) - 1, tmp ) < 0) + break; + + volset(options, volname, sizeof(volname) - 1, + obj->options.nlspath, tmp); + } + + /* check allow/deny lists: + allow -> either no list (-1), or in list (1) + deny -> either no list (-1), or not in list (0) */ + if (accessvol(options[VOLOPT_ALLOW].c_value, obj->username) && + (accessvol(options[VOLOPT_DENY].c_value, obj->username) < 1)) { + + /* handle read-only behaviour. semantics: + * 1) neither the rolist nor the rwlist exist -> rw + * 2) rolist exists -> ro if user is in it. + * 3) rwlist exists -> ro unless user is in it. */ + if (((options[VOLOPT_FLAGS].i_value & AFPVOL_RO) == 0) && + ((accessvol(options[VOLOPT_ROLIST].c_value, + obj->username) == 1) || + !accessvol(options[VOLOPT_RWLIST].c_value, + obj->username))) + options[VOLOPT_FLAGS].i_value |= AFPVOL_RO; + + /* do variable substitution */ + volxlate(obj, tmp, sizeof(tmp) - 1, volname, pwent, path); + creatvol(path, tmp, options); + } + volfree(options, save_options); + break; + + case '.' : + parseline( sizeof( type ) - 1, type ); + parseline( sizeof( creator ) - 1, creator ); + setextmap( path, type, creator, user); + break; + + default : + break; + } } volfree(save_options, NULL); if ( fclose( fp ) != 0 ) { - syslog( LOG_ERR, "readvolfile: fclose: %s", strerror(errno) ); + syslog( LOG_ERR, "readvolfile: fclose: %s", strerror(errno) ); } return( 0 ); } @@ -778,38 +778,38 @@ static int readvolfile(obj, p1, p2, user, pwent) static void load_volumes(AFPObj *obj) { - struct passwd *pwent = getpwnam(obj->username); + struct passwd *pwent = getpwnam(obj->username); - if ( (obj->options.flags & OPTION_USERVOLFIRST) == 0 ) { - readvolfile(obj, obj->options.systemvol, NULL, 0, pwent); - } + if ( (obj->options.flags & OPTION_USERVOLFIRST) == 0 ) { + readvolfile(obj, obj->options.systemvol, NULL, 0, pwent); + } - if ((*obj->username == '\0') || (obj->options.flags & OPTION_NOUSERVOL)) { - readvolfile(obj, obj->options.defaultvol, NULL, 1, pwent); - } else if (pwent) { + if ((*obj->username == '\0') || (obj->options.flags & OPTION_NOUSERVOL)) { + readvolfile(obj, obj->options.defaultvol, NULL, 1, pwent); + } else if (pwent) { /* - * Read user's AppleVolumes or .AppleVolumes file - * If neither are readable, read the default volumes file. if - * that doesn't work, create a user share. - */ - if ( readvolfile(obj, pwent->pw_dir, "AppleVolumes", 1, pwent) < 0 && - readvolfile(obj, pwent->pw_dir, ".AppleVolumes", 1, pwent) < 0 && - readvolfile(obj, pwent->pw_dir, "applevolumes", 1, pwent) < 0 && - readvolfile(obj, pwent->pw_dir, ".applevolumes", 1, pwent) < 0 && - obj->options.defaultvol != NULL ) { - if (readvolfile(obj, obj->options.defaultvol, NULL, 1, pwent) < 0) - creatvol(pwent->pw_dir, NULL, NULL); + * Read user's AppleVolumes or .AppleVolumes file + * If neither are readable, read the default volumes file. if + * that doesn't work, create a user share. + */ + if ( readvolfile(obj, pwent->pw_dir, "AppleVolumes", 1, pwent) < 0 && + readvolfile(obj, pwent->pw_dir, ".AppleVolumes", 1, pwent) < 0 && + readvolfile(obj, pwent->pw_dir, "applevolumes", 1, pwent) < 0 && + readvolfile(obj, pwent->pw_dir, ".applevolumes", 1, pwent) < 0 && + obj->options.defaultvol != NULL ) { + if (readvolfile(obj, obj->options.defaultvol, NULL, 1, pwent) < 0) + creatvol(pwent->pw_dir, NULL, NULL); + } + } + if ( obj->options.flags & OPTION_USERVOLFIRST ) { + readvolfile(obj, obj->options.systemvol, NULL, 0, pwent ); } - } - if ( obj->options.flags & OPTION_USERVOLFIRST ) { - readvolfile(obj, obj->options.systemvol, NULL, 0, pwent ); - } } static int getvolspace( vol, bfree, btotal, xbfree, xbtotal, bsize ) - struct vol *vol; - u_int32_t *bfree, *btotal, *bsize; - VolSpace *xbfree, *xbtotal; +struct vol *vol; +u_int32_t *bfree, *btotal, *bsize; +VolSpace *xbfree, *xbtotal; { int spaceflag, rc; u_int32_t maxsize; @@ -820,32 +820,32 @@ static int getvolspace( vol, bfree, btotal, xbfree, xbtotal, bsize ) spaceflag = AFPVOL_GVSMASK & vol->v_flags; /* report up to 2GB if afp version is < 2.2 (4GB if not) */ maxsize = (vol->v_flags & AFPVOL_A2VOL) ? 0x01fffe00 : - (((afp_version < 22) || (vol->v_flags & AFPVOL_LIMITSIZE)) - ? 0x7fffffffL : 0xffffffffL); + (((afp_version < 22) || (vol->v_flags & AFPVOL_LIMITSIZE)) + ? 0x7fffffffL : 0xffffffffL); #ifdef AFS if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_AFSGVS ) { - if ( afs_getvolspace( vol, xbfree, xbtotal, bsize ) == AFP_OK ) { - vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_AFSGVS; - goto getvolspace_done; - } + if ( afs_getvolspace( vol, xbfree, xbtotal, bsize ) == AFP_OK ) { + vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_AFSGVS; + goto getvolspace_done; + } } #endif /* AFS */ if (( rc = ustatfs_getvolspace( vol, xbfree, xbtotal, - bsize)) != AFP_OK ) { - return( rc ); + bsize)) != AFP_OK ) { + return( rc ); } #define min(a,b) ((a)<(b)?(a):(b)) #ifndef NO_QUOTA_SUPPORT if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_UQUOTA ) { - if ( uquota_getvolspace( vol, &qfree, &qtotal, *bsize ) == AFP_OK ) { - vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_UQUOTA; - *xbfree = min(*xbfree, qfree); - *xbtotal = min( *xbtotal, qtotal); - goto getvolspace_done; - } + if ( uquota_getvolspace( vol, &qfree, &qtotal, *bsize ) == AFP_OK ) { + vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_UQUOTA; + *xbfree = min(*xbfree, qfree); + *xbtotal = min( *xbtotal, qtotal); + goto getvolspace_done; + } } #endif /* ! NO_QUOTA_SUPPORT */ vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_USTATFS; @@ -857,11 +857,11 @@ getvolspace_done: } static int getvolparams( bitmap, vol, st, buf, buflen ) - u_int16_t bitmap; - struct vol *vol; - struct stat *st; - char *buf; - int *buflen; +u_int16_t bitmap; +struct vol *vol; +struct stat *st; +char *buf; +int *buflen; { struct adouble ad; int bit = 0, isad = 1; @@ -875,161 +875,161 @@ static int getvolparams( bitmap, vol, st, buf, buflen ) /* courtesy of jallison@whistle.com: * For MacOS8.x support we need to create the * .Parent file here if it doesn't exist. */ - + memset(&ad, 0, sizeof(ad)); if ( ad_open( vol->v_path, vol_noadouble(vol) | - ADFLAGS_HF|ADFLAGS_DIR, O_RDWR | O_CREAT, - 0666, &ad) < 0 ) { - isad = 0; + ADFLAGS_HF|ADFLAGS_DIR, O_RDWR | O_CREAT, + 0666, &ad) < 0 ) { + isad = 0; } else if (ad_getoflags( &ad, ADFLAGS_HF ) & O_CREAT) { - slash = strrchr( vol->v_path, '/' ); - if(slash) - slash++; - else - slash = vol->v_path; - - ad_setentrylen( &ad, ADEID_NAME, strlen( slash )); - memcpy(ad_entry( &ad, ADEID_NAME ), slash, - ad_getentrylen( &ad, ADEID_NAME )); - ad_flush(&ad, ADFLAGS_HF); + slash = strrchr( vol->v_path, '/' ); + if(slash) + slash++; + else + slash = vol->v_path; + + ad_setentrylen( &ad, ADEID_NAME, strlen( slash )); + memcpy(ad_entry( &ad, ADEID_NAME ), slash, + ad_getentrylen( &ad, ADEID_NAME )); + ad_flush(&ad, ADFLAGS_HF); } if (( bitmap & ( (1<>1; - bit++; - } + while (( bitmap & 1 ) == 0 ) { + bitmap = bitmap>>1; + bit++; + } - switch ( bit ) { - case VOLPBIT_ATTR : + switch ( bit ) { + case VOLPBIT_ATTR : #ifdef CNID_DB - ashort = VOLPBIT_ATTR_FILEID; + ashort = VOLPBIT_ATTR_FILEID; #else /* CNID_DB */ - ashort = 0; + ashort = 0; #endif /* CNID_DB */ - /* check for read-only. - * NOTE: we don't actually set the read-only flag unless - * it's passed in that way as it's possible to mount - * a read-write filesystem under a read-only one. */ - if ((vol->v_flags & AFPVOL_RO) || - ((utime(vol->v_path, NULL) < 0) && (errno == EROFS))) - ashort |= VOLPBIT_ATTR_RO; - ashort = htons(ashort); - memcpy(data, &ashort, sizeof( ashort )); - data += sizeof( ashort ); - break; - - case VOLPBIT_SIG : - ashort = htons( AFPVOLSIG_DEFAULT ); - memcpy(data, &ashort, sizeof( ashort )); - data += sizeof( ashort ); - break; - - case VOLPBIT_CDATE : - if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0)) - aint = AD_DATE_FROM_UNIX(st->st_mtime); - memcpy(data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case VOLPBIT_MDATE : - if ( st->st_mtime > vol->v_time ) { - vol->v_time = st->st_mtime; - aint = AD_DATE_FROM_UNIX(st->st_mtime); - } else { - aint = AD_DATE_FROM_UNIX(vol->v_time); - } - memcpy(data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case VOLPBIT_BDATE : - if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0)) - aint = AD_DATE_START; - memcpy(data, &aint, sizeof( aint )); - data += sizeof( aint ); - break; - - case VOLPBIT_VID : - memcpy(data, &vol->v_vid, sizeof( vol->v_vid )); - data += sizeof( vol->v_vid ); - break; - - case VOLPBIT_BFREE : - bfree = htonl( bfree ); - memcpy(data, &bfree, sizeof( bfree )); - data += sizeof( bfree ); - break; - - case VOLPBIT_BTOTAL : - btotal = htonl( btotal ); - memcpy(data, &btotal, sizeof( btotal )); - data += sizeof( btotal ); - break; + /* check for read-only. + * NOTE: we don't actually set the read-only flag unless + * it's passed in that way as it's possible to mount + * a read-write filesystem under a read-only one. */ + if ((vol->v_flags & AFPVOL_RO) || + ((utime(vol->v_path, NULL) < 0) && (errno == EROFS))) + ashort |= VOLPBIT_ATTR_RO; + ashort = htons(ashort); + memcpy(data, &ashort, sizeof( ashort )); + data += sizeof( ashort ); + break; + + case VOLPBIT_SIG : + ashort = htons( AFPVOLSIG_DEFAULT ); + memcpy(data, &ashort, sizeof( ashort )); + data += sizeof( ashort ); + break; + + case VOLPBIT_CDATE : + if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0)) + aint = AD_DATE_FROM_UNIX(st->st_mtime); + memcpy(data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case VOLPBIT_MDATE : + if ( st->st_mtime > vol->v_time ) { + vol->v_time = st->st_mtime; + aint = AD_DATE_FROM_UNIX(st->st_mtime); + } else { + aint = AD_DATE_FROM_UNIX(vol->v_time); + } + memcpy(data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case VOLPBIT_BDATE : + if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0)) + aint = AD_DATE_START; + memcpy(data, &aint, sizeof( aint )); + data += sizeof( aint ); + break; + + case VOLPBIT_VID : + memcpy(data, &vol->v_vid, sizeof( vol->v_vid )); + data += sizeof( vol->v_vid ); + break; + + case VOLPBIT_BFREE : + bfree = htonl( bfree ); + memcpy(data, &bfree, sizeof( bfree )); + data += sizeof( bfree ); + break; + + case VOLPBIT_BTOTAL : + btotal = htonl( btotal ); + memcpy(data, &btotal, sizeof( btotal )); + data += sizeof( btotal ); + break; #ifndef NO_LARGE_VOL_SUPPORT - case VOLPBIT_XBFREE : - xbfree = hton64( xbfree ); + case VOLPBIT_XBFREE : + xbfree = hton64( xbfree ); #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG) - bcopy(&xbfree, data, sizeof(xbfree)); + bcopy(&xbfree, data, sizeof(xbfree)); #else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */ - memcpy(data, &xbfree, sizeof( xbfree )); + memcpy(data, &xbfree, sizeof( xbfree )); #endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */ - data += sizeof( xbfree ); - break; + data += sizeof( xbfree ); + break; - case VOLPBIT_XBTOTAL : - xbtotal = hton64( xbtotal ); + case VOLPBIT_XBTOTAL : + xbtotal = hton64( xbtotal ); #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG) - bcopy(&xbtotal, data, sizeof(xbtotal)); + bcopy(&xbtotal, data, sizeof(xbtotal)); #else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */ - memcpy(data, &xbtotal, sizeof( xbtotal )); + memcpy(data, &xbtotal, sizeof( xbtotal )); #endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */ - data += sizeof( xbfree ); - break; + data += sizeof( xbfree ); + break; #endif /* ! NO_LARGE_VOL_SUPPORT */ - case VOLPBIT_NAME : - nameoff = data; - data += sizeof( u_int16_t ); - break; - - case VOLPBIT_BSIZE: /* block size */ - bsize = htonl(bsize); - memcpy(data, &bsize, sizeof(bsize)); - data += sizeof(bsize); - break; - - default : - if ( isad ) { - ad_close( &ad, ADFLAGS_HF ); - } - return( AFPERR_BITMAP ); - } - bitmap = bitmap>>1; - bit++; + case VOLPBIT_NAME : + nameoff = data; + data += sizeof( u_int16_t ); + break; + + case VOLPBIT_BSIZE: /* block size */ + bsize = htonl(bsize); + memcpy(data, &bsize, sizeof(bsize)); + data += sizeof(bsize); + break; + + default : + if ( isad ) { + ad_close( &ad, ADFLAGS_HF ); + } + return( AFPERR_BITMAP ); + } + bitmap = bitmap>>1; + bit++; } if ( nameoff ) { - ashort = htons( data - buf ); - memcpy(nameoff, &ashort, sizeof( ashort )); - aint = strlen( vol->v_name ); - *data++ = aint; - memcpy(data, vol->v_name, aint ); - data += aint; + ashort = htons( data - buf ); + memcpy(nameoff, &ashort, sizeof( ashort )); + aint = strlen( vol->v_name ); + *data++ = aint; + memcpy(data, vol->v_name, aint ); + data += aint; } if ( isad ) { ad_close( &ad, ADFLAGS_HF ); @@ -1041,9 +1041,9 @@ static int getvolparams( bitmap, vol, st, buf, buflen ) int afp_getsrvrparms(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct timeval tv; struct stat st; @@ -1051,44 +1051,44 @@ int afp_getsrvrparms(obj, ibuf, ibuflen, rbuf, rbuflen ) char *data; int vcnt, len; - + if (!volumes) - load_volumes(obj); + load_volumes(obj); data = rbuf + 5; for ( vcnt = 0, volume = volumes; volume; volume = volume->v_next ) { - if ( stat( volume->v_path, &st ) < 0 ) { - syslog( LOG_INFO, "afp_getsrvrparms: stat %s: %s", - volume->v_path, strerror(errno) ); - continue; /* can't access directory */ - } - if (!S_ISDIR(st.st_mode)) { - continue; /* not a dir */ - } - - /* set password bit if there's a volume password */ - *data = (volume->v_password) ? AFPSRVR_PASSWD : 0; - - /* Apple 2 clients running ProDOS-8 expect one volume to have - bit 0 of this byte set. They will not recognize anything - on the server unless this is the case. I have not - completely worked this out, but it's related to booting - from the server. Support for that function is a ways - off.. */ - *data++ |= (volume->v_flags & AFPVOL_A2VOL) ? AFPSRVR_CONFIGINFO : 0; - len = strlen( volume->v_name ); - *data++ = len; - memcpy(data, volume->v_name, len ); - data += len; - vcnt++; + if ( stat( volume->v_path, &st ) < 0 ) { + syslog( LOG_INFO, "afp_getsrvrparms: stat %s: %s", + volume->v_path, strerror(errno) ); + continue; /* can't access directory */ + } + if (!S_ISDIR(st.st_mode)) { + continue; /* not a dir */ + } + + /* set password bit if there's a volume password */ + *data = (volume->v_password) ? AFPSRVR_PASSWD : 0; + + /* Apple 2 clients running ProDOS-8 expect one volume to have + bit 0 of this byte set. They will not recognize anything + on the server unless this is the case. I have not + completely worked this out, but it's related to booting + from the server. Support for that function is a ways + off.. */ + *data++ |= (volume->v_flags & AFPVOL_A2VOL) ? AFPSRVR_CONFIGINFO : 0; + len = strlen( volume->v_name ); + *data++ = len; + memcpy(data, volume->v_name, len ); + data += len; + vcnt++; } *rbuflen = data - rbuf; data = rbuf; if ( gettimeofday( &tv, 0 ) < 0 ) { - syslog( LOG_ERR, "afp_getsrvrparms: gettimeofday: %s", strerror(errno) ); - *rbuflen = 0; - return AFPERR_PARAM; + syslog( LOG_ERR, "afp_getsrvrparms: gettimeofday: %s", strerror(errno) ); + *rbuflen = 0; + return AFPERR_PARAM; } tv.tv_sec = AD_DATE_FROM_UNIX(tv.tv_sec); memcpy(data, &tv.tv_sec, sizeof( u_int32_t)); @@ -1098,9 +1098,9 @@ int afp_getsrvrparms(obj, ibuf, ibuflen, rbuf, rbuflen ) } int afp_openvol(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct stat st; char *volname; @@ -1118,7 +1118,7 @@ int afp_openvol(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof( bitmap ); if (( bitmap & (1<v_next ) { - if ( strcasecmp( volname, volume->v_name ) == 0 ) { - break; - } + if ( strcasecmp( volname, volume->v_name ) == 0 ) { + break; + } } if ( volume == NULL ) { - ret = AFPERR_PARAM; - goto openvol_err; + ret = AFPERR_PARAM; + goto openvol_err; } /* check for a volume password */ - if (volume->v_password && - strncmp(ibuf, volume->v_password, VOLPASSLEN)) { + if (volume->v_password && + strncmp(ibuf, volume->v_password, VOLPASSLEN)) { ret = AFPERR_ACCESS; - goto openvol_err; + goto openvol_err; } if (( volume->v_flags & AFPVOL_OPEN ) == 0 ) { if ((dir = dirnew(strlen(volume->v_name) + 1)) == NULL) { - syslog( LOG_ERR, "afp_openvol: malloc: %s", strerror(errno) ); - ret = AFPERR_MISC; - goto openvol_err; - } - dir->d_did = DIRDID_ROOT; - dir->d_color = DIRTREE_COLOR_BLACK; /* root node is black */ - strcpy( dir->d_name, volume->v_name ); - volume->v_dir = volume->v_root = dir; - volume->v_flags |= AFPVOL_OPEN; + syslog( LOG_ERR, "afp_openvol: malloc: %s", strerror(errno) ); + ret = AFPERR_MISC; + goto openvol_err; + } + dir->d_did = DIRDID_ROOT; + dir->d_color = DIRTREE_COLOR_BLACK; /* root node is black */ + strcpy( dir->d_name, volume->v_name ); + volume->v_dir = volume->v_root = dir; + volume->v_flags |= AFPVOL_OPEN; } if ( stat( volume->v_path, &st ) < 0 ) { - ret = AFPERR_PARAM; - goto openvol_err; + ret = AFPERR_PARAM; + goto openvol_err; } buflen = *rbuflen - sizeof( bitmap ); if (( ret = getvolparams( bitmap, volume, &st, - rbuf + sizeof(bitmap), &buflen )) != AFP_OK ) { + rbuf + sizeof(bitmap), &buflen )) != AFP_OK ) { goto openvol_err; } *rbuflen = buflen + sizeof( bitmap ); @@ -1180,14 +1180,14 @@ int afp_openvol(obj, ibuf, ibuflen, rbuf, rbuflen ) curdir = volume->v_dir; if ( chdir( volume->v_path ) < 0 ) { ret = AFPERR_PARAM; - goto openvol_err; + goto openvol_err; } #ifdef CNID_DB - if (volume->v_dbpath) - volume->v_db = cnid_open (volume->v_dbpath); - if (volume->v_db == 0) - volume->v_db = cnid_open (volume->v_path); + if (volume->v_dbpath) + volume->v_db = cnid_open (volume->v_dbpath); + if (volume->v_db == 0) + volume->v_db = cnid_open (volume->v_path); #endif /* CNID_DB */ #ifndef CNID_DB @@ -1210,9 +1210,9 @@ openvol_err: } int afp_closevol(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct vol *vol, *ovol; u_int16_t vid; @@ -1221,20 +1221,20 @@ int afp_closevol(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += 2; memcpy(&vid, ibuf, sizeof( vid )); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } vol->v_flags &= ~AFPVOL_OPEN; for ( ovol = volumes; ovol; ovol = ovol->v_next ) { - if ( ovol->v_flags & AFPVOL_OPEN ) { - break; - } + if ( ovol->v_flags & AFPVOL_OPEN ) { + break; + } } if ( ovol != NULL ) { - curdir = ovol->v_dir; - if ( chdir( ovol->v_path ) < 0 ) { - return( AFPERR_PARAM ); - } + curdir = ovol->v_dir; + if ( chdir( ovol->v_path ) < 0 ) { + return( AFPERR_PARAM ); + } } dirfree( vol->v_root ); @@ -1251,12 +1251,12 @@ struct vol *getvolbyvid(const u_int16_t vid ) struct vol *vol; for ( vol = volumes; vol; vol = vol->v_next ) { - if ( vid == vol->v_vid ) { - break; - } + if ( vid == vol->v_vid ) { + break; + } } if ( vol == NULL || ( vol->v_flags & AFPVOL_OPEN ) == 0 ) { - return( NULL ); + return( NULL ); } return( vol ); @@ -1268,24 +1268,24 @@ struct extmap *getextmap(const char *path) struct extmap *em; if (( p = strrchr( path, '.' )) == NULL ) { - return( defextmap ); + return( defextmap ); } for ( em = extmap; em; em = em->em_next ) { - if ( strdiacasecmp( em->em_ext, p ) == 0 ) { - break; - } + if ( strdiacasecmp( em->em_ext, p ) == 0 ) { + break; + } } if ( em == NULL ) { - return( defextmap ); + return( defextmap ); } else { - return( em ); + return( em ); } } void setvoltime(obj, vol ) - AFPObj *obj; - struct vol *vol; +AFPObj *obj; +struct vol *vol; { struct timeval tv; @@ -1296,8 +1296,8 @@ void setvoltime(obj, vol ) * [RS] */ if ( gettimeofday( &tv, 0 ) < 0 ) { - syslog( LOG_ERR, "setvoltime: gettimeofday: %s", strerror(errno) ); - return; + syslog( LOG_ERR, "setvoltime: gettimeofday: %s", strerror(errno) ); + return; } if( utime( vol->v_path, NULL ) < 0 ) { /* write of time failed ... probably a read only filesys, @@ -1307,15 +1307,15 @@ void setvoltime(obj, vol ) /* a little granularity */ if (vol->v_time < tv.tv_sec) { - vol->v_time = tv.tv_sec; - obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED); + vol->v_time = tv.tv_sec; + obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED); } } int afp_getvolparams(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct stat st; struct vol *vol; @@ -1329,20 +1329,20 @@ int afp_getvolparams(obj, ibuf, ibuflen, rbuf, rbuflen ) bitmap = ntohs( bitmap ); if (( vol = getvolbyvid( vid )) == NULL ) { - *rbuflen = 0; - return( AFPERR_PARAM ); + *rbuflen = 0; + return( AFPERR_PARAM ); } if ( stat( vol->v_path, &st ) < 0 ) { - *rbuflen = 0; - return( AFPERR_PARAM ); + *rbuflen = 0; + return( AFPERR_PARAM ); } buflen = *rbuflen - sizeof( bitmap ); if (( ret = getvolparams( bitmap, vol, &st, - rbuf + sizeof( bitmap ), &buflen )) != AFP_OK ) { - *rbuflen = 0; - return( ret ); + rbuf + sizeof( bitmap ), &buflen )) != AFP_OK ) { + *rbuflen = 0; + return( ret ); } *rbuflen = buflen + sizeof( bitmap ); bitmap = htons( bitmap ); @@ -1351,9 +1351,9 @@ int afp_getvolparams(obj, ibuf, ibuflen, rbuf, rbuflen ) } int afp_setvolparams(obj, ibuf, ibuflen, rbuf, rbuflen ) - AFPObj *obj; - char *ibuf, *rbuf; - int ibuflen, *rbuflen; +AFPObj *obj; +char *ibuf, *rbuf; +int ibuflen, *rbuflen; { struct adouble ad; struct vol *vol; @@ -1370,7 +1370,7 @@ int afp_setvolparams(obj, ibuf, ibuflen, rbuf, rbuflen ) ibuf += sizeof(bitmap); if (( vol = getvolbyvid( vid )) == NULL ) { - return( AFPERR_PARAM ); + return( AFPERR_PARAM ); } if (vol->v_flags & AFPVOL_RO) @@ -1378,15 +1378,15 @@ int afp_setvolparams(obj, ibuf, ibuflen, rbuf, rbuflen ) /* we can only set the backup date. */ if (bitmap != VOLPBIT_BDATE) - return AFPERR_BITMAP; + return AFPERR_BITMAP; memset(&ad, 0, sizeof(ad)); - if ( ad_open( vol->v_path, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR, - 0666, &ad) < 0 ) { - if (errno == EROFS) - return AFPERR_VLOCK; + if ( ad_open( vol->v_path, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR, + 0666, &ad) < 0 ) { + if (errno == EROFS) + return AFPERR_VLOCK; - return AFPERR_ACCESS; + return AFPERR_ACCESS; } memcpy(&aint, ibuf, sizeof(aint)); diff --git a/etc/afpd/volume.h b/etc/afpd/volume.h index 692413e0..61b59ec2 100644 --- a/etc/afpd/volume.h +++ b/etc/afpd/volume.h @@ -1,5 +1,5 @@ /* - * $Id: volume.h,v 1.7 2001-09-04 13:52:45 rufustfirefly Exp $ + * $Id: volume.h,v 1.7.2.1 2001-12-03 05:01:04 jmarcus Exp $ * * Copyright (c) 1990,1994 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -16,18 +16,18 @@ #define AFPVOL_NAMELEN 27 struct codepage_hash { - unsigned char *from, *to; - struct codepage_hash *next, *prev; + unsigned char *from, *to; + struct codepage_hash *next, *prev; }; union codepage_val { - struct codepage_hash hash; /* hash for multibyte values */ - unsigned char value; /* single byte value/rule */ + struct codepage_hash hash; /* hash for multibyte values */ + unsigned char value; /* single byte value/rule */ }; struct codepage { - union codepage_val *map; - int quantum; + union codepage_val *map; + int quantum; }; #define CP_HASH(a) (*(a)) @@ -55,8 +55,8 @@ struct vol { char *v_dbpath; #endif /* CNID_DB */ #ifdef FORCE_UIDGID - char *v_forceuid; - char *v_forcegid; + char *v_forceuid; + char *v_forcegid; #endif /* FORCE_UIDGID */ }; @@ -81,7 +81,7 @@ typedef u_int64_t VolSpace; #define AFPVOL_NOADOUBLE (1 << 7) /* don't create .AppleDouble by default */ #define AFPVOL_RO (1 << 8) /* read-only volume */ #define AFPVOL_MSWINDOWS (1 << 9) /* deal with ms-windows yuckiness. - this is going away. */ +this is going away. */ #define AFPVOL_NOHEX (1 << 10) /* don't do :hex translation */ #define AFPVOL_USEDOTS (1 << 11) /* use real dots */ #define AFPVOL_LIMITSIZE (1 << 12) /* limit size for older macs */ @@ -101,7 +101,7 @@ typedef u_int64_t VolSpace; #define AFPVOL_UMUPPER (AFPVOL_MTOUUPPER | AFPVOL_UTOMUPPER) #define AFPVOL_UUPPERMLOWER (AFPVOL_MTOUUPPER | AFPVOL_UTOMLOWER) #define AFPVOL_ULOWERMUPPER (AFPVOL_MTOULOWER | AFPVOL_UTOMUPPER) - + #define MSWINDOWS_BADCHARS "\\/<>*?|\"" #define MSWINDOWS_CODEPAGE "maccode.iso8859-1" @@ -137,10 +137,10 @@ typedef u_int64_t VolSpace; extern struct vol *getvolbyvid __P((const u_int16_t)); extern int ustatfs_getvolspace __P((const struct vol *, - VolSpace *, VolSpace *, - u_int32_t *)); -extern int codepage_init __P((struct vol *, const int, - const int)); + VolSpace *, VolSpace *, + u_int32_t *)); +extern int codepage_init __P((struct vol *, const int, + const int)); extern int codepage_read __P((struct vol *, const char *)); extern union codepage_val codepage_find __P(()); extern void setvoltime __P((AFPObj *, struct vol *)); -- 2.39.2