diff --git a/src/WINNT/afsd/afsd_init.c b/src/WINNT/afsd/afsd_init.c index 9f241a992d..9c9908cbc6 100644 --- a/src/WINNT/afsd/afsd_init.c +++ b/src/WINNT/afsd/afsd_init.c @@ -622,7 +622,7 @@ int afsd_InitCM(char **reasonP) } afsi_log("Cache path %s", cm_CachePath); } else { - dummyLen = ExpandEnvironmentStrings("%TEMP%\AFSCache", cm_CachePath, sizeof(cm_CachePath)); + dummyLen = ExpandEnvironmentStrings("%TEMP%\\AFSCache", cm_CachePath, sizeof(cm_CachePath)); if (dummyLen > sizeof(cm_CachePath)) { afsi_log("Cache path [%%TEMP%%\\AFSCache] longer than %d after expanding env strings", sizeof(cm_CachePath)); diff --git a/src/WINNT/afsd/afsd_service.c b/src/WINNT/afsd/afsd_service.c index 5903ac4da7..d72092eb45 100644 --- a/src/WINNT/afsd/afsd_service.c +++ b/src/WINNT/afsd/afsd_service.c @@ -171,10 +171,8 @@ afsd_ServiceControlHandler(DWORD ctrlCode) long code; switch (ctrlCode) { + case SERVICE_CONTROL_SHUTDOWN: case SERVICE_CONTROL_STOP: - /* Shutdown RPC */ - RpcMgmtStopServerListening(NULL); - /* Force trace if requested */ code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName, @@ -199,7 +197,7 @@ afsd_ServiceControlHandler(DWORD ctrlCode) ServiceStatus.dwWin32ExitCode = NO_ERROR; ServiceStatus.dwCheckPoint = 1; ServiceStatus.dwWaitHint = 10000; - ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; + ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; SetServiceStatus(StatusHandle, &ServiceStatus); SetEvent(WaitToTerminate); break; @@ -208,7 +206,7 @@ afsd_ServiceControlHandler(DWORD ctrlCode) ServiceStatus.dwWin32ExitCode = NO_ERROR; ServiceStatus.dwCheckPoint = 0; ServiceStatus.dwWaitHint = 0; - ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; + ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; SetServiceStatus(StatusHandle, &ServiceStatus); break; /* XXX handle system shutdown */ @@ -237,9 +235,6 @@ afsd_ServiceControlHandlerEx( switch (ctrlCode) { case SERVICE_CONTROL_STOP: - /* Shutdown RPC */ - RpcMgmtStopServerListening(NULL); - /* Force trace if requested */ code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName, @@ -275,7 +270,7 @@ afsd_ServiceControlHandlerEx( ServiceStatus.dwWin32ExitCode = NO_ERROR; ServiceStatus.dwCheckPoint = 0; ServiceStatus.dwWaitHint = 0; - ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_POWEREVENT; + ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_POWEREVENT; SetServiceStatus(StatusHandle, &ServiceStatus); dwRet = NO_ERROR; break; @@ -1155,7 +1150,7 @@ void afsd_Main(DWORD argc, LPTSTR *argv) ServiceStatus.dwWaitHint = 0; /* accept Power events */ - ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_POWEREVENT; + ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_POWEREVENT; SetServiceStatus(StatusHandle, &ServiceStatus); #endif { @@ -1181,6 +1176,7 @@ void afsd_Main(DWORD argc, LPTSTR *argv) DismountGlobalDrives(); smb_Shutdown(); rx_Finalize(); + RpcShutdown(); buf_Shutdown(); #ifdef REGISTER_POWER_NOTIFICATIONS diff --git a/src/WINNT/afsd/afskfw.c b/src/WINNT/afsd/afskfw.c index 01ace95a8d..5a4a2b70d1 100644 --- a/src/WINNT/afsd/afskfw.c +++ b/src/WINNT/afsd/afskfw.c @@ -63,6 +63,7 @@ #include #include /* for life_to_time */ #include +#include /* * TIMING _____________________________________________________________________ diff --git a/src/WINNT/afsd/afslogon.c b/src/WINNT/afsd/afslogon.c index 0446fb4989..e13022342b 100644 --- a/src/WINNT/afsd/afslogon.c +++ b/src/WINNT/afsd/afslogon.c @@ -254,6 +254,28 @@ BOOL IsServiceRunning (void) return (Status.dwCurrentState == SERVICE_RUNNING); } +BOOL IsServiceStartPending (void) +{ + SERVICE_STATUS Status; + SC_HANDLE hManager; + memset (&Status, 0x00, sizeof(Status)); + Status.dwCurrentState = SERVICE_STOPPED; + + if ((hManager = OpenSCManager (NULL, NULL, GENERIC_READ)) != NULL) + { + SC_HANDLE hService; + if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"), GENERIC_READ)) != NULL) + { + QueryServiceStatus (hService, &Status); + CloseServiceHandle (hService); + } + + CloseServiceHandle (hManager); + } + DebugEvent("AFS AfsLogon - Test Service Start Pending","Return Code[%x] ?Start Pending[%d]",Status.dwCurrentState,(Status.dwCurrentState == SERVICE_START_PENDING)); + return (Status.dwCurrentState == SERVICE_RUNNING); +} + /* LOOKUPKEYCHAIN: macro to look up the value in the list of keys in order until it's found v:variable to receive value (reference type) t:type @@ -550,6 +572,10 @@ UnicodeStringToANSI(UNICODE_STRING uInputString, LPSTR lpszOutputString, int nOu GetCPInfo(CP_ACP, &CodePageInfo); + if (CodePageInfo.MaxCharSize > 1) + // Only supporting non-Unicode strings + return FALSE; + if (uInputString.Buffer && ((LPBYTE) uInputString.Buffer)[1] == '\0') { // Looks like unicode, better translate it @@ -561,7 +587,6 @@ UnicodeStringToANSI(UNICODE_STRING uInputString, LPSTR lpszOutputString, int nOu } else lpszOutputString[0] = '\0'; - return FALSE; } // UnicodeStringToANSI @@ -654,6 +679,9 @@ DWORD APIENTRY NPLogonNotify( sleepInterval = opt.sleepInterval; *lpLogonScript = opt.logonScript; + if (retryInterval < sleepInterval) + sleepInterval = retryInterval; + DebugEvent("Got logon script: %S",opt.logonScript); afsWillAutoStart = AFSWillAutoStart(); @@ -687,7 +715,7 @@ DWORD APIENTRY NPLogonNotify( /* We get the user's home directory path, if applicable, though we can't lookup the cell right away because the client service may not have started yet. This call also sets the AD_REALM flag in opt.flags if applicable. */ - if(ISREMOTE(opt.flags)) { + if (ISREMOTE(opt.flags)) { DebugEvent("Is Remote"); GetAdHomePath(homePath,MAX_PATH,lpLogonId,&opt); } @@ -698,9 +726,9 @@ DWORD APIENTRY NPLogonNotify( DebugEvent("while(TRUE) LogonOption[%x], Service AutoStart[%d]", opt.LogonOption,afsWillAutoStart); - if(ISADREALM(opt.flags)) { + if (ISADREALM(opt.flags)) { code = GetFileCellName(homePath,cell,256); - if(!code) { + if (!code) { DebugEvent("profile path [%s] is in cell [%s]",homePath,cell); } /* Don't bail out if GetFileCellName failed. @@ -728,29 +756,31 @@ DWORD APIENTRY NPLogonNotify( *ctemp = tolower(*ctemp); } uppercased_name = FALSE; - continue; + goto sleeping; } + + /* is service started yet?*/ + DebugEvent("AFS AfsLogon - ka_UserAuthenticateGeneral2","Code[%x] uname[%s] Cell[%s]", + code,uname,cell); + + /* If we've failed because the client isn't running yet and the + * client is set to autostart (and therefore it makes sense for + * us to wait for it to start) then sleep a while and try again. + * If the error was something else, then give up. */ + if (code != KTC_NOCM && code != KTC_NOCMRPC || !afsWillAutoStart) + break; } else { /*JUST check to see if its running*/ if (IsServiceRunning()) break; - code = KTC_NOCM; - if (!afsWillAutoStart) + if (afsWillAutoStart && !IsServiceStartPending()) { + code = KTC_NOCMRPC; + reason = "AFS Service start failed"; break; + } } - /* is service started yet?*/ - DebugEvent("AFS AfsLogon - ka_UserAuthenticateGeneral2","Code[%x] uname[%s] Cell[%s]", - code,uname,cell); - - /* If we've failed because the client isn't running yet and the - * client is set to autostart (and therefore it makes sense for - * us to wait for it to start) then sleep a while and try again. - * If the error was something else, then give up. */ - if (code != KTC_NOCM && code != KTC_NOCMRPC || !afsWillAutoStart) - break; - /* If the retry interval has expired and we still aren't * logged in, then just give up if we are not in interactive * mode or the failSilently flag is set, otherwise let the @@ -767,14 +797,11 @@ DWORD APIENTRY NPLogonNotify( break; /* Wait just a little while and try again */ - retryInterval = sleepInterval = DEFAULT_SLEEP_INTERVAL; + retryInterval = opt.retryInterval; } - if (retryInterval < sleepInterval) - sleepInterval = retryInterval; - + sleeping: Sleep(sleepInterval * 1000); - retryInterval -= sleepInterval; } @@ -809,7 +836,6 @@ DWORD APIENTRY NPLogonNotify( *lpLogonScript = NULL; if (!afsWillAutoStart) // its not running, so if not autostart or integrated logon then just skip code = 0; - } } diff --git a/src/WINNT/afsd/afslogon.h b/src/WINNT/afsd/afslogon.h index d222642f3b..120be6b062 100644 --- a/src/WINNT/afsd/afslogon.h +++ b/src/WINNT/afsd/afslogon.h @@ -41,7 +41,7 @@ SOFTWARE. #define REG_CLIENT_TRACE_OPTION_PARM "TraceOption" #define REG_CLIENT_LOGON_OPTION_PARM "LogonOptions" #define REG_CLIENT_LOGON_SCRIPT_PARMW L"LogonScript" -#define DEFAULT_RETRY_INTERVAL 30 /* seconds*/ +#define DEFAULT_RETRY_INTERVAL 60 /* seconds*/ #define DEFAULT_FAIL_SILENTLY FALSE #define DEFAULT_SLEEP_INTERVAL 5 /* seconds*/ #define DEFAULT_LOGON_OPTION 1 diff --git a/src/WINNT/afsd/cm_cell.c b/src/WINNT/afsd/cm_cell.c index e82ff96635..5c089dd412 100644 --- a/src/WINNT/afsd/cm_cell.c +++ b/src/WINNT/afsd/cm_cell.c @@ -95,12 +95,25 @@ cm_cell_t *cm_GetCell_Gen(char *namep, char *newnamep, long flags) memset(cp, 0, sizeof(cm_cell_t)); } else { + cm_cell_t **cpp; + dns_expired = 1; - /* must empty cp->vlServersp */ - lock_ObtainWrite(&cp->mx); - cm_FreeServerList(&cp->vlServersp); - cp->vlServersp = NULL; - lock_ReleaseWrite(&cp->mx); + if (cp->vlServersp) { + /* must empty cp->vlServersp */ + lock_ObtainMutex(&cp->mx); + cm_FreeServerList(&cp->vlServersp); + cp->vlServersp = NULL; + lock_ReleaseMutex(&cp->mx); + } + /* remove the entry from the allCells list + * we will re-insert it later + */ + for (cpp = &cm_data.allCellsp; *cpp; cpp=&(*cpp)->nextp) { + if (*cpp == cp) { + (*cpp) = cp->nextp; + break; + } + } } code = cm_SearchCellFile(namep, fullname, cm_AddCellProc, cp); diff --git a/src/WINNT/afsd/cm_dcache.c b/src/WINNT/afsd/cm_dcache.c index 550fa2278c..274c61ea0a 100644 --- a/src/WINNT/afsd/cm_dcache.c +++ b/src/WINNT/afsd/cm_dcache.c @@ -1182,7 +1182,7 @@ long cm_GetBuffer(cm_scache_t *scp, cm_buf_t *bufp, int *cpffp, cm_user_t *up, afsStatus.FileType = 0x2; afsStatus.LinkCount = scp->linkCount; afsStatus.Length = cm_fakeDirSize; - afsStatus.DataVersion = cm_fakeDirVersion; + afsStatus.DataVersion = scp->dataVersion; afsStatus.Author = 0x1; afsStatus.Owner = 0x0; afsStatus.CallerAccess = 0x9; diff --git a/src/WINNT/afsd/cm_rpc.c b/src/WINNT/afsd/cm_rpc.c index 17845c34f0..ad4d2a1360 100644 --- a/src/WINNT/afsd/cm_rpc.c +++ b/src/WINNT/afsd/cm_rpc.c @@ -40,15 +40,17 @@ extern void afsi_log(char *pattern, ...); typedef struct tokenEvent { - afs_uuid_t uuid; - char sessionKey[8]; - struct tokenEvent *next; + afs_uuid_t uuid; + char sessionKey[8]; + struct tokenEvent *next; } tokenEvent_t; tokenEvent_t *tokenEvents = NULL; osi_mutex_t tokenEventLock; +EVENT_HANDLE rpc_ShutdownEvent = NULL; + /* * Add a new uuid and session key to the list. */ @@ -56,13 +58,13 @@ void cm_RegisterNewTokenEvent( afs_uuid_t uuid, char sessionKey[8]) { - tokenEvent_t *te = malloc(sizeof(tokenEvent_t)); - te->uuid = uuid; - memcpy(te->sessionKey, sessionKey, sizeof(te->sessionKey)); - lock_ObtainMutex(&tokenEventLock); - te->next = tokenEvents; - tokenEvents = te; - lock_ReleaseMutex(&tokenEventLock); + tokenEvent_t *te = malloc(sizeof(tokenEvent_t)); + te->uuid = uuid; + memcpy(te->sessionKey, sessionKey, sizeof(te->sessionKey)); + lock_ObtainMutex(&tokenEventLock); + te->next = tokenEvents; + tokenEvents = te; + lock_ReleaseMutex(&tokenEventLock); } /* @@ -73,27 +75,27 @@ void cm_RegisterNewTokenEvent( */ BOOL cm_FindTokenEvent(afs_uuid_t uuid, char sessionKey[8]) { - RPC_STATUS status; - tokenEvent_t *te; - tokenEvent_t **ltep; + RPC_STATUS status; + tokenEvent_t *te; + tokenEvent_t **ltep; - lock_ObtainMutex(&tokenEventLock); - te = tokenEvents; - ltep = &tokenEvents; - while (te) { - if (UuidEqual((UUID *)&uuid, (UUID *)&te->uuid, &status)) { - *ltep = te->next; - lock_ReleaseMutex(&tokenEventLock); - memcpy(sessionKey, te->sessionKey, - sizeof(te->sessionKey)); - free(te); - return TRUE; - } - ltep = &te->next; - te = te->next; - } - lock_ReleaseMutex(&tokenEventLock); - return FALSE; + lock_ObtainMutex(&tokenEventLock); + te = tokenEvents; + ltep = &tokenEvents; + while (te) { + if (UuidEqual((UUID *)&uuid, (UUID *)&te->uuid, &status)) { + *ltep = te->next; + lock_ReleaseMutex(&tokenEventLock); + memcpy(sessionKey, te->sessionKey, + sizeof(te->sessionKey)); + free(te); + return TRUE; + } + ltep = &te->next; + te = te->next; + } + lock_ReleaseMutex(&tokenEventLock); + return FALSE; } /* @@ -104,117 +106,137 @@ long AFSRPC_SetToken( afs_uuid_t uuid, unsigned char __RPC_FAR sessionKey[8]) { - cm_RegisterNewTokenEvent(uuid, sessionKey); - return 0; + cm_RegisterNewTokenEvent(uuid, sessionKey); + return 0; } long AFSRPC_GetToken( afs_uuid_t uuid, unsigned char __RPC_FAR sessionKey[8]) { - BOOL found; + BOOL found; - found = cm_FindTokenEvent(uuid, sessionKey); - if (!found) - return 1; + found = cm_FindTokenEvent(uuid, sessionKey); + if (!found) + return 1; - return 0; + return 0; } void __RPC_FAR * __RPC_USER midl_user_allocate (size_t cBytes) { - return ((void __RPC_FAR *) malloc(cBytes)); + return ((void __RPC_FAR *) malloc(cBytes)); } void __RPC_USER midl_user_free(void __RPC_FAR * p) { - free(p); + free(p); } void RpcListen() { - RPC_STATUS status; - char *task; - RPC_BINDING_VECTOR *ptrBindingVector = NULL; - BOOLEAN ifaceRegistered = FALSE; - BOOLEAN epRegistered = FALSE; + RPC_STATUS status; + char *task; + RPC_BINDING_VECTOR *ptrBindingVector = NULL; + BOOLEAN ifaceRegistered = FALSE; + BOOLEAN epRegistered = FALSE; #ifdef NOOSIDEBUGSERVER /* Use All Protseqs already done in OSI */ - status = RpcServerUseAllProtseqs(1, NULL); - if (status != RPC_S_OK) { - task = "Use All Protocol Sequences"; - goto cleanup; - } + status = RpcServerUseAllProtseqs(1, NULL); + if (status != RPC_S_OK) { + task = "Use All Protocol Sequences"; + goto cleanup; + } #endif /* NOOSIDEBUGSERVER */ - status = RpcServerRegisterIf(afsrpc_v1_0_s_ifspec, NULL, NULL); - if (status != RPC_S_OK) { - task = "Register Interface"; - goto cleanup; - } - ifaceRegistered = TRUE; + status = RpcServerRegisterIf(afsrpc_v1_0_s_ifspec, NULL, NULL); + if (status != RPC_S_OK) { + task = "Register Interface"; + goto cleanup; + } + ifaceRegistered = TRUE; - status = RpcServerInqBindings(&ptrBindingVector); - if (status != RPC_S_OK) { - task = "Inquire Bindings"; - goto cleanup; - } + status = RpcServerInqBindings(&ptrBindingVector); + if (status != RPC_S_OK) { + task = "Inquire Bindings"; + goto cleanup; + } - status = RpcServerRegisterAuthInfo(NULL, RPC_C_AUTHN_WINNT, NULL, NULL); - if (status != RPC_S_OK) { - task = "Register Authentication Info"; - goto cleanup; - } + status = RpcServerRegisterAuthInfo(NULL, RPC_C_AUTHN_WINNT, NULL, NULL); + if (status != RPC_S_OK) { + task = "Register Authentication Info"; + goto cleanup; + } - status = RpcEpRegister(afsrpc_v1_0_s_ifspec, ptrBindingVector, - NULL, "AFS session key interface"); - if (status != RPC_S_OK) { - task = "Register Endpoints"; - goto cleanup; - } - epRegistered = TRUE; + status = RpcEpRegister(afsrpc_v1_0_s_ifspec, ptrBindingVector, + NULL, "AFS session key interface"); + if (status != RPC_S_OK) { + task = "Register Endpoints"; + goto cleanup; + } + epRegistered = TRUE; - afsi_log("RPC server listening"); + afsi_log("RPC server listening"); - status = RpcServerListen(OSI_MAXRPCCALLS, OSI_MAXRPCCALLS, 0); - if (status != RPC_S_OK) { - task = "Server Listen"; - } + status = RpcServerListen(OSI_MAXRPCCALLS, OSI_MAXRPCCALLS, 0); + if (status != RPC_S_OK) { + task = "Server Listen"; + } cleanup: - if (epRegistered) - (void) RpcEpUnregister(afsrpc_v1_0_s_ifspec, ptrBindingVector, - NULL); + if (epRegistered) + (void) RpcEpUnregister(afsrpc_v1_0_s_ifspec, ptrBindingVector, + NULL); - if (ptrBindingVector) - (void) RpcBindingVectorFree(&ptrBindingVector); + if (ptrBindingVector) + (void) RpcBindingVectorFree(&ptrBindingVector); - if (ifaceRegistered) - (void) RpcServerUnregisterIf(afsrpc_v1_0_s_ifspec, NULL, FALSE); + if (ifaceRegistered) + (void) RpcServerUnregisterIf(afsrpc_v1_0_s_ifspec, NULL, FALSE); - if (status != RPC_S_OK) - afsi_log("RPC problem, code %d for %s", status, task); + if (status != RPC_S_OK) + afsi_log("RPC problem, code %d for %s", status, task); + else + afsi_log("RPC shutdown"); - return; + if (rpc_ShutdownEvent != NULL) + thrd_SetEvent(rpc_ShutdownEvent); + return; } long RpcInit() { - LONG status = ERROR_SUCCESS; - HANDLE listenThread; - ULONG listenThreadID = 0; + LONG status = ERROR_SUCCESS; + HANDLE listenThread; + ULONG listenThreadID = 0; + char * name = "afsd_rpc_ShutdownEvent"; - lock_InitializeMutex(&tokenEventLock, "token event lock"); + lock_InitializeMutex(&tokenEventLock, "token event lock"); - listenThread = CreateThread(NULL, 0, (PTHREAD_START_ROUTINE)RpcListen, - 0, 0, &listenThreadID); + rpc_ShutdownEvent = thrd_CreateEvent(NULL, FALSE, FALSE, name); + if ( GetLastError() == ERROR_ALREADY_EXISTS ) + afsi_log("Event Object Already Exists: %s", name); - if (listenThread == NULL) { - status = GetLastError(); - } - CloseHandle(listenThread); + listenThread = CreateThread(NULL, 0, (PTHREAD_START_ROUTINE)RpcListen, + 0, 0, &listenThreadID); - return status; + if (listenThread == NULL) { + status = GetLastError(); + } + CloseHandle(listenThread); + + return status; } + +void RpcShutdown(void) +{ + RpcMgmtStopServerListening(NULL); + + if (rpc_ShutdownEvent != NULL) { + thrd_WaitForSingleObject_Event(rpc_ShutdownEvent, INFINITE); + CloseHandle(rpc_ShutdownEvent); + } +} + diff --git a/src/WINNT/afsd/cm_rpc.h b/src/WINNT/afsd/cm_rpc.h index beba2e3d7f..8571ad7827 100644 --- a/src/WINNT/afsd/cm_rpc.h +++ b/src/WINNT/afsd/cm_rpc.h @@ -19,6 +19,6 @@ void cm_RegisterNewTokenEvent(afs_uuid_t uuid, char sessionKey[8]); BOOL cm_FindTokenEvent(afs_uuid_t uuid, char sessionKey[8]); -extern long RpcInit(); - +extern long RpcInit(void); +extern void RpcShutdown(void); #endif /* __CM_RPC_H__ */ diff --git a/src/WINNT/afsd/cm_scache.c b/src/WINNT/afsd/cm_scache.c index 2c15aa16b7..74cc3cb549 100644 --- a/src/WINNT/afsd/cm_scache.c +++ b/src/WINNT/afsd/cm_scache.c @@ -844,7 +844,7 @@ void cm_MergeStatus(cm_scache_t *scp, AFSFetchStatus *statusp, AFSVolSync *volp, statusp->FileType = CM_SCACHETYPE_DIRECTORY; statusp->LinkCount = scp->linkCount; statusp->Length = cm_fakeDirSize; - statusp->DataVersion = cm_fakeDirVersion; + statusp->DataVersion = scp->dataVersion; statusp->Author = 0x1; statusp->Owner = 0x0; statusp->CallerAccess = 0x9; diff --git a/src/WINNT/afsd/fs.c b/src/WINNT/afsd/fs.c index 1f3630eec0..f33ffb970a 100644 --- a/src/WINNT/afsd/fs.c +++ b/src/WINNT/afsd/fs.c @@ -18,10 +18,13 @@ #include #include #include +#include #include #include #include +#include +#include #include "fs.h" #include "fs_utils.h" @@ -31,10 +34,13 @@ #define MAXHOSTS 13 #define OMAXHOSTS 8 +#define MAXCELLHOSTS 8 #define MAXNAME 100 #define MAXSIZE 2048 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */ #define VMSGSIZE 128 /* size of msg buf in volume hdr */ +#define MAXCELLCHARS 64 +#define MAXHOSTCHARS 64 static char space[MAXSIZE]; static char tspace[1024]; @@ -43,28 +49,30 @@ static char tspace[1024]; static struct ubik_client *uclient; #endif /* not WIN32 */ -static MemDumpCmd(struct cmd_syndesc *asp); -static CSCPolicyCmd(struct cmd_syndesc *asp); +static int GetClientAddrsCmd(struct cmd_syndesc *asp, char *arock); +static int SetClientAddrsCmd(struct cmd_syndesc *asp, char *arock); +static int FlushMountCmd(struct cmd_syndesc *asp, char *arock); +static int RxStatProcCmd(struct cmd_syndesc *asp, char *arock); +static int RxStatPeerCmd(struct cmd_syndesc *asp, char *arock); + +extern struct cmd_syndesc *cmd_CreateSyntax(); + +static int MemDumpCmd(struct cmd_syndesc *asp, char *arock); +static int CSCPolicyCmd(struct cmd_syndesc *asp, char *arock); extern afs_int32 VL_GetEntryByNameO(); static char pn[] = "fs"; static int rxInitDone = 0; -static GetCellName(); - -#define MAXCELLCHARS 64 -#define MAXHOSTCHARS 64 -#define MAXHOSTSPERCELL 8 - struct afsconf_cell { - char name[MAXCELLCHARS]; - short numServers; - short flags; - struct sockaddr_in hostAddr[MAXHOSTSPERCELL]; - char hostName[MAXHOSTSPERCELL][MAXHOSTCHARS]; - char *linkedCell; -}; + char name[MAXCELLCHARS]; + short numServers; + short flags; + struct sockaddr_in hostAddr[MAXCELLHOSTS]; + char hostName[MAXCELLHOSTS][MAXHOSTCHARS]; + char *linkedCell; +}; /* @@ -76,9 +84,9 @@ struct afsconf_cell { typedef char sec_rgy_name_t[1025]; /* A DCE definition */ struct Acl { - int dfs; /* Originally true if a dfs acl; now also the type - of the acl (1, 2, or 3, corresponding to object, - initial dir, or initial object). */ + int dfs; /* Originally true if a dfs acl; now also the type + * of the acl (1, 2, or 3, corresponding to object, + * initial dir, or initial object). */ sec_rgy_name_t cell; /* DFS cell name */ int nplus; int nminus; @@ -92,27 +100,17 @@ struct AclEntry { afs_int32 rights; }; -void ZapAcl (acl) - struct Acl *acl; { +static void +ZapAcl (struct Acl *acl) +{ + if (!acl) + return; + ZapList(acl->pluslist); ZapList(acl->minuslist); free(acl); } -foldcmp (a, b) - register char *a; - register char *b; { - register char t, u; - while (1) { - t = *a++; - u = *b++; - if (t >= 'A' && t <= 'Z') t += 0x20; - if (u >= 'A' && u <= 'Z') u += 0x20; - if (t != u) return 1; - if (t == 0) return 0; - } -} - /* * Mods for the AFS/DFS protocol translator. * @@ -144,15 +142,15 @@ foldcmp (a, b) * Offset of -id switch in command structure for various commands. * The -if switch is the next switch always. */ -int parm_setacl_id, parm_copyacl_id, parm_listacl_id; +static int parm_setacl_id, parm_copyacl_id, parm_listacl_id; /* * Determine whether either the -id or -if switches are present, and * return 0, 1 or 2, as appropriate. Abort if both switches are present. */ -int getidf(as, id) - struct cmd_syndesc *as; - int id; /* Offset of -id switch; -if is next switch */ +/* int id; Offset of -id switch; -if is next switch */ +static int +getidf(struct cmd_syndesc *as, int id) { int idf = 0; @@ -163,8 +161,7 @@ int getidf(as, id) idf |= 2; } if (idf == 3) { - fprintf - (stderr, + fprintf(stderr, "%s: you may specify either -id or -if, but not both switches\n", pn); exit(1); @@ -172,50 +169,93 @@ int getidf(as, id) return idf; } -void PRights (arights, dfs) - register afs_int32 arights; - int dfs; +static int +PRights(afs_int32 arights, int dfs) { if (!dfs) { - if (arights & PRSFS_READ) printf("r"); - if (arights & PRSFS_LOOKUP) printf("l"); - if (arights & PRSFS_INSERT) printf("i"); - if (arights & PRSFS_DELETE) printf("d"); - if (arights & PRSFS_WRITE) printf("w"); - if (arights & PRSFS_LOCK) printf("k"); - if (arights & PRSFS_ADMINISTER) printf("a"); - if (arights & PRSFS_USR0) printf("A"); - if (arights & PRSFS_USR1) printf("B"); - if (arights & PRSFS_USR2) printf("C"); - if (arights & PRSFS_USR3) printf("D"); - if (arights & PRSFS_USR4) printf("E"); - if (arights & PRSFS_USR5) printf("F"); - if (arights & PRSFS_USR6) printf("G"); - if (arights & PRSFS_USR7) printf("H"); + if (arights & PRSFS_READ) + printf("r"); + if (arights & PRSFS_LOOKUP) + printf("l"); + if (arights & PRSFS_INSERT) + printf("i"); + if (arights & PRSFS_DELETE) + printf("d"); + if (arights & PRSFS_WRITE) + printf("w"); + if (arights & PRSFS_LOCK) + printf("k"); + if (arights & PRSFS_ADMINISTER) + printf("a"); + if (arights & PRSFS_USR0) + printf("A"); + if (arights & PRSFS_USR1) + printf("B"); + if (arights & PRSFS_USR2) + printf("C"); + if (arights & PRSFS_USR3) + printf("D"); + if (arights & PRSFS_USR4) + printf("E"); + if (arights & PRSFS_USR5) + printf("F"); + if (arights & PRSFS_USR6) + printf("G"); + if (arights & PRSFS_USR7) + printf("H"); } else { - if (arights & DFS_READ) printf("r"); else printf("-"); - if (arights & DFS_WRITE) printf("w"); else printf("-"); - if (arights & DFS_EXECUTE) printf("x"); else printf("-"); - if (arights & DFS_CONTROL) printf("c"); else printf("-"); - if (arights & DFS_INSERT) printf("i"); else printf("-"); - if (arights & DFS_DELETE) printf("d"); else printf("-"); - if (arights & (DFS_USRALL)) printf("+"); - if (arights & DFS_USR0) printf("A"); - if (arights & DFS_USR1) printf("B"); - if (arights & DFS_USR2) printf("C"); - if (arights & DFS_USR3) printf("D"); - if (arights & DFS_USR4) printf("E"); - if (arights & DFS_USR5) printf("F"); - if (arights & DFS_USR6) printf("G"); - if (arights & DFS_USR7) printf("H"); + if (arights & DFS_READ) + printf("r"); + else + printf("-"); + if (arights & DFS_WRITE) + printf("w"); + else + printf("-"); + if (arights & DFS_EXECUTE) + printf("x"); + else + printf("-"); + if (arights & DFS_CONTROL) + printf("c"); + else + printf("-"); + if (arights & DFS_INSERT) + printf("i"); + else + printf("-"); + if (arights & DFS_DELETE) + printf("d"); + else + printf("-"); + if (arights & (DFS_USRALL)) + printf("+"); + if (arights & DFS_USR0) + printf("A"); + if (arights & DFS_USR1) + printf("B"); + if (arights & DFS_USR2) + printf("C"); + if (arights & DFS_USR3) + printf("D"); + if (arights & DFS_USR4) + printf("E"); + if (arights & DFS_USR5) + printf("F"); + if (arights & DFS_USR6) + printf("G"); + if (arights & DFS_USR7) + printf("H"); } + return 0; } /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */ -static int InAFS(apath) -register char *apath; { +static int +InAFS(char *apath) +{ struct ViceIoctl blob; - register afs_int32 code; + afs_int32 code; blob.in_size = 0; blob.out_size = MAXSIZE; @@ -223,15 +263,17 @@ register char *apath; { code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1); if (code) { - if ((errno == EINVAL) || (errno == ENOENT)) return 0; + if ((errno == EINVAL) || (errno == ENOENT)) + return 0; } return 1; } /* return a static pointer to a buffer */ -static char *Parent(apath) -char *apath; { - register char *tp; +static char * +Parent(char *apath) +{ + char *tp; strcpy(tspace, apath); tp = strrchr(tspace, '\\'); if (tp) { @@ -246,14 +288,12 @@ char *apath; { enum rtype {add, destroy, deny}; -afs_int32 Convert(arights, dfs, rtypep) - register char *arights; - int dfs; - enum rtype *rtypep; +static afs_int32 +Convert(char *arights, int dfs, enum rtype *rtypep) { - register int i, len; + int i, len; afs_int32 mode; - register char tc; + char tc; *rtypep = add; /* add rights, by default */ @@ -262,14 +302,25 @@ afs_int32 Convert(arights, dfs, rtypep) *rtypep = deny; return 0; } - if (!strcmp(arights,"read")) return DFS_READ | DFS_EXECUTE; - if (!strcmp(arights, "write")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE; - if (!strcmp(arights, "all")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE | DFS_CONTROL; + if (!strcmp(arights,"read")) + return DFS_READ | DFS_EXECUTE; + if (!strcmp(arights, "write")) + return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | + DFS_WRITE; + if (!strcmp(arights, "all")) + return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | + DFS_WRITE | DFS_CONTROL; } else { - if (!strcmp(arights,"read")) return PRSFS_READ | PRSFS_LOOKUP; - if (!strcmp(arights, "write")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK; - if (!strcmp(arights, "mail")) return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP; - if (!strcmp(arights, "all")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER; + if (!strcmp(arights,"read")) + return PRSFS_READ | PRSFS_LOOKUP; + if (!strcmp(arights, "write")) + return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | + PRSFS_WRITE | PRSFS_LOCK; + if (!strcmp(arights, "mail")) + return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP; + if (!strcmp(arights, "all")) + return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | + PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER; } if (!strcmp(arights, "none")) { *rtypep = destroy; /* Remove entire entry */ @@ -280,43 +331,75 @@ afs_int32 Convert(arights, dfs, rtypep) for(i=0;iname, aname)) return alist; + if (!strcasecmp(alist->name, aname)) + return alist; alist = alist->next; } return 0; } /* if no parm specified in a particular slot, set parm to be "." instead */ -static void SetDotDefault(aitemp) -struct cmd_item **aitemp; { - register struct cmd_item *ti; - if (*aitemp) return; /* already has value */ +static void +SetDotDefault(struct cmd_item **aitemp) +{ + struct cmd_item *ti; + if (*aitemp) + return; /* already has value */ /* otherwise, allocate an item representing "." */ ti = (struct cmd_item *) malloc(sizeof(struct cmd_item)); + assert(ti); ti->next = (struct cmd_item *) 0; ti->data = (char *) malloc(2); + assert(ti->data); strcpy(ti->data, "."); *aitemp = ti; } -void ChangeList (al, plus, aname, arights) - struct Acl *al; - char *aname; - afs_int32 arights, plus; { +static void +ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights) +{ struct AclEntry *tlist; tlist = (plus ? al->pluslist : al->minuslist); tlist = FindList (tlist, aname); @@ -365,6 +452,7 @@ void ChangeList (al, plus, aname, arights) } /* Otherwise we make a new item and plug in the new data. */ tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry)); + assert(tlist); strcpy(tlist->name, aname); tlist->rights = arights; if (plus) { @@ -373,27 +461,27 @@ void ChangeList (al, plus, aname, arights) al->nplus++; if (arights == 0 || arights == -1) al->nplus -= PruneList(&al->pluslist, al->dfs); - } - else { + } else { tlist->next = al->minuslist; al->minuslist = tlist; al->nminus++; - if (arights == 0) al->nminus -= PruneList(&al->minuslist, al->dfs); + if (arights == 0) + al->nminus -= PruneList(&al->minuslist, al->dfs); } } -void ZapList (alist) - struct AclEntry *alist; { - register struct AclEntry *tp, *np; +static void +ZapList (struct AclEntry *alist) +{ + struct AclEntry *tp, *np; for (tp = alist; tp; tp = np) { np = tp->next; free(tp); } } -int PruneList (ae, dfs) - struct AclEntry **ae; - int dfs; +static int +PruneList (struct AclEntry **ae, int dfs) { struct AclEntry **lp; struct AclEntry *te, *ne; @@ -406,8 +494,7 @@ int PruneList (ae, dfs) ne = te->next; free(te); ctr++; - } - else { + } else { ne = te->next; lp = &te->next; } @@ -415,9 +502,11 @@ int PruneList (ae, dfs) return ctr; } -char *SkipLine (astr) - register char *astr; { - while (*astr !='\n') astr++; +static char * +SkipLine (char *astr) +{ + while (*astr !='\n') + astr++; astr++; return astr; } @@ -429,13 +518,14 @@ char *SkipLine (astr) * assume that the acl is AFS: for DFS, the user can always resort to * acl_edit, but for AFS there may be no other way out). */ -struct Acl *EmptyAcl(astr) - char *astr; +static struct Acl * +EmptyAcl(char *astr) { - register struct Acl *tp; + struct Acl *tp; int junk; tp = (struct Acl *)malloc(sizeof (struct Acl)); + assert(tp); tp->nplus = tp->nminus = 0; tp->pluslist = tp->minuslist = 0; tp->dfs = 0; @@ -443,14 +533,16 @@ struct Acl *EmptyAcl(astr) return tp; } -struct Acl *ParseAcl (astr) - char *astr; { +static struct Acl * +ParseAcl (char *astr) +{ int nplus, nminus, i, trights; char tname[MAXNAME]; struct AclEntry *first, *last, *tl; struct Acl *ta; ta = (struct Acl *) malloc (sizeof (struct Acl)); + assert(ta); ta->dfs = 0; sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell); astr = SkipLine(astr); @@ -466,11 +558,14 @@ struct Acl *ParseAcl (astr) sscanf(astr, "%100s %d", tname, &trights); astr = SkipLine(astr); tl = (struct AclEntry *) malloc(sizeof (struct AclEntry)); - if (!first) first = tl; + assert(tl); + if (!first) + first = tl; strcpy(tl->name, tname); tl->rights = trights; tl->next = 0; - if (last) last->next = tl; + if (last) + last->next = tl; last = tl; } ta->pluslist = first; @@ -481,11 +576,14 @@ struct Acl *ParseAcl (astr) sscanf(astr, "%100s %d", tname, &trights); astr = SkipLine(astr); tl = (struct AclEntry *) malloc(sizeof (struct AclEntry)); - if (!first) first = tl; + assert(tl); + if (!first) + first = tl; strcpy(tl->name, tname); tl->rights = trights; tl->next = 0; - if (last) last->next = tl; + if (last) + last->next = tl; last = tl; } ta->minuslist = first; @@ -493,26 +591,28 @@ struct Acl *ParseAcl (astr) return ta; } -void PrintStatus(status, name, motd, offmsg) - VolumeStatus *status; - char *name; - char *motd; - char *offmsg; { +static int +PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg) +{ printf("Volume status for vid = %u named %s\n",status->Vid, name); if (*offmsg != 0) printf("Current offline message is %s\n",offmsg); if (*motd != 0) printf("Current message of the day is %s\n",motd); printf("Current disk quota is "); - if (status->MaxQuota != 0) printf("%d\n", status->MaxQuota); - else printf("unlimited\n"); + if (status->MaxQuota != 0) + printf("%d\n", status->MaxQuota); + else + printf("unlimited\n"); printf("Current blocks used are %d\n",status->BlocksInUse); - printf("The partition has %d blocks available out of %d\n\n",status->PartBlocksAvail, status->PartMaxBlocks); + printf("The partition has %d blocks available out of %d\n\n", + status->PartBlocksAvail, status->PartMaxBlocks); + return 0; } -void QuickPrintStatus(status, name) -VolumeStatus *status; -char *name; { +static int +QuickPrintStatus(VolumeStatus *status, char *name) +{ double QuotaUsed =0.0; double PartUsed =0.0; int WARN = 0; @@ -527,23 +627,24 @@ char *name; { if (QuotaUsed > 90.0){ printf(" %5.0f%%<<", QuotaUsed); WARN = 1; - } - else printf(" %5.0f%% ", QuotaUsed); + } else + printf(" %5.0f%% ", QuotaUsed); PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0)); if (PartUsed > 97.0){ printf(" %9.0f%%<<", PartUsed); WARN = 1; - } - else printf(" %9.0f%% ", PartUsed); + } else + printf(" %9.0f%% ", PartUsed); if (WARN){ - printf("\t< 90.0){ printf(" %4.0f%%<<", PartUsed); WARN = 1; - } - else printf(" %4.0f%% ", PartUsed); + } else + printf(" %4.0f%% ", PartUsed); if (WARN){ - printf("\t<dfs) sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell); - else dfsstring[0] = '\0'; + if (acl->dfs) + sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell); + else + dfsstring[0] = '\0'; sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus); - for(tp = acl->pluslist;tp;tp=tp->next) { + for (tp = acl->pluslist;tp;tp=tp->next) { sprintf(tstring, "%s %d\n", tp->name, tp->rights); strcat(mydata, tstring); } - for(tp = acl->minuslist;tp;tp=tp->next) { + for (tp = acl->minuslist;tp;tp=tp->next) { sprintf(tstring, "%s %d\n", tp->name, tp->rights); strcat(mydata, tstring); } @@ -631,7 +736,9 @@ BOOL IsAdmin (void) } psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize); + assert(psidAdmin); pszRefDomain = (char *)malloc(dwSize2); + assert(pszRefDomain); if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) { /* We can't lookup the group now even though we looked it up earlier. @@ -655,6 +762,7 @@ BOOL IsAdmin (void) GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize); pGroups = (PTOKEN_GROUPS)malloc(dwSize); + assert(pGroups); /* Allocate that buffer, and read in the list of groups. */ if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize)) @@ -687,6 +795,7 @@ BOOL IsAdmin (void) GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize); pTokenUser = (PTOKEN_USER)malloc(dwSize); + assert(pTokenUser); if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize)) gle = GetLastError(); @@ -718,19 +827,24 @@ BOOL IsAdmin (void) return fAdmin; } -static SetACLCmd(as) -struct cmd_syndesc *as; { - register afs_int32 code; +static int +SetACLCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; - struct Acl *ta; - register struct cmd_item *ti, *ui; + struct Acl *ta = 0; + struct cmd_item *ti, *ui; int plusp; afs_int32 rights; int clear; int idf = getidf(as, parm_setacl_id); - if (as->parms[2].items) clear=1; - else clear=0; + int error = 0; + + if (as->parms[2].items) + clear = 1; + else + clear = 0; plusp = !(as->parms[3].items); for(ti=as->parms[0].items; ti;ti=ti->next) { blob.out_size = MAXSIZE; @@ -739,34 +853,47 @@ struct cmd_syndesc *as; { code = pioctl(ti->data, VIOCGETAL, &blob, 1); if (code) { Die(errno, ti->data); - return 1; + error = 1; + continue; } + if (ta) + ZapAcl(ta); ta = ParseAcl(space); if (!plusp && ta->dfs) { fprintf(stderr, "fs: %s: you may not use the -negative switch with DFS acl's.\n%s", ti->data, "(you may specify \"null\" to revoke all rights, however)\n"); - return 1; + error = 1; + continue; } - if (clear) ta = EmptyAcl(space); - else ta = ParseAcl(space); - CleanAcl(ta); + if (ta) + ZapAcl(ta); + if (clear) + ta = EmptyAcl(space); + else + ta = ParseAcl(space); + CleanAcl(ta, ti->data); for(ui=as->parms[1].items; ui; ui=ui->next->next) { enum rtype rtype; if (!ui->next) { - fprintf(stderr,"%s: Missing second half of user/access pair.\n", pn); + fprintf(stderr, + "%s: Missing second half of user/access pair.\n", pn); + ZapAcl(ta); return 1; } rights = Convert(ui->next->data, ta->dfs, &rtype); if (rtype == destroy && !ta->dfs) { - if (!FindList(ta->pluslist, ui->data)) { - fprintf(stderr,"%s: Invalid arg (%s doesn't exist in the current acl)\n", pn, ui->data); - return 1; - } + struct AclEntry *tlist; + + tlist = (plusp ? ta->pluslist : ta->minuslist); + if (!FindList(tlist, ui->data)) + continue; } - if (rtype == deny && !ta->dfs) plusp = 0; - if (rtype == destroy && ta->dfs) rights = -1; + if (rtype == deny && !ta->dfs) + plusp = 0; + if (rtype == destroy && ta->dfs) + rights = -1; ChangeList(ta, plusp, ui->data, rights); } blob.in = AclToString(ta); @@ -810,35 +937,42 @@ struct cmd_syndesc *as; { " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n"); } } else { - fprintf(stderr,"%s: Invalid argument, possible reasons include:\n", pn); + fprintf(stderr, + "%s: Invalid argument, possible reasons include:\n", + pn); fprintf(stderr,"\t-File not in AFS\n"); - fprintf(stderr,"\t-Too many users on access control list\n"); - fprintf(stderr,"\t-Tried to add non-existent user to access control list\n"); + fprintf(stderr, + "\t-Too many users on access control list\n"); + fprintf(stderr, + "\t-Tried to add non-existent user to access control list\n"); } - return 1; - } - else { + } else { Die(errno, ti->data); - continue; - } - } + } + error = 1; + } } - return 0; + if (ta) + ZapAcl(ta); + return error; } - -static CopyACLCmd(as) -struct cmd_syndesc *as; { - register afs_int32 code; +static int +CopyACLCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; - struct Acl *fa, *ta; + struct Acl *fa, *ta = 0; struct AclEntry *tp; - register struct cmd_item *ti; + struct cmd_item *ti; int clear; int idf = getidf(as, parm_copyacl_id); + int error = 0; - if (as->parms[2].items) clear=1; - else clear=0; + if (as->parms[2].items) + clear=1; + else + clear=0; blob.out_size = MAXSIZE; blob.in_size = idf; blob.in = blob.out = space; @@ -848,7 +982,7 @@ struct cmd_syndesc *as; { return 1; } fa = ParseAcl(space); - CleanAcl(fa); + CleanAcl(fa, as->parms[0].items->data); for (ti=as->parms[1].items; ti;ti=ti->next) { blob.out_size = MAXSIZE; blob.in_size = idf; @@ -856,19 +990,30 @@ struct cmd_syndesc *as; { code = pioctl(ti->data, VIOCGETAL, &blob, 1); if (code) { Die(errno, ti->data); - return 1; + error = 1; + continue; } - if (clear) ta = EmptyAcl(space); - else ta = ParseAcl(space); - CleanAcl(ta); + if (ta) + ZapAcl(ta); + if (clear) + ta = EmptyAcl(space); + else + ta = ParseAcl(space); + CleanAcl(ta, ti->data); if (ta->dfs != fa->dfs) { - fprintf(stderr, "fs: incompatible file system types: acl not copied to %s; aborted\n", ti->data); - goto next; + fprintf(stderr, + "%s: incompatible file system types: acl not copied to %s; aborted\n", + pn, ti->data); + error = 1; + continue; } if (ta->dfs) { if (! clear && strcmp(ta->cell, fa->cell) != 0) { - fprintf(stderr, "fs: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n", ti->data); - goto next; + fprintf(stderr, + "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n", + pn, ti->data); + error = 1; + continue; } strcpy(ta->cell, fa->cell); } @@ -882,40 +1027,73 @@ struct cmd_syndesc *as; { code = pioctl(ti->data, VIOCSETAL, &blob, 1); if (code) { if (errno == EINVAL) { - fprintf(stderr,"%s: Invalid argument, possible reasons include:\n", pn); + fprintf(stderr, + "%s: Invalid argument, possible reasons include:\n", pn); fprintf(stderr,"\t-File not in AFS\n"); - return 1; - } - else { + } else { Die(errno, ti->data); - goto next; } + error = 1; } - next: + } + if (ta) ZapAcl(ta); - } - return 0; + ZapAcl(fa); + return error; } +/* pioctl() call to get the cellname of a pathname */ +static afs_int32 +GetCell(char *fname, char *cellname) +{ + afs_int32 code; + struct ViceIoctl blob; + blob.in_size = 0; + blob.out_size = MAXCELLCHARS; + blob.out = cellname; -/* tell if a name is 23 or -45 (digits or minus digits), which are bad names we must prune */ -static BadName(aname) -register char *aname; { - register int tc; - while(tc = *aname++) { + code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1); + return code ? errno : 0; +} + +/* Check if a username is valid: If it contains only digits (or a + * negative sign), then it might be bad. We then query the ptserver + * to see. + */ +static int +BadName(char *aname, char *fname) +{ + afs_int32 tc, code, id; + char *nm; + char cell[MAXCELLCHARS]; + + for ( nm = aname; tc = *nm; nm++) { /* all must be '-' or digit to be bad */ - if (tc != '-' && (tc < '0' || tc > '9')) return 0; + if (tc != '-' && (tc < '0' || tc > '9')) + return 0; } - return 1; + + /* Go to the PRDB and see if this all number username is valid */ + code = GetCell(fname, cell); + if (code) + return 0; + + pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell); + code = pr_SNameToId(aname, &id); + pr_End(); + + /* 1=>Not-valid; 0=>Valid */ + return ((!code && (id == ANONYMOUSID)) ? 1 : 0); } /* clean up an access control list of its bad entries; return 1 if we made any changes to the list, and 0 otherwise */ -int CleanAcl(aa) -struct Acl *aa; { - register struct AclEntry *te, **le, *ne; +static int +CleanAcl(struct Acl *aa, char *fname) +{ + struct AclEntry *te, **le, *ne; int changes; /* Don't correct DFS ACL's for now */ @@ -927,28 +1105,26 @@ struct Acl *aa; { le = &aa->pluslist; for(te = aa->pluslist; te; te=ne) { ne = te->next; - if (BadName(te->name)) { + if (BadName(te->name, fname)) { /* zap this dude */ *le = te->next; aa->nplus--; free(te); changes++; - } - else { + } else { le = &te->next; } } le = &aa->minuslist; for(te = aa->minuslist; te; te=ne) { ne = te->next; - if (BadName(te->name)) { + if (BadName(te->name, fname)) { /* zap this dude */ *le = te->next; aa->nminus--; free(te); changes++; - } - else { + } else { le = &te->next; } } @@ -957,14 +1133,16 @@ struct Acl *aa; { /* clean up an acl to not have bogus entries */ -static CleanACLCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; - register struct Acl *ta; +static int +CleanACLCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; + struct Acl *ta = 0; struct ViceIoctl blob; int changes; - register struct cmd_item *ti; - register struct AclEntry *te; + struct cmd_item *ti; + struct AclEntry *te; + int error = 0; SetDotDefault(&as->parms[0].items); for(ti=as->parms[0].items; ti; ti=ti->next) { @@ -974,18 +1152,22 @@ register struct cmd_syndesc *as; { code = pioctl(ti->data, VIOCGETAL, &blob, 1); if (code) { Die(errno, ti->data); + error = 1; continue; } + if (ta) + ZapAcl(ta); ta = ParseAcl(space); if (ta->dfs) { fprintf(stderr, "%s: cleanacl is not supported for DFS access lists.\n", pn); - return 1; + error = 1; + continue; } - changes = CleanAcl(ta); + changes = CleanAcl(ta, ti->data); if (changes) { /* now set the acl */ @@ -995,21 +1177,25 @@ register struct cmd_syndesc *as; { code = pioctl(ti->data, VIOCSETAL, &blob, 1); if (code) { if (errno == EINVAL) { - fprintf(stderr,"%s: Invalid argument, possible reasons include\n", pn); + fprintf(stderr, + "%s: Invalid argument, possible reasons include\n", + pn); fprintf(stderr,"%s: File not in vice or\n", pn); - fprintf(stderr,"%s: Too many users on access control list or\n", pn); - return 1; - } - else { + fprintf(stderr, + "%s: Too many users on access control list or\n", + pn); + } else { Die(errno, ti->data); - continue; } + error = 1; + continue; } /* now list the updated acl */ printf("Access list for %s is now\n", ti->data); if (ta->nplus > 0) { - if (!ta->dfs) printf("Normal rights:\n"); + if (!ta->dfs) + printf("Normal rights:\n"); for(te = ta->pluslist;te;te=te->next) { printf(" %s ", te->name); PRights(te->rights, ta->dfs); @@ -1024,22 +1210,26 @@ register struct cmd_syndesc *as; { printf("\n"); } } - if (ti->next) printf("\n"); - } - else + if (ti->next) + printf("\n"); + } else printf("Access list for %s is fine.\n", ti->data); } - return 0; + if (ta) + ZapAcl(ta); + return error; } -static ListACLCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; - register struct Acl *ta; +static int +ListACLCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; + struct Acl *ta = 0; struct ViceIoctl blob; struct AclEntry *te; - register struct cmd_item *ti; + struct cmd_item *ti; int idf = getidf(as, parm_listacl_id); + int error = 0; SetDotDefault(&as->parms[0].items); for(ti=as->parms[0].items; ti; ti=ti->next) { @@ -1050,6 +1240,7 @@ register struct cmd_syndesc *as; { code = pioctl(ti->data, VIOCGETAL, &blob, 1); if (code) { Die(errno, ti->data); + error = 1; continue; } ta = ParseAcl(space); @@ -1072,7 +1263,8 @@ register struct cmd_syndesc *as; { } separator = ta->dfs? DFS_SEPARATOR : ' '; if (ta->nplus > 0) { - if (!ta->dfs) printf("Normal rights:\n"); + if (!ta->dfs) + printf("Normal rights:\n"); for(te = ta->pluslist;te;te=te->next) { printf(" %s%c", te->name, separator); PRights(te->rights, ta->dfs); @@ -1087,73 +1279,80 @@ register struct cmd_syndesc *as; { printf("\n"); } } - if (ti->next) printf("\n"); + if (ti->next) + printf("\n"); + ZapAcl(ta); } - return 0; + return error; } -static FlushVolumeCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +FlushVolumeCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; - register struct cmd_item *ti; + struct cmd_item *ti; + int error = 0; + SetDotDefault(&as->parms[0].items); for(ti=as->parms[0].items; ti; ti=ti->next) { blob.in_size = blob.out_size = 0; code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0); if (code) { - fprintf(stderr, "Error flushing volume\n"); - Die(errno,ti->data); + fprintf(stderr, "Error flushing volume "); + perror(ti->data); + error = 1; continue; } } - return 0; + return error; } -static FlushCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +FlushCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; - int error; - register struct cmd_item *ti; + struct cmd_item *ti; + + int error = 0; - error = 0; for(ti=as->parms[0].items; ti; ti=ti->next) { blob.in_size = blob.out_size = 0; code = pioctl(ti->data, VIOCFLUSH, &blob, 0); if (code) { - error = 1; if (errno == EMFILE) { - fprintf(stderr,"%s: Can't flush active file %s\n", pn, ti->data); - continue; - } - else { - fprintf(stderr, "Error flushing file\n"); - Die(errno,ti->data); - continue; + fprintf(stderr, "%s: Can't flush active file %s\n", pn, + ti->data); + } else { + fprintf(stderr, "%s: Error flushing file ", pn); + perror(ti->data); } + error = 1; + continue; } } return error; } /* all this command does is repackage its args and call SetVolCmd */ -static SetQuotaCmd(as) -register struct cmd_syndesc *as; { +static int +SetQuotaCmd(struct cmd_syndesc *as, char *arock) { struct cmd_syndesc ts; /* copy useful stuff from our command slot; we may later have to reorder */ memcpy(&ts, as, sizeof(ts)); /* copy whole thing */ - return SetVolCmd(&ts); + return SetVolCmd(&ts, arock); } -static SetVolCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +SetVolCmd(struct cmd_syndesc *as, char *arock) { + afs_int32 code; struct ViceIoctl blob; - register struct cmd_item *ti; + struct cmd_item *ti; struct VolumeStatus *status; char *motd, *offmsg, *input; + int error = 0; SetDotDefault(&as->parms[0].items); for(ti=as->parms[0].items; ti; ti=ti->next) { @@ -1164,61 +1363,78 @@ register struct cmd_syndesc *as; { blob.in = space; status = (VolumeStatus *)space; status->MinQuota = status->MaxQuota = -1; - motd = offmsg = (char *) 0; + motd = offmsg = NULL; if (as->parms[1].items) { code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota); if (code) { - fprintf(stderr,"fs: bad integer specified for quota.\n"); - return code; + fprintf(stderr,"%s: bad integer specified for quota.\n", pn); + error = 1; + continue; } } - if (as->parms[2].items) motd = as->parms[2].items->data; - if (as->parms[3].items) offmsg = as->parms[3].items->data; + if (as->parms[2].items) + motd = as->parms[2].items->data; + if (as->parms[3].items) + offmsg = as->parms[3].items->data; input = (char *)status + sizeof(*status); *(input++) = '\0'; /* never set name: this call doesn't change vldb */ if(offmsg) { - if (strlen(offmsg) >= VMSGSIZE) { - fprintf(stderr,"fs: message must be shorter than %d characters\n", - VMSGSIZE); - return code; - } + if (strlen(offmsg) >= VMSGSIZE) { + fprintf(stderr,"%s: message must be shorter than %d characters\n", + pn, VMSGSIZE); + error = 1; + continue; + } strcpy(input,offmsg); blob.in_size += strlen(offmsg); input += strlen(offmsg) + 1; - } - else *(input++) = '\0'; + } else + *(input++) = '\0'; if(motd) { - if (strlen(motd) >= VMSGSIZE) { - fprintf(stderr,"fs: message must be shorter than %d characters\n", - VMSGSIZE); - return code; - } + if (strlen(motd) >= VMSGSIZE) { + fprintf(stderr,"%s: message must be shorter than %d characters\n", + pn, VMSGSIZE); + return code; + } strcpy(input,motd); blob.in_size += strlen(motd); input += strlen(motd) + 1; - } - else *(input++) = '\0'; + } else + *(input++) = '\0'; code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1); if (code) { - Die(errno, ti->data); - return 1; + error = 1; } } - return 0; + return error; } -static ExamineCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +#ifndef WIN32 +/* + * Why is VenusFid declared in the kernel-only section of afs.h, + * if it's the exported interface of the (UNIX) cache manager? + */ +struct VenusFid { + afs_int32 Cell; + AFSFid Fid; +}; +#endif /* WIN32 */ + +static int +ExamineCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; - register struct cmd_item *ti; + struct cmd_item *ti; struct VolumeStatus *status; char *name, *offmsg, *motd; - int error; + int error = 0; - error = 0; SetDotDefault(&as->parms[0].items); for(ti=as->parms[0].items; ti; ti=ti->next) { +#ifndef WIN32 + struct VenusFid vfid; +#endif /* WIN32 */ /* once per file */ blob.out_size = MAXSIZE; blob.in_size = 0; @@ -1233,18 +1449,31 @@ register struct cmd_syndesc *as; { name = (char *)status + sizeof(*status); offmsg = name + strlen(name) + 1; motd = offmsg + strlen(offmsg) + 1; + +#ifndef WIN32 + blob.out_size = sizeof(struct VenusFid); + blob.out = (char *) &vfid; + if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) { + printf("File %s (%u.%u.%u) contained in volume %u\n", + ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique, + vfid.Fid.Volume); + } +#endif /* WIN32 */ PrintStatus(status, name, motd, offmsg); } return error; } -static ListQuotaCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +ListQuotaCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; - register struct cmd_item *ti; + struct cmd_item *ti; struct VolumeStatus *status; char *name; + + int error = 0; printf("%-25s%-10s%-10s%-7s%-13s\n", "Volume Name", " Quota", " Used", " %Used", " Partition"); @@ -1257,23 +1486,26 @@ register struct cmd_syndesc *as; { code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1); if (code) { Die(errno, ti->data); + error = 1; continue; } status = (VolumeStatus *)space; name = (char *)status + sizeof(*status); QuickPrintStatus(status, name); } - return 0; + return error; } -static WhereIsCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +WhereIsCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; - register struct cmd_item *ti; - register int j; + struct cmd_item *ti; + int j; afs_int32 *hosts; char *tp; + int error = 0; SetDotDefault(&as->parms[0].items); for(ti=as->parms[0].items; ti; ti=ti->next) { @@ -1285,28 +1517,33 @@ register struct cmd_syndesc *as; { code = pioctl(ti->data, VIOCWHEREIS, &blob, 1); if (code) { Die(errno, ti->data); + error = 1; continue; } hosts = (afs_int32 *) space; - printf("File %s is on host%s ", ti->data, (hosts[0] && !hosts[1]) ? "": "s"); + printf("File %s is on host%s ", ti->data, + (hosts[0] && !hosts[1]) ? "": "s"); for(j=0; jdata, VIOCGETVOLSTAT, &blob, 1); if (code) { Die(errno, ti->data); + error = 1; continue; } status = (VolumeStatus *)space; name = (char *)status + sizeof(*status); QuickPrintSpace(status, name); } - return 0; + return error; } -static QuotaCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +QuotaCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; - register struct cmd_item *ti; + struct cmd_item *ti; double quotaPct; struct VolumeStatus *status; + int error = 0; SetDotDefault(&as->parms[0].items); for(ti=as->parms[0].items; ti; ti=ti->next) { @@ -1345,26 +1585,29 @@ register struct cmd_syndesc *as; { code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1); if (code) { Die(errno, ti->data); + error = 1; continue; } status = (VolumeStatus *)space; - if (status->MaxQuota) quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0); - else quotaPct = 0.0; + if (status->MaxQuota) + quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0); + else + quotaPct = 0.0; printf("%2.0f%% of quota used.\n", quotaPct); } - return 0; + return error; } -static ListMountCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +ListMountCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; - int error; - register struct cmd_item *ti; + struct cmd_item *ti; char orig_name[1024]; /*Original name, may be modified*/ char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/ char parent_dir[1024]; /*Parent directory of true name*/ - register char *last_component; /*Last component of true name*/ + char *last_component; /*Last component of true name*/ #ifndef WIN32 struct stat statbuff; /*Buffer for status info*/ #endif /* not WIN32 */ @@ -1373,7 +1616,7 @@ register struct cmd_syndesc *as; { #endif /* not WIN32 */ int thru_symlink; /*Did we get to a mount point via a symlink?*/ - error = 0; + int error = 0; for(ti=as->parms[0].items; ti; ti=ti->next) { /* once per file */ thru_symlink = 0; @@ -1388,8 +1631,8 @@ register struct cmd_syndesc *as; { #ifndef WIN32 if (lstat(orig_name, &statbuff) < 0) { /* if lstat fails, we should still try the pioctl, since it - may work (for example, lstat will fail, but pioctl will - work if the volume of offline (returning ENODEV). */ + * may work (for example, lstat will fail, but pioctl will + * work if the volume of offline (returning ENODEV). */ statbuff.st_mode = S_IFDIR; /* lie like pros */ } @@ -1404,9 +1647,11 @@ register struct cmd_syndesc *as; { */ link_chars_read = readlink(orig_name, true_name, 1024); if (link_chars_read <= 0) { - fprintf(stderr,"%s: Can't read target name for '%s' symbolic link!\n", + fprintf(stderr, + "%s: Can't read target name for '%s' symbolic link!\n", pn, orig_name); - exit(1); + error = 1; + continue; } /* @@ -1425,8 +1670,7 @@ register struct cmd_syndesc *as; { strcpy(++last_component, true_name); strcpy(true_name, orig_name); } - } - else + } else strcpy(true_name, orig_name); #else /* WIN32 */ strcpy(true_name, orig_name); @@ -1435,8 +1679,10 @@ register struct cmd_syndesc *as; { /* * Find rightmost slash, if any. */ +#ifdef WIN32 last_component = (char *) strrchr(true_name, '\\'); if (!last_component) +#endif /* WIN32 */ last_component = (char *) strrchr(true_name, '/'); if (last_component) { /* @@ -1446,8 +1692,7 @@ register struct cmd_syndesc *as; { strncpy(parent_dir, true_name, last_component - true_name + 1); parent_dir[last_component - true_name + 1] = 0; last_component++; /*Skip the slash*/ - } - else { + } else { /* * No slash appears in the given file name. Set parent_dir to the current * directory, and the last component as the given name. @@ -1459,8 +1704,8 @@ register struct cmd_syndesc *as; { } if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) { - fprintf(stderr,"fs: you may not use '.' or '..' as the last component\n"); - fprintf(stderr,"fs: of a name in the 'fs lsmount' command.\n"); + fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn); + fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn); error = 1; continue; } @@ -1473,29 +1718,29 @@ register struct cmd_syndesc *as; { code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1); - if (code == 0) + if (code == 0) { printf("'%s' is a %smount point for volume '%s'\n", ti->data, (thru_symlink ? "symbolic link, leading to a " : ""), space); - else { - error = 1; - if (errno == EINVAL) - fprintf(stderr,"'%s' is not a mount point.\n", - ti->data); - else { + } else { + if (errno == EINVAL) { + fprintf(stderr,"'%s' is not a mount point.\n", ti->data); + } else { Die(errno, (ti->data ? ti->data : parent_dir)); } + error = 1; } } return error; } -static MakeMountCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; - register char *cellName, *volName, *tmpName; +static int +MakeMountCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; + char *cellName, *volName, *tmpName; #ifdef WIN32 char localCellName[1000]; #else /* not WIN32 */ @@ -1504,43 +1749,43 @@ register struct cmd_syndesc *as; { #endif /* not WIN32 */ struct ViceIoctl blob; -/* + /* -defect #3069 + defect #3069 if (as->parms[5].items && !as->parms[2].items) { - fprintf(stderr,"fs: must provide cell when creating cellular mount point.\n"); + fprintf(stderr,"%s: must provide cell when creating cellular mount point.\n", pn); return 1; } -*/ + */ if (as->parms[2].items) /* cell name specified */ cellName = as->parms[2].items->data; else - cellName = (char *) 0; + cellName = NULL; volName = as->parms[1].items->data; if (strlen(volName) >= 64) { - fprintf(stderr,"fs: volume name too long (length must be < 64 characters)\n"); + fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn); return 1; } /* Check for a cellname in the volume specification, and complain * if it doesn't match what was specified with -cell */ if (tmpName = strchr(volName, ':')) { - *tmpName = '\0'; - if (cellName) { - if (foldcmp(cellName,volName)) { - fprintf(stderr,"fs: cellnames do not match.\n"); - return 1; - } - } - cellName = volName; - volName = ++tmpName; + *tmpName = '\0'; + if (cellName) { + if (strcasecmp(cellName,volName)) { + fprintf(stderr,"fs: cellnames do not match.\n"); + return 1; + } + } + cellName = volName; + volName = ++tmpName; } if (!InAFS(Parent(as->parms[0].items->data))) { - fprintf(stderr,"fs: mount points must be created within the AFS file system\n"); + fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn); return 1; } @@ -1568,8 +1813,8 @@ defect #3069 /* make the check. Don't complain if there are problems with init */ code = ubik_Call(VL_GetEntryByNameO, uclient, 0, volName, &vldbEntry); if (code == VL_NOENT) { - fprintf(stderr,"fs: warning, volume %s does not exist in cell %s.\n", - volName, cellName ? cellName : space); + fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n", + pn, volName, cellName ? cellName : space); } } } @@ -1615,14 +1860,15 @@ defect #3069 * (or ``.'' if none is provided) * tp: Set to point to the actual name of the mount point to nuke. */ -static RemoveMountCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code=0; +static int +RemoveMountCmd(struct cmd_syndesc *as, char *arock) { + afs_int32 code=0; struct ViceIoctl blob; - register struct cmd_item *ti; + struct cmd_item *ti; char tbuffer[1024]; char lsbuffer[1024]; - register char *tp; + char *tp; + int error = 0; for(ti=as->parms[0].items; ti; ti=ti->next) { /* once per file */ @@ -1633,8 +1879,7 @@ register struct cmd_syndesc *as; { strncpy(tbuffer, ti->data, code=tp-ti->data+1); /* the dir name */ tbuffer[code] = 0; tp++; /* skip the slash */ - } - else { + } else { fs_ExtractDriveLetter(ti->data, tbuffer); strcat(tbuffer, "."); tp = ti->data; @@ -1646,11 +1891,12 @@ register struct cmd_syndesc *as; { blob.out_size = sizeof(lsbuffer); code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0); if (code) { - if (errno == EINVAL) - fprintf(stderr,"fs: '%s' is not a mount point.\n", ti->data); - else { + if (errno == EINVAL) { + fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data); + } else { Die(errno, ti->data); } + error = 1; continue; /* don't bother trying */ } blob.out_size = 0; @@ -1659,22 +1905,23 @@ register struct cmd_syndesc *as; { code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0); if (code) { Die(errno, ti->data); + error = 1; } - } - return code; + return error; } /* */ -static CheckServersCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +CheckServersCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; - register afs_int32 j; + afs_int32 j; afs_int32 temp; - register char *tp; + char *tp; struct afsconf_cell info; struct chservinfo checkserv; @@ -1688,8 +1935,10 @@ register struct cmd_syndesc *as; { /* prepare flags for checkservers command */ temp = 2; /* default to checking local cell only */ - if (as->parms[2].items) temp |= 1; /* set fast flag */ - if (as->parms[1].items) temp &= ~2; /* turn off local cell check */ + if (as->parms[2].items) + temp |= 1; /* set fast flag */ + if (as->parms[1].items) + temp &= ~2; /* turn off local cell check */ checkserv.magic = 0x12345678; /* XXX */ checkserv.tflags=temp; @@ -1702,29 +1951,25 @@ register struct cmd_syndesc *as; { } strcpy(checkserv.tbuffer,info.name); checkserv.tsize=strlen(info.name)+1; + } else { + strcpy(checkserv.tbuffer,"\0"); + checkserv.tsize=0; } - else - { - strcpy(checkserv.tbuffer,"\0"); - checkserv.tsize=0; - } - if(as->parms[3].items) - { - checkserv.tinterval=atol(as->parms[3].items->data); + if(as->parms[3].items) { + checkserv.tinterval=atol(as->parms[3].items->data); - /* sanity check */ - if(checkserv.tinterval<0) { - printf("Warning: The negative -interval is ignored; treated as an inquiry\n"); - checkserv.tinterval=0; - } else if(checkserv.tinterval> 600) { - printf("Warning: The maximum -interval value is 10 mins (600 secs)\n"); - checkserv.tinterval=600; /* 10 min max interval */ - } - } - else { + /* sanity check */ + if(checkserv.tinterval<0) { + printf("Warning: The negative -interval is ignored; treated as an inquiry\n"); + checkserv.tinterval=0; + } else if(checkserv.tinterval> 600) { + printf("Warning: The maximum -interval value is 10 mins (600 secs)\n"); + checkserv.tinterval=600; /* 10 min max interval */ + } + } else { checkserv.tinterval = -1; /* don't change current interval */ - } + } if ( checkserv.tinterval != 0 ) { #ifdef WIN32 @@ -1747,7 +1992,7 @@ register struct cmd_syndesc *as; { return code; } Die(errno, 0); - return code; + return 1; } memcpy(&temp, space, sizeof(afs_int32)); if (checkserv.tinterval >= 0) { @@ -1760,12 +2005,12 @@ register struct cmd_syndesc *as; { } if (temp == 0) { printf("All servers are running.\n"); - } - else { + } else { printf("These servers unavailable due to network or server problems: "); for(j=0; j < MAXHOSTS; j++) { memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32)); - if (temp == 0) break; + if (temp == 0) + break; tp = hostutil_GetNameByINet(temp); printf(" %s", tp); } @@ -1775,9 +2020,10 @@ register struct cmd_syndesc *as; { return code; } -static GagCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code=0; +static int +MessagesCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code=0; struct ViceIoctl blob; struct gaginfo gagflags; struct cmd_item *show; @@ -1789,36 +2035,38 @@ register struct cmd_syndesc *as; { blob.out = space; memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */ - if (show = as->parms[0].items) - if (!foldcmp (show->data, "user")) - gagflags.showflags |= GAGUSER; - else if (!foldcmp (show->data, "console")) - gagflags.showflags |= GAGCONSOLE; - else if (!foldcmp (show->data, "all")) - gagflags.showflags |= GAGCONSOLE | GAGUSER; - else if (!foldcmp (show->data, "none")) - /* do nothing */ ; - else { - fprintf(stderr, - "unrecognized flag %s: must be in {user,console,all,none}\n", - show->data); - code = EINVAL; - } + if (show = as->parms[0].items) { + if (!strcasecmp (show->data, "user")) + gagflags.showflags |= GAGUSER; + else if (!strcasecmp (show->data, "console")) + gagflags.showflags |= GAGCONSOLE; + else if (!strcasecmp (show->data, "all")) + gagflags.showflags |= GAGCONSOLE | GAGUSER; + else if (!strcasecmp (show->data, "none")) + /* do nothing */ ; + else { + fprintf(stderr, + "unrecognized flag %s: must be in {user,console,all,none}\n", + show->data); + code = EINVAL; + } + } if (code) - return code; + return 1; code = pioctl(0, VIOC_GAG, &blob, 1); if (code) { Die(errno, 0); - return code; + return 1; } - return code; + return 0; } -static CheckVolumesCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +CheckVolumesCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; blob.in_size = 0; @@ -1828,14 +2076,15 @@ register struct cmd_syndesc *as; { Die(errno, 0); return 1; } - else printf("All volumeID/name mappings checked.\n"); + printf("All volumeID/name mappings checked.\n"); return 0; } -static SetCacheSizeCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +SetCacheSizeCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; afs_int32 temp; @@ -1858,53 +2107,61 @@ register struct cmd_syndesc *as; { if (as->parms[0].items) { code = util_GetInt32(as->parms[0].items->data, &temp); if (code) { - fprintf(stderr,"fs: bad integer specified for cache size.\n"); - return code; + fprintf(stderr,"%s: bad integer specified for cache size.\n", pn); + return 1; } - } - else + } else temp = 0; blob.in = (char *) &temp; blob.in_size = sizeof(afs_int32); blob.out_size = 0; code = pioctl(0, VIOCSETCACHESIZE, &blob, 1); - if (code) + if (code) { Die(errno, (char *) 0); - else - printf("New cache size set.\n"); + return 1; + } + + printf("New cache size set.\n"); return 0; } #define MAXGCSIZE 16 -static GetCacheParmsCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +GetCacheParmsCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; afs_int32 parms[MAXGCSIZE]; - - blob.in = (char *) 0; + + memset(parms, 0, sizeof(parms)); + blob.in = NULL; blob.in_size = 0; blob.out_size = sizeof(parms); blob.out = (char *) parms; code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1); - if (code) - Die(errno, (char *) 0); - else { - printf("AFS using %d of the cache's available %d 1K byte blocks.\n", - parms[1], parms[0]); - if (parms[1] > parms[0]) - printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n"); + if (code) { + Die(errno, NULL); + return 1; } + + printf("AFS using %d of the cache's available %d 1K byte blocks.\n", + parms[1], parms[0]); + if (parms[1] > parms[0]) + printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n"); return 0; } -static ListCellsCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +ListCellsCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; afs_int32 i, j, *lp, magic, size; - char *tcp, *tp; - afs_int32 clear, maxa = OMAXHOSTS; + char *tp; + afs_int32 addr, maxa = OMAXHOSTS; struct ViceIoctl blob; + int resolve; + + resolve = !(as->parms[0].items); /* -numeric */ for(i=0;i<1000;i++) { tp = space; @@ -1919,12 +2176,11 @@ register struct cmd_syndesc *as; { blob.out = space; code = pioctl(0, VIOCGETCELL, &blob, 1); if (code < 0) { - if (errno == EDOM) break; /* done with the list */ - else { - Die(errno, 0); - return 1; - } - } + if (errno == EDOM) + break; /* done with the list */ + Die(errno, 0); + return 1; + } tp = space; memcpy(&magic, tp, sizeof(afs_int32)); if (magic == 0x12345678) { @@ -1933,38 +2189,109 @@ register struct cmd_syndesc *as; { } printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32)); for(j=0; j < maxa; j++) { - memcpy(&clear, tp + j*sizeof(afs_int32), sizeof(afs_int32)); - if (clear == 0) break; - tcp = hostutil_GetNameByINet(clear); - printf(" %s", tcp); + char *name, tbuffer[20]; + + memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32)); + if (addr == 0) + break; + + if (resolve) { + name = hostutil_GetNameByINet(addr); + } else { + addr = ntohl(addr); + sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff, + (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); + name = tbuffer; + } + printf(" %s", name); } printf(".\n"); } return 0; } -static NewCellCmd(as) -register struct cmd_syndesc *as; { #ifndef WIN32 - register afs_int32 code, linkedstate=0, size=0, *lp; +static int +ListAliasesCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code, i; + char *tp, *aliasName, *realName; struct ViceIoctl blob; - register struct cmd_item *ti; - register char *tp, *cellname=0; - register struct hostent *thp; - afs_int32 fsport = 0, vlport = 0; -#ifdef WIN32 - if ( !IsAdmin() ) { - fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); - return EACCES; + for (i = 0;; i++) { + tp = space; + memcpy(tp, &i, sizeof(afs_int32)); + blob.out_size = MAXSIZE; + blob.in_size = sizeof(afs_int32); + blob.in = space; + blob.out = space; + code = pioctl(0, VIOC_GETALIAS, &blob, 1); + if (code < 0) { + if (errno == EDOM) + break; /* done with the list */ + Die(errno, 0); + return 1; + } + tp = space; + aliasName = tp; + tp += strlen(aliasName) + 1; + realName = tp; + printf("Alias %s for cell %s\n", aliasName, realName); } -#else /* WIN32 */ - if (geteuid()) { - fprintf (stderr,"Permission denied: requires root access.\n"); - return EACCES; + return 0; +} + +static int +CallBackRxConnCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; + struct ViceIoctl blob; + struct cmd_item *ti; + afs_int32 hostAddr; + struct hostent *thp; + char *tp; + int setp; + + ti = as->parms[0].items; + setp = 1; + if (ti) { + thp = hostutil_GetHostByName(ti->data); + if (!thp) { + fprintf(stderr, "host %s not found in host table.\n", ti->data); + return 1; + } + else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32)); + } else { + hostAddr = 0; /* means don't set host */ + setp = 0; /* aren't setting host */ } + + /* now do operation */ + blob.in_size = sizeof(afs_int32); + blob.out_size = sizeof(afs_int32); + blob.in = (char *) &hostAddr; + blob.out = (char *) &hostAddr; + + code = pioctl(0, VIOC_CBADDR, &blob, 1); + if (code < 0) { + Die(errno, 0); + return 1; + } + return 0; +} #endif /* WIN32 */ +static int +NewCellCmd(struct cmd_syndesc *as, char *arock) +{ +#ifndef WIN32 + afs_int32 code, linkedstate=0, size=0, *lp; + struct ViceIoctl blob; + struct cmd_item *ti; + char *tp, *cellname=0; + struct hostent *thp; + afs_int32 fsport = 0, vlport = 0; + memset(space, 0, MAXHOSTS * sizeof(afs_int32)); tp = space; lp = (afs_int32 *)tp; @@ -2025,9 +2352,14 @@ register struct cmd_syndesc *as; { Die(errno, 0); return 0; #else /* WIN32 */ - register afs_int32 code; + afs_int32 code; struct ViceIoctl blob; + if ( !IsAdmin() ) { + fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); + return EACCES; + } + blob.in_size = 0; blob.in = (char *) 0; blob.out_size = MAXSIZE; @@ -2036,30 +2368,63 @@ register struct cmd_syndesc *as; { code = pioctl((char *) 0, VIOCNEWCELL, &blob, 1); if (code) { - Die(errno, (char *) 0); + Die(errno, (char *) 0); + return 1; } - else - printf("Cell servers information refreshed\n"); + + printf("Cell servers information refreshed\n"); return 0; #endif /* WIN32 */ } -static WhichCellCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +#ifndef WIN32 +static int +NewAliasCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; - register struct cmd_item *ti; - int error; + char *tp; + char *aliasName, *realName; + + /* Setup and do the NEWALIAS pioctl call */ + aliasName = as->parms[0].items->data; + realName = as->parms[1].items->data; + tp = space; + strcpy(tp, aliasName); + tp += strlen(aliasName) + 1; + strcpy(tp, realName); + tp += strlen(realName) + 1; + + blob.in_size = tp - space; + blob.in = space; + blob.out_size = 0; + blob.out = space; + code = pioctl(0, VIOC_NEWALIAS, &blob, 1); + if (code < 0) { + if (errno == EEXIST) { + fprintf(stderr, + "%s: cell name `%s' in use by an existing cell.\n", pn, + aliasName); + } else { + Die(errno, 0); + } + return 1; + } + return 0; +} +#endif /* WIN32 */ + +static int +WhichCellCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; + struct cmd_item *ti; + int error = 0; + char cell[MAXCELLCHARS]; - error = 0; /* no error occurred */ SetDotDefault(&as->parms[0].items); for(ti=as->parms[0].items; ti; ti=ti->next) { - /* once per file */ - blob.in_size = 0; - blob.out_size = MAXSIZE; - blob.out = space; - - code = pioctl(ti->data, VIOC_FILE_CELL_NAME, &blob, 1); + code = GetCell(ti->data, cell); if (code) { if (errno == ENOENT) fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data); @@ -2068,47 +2433,50 @@ register struct cmd_syndesc *as; { error = 1; continue; } - else - printf("File %s lives in cell '%s'\n", ti->data, space); + printf("File %s lives in cell '%s'\n", ti->data, cell); } return error; } -static WSCellCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +WSCellCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; blob.in_size = 0; - blob.in = (char *) 0; + blob.in = NULL; blob.out_size = MAXSIZE; blob.out = space; - code = pioctl((char *) 0, VIOC_GET_WS_CELL, &blob, 1); + code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1); if (code) { - Die(errno, (char *) 0); + Die(errno, NULL); + return 1; } - else - printf("This workstation belongs to cell '%s'\n", space); + + printf("This workstation belongs to cell '%s'\n", space); return 0; } -static PrimaryCellCmd(as) -register struct cmd_syndesc *as; { /* +static int +PrimaryCellCmd(struct cmd_syndesc *as, char *arock) +{ fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n"); -*/ return 0; } +*/ -static MonitorCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +MonitorCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; - register struct cmd_item *ti; + struct cmd_item *ti; afs_int32 hostAddr; - register struct hostent *thp; + struct hostent *thp; char *tp; int setp; @@ -2116,24 +2484,23 @@ register struct cmd_syndesc *as; { setp = 1; if (ti) { /* set the host */ - if (!strcmp(ti->data, "off")) + if (!strcmp(ti->data, "off")) { hostAddr = 0xffffffff; - else { + } else { thp = hostutil_GetHostByName(ti->data); if (!thp) { if (!strcmp(ti->data, "localhost")) { fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n"); hostAddr = htonl(0x7f000001); - } - else { + } else { fprintf(stderr,"host %s not found in host table.\n", ti->data); return 1; } - } - else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32)); + } else { + memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32)); + } } - } - else { + } else { hostAddr = 0; /* means don't set host */ setp = 0; /* aren't setting host */ } @@ -2146,17 +2513,15 @@ register struct cmd_syndesc *as; { code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1); if (code) { Die(errno, 0); - exit(1); + return 1; } if (setp) { printf("%s: new monitor host set.\n", pn); - } - else { + } else { /* now decode old address */ if (hostAddr == 0xffffffff) { printf("Cache monitoring is currently disabled.\n"); - } - else { + } else { tp = hostutil_GetNameByINet(hostAddr); printf("Using host %s for monitor services.\n", tp); } @@ -2164,9 +2529,10 @@ register struct cmd_syndesc *as; { return 0; } -static SysNameCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +SysNameCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; struct cmd_item *ti; char *input = space; @@ -2212,7 +2578,7 @@ register struct cmd_syndesc *as; { return 1; } if (setp) { - printf("%s: new sysname%s set.\n", pn, setp > 1 ? "s" : ""); + printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : ""); return 0; } @@ -2224,7 +2590,7 @@ register struct cmd_syndesc *as; { return 1; } - printf("Current sysname%s", setp > 1 ? "s are" : " is"); + printf("Current sysname%s is", setp > 1 ? " list" : ""); for (; setp > 0; --setp ) { printf(" \'%s\'", input); input += strlen(input) + 1; @@ -2233,13 +2599,14 @@ register struct cmd_syndesc *as; { return 0; } -char *exported_types[] = {"null", "nfs", ""}; -static ExportAfsCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static char *exported_types[] = {"null", "nfs", ""}; +static int ExportAfsCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; - register struct cmd_item *ti; - int export=0, type=0, mode = 0, exp = 0, gstat = 0, exportcall, pwsync=0, smounts=0; + struct cmd_item *ti; + int export = 0, type = 0, mode = 0, exp = 0, gstat = 0; + int exportcall, pwsync = 0, smounts = 0; #ifdef WIN32 if ( !IsAdmin() ) { @@ -2254,42 +2621,52 @@ register struct cmd_syndesc *as; { #endif /* WIN32 */ ti = as->parms[0].items; - if (strcmp(ti->data, "nfs") == 0) type = 0x71; /* NFS */ + if (strcmp(ti->data, "nfs") == 0) + type = 0x71; /* NFS */ else { - fprintf(stderr,"Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data); + fprintf(stderr, + "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data); return 1; } ti = as->parms[1].items; if (ti) { - if (strcmp(ti->data, "on") == 0) export = 3; - else if (strcmp(ti->data, "off") == 0) export = 2; + if (strcmp(ti->data, "on") == 0) + export = 3; + else if (strcmp(ti->data, "off") == 0) + export = 2; else { - printf("Illegal argument %s\n", ti->data); + fprintf(stderr, "Illegal argument %s\n", ti->data); return 1; } exp = 1; } if (ti = as->parms[2].items) { /* -noconvert */ - if (strcmp(ti->data, "on") == 0) mode = 2; - else if (strcmp(ti->data, "off") == 0) mode = 3; + if (strcmp(ti->data, "on") == 0) + mode = 2; + else if (strcmp(ti->data, "off") == 0) + mode = 3; else { - printf("Illegal argument %s\n", ti->data); + fprintf(stderr, "Illegal argument %s\n", ti->data); return 1; } } if (ti = as->parms[3].items) { /* -uidcheck */ - if (strcmp(ti->data, "on") == 0) pwsync = 3; - else if (strcmp(ti->data, "off") == 0) pwsync = 2; + if (strcmp(ti->data, "on") == 0) + pwsync = 3; + else if (strcmp(ti->data, "off") == 0) + pwsync = 2; else { - printf("Illegal argument %s\n", ti->data); + fprintf(stderr, "Illegal argument %s\n", ti->data); return 1; } } if (ti = as->parms[4].items) { /* -submounts */ - if (strcmp(ti->data, "on") == 0) smounts = 3; - else if (strcmp(ti->data, "off") == 0) smounts = 2; + if (strcmp(ti->data, "on") == 0) + smounts = 3; + else if (strcmp(ti->data, "off") == 0) + smounts = 2; else { - printf("Illegal argument %s\n", ti->data); + fprintf(stderr, "Illegal argument %s\n", ti->data); return 1; } } @@ -2303,11 +2680,12 @@ register struct cmd_syndesc *as; { code = pioctl(0, VIOC_EXPORTAFS, &blob, 1); if (code) { if (errno == ENODEV) { - fprintf(stderr,"Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]); + fprintf(stderr, + "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]); } else { Die(errno, 0); - exit(1); } + return 1; } else { if (!gstat) { if (exportcall & 1) { @@ -2320,27 +2698,31 @@ register struct cmd_syndesc *as; { } } } - return(0); + return 0; } -static GetCellCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int +GetCellCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; struct afsconf_cell info; - register struct cmd_item *ti; + struct cmd_item *ti; struct a { afs_int32 stat; afs_int32 junk; } args; - + int error = 0; + + memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */ for(ti=as->parms[0].items; ti; ti=ti->next) { /* once per cell */ blob.out_size = sizeof(args); blob.out = (caddr_t) &args; code = GetCellName(ti->data, &info); if (code) { + error = 1; continue; } blob.in_size = 1+strlen(info.name); @@ -2348,34 +2730,46 @@ register struct cmd_syndesc *as; { code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1); if (code) { if (errno == ENOENT) - fprintf(stderr,"fs: the cell named '%s' does not exist\n", info.name); + fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name); else Die(errno, info.name); - return 1; + error = 1; + continue; } printf("Cell %s status: ", info.name); #ifdef notdef - if (args.stat & 1) printf("primary "); + if (args.stat & 1) + printf("primary "); #endif - if (args.stat & 2) printf("no setuid allowed"); - else printf("setuid allowed"); - if (args.stat & 4) printf(", using old VLDB"); + if (args.stat & 2) + printf("no setuid allowed"); + else + printf("setuid allowed"); + if (args.stat & 4) + printf(", using old VLDB"); printf("\n"); } - return 0; + return error; } -static SetCellCmd(as) -register struct cmd_syndesc *as; { - register afs_int32 code; +static int SetCellCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; struct ViceIoctl blob; struct afsconf_cell info; - register struct cmd_item *ti; + struct cmd_item *ti; struct a { afs_int32 stat; afs_int32 junk; char cname[64]; } args; + int error = 0; + + /* Check arguments. */ + if (as->parms[1].items && as->parms[2].items) { + fprintf(stderr, "Cannot specify both -suid and -nosuid.\n"); + return 1; + } /* figure stuff to set */ args.stat = 0; @@ -2393,13 +2787,15 @@ register struct cmd_syndesc *as; { } #endif /* WIN32 */ - if (! as->parms[1].items) args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */ + if (! as->parms[1].items) + args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */ /* set stat for all listed cells */ for(ti=as->parms[0].items; ti; ti=ti->next) { /* once per cell */ code = GetCellName(ti->data, &info); if (code) { + error = 1; continue; } strcpy(args.cname, info.name); @@ -2409,43 +2805,45 @@ register struct cmd_syndesc *as; { blob.out = (caddr_t) 0; code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1); if (code) { - Die(errno, 0); - exit(1); + Die(errno, info.name); /* XXX added cell name to Die() call */ + error = 1; } } - return 0; + return error; } #ifdef WIN32 -static GetCellName(char *cellNamep, struct afsconf_cell *infop) +static int +GetCellName(char *cellNamep, struct afsconf_cell *infop) { - strcpy(infop->name, cellNamep); - return 0; + strcpy(infop->name, cellNamep); + return 0; } -static VLDBInit(int noAuthFlag, struct afsconf_cell *infop) +static int +VLDBInit(int noAuthFlag, struct afsconf_cell *infop) { - return 0; + return 0; } - #else /* not WIN32 */ - -static GetCellName(cellName, info) -char *cellName; -struct afsconf_cell *info; +static int +GetCellName(char *cellName, struct afsconf_cell *info) { struct afsconf_dir *tdir; - register int code; + int code; - tdir = afsconf_Open(AFSCONF_CLIENTNAME); + tdir = afsconf_Open(AFSDIR_CLIENT_ETC_CLIENTNAME); if (!tdir) { - fprintf(stderr,"Could not process files in configuration directory (%s).\n",AFSCONF_CLIENTNAME); + fprintf(stderr, + "Could not process files in configuration directory (%s).\n", + AFSDIR_CLIENT_ETC_CLIENTNAME); return -1; } code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info); if (code) { - fprintf(stderr,"fs: cell %s not in %s/CellServDB\n", cellName, AFSCONF_CLIENTNAME); + fprintf(stderr,"fs: cell %s not in %s/CellServDB\n", cellName, + AFSDIR_CLIENT_ETC_CLIENTNAME); return code; } @@ -2453,82 +2851,22 @@ struct afsconf_cell *info; } -static VLDBInit(noAuthFlag, info) -int noAuthFlag; -struct afsconf_cell *info; -{ afs_int32 code; - struct ktc_principal sname; - struct ktc_token ttoken; - afs_int32 scIndex; - struct rx_securityClass *sc; - struct rx_connection *serverconns[VLDB_MAXSERVERS]; - afs_int32 i; +static int +VLDBInit(int noAuthFlag, struct afsconf_cell *info) +{ + afs_int32 code; - code = rx_Init(0); - if (code) { - fprintf(stderr,"fs: could not initialize rx.\n"); - return code; - } + code = ugen_ClientInit(noAuthFlag, AFSDIR_CLIENT_ETC_DIRPATH, + info->name, 0, &uclient, + NULL, pn, rxkad_clear, + VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50, + 0, 0, USER_SERVICE_ID); rxInitDone = 1; - rx_SetRxDeadTime(50); - if (!noAuthFlag) { /* we don't need tickets for null */ - strcpy(sname.cell, info->name); - sname.instance[0] = 0; - strcpy(sname.name, "afs"); - code = ktc_GetToken(&sname,&ttoken, sizeof(ttoken), (char *)0); - if (code) { - fprintf(stderr,"fs: Could not get afs tokens, running unauthenticated.\n"); - scIndex = 0; - } - else { - /* got a ticket */ - if (ttoken.kvno >= 0 && ttoken.kvno <= 256) scIndex = 2; /* kerberos */ - else { - fprintf (stderr, "fs: funny kvno (%d) in ticket, proceeding\n", - ttoken.kvno); - scIndex = 2; - } - } - } - else scIndex = 0; /* don't authenticate */ - switch (scIndex) { - case 0 : - sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject(); - break; - - case 1 : - break; - case 2: - sc = (struct rx_securityClass *) - rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey, - ttoken.kvno, ttoken.ticketLen, - ttoken.ticket); - break; - } - if (info->numServers > VLDB_MAXSERVERS) { - fprintf(stderr, "fs: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n", - info->numServers, VLDB_MAXSERVERS); - exit(1); - } - memset(serverconns, 0, sizeof(serverconns)); - for (i = 0;inumServers;i++) - serverconns[i] = rx_NewConnection(info->hostAddr[i].sin_addr.s_addr, - info->hostAddr[i].sin_port, USER_SERVICE_ID, - sc, scIndex); - - if (sc) - rxs_Release(sc); /* Decrement the initial refCount */ - code = ubik_ClientInit(serverconns, &uclient); - - if (code) { - fprintf(stderr,"fs: ubik client init failed.\n"); - return code; - } - return 0; + return code; } #endif /* not WIN32 */ -static struct ViceIoctl gblob; +static struct ViceIoctl gblob; static int debug = 0; /* * here follow some routines in suport of the setserverprefs and @@ -2541,10 +2879,11 @@ static int debug = 0; * GetPrefCmd reads the Cache Manager's current list of server ranks */ -static pokeServers() +#ifdef WIN32 +static int +pokeServers(void) { -int code; - + int code; cm_SSetPref_t *ssp; code = pioctl(0, VIOC_SETSPREFS, &gblob, 1); @@ -2553,15 +2892,44 @@ int code; gblob.in = space; return code; } +#else +/* + * returns -1 if error message printed, + * 0 on success, + * errno value if error and no error message printed + */ +static int +pokeServers(void) +{ + int code; -static addServer(name, rank) - char *name; - unsigned short rank; + code = pioctl(0, VIOC_SETSPREFS, &gblob, 1); + if (code && (errno == EINVAL)) { + struct setspref *ssp; + ssp = (struct setspref *)gblob.in; + if (!(ssp->flags & DBservers)) { + gblob.in = (void *)&(ssp->servers[0]); + gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp; + code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1); + return code ? errno : 0; + } + fprintf(stderr, + "This cache manager does not support VL server preferences.\n"); + return -1; + } + + return code ? errno : 0; +} +#endif /* WIN32 */ + +#ifdef WIN32 +static int +addServer(char *name, unsigned short rank) { - int code; - cm_SSetPref_t *ssp; - cm_SPref_t *sp; - struct hostent *thostent; + int code; + cm_SSetPref_t *ssp; + cm_SPref_t *sp; + struct hostent *thostent; #ifndef MAXUSHORT #ifdef MAXSHORT @@ -2571,31 +2939,87 @@ static addServer(name, rank) #endif #endif - code = 0; - thostent = hostutil_GetHostByName(name); - if (!thostent) { - fprintf (stderr, "%s: couldn't resolve name.\n", name); - return EINVAL; + code = 0; + thostent = hostutil_GetHostByName(name); + if (!thostent) { + fprintf (stderr, "%s: couldn't resolve name.\n", name); + return EINVAL; + } + + ssp = (cm_SSetPref_t *)(gblob.in); + + if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) { + code = pokeServers(); + ssp->num_servers = 0; + } + + sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size); + memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32)); + sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank); + gblob.in_size += sizeof(cm_SPref_t); + ssp->num_servers++; + + if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr); + + return code; +} +#else +/* + * returns -1 if error message printed, + * 0 on success, + * errno value if error and no error message printed + */ +static int +addServer(char *name, afs_int32 rank) +{ + int t, code; + struct setspref *ssp; + struct spref *sp; + struct hostent *thostent; + afs_uint32 addr; + int error = 0; + +#ifndef MAXUSHORT +#ifdef MAXSHORT +#define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */ +#else +#define MAXUSHORT ((unsigned short) ~0) +#endif +#endif + + thostent = hostutil_GetHostByName(name); + if (!thostent) { + fprintf(stderr, "%s: couldn't resolve name.\n", name); + return -1; + } + + ssp = (struct setspref *)(gblob.in); + + for (t = 0; thostent->h_addr_list[t]; t++) { + if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) { + code = pokeServers(); + if (code) + error = code; + ssp->num_servers = 0; } - ssp = (cm_SSetPref_t *)(gblob.in); - - if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) { - code = pokeServers(); - ssp->num_servers = 0; - } - - sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size); - memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32)); + sp = (struct spref *)(gblob.in + gblob.in_size); + memcpy(&(sp->server.s_addr), thostent->h_addr_list[t], + sizeof(afs_uint32)); sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank); - gblob.in_size += sizeof(cm_SPref_t); + gblob.in_size += sizeof(struct spref); ssp->num_servers++; - if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr); - - return code; -} + if (debug) + fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n", + name, sp->rank, sp->server.s_addr); + } + return error; +} +#endif /* WIN32 */ + +#ifdef WIN32 static BOOL IsWindowsNT (void) { static BOOL fChecked = FALSE; @@ -2618,178 +3042,351 @@ static BOOL IsWindowsNT (void) } return fIsWinNT; } - - -static SetPrefCmd(as) -register struct cmd_syndesc *as; { - FILE *infd; - afs_int32 code; - struct cmd_item *ti; - char name[80]; - afs_int32 rank; - cm_SSetPref_t *ssp; - - ssp = (cm_SSetPref_t *)space; - ssp->flags = 0; - ssp->num_servers = 0; - gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp; - gblob.in = space; - gblob.out = space; - gblob.out_size = MAXSIZE; +#endif /* WIN32 */ #ifdef WIN32 +static int +SetPrefCmd(struct cmd_syndesc *as, char * arock) +{ + FILE *infd; + afs_int32 code; + struct cmd_item *ti; + char name[80]; + afs_int32 rank; + cm_SSetPref_t *ssp; + + ssp = (cm_SSetPref_t *)space; + ssp->flags = 0; + ssp->num_servers = 0; + gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp; + gblob.in = space; + gblob.out = space; + gblob.out_size = MAXSIZE; + if ( !IsAdmin() ) { fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); return EACCES; } -#else /* WIN32 */ - if (geteuid()) { - fprintf (stderr,"Permission denied: requires root access.\n"); - return EACCES; - } -#endif /* WIN32 */ - code = 0; + code = 0; - ti = as->parms[2].items; /* -file */ - if (ti) { - if (debug) fprintf(stderr,"opening file %s\n",ti->data); - if (!(infd = fopen(ti->data,"r" ))) { - code = errno; - Die(errno,ti->data); - } - else - while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) { - code = addServer (name, (unsigned short) rank); - } - } - - ti = as->parms[3].items; /* -stdin */ - if (ti) { - while ( scanf("%79s%ld", name, &rank) != EOF) { - code = addServer (name, (unsigned short) rank); - } - } - - for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */ + ti = as->parms[2].items; /* -file */ if (ti) { - if (!ti->next) { - break; - } - code = addServer (ti->data, (unsigned short) atol(ti->next->data)); - if (debug) - printf("set fs prefs %s %s\n", ti->data, ti->next->data); - ti=ti->next; + if (debug) fprintf(stderr,"opening file %s\n",ti->data); + if (!(infd = fopen(ti->data,"r" ))) { + code = errno; + Die(errno,ti->data); + } + else + while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) { + code = addServer (name, (unsigned short) rank); + } } - } - code = pokeServers(); - if (debug) - printf("now working on vlservers, code=%d, errno=%d\n",code,errno); - ssp = (cm_SSetPref_t *)space; - gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp; - gblob.in = space; - ssp->flags = CM_SPREF_VLONLY; - ssp->num_servers = 0; - - for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */ + ti = as->parms[3].items; /* -stdin */ if (ti) { - if (!ti->next) { - break; - } - code = addServer (ti->data, (unsigned short) atol(ti->next->data)); - if (debug) - printf("set vl prefs %s %s\n", ti->data, ti->next->data); - ti=ti->next; + while ( scanf("%79s%ld", name, &rank) != EOF) { + code = addServer (name, (unsigned short) rank); + } } - } - if (as->parms[1].items) { - if (debug) - printf("now poking vlservers\n"); + for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */ + if (ti) { + if (!ti->next) { + break; + } + code = addServer (ti->data, (unsigned short) atol(ti->next->data)); + if (debug) + printf("set fs prefs %s %s\n", ti->data, ti->next->data); + ti=ti->next; + } + } code = pokeServers(); - } + if (debug) + printf("now working on vlservers, code=%d, errno=%d\n",code,errno); -if (code) - Die(errno,0); + ssp = (cm_SSetPref_t *)space; + gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp; + gblob.in = space; + ssp->flags = CM_SPREF_VLONLY; + ssp->num_servers = 0; -return code; -} - - -static GetPrefCmd(as) -register struct cmd_syndesc *as; { - afs_int32 code; - struct cmd_item *ti; - char *name, tbuffer[20]; - afs_int32 addr; - FILE * outfd; - int resolve; - int vlservers; - struct ViceIoctl blob; - struct cm_SPrefRequest *in; - struct cm_SPrefInfo *out; - int i; - - code = 0; - ti = as->parms[0].items; /* -file */ - if (ti) { - if (debug) fprintf(stderr,"opening file %s\n",ti->data); - if (!(outfd = freopen(ti->data,"w",stdout))) { - Die(errno,ti->data); - return errno; + for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */ + if (ti) { + if (!ti->next) { + break; + } + code = addServer (ti->data, (unsigned short) atol(ti->next->data)); + if (debug) + printf("set vl prefs %s %s\n", ti->data, ti->next->data); + ti=ti->next; + } } - } - ti = as->parms[1].items; /* -numeric */ - resolve = !(ti); - ti = as->parms[2].items; /* -vlservers */ - vlservers = (ti ? CM_SPREF_VLONLY : 0); -/* ti = as->parms[3].items; -cell */ - - in = (struct cm_SPrefRequest *)space; - in->offset = 0; - - do { - blob.in_size=sizeof(struct cm_SPrefRequest); - blob.in = (char *)in; - blob.out = space; - blob.out_size = MAXSIZE; - - in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref); - in->flags = vlservers; - - code = pioctl(0, VIOC_GETSPREFS, &blob, 1); - if (code){ - perror("getserverprefs pioctl"); - Die (errno,0); + if (as->parms[1].items) { + if (debug) + printf("now poking vlservers\n"); + code = pokeServers(); } - else { - out = (struct cm_SPrefInfo *) blob.out; - for (i=0;inum_servers;i++) { - if (resolve) { - name = hostutil_GetNameByINet(out->servers[i].host.s_addr); - } - else { - addr = ntohl(out->servers[i].host.s_addr); - sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff, - (addr>>8) & 0xff, addr & 0xff); - name=tbuffer; - } - printf ("%-50s %5u\n",name,out->servers[i].rank); - } - - in->offset = out->next_offset; - } - } while (!code && out->next_offset > 0); + if (code) + Die(errno,0); return code; } - -static TraceCmd(struct cmd_syndesc *asp) +#else +static int +SetPrefCmd(struct cmd_syndesc *as, char *arock) { - long code; + FILE *infd; + afs_int32 code; + struct cmd_item *ti; + char name[80]; + afs_int32 rank; + struct setspref *ssp; + int error = 0; /* -1 means error message printed, + * >0 means errno value for unprinted message */ + + ssp = (struct setspref *)space; + ssp->flags = 0; + ssp->num_servers = 0; + gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp; + gblob.in = space; + gblob.out = space; + gblob.out_size = MAXSIZE; + + + if (geteuid()) { + fprintf(stderr, "Permission denied: requires root access.\n"); + return 1; + } + + ti = as->parms[2].items; /* -file */ + if (ti) { + if (debug) + fprintf(stderr, "opening file %s\n", ti->data); + if (!(infd = fopen(ti->data, "r"))) { + perror(ti->data); + error = -1; + } else { + while (fscanf(infd, "%79s%ld", name, &rank) != EOF) { + code = addServer(name, (unsigned short)rank); + if (code) + error = code; + } + } + } + + ti = as->parms[3].items; /* -stdin */ + if (ti) { + while (scanf("%79s%ld", name, &rank) != EOF) { + code = addServer(name, (unsigned short)rank); + if (code) + error = code; + } + } + + for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */ + if (ti) { + if (!ti->next) { + break; + } + code = addServer(ti->data, (unsigned short)atol(ti->next->data)); + if (code) + error = code; + if (debug) + printf("set fs prefs %s %s\n", ti->data, ti->next->data); + ti = ti->next; + } + } + code = pokeServers(); + if (code) + error = code; + if (debug) + printf("now working on vlservers, code=%d\n", code); + + ssp = (struct setspref *)space; + ssp->flags = DBservers; + ssp->num_servers = 0; + gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp; + gblob.in = space; + + for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */ + if (ti) { + if (!ti->next) { + break; + } + code = addServer(ti->data, (unsigned short)atol(ti->next->data)); + if (code) + error = code; + if (debug) + printf("set vl prefs %s %s\n", ti->data, ti->next->data); + ti = ti->next; + } + } + + if (as->parms[1].items) { + if (debug) + printf("now poking vlservers\n"); + code = pokeServers(); + if (code) + error = code; + } + + if (error > 0) + Die(error, 0); + + return error ? 1 : 0; +} +#endif /* WIN32 */ + +#ifdef WIN32 +static int +GetPrefCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; + struct cmd_item *ti; + char *name, tbuffer[20]; + afs_int32 addr; + FILE * outfd; + int resolve; + int vlservers; + struct ViceIoctl blob; + struct cm_SPrefRequest *in; + struct cm_SPrefInfo *out; + int i; + + code = 0; + ti = as->parms[0].items; /* -file */ + if (ti) { + if (debug) fprintf(stderr,"opening file %s\n",ti->data); + if (!(outfd = freopen(ti->data,"w",stdout))) { + Die(errno,ti->data); + return errno; + } + } + + ti = as->parms[1].items; /* -numeric */ + resolve = !(ti); + ti = as->parms[2].items; /* -vlservers */ + vlservers = (ti ? CM_SPREF_VLONLY : 0); + /* ti = as->parms[3].items; -cell */ + + in = (struct cm_SPrefRequest *)space; + in->offset = 0; + + do { + blob.in_size=sizeof(struct cm_SPrefRequest); + blob.in = (char *)in; + blob.out = space; + blob.out_size = MAXSIZE; + + in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref); + in->flags = vlservers; + + code = pioctl(0, VIOC_GETSPREFS, &blob, 1); + if (code){ + perror("getserverprefs pioctl"); + Die (errno,0); + } + else { + out = (struct cm_SPrefInfo *) blob.out; + + for (i=0;inum_servers;i++) { + if (resolve) { + name = hostutil_GetNameByINet(out->servers[i].host.s_addr); + } + else { + addr = ntohl(out->servers[i].host.s_addr); + sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff, + (addr>>8) & 0xff, addr & 0xff); + name=tbuffer; + } + printf ("%-50s %5u\n",name,out->servers[i].rank); + } + + in->offset = out->next_offset; + } + } while (!code && out->next_offset > 0); + + return code; +} +#else +static int +GetPrefCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; + struct cmd_item *ti; + char *name, tbuffer[20]; + afs_int32 rank, addr; + FILE *outfd; + int resolve; + int vlservers = 0; + struct ViceIoctl blob; + struct sprefrequest *in; + struct sprefinfo *out; + int i; + + ti = as->parms[0].items; /* -file */ + if (ti) { + if (debug) + fprintf(stderr, "opening file %s\n", ti->data); + if (!(outfd = freopen(ti->data, "w", stdout))) { + perror(ti->data); + return 1; + } + } + + ti = as->parms[1].items; /* -numeric */ + resolve = !(ti); + ti = as->parms[2].items; /* -vlservers */ + vlservers |= (ti ? DBservers : 0); + /* ti = as->parms[3].items; -cell */ + + in = (struct sprefrequest *)space; + in->offset = 0; + + do { + blob.in_size = sizeof(struct sprefrequest); + blob.in = (char *)in; + blob.out = space; + blob.out_size = MAXSIZE; + + in->num_servers = + (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref); + in->flags = vlservers; + + code = pioctl(0, VIOC_GETSPREFS, &blob, 1); + if (code) { + perror("getserverprefs pioctl"); + return 1; + } + + out = (struct sprefinfo *)blob.out; + + for (i = 0; i < out->num_servers; i++) { + if (resolve) { + name = hostutil_GetNameByINet(out->servers[i].server.s_addr); + } else { + addr = ntohl(out->servers[i].server.s_addr); + sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff, + (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); + name = tbuffer; + } + printf("%-50s %5u\n", name, out->servers[i].rank); + } + + in->offset = out->next_offset; + } while (out->next_offset > 0); + + return 0; +} +#endif /* WIN32 */ + +static int +TraceCmd(struct cmd_syndesc *asp, char *arock) +{ + long code; struct ViceIoctl blob; long inValue; long outValue; @@ -2807,109 +3404,156 @@ static TraceCmd(struct cmd_syndesc *asp) #endif /* WIN32 */ if ((asp->parms[0].items && asp->parms[1].items)) { - fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n"); + fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n"); return EINVAL; } - /* determine if we're turning this tracing on or off */ - inValue = 0; + /* determine if we're turning this tracing on or off */ + inValue = 0; if (asp->parms[0].items) inValue = 3; /* enable */ - else if (asp->parms[1].items) inValue = 2; /* disable */ - if (asp->parms[2].items) inValue |= 4; /* do reset */ - if (asp->parms[3].items) inValue |= 8; /* dump */ + else if (asp->parms[1].items) + inValue = 2; /* disable */ + if (asp->parms[2].items) + inValue |= 4; /* do reset */ + if (asp->parms[3].items) + inValue |= 8; /* dump */ blob.in_size = sizeof(long); blob.in = (char *) &inValue; blob.out_size = sizeof(long); blob.out = (char *) &outValue; - code = pioctl(NULL, VIOC_TRACECTL, &blob, 1); - if (code) { - Die(errno, NULL); - return code; - } - - if (outValue) printf("AFS tracing enabled.\n"); - else printf("AFS tracing disabled.\n"); + code = pioctl(NULL, VIOC_TRACECTL, &blob, 1); + if (code) { + Die(errno, NULL); + return code; + } + + if (outValue) + printf("AFS tracing enabled.\n"); + else + printf("AFS tracing disabled.\n"); return 0; } -static void sbusage() +static void sbusage(void) { - fprintf(stderr, "example usage: fs storebehind -files *.o -kb 99999 -default 0\n"); - fprintf(stderr, " fs sb 50000 *.[ao] -default 10\n"); -} + fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn); + fprintf(stderr, " %s sb 50000 *.[ao] -default 10\n", pn); +} -static StoreBehindCmd(as) /* fs sb -kbytes 9999 -files *.o -default 64 */ -struct cmd_syndesc *as; { - afs_int32 code; +/* fs sb -kbytes 9999 -files *.o -default 64 */ +static int +StoreBehindCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code = 0; struct ViceIoctl blob; struct cmd_item *ti; - struct sbstruct tsb; - int kb; - + struct sbstruct tsb, tsb2; + int verbose = 0; + afs_int32 allfiles; + char *t; + int error = 0; + #ifdef WIN32 if ( !IsAdmin() ) { fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); return EACCES; } -#else /* WIN32 */ - if (geteuid()) { - fprintf (stderr,"Permission denied: requires root access.\n"); - return EACCES; - } #endif /* WIN32 */ - if ((as->parms[0].items && as->parms[1].items) || - (!as->parms[0].items && !as->parms[1].items)) /* same as logical xor */ - ; - else { - sbusage(); - return EINVAL; + tsb.sb_thisfile = -1; + ti = as->parms[0].items; /* -kbytes */ + if (ti) { + if (!as->parms[1].items) { + fprintf(stderr, "%s: you must specify -files with -kbytes.\n", + pn); + return 1; + } + tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024; + if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) { + fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn, + ti->data); + return 1; + } } - ti=as->parms[2].items; - if (ti && ti->data) { - kb = atoi (ti->data); + allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */ + ti = as->parms[2].items; /* -allfiles */ + if (ti) { + allfiles = strtol(ti->data, &t, 10) * 1024; + if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) { + fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn, + ti->data); + return 1; + } } - else kb = -1; - tsb.sb_default = kb; - ti=as->parms[1].items; - if (ti && ti->data) { - kb = atoi (ti->data); + /* -verbose or -file only or no options */ + if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items) + || (!as->parms[0].items && !as->parms[1].items + && !as->parms[2].items)) + verbose = 1; + + blob.in = (char *)&tsb; + blob.out = (char *)&tsb2; + blob.in_size = blob.out_size = sizeof(struct sbstruct); + memset(&tsb2, 0, sizeof(tsb2)); + + /* once per -file */ + for (ti = as->parms[1].items; ti; ti = ti->next) { + /* Do this solely to see if the file is there */ + code = pioctl(ti->data, VIOCWHEREIS, &blob, 1); + if (code) { + Die(errno, ti->data); + error = 1; + continue; + } + + code = pioctl(ti->data, VIOC_STOREBEHIND, &blob, 1); + if (code) { + Die(errno, ti->data); + error = 1; + continue; + } + + if (verbose && (blob.out_size == sizeof(tsb2))) { + if (tsb2.sb_thisfile == -1) { + fprintf(stdout, "Will store %s according to default.\n", + ti->data); + } else { + fprintf(stdout, + "Will store up to %d kbytes of %s asynchronously.\n", + (tsb2.sb_thisfile / 1024), ti->data); + } + } } - else kb = -1; - tsb.sb_thisfile = kb; - - ti=as->parms[0].items; - do { - /* once per file */ - blob.in = &tsb; - blob.out = &tsb; - blob.in_size = sizeof(tsb); - blob.out_size = sizeof(tsb); - fprintf (stderr, "storbehind %s %d %d\n", (ti?ti->data:0), - tsb.sb_thisfile, tsb.sb_default); - code = pioctl((ti ? ti->data : 0) , VIOC_STOREBEHIND, &blob, 1); - if (code) { - Die(errno, (ti ? ti->data : 0)); - continue; - } - if (blob.out_size == sizeof(tsb)) { - fprintf (stderr, "storbehind %s is now %d (default %d)\n", (ti?ti->data:0), - tsb.sb_thisfile, tsb.sb_default); - } - ti = (ti ? ti->next : ti); - } while (ti); - return 0; + /* If no files - make at least one pioctl call, or + * set the allfiles default if we need to. + */ + if (!as->parms[1].items || (allfiles != -1)) { + tsb.sb_default = allfiles; + code = pioctl(0, VIOC_STOREBEHIND, &blob, 1); + if (code) { + Die(errno, ((allfiles == -1) ? 0 : "-allfiles")); + error = 1; + } + } + + /* Having no arguments also reports the default store asynchrony */ + if (verbose && (blob.out_size == sizeof(tsb2))) { + fprintf(stdout, "Default store asynchrony is %d kbytes.\n", + (tsb2.sb_default / 1024)); + } + + return error; } -static afs_int32 SetCryptCmd(as) - struct cmd_syndesc *as; +static afs_int32 +SetCryptCmd(struct cmd_syndesc *as, char *arock) { afs_int32 code = 0, flag; struct ViceIoctl blob; @@ -2920,11 +3564,6 @@ static afs_int32 SetCryptCmd(as) fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); return EACCES; } -#else /* WIN32 */ - if (geteuid()) { - fprintf (stderr,"Permission denied: requires root access.\n"); - return EACCES; - } #endif /* WIN32 */ tp = as->parms[0].items->data; @@ -2942,25 +3581,26 @@ static afs_int32 SetCryptCmd(as) blob.out_size = 0; code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1); if (code) - Die(code, (char *) 0); + Die(code, NULL); return 0; } -static afs_int32 GetCryptCmd(as) - struct cmd_syndesc *as; +static afs_int32 +GetCryptCmd(struct cmd_syndesc *as, char *arock) { afs_int32 code = 0, flag; struct ViceIoctl blob; char *tp; - blob.in = (char *) 0; + blob.in = NULL; blob.in_size = 0; blob.out_size = sizeof(flag); blob.out = space; code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1); - if (code) Die(code, (char *) 0); + if (code) + Die(code, NULL); else { tp = space; memcpy(&flag, tp, sizeof(afs_int32)); @@ -2973,307 +3613,8 @@ static afs_int32 GetCryptCmd(as) return 0; } -main(argc, argv) -int argc; -char **argv; { - register afs_int32 code; - register struct cmd_syndesc *ts; - -#ifdef AFS_AIX32_ENV - /* - * The following signal action for AIX is necessary so that in case of a - * crash (i.e. core is generated) we can include the user's data section - * in the core dump. Unfortunately, by default, only a partial core is - * generated which, in many cases, isn't too useful. - */ - struct sigaction nsa; - - sigemptyset(&nsa.sa_mask); - nsa.sa_handler = SIG_DFL; - nsa.sa_flags = SA_FULLDUMP; - sigaction(SIGSEGV, &nsa, NULL); -#endif - -#ifdef WIN32 - WSADATA WSAjunk; - WSAStartup(0x0101, &WSAjunk); -#endif /* WIN32 */ - - /* try to find volume location information */ - - - osi_Init(); - - ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, "set server ranks"); - cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks"); - cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks"); - cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file"); - cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin"); - cmd_CreateAlias(ts, "sp"); - - ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, "get server ranks"); - cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file"); - cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only"); - cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers"); - /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */ - cmd_CreateAlias(ts, "gp"); - - ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list"); - cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory"); - cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries"); - cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list"); - cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights"); - parm_setacl_id = ts->nParms; - cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)"); - cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)"); - cmd_CreateAlias(ts, "sa"); - - ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, "list access control list"); - cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - parm_listacl_id = ts->nParms; - cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl"); - cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl"); - cmd_CreateAlias(ts, "la"); - - ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, "clean up access control list"); - cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - - ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, "copy access control list"); - cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)"); - cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)"); - cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list"); - parm_copyacl_id = ts->nParms; - cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl"); - cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl"); - - cmd_CreateAlias(ts, "ca"); - - ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache"); - cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - - ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status"); - cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units"); -#ifdef notdef - cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed"); -#endif - cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day"); - cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message"); - cmd_CreateAlias(ts, "sv"); - - ts = cmd_CreateSyntax("messages", GagCmd, 0, "control Cache Manager messages"); - cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]"); - - ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display volume status"); - cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - cmd_CreateAlias(ts, "lv"); - cmd_CreateAlias(ts, "listvol"); - - ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota"); - cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - cmd_CreateAlias(ts, "lq"); - - ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, "show server disk space usage"); - cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - cmd_CreateAlias(ts, "df"); - - ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage"); - cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - - ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point"); - cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory"); - - ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point"); - cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory"); - cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name"); - cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name"); - cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume"); - cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB"); - - /* - * - * defect 3069 - * - cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point"); - */ - - - ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point"); - cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory"); - - ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, "check local cell's servers"); - cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check"); - cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells"); - cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check"); - cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes"); - - ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd,0, "check volumeID/name mappings"); - cmd_CreateAlias(ts, "checkbackups"); - - - ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, "set cache size"); - cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)"); - cmd_CreateAlias(ts, "cachesize"); - - cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value"); - - ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, "get cache usage info"); - - ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, "list configured cells"); - - ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota"); - cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path"); - cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes"); -#ifdef notdef - cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes"); -#endif - cmd_CreateAlias(ts, "sq"); - - ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell"); -#ifndef WIN32 - cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name"); - cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers"); - cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name"); -#endif - -#ifdef FS_ENABLE_SERVER_DEBUG_PORTS - /* - * Turn this on only if you wish to be able to talk to a server which is listening - * on alternative ports. This is not intended for general use and may not be - * supported in the cache manager. It is not a way to run two servers at the - * same host, since the cache manager cannot properly distinguish those two hosts. - */ - cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port"); - cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port"); -#endif - - ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell"); - cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - - ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location"); - cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - - ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell"); - - /* - ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)"); - */ - - ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, "set cache monitor host address"); - cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'"); - cmd_CreateAlias(ts, "mariner"); - - - ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status"); - cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name"); - - ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status"); - cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name"); - cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs"); - cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs"); - - ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, "flush all data in volume"); - cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); - - ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, "get/set sysname (i.e. @sys) value"); - cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname"); - - ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, "enable/disable translators to AFS"); - cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name"); - cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')"); - cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')"); - cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')"); - cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')"); - - - ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0, - "store to server after file close"); - cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names"); - cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames"); - cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)"); - cmd_CreateAlias(ts, "sb"); - - ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0, "set cache manager encryption flag"); - cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off"); - - ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0, "get cache manager encryption flag"); - - ts = cmd_CreateSyntax("trace", TraceCmd, 0, "enable or disable CM tracing"); - cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing"); - cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing"); - cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents"); - cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents"); - cmd_CreateAlias(ts, "tr"); - - ts = cmd_CreateSyntax("memdump", MemDumpCmd, 0, "dump memory allocs in debug builds"); - cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint"); - cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs"); - - ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, 0, "change client side caching policy for AFS shares"); - cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share"); - cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents"); - cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents"); - cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents"); - cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching"); - - code = cmd_Dispatch(argc, argv); - -#ifndef WIN32 - if (rxInitDone) rx_Finalize(); -#endif /* not WIN32 */ - - return code; -} - -void Die(code, filename) - int code; - char *filename; -{ /*Die*/ - - if (code == EINVAL) { - if (filename) - fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename); - else fprintf(stderr,"%s: Invalid argument.\n", pn); - } - else if (code == ENOENT) { - if (filename) fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename); - else fprintf(stderr,"%s: no such file returned\n", pn); - } - else if (code == EROFS) fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn); - else if (code == EACCES || code == EPERM) { - if (filename) fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename); - else fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn); - } - else if (code == ENODEV) { - fprintf(stderr,"%s: AFS service may not have started.\n", pn); - } - else if (code == ESRCH) { - fprintf(stderr,"%s: Cell name not recognized.\n", pn); - } - else if (code == EPIPE) { - fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn); - } - else if (code == EFBIG) { - fprintf(stderr,"%s: Cache size too large.\n", pn); - } - else if (code == ETIMEDOUT) { - if (filename) - fprintf(stderr,"%s:'%s': Connection timed out", pn, filename); - else - fprintf(stderr,"%s: Connection timed out", pn); - } - else { - if (filename) fprintf(stderr,"%s:'%s'", pn, filename); - else fprintf(stderr,"%s", pn); -#ifdef WIN32 - fprintf(stderr, ": code 0x%x\n", code); -#else /* not WIN32 */ - fprintf(stderr,": %s\n", error_message(code)); -#endif /* not WIN32 */ - } -} /*Die*/ - -static MemDumpCmd(struct cmd_syndesc *asp) +static int +MemDumpCmd(struct cmd_syndesc *asp, char *arock) { long code; struct ViceIoctl blob; @@ -3281,7 +3622,7 @@ static MemDumpCmd(struct cmd_syndesc *asp) long outValue; if ((asp->parms[0].items && asp->parms[1].items)) { - fprintf(stderr, "fs trace: must use at most one of '-begin' or '-end'\n"); + fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn); return EINVAL; } @@ -3309,7 +3650,8 @@ static MemDumpCmd(struct cmd_syndesc *asp) return 0; } -static CSCPolicyCmd(struct cmd_syndesc *asp) +static int +CSCPolicyCmd(struct cmd_syndesc *asp, char *arock) { struct cmd_item *ti; char *share = NULL; @@ -3414,3 +3756,663 @@ static CSCPolicyCmd(struct cmd_syndesc *asp) RegCloseKey(hkCSCPolicy); return (0); } + +#ifndef WIN32 +/* get clients interface addresses */ +static int +GetClientAddrsCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; + struct cmd_item *ti; + char *name; + struct ViceIoctl blob; + struct sprefrequest *in; + struct sprefinfo *out; + + in = (struct sprefrequest *)space; + in->offset = 0; + + do { + blob.in_size = sizeof(struct sprefrequest); + blob.in = (char *)in; + blob.out = space; + blob.out_size = MAXSIZE; + + in->num_servers = + (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref); + /* returns addr in network byte order */ + code = pioctl(0, VIOC_GETCPREFS, &blob, 1); + if (code) { + perror("getClientInterfaceAddr pioctl"); + return 1; + } + + { + int i; + out = (struct sprefinfo *)blob.out; + for (i = 0; i < out->num_servers; i++) { + afs_int32 addr; + char tbuffer[32]; + addr = ntohl(out->servers[i].server.s_addr); + sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff, + (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); + printf("%-50s\n", tbuffer); + } + in->offset = out->next_offset; + } + } while (out->next_offset > 0); + + return 0; +} + +static int +SetClientAddrsCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code, addr; + struct cmd_item *ti; + char name[80]; + struct ViceIoctl blob; + struct setspref *ssp; + int sizeUsed = 0, i, flag; + afs_int32 existingAddr[1024]; /* existing addresses on this host */ + int existNu; + int error = 0; + + ssp = (struct setspref *)space; + ssp->num_servers = 0; + blob.in = space; + blob.out = space; + blob.out_size = MAXSIZE; + + if (geteuid()) { + fprintf(stderr, "Permission denied: requires root access.\n"); + return 1; + } + + /* extract all existing interface addresses */ + existNu = rx_getAllAddr(existingAddr, 1024); + if (existNu < 0) + return 1; + + sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */ + for (ti = as->parms[0].items; ti; ti = ti->next) { + if (sizeUsed >= sizeof(space)) { + fprintf(stderr, "No more space\n"); + return 1; + } + addr = extractAddr(ti->data, 20); /* network order */ + if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) { + fprintf(stderr, "Error in specifying address: %s..ignoring\n", + ti->data); + error = 1; + continue; + } + /* see if it is an address that really exists */ + for (flag = 0, i = 0; i < existNu; i++) + if (existingAddr[i] == addr) { + flag = 1; + break; + } + if (!flag) { /* this is an nonexistent address */ + fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr); + error = 1; + continue; + } + /* copy all specified addr into ioctl buffer */ + (ssp->servers[ssp->num_servers]).server.s_addr = addr; + printf("Adding 0x%08x\n", addr); + ssp->num_servers++; + sizeUsed += sizeof(struct spref); + } + if (ssp->num_servers < 1) { + fprintf(stderr, "No addresses specified\n"); + return 1; + } + blob.in_size = sizeUsed - sizeof(struct spref); + + code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */ + if (code) { + Die(errno, 0); + error = 1; + } + + return error; +} + +static int +FlushMountCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; + struct ViceIoctl blob; + struct cmd_item *ti; + char orig_name[1024]; /*Original name, may be modified */ + char true_name[1024]; /*``True'' dirname (e.g., symlink target) */ + char parent_dir[1024]; /*Parent directory of true name */ + char *last_component; /*Last component of true name */ + struct stat statbuff; /*Buffer for status info */ + int link_chars_read; /*Num chars read in readlink() */ + int thru_symlink; /*Did we get to a mount point via a symlink? */ + int error = 0; + + for (ti = as->parms[0].items; ti; ti = ti->next) { + /* once per file */ + thru_symlink = 0; + sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./", + ti->data); + + if (lstat(orig_name, &statbuff) < 0) { + /* if lstat fails, we should still try the pioctl, since it + * may work (for example, lstat will fail, but pioctl will + * work if the volume of offline (returning ENODEV). */ + statbuff.st_mode = S_IFDIR; /* lie like pros */ + } + + /* + * The lstat succeeded. If the given file is a symlink, substitute + * the file name with the link name. + */ + if ((statbuff.st_mode & S_IFMT) == S_IFLNK) { + thru_symlink = 1; + /* + * Read name of resolved file. + */ + link_chars_read = readlink(orig_name, true_name, 1024); + if (link_chars_read <= 0) { + fprintf(stderr, + "%s: Can't read target name for '%s' symbolic link!\n", + pn, orig_name); + error = 1; + continue; + } + + /* + * Add a trailing null to what was read, bump the length. + */ + true_name[link_chars_read++] = 0; + + /* + * If the symlink is an absolute pathname, we're fine. Otherwise, we + * have to create a full pathname using the original name and the + * relative symlink name. Find the rightmost slash in the original + * name (we know there is one) and splice in the symlink value. + */ + if (true_name[0] != '/') { + last_component = (char *)strrchr(orig_name, '/'); + strcpy(++last_component, true_name); + strcpy(true_name, orig_name); + } + } else + strcpy(true_name, orig_name); + + /* + * Find rightmost slash, if any. + */ + last_component = (char *)strrchr(true_name, '/'); + if (last_component) { + /* + * Found it. Designate everything before it as the parent directory, + * everything after it as the final component. + */ + strncpy(parent_dir, true_name, last_component - true_name); + parent_dir[last_component - true_name] = 0; + last_component++; /*Skip the slash */ + } else { + /* + * No slash appears in the given file name. Set parent_dir to the current + * directory, and the last component as the given name. + */ + strcpy(parent_dir, "."); + last_component = true_name; + } + + if (strcmp(last_component, ".") == 0 + || strcmp(last_component, "..") == 0) { + fprintf(stderr, + "%s: you may not use '.' or '..' as the last component\n", + pn); + fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n", + pn); + error = 1; + continue; + } + + blob.in = last_component; + blob.in_size = strlen(last_component) + 1; + blob.out_size = 0; + memset(space, 0, MAXSIZE); + + code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1); + + if (code != 0) { + if (errno == EINVAL) { + fprintf(stderr, "'%s' is not a mount point.\n", ti->data); + } else { + Die(errno, (ti->data ? ti->data : parent_dir)); + } + error = 1; + } + } + return error; +} + +static int +RxStatProcCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; + afs_int32 flags = 0; + struct ViceIoctl blob; + struct cmd_item *ti; + + if (as->parms[0].items) { /* -enable */ + flags |= AFSCALL_RXSTATS_ENABLE; + } + if (as->parms[1].items) { /* -disable */ + flags |= AFSCALL_RXSTATS_DISABLE; + } + if (as->parms[2].items) { /* -clear */ + flags |= AFSCALL_RXSTATS_CLEAR; + } + if (flags == 0) { + fprintf(stderr, "You must specify at least one argument\n"); + return 1; + } + + blob.in = (char *)&flags; + blob.in_size = sizeof(afs_int32); + blob.out_size = 0; + + code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1); + if (code != 0) { + Die(errno, NULL); + return 1; + } + + return 0; +} + +static int +RxStatPeerCmd(struct cmd_syndesc *as, char *arock) +{ + afs_int32 code; + afs_int32 flags = 0; + struct ViceIoctl blob; + struct cmd_item *ti; + + if (as->parms[0].items) { /* -enable */ + flags |= AFSCALL_RXSTATS_ENABLE; + } + if (as->parms[1].items) { /* -disable */ + flags |= AFSCALL_RXSTATS_DISABLE; + } + if (as->parms[2].items) { /* -clear */ + flags |= AFSCALL_RXSTATS_CLEAR; + } + if (flags == 0) { + fprintf(stderr, "You must specify at least one argument\n"); + return 1; + } + + blob.in = (char *)&flags; + blob.in_size = sizeof(afs_int32); + blob.out_size = 0; + + code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1); + if (code != 0) { + Die(errno, NULL); + return 1; + } + + return 0; +} +#endif /* WIN32 */ + +#ifndef WIN32 +#include "AFS_component_version_number.c" +#endif + +main(int argc, char **argv) +{ + afs_int32 code; + struct cmd_syndesc *ts; + +#ifdef AFS_AIX32_ENV + /* + * The following signal action for AIX is necessary so that in case of a + * crash (i.e. core is generated) we can include the user's data section + * in the core dump. Unfortunately, by default, only a partial core is + * generated which, in many cases, isn't too useful. + */ + struct sigaction nsa; + + sigemptyset(&nsa.sa_mask); + nsa.sa_handler = SIG_DFL; + nsa.sa_flags = SA_FULLDUMP; + sigaction(SIGSEGV, &nsa, NULL); +#endif + +#ifdef WIN32 + WSADATA WSAjunk; + WSAStartup(0x0101, &WSAjunk); +#endif /* WIN32 */ + + /* try to find volume location information */ + osi_Init(); + +#ifndef WIN32 + ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0, + "get client network interface addresses"); + cmd_CreateAlias(ts, "gc"); + + ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0, + "set client network interface addresses"); + cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS, + "client network interfaces"); + cmd_CreateAlias(ts, "sc"); +#endif /* WIN32 */ + + ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, "set server ranks"); + cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks"); + cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks"); + cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file"); + cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin"); + cmd_CreateAlias(ts, "sp"); + + ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, "get server ranks"); + cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file"); + cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only"); + cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers"); + /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */ + cmd_CreateAlias(ts, "gp"); + + ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list"); + cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory"); + cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries"); + cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list"); + cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights"); + parm_setacl_id = ts->nParms; + cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)"); + cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)"); + cmd_CreateAlias(ts, "sa"); + + ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, "list access control list"); + cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); + parm_listacl_id = ts->nParms; + cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl"); + cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl"); + cmd_CreateAlias(ts, "la"); + + ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, "clean up access control list"); + cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); + + ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, "copy access control list"); + cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)"); + cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)"); + cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list"); + parm_copyacl_id = ts->nParms; + cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl"); + cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl"); + + cmd_CreateAlias(ts, "ca"); + + ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache"); + cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); + +#ifndef WIN32 + ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0, + "flush mount symlink from cache"); + cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); +#endif + + ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status"); + cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); + cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units"); +#ifdef notdef + cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed"); +#endif + cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day"); + cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message"); + cmd_CreateAlias(ts, "sv"); + + ts = cmd_CreateSyntax("messages", MessagesCmd, 0, "control Cache Manager messages"); + cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]"); + + ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display file/volume status"); + cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); + cmd_CreateAlias(ts, "lv"); + cmd_CreateAlias(ts, "listvol"); + + ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota"); + cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); + cmd_CreateAlias(ts, "lq"); + + ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, "show server disk space usage"); + cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); + cmd_CreateAlias(ts, "df"); + + ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage"); + cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); + + ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point"); + cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory"); + + ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point"); + cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory"); + cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name"); + cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name"); + cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume"); + cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB"); + + /* + * + * defect 3069 + * + cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point"); + */ + + + ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point"); + cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory"); + + ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, "check local cell's servers"); + cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check"); + cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells"); + cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check"); + cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes"); + + ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd,0, "check volumeID/name mappings"); + cmd_CreateAlias(ts, "checkbackups"); + + + ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, "set cache size"); + cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)"); + cmd_CreateAlias(ts, "cachesize"); + + cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value"); + + ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, "get cache usage info"); + + ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, "list configured cells"); + cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only"); + + ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota"); + cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path"); + cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes"); +#ifdef notdef + cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes"); +#endif + cmd_CreateAlias(ts, "sq"); + + ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell"); +#ifndef WIN32 + cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name"); + cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers"); + cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name"); + +#ifdef FS_ENABLE_SERVER_DEBUG_PORTS + /* + * Turn this on only if you wish to be able to talk to a server which is listening + * on alternative ports. This is not intended for general use and may not be + * supported in the cache manager. It is not a way to run two servers at the + * same host, since the cache manager cannot properly distinguish those two hosts. + */ + cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port"); + cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port"); +#endif + + ts = cmd_CreateSyntax("newalias", NewAliasCmd, 0, + "configure new cell alias"); + cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name"); + cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell"); +#endif + + ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell"); + cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); + + ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location"); + cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); + + ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell"); + + /* + ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)"); + */ + + ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, "set cache monitor host address"); + cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'"); + cmd_CreateAlias(ts, "mariner"); + + + ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status"); + cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name"); + + ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status"); + cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name"); + cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs"); + cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs"); + + ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, "flush all data in volume"); + cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path"); + + ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, "get/set sysname (i.e. @sys) value"); + cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname"); + + ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, "enable/disable translators to AFS"); + cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name"); + cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')"); + cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')"); + cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')"); + cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')"); + + + ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0, + "store to server after file close"); + cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names"); + cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames"); + cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)"); + cmd_CreateAlias(ts, "sb"); + + ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0, "set cache manager encryption flag"); + cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off"); + + ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0, "get cache manager encryption flag"); + +#ifndef WIN32 + ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0, + "Manage per process RX statistics"); + cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats"); + cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats"); + cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats"); + + ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, 0, + "Manage per peer RX statistics"); + cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats"); + cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats"); + cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats"); + + ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, 0, "configure callback connection address"); + cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address"); +#endif + + ts = cmd_CreateSyntax("trace", TraceCmd, 0, "enable or disable CM tracing"); + cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing"); + cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing"); + cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents"); + cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents"); + cmd_CreateAlias(ts, "tr"); + + ts = cmd_CreateSyntax("memdump", MemDumpCmd, 0, "dump memory allocs in debug builds"); + cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint"); + cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs"); + + ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, 0, "change client side caching policy for AFS shares"); + cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share"); + cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents"); + cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents"); + cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents"); + cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching"); + + code = cmd_Dispatch(argc, argv); + +#ifndef WIN32 + if (rxInitDone) + rx_Finalize(); +#endif /* not WIN32 */ + + return code; +} + +static void +Die(int code, char *filename) +{ /*Die*/ + + if (code == EINVAL) { + if (filename) + fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename); + else + fprintf(stderr,"%s: Invalid argument.\n", pn); + } + else if (code == ENOENT) { + if (filename) + fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename); + else + fprintf(stderr,"%s: no such file returned\n", pn); + } + else if (code == EROFS) + fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn); + else if (code == EACCES || code == EPERM) { + if (filename) + fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename); + else + fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn); + } + else if (code == ENODEV) { + fprintf(stderr,"%s: AFS service may not have started.\n", pn); + } + else if (code == ESRCH) { + fprintf(stderr,"%s: Cell name not recognized.\n", pn); + } + else if (code == EPIPE) { + fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn); + } + else if (code == EFBIG) { + fprintf(stderr,"%s: Cache size too large.\n", pn); + } + else if (code == ETIMEDOUT) { + if (filename) + fprintf(stderr,"%s:'%s': Connection timed out", pn, filename); + else + fprintf(stderr,"%s: Connection timed out", pn); + } + else { + if (filename) + fprintf(stderr,"%s:'%s'", pn, filename); + else + fprintf(stderr,"%s", pn); +#ifdef WIN32 + fprintf(stderr, ": code 0x%x\n", code); +#else /* not WIN32 */ + fprintf(stderr,": %s\n", error_message(code)); +#endif /* not WIN32 */ + } +} /*Die*/ + diff --git a/src/WINNT/afsd/fs.h b/src/WINNT/afsd/fs.h index cfd473e20a..5f2c3bd0a7 100644 --- a/src/WINNT/afsd/fs.h +++ b/src/WINNT/afsd/fs.h @@ -11,18 +11,17 @@ #define __FS_H_ENV__ 1 /* some forward references */ -extern void ZapList(struct AclEntry *); +static void ZapList (struct AclEntry *alist); -extern void ZapAcl(struct Acl *); +static int PruneList (struct AclEntry **ae, int dfs); -extern int PruneList (struct AclEntry **, int); +static int CleanAcl(struct Acl *aa, char *fname); -extern void ChangeList(struct Acl *, afs_int32, char *, afs_int32); +static int SetVolCmd(struct cmd_syndesc *as, char *arock); -extern int CleanAcl(struct Acl *); +static int GetCellName(char *cellNamep, struct afsconf_cell *infop); -extern void Die(int, char *); - -static SetVolCmd(struct cmd_syndesc *); +static int VLDBInit(int noAuthFlag, struct afsconf_cell *infop); +static void Die(int code, char *filename); #endif /* FS_H_ENV */ diff --git a/src/WINNT/afsd/fs_utils.c b/src/WINNT/afsd/fs_utils.c index dddbb342df..45014264b1 100644 --- a/src/WINNT/afsd/fs_utils.c +++ b/src/WINNT/afsd/fs_utils.c @@ -121,6 +121,7 @@ long fs_GetFullPath(char *pathp, char *outPathp, long outSize) return 0; } +#ifdef COMMENT struct hostent *hostutil_GetHostByName(char *namep) { struct hostent *thp; @@ -149,6 +150,7 @@ char *hostutil_GetNameByINet(afs_uint32 addr) /* return static buffer */ return hostNameBuffer; } +#endif /* is this a digit or a digit-like thing? */ static int ismeta(ac, abase) diff --git a/src/WINNT/aklog/aklog.c b/src/WINNT/aklog/aklog.c index a226d3a156..4b017d96e7 100644 --- a/src/WINNT/aklog/aklog.c +++ b/src/WINNT/aklog/aklog.c @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef WIN32 #include diff --git a/src/WINNT/client_exp/NTMakefile b/src/WINNT/client_exp/NTMakefile index 61a7367e63..ebfc7b6890 100644 --- a/src/WINNT/client_exp/NTMakefile +++ b/src/WINNT/client_exp/NTMakefile @@ -59,7 +59,8 @@ DLLLIBS =\ $(DESTDIR)\lib\afsauthent.lib \ $(DESTDIR)\lib\libafsconf.lib \ $(DESTDIR)\lib\libosi.lib \ - $(DESTDIR)\lib\afs\TaLocale.lib + $(DESTDIR)\lib\afs\TaLocale.lib \ + $(DESTDIR)\lib\afs\afsutil.lib $(DLLFILE): $(DLLOBJS) $(DLLLIBS) $(DLLCONLINK) /DEF:afs_shl_ext.def $(DLLSDKLIBS)