📄 nfslib.c
字号:
** RETURNS: OK | ERROR*/LOCAL STATUS nfsClientCall ( char * host, /* server's host name */ u_int prognum, /* RPC program number */ u_int versnum, /* RPC version number */ u_int procnum, /* RPC procedure number */ xdrproc_t inproc, /* xdr routine for args */ char * in, xdrproc_t outproc, /* xdr routine for results */ char * out ) { nfstime tottimeout; enum clnt_stat clientStat; FAST NFS_MODULE_STATICS *ms; if (nfsInit () != OK) return (ERROR); ms = taskRpcStatics->nfsClientCache; /* get an appropriate client in the cache */ if (nfsClientCacheSetUp (ms, host, prognum, versnum) != OK) return (ERROR); /* set time to allow results to come back */ tottimeout.seconds = nfsTimeoutSec; tottimeout.useconds = nfsTimeoutUSec; clientStat = clnt_call (ms->client, procnum, inproc, in, outproc, out, tottimeout); if (clientStat != RPC_SUCCESS) { /* XXX this should be more gracefull */ nfsClientCacheCleanUp (ms); rpcClntErrnoSet (clientStat); return (ERROR); } return (OK); }/********************************************************************************* nfsClientClose - close the NFS client socket and associated structures** NOMANUAL*/void nfsClientClose (void) { if (taskRpcStatics != NULL) nfsClientCacheCleanUp (taskRpcStatics->nfsClientCache); }/********************************************************************************* nfsMountListPrint - prints a list of mount entries*/LOCAL void nfsMountListPrint ( FAST mountlist pMountList ) { while (pMountList) { printf ("%s:%s\n", pMountList->ml_hostname, pMountList->ml_directory); pMountList = pMountList->ml_next; } }/********************************************************************************* nfsGroupsPrint - print a list of groups*/LOCAL void nfsGroupsPrint ( FAST groups pGroup ) { while (pGroup != NULL) { printf ("%s ", pGroup->gr_name); pGroup = pGroup->gr_next; } }/********************************************************************************* nfsExportPrint - prints a list of exported file systems on a host*/LOCAL void nfsExportPrint ( FAST exports pExport ) { while (pExport != NULL) { printf ("%-25s ", pExport->ex_dir); nfsGroupsPrint (pExport->ex_groups); printf ("\n"); pExport = pExport->ex_next; } }/********************************************************************************* nfsErrnoSet - set NFS status** nfsErrnoSet calls errnoSet with the given "nfs stat" or'd with the* NFS status prefix.*/LOCAL void nfsErrnoSet ( enum nfsstat status ) { errnoSet (M_nfsStat | (int) status); }/********************************************************************************* nfsAuthUnixPrompt - modify the NFS UNIX authentication parameters** This routine allows* UNIX authentication parameters to be changed from the shell.* The user is prompted for each parameter, which can be changed* by entering the new value next to the current one.** EXAMPLE* .CS* -> nfsAuthUnixPrompt* machine name: yuba* user ID: 2001 128* group ID: 100* num of groups: 1 3* group #1: 100 100* group #2: 0 120* group #3: 0 200* value = 3 = 0x3* .CE** SEE ALSO: nfsAuthUnixShow(), nfsAuthUnixSet(), nfsAuthUnixGet(), nfsIdSet()*/void nfsAuthUnixPrompt (void) { char machname [AUTH_UNIX_FIELD_LEN];/* host name where client is */ int uid; /* client's UNIX effective uid */ int gid; /* client's current group ID */ int len; /* element length of aup_gids */ int aup_gids [MAX_GRPS]; /* array of groups user is in */ int ix; nfsAuthUnixGet (machname, &uid, &gid, &len, aup_gids); promptParamString ("machine name: ", machname, sizeof (machname)); promptParamNum ("user ID: ", &uid, 8, "%d "); promptParamNum ("group ID: ", &gid, 8, "%d "); promptParamNum ("num of groups: ", &len, 8, "%d "); for (ix = 0; ix < len; ix++) { printf ("group #%d: ", ix + 1); promptParamNum ("", &aup_gids [ix], 8, "%d "); } nfsAuthUnixSet (machname, uid, gid, len, aup_gids); }/********************************************************************************* nfsAuthUnixShow - display the NFS UNIX authentication parameters** This routine displays the parameters set by nfsAuthUnixSet() or* nfsAuthUnixPrompt().** EXAMPLE:* .CS* -> nfsAuthUnixShow* machine name = yuba* user ID = 2001* group ID = 100* group [0] = 100* value = 1 = 0x1* .CE** RETURNS: N/A** SEE ALSO: nfsAuthUnixPrompt(), nfsAuthUnixSet(), nfsAuthUnixGet(), nfsIdSet()*/void nfsAuthUnixShow (void) { char machname [AUTH_UNIX_FIELD_LEN]; /* host name where client is */ int uid; /* client's UNIX effective uid */ int gid; /* client's current group ID */ int len; /* element length of aup_gids */ int aup_gids [MAX_GRPS]; /* array of groups user is in */ int ix; nfsAuthUnixGet (machname, &uid, &gid, &len, aup_gids); printf ("machine name = %s\n", machname); printf ("user ID = %d\n", uid); printf ("group ID = %d\n", gid); for (ix = 0; ix < len; ix++) printf ("group [%d] = %d\n", ix, aup_gids [ix]); }/********************************************************************************* nfsAuthUnixSet - set the NFS UNIX authentication parameters** This routine sets UNIX authentication parameters.* It is initially called by usrNetInit().* `machname' should be set with the name of the mounted system (i.e. the target* name itself) to distinguish hosts from hosts on a NFS network.** RETURNS: N/A** SEE ALSO: nfsAuthUnixPrompt(), nfsAuthUnixShow(), nfsAuthUnixGet(), * nfsIdSet()* * **/void nfsAuthUnixSet ( char *machname, /* host machine */ int uid, /* user ID */ int gid, /* group ID */ int ngids, /* number of group IDs */ int *aup_gids /* array of group IDs */ ) { int ix; taskLock (); (void) strcpy (nfsAuthUnix.machname, machname); nfsAuthUnix.uid = uid; nfsAuthUnix.gid = gid; nfsAuthUnix.len = (ngids < MAX_GRPS ? ngids : MAX_GRPS); for (ix = 0; ix < ngids; ix++) nfsAuthUnix.aup_gids [ix] = aup_gids [ix]; /* Cached client authentications are out of date now. * Bump auth count so clients will be rebuilt with new auth, * next time the client transport is used. */ nfsAuthCount++; taskUnlock (); }/********************************************************************************* nfsAuthUnixGet - get the NFS UNIX authentication parameters** This routine gets the previously set UNIX authentication values.** RETURNS: N/A** SEE ALSO: nfsAuthUnixPrompt(), nfsAuthUnixShow(), nfsAuthUnixSet(), * nfsIdSet()*/void nfsAuthUnixGet ( char *machname, /* where to store host machine */ int *pUid, /* where to store user ID */ int *pGid, /* where to store group ID */ int *pNgids, /* where to store number of group IDs */ int *gids /* where to store array of group IDs */ ) { int ix; (void) strcpy (machname, nfsAuthUnix.machname); *pUid = nfsAuthUnix.uid; *pGid = nfsAuthUnix.gid; *pNgids = nfsAuthUnix.len; for (ix = 0; ix < nfsAuthUnix.len; ix++) gids [ix] = nfsAuthUnix.aup_gids [ix]; }/********************************************************************************* nfsIdSet - set the ID number of the NFS UNIX authentication parameters** This routine sets only the UNIX authentication user ID number.* For most NFS permission needs, only the user ID needs to be changed.* Set <uid> to the user ID on the NFS server.** RETURNS: N/A** SEE ALSO: nfsAuthUnixPrompt(), nfsAuthUnixShow(), nfsAuthUnixSet(),* nfsAuthUnixGet()* */void nfsIdSet ( int uid /* user ID on host machine */ ) { taskLock (); nfsAuthUnix.uid = uid; /* Cached client authentications are out of date now. * Bump auth count so clients will be rebuilt with new auth, * next time the client transport is used. */ nfsAuthCount++; taskUnlock (); }/********************************************************************************* printClear - print string with '?' for unprintable characters*/LOCAL void printClear ( FAST char *param ) { FAST char ch; while ((ch = *(param++)) != EOS) printf ("%c", (isascii ((UINT)ch) && isprint ((UINT)ch)) ? ch : '?'); }/********************************************************************************* promptParamString - prompt the user for a string parameter** - carriage return leaves the parameter unmodified;* - "." clears the parameter (null string).*/LOCAL void promptParamString ( char *msg, char *param, int fieldWidth ) { int ix; char buf [100]; FOREVER { printf ("%s ", msg); printClear (param); printf (" "); ix = fioRdString (STD_IN, buf, sizeof (buf)); if (ix < fieldWidth) break; printf ("too big - maximum field width = %d.\n", fieldWidth); } if (ix == 1) return; /* just CR; leave field unchanged */ if (buf[0] == '.') { param [0] = EOS; /* just '.'; make empty field */ return; } (void) strcpy (param, buf); /* update parameter */ }/********************************************************************************* promptParamNum - prompt the user for a parameter** - carriage return leaves the parameter unmodified;* - "." clears the parameter (0).*/LOCAL void promptParamNum ( char *msg, int *pParam, int fieldWidth, char *format ) { int ix; char buf [100]; FOREVER { (void) strcpy (buf, "%s "); (void) strcat (buf, format); printf (buf, msg, *pParam); ix = fioRdString (STD_IN, buf, sizeof (buf)); if (ix < fieldWidth) break; printf ("too big - maximum field width = %d.\n", fieldWidth); } if (ix == 1) return; /* just CR; leave field unchanged */ if (buf[0] == '.') { pParam = 0; /* just '.'; make empty field */ return; } (void) sscanf (buf, format, pParam); /* scan field */ }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -