From af1a0ea039223063b582cb44e55a4b58d1ec2836 Mon Sep 17 00:00:00 2001 From: Manuel Pereira Date: Thu, 19 Jun 2003 17:53:09 +0000 Subject: [PATCH] java-jafs-update-20030619 FIXES 1565 updates to java jafs, make it work with new cell code. --- src/JAVA/classes/ErrorMessages.properties | 20 + src/JAVA/classes/org/openafs/jafs/ACL.java | 724 +++++++++-- .../org/openafs/jafs/AFSException.java | 15 - .../openafs/jafs/AFSSecurityException.java | 15 - src/JAVA/classes/org/openafs/jafs/Cell.java | 39 +- src/JAVA/classes/org/openafs/jafs/Group.java | 6 +- src/JAVA/classes/org/openafs/jafs/Key.java | 8 - .../classes/org/openafs/jafs/Partition.java | 9 - src/JAVA/classes/org/openafs/jafs/Server.java | 16 +- src/JAVA/classes/org/openafs/jafs/Token.java | 1 - src/JAVA/classes/org/openafs/jafs/User.java | 47 +- src/JAVA/classes/org/openafs/jafs/Volume.java | 85 +- src/JAVA/libjafs/ACL.c | 94 +- src/JAVA/libjafs/AdminToken.c | 284 ++--- src/JAVA/libjafs/Cell.c | 601 +++++----- src/JAVA/libjafs/File.c | 36 +- src/JAVA/libjafs/FileInputStream.c | 11 +- src/JAVA/libjafs/FileOutputStream.c | 106 +- src/JAVA/libjafs/Group.c | 403 +++---- src/JAVA/libjafs/Internal.c | 261 ++-- src/JAVA/libjafs/Internal.h | 34 +- src/JAVA/libjafs/Key.c | 71 +- src/JAVA/libjafs/Makefile.in | 71 +- src/JAVA/libjafs/Partition.c | 108 +- src/JAVA/libjafs/Process.c | 435 +++---- src/JAVA/libjafs/Server.c | 759 +++++------- src/JAVA/libjafs/User.c | 1058 ++++++++--------- src/JAVA/libjafs/UserToken.c | 92 +- src/JAVA/libjafs/Volume.c | 357 +++--- src/afs/UKERNEL/afs_usrops.c | 12 +- src/afs/afs_cell.c | 30 +- src/libuafs/README | 8 +- 32 files changed, 2929 insertions(+), 2887 deletions(-) diff --git a/src/JAVA/classes/ErrorMessages.properties b/src/JAVA/classes/ErrorMessages.properties index 2f20124131..4821ffd682 100644 --- a/src/JAVA/classes/ErrorMessages.properties +++ b/src/JAVA/classes/ErrorMessages.properties @@ -11,6 +11,26 @@ E1002 = Session has expired, please login again E1003 = Operation aborted E1004 = Operation was forced to abort +#----------------------------------------------------------- +# Internal JAFS Error Codes +#----------------------------------------------------------- +E1050 = Could not allocate memory. +E1051 = Could not find specified Java class. +E1052 = Could not find specified Java method. +E1053 = Could not find specified Java field. +E1054 = Invalid argument value, argument is NULL. +E1055 = Username provided is NULL. +E1056 = Password provided is NULL. +E1057 = Group name provided is NULL. +E1058 = Group owner provided is NULL. +E1059 = Volume name provided is NULL. +E1060 = Partition name provided is NULL. +E1061 = Process name provided is NULL. +E1062 = Server name provided is NULL. +E1063 = Cell name provided is NULL. +E1064 = Invalid path name provided, path is NULL. +E1065 = Invalid ACL provided, string is NULL. + #----------------------------------------------------------- # Standard UNIX Error Codes #----------------------------------------------------------- diff --git a/src/JAVA/classes/org/openafs/jafs/ACL.java b/src/JAVA/classes/org/openafs/jafs/ACL.java index 10b1b96908..61e5ca22f8 100644 --- a/src/JAVA/classes/org/openafs/jafs/ACL.java +++ b/src/JAVA/classes/org/openafs/jafs/ACL.java @@ -33,6 +33,8 @@ import java.util.StringTokenizer; * This class is an extension of the standard Java File class with file-based * manipulation methods overridden by integrated AFS native methods. * + * @version 2.2, 03/24/2003 - Added new Delta ACL functionality and changes + * from Stonehenge. * @version 2.0, 04/18/2001 - Completely revised class for efficiency. */ @@ -41,9 +43,23 @@ public class ACL implements Serializable, Comparable private ACL.Entry[] positiveEntries; private ACL.Entry[] negativeEntries; - private String path; + private ACL.Entry[] positiveExpungeEntries; + private ACL.Entry[] negativeExpungeEntries; + + /** + * Path for this ACL, if null then this ACL instance is most likely a + * Delta ACL. + */ + private String path = null; - public ACL(String path) throws AFSException + private ACL() + { + } + public ACL( String path ) throws AFSException + { + this( path, true ); + } + public ACL( String path, boolean init ) throws AFSException { int numberPositiveEntries = 0; int numberNegativeEntries = 0; @@ -52,85 +68,562 @@ public class ACL implements Serializable, Comparable this.path = path; - StringTokenizer st = new StringTokenizer(getACLString(path), "\n\t"); - - buffer = st.nextToken(); - numberPositiveEntries = new Integer(buffer).intValue(); - positiveEntries = new ACL.Entry[numberPositiveEntries]; - - buffer = st.nextToken(); - numberNegativeEntries = new Integer(buffer).intValue(); - negativeEntries = new ACL.Entry[numberNegativeEntries]; - - for(int i = 0; i < numberPositiveEntries; i++) - { - aclEntry = new ACL.Entry(); - aclEntry.setUser(st.nextToken()); - aclEntry.setPermissions(new Integer(st.nextToken()).intValue()); - positiveEntries[i] = aclEntry; - } - - for(int i = 0; i < numberNegativeEntries; i++) - { - aclEntry = new ACL.Entry(); - aclEntry.setUser(st.nextToken()); - aclEntry.setPermissions(new Integer(st.nextToken()).intValue()); - negativeEntries[i] = aclEntry; + if ( init ) { + StringTokenizer st = new StringTokenizer( getACLString(path), "\n\t" ); + + buffer = st.nextToken(); + numberPositiveEntries = new Integer(buffer).intValue(); + positiveEntries = new ACL.Entry[numberPositiveEntries]; + + buffer = st.nextToken(); + numberNegativeEntries = new Integer(buffer).intValue(); + negativeEntries = new ACL.Entry[numberNegativeEntries]; + + for(int i = 0; i < numberPositiveEntries; i++) + { + aclEntry = new ACL.Entry(); + aclEntry.setUser(st.nextToken()); + aclEntry.setPermissions(new Integer(st.nextToken()).intValue()); + positiveEntries[i] = aclEntry; + } + + for(int i = 0; i < numberNegativeEntries; i++) + { + aclEntry = new ACL.Entry(); + aclEntry.setUser(st.nextToken()); + aclEntry.setPermissions(new Integer(st.nextToken()).intValue()); + negativeEntries[i] = aclEntry; + } + } else { + positiveEntries = new ACL.Entry[0]; + negativeEntries = new ACL.Entry[0]; } } + /** + * Returns the total number of ACL entries, this is the sum of positive + * and negative entries. + * + * @return Total number of ACL entries + */ public int getEntryCount() { - return positiveEntries.length + positiveEntries.length; + return getPositiveEntryCount() + getNegativeEntryCount(); } + /** + * Returns the path this ACL instance is bound to. + * + * @return Path for this ACL + */ public String getPath() { return path; } - public ACL.Entry[] getPositiveEntries() - { - return positiveEntries; - } - public void addPositiveEntry(ACL.Entry entry) throws AFSException - { - int n = positiveEntries.length; - ACL.Entry[] e = new ACL.Entry[n + 1]; - System.arraycopy(positiveEntries, 0, e, 0, n); - e[n] = entry; - positiveEntries = e; - setACLString(path, getFormattedString()); - } - public void setPositiveEntries(ACL.Entry[] entries) throws AFSException - { - this.positiveEntries = entries; - setACLString(path, getFormattedString()); - } - public ACL.Entry[] getNegativeEntries() - { - return negativeEntries; - } - public void addNegativeEntry(ACL.Entry entry) throws AFSException - { - int n = negativeEntries.length; - ACL.Entry[] e = new ACL.Entry[n + 1]; - System.arraycopy(negativeEntries, 0, e, 0, n); - e[n] = entry; - negativeEntries = e; - setACLString(path, getFormattedString()); - } - public void setNegativeEntries(ACL.Entry[] entries) throws AFSException - { - this.negativeEntries = entries; - setACLString(path, getFormattedString()); - } - + /** + * Writes the ACL to AFS, making all changes immediately effective. + * This method requires an active connection to AFS. + */ public void flush() throws AFSException { setACLString(path, getFormattedString()); } - private ACL.Entry[] getNonEmptyEntries(ACL.Entry[] entries) + + /*--------------------------------------------------------------------------*/ + /* Positive ACL Methods */ + /*--------------------------------------------------------------------------*/ + + /** + * Returns the number of positive ACL entries for this ACL instance. + * + * @return Positive ACL entry count + */ + public int getPositiveEntryCount() { - ArrayList response = new ArrayList(entries.length); + return ( positiveEntries == null ) ? 0 : positiveEntries.length; + } + /** + * Returns all positive ACL entries for this ACL instance. + * + * @return All positive ACL entries + */ + public ACL.Entry[] getPositiveEntries() + { + return ( positiveEntries == null ) ? new ACL.Entry[0] : positiveEntries; + } + /** + * Returns the positive ACL entry associated with the specified + * user/group name. + * + * @param name Name of user/group for desired ACL entry. + * @return Positive ACL entry + * @see ACL.Entry#getUser() + */ + public Entry getPositiveEntry(String name) + { + int n = getPositiveEntryCount(); + for (int i = 0; i < n; i++) { + if (positiveEntries[i].getUser().equalsIgnoreCase(name)) { + return positiveEntries[i]; + } + } + return null; + } + /** + * Returns all positive ACL entries to be expunged; used in Delta ACLs. + * + * @return All positive ACL entries + */ + public ACL.Entry[] getPositiveExpungeEntries() + { + return ( positiveExpungeEntries == null ) ? new ACL.Entry[0] : positiveExpungeEntries; + } + /** + * Returns true if this ACL contains the specified ACL entry. + * + * @param entry Positive ACL entry + * @return true if the specified ACL entry is present; + * false otherwise. + */ + public boolean containsPositiveEntry(Entry entry) + { + int n = getPositiveEntryCount(); + for (int i = 0; i < n; i++) { + if (positiveEntries[i].equals(entry)) { + return true; + } + } + return false; + } + /** + * Adds a single positive ACL entry to this ACL instance. + * + * @param entry ACL.Entry object to add + */ + public void addPositiveEntry( ACL.Entry entry ) throws AFSException + { + int n = getPositiveEntryCount(); + ACL.Entry[] e = new ACL.Entry[n + 1]; + if ( n > 0 ) System.arraycopy(positiveEntries, 0, e, 0, n); + e[n] = entry; + positiveEntries = e; + update(); + } + /** + * Adds the provided list of positive ACL entries to this ACL instance. + * + * @param entries Array of ACL.Entry objects to add + */ + public void addPositiveEntries( ACL.Entry[] entries ) throws AFSException + { + int n = getPositiveEntryCount(); + ACL.Entry[] e = new ACL.Entry[n + entries.length]; + System.arraycopy(positiveEntries, 0, e, 0, n); + System.arraycopy(entries,0,e,n,entries.length); + positiveEntries = e; + update(); + } + /** + * Sets the complete array of positive ACL entries to the provided + * ACL entry list (entries) for this ACL instance. + * + * @param entries Array of ACL.Entry objects that represent this + * ACL's positive entry list. + */ + public void setPositiveEntries( ACL.Entry[] entries ) throws AFSException + { + this.positiveEntries = entries; + update(); + } + /** + * Add a positive ACL entry to the list of positive ACL entries to be + * expunged; used in Delta ACLs. + * + * @param entry Positive ACL entries to be expunged. + */ + public void addPositiveExpungeEntry( ACL.Entry entry ) throws AFSException + { + int n = ( positiveExpungeEntries == null ) ? 0 : positiveExpungeEntries.length; + ACL.Entry[] e = new ACL.Entry[n + 1]; + if ( n > 0 ) System.arraycopy(positiveExpungeEntries, 0, e, 0, n); + e[n] = entry; + positiveExpungeEntries = e; + update(); + } + + /** + * Removes a single positive ACL entry from this ACL instance. + * + * @param entry ACL.Entry object to removed + */ + public void removePositiveEntry(Entry entry) throws AFSException + { + int n = getPositiveEntryCount(); + ArrayList list = new ArrayList(); + + for (int i = 0; i < n; i++) { + if (!positiveEntries[i].equals(entry)) { + list.add(positiveEntries[i]); + } + } + + positiveEntries = (ACL.Entry[]) list.toArray(new ACL.Entry[list.size()]); + update(); + } + /** + * Removes all positive ACL entries from this ACL instance. + */ + public void removeAllPositiveEntries() throws AFSException + { + positiveEntries = new Entry[0]; + update(); + } + + + /*--------------------------------------------------------------------------*/ + /* Negative ACL Methods */ + /*--------------------------------------------------------------------------*/ + + /** + * Returns the number of negative ACL entries for this ACL instance. + * + * @return Negative ACL entry count + */ + public int getNegativeEntryCount() + { + return ( negativeEntries == null ) ? 0 : negativeEntries.length; + } + /** + * Returns all negative ACL entries for this ACL instance. + * + * @return All negative ACL entries + */ + public ACL.Entry[] getNegativeEntries() + { + return ( negativeEntries == null ) ? new ACL.Entry[0] : negativeEntries; + } + /** + * Returns the negative ACL entry associated with the specified + * user/group name. + * + * @param name Name of user/group for desired ACL entry. + * @return Negative ACL entry + * @see ACL.Entry#getUser() + */ + public Entry getNegativeEntry(String name) + { + int n = getNegativeEntryCount(); + for (int i = 0; i < n; i++) { + if (negativeEntries[i].getUser().equalsIgnoreCase(name)) { + return negativeEntries[i]; + } + } + return null; + } + /** + * Returns all negative ACL entries to be expunged; used in Delta ACLs. + * + * @return All negative ACL entries to be expunged. + */ + public ACL.Entry[] getNegativeExpungeEntries() + { + return ( negativeExpungeEntries == null ) ? new ACL.Entry[0] : negativeExpungeEntries; + } + /** + * Returns true if this ACL contains the specified ACL entry. + * + * @param entry Negative ACL entry + * @return true if the specified ACL entry is present; + * false otherwise. + */ + public boolean containsNegative(Entry entry) + { + int n = getNegativeEntryCount(); + for (int i = 0; i < n; i++) { + if (negativeEntries[i].equals(entry)) { + return true; + } + } + return false; + } + /** + * Adds a single negative ACL entry to this ACL instance. + * + * @param entry ACL.Entry object to add + */ + public void addNegativeEntry( ACL.Entry entry ) throws AFSException + { + int n = getNegativeEntryCount(); + ACL.Entry[] e = new ACL.Entry[n + 1]; + if ( n > 0 ) System.arraycopy(negativeEntries, 0, e, 0, n); + e[n] = entry; + negativeEntries = e; + update(); + } + /** + * Adds the provided list of negative ACL entries to this ACL instance. + * + * @param entries Array of ACL.Entry objects to add + */ + public void addNegativeEntries( ACL.Entry[] entries ) throws AFSException + { + int n = getNegativeEntryCount(); + ACL.Entry[] e = new ACL.Entry[n + entries.length]; + System.arraycopy(negativeEntries, 0, e, 0, n); + System.arraycopy(entries,0,e,n,entries.length); + negativeEntries = e; + update(); + } + /** + * Add a negative ACL entry to the list of negative ACL entries to be + * expunged; used in Delta ACLs. + * + * @param entry Negative ACL entries to be expunged. + */ + public void addNegativeExpungeEntry( ACL.Entry entry ) throws AFSException + { + int n = ( negativeExpungeEntries == null ) ? 0 : negativeExpungeEntries.length; + ACL.Entry[] e = new ACL.Entry[n + 1]; + if ( n > 0 ) System.arraycopy(negativeExpungeEntries, 0, e, 0, n); + e[n] = entry; + negativeExpungeEntries = e; + update(); + } + /** + * Sets the complete array of negative ACL entries to the provided + * ACL entry list (entries) for this ACL instance. + * + * @param entries Array of ACL.Entry objects that represent this + * ACL's negative entry list. + */ + public void setNegativeEntries( ACL.Entry[] entries ) throws AFSException + { + this.negativeEntries = entries; + update(); + } + + /** + * Removes a single negative ACL entry from this ACL instance. + * + * @param entry ACL.Entry object to removed + */ + public void removeNegativeEntry(Entry entry) throws AFSException + { + int n = getNegativeEntryCount(); + ArrayList list = new ArrayList(); + + for (int i = 0; i < n; i++) { + if (!negativeEntries[i].equals(entry)) { + list.add(negativeEntries[i]); + } + } + + negativeEntries = (ACL.Entry[]) list.toArray(new ACL.Entry[list.size()]); + update(); + } + + /** + * Removes all negative ACL entries from this ACL instance. + */ + public void removeAllNegativeEntries() throws AFSException + { + negativeEntries = new Entry[0]; + update(); + } + + + /*--------------------------------------------------------------------------*/ + /* Delta ACL Methods */ + /*--------------------------------------------------------------------------*/ + + /** + * Returns a "Delta ACL", which is an ACL that represents only the difference + * (delta) of two ACLs, relative to the current ACL instance by the provided + * ACL specified by acl. + * + *

This ACL instance represents the base or reference object while the + * provided ACL (acl) represents the object in question. + * Therefore, if the provided ACL has an entry that differs from the base ACL, + * then the resulting Delta ACL will contain that entry found in the provided + * ACL; base ACL entries are never entered into the Delta ACL, but rather are + * used solely for comparison. + * + * @param acl the ACL to compare this ACL instance to + * @return Delta ACL by comparing this ACL instance with acl + */ + public ACL getDeltaACL( ACL acl ) throws AFSException + { + ACL delta = new ACL(); + int n = getPositiveEntryCount(); + + ACL.Entry[] pEntries = acl.getPositiveEntries(); + for ( int i = 0; i < pEntries.length; i++ ) + { + boolean match = false; + for ( int j = 0; j < n; j++ ) + { + if ( pEntries[i].equals( positiveEntries[j] ) ) { + match = true; + break; + } + } + if ( !match ) delta.addPositiveEntry( pEntries[i] ); + } + + // Check for positive entries that need to be expunged. + n = getPositiveEntryCount(); + if ( n > pEntries.length ) { + for ( int i = 0; i < n; i++ ) + { + String eu = positiveEntries[i].getUser(); + boolean match = false; + for ( int j = 0; j < pEntries.length; j++ ) + { + if ( eu != null && eu.equals( pEntries[j].getUser() ) ) { + match = true; + break; + } + } + if ( !match ) delta.addPositiveExpungeEntry( positiveEntries[i] ); + } + } + + n = getNegativeEntryCount(); + ACL.Entry[] nEntries = acl.getNegativeEntries(); + for ( int i = 0; i < nEntries.length; i++ ) + { + boolean match = false; + for ( int j = 0; j < n; j++ ) + { + if ( nEntries[i].equals( negativeEntries[j] ) ) { + match = true; + break; + } + } + if ( !match ) delta.addNegativeEntry( nEntries[i] ); + } + + // Check for negative entries that need to be expunged. + n = getNegativeEntryCount(); + if ( n > nEntries.length ) { + for ( int i = 0; i < n; i++ ) + { + String eu = negativeEntries[i].getUser(); + boolean match = false; + for ( int j = 0; j < nEntries.length; j++ ) + { + if ( eu != null && eu.equals( nEntries[j].getUser() ) ) { + match = true; + break; + } + } + if ( !match ) delta.addNegativeExpungeEntry( negativeEntries[i] ); + } + } + + return delta; + } + + /** + * Updates the current ACL instance by replacing, adding, or deleting + * ACL entries designated by the specified Delta ACL (delta). + * + *

If the provided Delta ACL has an entry that differs from this ACL + * instance, then the ACL entry of the Delta ACL will be set. + * + * @param delta the Delta ACL to be applied to this ACL instance + */ + public void update( ACL delta ) throws AFSException + { + ArrayList pos = new ArrayList( this.getPositiveEntryCount() ); + ArrayList neg = new ArrayList( this.getNegativeEntryCount() ); + + ACL.Entry[] pExpungeEntries = delta.getPositiveExpungeEntries(); + ACL.Entry[] nExpungeEntries = delta.getNegativeExpungeEntries(); + + ACL.Entry[] pEntries = delta.getPositiveEntries(); + ACL.Entry[] nEntries = delta.getNegativeEntries(); + + // Delete positive expunge entries first + int n = getPositiveEntryCount(); + for ( int i = 0; i < n; i++ ) + { + boolean match = false; + for ( int j = 0; j < pExpungeEntries.length; j++ ) + { + if ( pExpungeEntries[j].equals( positiveEntries[i] ) ) { + match = true; + break; + } + } + if ( !match ) pos.add( positiveEntries[i] ); + } + + // Now check for entries that need replacing + for ( int i = 0; i < pEntries.length; i++ ) + { + boolean match = false; + String user = pEntries[i].getUser(); + for ( int j = 0; j < pos.size(); j++ ) + { + if ( user.equals( ((ACL.Entry)pos.get(j)).getUser() ) ) { + pos.set( j, pEntries[i] ); + match = true; + break; + } + } + if ( !match ) pos.add( pEntries[i] ); + } + setPositiveEntries( (ACL.Entry[])pos.toArray(new ACL.Entry[pos.size()]) ); + + // Delete negative expunge entries next + n = getNegativeEntryCount(); + for ( int i = 0; i < n; i++ ) + { + boolean match = false; + for ( int j = 0; j < nExpungeEntries.length; j++ ) + { + if ( nExpungeEntries[j].equals( negativeEntries[i] ) ) { + match = true; + break; + } + } + if ( !match ) neg.add( negativeEntries[i] ); + } + + // Now check for entries that need replacing (negative) + for ( int i = 0; i < nEntries.length; i++ ) + { + boolean match = false; + String user = nEntries[i].getUser(); + for ( int j = 0; j < neg.size(); j++ ) + { + if ( user.equals( ((ACL.Entry)neg.get(j)).getUser() ) ) { + neg.set( j, nEntries[i] ); + match = true; + break; + } + } + if ( !match ) neg.add( nEntries[i] ); + } + setNegativeEntries( (ACL.Entry[])neg.toArray(new ACL.Entry[neg.size()]) ); + } + + + /*--------------------------------------------------------------------------*/ + /* Private Methods */ + /*--------------------------------------------------------------------------*/ + + /** + * Returns a resized array containing only valid (non-empty) ACL entries. + * + * @param entries Original array of entries, possibly containing empty + * entries. + * @return All non-empty ACL entries + */ + private ACL.Entry[] getNonEmptyEntries( ACL.Entry[] entries ) + { + if ( entries == null ) return new ACL.Entry[0]; + ArrayList list = new ArrayList( entries.length ); for (int i = 0; i < entries.length; i++) { boolean isNonEmpty = entries[i].canRead() || @@ -140,23 +633,28 @@ public class ACL implements Serializable, Comparable entries[i].canDelete() || entries[i].canLock() || entries[i].canAdmin(); - if (isNonEmpty) response.add(entries[i]); + if (isNonEmpty) list.add(entries[i]); } - if (response.size() == entries.length) return entries; - return (ACL.Entry[])response.toArray(new ACL.Entry[response.size()]); + if (list.size() == entries.length) return entries; + return (ACL.Entry[])list.toArray(new ACL.Entry[list.size()]); } - private void entriesToString(ACL.Entry[] entries, StringBuffer response) + private void entriesToString( ACL.Entry[] entries, StringBuffer buffer ) { for (int i = 0; i < entries.length; i++) { - this.entryToString((ACL.Entry)entries[i], response); + this.entryToString((ACL.Entry)entries[i], buffer); } } - private void entryToString(ACL.Entry entry, StringBuffer response) + private void entryToString( ACL.Entry entry, StringBuffer buffer ) { - response.append(entry.getUser() + '\t' + entry.getPermissionsMask() + '\n'); + buffer.append(entry.getUser() + '\t' + entry.getPermissionsMask() + '\n'); + } + + private void update() throws AFSException + { + if ( path != null ) setACLString(path, getFormattedString()); } /** @@ -179,7 +677,10 @@ public class ACL implements Serializable, Comparable return out.toString(); } - /////////////// custom override methods //////////////////// + + /*--------------------------------------------------------------------------*/ + /* Custom Override Methods */ + /*--------------------------------------------------------------------------*/ /** * Compares two ACL objects respective to their paths and does not @@ -234,9 +735,14 @@ public class ACL implements Serializable, Comparable ACL.Entry[] nonEmptyPos = this.getNonEmptyEntries(this.getPositiveEntries()); ACL.Entry[] nonEmptyNeg = this.getNonEmptyEntries(this.getNegativeEntries()); - StringBuffer out = new StringBuffer("ACL for "); - out.append(path); - out.append("\n"); + StringBuffer out = new StringBuffer(); + if ( path == null ) { + out.append("Delta ACL\n"); + } else { + out.append("ACL for "); + out.append(path); + out.append("\n"); + } out.append("Positive Entries:\n"); for (int i = 0; i < nonEmptyPos.length; i++) { out.append(" "); @@ -250,10 +756,33 @@ public class ACL implements Serializable, Comparable } } + // Check to see if this is a Delta ACL + if ( path == null ) { + nonEmptyPos = this.getNonEmptyEntries(this.getPositiveExpungeEntries()); + nonEmptyNeg = this.getNonEmptyEntries(this.getNegativeExpungeEntries()); + + if (nonEmptyPos.length > 0) { + out.append("Positive Entries to Delete:\n"); + for (int i = 0; i < nonEmptyPos.length; i++) { + out.append(" "); + out.append(nonEmptyPos[i].toString()); + } + } + if (nonEmptyNeg.length > 0) { + out.append("Negative Entries to Delete:\n"); + for (int i = 0; i < nonEmptyNeg.length; i++) { + out.append(" "); + out.append(nonEmptyNeg[i].toString()); + } + } + } + return out.toString(); } - /////////////// native methods //////////////////// + /*--------------------------------------------------------------------------*/ + /* Native Methods */ + /*--------------------------------------------------------------------------*/ /** * Returns a formatted String representing the ACL for the specified path. @@ -278,7 +807,7 @@ public class ACL implements Serializable, Comparable private native void setACLString(String path, String aclString) throws AFSException; /*====================================================================*/ - /* INNER CLASSES */ + /* INNER CLASSES */ /*====================================================================*/ /** @@ -456,13 +985,13 @@ public class ACL implements Serializable, Comparable username = user; } /** - * File Permission Tests whether the ACL permits read access. + * File Permission Tests whether the ACL permits read access. * *

This permission enables a user to read the contents of files in the directory * and to obtain complete status information for the files (read/retrieve the file * attributes). * - *

File Permission File Permission
+ *

File Permission File Permission
* This permission is meaningful with respect to files in * a directory, rather than the directory itself or its subdirectories. * @@ -487,7 +1016,7 @@ public class ACL implements Serializable, Comparable r = flag; } /** - * Directory Permission Tests whether the ACL permits lookup access. + * Directory Permission Tests whether the ACL permits lookup access. * *

This permission functions as something of a gate keeper for access to the directory * and its files, because a user must have it in order to exercise any other permissions. @@ -507,7 +1036,7 @@ public class ACL implements Serializable, Comparable * the directory. Those operations require the lookup permission on the ACL * of the subdirectory itself. * - *

Directory Permission Directory Permission
+ *

Directory Permission Directory Permission
* This permission is meaningful with respect to the * directory itself. For example, the insert permission (see: {@link #canInsert}) * does not control addition of data to a file, but rather creation of a new file or @@ -534,13 +1063,13 @@ public class ACL implements Serializable, Comparable l = flag; } /** - * Directory Permission Tests whether the ACL permits insert access. + * Directory Permission Tests whether the ACL permits insert access. * *

This permission enables a user to add new files to the directory, either by creating * or copying, and to create new subdirectories. It does not extend into any subdirectories, * which are protected by their own ACLs. * - *

Directory Permission Directory Permission
+ *

Directory Permission Directory Permission
* This permission is meaningful with respect to the * directory itself. For example, the insert permission (see: {@link #canInsert}) * does not control addition of data to a file, but rather creation of a new file or @@ -567,13 +1096,13 @@ public class ACL implements Serializable, Comparable i = flag; } /** - * Directory Permission Tests whether the ACL permits delete access. + * Directory Permission Tests whether the ACL permits delete access. * *

This permission enables a user to remove files and subdirectories from the directory * or move them into other directories (assuming that the user has the insert * (see: {@link #canInsert}) permission on the ACL of the other directories). * - *

Directory Permission Directory Permission
+ *

Directory Permission Directory Permission
* This permission is meaningful with respect to the * directory itself. For example, the insert permission (see: {@link #canInsert}) * does not control addition of data to a file, but rather creation of a new file or @@ -600,12 +1129,12 @@ public class ACL implements Serializable, Comparable d = flag; } /** - * File Permission Tests whether the ACL permits write access. + * File Permission Tests whether the ACL permits write access. * *

This permission enables a user to modify the contents of files in the directory * and to change their operating system specific mode bits. * - *

File Permission File Permission
+ *

File Permission File Permission
* This permission is meaningful with respect to files in * a directory, rather than the directory itself or its subdirectories. * @@ -630,12 +1159,12 @@ public class ACL implements Serializable, Comparable w = flag; } /** - * File Permission Tests whether the ACL permits the lock authority. + * File Permission Tests whether the ACL permits the lock authority. * *

This permission enables the user to run programs that issue system calls to * lock files in the directory. * - *

File Permission File Permission
+ *

File Permission File Permission
* This permission is meaningful with respect to files in * a directory, rather than the directory itself or its subdirectories. * @@ -660,7 +1189,7 @@ public class ACL implements Serializable, Comparable k = flag; } /** - * Directory Permission Tests whether the ACL permits administer access. + * Directory Permission Tests whether the ACL permits administer access. * *

This permission enables a user to change the directory's ACL. Members of the * system:administrators group implicitly have this permission on every @@ -668,7 +1197,7 @@ public class ACL implements Serializable, Comparable * owner of a directory implicitly has this permission on its ACL and those of all * directories below it that he or she owns. * - *

Directory Permission Directory Permission
+ *

Directory Permission Directory Permission
* This permission is meaningful with respect to the * directory itself. For example, the insert permission (see: {@link #canInsert}) * does not control addition of data to a file, but rather creation of a new file or @@ -732,12 +1261,3 @@ public class ACL implements Serializable, Comparable } } - - - - - - - - - diff --git a/src/JAVA/classes/org/openafs/jafs/AFSException.java b/src/JAVA/classes/org/openafs/jafs/AFSException.java index a250f9abab..ed6154e5ba 100644 --- a/src/JAVA/classes/org/openafs/jafs/AFSException.java +++ b/src/JAVA/classes/org/openafs/jafs/AFSException.java @@ -187,18 +187,3 @@ public class AFSException extends Exception } /*-----------------------------------------------------------------------*/ } - - - - - - - - - - - - - - - diff --git a/src/JAVA/classes/org/openafs/jafs/AFSSecurityException.java b/src/JAVA/classes/org/openafs/jafs/AFSSecurityException.java index 2aacb400ac..2a138ecf6a 100644 --- a/src/JAVA/classes/org/openafs/jafs/AFSSecurityException.java +++ b/src/JAVA/classes/org/openafs/jafs/AFSSecurityException.java @@ -185,18 +185,3 @@ public class AFSSecurityException extends SecurityException } /*-----------------------------------------------------------------------*/ } - - - - - - - - - - - - - - - diff --git a/src/JAVA/classes/org/openafs/jafs/Cell.java b/src/JAVA/classes/org/openafs/jafs/Cell.java index c723bd6cb5..61aa84a07c 100644 --- a/src/JAVA/classes/org/openafs/jafs/Cell.java +++ b/src/JAVA/classes/org/openafs/jafs/Cell.java @@ -270,7 +270,7 @@ public class Cell implements java.io.Serializable /** * Sets all the information fields of this Cell object, - * such as max group and user ids, to trheir most current values. + * such as max group and user ids, to their most current values. * * @exception AFSException If an error occurs in the native code */ @@ -310,8 +310,13 @@ public class Cell implements java.io.Serializable System.err.println("ERROR Cell::refreshUsers():kas (User: " + currUser.getName() + ") -> " + e.getMessage()); authorized = false; - //if (org.openafs.jafs.ErrorCodes.isPermissionDenied(e.getErrorCode())) - //r = 0; + if (org.openafs.jafs.ErrorTable.isPermissionDenied(e.getErrorCode())) { + // Check to see if the user has failed more than 25 times, + // if so it is most likely because they are not appropriately + // authorized to list or examine users. May want to check for + // KAS admin attribute. + if ( r++ > 25 ) r = 0; + } } } getKasUsersDone( iterationId ); @@ -334,8 +339,13 @@ public class Cell implements java.io.Serializable System.err.println("ERROR Cell::refreshUsers():pts (User: " + currUser.getName() + ") -> " + e.getMessage()); authorized = false; - //if (org.openafs.jafs.ErrorCodes.isPermissionDenied(e.getErrorCode())) - // r = 0; + if (org.openafs.jafs.ErrorTable.isPermissionDenied(e.getErrorCode())) { + // Check to see if the user has failed more than 25 times, + // if so it is most likely because they are not appropriately + // authorized to list or examine users. May want to check for + // KAS admin attribute. + if ( r++ > 25 ) r = 0; + } } } getPtsUsersDone( iterationId ); @@ -400,8 +410,10 @@ public class Cell implements java.io.Serializable System.err.println("ERROR Cell::refreshGroups() (Group: " + currGroup.getName() + ") -> " + e.getMessage()); authorized = false; - //if (org.openafs.jafs.ErrorCodes.isPermissionDenied(e.getErrorCode())) - // r = 0; + if (org.openafs.jafs.ErrorTable.isPermissionDenied(e.getErrorCode())) { + if ( r++ > 25 ) r = 0; + } + } } Cell.getGroupsDone( iterationId ); @@ -456,8 +468,9 @@ System.out.println("[Java] Cell::refreshServers() -> r: " + r); System.err.println("ERROR Cell::refreshServers() (Server: " + currServer.getName() + ") -> " + e.getMessage()); authorized = false; - //if (e.getErrorCode() == org.openafs.jafs.ErrorCodes.PERMISSION_DENIED) - // r = 0; + if (org.openafs.jafs.ErrorTable.isPermissionDenied(e.getErrorCode())) { + if ( r++ > 25 ) r = 0; + } } } getServersDone( iterationId ); @@ -1864,11 +1877,3 @@ System.out.println("[Java] Cell::refreshServers() -> r: " + r); protected static native void closeCell( int cellHandle ) throws AFSException; } - - - - - - - - diff --git a/src/JAVA/classes/org/openafs/jafs/Group.java b/src/JAVA/classes/org/openafs/jafs/Group.java index 3b93345184..1572e452bc 100644 --- a/src/JAVA/classes/org/openafs/jafs/Group.java +++ b/src/JAVA/classes/org/openafs/jafs/Group.java @@ -1174,7 +1174,7 @@ public class Group implements PTSEntry, Serializable, Comparable * null if there are no more members. * * @param iterationId the iteration ID of this iteration - * @see getGroupMembersBegin + * @see #getGroupMembersBegin * @return the name of the next member * @exception AFSException If an error occurs in the native code */ @@ -1188,7 +1188,7 @@ public class Group implements PTSEntry, Serializable, Comparable * @param cellHandle the handle of the cell to which the users belong * @see Cell#getCellHandle * @param iterationId the iteration ID of this iteration - * @see getGroupMembersBegin + * @see #getGroupMembersBegin * @param theUser a User object to be populated with the values of the * next user * @return 0 if there are no more users, != 0 otherwise @@ -1203,7 +1203,7 @@ public class Group implements PTSEntry, Serializable, Comparable * Signals that the iteration is complete and will not be accessed anymore. * * @param iterationId the iteration ID of this iteration - * @see getGroupMembersBegin + * @see #getGroupMembersBegin * @exception AFSException If an error occurs in the native code */ protected static native void getGroupMembersDone( int iterationId ) diff --git a/src/JAVA/classes/org/openafs/jafs/Key.java b/src/JAVA/classes/org/openafs/jafs/Key.java index ad205448a7..7f22733202 100644 --- a/src/JAVA/classes/org/openafs/jafs/Key.java +++ b/src/JAVA/classes/org/openafs/jafs/Key.java @@ -457,11 +457,3 @@ public class Key implements Serializable, Comparable protected static native void reclaimKeyMemory(); } - - - - - - - - diff --git a/src/JAVA/classes/org/openafs/jafs/Partition.java b/src/JAVA/classes/org/openafs/jafs/Partition.java index 98b0adc088..bf10c2095e 100644 --- a/src/JAVA/classes/org/openafs/jafs/Partition.java +++ b/src/JAVA/classes/org/openafs/jafs/Partition.java @@ -1041,12 +1041,3 @@ public class Partition implements Serializable, Comparable */ protected static native void reclaimPartitionMemory(); } - - - - - - - - - diff --git a/src/JAVA/classes/org/openafs/jafs/Server.java b/src/JAVA/classes/org/openafs/jafs/Server.java index de25385da3..1446634128 100644 --- a/src/JAVA/classes/org/openafs/jafs/Server.java +++ b/src/JAVA/classes/org/openafs/jafs/Server.java @@ -1443,12 +1443,12 @@ public class Server implements Serializable, Comparable * methods as a means of identification. * * @param cellHandle a cell handle previously returned by - * a call to {@link #getCellHandle} + * a call to {@link Cell#getCellHandle} * @param serverName the name of the server for which to retrieve * a vos handle * @return a vos handle to the server * @exception AFSException If an error occurs in the native code - * @see #getCellHandle + * @see Cell#getCellHandle */ protected static native int getVosServerHandle( int cellHandle, String serverName ) @@ -1469,12 +1469,12 @@ public class Server implements Serializable, Comparable * as a means of identification. * * @param cellHandle a cell handle previously returned by a call - * to {@link #getCellHandle} + * to {@link Cell#getCellHandle} * @param serverName the name of the server for which to retrieve * a bos handle * @return a bos handle to the server * @exception AFSException If an error occurs in the native code - * @see #getCellHandle + * @see Cell#getCellHandle */ protected static native int getBosServerHandle( int cellHandle, String serverName ) @@ -1735,7 +1735,7 @@ public class Server implements Serializable, Comparable * are no more admins, != 0 otherwise. * * @param cellHandle the handle of the cell to which these admins belong - * @see #getCellHandle + * @see Cell#getCellHandle * @param iterationId the iteration ID of this iteration * @see #getBosAdminsBegin * @param theUser the user object in which to fill the values of this admin @@ -1787,7 +1787,7 @@ public class Server implements Serializable, Comparable * Salvages (restores consistency to) a volume, partition, or server * * @param cellHandle the handle of the cell to which the volume belongs - * @see #getCellHandle + * @see Cell#getCellHandle * @param serverHandle the bos handle of the server on which the * volume resides * @see #getBosServerHandle @@ -1831,7 +1831,7 @@ public class Server implements Serializable, Comparable * Synchronizes a particular server with the volume location database. * * @param cellHandle the handle of the cell to which the server belongs - * @see #getCellHandle + * @see Cell#getCellHandle * @param serverHandle the vos handle of the server * @see #getVosServerHandle * @param partition the id of the partition to sync, can be -1 to ignore @@ -1846,7 +1846,7 @@ public class Server implements Serializable, Comparable * Synchronizes the volume location database with a particular server. * * @param cellHandle the handle of the cell to which the server belongs - * @see #getCellHandle + * @see Cell#getCellHandle * @param serverHandle the vos handle of the server * @see #getVosServerHandle * @param partition the id of the partition to sync, can be -1 to ignore diff --git a/src/JAVA/classes/org/openafs/jafs/Token.java b/src/JAVA/classes/org/openafs/jafs/Token.java index 5fe2ef7058..5626a718bc 100644 --- a/src/JAVA/classes/org/openafs/jafs/Token.java +++ b/src/JAVA/classes/org/openafs/jafs/Token.java @@ -250,7 +250,6 @@ System.out.println(username + ", " + cellName); public void login() throws AFSException { this.tokenHandle = this.getToken(cellName, username, password); -System.out.println("Token handle -> " + tokenHandle); } /** diff --git a/src/JAVA/classes/org/openafs/jafs/User.java b/src/JAVA/classes/org/openafs/jafs/User.java index b34293feec..5427157df6 100644 --- a/src/JAVA/classes/org/openafs/jafs/User.java +++ b/src/JAVA/classes/org/openafs/jafs/User.java @@ -1288,7 +1288,7 @@ public class User implements PTSEntry, Serializable, Comparable if( (value != this.USER_OWNER_ACCESS) && (value != this.USER_ANYUSER_ACCESS) ) { throw new IllegalArgumentException( "Cannot set listStatus to " - + value ); + + value ); } else { listStatus = value; } @@ -1313,7 +1313,7 @@ public class User implements PTSEntry, Serializable, Comparable if( (value != this.USER_OWNER_ACCESS) && (value != this.USER_ANYUSER_ACCESS) ) { throw new IllegalArgumentException( "Cannot set listGroupsOwned to " - + value ); + + value ); } else { listGroupsOwned = value; } @@ -1339,7 +1339,7 @@ public class User implements PTSEntry, Serializable, Comparable if( (value != this.USER_OWNER_ACCESS) && (value != this.USER_ANYUSER_ACCESS) ) { throw new IllegalArgumentException( "Cannot set listMembership to " - + value ); + + value ); } else { listMembership = value; } @@ -1724,7 +1724,7 @@ public class User implements PTSEntry, Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native void create( int cellHandle, String userName, - String password, int uid ) + String password, int uid ) throws AFSException; /** @@ -1764,7 +1764,7 @@ public class User implements PTSEntry, Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native void getUserInfo( int cellHandle, String name, - User user ) + User user ) throws AFSException; /** @@ -1779,7 +1779,7 @@ public class User implements PTSEntry, Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native void setUserInfo( int cellHandle, String name, - User theUser ) + User theUser ) throws AFSException; /** @@ -1793,7 +1793,7 @@ public class User implements PTSEntry, Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native void rename( int cellHandle, String oldName, - String newName ) + String newName ) throws AFSException; /** @@ -1806,7 +1806,7 @@ public class User implements PTSEntry, Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native void setPassword( int cellHandle, String userName, - String newPassword ) + String newPassword ) throws AFSException; /** @@ -1828,7 +1828,7 @@ public class User implements PTSEntry, Serializable, Comparable * null if there are no more groups. * * @param iterationId the iteration ID of this iteration - * @see getUserGroupsBegin + * @see #getUserGroupsBegin * @return the name of the next group * @exception AFSException If an error occurs in the native code */ @@ -1842,22 +1842,22 @@ public class User implements PTSEntry, Serializable, Comparable * @param cellHandle the handle of the cell to which the users belong * @see Cell#getCellHandle * @param iterationId the iteration ID of this iteration - * @see getUserGroupsBegin + * @see #getUserGroupsBegin * @param theGroup a Group object to be populated with the values of the * next group * @return 0 if there are no more users, != 0 otherwise * @exception AFSException If an error occurs in the native code */ protected static native int getUserGroupsNext( int cellHandle, - int iterationId, - Group theGroup ) + int iterationId, + Group theGroup ) throws AFSException; /** * Signals that the iteration is complete and will not be accessed anymore. * * @param iterationId the iteration ID of this iteration - * @see getUserGroupsBegin + * @see #getUserGroupsBegin * @exception AFSException If an error occurs in the native code */ protected static native void getUserGroupsDone( int iterationId ) @@ -1887,7 +1887,7 @@ public class User implements PTSEntry, Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native int getGroupsOwnedBegin( int cellHandle, - String name ) + String name ) throws AFSException; /** @@ -1895,7 +1895,7 @@ public class User implements PTSEntry, Serializable, Comparable * if there are no more groups. * * @param iterationId the iteration ID of this iteration - * @see getGroupsOwnedBegin + * @see #getGroupsOwnedBegin * @return the name of the next group * @exception AFSException If an error occurs in the native code */ @@ -1909,22 +1909,22 @@ public class User implements PTSEntry, Serializable, Comparable * @param cellHandle the handle of the cell to which the users belong * @see Cell#getCellHandle * @param iterationId the iteration ID of this iteration - * @see getGroupsOwnedBegin + * @see #getGroupsOwnedBegin * @param theGroup a Group object to be populated with the values of the * next group * @return 0 if there are no more users, != 0 otherwise * @exception AFSException If an error occurs in the native code */ protected static native int getGroupsOwnedNext( int cellHandle, - int iterationId, - Group theGroup ) + int iterationId, + Group theGroup ) throws AFSException; /** * Signals that the iteration is complete and will not be accessed anymore. * * @param iterationId the iteration ID of this iteration - * @see getGroupsOwnedBegin + * @see #getGroupsOwnedBegin * @exception AFSException If an error occurs in the native code */ protected static native void getGroupsOwnedDone( int iterationId ) @@ -1937,12 +1937,3 @@ public class User implements PTSEntry, Serializable, Comparable */ protected static native void reclaimUserMemory(); } - - - - - - - - - diff --git a/src/JAVA/classes/org/openafs/jafs/Volume.java b/src/JAVA/classes/org/openafs/jafs/Volume.java index 88cf7de73b..85fe4ca2b0 100644 --- a/src/JAVA/classes/org/openafs/jafs/Volume.java +++ b/src/JAVA/classes/org/openafs/jafs/Volume.java @@ -315,7 +315,7 @@ public class Volume implements Serializable, Comparable protected void refreshInfo() throws AFSException { getVolumeInfo( cell.getCellHandle(), server.getVosHandle(), - partition.getID(), getID(), this ); + partition.getID(), getID(), this ); cachedInfo = true; creationDateCal = null; lastUpdateDateCal = null; @@ -333,7 +333,7 @@ public class Volume implements Serializable, Comparable public void create( int quota ) throws AFSException { id = create( cell.getCellHandle(), server.getVosHandle(), - partition.getID(), name, quota ); + partition.getID(), name, quota ); maxQuota = quota; } @@ -366,7 +366,7 @@ public class Volume implements Serializable, Comparable { Server siteServer = sitePartition.getServer(); createReadOnlyVolume( cell.getCellHandle(), siteServer.getVosHandle(), - sitePartition.getID(), getID() ); + sitePartition.getID(), getID() ); release( false ); return new Volume( name + ".readonly", sitePartition ); } @@ -379,7 +379,7 @@ public class Volume implements Serializable, Comparable public void delete() throws AFSException { delete( cell.getCellHandle(), server.getVosHandle(), partition.getID(), - getID() ); + getID() ); name = null; creationDateCal = null; lastUpdateDateCal = null; @@ -434,7 +434,7 @@ public class Volume implements Serializable, Comparable startTime = (int) ((dumpSince.getTime().getTime())/((long) 1000)); } dump( cell.getCellHandle(), server.getVosHandle(), partition.getID(), - getID(), startTime, fileName ); + getID(), startTime, fileName ); } /** @@ -485,7 +485,7 @@ public class Volume implements Serializable, Comparable throws AFSException { restore( cell.getCellHandle(), server.getVosHandle(), partition.getID(), - id, name, fileName, incremental ); + id, name, fileName, incremental ); } /** @@ -541,7 +541,7 @@ public class Volume implements Serializable, Comparable { Server newServer = newPartition.getServer(); move( cell.getCellHandle(), server.getVosHandle(), partition.getID(), - newServer.getVosHandle(), newPartition.getID(), getID() ); + newServer.getVosHandle(), newPartition.getID(), getID() ); server = newServer; partition = newPartition; @@ -568,8 +568,8 @@ public class Volume implements Serializable, Comparable public void salvage() throws AFSException { Server.salvage( cell.getCellHandle(), server.getBosHandle(), - partition.getName(), name, 4, null, null, false, false, - false, false, false, false ); + partition.getName(), name, 4, null, null, false, false, + false, false, false, false ); } /** @@ -598,7 +598,7 @@ public class Volume implements Serializable, Comparable throws AFSException { Cell.createMountPoint( cell.getCellHandle(), directory, getName(), - readWrite, false ); + readWrite, false ); } //////////////// accessors: //////////////////////// @@ -847,7 +847,7 @@ public class Volume implements Serializable, Comparable if ( !cachedInfo ) refreshInfo(); if (maxQuota == 0) { throw new AFSException("Volume with id " + id + - " has an unlimited quota configured.", 0); + " has an unlimited quota configured.", 0); } return maxQuota; } @@ -954,7 +954,7 @@ public class Volume implements Serializable, Comparable public void setQuota( int quota ) throws AFSException { this.changeQuota( cell.getCellHandle(), server.getVosHandle(), - partition.getID(), getID(), quota ); + partition.getID(), getID(), quota ); maxQuota = quota; } @@ -1097,8 +1097,8 @@ public class Volume implements Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native void getVolumeInfo( int cellHandle, int serverHandle, - int partition, int volId, - Volume theVolume ) + int partition, int volId, + Volume theVolume ) throws AFSException; /** @@ -1117,8 +1117,8 @@ public class Volume implements Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native int create( int cellHandle, int serverHandle, - int partition, String volumeName, - int quota ) + int partition, String volumeName, + int quota ) throws AFSException; /** @@ -1135,7 +1135,7 @@ public class Volume implements Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native void delete( int cellHandle, int serverHandle, - int partition, int volId ) + int partition, int volId ) throws AFSException; /** @@ -1162,8 +1162,8 @@ public class Volume implements Serializable, Comparable * @see Cell#getCellHandle */ protected static native void createReadOnlyVolume( int cellHandle, - int serverHandle, - int partition, int volId ) + int serverHandle, + int partition, int volId ) throws AFSException; /** @@ -1180,8 +1180,8 @@ public class Volume implements Serializable, Comparable * @see Cell#getCellHandle */ protected static native void deleteReadOnlyVolume( int cellHandle, - int serverHandle, - int partition, int volId ) + int serverHandle, + int partition, int volId ) throws AFSException; /** @@ -1199,8 +1199,8 @@ public class Volume implements Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native void changeQuota( int cellHandle, int serverHandle, - int partition, int volId, - int newQuota ) + int partition, int volId, + int newQuota ) throws AFSException; /** @@ -1221,8 +1221,8 @@ public class Volume implements Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native void move( int cellHandle, int fromServerHandle, - int fromPartition, int toServerHandle, - int toPartition, int volId ) + int fromPartition, int toServerHandle, + int toPartition, int volId ) throws AFSException; /** @@ -1234,7 +1234,7 @@ public class Volume implements Serializable, Comparable * @see Cell#getCellHandle */ protected static native void release( int cellHandle, int volId, - boolean forceComplete ) + boolean forceComplete ) throws AFSException; /** @@ -1254,8 +1254,8 @@ public class Volume implements Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native void dump( int cellHandle, int serverHandle, - int partition, int volId, int startTime, - String dumpFile ) + int partition, int volId, int startTime, + String dumpFile ) throws AFSException; /** @@ -1278,9 +1278,9 @@ public class Volume implements Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native void restore( int cellHandle, int serverHandle, - int partition, int volId, - String volumeName, String dumpFile, - boolean incremental ) + int partition, int volId, + String volumeName, String dumpFile, + boolean incremental ) throws AFSException; /** @@ -1293,7 +1293,7 @@ public class Volume implements Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native void rename( int cellHandle, int volId, - String newVolumeName ) + String newVolumeName ) throws AFSException; /** @@ -1312,8 +1312,8 @@ public class Volume implements Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native void mount( int serverHandle, int partition, - int volId, int sleepTime, - boolean offline ) + int volId, int sleepTime, + boolean offline ) throws AFSException; /** @@ -1328,7 +1328,7 @@ public class Volume implements Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native void unmount( int serverHandle, int partition, - int volId ) + int volId ) throws AFSException; /** @@ -1369,7 +1369,7 @@ public class Volume implements Serializable, Comparable * @exception AFSException If an error occurs in the native code */ protected static native int translateNameToID( int cellHandle, String name, - int volumeType ) + int volumeType ) throws AFSException; /** @@ -1379,16 +1379,3 @@ public class Volume implements Serializable, Comparable */ protected static native void reclaimVolumeMemory(); } - - - - - - - - - - - - - diff --git a/src/JAVA/libjafs/ACL.c b/src/JAVA/libjafs/ACL.c index 7770bb667a..d54887ca2f 100644 --- a/src/JAVA/libjafs/ACL.c +++ b/src/JAVA/libjafs/ACL.c @@ -19,16 +19,31 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include + #include "Internal.h" #include "org_openafs_jafs_ACL.h" -#include #include #include #include #include #include -#include + +/* + #include +*/ + +/* just for debugging */ +#define MAXHOSTS 13 +#define OMAXHOSTS 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 */ + +static char space[MAXSIZE]; #ifdef DMALLOC #include "dmalloc.h" @@ -49,8 +64,11 @@ char* getACL(char *path) struct ViceIoctl params; char *buffer; - params.in = NULL; - params.in_size = 0; + params.in = NULL; + params.out = NULL; + params.in_size = 0; + params.out_size = 0; + buffer = (char*) malloc(ACL_LEN); if (!buffer) { @@ -61,9 +79,9 @@ char* getACL(char *path) params.out = buffer; params.out_size = ACL_LEN; - if(call_syscall(AFSCALL_PIOCTL, path, VIOCGETAL, ¶ms, 1)) { + if ( call_syscall(AFSCALL_PIOCTL, path, VIOCGETAL, ¶ms, 1, 0) ) { fprintf(stderr, "ERROR: ACL::getACL -> VIOCGETAL failed: %d\n", errno); - free(buffer); + free( buffer ); return NULL; } @@ -88,7 +106,7 @@ jboolean setACL(char *path, char *aclString) params.out = NULL; params.out_size = 0; - if(call_syscall(AFSCALL_PIOCTL, path, VIOCSETAL, ¶ms, 1)) { + if ( call_syscall(AFSCALL_PIOCTL, path, VIOCGETAL, ¶ms, 1) ) { fprintf(stderr, "ERROR: ACL::setACL -> VIOCSETAL failed: %d\n", errno); return JNI_FALSE; } @@ -112,21 +130,20 @@ JNIEXPORT jstring JNICALL Java_org_openafs_jafs_ACL_getACLString char *path, *acl; jstring answer = NULL; - path = (char*) (*env)->GetStringUTFChars(env, pathUTF, 0); - - if(path == NULL) { + path = getNativeString(env, pathUTF); + if ( path == NULL ) { fprintf(stderr, "ERROR: ACL::getACLString ->"); - fprintf(stderr, "GetStringUTFChars() returned path = NULL\n"); - throwMessageException( env, "Path is NULL" ); + fprintf(stderr, "path = NULL\n"); + throwAFSException( env, JAFSNULLPATH ); return NULL; } - acl = getACL(path); - (*env)->ReleaseStringUTFChars(env, pathUTF, path); + acl = getACL( path ); + free( path ); - if(acl) { - answer = (*env) -> NewStringUTF(env, acl); - free(acl); + if ( acl ) { + answer = (*env)->NewStringUTF( env, acl ); + free( acl ); } else { throwAFSException( env, errno ); } @@ -151,42 +168,45 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_ACL_setACLString { char *path, *aclString; - if(!pathUTF) { + if ( pathUTF == NULL ) { fprintf(stderr, "ERROR: ACL::setACLString -> pathUTF == NULL\n"); - throwMessageException( env, "pathUTF == NULL" ); + throwAFSException( env, JAFSNULLPATH ); return; } - path = (char*) (*env)->GetStringUTFChars(env, pathUTF, 0); - - if(path == NULL) { - fprintf(stderr, "ERROR: ACL::setACLString -> failed to get path\n"); - throwMessageException( env, "Failed to get path" ); - return; - } - - if(!aclStringUTF) { + if ( aclStringUTF == NULL ) { fprintf(stderr, "ERROR: ACL::setACLString -> aclStringUTF == NULL\n"); - throwMessageException( env, "aclStringUTF == NULL" ); + throwAFSException( env, JAFSNULLACL ); return; } - aclString = (char*) (*env)->GetStringUTFChars(env, aclStringUTF, 0); + /* path = (char*) (*env)->GetStringUTFChars(env, pathUTF, 0); */ + path = getNativeString( env, pathUTF ); + if ( path == NULL ) { + fprintf(stderr, "ERROR: ACL::setACLString -> failed to get path\n"); + throwMessageException( env, "Failed to get path." ); + return; + } - if(aclString == NULL) { + /* aclString = (char*) (*env)->GetStringUTFChars(env, aclStringUTF, 0); */ + aclString = getNativeString( env, aclStringUTF ); + if ( aclString == NULL ) { + free( path ); fprintf(stderr, "ERROR: ACL::setACLString -> failed to get aclString\n"); - (*env)->ReleaseStringUTFChars(env, pathUTF, path); - throwMessageException( env, "aclString == NULL" ); + throwMessageException( env, "Failed to get ACL string." ); return; } - if (!setACL(path, aclString)) { + if ( !setACL(path, aclString) ) { throwAFSException( env, errno ); } + /* Clean up */ + free( path ); + free( aclString ); + + /* (*env)->ReleaseStringUTFChars(env, pathUTF, path); (*env)->ReleaseStringUTFChars(env, aclStringUTF, aclString); + */ } - - - diff --git a/src/JAVA/libjafs/AdminToken.c b/src/JAVA/libjafs/AdminToken.c index b1d3358515..bc446dfd14 100644 --- a/src/JAVA/libjafs/AdminToken.c +++ b/src/JAVA/libjafs/AdminToken.c @@ -42,7 +42,7 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_Token_initializeAdminClient(JNIEnv *env, jclass cls) { afs_status_t ast; - if( !afsclient_Init( &ast ) ) { + if ( !afsclient_Init( &ast ) ) { throwAFSException( env, ast ); return; } @@ -66,67 +66,59 @@ Java_org_openafs_jafs_Token_getToken jstring jpassword) { afs_status_t ast; - const char *cellName; - const char *userName; - const char *password; + char *cellName; + char *userName; + char *password; void *tokenHandle; int rc; // convert java strings - if( jcellName != NULL ) { - cellName = (*env)->GetStringUTFChars(env, jcellName, 0); - if( !cellName ) { - throwAFSException( env, JAFSADMNOMEM ); - return 0; - } + if ( jcellName != NULL ) { + cellName = getNativeString(env, jcellName); + if ( !cellName ) { + throwAFSException( env, JAFSADMNOMEM ); + return 0; + } } else { - cellName = NULL; + cellName = NULL; } - if( juserName != NULL ) { - userName = (*env)->GetStringUTFChars(env, juserName, 0); - if( !userName ) { - throwAFSException( env, JAFSADMNOMEM ); - return 0; - } + + if ( juserName != NULL ) { + userName = getNativeString(env, juserName); + if ( !userName ) { + if ( cellName != NULL ) free( cellName ); + throwAFSException( env, JAFSADMNOMEM ); + return 0; + } } else { - userName = NULL; + if ( cellName != NULL ) free( cellName ); + throwAFSException( env, JAFSNULLUSER ); + return 0; } - if( jpassword != NULL ) { - password = (*env)->GetStringUTFChars(env, jpassword, 0); - if( !password ) { - throwAFSException( env, JAFSADMNOMEM ); - return 0; - } + + if ( jpassword != NULL ) { + password = getNativeString(env, jpassword); + if ( !password ) { + if ( cellName != NULL ) free( cellName ); + free( userName ); + throwAFSException( env, JAFSADMNOMEM ); + return 0; + } } else { - password = NULL; + if ( cellName != NULL ) free( cellName ); + free( userName ); + throwAFSException( env, JAFSNULLPASS ); + return 0; } if ( !(afsclient_TokenGetNew( cellName, userName, password, &tokenHandle, - &ast) ) ) { - // release converted strings - if( cellName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jcellName, cellName); - } - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( password != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpassword, password); - } - throwAFSException( env, ast ); - return 0; + &ast) ) ) { + throwAFSException( env, ast ); } - // release converted strings - if( cellName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jcellName, cellName); - } - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( password != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpassword, password); - } + if ( cellName != NULL ) free( cellName ); + free( userName ); + free( password ); return (jint) tokenHandle; } @@ -142,12 +134,12 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_Token_close (JNIEnv *env, jobject obj, jint tokenHandle) { - afs_status_t ast; + afs_status_t ast; - if( !afsclient_TokenClose( (void *) tokenHandle, &ast ) ) { - throwAFSException( env, ast ); - return; - } + if ( !afsclient_TokenClose( (void *) tokenHandle, &ast ) ) { + throwAFSException( env, ast ); + return; + } } /** @@ -166,31 +158,27 @@ Java_org_openafs_jafs_Cell_getCellHandle (JNIEnv *env, jobject obj, jstring jcellName, jint tokenHandle) { afs_status_t ast; - const char *cellName; + char *cellName; void *cellHandle; - if( jcellName != NULL ) { - cellName = (*env)->GetStringUTFChars(env, jcellName, 0); - if( !cellName ) { + if ( jcellName != NULL ) { + cellName = getNativeString(env, jcellName); + if ( !cellName ) { throwAFSException( env, JAFSADMNOMEM ); - return; + return -1; } } else { - cellName = NULL; + throwAFSException( env, JAFSNULLCELL ); + return -1; } - if( !afsclient_CellOpen( cellName, (void *) tokenHandle, + if ( !afsclient_CellOpen( cellName, (void *) tokenHandle, &cellHandle, &ast ) ) { - if( cellName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jcellName, cellName); - } throwAFSException( env, ast ); - return; } - if( cellName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jcellName, cellName); - } + free( cellName ); + return (jint) cellHandle; } @@ -202,17 +190,15 @@ Java_org_openafs_jafs_Cell_getCellHandle * cellHandle the cell handle to close */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Cell_closeCell (JNIEnv *env, jobject obj, - jint cellHandle) +Java_org_openafs_jafs_Cell_closeCell + (JNIEnv *env, jobject obj, jint cellHandle) { + afs_status_t ast; - afs_status_t ast; - - if( !afsclient_CellClose( (void *) cellHandle, &ast ) ) { - throwAFSException( env, ast ); - return; - } - + if ( !afsclient_CellClose( (void *) cellHandle, &ast ) ) { + throwAFSException( env, ast ); + return; + } } /** @@ -234,32 +220,26 @@ Java_org_openafs_jafs_Server_getVosServerHandle { afs_status_t ast; void *serverHandle; - // convert java string - const char *serverName; + char *serverName; - if( jserverName != NULL ) { - serverName = (*env)->GetStringUTFChars(env, jserverName, 0); - if( !serverName ) { - throwAFSException( env, JAFSADMNOMEM ); - return; - } + if ( jserverName != NULL ) { + serverName = getNativeString(env, jserverName); + if ( !serverName ) { + throwAFSException( env, JAFSADMNOMEM ); + return -1; + } } else { - serverName = NULL; + throwAFSException( env, JAFSNULLSERVER ); + return -1; } - if( !vos_ServerOpen( (void *) cellHandle, serverName, - (void **) &serverHandle, &ast ) ) { - if( serverName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jserverName, serverName); - } - throwAFSException( env, ast ); - return 0; + if ( !vos_ServerOpen( (void *) cellHandle, serverName, + (void **) &serverHandle, &ast ) ) { + throwAFSException( env, ast ); } // release converted string - if( serverName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jserverName, serverName); - } + free( serverName ); return (jint) serverHandle; } @@ -275,12 +255,12 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_Server_closeVosServerHandle (JNIEnv *env, jobject obj, jint vosServerHandle) { - afs_status_t ast; + afs_status_t ast; - if( !vos_ServerClose( (void *) vosServerHandle, &ast ) ) { - throwAFSException( env, ast ); - return; - } + if ( !vos_ServerClose( (void *) vosServerHandle, &ast ) ) { + throwAFSException( env, ast ); + return; + } } /** @@ -302,32 +282,26 @@ Java_org_openafs_jafs_Server_getBosServerHandle { afs_status_t ast; void *serverHandle; - // convert java string - const char *serverName; + char *serverName; - if( jserverName != NULL ) { - serverName = (*env)->GetStringUTFChars(env, jserverName, 0); - if( !serverName ) { - throwAFSException( env, JAFSADMNOMEM ); - return; - } + if ( jserverName != NULL ) { + serverName = getNativeString(env, jserverName); + if ( !serverName ) { + throwAFSException( env, JAFSADMNOMEM ); + return; + } } else { - serverName = NULL; + throwAFSException( env, JAFSNULLSERVER ); + return; } - if( !bos_ServerOpen( (void *) cellHandle, serverName, - (void **) &serverHandle, &ast ) ) { - if( serverName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jserverName, serverName); - } - throwAFSException( env, ast ); - return 0; + if ( !bos_ServerOpen( (void *) cellHandle, serverName, + (void **) &serverHandle, &ast ) ) { + throwAFSException( env, ast ); } // release converted string - if( serverName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jserverName, serverName); - } + free( serverName ); return (jint) serverHandle; } @@ -343,12 +317,12 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_Server_closeBosServerHandle (JNIEnv *env, jobject obj, jint bosServerHandle) { - afs_status_t ast; + afs_status_t ast; - if( !bos_ServerClose( (void *) bosServerHandle, &ast ) ) { - throwAFSException( env, ast ); - return; - } + if ( !bos_ServerClose( (void *) bosServerHandle, &ast ) ) { + throwAFSException( env, ast ); + return; + } } /** @@ -365,41 +339,37 @@ JNIEXPORT jlong JNICALL Java_org_openafs_jafs_Token_getExpiration (JNIEnv *env, jobject obj, jint tokenHandle) { - afs_status_t ast; - unsigned long expTime; - char *prince = malloc( sizeof(char)*KAS_MAX_NAME_LEN ); - char *inst = malloc( sizeof(char)*KAS_MAX_NAME_LEN ); - char *cell = malloc( sizeof(char)*AFS_MAX_SERVER_NAME_LEN ); - int hkt; + afs_status_t ast; + unsigned long expTime; + char *prince = malloc( sizeof(char)*KAS_MAX_NAME_LEN ); + char *inst = malloc( sizeof(char)*KAS_MAX_NAME_LEN ); + char *cell = malloc( sizeof(char)*AFS_MAX_SERVER_NAME_LEN ); + int hkt; - if( !prince || !inst || !cell ) { - if( prince ) { - free( prince ); - } - if( inst ) { - free( inst ); - } - if( cell ) { - free( cell ); - } - throwAFSException( env, JAFSADMNOMEM ); - return; + if ( !prince || !inst || !cell ) { + if ( prince ) { + free( prince ); } - - if( !afsclient_TokenQuery( (void *) tokenHandle, &expTime, prince, inst, - cell, &hkt, &ast ) ) { - free( prince ); - free( inst ); - free( cell ); - throwAFSException( env, ast ); - return 0; + if ( inst ) { + free( inst ); } + if ( cell ) { + free( cell ); + } + throwAFSException( env, JAFSADMNOMEM ); + return; + } - free( prince ); - free( inst ); - free( cell ); + if ( !afsclient_TokenQuery( (void *) tokenHandle, &expTime, prince, inst, + cell, &hkt, &ast ) ) { + throwAFSException( env, ast ); + } - return (jlong) expTime; + free( prince ); + free( inst ); + free( cell ); + + return (jlong) expTime; } // reclaim global memory used by this portion @@ -407,9 +377,3 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_Token_reclaimAuthMemory (JNIEnv *env, jclass cls) { } - - - - - - diff --git a/src/JAVA/libjafs/Cell.c b/src/JAVA/libjafs/Cell.c index 47bb0df9d6..aafbfe6c61 100644 --- a/src/JAVA/libjafs/Cell.c +++ b/src/JAVA/libjafs/Cell.c @@ -33,8 +33,9 @@ #include #include -//// definitions in Internal.c ////////////////// - +/*----------------------------------------------------------------------- + * Definitions in Internal.c + */ extern jclass userCls; //extern jfieldID user_cellHandleField; extern jfieldID user_nameField; @@ -49,28 +50,26 @@ extern jclass serverCls; //extern jfieldID server_cellHandleField; extern jfieldID server_cachedInfoField; -////////////////////////////////////////////////////////// - -///// definition in jafs_User.c ///////////////// - +/*----------------------------------------------------------------------- + * Definition in User.c + */ extern void getUserInfoChar (JNIEnv *env, int cellHandle, const char *name, jobject user); -/////////////////////////////////////////////////// - -///// definition in jafs_Group.c ///////////////// - +/*----------------------------------------------------------------------- + * Definition in Group.c + */ extern void getGroupInfoChar (JNIEnv *env, int cellHandle, const char *name, jobject group); -/////////////////////////////////////////////////// - -///// definition in jafs_Server.c ///////////////// - +/*----------------------------------------------------------------------- + * Definition in Server.c + */ extern void fillServerInfo (JNIEnv *env, jint cellHandle, jobject server, afs_serverEntry_t servEntry); -/////////////////////////////////////////////////// + +/*-----------------------------------------------------------------------*/ /** * Returns the total number of KAS users belonging to the cell denoted @@ -82,15 +81,15 @@ extern void fillServerInfo (JNIEnv *env, jint cellHandle, jobject server, * returns total count of KAS users */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getKasUserCount (JNIEnv *env, jclass cls, - jint cellHandle) { - +Java_org_openafs_jafs_Cell_getKasUserCount + (JNIEnv *env, jclass cls, jint cellHandle) +{ afs_status_t ast; void *iterationId; kas_identity_t who; int i = 0; - if( !kas_PrincipalGetBegin( (void *) cellHandle, NULL, + if ( !kas_PrincipalGetBegin( (void *) cellHandle, NULL, &iterationId, &ast ) ) { throwAFSException( env, ast ); return -1; @@ -98,7 +97,7 @@ Java_org_openafs_jafs_Cell_getKasUserCount (JNIEnv *env, jclass cls, while ( kas_PrincipalGetNext( (void *) iterationId, &who, &ast ) ) i++; - if( ast != ADMITERATORDONE ) { + if ( ast != ADMITERATORDONE ) { throwAFSException( env, ast ); return -1; } @@ -119,20 +118,19 @@ Java_org_openafs_jafs_Cell_getKasUserCount (JNIEnv *env, jclass cls, * returns an iteration ID */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getKasUsersBegin (JNIEnv *env, jclass cls, - jint cellHandle) { - +Java_org_openafs_jafs_Cell_getKasUsersBegin + (JNIEnv *env, jclass cls, jint cellHandle) +{ afs_status_t ast; void *iterationId; - if( !kas_PrincipalGetBegin( (void *) cellHandle, NULL, &iterationId, + if ( !kas_PrincipalGetBegin( (void *) cellHandle, NULL, &iterationId, &ast ) ) { throwAFSException( env, ast ); return; } return (jint) iterationId; - } /** @@ -149,24 +147,23 @@ Java_org_openafs_jafs_Cell_getKasUsersBegin (JNIEnv *env, jclass cls, * returns an iteration ID */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getKasUsersBeginAt (JNIEnv *env, jclass cls, - jint cellHandle, - jint startIndex) { - +Java_org_openafs_jafs_Cell_getKasUsersBeginAt + (JNIEnv *env, jclass cls, jint cellHandle, jint startIndex) +{ afs_status_t ast; void *iterationId; kas_identity_t who; int i; - if( !kas_PrincipalGetBegin( (void *) cellHandle, NULL, + if ( !kas_PrincipalGetBegin( (void *) cellHandle, NULL, &iterationId, &ast ) ) { throwAFSException( env, ast ); return; } for ( i = 1; i < startIndex; i++) { - if( !kas_PrincipalGetNext( (void *) iterationId, &who, &ast ) ) { - if( ast == ADMITERATORDONE ) { + if ( !kas_PrincipalGetNext( (void *) iterationId, &who, &ast ) ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -176,7 +173,6 @@ Java_org_openafs_jafs_Cell_getKasUsersBeginAt (JNIEnv *env, jclass cls, } return (jint) iterationId; - } /** @@ -190,15 +186,15 @@ Java_org_openafs_jafs_Cell_getKasUsersBeginAt (JNIEnv *env, jclass cls, * returns the name of the next user of the cell */ JNIEXPORT jstring JNICALL -Java_org_openafs_jafs_Cell_getKasUsersNextString (JNIEnv *env, jclass cls, - jint iterationId) { - +Java_org_openafs_jafs_Cell_getKasUsersNextString + (JNIEnv *env, jclass cls, jint iterationId) +{ afs_status_t ast; kas_identity_t who; jstring juser; - if( !kas_PrincipalGetNext( (void *) iterationId, &who, &ast ) ) { - if( ast == ADMITERATORDONE ) { + if ( !kas_PrincipalGetNext( (void *) iterationId, &who, &ast ) ) { + if ( ast == ADMITERATORDONE ) { return NULL; // other } else { @@ -207,11 +203,11 @@ Java_org_openafs_jafs_Cell_getKasUsersNextString (JNIEnv *env, jclass cls, } } - if( strcmp( who.instance, "" ) ) { + if ( strcmp( who.instance, "" ) ) { char *fullName = (char *) malloc( sizeof(char)*( strlen( who.principal ) + strlen( who.instance ) + 2 ) ); - if( !fullName ) { + if ( !fullName ) { throwAFSException( env, JAFSADMNOMEM ); return; } @@ -242,10 +238,10 @@ Java_org_openafs_jafs_Cell_getKasUsersNextString (JNIEnv *env, jclass cls, * returns 0 if there are no more users, != 0 otherwise */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getKasUsersNext (JNIEnv *env, jclass cls, - jint cellHandle, - jint iterationId, - jobject juserObject) { +Java_org_openafs_jafs_Cell_getKasUsersNext + (JNIEnv *env, jclass cls, jint cellHandle, jint iterationId, + jobject juserObject) +{ afs_status_t ast; kas_identity_t who; @@ -253,8 +249,8 @@ Java_org_openafs_jafs_Cell_getKasUsersNext (JNIEnv *env, jclass cls, char *fullName = NULL; - if( !kas_PrincipalGetNext( (void *) iterationId, &who, &ast ) ) { - if( ast == ADMITERATORDONE ) { + if ( !kas_PrincipalGetNext( (void *) iterationId, &who, &ast ) ) { + if ( ast == ADMITERATORDONE ) { return 0; // other } else { @@ -264,10 +260,10 @@ Java_org_openafs_jafs_Cell_getKasUsersNext (JNIEnv *env, jclass cls, } // take care of the instance stuff(by concatenating with a period in between) - if( strcmp( who.instance, "" ) ) { + if ( strcmp( who.instance, "" ) ) { fullName = (char *) malloc( sizeof(char)*( strlen( who.principal ) + strlen( who.instance ) + 2 ) ); - if( !fullName ) { + if ( !fullName ) { throwAFSException( env, JAFSADMNOMEM ); return; } @@ -280,13 +276,13 @@ Java_org_openafs_jafs_Cell_getKasUsersNext (JNIEnv *env, jclass cls, juser = (*env)->NewStringUTF(env, who.principal); } - if( userCls == 0 ) { + if ( userCls == 0 ) { internal_getUserClass( env, juserObject ); } (*env)->SetObjectField(env, juserObject, user_nameField, juser); - if( fullName != NULL ) { + if ( fullName != NULL ) { getUserInfoChar( env, (int) cellHandle, fullName, juserObject ); free( fullName ); } else { @@ -306,12 +302,12 @@ Java_org_openafs_jafs_Cell_getKasUsersNext (JNIEnv *env, jclass cls, * iterationId the iteration ID of this iteration */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Cell_getKasUsersDone (JNIEnv *env, jclass cls, - jint iterationId) { - +Java_org_openafs_jafs_Cell_getKasUsersDone + (JNIEnv *env, jclass cls, jint iterationId) +{ afs_status_t ast; - if( !kas_PrincipalGetDone( (void *) iterationId, &ast ) ) { + if ( !kas_PrincipalGetDone( (void *) iterationId, &ast ) ) { throwAFSException( env, ast ); return; } @@ -327,14 +323,14 @@ Java_org_openafs_jafs_Cell_getKasUsersDone (JNIEnv *env, jclass cls, * returns the name of the cell */ JNIEXPORT jstring JNICALL -Java_org_openafs_jafs_Cell_getCellName (JNIEnv *env, jclass cls, - jint cellHandle) { - +Java_org_openafs_jafs_Cell_getCellName + (JNIEnv *env, jclass cls, jint cellHandle) +{ afs_status_t ast; char *cellName; jstring jcellName; - if( !afsclient_CellNameGet( (void *) cellHandle, + if ( !afsclient_CellNameGet( (void *) cellHandle, (const char **) &cellName, &ast ) ) { throwAFSException( env, ast ); return; @@ -356,22 +352,22 @@ Java_org_openafs_jafs_Cell_getCellName (JNIEnv *env, jclass cls, * returns total number of PTS users */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getPtsUserCount (JNIEnv *env, jclass cls, - jint cellHandle) { - +Java_org_openafs_jafs_Cell_getPtsUserCount + (JNIEnv *env, jclass cls, jint cellHandle) +{ afs_status_t ast; void *iterationId; char *userName; int i = 0; - if( !pts_UserListBegin( (void *) cellHandle, &iterationId, &ast ) ) { + if ( !pts_UserListBegin( (void *) cellHandle, &iterationId, &ast ) ) { throwAFSException( env, ast ); return -1; } userName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); - if( !userName ) { + if ( !userName ) { throwAFSException( env, JAFSADMNOMEM ); return -1; } @@ -380,7 +376,7 @@ Java_org_openafs_jafs_Cell_getPtsUserCount (JNIEnv *env, jclass cls, free( userName ); - if( ast != ADMITERATORDONE ) { + if ( ast != ADMITERATORDONE ) { throwAFSException( env, ast ); return -1; } @@ -398,9 +394,9 @@ Java_org_openafs_jafs_Cell_getPtsUserCount (JNIEnv *env, jclass cls, * returns total number of users that are in PTS and not KAS */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getPtsOnlyUserCount (JNIEnv *env, jclass cls, - jint cellHandle) { - +Java_org_openafs_jafs_Cell_getPtsOnlyUserCount + (JNIEnv *env, jclass cls, jint cellHandle) +{ afs_status_t ast; void *iterationId; kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) ); @@ -408,29 +404,28 @@ Java_org_openafs_jafs_Cell_getPtsOnlyUserCount (JNIEnv *env, jclass cls, char *userName; int i = 0; - if( !who ) { + if ( who == NULL ) { throwAFSException( env, JAFSADMNOMEM ); return -1; } - if( !pts_UserListBegin( (void *) cellHandle, &iterationId, &ast ) ) { + if ( !pts_UserListBegin( (void *) cellHandle, &iterationId, &ast ) ) { free( who ); throwAFSException( env, ast ); return -1; } userName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); - - if( !userName ) { + if ( !userName ) { free( who ); throwAFSException( env, JAFSADMNOMEM ); return -1; } while ( pts_UserListNext( (void *) iterationId, userName, &ast ) ) { - if( strcmp( userName, "anonymous" ) != 0 ) { + if ( strcmp( userName, "anonymous" ) != 0 ) { // make sure the name is within the allowed bounds - if( strlen( userName ) > KAS_MAX_NAME_LEN ) { + if ( strlen( userName ) > KAS_MAX_NAME_LEN ) { free( who ); free( userName ); throwAFSException( env, ADMPTSUSERNAMETOOLONG ); @@ -439,7 +434,7 @@ Java_org_openafs_jafs_Cell_getPtsOnlyUserCount (JNIEnv *env, jclass cls, // if there is a kas entry, recurse internal_makeKasIdentity( userName, who ); - if( !kas_PrincipalGet( (void *) cellHandle, NULL, who, + if ( !kas_PrincipalGet( (void *) cellHandle, NULL, who, &kasEntry, &ast ) ) i++; } } @@ -447,7 +442,7 @@ Java_org_openafs_jafs_Cell_getPtsOnlyUserCount (JNIEnv *env, jclass cls, free( userName ); free( who ); - if( ast != ADMITERATORDONE ) { + if ( ast != ADMITERATORDONE ) { throwAFSException( env, ast ); return -1; } @@ -467,15 +462,15 @@ Java_org_openafs_jafs_Cell_getPtsOnlyUserCount (JNIEnv *env, jclass cls, * returns an iteration ID */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getPtsUsersBegin (JNIEnv *env, jclass cls, - jint cellHandle) { - +Java_org_openafs_jafs_Cell_getPtsUsersBegin + (JNIEnv *env, jclass cls, jint cellHandle) +{ afs_status_t ast; void *iterationId; - if( !pts_UserListBegin( (void *) cellHandle, &iterationId, &ast ) ) { + if ( !pts_UserListBegin( (void *) cellHandle, &iterationId, &ast ) ) { throwAFSException( env, ast ); - return; + return -1; } return (jint) iterationId; @@ -492,31 +487,31 @@ Java_org_openafs_jafs_Cell_getPtsUsersBegin (JNIEnv *env, jclass cls, * returns the name of the next user of the cell */ JNIEXPORT jstring JNICALL -Java_org_openafs_jafs_Cell_getPtsUsersNextString (JNIEnv *env, jclass cls, - jint iterationId) { - +Java_org_openafs_jafs_Cell_getPtsUsersNextString + (JNIEnv *env, jclass cls, jint iterationId) +{ afs_status_t ast; char *userName; jstring juser; userName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); - if( !userName ) { + if ( !userName ) { throwAFSException( env, JAFSADMNOMEM ); - return; + return NULL; } - if( !pts_UserListNext( (void *) iterationId, userName, &ast ) ) { + if ( !pts_UserListNext( (void *) iterationId, userName, &ast ) ) { free( userName ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return NULL; } else { throwAFSException( env, ast ); - return; + return NULL; } } - if( strcmp( userName, "anonymous" ) == 0 ) { + if ( strcmp( userName, "anonymous" ) == 0 ) { free( userName ); return Java_org_openafs_jafs_Cell_getPtsUsersNextString( env, cls, iterationId ); @@ -539,58 +534,56 @@ Java_org_openafs_jafs_Cell_getPtsUsersNextString (JNIEnv *env, jclass cls, * returns the name of the next pts user (not kas user) of the cell */ JNIEXPORT jstring JNICALL -Java_org_openafs_jafs_Cell_getPtsOnlyUsersNextString (JNIEnv *env, - jclass cls, - jint iterationId, - jint cellHandle) { - +Java_org_openafs_jafs_Cell_getPtsOnlyUsersNextString + (JNIEnv *env, jclass cls, jint iterationId, jint cellHandle) +{ kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) ); kas_principalEntry_t kasEntry; afs_status_t ast; char *userName; jstring juser; - if( !who ) { + if ( !who ) { throwAFSException( env, JAFSADMNOMEM ); - return; + return NULL; } userName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); - - if( !userName ) { + + if ( !userName ) { free( who ); throwAFSException( env, JAFSADMNOMEM ); - return; + return NULL; } while( 1 ) { - if( !pts_UserListNext( (void *) iterationId, userName, &ast ) ) { + if ( !pts_UserListNext( (void *) iterationId, userName, &ast ) ) { free( userName ); free( who ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return NULL; } else { throwAFSException( env, ast ); - return; + return NULL; } } - if( strcmp( userName, "anonymous" ) == 0 ) { + if ( strcmp( userName, "anonymous" ) == 0 ) { continue; } // make sure the name is within the allowed bounds - if( strlen( userName ) > KAS_MAX_NAME_LEN ) { + if ( strlen( userName ) > KAS_MAX_NAME_LEN ) { free( who ); free( userName ); throwAFSException( env, ADMPTSUSERNAMETOOLONG ); - return; + return NULL; } // if there is a kas entry, recurse internal_makeKasIdentity( userName, who ); - if( kas_PrincipalGet( (void *) cellHandle, NULL, who, + if ( kas_PrincipalGet( (void *) cellHandle, NULL, who, &kasEntry, &ast ) ) { continue; } @@ -599,7 +592,6 @@ Java_org_openafs_jafs_Cell_getPtsOnlyUsersNextString (JNIEnv *env, free( userName ); free( who ); return juser; - } } @@ -617,25 +609,25 @@ Java_org_openafs_jafs_Cell_getPtsOnlyUsersNextString (JNIEnv *env, * returns 0 if there are no more users, != 0 otherwise */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getPtsUsersNext (JNIEnv *env, jclass cls, - jint cellHandle, - jint iterationId, - jobject juserObject ) { - +Java_org_openafs_jafs_Cell_getPtsUsersNext + (JNIEnv *env, jclass cls, jint cellHandle, jint iterationId, + jobject juserObject ) +{ + afs_status_t ast; char *userName; jstring juser; userName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); - if( !userName ) { + if ( !userName ) { throwAFSException( env, JAFSADMNOMEM ); - return; + return 0; } - if( !pts_UserListNext( (void *) iterationId, userName, &ast ) ) { + if ( !pts_UserListNext( (void *) iterationId, userName, &ast ) ) { free( userName ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -643,7 +635,7 @@ Java_org_openafs_jafs_Cell_getPtsUsersNext (JNIEnv *env, jclass cls, } } - if( strcmp( userName, "anonymous" ) == 0 ) { + if ( strcmp( userName, "anonymous" ) == 0 ) { free( userName ); return Java_org_openafs_jafs_Cell_getPtsUsersNext( env, cls, cellHandle, @@ -653,7 +645,7 @@ Java_org_openafs_jafs_Cell_getPtsUsersNext (JNIEnv *env, jclass cls, juser = (*env)->NewStringUTF(env, userName); - if( userCls == 0 ) { + if ( userCls == 0 ) { internal_getUserClass( env, juserObject ); } @@ -664,7 +656,6 @@ Java_org_openafs_jafs_Cell_getPtsUsersNext (JNIEnv *env, jclass cls, free( userName ); return 1; - } /** @@ -680,36 +671,35 @@ Java_org_openafs_jafs_Cell_getPtsUsersNext (JNIEnv *env, jclass cls, * returns 0 if there are no more users, != 0 otherwise */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getPtsOnlyUsersNext (JNIEnv *env, jclass cls, - jint cellHandle, - jint iterationId, - jobject juserObject ) { - +Java_org_openafs_jafs_Cell_getPtsOnlyUsersNext + (JNIEnv *env, jclass cls, jint cellHandle, jint iterationId, + jobject juserObject ) +{ kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) ); kas_principalEntry_t kasEntry; afs_status_t ast; char *userName; jstring juser; - if( !who ) { + if ( !who ) { throwAFSException( env, JAFSADMNOMEM ); - return; + return 0; } userName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); - if( !userName ) { + if ( !userName ) { free( who ); throwAFSException( env, JAFSADMNOMEM ); - return; + return 0; } while( 1 ) { - if( !pts_UserListNext( (void *) iterationId, userName, &ast ) ) { + if ( !pts_UserListNext( (void *) iterationId, userName, &ast ) ) { free( userName ); free( who ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -717,26 +707,26 @@ Java_org_openafs_jafs_Cell_getPtsOnlyUsersNext (JNIEnv *env, jclass cls, } } - if( strcmp( userName, "anonymous" ) == 0 ) { + if ( strcmp( userName, "anonymous" ) == 0 ) { continue; } // make sure the name is within the allowed bounds - if( strlen( userName ) > KAS_MAX_NAME_LEN ) { + if ( strlen( userName ) > KAS_MAX_NAME_LEN ) { free( userName ); free( who ); throwAFSException( env, ADMPTSUSERNAMETOOLONG ); return 0; } - if( userCls == 0 ) { + if ( userCls == 0 ) { internal_getUserClass( env, juserObject ); } // if there is a kas entry, recurse internal_makeKasIdentity( userName, who ); - if( kas_PrincipalGet( (void *) cellHandle, NULL, who, + if ( kas_PrincipalGet( (void *) cellHandle, NULL, who, &kasEntry, &ast ) ) { continue; } @@ -763,12 +753,12 @@ Java_org_openafs_jafs_Cell_getPtsOnlyUsersNext (JNIEnv *env, jclass cls, * iterationId the iteration ID of this iteration */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Cell_getPtsUsersDone (JNIEnv *env, jclass cls, - jint iterationId) { - +Java_org_openafs_jafs_Cell_getPtsUsersDone + (JNIEnv *env, jclass cls, jint iterationId) +{ afs_status_t ast; - if( !pts_UserListDone( (void *) iterationId, &ast ) ) { + if ( !pts_UserListDone( (void *) iterationId, &ast ) ) { throwAFSException( env, ast ); return; } @@ -785,22 +775,23 @@ Java_org_openafs_jafs_Cell_getPtsUsersDone (JNIEnv *env, jclass cls, * returns total number of groups */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getGroupCount (JNIEnv *env, jclass cls, - jint cellHandle) { +Java_org_openafs_jafs_Cell_getGroupCount + (JNIEnv *env, jclass cls, jint cellHandle) +{ afs_status_t ast; void *iterationId; char *groupName; int i = 0; - if( !pts_GroupListBegin( (void *) cellHandle, &iterationId, &ast ) ) { + if ( !pts_GroupListBegin( (void *) cellHandle, &iterationId, &ast ) ) { throwAFSException( env, ast ); return -1; } groupName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); - if( !groupName ) { + if ( !groupName ) { throwAFSException( env, JAFSADMNOMEM ); return -1; } @@ -809,7 +800,7 @@ Java_org_openafs_jafs_Cell_getGroupCount (JNIEnv *env, jclass cls, free( groupName ); - if( ast != ADMITERATORDONE ) { + if ( ast != ADMITERATORDONE ) { throwAFSException( env, ast ); return -1; } @@ -829,19 +820,18 @@ Java_org_openafs_jafs_Cell_getGroupCount (JNIEnv *env, jclass cls, * returns an iteration ID */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getGroupsBegin (JNIEnv *env, jclass cls, - jint cellHandle) { - +Java_org_openafs_jafs_Cell_getGroupsBegin + (JNIEnv *env, jclass cls, jint cellHandle) +{ afs_status_t ast; void *iterationId; - if( !pts_GroupListBegin( (void *) cellHandle, &iterationId, &ast ) ) { + if ( !pts_GroupListBegin( (void *) cellHandle, &iterationId, &ast ) ) { throwAFSException( env, ast ); return; } return (jint) iterationId; - } /** @@ -857,10 +847,9 @@ Java_org_openafs_jafs_Cell_getGroupsBegin (JNIEnv *env, jclass cls, * returns an iteration ID */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getGroupsBeginAt (JNIEnv *env, jclass cls, - jint cellHandle, - jint startIndex) { - +Java_org_openafs_jafs_Cell_getGroupsBeginAt + (JNIEnv *env, jclass cls, jint cellHandle, jint startIndex) +{ afs_status_t ast; void *iterationId; char *groupName; @@ -868,15 +857,15 @@ Java_org_openafs_jafs_Cell_getGroupsBeginAt (JNIEnv *env, jclass cls, groupName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); - if( !pts_GroupListBegin( (void *) cellHandle, &iterationId, &ast ) ) { + if ( !pts_GroupListBegin( (void *) cellHandle, &iterationId, &ast ) ) { throwAFSException( env, ast ); return 0; } for ( i = 1; i < startIndex; i++) { - if( !pts_GroupListNext( (void *) iterationId, groupName, &ast ) ) { + if ( !pts_GroupListNext( (void *) iterationId, groupName, &ast ) ) { free( groupName ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -887,7 +876,6 @@ Java_org_openafs_jafs_Cell_getGroupsBeginAt (JNIEnv *env, jclass cls, free( groupName ); return (jint) iterationId; - } /** @@ -900,27 +888,27 @@ Java_org_openafs_jafs_Cell_getGroupsBeginAt (JNIEnv *env, jclass cls, * returns the name of the next user of the cell */ JNIEXPORT jstring JNICALL -Java_org_openafs_jafs_Cell_getGroupsNextString (JNIEnv *env, jclass cls, - jint iterationId) { - +Java_org_openafs_jafs_Cell_getGroupsNextString + (JNIEnv *env, jclass cls, jint iterationId) +{ afs_status_t ast; char *groupName; jstring jgroup; groupName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); - if( !groupName ) { + if ( !groupName ) { throwAFSException( env, JAFSADMNOMEM ); - return; + return NULL; } - if( !pts_GroupListNext( (void *) iterationId, groupName, &ast ) ) { + if ( !pts_GroupListNext( (void *) iterationId, groupName, &ast ) ) { free( groupName ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return NULL; } else { throwAFSException( env, ast ); - return; + return NULL; } } @@ -943,25 +931,24 @@ Java_org_openafs_jafs_Cell_getGroupsNextString (JNIEnv *env, jclass cls, * returns 0 if there are no more users, != 0 otherwise */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getGroupsNext (JNIEnv *env, jclass cls, - jint cellHandle, - jint iterationId, - jobject jgroupObject) { - +Java_org_openafs_jafs_Cell_getGroupsNext + (JNIEnv *env, jclass cls, jint cellHandle, jint iterationId, + jobject jgroupObject) +{ afs_status_t ast; char *groupName; jstring jgroup; groupName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN ); - if( !groupName ) { + if ( !groupName ) { throwAFSException( env, JAFSADMNOMEM ); - return; + return; } - if( !pts_GroupListNext( (void *) iterationId, groupName, &ast ) ) { + if ( !pts_GroupListNext( (void *) iterationId, groupName, &ast ) ) { free( groupName ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -971,7 +958,7 @@ Java_org_openafs_jafs_Cell_getGroupsNext (JNIEnv *env, jclass cls, jgroup = (*env)->NewStringUTF(env, groupName); - if( groupCls == 0 ) { + if ( groupCls == 0 ) { internal_getGroupClass( env, jgroupObject ); } @@ -982,7 +969,6 @@ Java_org_openafs_jafs_Cell_getGroupsNext (JNIEnv *env, jclass cls, free( groupName ); return 1; - } /** @@ -993,16 +979,16 @@ Java_org_openafs_jafs_Cell_getGroupsNext (JNIEnv *env, jclass cls, * iterationId the iteration ID of this iteration */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Cell_getGroupsDone (JNIEnv *env, jclass cls, - jint iterationId) { - +Java_org_openafs_jafs_Cell_getGroupsDone + (JNIEnv *env, jclass cls, jint iterationId) +{ afs_status_t ast; - if( !pts_GroupListDone( (void *) iterationId, &ast ) ) { + if ( !pts_GroupListDone( (void *) iterationId, &ast ) ) { throwAFSException( env, ast ); return; } - + } /** @@ -1016,19 +1002,18 @@ Java_org_openafs_jafs_Cell_getGroupsDone (JNIEnv *env, jclass cls, * returns an integer reresenting the max group id in a cell */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getMaxGroupID (JNIEnv *env, jclass cls, - jint cellHandle) { - +Java_org_openafs_jafs_Cell_getMaxGroupID + (JNIEnv *env, jclass cls, jint cellHandle) +{ afs_status_t ast; jint maxID; - if( !pts_GroupMaxGet( (void *) cellHandle, (int *) &maxID, &ast ) ) { + if ( !pts_GroupMaxGet( (void *) cellHandle, (int *) &maxID, &ast ) ) { throwAFSException( env, ast ); - return; + return 0; } return maxID; - } /** @@ -1041,16 +1026,15 @@ Java_org_openafs_jafs_Cell_getMaxGroupID (JNIEnv *env, jclass cls, * maxID an integer reresenting the new max group id in a cell */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Cell_setMaxGroupID (JNIEnv *env, jclass cls, - jint cellHandle, jint maxID) { - +Java_org_openafs_jafs_Cell_setMaxGroupID + (JNIEnv *env, jclass cls, jint cellHandle, jint maxID) +{ afs_status_t ast; - if( !pts_GroupMaxSet( (void *) cellHandle, (int) maxID, &ast ) ) { + if ( !pts_GroupMaxSet( (void *) cellHandle, (int) maxID, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -1064,19 +1048,18 @@ Java_org_openafs_jafs_Cell_setMaxGroupID (JNIEnv *env, jclass cls, * returns an integer reresenting the max user id in a cell */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getMaxUserID (JNIEnv *env, jclass cls, - jint cellHandle) { - +Java_org_openafs_jafs_Cell_getMaxUserID + (JNIEnv *env, jclass cls, jint cellHandle) +{ afs_status_t ast; jint maxID; - if( !pts_UserMaxGet( (void *) cellHandle, (int *) &maxID, &ast ) ) { + if ( !pts_UserMaxGet( (void *) cellHandle, (int *) &maxID, &ast ) ) { throwAFSException( env, ast ); - return; + return 0; } return maxID; - } /** @@ -1089,16 +1072,15 @@ Java_org_openafs_jafs_Cell_getMaxUserID (JNIEnv *env, jclass cls, * maxID an integer reresenting the new max user id in a cell */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Cell_setMaxUserID (JNIEnv *env, jclass cls, - jint cellHandle, jint maxID) { - +Java_org_openafs_jafs_Cell_setMaxUserID + (JNIEnv *env, jclass cls, jint cellHandle, jint maxID) +{ afs_status_t ast; - if( !pts_UserMaxSet( (void *) cellHandle, (int) maxID, &ast ) ) { + if ( !pts_UserMaxSet( (void *) cellHandle, (int) maxID, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -1111,15 +1093,15 @@ Java_org_openafs_jafs_Cell_setMaxUserID (JNIEnv *env, jclass cls, * returns total number of servers */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getServerCount (JNIEnv *env, jclass cls, - jint cellHandle) { - +Java_org_openafs_jafs_Cell_getServerCount + (JNIEnv *env, jclass cls, jint cellHandle) +{ afs_status_t ast; void *iterationId; afs_serverEntry_t servEntry; int i = 0; - if( !afsclient_AFSServerGetBegin( (void *) cellHandle, + if ( !afsclient_AFSServerGetBegin( (void *) cellHandle, &iterationId, &ast ) ) { throwAFSException( env, ast ); return -1; @@ -1128,7 +1110,7 @@ Java_org_openafs_jafs_Cell_getServerCount (JNIEnv *env, jclass cls, while ( afsclient_AFSServerGetNext( (void *) iterationId, &servEntry, &ast ) ) i++; - if( ast != ADMITERATORDONE ) { + if ( ast != ADMITERATORDONE ) { throwAFSException( env, ast ); return -1; } @@ -1147,20 +1129,19 @@ Java_org_openafs_jafs_Cell_getServerCount (JNIEnv *env, jclass cls, * returns an iteration ID */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Cell_getServersBegin (JNIEnv *env, jclass cls, - jint cellHandle) { - +Java_org_openafs_jafs_Cell_getServersBegin + (JNIEnv *env, jclass cls, jint cellHandle) +{ afs_status_t ast; void *iterationId; - if( !afsclient_AFSServerGetBegin( (void *) cellHandle, + if ( !afsclient_AFSServerGetBegin( (void *) cellHandle, &iterationId, &ast ) ) { throwAFSException( env, ast ); - return; + return -1; } return (jint) iterationId; - } /** @@ -1173,24 +1154,22 @@ Java_org_openafs_jafs_Cell_getServersBegin (JNIEnv *env, jclass cls, * returns the name of the next server of the cell */ JNIEXPORT jstring JNICALL -Java_org_openafs_jafs_Cell_getServersNextString (JNIEnv *env, jclass cls, - jint iterationId) { - +Java_org_openafs_jafs_Cell_getServersNextString + (JNIEnv *env, jclass cls, jint iterationId) +{ afs_status_t ast; jstring jserver; afs_serverEntry_t servEntry; - if( !afsclient_AFSServerGetNext( (void *) iterationId, &servEntry, &ast ) ) { - if( ast == ADMITERATORDONE ) { - return NULL; - } else { - throwAFSException( env, ast ); - return; - } + if ( !afsclient_AFSServerGetNext( (void *) iterationId, &servEntry, &ast ) ) { + if ( ast == ADMITERATORDONE ) { + return NULL; + } else { + throwAFSException( env, ast ); + return NULL; + } } - return jserver; - } /** @@ -1215,8 +1194,8 @@ Java_org_openafs_jafs_Cell_getServersNext afs_serverEntry_t servEntry; jintArray jaddress; - if( !afsclient_AFSServerGetNext( (void *) iterationId, &servEntry, &ast ) ) { - if( ast == ADMITERATORDONE ) { + if ( !afsclient_AFSServerGetNext( (void *) iterationId, &servEntry, &ast ) ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -1225,7 +1204,7 @@ Java_org_openafs_jafs_Cell_getServersNext } // get the class fields if need be - if( serverCls == 0 ) { + if ( serverCls == 0 ) { internal_getServerClass( env, jserverObject ); } @@ -1249,11 +1228,10 @@ Java_org_openafs_jafs_Cell_getServersDone { afs_status_t ast; - if( !afsclient_AFSServerGetDone( (void *) iterationId, &ast ) ) { + if ( !afsclient_AFSServerGetDone( (void *) iterationId, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -1269,72 +1247,58 @@ Java_org_openafs_jafs_Cell_getServersDone * forceCheck whether or not to check if this volume name exists */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Cell_createMountPoint (JNIEnv *env, jclass cls, - jint cellHandle, - jstring jdirectory, - jstring jvolumeName, - jboolean readWrite, - jboolean forceCheck) { - +Java_org_openafs_jafs_Cell_createMountPoint + (JNIEnv *env, jclass cls, jint cellHandle, jstring jdirectory, + jstring jvolumeName, jboolean readWrite, jboolean forceCheck) +{ afs_status_t ast; - const char *directory; - const char *volumeName; + char *directory; + char *volumeName; vol_type_t type; vol_check_t check; - if( jdirectory != NULL ) { - directory = (*env)->GetStringUTFChars(env, jdirectory, 0); - if( !directory ) { + if ( jdirectory != NULL ) { + directory = getNativeString(env, jdirectory); + if ( !directory ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - directory = NULL; + throwAFSException( env, JAFSNULLPATH ); + return; } - if( jvolumeName != NULL ) { - volumeName = (*env)->GetStringUTFChars(env, jvolumeName, 0); - if( !volumeName ) { - if( directory != NULL ) { - (*env)->ReleaseStringUTFChars(env, jdirectory, directory); - } + if ( jvolumeName != NULL ) { + volumeName = getNativeString(env, jvolumeName); + if ( volumeName == NULL ) { + free( directory ); throwAFSException( env, JAFSADMNOMEM ); return; } } else { - volumeName = NULL; + free( directory ); + throwAFSException( env, JAFSNULLVOLUME ); + return; } - if( readWrite ) { + if ( readWrite ) { type = READ_WRITE; } else { type = READ_ONLY; } - if( forceCheck ) { + if ( forceCheck ) { check = CHECK_VOLUME; } else { check = DONT_CHECK_VOLUME; } - if( !afsclient_MountPointCreate( (void *) cellHandle, directory, + if ( !afsclient_MountPointCreate( (void *) cellHandle, directory, volumeName, type, check, &ast ) ) { - if( volumeName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jvolumeName, volumeName); - } - if( directory != NULL ) { - (*env)->ReleaseStringUTFChars(env, jdirectory, directory); - } throwAFSException( env, ast ); - return; - } - - if( volumeName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jvolumeName, volumeName); - } - if( directory != NULL ) { - (*env)->ReleaseStringUTFChars(env, jdirectory, directory); } + free( directory ); + free( volumeName ); } /* @@ -1354,132 +1318,97 @@ Java_org_openafs_jafs_Cell_createMountPoint (JNIEnv *env, jclass cls, * admin whether or not to allow admin access to this user */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Cell_setACL (JNIEnv *env, jclass cls, - jstring jdirectory, jstring juserName, - jboolean read, jboolean write, - jboolean lookup, jboolean delete, - jboolean insert, jboolean lock, - jboolean admin) { - +Java_org_openafs_jafs_Cell_setACL + (JNIEnv *env, jclass cls, jstring jdirectory, jstring juserName, + jboolean read, jboolean write, jboolean lookup, jboolean delete, + jboolean insert, jboolean lock, jboolean admin) +{ afs_status_t ast; - const char *directory; - const char *userName; + char *directory; + char *userName; acl_t acl; - // Added by MP - if( !afsclient_Init( &ast ) ) { + if ( !afsclient_Init( &ast ) ) { throwAFSException( env, ast ); return; } - if( jdirectory != NULL ) { - directory = (*env)->GetStringUTFChars(env, jdirectory, 0); - if( !directory ) { + if ( jdirectory != NULL ) { + directory = getNativeString(env, jdirectory); + if ( !directory ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - directory = NULL; + throwAFSException( env, JAFSNULLPATH ); + return; } - if( juserName != NULL ) { - userName = (*env)->GetStringUTFChars(env, juserName, 0); - if( !userName ) { - if( directory != NULL ) { - (*env)->ReleaseStringUTFChars(env, jdirectory, directory); - } + + if ( juserName != NULL ) { + userName = getNativeString(env, juserName); + if ( !userName ) { + free( directory ); throwAFSException( env, JAFSADMNOMEM ); return; } } else { - userName = NULL; + free( directory ); + throwAFSException( env, JAFSNULLUSER ); + return; } - if( read ) { + if ( read ) { acl.read = READ; } else { acl.read = NO_READ; } - if( write ) { + if ( write ) { acl.write = WRITE; } else { acl.write = NO_WRITE; } - if( lookup ) { + if ( lookup ) { acl.lookup = LOOKUP; } else { acl.lookup = NO_LOOKUP; } - if( delete ) { + if ( delete ) { acl.del = DELETE; } else { acl.del = NO_DELETE; } - if( insert ) { + if ( insert ) { acl.insert = INSERT; } else { acl.insert = NO_INSERT; } - if( lock ) { + if ( lock ) { acl.lock = LOCK; } else { acl.lock = NO_LOCK; } - if( admin ) { + if ( admin ) { acl.admin = ADMIN; } else { acl.admin = NO_ADMIN; } - if( !afsclient_ACLEntryAdd( directory, userName, &acl, &ast ) ) { - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( directory != NULL ) { - (*env)->ReleaseStringUTFChars(env, jdirectory, directory); - } - throwAFSException( env, ast ); - return; - } - - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( directory != NULL ) { - (*env)->ReleaseStringUTFChars(env, jdirectory, directory); + if ( !afsclient_ACLEntryAdd( directory, userName, &acl, &ast ) ) { + throwAFSException( env, ast ); } + free( userName ); + free( directory ); } // reclaim global memory used by this portion JNIEXPORT void JNICALL -Java_org_openafs_jafs_Cell_reclaimCellMemory (JNIEnv *env, jclass cls) { - +Java_org_openafs_jafs_Cell_reclaimCellMemory (JNIEnv *env, jclass cls) +{ } - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/JAVA/libjafs/File.c b/src/JAVA/libjafs/File.c index 4adcfd06dd..b2f563b862 100644 --- a/src/JAVA/libjafs/File.c +++ b/src/JAVA/libjafs/File.c @@ -19,6 +19,11 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#if 0 +#include +#include +#endif + #include "Internal.h" #include "org_openafs_jafs_File.h" @@ -76,28 +81,34 @@ char* getAbsolutePath(JNIEnv *env, jobject *obj, char *dirName) jclass thisClass; jstring jDirName; jmethodID getAbsolutePathID; - const char *auxDirName; + char *auxDirName; jfieldID fid; thisClass = (*env)->GetObjectClass(env, *obj); - if(thisClass == NULL) { + if( thisClass == NULL ) { fprintf(stderr, "File::getAbsolutePath(): GetObjectClass failed\n"); return NULL; } + fid = (*env)->GetFieldID(env, thisClass, "path", "Ljava/lang/String;"); - if (fid == 0) { + if ( fid == NULL ) { fprintf(stderr, "File::getAbsolutePath(): GetFieldID (path) failed\n"); return NULL; } - jDirName = (*env)->GetObjectField(env, *obj, fid); - if(jDirName == NULL) { + jDirName = (*env)->GetObjectField(env, *obj, fid); + if( jDirName == NULL ) { fprintf(stderr, "File::getAbsolutePath(): failed to get file name\n"); return NULL; } - auxDirName = (*env) -> GetStringUTFChars(env, jDirName, 0); + + auxDirName = getNativeString(env, jDirName); + if ( auxDirName == NULL ) { + fprintf(stderr, "File::getAbsolutePath(): failed to get translated file name\n"); + return NULL; + } strcpy(dirName, auxDirName); - (*env) -> ReleaseStringUTFChars(env, jDirName, auxDirName); + free( auxDirName ); } /** @@ -464,8 +475,9 @@ JNIEXPORT jboolean JNICALL Java_org_openafs_jafs_File_closeDir if (rc < 0) { setError(env, &obj, errno); return JNI_FALSE; + } else { + return JNI_TRUE; } - else return JNI_TRUE; } @@ -636,8 +648,7 @@ void setFileNotExistsAttributes fid = (*env)->GetFieldID(env, thisClass, "isDirectory", "Z"); if (fid == 0) { fprintf(stderr, - "File::setFileNotExistsAttributes(): GetFieldID (isDirectory) - failed\n"); + "File::setFileNotExistsAttributes(): GetFieldID (isDirectory) failed\n"); return; } (*env)->SetBooleanField(env, *obj, fid, JNI_FALSE); @@ -645,8 +656,7 @@ void setFileNotExistsAttributes fid = (*env)->GetFieldID(env, thisClass, "isFile", "Z"); if (fid == 0) { fprintf(stderr, - "File::setFileNotExistsAttributes(): GetFieldID (isDirectory) - failed\n"); + "File::setFileNotExistsAttributes(): GetFieldID (isDirectory) failed\n"); return; } (*env)->SetBooleanField(env, *obj, fid, JNI_FALSE); @@ -670,5 +680,3 @@ void setFileNotExistsAttributes return; } - - diff --git a/src/JAVA/libjafs/FileInputStream.c b/src/JAVA/libjafs/FileInputStream.c index 95b9327dd2..7c1b7fc873 100644 --- a/src/JAVA/libjafs/FileInputStream.c +++ b/src/JAVA/libjafs/FileInputStream.c @@ -33,7 +33,7 @@ extern int errno; /** * Be carefull with the memory management: * - * - For every GetStringUTFChars call the corresponding ReleaseStringUTFChars. + * - For every getNativeString call the corresponding free(). * - For every GetArrayElements call the corresponding * ReleaseArrayElements * - For every malloc call the corresponding free. @@ -91,13 +91,13 @@ JNIEXPORT jint JNICALL Java_org_openafs_jafs_FileInputStream_read jfieldID fid; /* If we have to read 0 bytes just return */ - if(length == 0) return 0; + if (length == 0) return 0; thisClass = (*env)->GetObjectClass(env, obj); fid = (*env)->GetFieldID(env, thisClass, "fileDescriptor", "I"); fd = (*env)->GetIntField(env, obj, fid); - if(fd < 0) { + if (fd < 0) { fprintf(stderr, "FileInputStream::read(): invalid file state\n"); throwAFSFileException(env, 0, "Invalid file state"); return -1; @@ -136,7 +136,7 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_FileInputStream_close fid = (*env)->GetFieldID(env, thisClass, "fileDescriptor", "I"); fd = (*env)->GetIntField(env, obj, fid); - if(fd < 0) { + if (fd < 0) { fprintf(stderr, "FileInputStream::close(): invalid file state\n"); throwAFSFileException(env, 0, "Invalid file state"); return; @@ -148,6 +148,3 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_FileInputStream_close throwAFSFileException(env, errno, NULL); } } - - - diff --git a/src/JAVA/libjafs/FileOutputStream.c b/src/JAVA/libjafs/FileOutputStream.c index ed3e617f11..effd823603 100644 --- a/src/JAVA/libjafs/FileOutputStream.c +++ b/src/JAVA/libjafs/FileOutputStream.c @@ -19,12 +19,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include + #include "Internal.h" #include "org_openafs_jafs_FileOutputStream.h" #include #include -#include +/*#include */ #ifdef DMALLOC #include "dmalloc.h" @@ -33,7 +36,7 @@ /** * Be carefull with the memory management: * - * - For every GetStringUTFChars call the corresponding ReleaseStringUTFChars. + * - For every getNativeString call the corresponding free(). * - For every GetArrayElements call the corresponding * ReleaseArrayElements * - For every malloc call the corresponding free. @@ -104,40 +107,43 @@ JNIEXPORT jint JNICALL Java_org_openafs_jafs_FileOutputStream_openAppend JNIEXPORT void JNICALL Java_org_openafs_jafs_FileOutputStream_write (JNIEnv *env, jobject obj, jbyteArray jbytes, jint offset, jint length) { - int fd, written, toWrite; - jint twritten; - jclass thisClass; - jmethodID getFileDescriptorID; - char *bytes; - jfieldID fid; + int fd, written, toWrite; + jint twritten; + jclass thisClass; + jmethodID getFileDescriptorID; + char *bytes; + jfieldID fid; - thisClass = (*env)->GetObjectClass(env, obj); - fid = (*env)->GetFieldID(env, thisClass, "fileDescriptor", "I"); - fd = (*env)->GetIntField(env, obj, fid); - if(fd < 0) { - fprintf(stderr, "FileOutputStream::write(): failed to get file + thisClass = (*env)->GetObjectClass(env, obj); + fid = (*env)->GetFieldID(env, thisClass, "fileDescriptor", "I"); + fd = (*env)->GetIntField(env, obj, fid); + if(fd < 0) { + fprintf(stderr, "FileOutputStream::write(): failed to get file descriptor\n"); - throwAFSFileException(env, 0, "Failed to get file descriptor!"); + throwAFSFileException(env, 0, "Failed to get file descriptor!"); + } + + bytes = (char*) malloc(length); + if(bytes == NULL) { + fprintf(stderr, "FileOutputStream::write(): malloc failed of %d bytes\n", + length); + throwAFSFileException(env, 0, "Failed to allocate memory!"); + } + + (*env) -> GetByteArrayRegion(env, jbytes, offset, length, bytes); + toWrite = length; + twritten = 0; + + while( toWrite > 0 ) { + written = uafs_write(fd, bytes, length); + twritten += written; + if( written < 0 ) { + free(bytes); + throwAFSFileException(env, errno, NULL); } - bytes = (char*) malloc(length); - if(bytes == NULL) { - fprintf(stderr, "FileOutputStream::write(): malloc failed of %d bytes\n", - length); - throwAFSFileException(env, 0, "Failed to allocate memory!"); - } - (*env) -> GetByteArrayRegion(env, jbytes, offset, length, bytes); - toWrite = length; - twritten = 0; - while(toWrite>0) { - written = uafs_write(fd, bytes, length); - twritten += written; - if(written<0) { - free(bytes); - throwAFSFileException(env, errno, NULL); - } - toWrite -= written; - } - free(bytes); + toWrite -= written; + } + free(bytes); } /** @@ -153,23 +159,21 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_FileOutputStream_write JNIEXPORT void JNICALL Java_org_openafs_jafs_FileOutputStream_close (JNIEnv *env, jobject obj) { - int fd, rc; - jclass thisClass; - jmethodID getFileDescriptorID; - char *bytes; - jfieldID fid; + int fd, rc; + jclass thisClass; + jmethodID getFileDescriptorID; + char *bytes; + jfieldID fid; - thisClass = (*env)->GetObjectClass(env, obj); - fid = (*env)->GetFieldID(env, thisClass, "fileDescriptor", "I"); - fd = (*env)->GetIntField(env, obj, fid); - if(fd < 0) { - fprintf(stderr, "FileOutputStream::close(): failed to get file descriptor\n"); - throwAFSFileException(env, 0, "Failed to get file descriptor!"); - } - rc = uafs_close(fd); - if (rc != 0) { - throwAFSFileException(env, rc, NULL); - } + thisClass = (*env)->GetObjectClass(env, obj); + fid = (*env)->GetFieldID(env, thisClass, "fileDescriptor", "I"); + fd = (*env)->GetIntField(env, obj, fid); + if(fd < 0) { + fprintf(stderr, "FileOutputStream::close(): failed to get file descriptor\n"); + throwAFSFileException(env, 0, "Failed to get file descriptor!"); + } + rc = uafs_close(fd); + if (rc != 0) { + throwAFSFileException(env, rc, NULL); + } } - - diff --git a/src/JAVA/libjafs/Group.c b/src/JAVA/libjafs/Group.c index 7b944ffc27..b314d920aa 100644 --- a/src/JAVA/libjafs/Group.c +++ b/src/JAVA/libjafs/Group.c @@ -72,63 +72,54 @@ Java_org_openafs_jafs_Group_create { afs_status_t ast; // convert java strings - const char *groupName; - const char *ownerName; + char *groupName; + char *ownerName; - if( jgroupName != NULL ) { - groupName = (*env)->GetStringUTFChars(env, jgroupName, 0); - if( !groupName ) { + if ( jgroupName != NULL ) { + groupName = getNativeString(env, jgroupName); + if ( groupName == NULL ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - groupName = NULL; + throwAFSException( env, JAFSNULLGROUP ); + return; } - if( jownerName != NULL ) { - ownerName = (*env)->GetStringUTFChars(env, jownerName, 0); - if( !ownerName ) { + if ( jownerName != NULL ) { + ownerName = getNativeString(env, jownerName); + if ( ownerName == NULL ) { + free( groupName ); throwAFSException( env, JAFSADMNOMEM ); return; } } else { - ownerName = NULL; + free( groupName ); + throwAFSException( env, JAFSNULLOWNER ); + return; } // make sure the name is within the allowed bounds - if( groupName != NULL && strlen( groupName ) > PTS_MAX_NAME_LEN ) { + if ( strlen( groupName ) > PTS_MAX_NAME_LEN ) { // release converted java strings - if( groupName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupName, groupName); - } - if( ownerName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jownerName, ownerName); - } + free( groupName ); + free( ownerName ); throwAFSException( env, ADMPTSGROUPNAMETOOLONG ); return; } - if( !pts_GroupCreate( (void *) cellHandle, groupName, ownerName, + if ( !pts_GroupCreate( (void *) cellHandle, groupName, ownerName, (int *) &gid, &ast ) ) { // release converted java strings - if( groupName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupName, groupName); - } - if( ownerName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jownerName, ownerName); - } + free( groupName ); + free( ownerName ); throwAFSException( env, ast ); return; } // release converted java strings - if( groupName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupName, groupName); - } - if( ownerName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jownerName, ownerName); - } - + free( groupName ); + free( ownerName ); } /** @@ -147,31 +138,25 @@ Java_org_openafs_jafs_Group_delete { afs_status_t ast; // convert java strings - const char *groupName; + char *groupName; - if( jgroupName != NULL ) { - groupName = (*env)->GetStringUTFChars(env, jgroupName, 0); - if( !groupName ) { + if ( jgroupName != NULL ) { + groupName = getNativeString(env, jgroupName); + if ( !groupName ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - groupName = NULL; + throwAFSException( env, JAFSNULLGROUP ); + return; } - if( !pts_GroupDelete( (void *) cellHandle, groupName, &ast ) ) { - if( groupName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupName, groupName); - } + if ( !pts_GroupDelete( (void *) cellHandle, groupName, &ast ) ) { throwAFSException( env, ast ); - return; } // release converted java strings - if( groupName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupName, groupName); - } - + free( groupName ); } /** @@ -192,7 +177,7 @@ void getGroupInfoChar pts_GroupEntry_t entry; afs_status_t ast; // get the field ids if you haven't already - if( groupCls == 0 ) { + if ( groupCls == 0 ) { internal_getGroupClass( env, group ); } @@ -208,10 +193,10 @@ void getGroupInfoChar (*env)->SetIntField(env, group, group_membershipCountField, entry.membershipCount); - if( entry.listStatus == PTS_GROUP_OWNER_ACCESS ) { + if ( entry.listStatus == PTS_GROUP_OWNER_ACCESS ) { (*env)->SetIntField(env, group, group_listStatusField, org_openafs_jafs_Group_GROUP_OWNER_ACCESS); - } else if( entry.listStatus == PTS_GROUP_ACCESS ) { + } else if ( entry.listStatus == PTS_GROUP_ACCESS ) { (*env)->SetIntField(env, group, group_listStatusField, org_openafs_jafs_Group_GROUP_GROUP_ACCESS); } else { @@ -219,10 +204,10 @@ void getGroupInfoChar org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS); } - if( entry.listGroupsOwned == PTS_GROUP_OWNER_ACCESS ) { + if ( entry.listGroupsOwned == PTS_GROUP_OWNER_ACCESS ) { (*env)->SetIntField(env, group, group_listGroupsOwnedField, org_openafs_jafs_Group_GROUP_OWNER_ACCESS); - } else if( entry.listGroupsOwned == PTS_GROUP_ACCESS ) { + } else if ( entry.listGroupsOwned == PTS_GROUP_ACCESS ) { (*env)->SetIntField(env, group, group_listGroupsOwnedField, org_openafs_jafs_Group_GROUP_GROUP_ACCESS); } else { @@ -230,10 +215,10 @@ void getGroupInfoChar org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS); } - if( entry.listMembership == PTS_GROUP_OWNER_ACCESS ) { + if ( entry.listMembership == PTS_GROUP_OWNER_ACCESS ) { (*env)->SetIntField(env, group, group_listMembershipField, org_openafs_jafs_Group_GROUP_OWNER_ACCESS); - } else if( entry.listMembership == PTS_GROUP_ACCESS ) { + } else if ( entry.listMembership == PTS_GROUP_ACCESS ) { (*env)->SetIntField(env, group, group_listMembershipField, org_openafs_jafs_Group_GROUP_GROUP_ACCESS); } else { @@ -241,10 +226,10 @@ void getGroupInfoChar org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS); } - if( entry.listAdd == PTS_GROUP_OWNER_ACCESS ) { + if ( entry.listAdd == PTS_GROUP_OWNER_ACCESS ) { (*env)->SetIntField(env, group, group_listAddField, org_openafs_jafs_Group_GROUP_OWNER_ACCESS); - } else if( entry.listAdd == PTS_GROUP_ACCESS ) { + } else if ( entry.listAdd == PTS_GROUP_ACCESS ) { (*env)->SetIntField(env, group, group_listAddField, org_openafs_jafs_Group_GROUP_GROUP_ACCESS); } else { @@ -252,10 +237,10 @@ void getGroupInfoChar org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS); } - if( entry.listDelete == PTS_GROUP_OWNER_ACCESS ) { + if ( entry.listDelete == PTS_GROUP_OWNER_ACCESS ) { (*env)->SetIntField(env, group, group_listDeleteField, org_openafs_jafs_Group_GROUP_OWNER_ACCESS); - } else if( entry.listDelete == PTS_GROUP_ACCESS ) { + } else if ( entry.listDelete == PTS_GROUP_ACCESS ) { (*env)->SetIntField(env, group, group_listDeleteField, org_openafs_jafs_Group_GROUP_GROUP_ACCESS); } else { @@ -263,12 +248,11 @@ void getGroupInfoChar org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS); } - jowner = (*env)->NewStringUTF(env, entry.owner); + jowner = (*env)->NewStringUTF(env, entry.owner); jcreator = (*env)->NewStringUTF(env, entry.creator); (*env)->SetObjectField(env, group, group_ownerField, jowner); (*env)->SetObjectField(env, group, group_creatorField, jcreator); - } /** @@ -286,32 +270,29 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_Group_getGroupInfo (JNIEnv *env, jclass cls, jint cellHandle, jstring jname, jobject group) { + char *name; - const char *name; - - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( !name ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - name = NULL; + throwAFSException( env, JAFSNULLGROUP ); + return; } getGroupInfoChar( env, cellHandle, name, group ); // get class fields if need be - if( groupCls == 0 ) { + if ( groupCls == 0 ) { internal_getGroupClass( env, group ); } // set name in case blank object (*env)->SetObjectField(env, group, group_nameField, jname); - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - + free( name ); } /** @@ -327,7 +308,7 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_Group_setGroupInfo (JNIEnv *env, jclass cls, jint cellHandle, jstring jname, jobject group) { - const char *name; + char *name; pts_GroupUpdateEntry_t ptsEntry; afs_status_t ast; @@ -338,7 +319,7 @@ Java_org_openafs_jafs_Group_setGroupInfo jint jlistDelete; // get the field ids if you haven't already - if( groupCls == 0 ) { + if ( groupCls == 0 ) { internal_getGroupClass( env, group ); } @@ -349,65 +330,60 @@ Java_org_openafs_jafs_Group_setGroupInfo jlistAdd = (*env)->GetIntField(env, group, group_listAddField); jlistDelete = (*env)->GetIntField(env, group, group_listDeleteField); - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( name == NULL ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - name = NULL; + throwAFSException( env, JAFSNULLGROUP ); + return; } - if( jlistStatus == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) { + if ( jlistStatus == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) { ptsEntry.listStatus = PTS_GROUP_OWNER_ACCESS; - } else if( jlistStatus == org_openafs_jafs_Group_GROUP_GROUP_ACCESS ) { + } else if ( jlistStatus == org_openafs_jafs_Group_GROUP_GROUP_ACCESS ) { ptsEntry.listStatus = PTS_GROUP_ACCESS; } else { ptsEntry.listStatus = PTS_GROUP_ANYUSER_ACCESS; } - if( jlistGroupsOwned == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) { + if ( jlistGroupsOwned == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) { ptsEntry.listGroupsOwned = PTS_GROUP_OWNER_ACCESS; - } else if( jlistGroupsOwned == + } else if ( jlistGroupsOwned == org_openafs_jafs_Group_GROUP_GROUP_ACCESS ) { ptsEntry.listGroupsOwned = PTS_GROUP_ACCESS; } else { ptsEntry.listGroupsOwned = PTS_GROUP_ANYUSER_ACCESS; } - if( jlistMembership == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) { + if ( jlistMembership == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) { ptsEntry.listMembership = PTS_GROUP_OWNER_ACCESS; - } else if( jlistMembership == + } else if ( jlistMembership == org_openafs_jafs_Group_GROUP_GROUP_ACCESS ) { ptsEntry.listMembership = PTS_GROUP_ACCESS; } else { ptsEntry.listMembership = PTS_GROUP_ANYUSER_ACCESS; } - if( jlistAdd == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) { + if ( jlistAdd == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) { ptsEntry.listAdd = PTS_GROUP_OWNER_ACCESS; - } else if( jlistAdd == org_openafs_jafs_Group_GROUP_GROUP_ACCESS ) { + } else if ( jlistAdd == org_openafs_jafs_Group_GROUP_GROUP_ACCESS ) { ptsEntry.listAdd = PTS_GROUP_ACCESS; } else { ptsEntry.listAdd = PTS_GROUP_ANYUSER_ACCESS; } - if( jlistDelete == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) { + if ( jlistDelete == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) { ptsEntry.listDelete = PTS_GROUP_OWNER_ACCESS; - } else if( jlistDelete == org_openafs_jafs_Group_GROUP_GROUP_ACCESS ) { + } else if ( jlistDelete == org_openafs_jafs_Group_GROUP_GROUP_ACCESS ) { ptsEntry.listDelete = PTS_GROUP_ACCESS; } else { ptsEntry.listDelete = PTS_GROUP_ANYUSER_ACCESS; } - if( !pts_GroupModify( (void *) cellHandle, name, &ptsEntry, &ast ) ) { - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } + + if ( !pts_GroupModify( (void *) cellHandle, name, &ptsEntry, &ast ) ) { throwAFSException( env, ast ); - return; - } - - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); } + free( name ); } /** @@ -425,35 +401,29 @@ JNIEXPORT jint JNICALL Java_org_openafs_jafs_Group_getGroupMembersBegin (JNIEnv *env, jclass cls, jint cellHandle, jstring jname) { - const char *name; + char *name; afs_status_t ast; void *iterationId; - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( name == NULL ) { throwAFSException( env, JAFSADMNOMEM ); - return; + return 0; } } else { - name = NULL; + throwAFSException( env, JAFSNULLGROUP ); + return 0; } - if( !pts_GroupMemberListBegin( (void *) cellHandle, name, &iterationId, + if ( !pts_GroupMemberListBegin( (void *) cellHandle, name, &iterationId, &ast ) ) { - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } throwAFSException( env, ast ); - return; } - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } + free( name ); return (jint) iterationId; - } /** @@ -473,14 +443,14 @@ Java_org_openafs_jafs_Group_getGroupMembersNextString char *userName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); jstring juser; - if( !userName ) { + if ( !userName ) { throwAFSException( env, JAFSADMNOMEM ); return; } - if( !pts_GroupMemberListNext( (void *) iterationId, userName, &ast ) ) { + if ( !pts_GroupMemberListNext( (void *) iterationId, userName, &ast ) ) { free( userName ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return NULL; } else { throwAFSException( env, ast ); @@ -516,14 +486,14 @@ Java_org_openafs_jafs_Group_getGroupMembersNext userName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); - if( !userName ) { + if ( !userName ) { throwAFSException( env, JAFSADMNOMEM ); return; } - if( !pts_GroupMemberListNext( (void *) iterationId, userName, &ast ) ) { + if ( !pts_GroupMemberListNext( (void *) iterationId, userName, &ast ) ) { free( userName ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -533,7 +503,7 @@ Java_org_openafs_jafs_Group_getGroupMembersNext juser = (*env)->NewStringUTF(env, userName); - if( userCls == 0 ) { + if ( userCls == 0 ) { internal_getUserClass( env, juserObject ); } @@ -560,11 +530,10 @@ Java_org_openafs_jafs_Group_getGroupMembersDone { afs_status_t ast; - if( !pts_GroupMemberListDone( (void *) iterationId, &ast ) ) { + if ( !pts_GroupMemberListDone( (void *) iterationId, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -582,49 +551,39 @@ Java_org_openafs_jafs_Group_addMember jstring juserName ) { afs_status_t ast; - const char *groupName; - const char *userName; + char *groupName; + char *userName; - if( jgroupName != NULL ) { - groupName = (*env)->GetStringUTFChars(env, jgroupName, 0); - if( !groupName ) { + if ( jgroupName != NULL ) { + groupName = getNativeString(env, jgroupName); + if ( groupName == NULL ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - groupName = NULL; + throwAFSException( env, JAFSNULLGROUP ); + return; } - if( juserName != NULL ) { - userName = (*env)->GetStringUTFChars(env, juserName, 0); - if( !userName ) { - if( groupName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupName, groupName); - } + if ( juserName != NULL ) { + userName = getNativeString(env, juserName); + if ( userName == NULL ) { + free( groupName ); throwAFSException( env, JAFSADMNOMEM ); return; } } else { - userName = NULL; - } - - if( !pts_GroupMemberAdd( (void *) cellHandle, userName, groupName, &ast ) ) { - if( groupName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupName, groupName); - } - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - throwAFSException( env, ast ); + free( groupName ); + throwAFSException( env, JAFSNULLUSER ); return; } - if( groupName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupName, groupName); - } - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); + if ( !pts_GroupMemberAdd( (void *) cellHandle, userName, groupName, &ast ) ) { + throwAFSException( env, ast ); } + + free( userName ); + free( groupName ); } /** @@ -643,50 +602,40 @@ Java_org_openafs_jafs_Group_removeMember jstring juserName) { afs_status_t ast; - const char *groupName; - const char *userName; + char *groupName; + char *userName; - if( jgroupName != NULL ) { - groupName = (*env)->GetStringUTFChars(env, jgroupName, 0); - if( !groupName ) { + if ( jgroupName != NULL ) { + groupName = getNativeString(env, jgroupName); + if ( groupName == NULL ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - groupName = NULL; + throwAFSException( env, JAFSNULLGROUP ); + return; } - if( juserName != NULL ) { - userName = (*env)->GetStringUTFChars(env, juserName, 0); - if( !userName ) { - if( groupName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupName, groupName); - } + if ( juserName != NULL ) { + userName = getNativeString(env, juserName); + if ( userName == NULL ) { + free( groupName ); throwAFSException( env, JAFSADMNOMEM ); return; } } else { - userName = NULL; - } - - if( !pts_GroupMemberRemove( (void *)cellHandle, userName, - groupName, &ast ) ) { - if( groupName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupName, groupName); - } - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - throwAFSException( env, ast ); + free( groupName ); + throwAFSException( env, JAFSNULLUSER ); return; } + + if ( !pts_GroupMemberRemove( (void *)cellHandle, userName, + groupName, &ast ) ) { + throwAFSException( env, ast ); + } - if( groupName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupName, groupName); - } - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } + free( groupName ); + free( userName ); } /** @@ -705,51 +654,40 @@ Java_org_openafs_jafs_Group_changeOwner jstring jownerName ) { afs_status_t ast; - const char *groupName; - const char *ownerName; + char *groupName; + char *ownerName; - if( jgroupName != NULL ) { - groupName = (*env)->GetStringUTFChars(env, jgroupName, 0); - if( !groupName ) { + if ( jgroupName != NULL ) { + groupName = getNativeString(env, jgroupName); + if ( groupName == NULL ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - groupName = NULL; + throwAFSException( env, JAFSNULLGROUP ); + return; } - if( jownerName != NULL ) { - ownerName = (*env)->GetStringUTFChars(env, jownerName, 0); - if( !ownerName ) { - if( groupName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupName, groupName); - } + if ( jownerName != NULL ) { + ownerName = getNativeString(env, jownerName); + if ( ownerName == NULL ) { + free( groupName ); throwAFSException( env, JAFSADMNOMEM ); return; } } else { - ownerName = NULL; + free( groupName ); + throwAFSException( env, JAFSNULLOWNER ); + return; } - if( !pts_GroupOwnerChange( (void *)cellHandle, groupName, + if ( !pts_GroupOwnerChange( (void *)cellHandle, groupName, ownerName, &ast ) ) { - if( groupName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupName, groupName); - } - if( ownerName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jownerName, ownerName); - } throwAFSException( env, ast ); - return; } - if( groupName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupName, groupName); - } - if( ownerName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jownerName, ownerName); - } - + free( groupName ); + free( ownerName ); } /** @@ -767,61 +705,48 @@ Java_org_openafs_jafs_Group_rename jstring jgroupNewName ) { afs_status_t ast; - const char *groupOldName; - const char *groupNewName; + char *groupOldName; + char *groupNewName; - if( jgroupOldName != NULL ) { - groupOldName = (*env)->GetStringUTFChars(env, jgroupOldName, 0); - if( !groupOldName ) { + if ( jgroupOldName != NULL ) { + groupOldName = getNativeString(env, jgroupOldName); + if ( groupOldName == NULL ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - groupOldName = NULL; + throwAFSException( env, JAFSNULLGROUP ); + return; } - if( jgroupNewName != NULL ) { - groupNewName = (*env)->GetStringUTFChars(env, jgroupNewName, 0); - if( !groupNewName ) { - if( groupOldName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupOldName, groupOldName); - } + if ( jgroupNewName != NULL ) { + groupNewName = getNativeString(env, jgroupNewName); + if ( groupNewName == NULL ) { + free( groupOldName ); throwAFSException( env, JAFSADMNOMEM ); return; } } else { - groupNewName = NULL; - } - - if( !pts_GroupRename( (void *)cellHandle, groupOldName, - groupNewName, &ast ) ) { - if( groupOldName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupOldName, groupOldName); - } - if( groupNewName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupNewName, groupNewName); - } - throwAFSException( env, ast ); + free( groupOldName ); + throwAFSException( env, JAFSNULLGROUP ); return; } - if( groupOldName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupOldName, groupOldName); - } - if( groupNewName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jgroupNewName, groupNewName); + if ( !pts_GroupRename( (void *)cellHandle, groupOldName, + groupNewName, &ast ) ) { + throwAFSException( env, ast ); } + + free( groupOldName ); + free( groupNewName ); } // reclaim global memory used by this portion JNIEXPORT void JNICALL Java_org_openafs_jafs_Group_reclaimGroupMemory (JNIEnv *env, jclass cls) { - if( groupCls ) { - (*env)->DeleteGlobalRef(env, groupCls); - groupCls = 0; + if ( groupCls ) { + (*env)->DeleteGlobalRef(env, groupCls); + groupCls = 0; } } - - - diff --git a/src/JAVA/libjafs/Internal.c b/src/JAVA/libjafs/Internal.c index c43bcb4679..e9bce8c73f 100644 --- a/src/JAVA/libjafs/Internal.c +++ b/src/JAVA/libjafs/Internal.c @@ -27,15 +27,16 @@ extern int errno; +jmethodID MID_String_getBytes = 0; + #ifndef LIBJUAFS -// user class and fields // -jclass userCls = 0; +/* User Class and Fields */ +jclass userCls = 0; jfieldID user_ptsField = 0; jfieldID user_kasField = 0; jfieldID user_nameField = 0; -//jfieldID user_cellHandleField = 0; jfieldID user_cachedInfoField = 0; -//pts fields +/* PTS Fields */ jfieldID user_nameUidField = 0; jfieldID user_ownerUidField = 0; jfieldID user_creatorUidField = 0; @@ -46,7 +47,7 @@ jfieldID user_groupCreationQuotaField = 0; jfieldID user_groupMembershipCountField = 0; jfieldID user_ownerField = 0; jfieldID user_creatorField = 0; -// kas fields +/* KAS Fields */ jfieldID user_adminSettingField = 0; jfieldID user_tgsSettingField = 0; jfieldID user_encSettingField = 0; @@ -65,10 +66,9 @@ jfieldID user_failLoginCountField = 0; jfieldID user_lockTimeField = 0; jfieldID user_lockedUntilField = 0; -// group class and fields // -jclass groupCls = 0; +/* Group Class and Fields */ +jclass groupCls = 0; jfieldID group_nameField = 0; -//jfieldID group_cellHandleField = 0; jfieldID group_cachedInfoField = 0; jfieldID group_nameUidField = 0; jfieldID group_ownerUidField = 0; @@ -82,10 +82,9 @@ jfieldID group_membershipCountField = 0; jfieldID group_ownerField = 0; jfieldID group_creatorField = 0; -// server class and fields // -jclass serverCls = 0; +/* Server Class and Fields */ +jclass serverCls = 0; jfieldID server_nameField = 0; -//jfieldID server_cellHandleField = 0; jfieldID server_cachedInfoField = 0; jfieldID server_databaseField = 0; jfieldID server_fileServerField = 0; @@ -93,8 +92,8 @@ jfieldID server_badDatabaseField = 0; jfieldID server_badFileServerField = 0; jfieldID server_IPAddressField = 0; -// executable time class and fields // -jclass exectimeCls = 0; +/* Executable Time Class and Fields */ +jclass exectimeCls = 0; jfieldID exectime_HourField = 0; jfieldID exectime_MinField = 0; jfieldID exectime_SecField = 0; @@ -102,8 +101,8 @@ jfieldID exectime_DayField = 0; jfieldID exectime_NowField = 0; jfieldID exectime_NeverField = 0; -// partition class and fields // -jclass partitionCls = 0; +/* Partition Class and Fields */ +jclass partitionCls = 0; jfieldID partition_nameField = 0; jfieldID partition_cachedInfoField = 0; jfieldID partition_idField = 0; @@ -112,8 +111,8 @@ jfieldID partition_lockFileDescriptorField = 0; jfieldID partition_totalSpaceField = 0; jfieldID partition_totalFreeSpaceField = 0; -// volume class and fields // -jclass volumeCls = 0; +/* Volume Class and Fields */ +jclass volumeCls = 0; jfieldID volume_nameField = 0; jfieldID volume_cachedInfoField = 0; jfieldID volume_idField = 0; @@ -133,8 +132,8 @@ jfieldID volume_statusField = 0; jfieldID volume_dispositionField = 0; jfieldID volume_typeField = 0; -// key class and fields // -jclass keyCls = 0; +/* Key Class and Fields */ +jclass keyCls = 0; jfieldID key_cachedInfoField = 0; jfieldID key_versionField = 0; jfieldID key_encryptionKeyField = 0; @@ -142,11 +141,10 @@ jfieldID key_lastModDateField = 0; jfieldID key_lastModMsField = 0; jfieldID key_checkSumField = 0; -// process class and fields // -jclass processCls = 0; +/* Process Class and Fields */ +jclass processCls = 0; jfieldID process_cachedInfoField = 0; jfieldID process_nameField = 0; -//jfieldID process_serverHandleField = 0; jfieldID process_typeField = 0; jfieldID process_stateField = 0; jfieldID process_goalField = 0; @@ -159,6 +157,7 @@ jfieldID process_errorSignalField = 0; jfieldID process_stateOkField = 0; jfieldID process_stateTooManyErrorsField = 0; jfieldID process_stateBadFileAccessField = 0; + #endif /* !LIBJUAFS */ /** @@ -173,23 +172,20 @@ void throwException if( *excCls == 0 ) { *excCls = (*env)->NewGlobalRef(env, (*env)->FindClass(env, excClsName )); if( !*excCls ) { - fprintf(stderr, "ERROR: Internal::throwException()\n - Cannot find class: %s\n", excClsName); + fprintf(stderr, "ERROR: Internal::throwException()\n Cannot find class: %s\n", excClsName); return; } *initID = (*env)->GetMethodID( env, *excCls, "", "(I)V" ); if( !*initID ) { - fprintf(stderr, "ERROR: Internal::throwException()\n - Cannot find construction method: %s\n", - excClsName); + fprintf(stderr, "ERROR: Internal::throwException()\n Cannot find construction method: %s\n", + excClsName); return; } } exc = (*env)->NewObject( env, *excCls, *initID, code ); if( !exc ) { - fprintf(stderr, "ERROR: Internal::throwException()\n - Cannot construct new exception object: %s\n", + fprintf(stderr, "ERROR: Internal::throwException()\n Cannot construct new exception object: %s\n", excClsName); return; } @@ -206,8 +202,7 @@ void throwMessageException( JNIEnv *env, char *msg ) { jclass excCls = (*env)->FindClass(env, afsExceptionName); if(excCls == 0) { - fprintf(stderr, "ERROR: Internal::throwMessageException()\n - Cannot find class: %s\n", afsExceptionName); + fprintf(stderr, "ERROR: Internal::throwMessageException()\n Cannot find class: %s\n", afsExceptionName); return; } (*env)->ThrowNew(env, excCls, msg); @@ -226,16 +221,14 @@ void throwAFSException( JNIEnv *env, int code ) afsExceptionCls = (*env)->FindClass(env, afsExceptionName); if( !afsExceptionCls ) { - fprintf(stderr, "ERROR: Internal::throwAFSException()\n - Cannot find class: %s\n", afsExceptionName); + fprintf(stderr, "ERROR: Internal::throwAFSException()\n Cannot find class: %s\n", afsExceptionName); return; } afsExceptionInit = (*env)->GetMethodID( env, afsExceptionCls, "", "(I)V" ); if( !afsExceptionInit ) { - fprintf(stderr, "ERROR: Internal::throwAFSException()\n - Cannot find construction method: %s\n", + fprintf(stderr, "ERROR: Internal::throwAFSException()\n Cannot find construction method: %s\n", afsExceptionName); return; } @@ -243,8 +236,7 @@ void throwAFSException( JNIEnv *env, int code ) exc = (*env)->NewObject( env, afsExceptionCls, afsExceptionInit, code ); if( !exc ) { - fprintf(stderr, "ERROR: Internal::throwAFSException()\n - Cannot construct new exception object: %s\n", + fprintf(stderr, "ERROR: Internal::throwAFSException()\n Cannot construct new exception object: %s\n", afsExceptionName); return; } @@ -264,16 +256,15 @@ void throwAFSFileException( JNIEnv *env, int code, char *msg ) afsFileExceptionCls = (*env)->FindClass(env, afsFileExceptionName); if( !afsFileExceptionCls ) { - fprintf(stderr, "ERROR: Internal::throwAFSFileException()\n - Cannot find class: %s\n", afsFileExceptionName); + fprintf(stderr, "ERROR: Internal::throwAFSFileException()\n Cannot find class: %s\n", afsFileExceptionName); return; } afsFileExceptionInit = (*env)->GetMethodID( env, afsFileExceptionCls, "", "(Ljava/lang/String;I)V" ); + if( !afsFileExceptionInit ) { - fprintf(stderr, "ERROR: Internal::throwAFSFileException()\n - Cannot find construction method: %s\n", + fprintf(stderr, "ERROR: Internal::throwAFSFileException()\n Cannot find construction method: %s\n", afsFileExceptionName); return; } @@ -281,8 +272,7 @@ void throwAFSFileException( JNIEnv *env, int code, char *msg ) exc = (*env)->NewObject( env, afsFileExceptionCls, afsFileExceptionInit, msg, code ); if( !exc ) { - fprintf(stderr, "ERROR: Internal::throwAFSFileException()\n - Cannot construct new exception object: %s\n", + fprintf(stderr, "ERROR: Internal::throwAFSFileException()\n Cannot construct new exception object: %s\n", afsFileExceptionName); return; } @@ -302,25 +292,23 @@ void throwAFSSecurityException( JNIEnv *env, int code ) afsSecurityExceptionCls = (*env)->FindClass(env, afsSecurityExceptionName); if( !afsSecurityExceptionCls ) { - fprintf(stderr, "ERROR: Internal::throwAFSSecurityException()\n - Cannot find class: %s\n", afsSecurityExceptionName); + fprintf(stderr, "ERROR: Internal::throwAFSSecurityException()\n Cannot find class: %s\n", afsSecurityExceptionName); return; } afsSecurityExceptionInit = (*env)->GetMethodID( env, afsSecurityExceptionCls, "", "(I)V" ); if( !afsSecurityExceptionInit ) { - fprintf(stderr, "ERROR: Internal::throwAFSSecurityException()\n - Cannot find construction method: %s\n", + fprintf(stderr, "ERROR: Internal::throwAFSSecurityException()\n Cannot find construction method: %s\n", afsSecurityExceptionName); return; } exc = (*env)->NewObject( env, afsSecurityExceptionCls, afsSecurityExceptionInit, code ); + if( !exc ) { - fprintf(stderr, "ERROR: Internal::throwAFSSecurityException()\n - Cannot construct new exception object: %s\n", + fprintf(stderr, "ERROR: Internal::throwAFSSecurityException()\n Cannot construct new exception object: %s\n", afsSecurityExceptionName); return; } @@ -342,6 +330,98 @@ int setError(JNIEnv *env, jobject *obj, int code) return -1; } +int setString(JNIEnv *env, jobject *obj, char *field, char *string) +{ + jclass cls; + jstring jstr; + jfieldID fid; + + cls = (*env)->GetObjectClass(env, *obj); + /*fprintf(stderr, "setString: env=0x%x, obj=0x%x, cls=0x%x\n", env, obj, cls);*/ + if (cls != NULL) { + fid = (*env)->GetFieldID(env, cls, field, "Ljava/lang/String;"); + /*fprintf(stderr, "setString: field=%s, fid=0x%x\n", field, fid);*/ + if (fid) { + jstr = (*env)->NewStringUTF(env, (string)); + /*fprintf(stderr, "jstr = 0x%x\n", jstr);*/ + (*env)->SetObjectField(env, *obj, fid, jstr); + return 0; + } + } + return -1; +} + +/** + * Translates a jstring to a locale-specific native C string. + * Use in place of "GetStringUTFChars()" for internationalization + * purposes. + * + * Make sure to "free()" any strings created by this function. + * + * A NULL (zero) return indicates a critical error has occurred and + * relies on the caller of this function to throw a Java exception. + * + * This function does not throw any Java exceptions. + * + * env the Java environment + * jstr the Java string (UTF) to translate + * + * @returns native C string with the appropriate locale-specific + * representation + */ +char* getNativeString(JNIEnv *env, const jstring jstr) +{ + jbyteArray bytes = 0; + char *result = NULL; + jint len = 0; + + if ((*env)->EnsureLocalCapacity(env, 2) < 0) { + // Out of memory error + fprintf(stderr, "Internal::getNativeString(): "); + fprintf(stderr, "EnsureLocalCapacity() failed: Most likely out of memory\n"); + return NULL; + } + + if ( !MID_String_getBytes ) { + jclass stringClass = (*env)->FindClass(env, "java/lang/String"); + if ( !stringClass ) { + fprintf(stderr, "Internal::getNativeString(): "); + fprintf(stderr, "Could not locate Java class: java.lang.String.\n"); + return NULL; + } + + MID_String_getBytes = (*env)->GetMethodID(env, stringClass, "getBytes","()[B"); + if ( !MID_String_getBytes ) { + fprintf(stderr, "Internal::getNativeString(): "); + fprintf(stderr, "Could not get Java method id for java.lang.String method \"getBytes()\".\n"); + return NULL; + } + } + + bytes = (*env)->CallObjectMethod(env, jstr, MID_String_getBytes); + if ( !bytes ) { + fprintf(stderr, "Internal::getNativeString(): "); + fprintf(stderr, "CallObjectMethod() failed for java.lang.String.getBytes().\n"); + fprintf(stderr, "\tMID_String_getBytes = %d\n", MID_String_getBytes); + return NULL; + } + + len = (*env)->GetArrayLength(env, bytes); + result = (char *)malloc(len + 1); + + if ( !result ) { + fprintf(stderr, "Internal::getNativeString(): "); + fprintf(stderr, "Could not allocate memory for byte array.\n"); + (*env)->DeleteLocalRef(env, bytes); + return NULL; + } + (*env)->GetByteArrayRegion(env, bytes, 0, len, (jbyte *)result); + result[len] = '\0'; // NULL-terminate + + (*env)->DeleteLocalRef(env, bytes); + return result; +} + #ifdef LIBJUAFS /** @@ -357,34 +437,46 @@ int setError(JNIEnv *env, jobject *obj, int code) * @returns file descriptor */ int openAFSFile - (JNIEnv *env, jstring fileNameUTF, int flags, int mode, int *err) + (JNIEnv *env, jstring filenameUTF, int flags, int mode, int *err) { - char *fileName; + char *filename; int fd = -1; *err = 0; errno = 0; - fileName=(char*) (*env)->GetStringUTFChars(env, fileNameUTF, 0); - if(fileName == NULL) { - fprintf(stderr, "Internal::openAFSFile(): failed to get fileName\n"); + filename = getNativeString(env, filenameUTF); + if(filename == NULL) { + fprintf(stderr, "Internal::openAFSFile(): failed to get filename\n"); *err = -1; return fd; } - fd = uafs_open(fileName, flags, mode); + fd = uafs_open(filename, flags, mode); + free( filename ); *err = errno; if (errno != 0) { fprintf(stderr, "Internal::openAFSFile(): errno=%d\n", errno); fprintf(stderr, "Internal::openAFSFile(): fd=%d\n", fd); } - (*env)->ReleaseStringUTFChars(env, fileNameUTF, fileName); if (fd < 0) { - fprintf(stderr, "Internal::openAFSFile(): failed to open fileName\n"); + fprintf(stderr, "Internal::openAFSFile(): failed to open filename\n"); fprintf(stderr, "Internal::openAFSFile(): fd=%d\n", fd); return -1; } return fd; } +/** + * Reads the "CacheConfig" file for user space configuration. + * By default, this file resides in "/usr/afswsp/etc/CacheConfig", + * however if the environment variable "LIBJAFS_CACHE_CONFIG" is + * set this function will use that value instead. + * + * The CacheConfig file contains several cache tuning parameters + * as well as a few parameters that define the runtime environment + * for the user space client, including: mount point location, + * configuration directory (where to find ThisCell and CellServDB), + * cache directory, debug and verbose options, and log file location. + */ int readCacheParms(char *afsMountPoint, char *afsConfDir, char *afsCacheDir, int *cacheBlocks, int *cacheFiles, int *cacheStatEntries, int *dCacheSize, int *vCacheSize, int *chunkSize, @@ -455,27 +547,6 @@ int readCacheParms(char *afsMountPoint, char *afsConfDir, char *afsCacheDir, return 0; } -int setString(JNIEnv *env, jobject *obj, char *field, char *string) -{ - jclass cls; - jstring jstr; - jfieldID fid; - - cls = (*env)->GetObjectClass(env, *obj); - /*fprintf(stderr, "setString: env=0x%x, obj=0x%x, cls=0x%x\n", env, obj, cls);*/ - if (cls != NULL) { - fid = (*env)->GetFieldID(env, cls, field, "Ljava/lang/String;"); - /*fprintf(stderr, "setString: field=%s, fid=0x%x\n", field, fid);*/ - if (fid) { - jstr = (*env)->NewStringUTF(env, (string)); - /*fprintf(stderr, "jstr = 0x%x\n", jstr);*/ - (*env)->SetObjectField(env, *obj, fid, jstr); - return 0; - } - } - return -1; -} - #else /** @@ -485,9 +556,8 @@ int setString(JNIEnv *env, jobject *obj, char *field, char *string) * the instance is the empty string. The memory for who * that's passed in should be fully allocated in advance. */ -void internal_makeKasIdentity( const char *fullName, - kas_identity_p who ) { - +void internal_makeKasIdentity( const char *fullName, kas_identity_p who ) +{ char *period; if( (period = (char *) strchr( fullName, '.' )) != NULL ) { @@ -499,14 +569,14 @@ void internal_makeKasIdentity( const char *fullName, strcpy( who->principal, fullName); strcpy( who->instance, "" ); } - } /** * Given a Java environment and an instance of a user, gets the object and * field information for the user object from the Java environment. */ -void internal_getUserClass( JNIEnv *env, jobject user ) { +void internal_getUserClass( JNIEnv *env, jobject user ) +{ if( userCls == 0 ) { userCls = (*env)->NewGlobalRef( env, (*env)->GetObjectClass(env, user) ); if( !userCls ) { @@ -595,7 +665,6 @@ void internal_getUserClass( JNIEnv *env, jobject user ) { throwAFSException( env, JAFSADMFIELDNOTFOUND ); return; - } } } @@ -604,7 +673,8 @@ void internal_getUserClass( JNIEnv *env, jobject user ) { * Given a Java environment and an instance of a group, gets the object and * field information for the group object from the Java environment. */ -void internal_getGroupClass( JNIEnv *env, jobject group ) { +void internal_getGroupClass( JNIEnv *env, jobject group ) +{ if( groupCls == 0 ) { groupCls = (*env)->NewGlobalRef( env, (*env)->GetObjectClass(env, group) ); if( !groupCls ) { @@ -643,7 +713,6 @@ void internal_getGroupClass( JNIEnv *env, jobject group ) { throwAFSException( env, JAFSADMFIELDNOTFOUND ); return; - } } } @@ -652,7 +721,8 @@ void internal_getGroupClass( JNIEnv *env, jobject group ) { * Given a Java environment and an instance of a server, gets the object and * field information for the server object from the Java environment. */ -void internal_getServerClass( JNIEnv *env, jobject server ) { +void internal_getServerClass( JNIEnv *env, jobject server ) +{ if( serverCls == 0 ) { serverCls = (*env)->NewGlobalRef( env, (*env)->GetObjectClass(env, server) ); @@ -690,7 +760,8 @@ void internal_getServerClass( JNIEnv *env, jobject server ) { * object and field information for the executableTime object from the * Java environment. */ -void internal_getExecTimeClass( JNIEnv *env, jobject exectime ) { +void internal_getExecTimeClass( JNIEnv *env, jobject exectime ) +{ if( exectimeCls == 0 ) { exectimeCls = (*env)->NewGlobalRef( env, (*env)->GetObjectClass(env, exectime) ); @@ -720,7 +791,8 @@ void internal_getExecTimeClass( JNIEnv *env, jobject exectime ) { * Given a Java environment and an instance of a partition, gets the object and * field information for the partition object from the Java environment. */ -void internal_getPartitionClass( JNIEnv *env, jobject partition ) { +void internal_getPartitionClass( JNIEnv *env, jobject partition ) +{ if( partitionCls == 0 ) { partitionCls = (*env)->NewGlobalRef( env, (*env)->GetObjectClass(env, partition) ); @@ -759,7 +831,8 @@ void internal_getPartitionClass( JNIEnv *env, jobject partition ) { * Given a Java environment and an instance of a volume, gets the object and * field information for the volume object from the Java environment. */ -void internal_getVolumeClass( JNIEnv *env, jobject volume ) { +void internal_getVolumeClass( JNIEnv *env, jobject volume ) +{ if( volumeCls == 0 ) { volumeCls = (*env)->NewGlobalRef( env, (*env)->GetObjectClass(env, volume) ); @@ -823,7 +896,8 @@ void internal_getVolumeClass( JNIEnv *env, jobject volume ) { * Given a Java environment and an instance of a key, gets the object and * field information for the key object from the Java environment. */ -void internal_getKeyClass( JNIEnv *env, jobject key ) { +void internal_getKeyClass( JNIEnv *env, jobject key ) +{ if( keyCls == 0 ) { keyCls = (*env)->NewGlobalRef( env, (*env)->GetObjectClass(env, key) ); if( !keyCls ) { @@ -854,7 +928,8 @@ void internal_getKeyClass( JNIEnv *env, jobject key ) { * Given a Java environment and an instance of a process, gets the object and * field information for the process object from the Java environment. */ -void internal_getProcessClass( JNIEnv *env, jobject process ) { +void internal_getProcessClass( JNIEnv *env, jobject process ) +{ if( processCls == 0 ) { processCls = (*env)->NewGlobalRef( env, (*env)->GetObjectClass(env, process) ); @@ -905,5 +980,3 @@ void internal_getProcessClass( JNIEnv *env, jobject process ) { } #endif /* LIBJUAFS */ - - diff --git a/src/JAVA/libjafs/Internal.h b/src/JAVA/libjafs/Internal.h index 29d9129e41..14b91cd678 100644 --- a/src/JAVA/libjafs/Internal.h +++ b/src/JAVA/libjafs/Internal.h @@ -4,15 +4,32 @@ #include #include "Exceptions.h" -#ifndef LIBJUAFS -#include -#include - -// error codes -#define JAFSADMNOMEM 1050 // Memory problems +/** + * ERROR CODES + * + * Please add any internal error codes to the ErrorMessages.properties + * file located in src/JAVA/classes/ + */ +#define JAFSADMNOMEM 1050 // Memory problems #define JAFSADMCLASSNOTFOUND 1051 // Trouble finding a Java class #define JAFSADMMETHODNOTFOUND 1052 // Trouble finding a Java method #define JAFSADMFIELDNOTFOUND 1053 // Trouble finding a Java field +#define JAFSNULLARG 1054 // Null argument (general) +#define JAFSNULLUSER 1055 // User argument null +#define JAFSNULLPASS 1056 // Password argument null +#define JAFSNULLGROUP 1057 // Group name argument null +#define JAFSNULLOWNER 1058 // Group owner name argument null +#define JAFSNULLVOLUME 1059 // Volume name argument null +#define JAFSNULLPART 1060 // Partition name argument null +#define JAFSNULLPROCESS 1061 // Process name argument null +#define JAFSNULLSERVER 1062 // Server name argument null +#define JAFSNULLCELL 1063 // Cell name argument null +#define JAFSNULLPATH 1064 // Path argument null +#define JAFSNULLACL 1065 // ACL string argument null + +#ifndef LIBJUAFS +#include +#include // make an identity out of a full name (possibly including an instance ) void internal_makeKasIdentity( const char *fullName, kas_identity_p who ); @@ -54,8 +71,9 @@ void throwException( JNIEnv *env, jclass *excCls, char *excClsName, jmethodID *i // reclaim global memory used by exceptions void reclaimExceptionMemory( JNIEnv *env, jclass cls ); -int setError(JNIEnv *env, jobject *obj, int code); -int setString(JNIEnv *env, jobject *obj, char *field, char *string); +int setError (JNIEnv *env, jobject *obj, int code); +int setString(JNIEnv *env, jobject *obj, char *field, char *string); +char* getNativeString(JNIEnv *env, jstring jstr); #endif diff --git a/src/JAVA/libjafs/Key.c b/src/JAVA/libjafs/Key.c index a9ddac94d6..19486f82d6 100644 --- a/src/JAVA/libjafs/Key.c +++ b/src/JAVA/libjafs/Key.c @@ -27,7 +27,7 @@ #include //// definitions in Internal.c ////////////////// -extern jclass keyCls; +extern jclass keyCls; extern jfieldID key_versionField; extern jfieldID key_encryptionKeyField; extern jfieldID key_lastModDateField; @@ -51,7 +51,7 @@ void fillKeyInfo( JNIEnv *env, jobject key, bos_KeyInfo_t keyEntry ) int i; // get the class fields if need be - if( keyCls == 0 ) { + if ( keyCls == 0 ) { internal_getKeyClass( env, key ); } @@ -60,7 +60,7 @@ void fillKeyInfo( JNIEnv *env, jobject key, bos_KeyInfo_t keyEntry ) convertedKey = (char *) malloc( sizeof(char *)* (sizeof(keyEntry.key.key)*4+1) ); - if( !convertedKey ) { + if ( !convertedKey ) { throwAFSException( env, JAFSADMNOMEM ); return; } @@ -100,7 +100,7 @@ Java_org_openafs_jafs_Key_getKeyInfo void *iterationId; int done; - if( !bos_KeyGetBegin( (void *) serverHandle, &iterationId, &ast ) ) { + if ( !bos_KeyGetBegin( (void *) serverHandle, &iterationId, &ast ) ) { throwAFSException( env, ast ); return; } @@ -111,11 +111,11 @@ Java_org_openafs_jafs_Key_getKeyInfo // one with the matching version while( !done ) { - if( !bos_KeyGetNext( iterationId, &keyEntry, &ast ) ) { + if ( !bos_KeyGetNext( iterationId, &keyEntry, &ast ) ) { // no matching key - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { afs_status_t astnew; - if( !bos_KeyGetDone( iterationId, &astnew ) ) { + if ( !bos_KeyGetDone( iterationId, &astnew ) ) { throwAFSException( env, astnew ); return; } @@ -128,7 +128,7 @@ Java_org_openafs_jafs_Key_getKeyInfo } } - if( keyEntry.keyVersionNumber == version ) { + if ( keyEntry.keyVersionNumber == version ) { done = TRUE; } @@ -136,7 +136,7 @@ Java_org_openafs_jafs_Key_getKeyInfo fillKeyInfo( env, key, keyEntry ); - if( !bos_KeyGetDone( iterationId, &ast ) ) { + if ( !bos_KeyGetDone( iterationId, &ast ) ) { throwAFSException( env, ast ); return; } @@ -161,19 +161,20 @@ Java_org_openafs_jafs_Key_create jstring jkeyString) { afs_status_t ast; - const char *keyString; + char *keyString; char *cellName; kas_encryptionKey_p key = (kas_encryptionKey_p) malloc( sizeof(kas_encryptionKey_t) ); - if( !key ) { + if ( !key ) { throwAFSException( env, JAFSADMNOMEM ); return; } - if( jkeyString != NULL ) { - keyString = (*env)->GetStringUTFChars(env, jkeyString, 0); - if( !keyString ) { + if ( jkeyString != NULL ) { + keyString = getNativeString(env, jkeyString); + if ( keyString == NULL ) { + free( key ); throwAFSException( env, JAFSADMNOMEM ); return; } @@ -181,37 +182,29 @@ Java_org_openafs_jafs_Key_create keyString = NULL; } - if( !afsclient_CellNameGet( (void *) cellHandle, &cellName, &ast ) ) { + if ( !afsclient_CellNameGet( (void *) cellHandle, &cellName, &ast ) ) { free( key ); - if( keyString != NULL ) { - (*env)->ReleaseStringUTFChars(env, jkeyString, keyString); - } + if ( keyString != NULL ) free( keyString ); throwAFSException( env, ast ); return; } - if( !kas_StringToKey( cellName, keyString, key, &ast ) ) { + if ( !kas_StringToKey( cellName, keyString, key, &ast ) ) { free( key ); - if( keyString != NULL ) { - (*env)->ReleaseStringUTFChars(env, jkeyString, keyString); - } + if ( keyString != NULL ) free( keyString ); throwAFSException( env, ast ); return; } - if( !bos_KeyCreate( (void *) serverHandle, version, key, &ast ) ) { + if ( !bos_KeyCreate( (void *) serverHandle, version, key, &ast ) ) { free( key ); - if( keyString != NULL ) { - (*env)->ReleaseStringUTFChars(env, jkeyString, keyString); - } + if ( keyString != NULL ) free( keyString ); throwAFSException( env, ast ); return; } free( key ); - if( keyString != NULL ) { - (*env)->ReleaseStringUTFChars(env, jkeyString, keyString); - } + if ( keyString != NULL ) free( keyString ); } /** @@ -226,24 +219,20 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_Key_delete (JNIEnv *env, jclass cls, jint serverHandle, jint version ) { - afs_status_t ast; + afs_status_t ast; - if( !bos_KeyDelete( (void *) serverHandle, version, &ast ) ) { - throwAFSException( env, ast ); - return; - } + if ( !bos_KeyDelete( (void *) serverHandle, version, &ast ) ) { + throwAFSException( env, ast ); + return; + } } // reclaim global memory being used by this portion JNIEXPORT void JNICALL Java_org_openafs_jafs_Key_reclaimKeyMemory (JNIEnv *env, jclass cls) { - if( keyCls ) { - (*env)->DeleteGlobalRef(env, keyCls); - keyCls = 0; + if ( keyCls ) { + (*env)->DeleteGlobalRef(env, keyCls); + keyCls = 0; } } - - - - diff --git a/src/JAVA/libjafs/Makefile.in b/src/JAVA/libjafs/Makefile.in index 9d03a74776..0ae417ce1e 100644 --- a/src/JAVA/libjafs/Makefile.in +++ b/src/JAVA/libjafs/Makefile.in @@ -27,28 +27,36 @@ COMPILE_ET=${TOP_SRCDIR}/comerr/compile_et RXGEN=${TOP_SRCDIR}/rxgen/rxgen SYS_NAME=@AFS_SYSNAME@ +include ../../config/Makefile.${SYS_NAME} CC = ${MT_CC} SHARED_FLAGS = -shared OBJECT_FLAGS = -fPIC -c ifeq "$(BUILD_TYPE)" "admin" - INC := -I${TOP_INCDIR} -I${TOP_INCDIR}/afs/ -I${JAVA_HOME}/include ${JNI_INC} + INC := -I${TOP_INCDIR} -I${TOP_INCDIR}/afs/ ${JNI_INC} CFLAGS := ${INC} ${DBG} ${OPTMZ} -I${TOP_SRCDIR}/config ${MT_CFLAGS} else - INC := -I${TOP_SRCDIR}/libuafs -I${TOP_INCDIR} -I${JAVA_HOME}/include ${JNI_INC} + INC := -I${TOP_SRCDIR}/libuafs -I${TOP_INCDIR} -I${TOP_SRCDIR} ${JNI_INC} CFLAGS := ${INC} ${DBG} ${OPTMZ} ${FSINCLUDES} -D_REENTRANT -DLIBJUAFS ${MT_CFLAGS} endif +ifeq "$(INCREMENT_BUILD)" "false" + INCREMENT_CMD := +else + INCREMENT_CMD := ${RM} -f ${LIBJAFSADMDIR}VersionInfo.o; perl buildinfo.pl ${LIBJAFSADMDIR}VersionInfo.h -i; +endif LIBJAFSADMDIR = ./ ROOTPACKAGEDIR = ../classes RELPACKAGEDIR = org/openafs/jafs/ PACKAGEDIR = ${ROOTPACKAGEDIR}/${RELPACKAGEDIR} -JAVADOCSDIR = javadocs/ +JAVADOCSDIR = ../javadocs/ +BUILD_VERSION = `perl buildinfo.pl ${LIBJAFSADMDIR}VersionInfo.h -version` JAVAH = ${JAVA_HOME}/bin/javah -classpath ${ROOTPACKAGEDIR} -jni -d ${LIBJAFSADMDIR} JAVAC = ${JAVA_HOME}/bin/javac -classpath ${ROOTPACKAGEDIR} +JAVADOC = ${JAVA_HOME}/bin/javadoc J_NATIVE_PREFIX = org.openafs.jafs. C_NATIVE_PREFIX = org_openafs_jafs_ @@ -69,6 +77,7 @@ PACKAGE =\ ${PACKAGEDIR}Server.class \ ${PACKAGEDIR}Token.class \ ${PACKAGEDIR}User.class \ + ${PACKAGEDIR}VersionInfo.class \ ${PACKAGEDIR}Volume.class LIBJAFS_OBJS =\ @@ -77,7 +86,8 @@ LIBJAFS_OBJS =\ ${LIBJAFSADMDIR}FileInputStream.o \ ${LIBJAFSADMDIR}FileOutputStream.o \ ${LIBJAFSADMDIR}Internal.o \ - ${LIBJAFSADMDIR}UserToken.o + ${LIBJAFSADMDIR}UserToken.o \ + ${LIBJAFSADMDIR}VersionInfo.o LIBJAFSADM_OBJS =\ ${LIBJAFSADMDIR}AdminToken.o \ @@ -89,6 +99,7 @@ LIBJAFSADM_OBJS =\ ${LIBJAFSADMDIR}Process.o \ ${LIBJAFSADMDIR}Server.o \ ${LIBJAFSADMDIR}User.o \ + ${LIBJAFSADMDIR}VersionInfo.o \ ${LIBJAFSADMDIR}Volume.o CORRELATING_SOURCE_FILES =\ @@ -103,6 +114,7 @@ CORRELATING_SOURCE_FILES =\ ${LIBJAFSADMDIR}Process.c \ ${LIBJAFSADMDIR}Server.c \ ${LIBJAFSADMDIR}User.c \ + ${LIBJAFSADMDIR}VersionInfo.c \ ${LIBJAFSADMDIR}Volume.c JAVA_HEADERS = ${PACKAGE:${PACKAGEDIR}%.class=${C_NATIVE_PREFIX}%.h} @@ -132,15 +144,14 @@ LIBJAFSADM_LIBS =\ ${TOP_LIBDIR}/libafsauthent.a \ ${TOP_LIBDIR}/libafsrpc.a \ ${TOP_LIBDIR}/libcmd.a \ + ${TOP_LIBDIR}/util.a \ -lresolv \ -lpthread JARFILE = jafs.jar -include ../../config/Makefile.${SYS_NAME} - -all: ${TOP_JLIBDIR} libjafs libjafsadm ${PACKAGE} all_jar +all: ${TOP_JLIBDIR} libjafs libjafsadm ${PACKAGE} jar install: all ${DESTDIR}${libdir}/libjafs.so ${DESTDIR}${libdir}/libjafsadm.so ${PACKAGE} install_jar if [ ! -e /usr/afswsp ]; then \ @@ -163,27 +174,39 @@ install: all ${DESTDIR}${libdir}/libjafs.so ${DESTDIR}${libdir}/libjafsadm.so $ ln -s /usr/vice/etc/ThisCell /usr/afswsp/etc/; \ fi +### Clean "C" and Java objects clean: - ${RM} -f ${PACKAGEDIR}*.class ${LIBJAFSADMDIR}*.o ${LIBJAFSADMDIR}${C_NATIVE_PREFIX}*.h + ${RM} -f ${PACKAGEDIR}*.class ${LIBJAFSADMDIR}*.o ${LIBJAFSADMDIR}${C_NATIVE_PREFIX}*.h ${LIBJAFSADMDIR}acltest + ${RM} -fR ${JAVADOCSDIR} + +### Clean just "C" objects +cleanc: + ${RM} -f ${LIBJAFSADMDIR}*.o ${LIBJAFSADMDIR}acltest + +increment-build: + ${INCREMENT_CMD} \ + export INCREMENT_BUILD=false; setup: FORCE - if [ ! -e ./h ]; then \ - ln -s /usr/include/sys h; \ - fi; \ ${TOP_JLIBDIR}: mkdir -p $@ FORCE: ; +############# Test program ############################### + +acltest: ${LIBJAFSADMDIR}/acltest.c + ${CC} ${CFLAGS} -o $@ $^ ${LIBJAFS_LIBS} + ############# Shared library ############################### -libjafs: setup +libjafs: setup increment-build ${RM} -f ${LIBJAFSADMDIR}Internal.o; \ export BUILD_TYPE=user; \ ${MAKE} ${TOP_LIBDIR}/libjafs.so -libjafsadm: +libjafsadm: increment-build ${RM} -f ${LIBJAFSADMDIR}Internal.o; \ export BUILD_TYPE=admin; \ ${MAKE} ${TOP_LIBDIR}/libjafsadm.so @@ -207,7 +230,7 @@ ${LIBJAFSADM_OBJS}: %.o: %.c ############## C files ##################################### -${CORRELATING_SOURCE_FILES}: ${LIBJAFSADMDIR}%.c: ${LIBJAFSADMDIR}${C_NATIVE_PREFIX}%.h ${LIBJAFSADMDIR}Internal.h +${CORRELATING_SOURCE_FILES}: ${LIBJAFSADMDIR}%.c: ${LIBJAFSADMDIR}${C_NATIVE_PREFIX}%.h ${LIBJAFSADMDIR}Internal.h ${LIBJAFSADMDIR}VersionInfo.h ${LIBJAFSADMDIR}AdminToken.c: ${LIBJAFSADMDIR}${C_NATIVE_PREFIX}Token.h ${LIBJAFSADMDIR}${C_NATIVE_PREFIX}Cell.h @@ -215,6 +238,8 @@ ${LIBJAFSADMDIR}Internal.c: ${LIBJAFSADMDIR}Internal.h ${LIBJAFSADMDIR}UserToken.c: ${LIBJAFSADMDIR}${C_NATIVE_PREFIX}Token.h +${LIBJAFSADMDIR}VersionInfo.c: ${LIBJAFSADMDIR}VersionInfo.h ${LIBJAFSADMDIR}${C_NATIVE_PREFIX}VersionInfo.h + ############## Package javac section ######################### ${PACKAGEDIR}%.class: ${PACKAGEDIR}%.java @@ -225,9 +250,22 @@ ${PACKAGEDIR}%.class: ${PACKAGEDIR}%.java ${JAVA_HEADERS}: ${C_NATIVE_PREFIX}%.h: ${PACKAGEDIR}%.class ${JAVAH} ${J_NATIVE_PREFIX}$* +############## Javadoc section ############################### + +javadocs: + echo "Preparing Javadoc API documentation..." + ${JAVADOC} -version -breakiterator \ + -link http://java.sun.com/j2se/1.4/docs/api/ \ + -windowtitle "Java AFS API" -header "JAFS API v${BUILD_VERSION}" \ + -doctitle "JAFS API v${BUILD_VERSION}" \ + -use -d ${JAVADOCSDIR} \ + -sourcepath ${ROOTPACKAGEDIR} \ + -classpath ${ROOTPACKAGEDIR} \ + -package org.openafs.jafs + ############# JAR file ##################################### -all_jar: clean_jar +jar: clean_jar cd ${ROOTPACKAGEDIR}; ${JAVA_HOME}/bin/jar -cMf ${TOP_JLIBDIR}/${JARFILE} *.properties ${RELPACKAGEDIR}*.class install_jar: clean_jar @@ -236,5 +274,6 @@ install_jar: clean_jar clean_jar: ${RM} -f ${TOP_JLIBDIR}/${JARFILE} - +clean_libs: + ${RM} -f ${TOP_LIBDIR}/libjafs.so ${TOP_LIBDIR}/libjafsadm.so diff --git a/src/JAVA/libjafs/Partition.c b/src/JAVA/libjafs/Partition.c index 6b35c12fc6..14af759440 100644 --- a/src/JAVA/libjafs/Partition.c +++ b/src/JAVA/libjafs/Partition.c @@ -40,7 +40,7 @@ extern jfieldID volume_cachedInfoField; ////////////////////////////////////////////////////////// -///// definition in jafs_Volume.c ///////////////// +///// Definition in jafs_Volume.c ///////////////// extern void fillVolumeInfo ( JNIEnv *env, jobject volume, vos_volumeEntry_t volEntry ); @@ -65,14 +65,14 @@ void fillPartitionInfo afs_status_t ast; // get the class fields if need be - if( partitionCls == 0 ) { + if ( partitionCls == 0 ) { internal_getPartitionClass( env, partition ); } // fill name and id in case it's a blank object jpartition = (*env)->NewStringUTF(env, partEntry.name); // get the id - if( !vos_PartitionNameToId( partEntry.name, (int *) &id, &ast ) ) { + if ( !vos_PartitionNameToId( partEntry.name, (int *) &id, &ast ) ) { throwAFSException( env, ast ); return; } @@ -138,33 +138,28 @@ Java_org_openafs_jafs_Partition_translateNameToID { afs_status_t ast; jint id; - const char *name; + char *name; - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( name == NULL ) { throwAFSException( env, JAFSADMNOMEM ); - return; + return -1; } } else { - name = NULL; + throwAFSException( env, JAFSNULLPART ); + return -1; } // get the id - if( !vos_PartitionNameToId( name, (unsigned int *) &id, &ast ) ) { - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } + if ( !vos_PartitionNameToId( name, (unsigned int *) &id, &ast ) ) { + id = -1; throwAFSException( env, ast ); - return -1; } - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } + free( name ); return id; - } /** @@ -181,24 +176,22 @@ Java_org_openafs_jafs_Partition_translateIDToName { afs_status_t ast; char *name = (char *) malloc( sizeof(char)*VOS_MAX_PARTITION_NAME_LEN); - jstring jname; + jstring jname = NULL; - if( !name ) { + if ( name == NULL ) { throwAFSException( env, JAFSADMNOMEM ); - return; + return NULL; } // get the name - if( !vos_PartitionIdToName( (unsigned int) id, name, &ast ) ) { - free(name); + if ( vos_PartitionIdToName( (unsigned int) id, name, &ast ) ) { + jname = (*env)->NewStringUTF(env, name); + } else { throwAFSException( env, ast ); - return NULL; } + free( name ); - jname = (*env)->NewStringUTF(env, name); - free(name); return jname; - } /** @@ -222,7 +215,7 @@ Java_org_openafs_jafs_Partition_getVolumeCount vos_volumeEntry_t volEntry; int i = 0; - if( !vos_VolumeGetBegin( (void *) cellHandle, (void *) serverHandle, NULL, + if ( !vos_VolumeGetBegin( (void *) cellHandle, (void *) serverHandle, NULL, (unsigned int) partition, &iterationId, &ast ) ) { throwAFSException( env, ast ); return -1; @@ -230,7 +223,7 @@ Java_org_openafs_jafs_Partition_getVolumeCount while ( vos_VolumeGetNext( (void *) iterationId, &volEntry, &ast ) ) i++; - if( ast != ADMITERATORDONE ) { + if ( ast != ADMITERATORDONE ) { throwAFSException( env, ast ); return -1; } @@ -260,10 +253,10 @@ Java_org_openafs_jafs_Partition_getVolumesBegin afs_status_t ast; void *iterationId; - if( !vos_VolumeGetBegin( (void *) cellHandle, (void *) serverHandle, NULL, + if ( !vos_VolumeGetBegin( (void *) cellHandle, (void *) serverHandle, NULL, (unsigned int) partition, &iterationId, &ast ) ) { throwAFSException( env, ast ); - return; + return -1; } return (jint) iterationId; @@ -294,15 +287,15 @@ Java_org_openafs_jafs_Partition_getVolumesBeginAt vos_volumeEntry_t volEntry; int i; - if( !vos_VolumeGetBegin( (void *) cellHandle, (void *) serverHandle, NULL, + if ( !vos_VolumeGetBegin( (void *) cellHandle, (void *) serverHandle, NULL, (unsigned int) partition, &iterationId, &ast ) ) { throwAFSException( env, ast ); - return; + return -1; } for ( i = 1; i < index; i++) { - if( !vos_VolumeGetNext( (void *) iterationId, &volEntry, &ast ) ) { - if( ast == ADMITERATORDONE ) { + if ( !vos_VolumeGetNext( (void *) iterationId, &volEntry, &ast ) ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -332,12 +325,12 @@ Java_org_openafs_jafs_Partition_getVolumesNextString jstring jvolume; vos_volumeEntry_t volEntry; - if( !vos_VolumeGetNext( (void *) iterationId, &volEntry, &ast ) ) { - if( ast == ADMITERATORDONE ) { + if ( !vos_VolumeGetNext( (void *) iterationId, &volEntry, &ast ) ) { + if ( ast == ADMITERATORDONE ) { return NULL; } else { throwAFSException( env, ast ); - return; + return NULL; } } @@ -365,8 +358,8 @@ Java_org_openafs_jafs_Partition_getVolumesNext jstring jvolume; vos_volumeEntry_t volEntry; - if( !vos_VolumeGetNext( (void *) iterationId, &volEntry, &ast ) ) { - if( ast == ADMITERATORDONE ) { + if ( !vos_VolumeGetNext( (void *) iterationId, &volEntry, &ast ) ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -378,7 +371,7 @@ Java_org_openafs_jafs_Partition_getVolumesNext fillVolumeInfo( env, jvolumeObject, volEntry ); // get the class fields if need be - if( volumeCls == 0 ) { + if ( volumeCls == 0 ) { internal_getVolumeClass( env, jvolumeObject ); } (*env)->SetBooleanField( env, jvolumeObject, volume_cachedInfoField, TRUE ); @@ -410,8 +403,8 @@ Java_org_openafs_jafs_Partition_getVolumesAdvanceTo int i; for ( i = 0; i < advanceCount; i++) { - if( !vos_VolumeGetNext( (void *) iterationId, &volEntry, &ast ) ) { - if( ast == ADMITERATORDONE ) { + if ( !vos_VolumeGetNext( (void *) iterationId, &volEntry, &ast ) ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -424,7 +417,7 @@ Java_org_openafs_jafs_Partition_getVolumesAdvanceTo fillVolumeInfo( env, jvolumeObject, volEntry ); // get the class fields if need be - if( volumeCls == 0 ) { + if ( volumeCls == 0 ) { internal_getVolumeClass( env, jvolumeObject ); } (*env)->SetBooleanField( env, jvolumeObject, volume_cachedInfoField, TRUE ); @@ -445,7 +438,7 @@ Java_org_openafs_jafs_Partition_getVolumesDone { afs_status_t ast; - if( !vos_VolumeGetDone( (void *) iterationId, &ast ) ) { + if ( !vos_VolumeGetDone( (void *) iterationId, &ast ) ) { throwAFSException( env, ast ); return; } @@ -456,27 +449,8 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_Partition_reclaimPartitionMemory (JNIEnv *env, jclass cls) { - if( partitionCls ) { - (*env)->DeleteGlobalRef(env, partitionCls); - partitionCls = 0; + if ( partitionCls ) { + (*env)->DeleteGlobalRef(env, partitionCls); + partitionCls = 0; } } - - - - - - - - - - - - - - - - - - - diff --git a/src/JAVA/libjafs/Process.c b/src/JAVA/libjafs/Process.c index 25c0add24f..3da7e69847 100644 --- a/src/JAVA/libjafs/Process.c +++ b/src/JAVA/libjafs/Process.c @@ -26,7 +26,7 @@ ///// definitions in Internal.c //////////////////// -extern jclass processCls; +extern jclass processCls; extern jfieldID process_nameField; extern jfieldID process_typeField; extern jfieldID process_stateField; @@ -52,9 +52,9 @@ extern jfieldID process_stateBadFileAccessField; * processName the name of the process for which to get the info * process the Process object to populate with the info */ -void getProcessInfoChar( JNIEnv *env, void *serverHandle, - const char *processName, jobject process ) { - +void getProcessInfoChar + (JNIEnv *env, void *serverHandle, const char *processName, jobject process) +{ afs_status_t ast; bos_ProcessType_t type; bos_ProcessInfo_t infoEntry; @@ -62,11 +62,11 @@ void getProcessInfoChar( JNIEnv *env, void *serverHandle, char *auxStatus; // get class fields if need be - if( processCls == 0 ) { + if ( processCls == 0 ) { internal_getProcessClass( env, process ); } - if( !bos_ProcessInfoGet( serverHandle, processName, &type, + if ( !bos_ProcessInfoGet( serverHandle, processName, &type, &infoEntry, &ast ) ) { throwAFSException( env, ast ); return; @@ -116,17 +116,18 @@ void getProcessInfoChar( JNIEnv *env, void *serverHandle, // set state variable auxStatus = (char *) malloc( sizeof(char)*BOS_MAX_NAME_LEN ); - if( !auxStatus ) { + if ( !auxStatus ) { throwAFSException( env, JAFSADMNOMEM ); return; } - if( !bos_ProcessExecutionStateGet( (void *) serverHandle, processName, + if ( !bos_ProcessExecutionStateGet( (void *) serverHandle, processName, &state, auxStatus, &ast ) ) { free( auxStatus ); throwAFSException( env, ast ); return; } free( auxStatus ); + switch( state ) { case BOS_PROCESS_STOPPED : (*env)->SetIntField(env, process, process_stateField, @@ -164,14 +165,14 @@ void getProcessInfoChar( JNIEnv *env, void *serverHandle, infoEntry.processErrorSignal ); // set stateOk to true if no core dump - if( infoEntry.state & BOS_PROCESS_CORE_DUMPED ) { + if ( infoEntry.state & BOS_PROCESS_CORE_DUMPED ) { (*env)->SetBooleanField(env, process, process_stateOkField, FALSE ); } else { (*env)->SetBooleanField(env, process, process_stateOkField, TRUE ); } // set stateTooManyErrors - if( infoEntry.state & BOS_PROCESS_TOO_MANY_ERRORS ) { + if ( infoEntry.state & BOS_PROCESS_TOO_MANY_ERRORS ) { (*env)->SetBooleanField(env, process, process_stateTooManyErrorsField, TRUE ); } else { @@ -180,7 +181,7 @@ void getProcessInfoChar( JNIEnv *env, void *serverHandle, } // set stateBadFileAccess - if( infoEntry.state & BOS_PROCESS_BAD_FILE_ACCESS ) { + if ( infoEntry.state & BOS_PROCESS_BAD_FILE_ACCESS ) { (*env)->SetBooleanField(env, process, process_stateBadFileAccessField, TRUE ); } else { @@ -202,34 +203,30 @@ void getProcessInfoChar( JNIEnv *env, void *serverHandle, * in the information */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Process_getProcessInfo (JNIEnv *env, jclass cls, - jint serverHandle, - jstring jname, - jobject process) { +Java_org_openafs_jafs_Process_getProcessInfo + (JNIEnv *env, jclass cls, jint serverHandle, jstring jname, jobject process) +{ + char *name; - const char *name; - - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( name == NULL ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - name = NULL; + throwAFSException( env, JAFSNULLPROCESS ); + return; } getProcessInfoChar( env, (void *) serverHandle, name, process ); // set name in case blank object - if( name != NULL ) { - if( processCls == 0 ) { - internal_getProcessClass( env, process ); - } - (*env)->SetObjectField(env, process, process_nameField, jname); - (*env)->ReleaseStringUTFChars(env, jname, name); + if ( processCls == NULL ) { + internal_getProcessClass( env, process ); } - + (*env)->SetObjectField(env, process, process_nameField, jname); + free( name ); } /** @@ -258,132 +255,91 @@ Java_org_openafs_jafs_Process_getProcessInfo (JNIEnv *env, jclass cls, * null */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Process_create (JNIEnv *env, jclass cls, - jint serverHandle, jstring jname, - jint jtype, jstring jpath, - jstring jcronTime, - jstring jnotifier) { +Java_org_openafs_jafs_Process_create + (JNIEnv *env, jclass cls, jint serverHandle, jstring jname, jint jtype, + jstring jpath, jstring jcronTime, jstring jnotifier) +{ + afs_status_t ast; + bos_ProcessType_t type; + char *name; + char *path; + char *cronTime; + char *notifier; - afs_status_t ast; - bos_ProcessType_t type; - const char *name; - const char *path; - const char *cronTime; - const char *notifier; + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( name == NULL ) { + throwAFSException( env, JAFSADMNOMEM ); + return; + } + } else { + throwAFSException( env, JAFSNULLPROCESS ); + return; + } - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { - throwAFSException( env, JAFSADMNOMEM ); - return; - } - } else { - name = NULL; + if ( jpath != NULL ) { + path = getNativeString(env, jpath); + if ( path == NULL ) { + free( name ); + throwAFSException( env, JAFSADMNOMEM ); + return; } + } else { + path = NULL; + } - if( jpath != NULL ) { - path = (*env)->GetStringUTFChars(env, jpath, 0); - if( !path ) { - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - throwAFSException( env, JAFSADMNOMEM ); - return; - } - } else { - path = NULL; - } + switch( jtype ) { + case org_openafs_jafs_Process_SIMPLE_PROCESS: + type = BOS_PROCESS_SIMPLE; + break; + case org_openafs_jafs_Process_FS_PROCESS: + type = BOS_PROCESS_FS; + break; + case org_openafs_jafs_Process_CRON_PROCESS: + type = BOS_PROCESS_CRON; + break; + default: + free( name ); + if ( path != NULL ) free( path ); + throwAFSException( env, jtype ); + return; + } - switch( jtype ) { - case org_openafs_jafs_Process_SIMPLE_PROCESS: - type = BOS_PROCESS_SIMPLE; - break; - case org_openafs_jafs_Process_FS_PROCESS: - type = BOS_PROCESS_FS; - break; - case org_openafs_jafs_Process_CRON_PROCESS: - type = BOS_PROCESS_CRON; - break; - default: - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - if( path != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpath, path); - } - throwAFSException( env, jtype ); - return; + if ( jcronTime != NULL ) { + cronTime = getNativeString(env, jcronTime); + if ( !cronTime ) { + free( name ); + if ( path != NULL ) free( path ); + throwAFSException( env, JAFSADMNOMEM ); + return; } + } else { + cronTime = NULL; + } - if( jcronTime != NULL ) { - cronTime = (*env)->GetStringUTFChars(env, jcronTime, 0); - if( !cronTime ) { - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - if( path != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpath, path); - } - throwAFSException( env, JAFSADMNOMEM ); - return; - } - } else { - cronTime = NULL; + if ( jnotifier != NULL ) { + notifier = getNativeString(env, jnotifier); + if ( !notifier ) { + free( name ); + if ( path != NULL ) free( path ); + if ( cronTime != NULL ) free( cronTime ); + throwAFSException( env, JAFSADMNOMEM ); + return; } + } else { + notifier = NULL; + } - if( jnotifier != NULL ) { - notifier = (*env)->GetStringUTFChars(env, jnotifier, 0); - if( !notifier ) { - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - if( path != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpath, path); - } - if( cronTime != NULL ) { - (*env)->ReleaseStringUTFChars(env, jcronTime, cronTime); - } - throwAFSException( env, JAFSADMNOMEM ); - return; - } - } else { - notifier = NULL; - } - - if( !bos_ProcessCreate( (void *) serverHandle, name, type, path, - cronTime, notifier, &ast ) ) { - // release strings - if( cronTime != NULL ) { - (*env)->ReleaseStringUTFChars(env, jcronTime, cronTime); - } - if( notifier != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnotifier, notifier); - } - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - if( path != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpath, path); - } - throwAFSException( env, ast ); - return; - } - - - // release strings - if( cronTime != NULL ) { - (*env)->ReleaseStringUTFChars(env, jcronTime, cronTime); - } - if( notifier != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnotifier, notifier); - } - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - if( path != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpath, path); - } + if ( !bos_ProcessCreate( (void *) serverHandle, name, type, path, + cronTime, notifier, &ast ) ) { + throwAFSException( env, ast ); + } + // release strings + free( name ); + if ( path != NULL ) free( path ); + if ( cronTime != NULL ) free( cronTime ); + if ( notifier != NULL ) free( notifier ); } /** @@ -396,34 +352,28 @@ Java_org_openafs_jafs_Process_create (JNIEnv *env, jclass cls, * jname the name of the process to remove */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Process_delete (JNIEnv *env, jclass cls, - jint serverHandle, jstring jname) { +Java_org_openafs_jafs_Process_delete + (JNIEnv *env, jclass cls, jint serverHandle, jstring jname) +{ + afs_status_t ast; + char *name; - afs_status_t ast; - const char *name; - - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { - throwAFSException( env, JAFSADMNOMEM ); - return; - } - } else { - name = NULL; + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( !name ) { + throwAFSException( env, JAFSADMNOMEM ); + return; } + } else { + throwAFSException( env, JAFSNULLPROCESS ); + return; + } - if( !bos_ProcessDelete( (void *) serverHandle, name, &ast ) ) { - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - throwAFSException( env, ast ); - return; - } - - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } + if ( !bos_ProcessDelete( (void *) serverHandle, name, &ast ) ) { + throwAFSException( env, ast ); + } + free( name ); } /** @@ -436,35 +386,29 @@ Java_org_openafs_jafs_Process_delete (JNIEnv *env, jclass cls, * jname the name of the process to stop */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Process_stop (JNIEnv *env, jclass cls, - jint serverHandle, jstring jname) { +Java_org_openafs_jafs_Process_stop + (JNIEnv *env, jclass cls, jint serverHandle, jstring jname) +{ + afs_status_t ast; + char *name; - afs_status_t ast; - const char *name; - - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { - throwAFSException( env, JAFSADMNOMEM ); - return; - } - } else { - name = NULL; + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( !name ) { + throwAFSException( env, JAFSADMNOMEM ); + return; } + } else { + throwAFSException( env, JAFSNULLPROCESS ); + return; + } - if( !bos_ProcessExecutionStateSet( (void *) serverHandle, name, - BOS_PROCESS_STOPPED, &ast ) ) { - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - throwAFSException( env, ast ); - return; - } - - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } + if ( !bos_ProcessExecutionStateSet( (void *) serverHandle, name, + BOS_PROCESS_STOPPED, &ast ) ) { + throwAFSException( env, ast ); + } + free( name ); } /** @@ -477,35 +421,29 @@ Java_org_openafs_jafs_Process_stop (JNIEnv *env, jclass cls, * jname the name of the process to start */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Process_start (JNIEnv *env, jclass cls, - jint serverHandle, jstring jname) { +Java_org_openafs_jafs_Process_start + (JNIEnv *env, jclass cls, jint serverHandle, jstring jname) +{ + afs_status_t ast; + char *name; - afs_status_t ast; - const char *name; - - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { - throwAFSException( env, JAFSADMNOMEM ); - return; - } - } else { - name = NULL; + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( !name ) { + throwAFSException( env, JAFSADMNOMEM ); + return; } + } else { + throwAFSException( env, JAFSNULLPROCESS ); + return; + } - if( !bos_ProcessExecutionStateSet( (void *) serverHandle, name, - BOS_PROCESS_RUNNING, &ast ) ) { - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - throwAFSException( env, ast ); - return; - } - - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } + if ( !bos_ProcessExecutionStateSet( (void *) serverHandle, name, + BOS_PROCESS_RUNNING, &ast ) ) { + throwAFSException( env, ast ); + } + free( name ); } /** @@ -518,50 +456,37 @@ Java_org_openafs_jafs_Process_start (JNIEnv *env, jclass cls, * jname the name of the process to restart */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Process_restart (JNIEnv *env, jclass cls, - jint serverHandle, jstring jname) { +Java_org_openafs_jafs_Process_restart + (JNIEnv *env, jclass cls, jint serverHandle, jstring jname) +{ + afs_status_t ast; + char *name; - afs_status_t ast; - const char *name; - - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { - throwAFSException( env, JAFSADMNOMEM ); - return; - } - } else { - name = NULL; + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( !name ) { + throwAFSException( env, JAFSADMNOMEM ); + return; } + } else { + throwAFSException( env, JAFSNULLPROCESS ); + return; + } - if( !bos_ProcessRestart( (void *) serverHandle, name, &ast ) ) { - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - throwAFSException( env, ast ); - return; - } - - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } + if ( !bos_ProcessRestart( (void *) serverHandle, name, &ast ) ) { + throwAFSException( env, ast ); + } + free( name ); } // reclaim global memory being used by this portion JNIEXPORT void JNICALL -Java_org_openafs_jafs_Process_reclaimProcessMemory (JNIEnv *env, - jclass cls) { - - if( processCls ) { - (*env)->DeleteGlobalRef(env, processCls); - processCls = 0; +Java_org_openafs_jafs_Process_reclaimProcessMemory + (JNIEnv *env, jclass cls) +{ + if ( processCls ) { + (*env)->DeleteGlobalRef(env, processCls); + processCls = 0; } - } - - - - - - diff --git a/src/JAVA/libjafs/Server.c b/src/JAVA/libjafs/Server.c index ce3f504c6e..24bb89427d 100644 --- a/src/JAVA/libjafs/Server.c +++ b/src/JAVA/libjafs/Server.c @@ -102,7 +102,7 @@ void fillServerInfo int i = 0; // get the class fields if need be - if( serverCls == 0 ) { + if ( serverCls == 0 ) { internal_getServerClass( env, server ); } @@ -114,20 +114,19 @@ void fillServerInfo jaddresses = (jobjectArray) (*env)->GetObjectField( env, server, server_IPAddressField ); for (i = 0; i < 16; i++) { - if (servEntry.serverAddress[i] != 0) { - jip = - (*env)->NewStringUTF(env, (char *) - inet_ntoa(htonl(servEntry.serverAddress[i]))); + if (servEntry.serverAddress[i] != 0) { + jip = (*env)->NewStringUTF(env, (char *) + inet_ntoa(htonl(servEntry.serverAddress[i]))); (*env)->SetObjectArrayElement(env, jaddresses, i, jip); - } else { - break; - } + } else { + break; + } } // let's check if this is really a database server (*env)->SetBooleanField(env, server, server_databaseField, servEntry.serverType & DATABASE_SERVER); - if( servEntry.serverType & DATABASE_SERVER ) { + if ( servEntry.serverType & DATABASE_SERVER ) { // for now, if it thinks it's a database server than it is // later, add checks for database configuration, and actual // on-ness of the machine @@ -142,7 +141,7 @@ void fillServerInfo // if it is a file server, mark it as such. If not, mark it as faulty. (*env)->SetBooleanField(env, server, server_fileServerField, servEntry.serverType & FILE_SERVER); - if( servEntry.serverType & FILE_SERVER ) { + if ( servEntry.serverType & FILE_SERVER ) { // to see if it's really a file server, make sure the // "fs" process is running @@ -155,16 +154,16 @@ void fillServerInfo // set the file server to true (it thinks it's a file server) (*env)->SetBooleanField(env, server, server_fileServerField, TRUE); - if( !bos_ServerOpen( (void *) cellHandle, servEntry.serverName, + if ( !bos_ServerOpen( (void *) cellHandle, servEntry.serverName, &bosHandle, &ast ) ) { throwAFSException( env, ast ); return; } - if( !bos_ProcessInfoGet( bosHandle, fileServerProcessName, &processTypeT, + if ( !bos_ProcessInfoGet( bosHandle, fileServerProcessName, &processTypeT, &processInfoT, &ast ) ) { // if the machine does not have a fs process or is not responding // or is part of another cell - if( ast == BZNOENT || ast == -1 || ast == RXKADBADTICKET ) { + if ( ast == BZNOENT || ast == -1 || ast == RXKADBADTICKET ) { (*env)->SetBooleanField(env, server, server_badFileServerField, TRUE); // otherwise } else { @@ -192,40 +191,33 @@ void fillServerInfo * the information */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_getServerInfo (JNIEnv *env, jclass cls, - jint cellHandle, jstring jname, - jobject server) { - - const char *name; +Java_org_openafs_jafs_Server_getServerInfo + (JNIEnv *env, jclass cls, jint cellHandle, jstring jname, jobject server) +{ + char *name; afs_status_t ast; afs_serverEntry_t servEntry; - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( name == NULL ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - name = NULL; + throwAFSException( env, JAFSNULLSERVER ); + return; } // get the server entry if ( !afsclient_AFSServerGet( (void *) cellHandle, name, &servEntry, &ast ) ) { - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } throwAFSException( env, ast ); - return; } fillServerInfo( env, cellHandle, server, servEntry ); - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - + free( name ); } /** @@ -240,16 +232,15 @@ Java_org_openafs_jafs_Server_getServerInfo (JNIEnv *env, jclass cls, * returns total number of partitions */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Server_getPartitionCount (JNIEnv *env, jclass cls, - jint cellHandle, - jint serverHandle) { - +Java_org_openafs_jafs_Server_getPartitionCount + (JNIEnv *env, jclass cls, jint cellHandle, jint serverHandle) +{ afs_status_t ast; void *iterationId; vos_partitionEntry_t partEntry; int i = 0; - if( !vos_PartitionGetBegin( (void *) cellHandle, (void *) serverHandle, + if ( !vos_PartitionGetBegin( (void *) cellHandle, (void *) serverHandle, NULL, &iterationId, &ast ) ) { throwAFSException( env, ast ); return -1; @@ -257,7 +248,7 @@ Java_org_openafs_jafs_Server_getPartitionCount (JNIEnv *env, jclass cls, while ( vos_PartitionGetNext( (void *) iterationId, &partEntry, &ast ) ) i++; - if( ast != ADMITERATORDONE ) { + if ( ast != ADMITERATORDONE ) { throwAFSException( env, ast ); return -1; } @@ -278,14 +269,13 @@ Java_org_openafs_jafs_Server_getPartitionCount (JNIEnv *env, jclass cls, * returns an iteration ID */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Server_getPartitionsBegin (JNIEnv *env, jclass cls, - jint cellHandle, - jint serverHandle) { - +Java_org_openafs_jafs_Server_getPartitionsBegin + (JNIEnv *env, jclass cls, jint cellHandle, jint serverHandle) +{ afs_status_t ast; void *iterationId; - if( !vos_PartitionGetBegin( (void *) cellHandle, (void *) serverHandle, + if ( !vos_PartitionGetBegin( (void *) cellHandle, (void *) serverHandle, NULL, &iterationId, &ast ) ) { throwAFSException( env, ast ); return; @@ -305,16 +295,15 @@ Java_org_openafs_jafs_Server_getPartitionsBegin (JNIEnv *env, jclass cls, * returns the name of the next partition of the server */ JNIEXPORT jstring JNICALL -Java_org_openafs_jafs_Server_getPartitionsNextString (JNIEnv *env, - jclass cls, - jint iterationId) { - +Java_org_openafs_jafs_Server_getPartitionsNextString + (JNIEnv *env, jclass cls, jint iterationId) +{ afs_status_t ast; jstring jpartition; vos_partitionEntry_t partEntry; - if( !vos_PartitionGetNext( (void *) iterationId, &partEntry, &ast ) ) { - if( ast == ADMITERATORDONE ) { + if ( !vos_PartitionGetNext( (void *) iterationId, &partEntry, &ast ) ) { + if ( ast == ADMITERATORDONE ) { return NULL; } else { throwAFSException( env, ast ); @@ -339,15 +328,14 @@ Java_org_openafs_jafs_Server_getPartitionsNextString (JNIEnv *env, * returns 0 if there are no more servers, != 0 otherwise */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Server_getPartitionsNext (JNIEnv *env, jclass cls, - jint iterationId, - jobject jpartitionObject) { - +Java_org_openafs_jafs_Server_getPartitionsNext + (JNIEnv *env, jclass cls, jint iterationId, jobject jpartitionObject) +{ afs_status_t ast; vos_partitionEntry_t partEntry; - if( !vos_PartitionGetNext( (void *) iterationId, &partEntry, &ast ) ) { - if( ast == ADMITERATORDONE ) { + if ( !vos_PartitionGetNext( (void *) iterationId, &partEntry, &ast ) ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -358,7 +346,7 @@ Java_org_openafs_jafs_Server_getPartitionsNext (JNIEnv *env, jclass cls, fillPartitionInfo( env, jpartitionObject, partEntry ); // get the class fields if need be - if( partitionCls == 0 ) { + if ( partitionCls == 0 ) { internal_getPartitionClass( env, jpartitionObject ); } (*env)->SetBooleanField( env, jpartitionObject, partition_cachedInfoField, @@ -377,12 +365,12 @@ Java_org_openafs_jafs_Server_getPartitionsNext (JNIEnv *env, jclass cls, * iterationId the iteration ID of this iteration */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_getPartitionsDone (JNIEnv *env, jclass cls, - jint iterationId) { - +Java_org_openafs_jafs_Server_getPartitionsDone + (JNIEnv *env, jclass cls, jint iterationId) +{ afs_status_t ast; - if( !vos_PartitionGetDone( (void *) iterationId, &ast ) ) { + if ( !vos_PartitionGetDone( (void *) iterationId, &ast ) ) { throwAFSException( env, ast ); return; } @@ -399,35 +387,29 @@ Java_org_openafs_jafs_Server_getPartitionsDone (JNIEnv *env, jclass cls, * jnewAdmin the name of the admin to add to the list */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_addBosAdmin (JNIEnv *env, jclass cls, - jint serverHandle, - jstring jnewAdmin) { - +Java_org_openafs_jafs_Server_addBosAdmin + (JNIEnv *env, jclass cls, jint serverHandle, jstring jnewAdmin) +{ afs_status_t ast; - const char *newAdmin; + char *newAdmin; - if( jnewAdmin != NULL ) { - newAdmin = (*env)->GetStringUTFChars(env, jnewAdmin, 0); - if( !newAdmin ) { + if ( jnewAdmin != NULL ) { + newAdmin = getNativeString(env, jnewAdmin); + if ( newAdmin == NULL ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - newAdmin = NULL; - } - - if( !bos_AdminCreate( (void *) serverHandle, newAdmin, &ast ) ) { - if( newAdmin != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewAdmin, newAdmin); - } - throwAFSException( env, ast ); + throwAFSException( env, JAFSNULLUSER ); return; } - if( newAdmin != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewAdmin, newAdmin); + if ( !bos_AdminCreate( (void *) serverHandle, newAdmin, &ast ) ) { + throwAFSException( env, ast ); } + free( newAdmin ); + } /** @@ -441,35 +423,28 @@ Java_org_openafs_jafs_Server_addBosAdmin (JNIEnv *env, jclass cls, * joldAdmin the name of the admin to remove from the list */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_removeBosAdmin (JNIEnv *env, jclass cls, - jint serverHandle, - jstring joldAdmin) { - +Java_org_openafs_jafs_Server_removeBosAdmin + (JNIEnv *env, jclass cls, jint serverHandle, jstring joldAdmin) +{ afs_status_t ast; - const char *oldAdmin; + char *oldAdmin; - if( joldAdmin != NULL ) { - oldAdmin = (*env)->GetStringUTFChars(env, joldAdmin, 0); - if( !oldAdmin ) { + if ( joldAdmin != NULL ) { + oldAdmin = getNativeString(env, joldAdmin); + if ( oldAdmin == NULL ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - oldAdmin = NULL; - } - - if( !bos_AdminDelete( (void *) serverHandle, oldAdmin, &ast ) ) { - if( oldAdmin != NULL ) { - (*env)->ReleaseStringUTFChars(env, joldAdmin, oldAdmin); - } - throwAFSException( env, ast ); + throwAFSException( env, JAFSNULLUSER ); return; } - if( oldAdmin != NULL ) { - (*env)->ReleaseStringUTFChars(env, joldAdmin, oldAdmin); + if ( !bos_AdminDelete( (void *) serverHandle, oldAdmin, &ast ) ) { + throwAFSException( env, ast ); } + free( oldAdmin ); } /** @@ -483,32 +458,32 @@ Java_org_openafs_jafs_Server_removeBosAdmin (JNIEnv *env, jclass cls, * returns total number of BOS administrators */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Server_getBosAdminCount (JNIEnv *env, jclass cls, - jint serverHandle) { - +Java_org_openafs_jafs_Server_getBosAdminCount + (JNIEnv *env, jclass cls, jint serverHandle) +{ afs_status_t ast; void *iterationId; char *admin; jstring jadmin; int i = 0; - if( !bos_AdminGetBegin( (void *) serverHandle, &iterationId, &ast ) ) { + if ( !bos_AdminGetBegin( (void *) serverHandle, &iterationId, &ast ) ) { throwAFSException( env, ast ); return -1; } admin = (char *) malloc( sizeof(char)*BOS_MAX_NAME_LEN); - if( !admin ) { + if ( !admin ) { throwAFSException( env, JAFSADMNOMEM ); return -1; } while ( bos_AdminGetNext( (void *) iterationId, admin, &ast ) ) i++; - free(admin); + free( admin ); - if( ast != ADMITERATORDONE ) { + if ( ast != ADMITERATORDONE ) { throwAFSException( env, ast ); return -1; } @@ -528,19 +503,18 @@ Java_org_openafs_jafs_Server_getBosAdminCount (JNIEnv *env, jclass cls, * returns an iteration ID */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Server_getBosAdminsBegin (JNIEnv *env, jclass cls, - jint serverHandle) { - +Java_org_openafs_jafs_Server_getBosAdminsBegin + (JNIEnv *env, jclass cls, jint serverHandle) +{ afs_status_t ast; void *iterationId; - if( !bos_AdminGetBegin( (void *) serverHandle, &iterationId, &ast ) ) { + if ( !bos_AdminGetBegin( (void *) serverHandle, &iterationId, &ast ) ) { throwAFSException( env, ast ); return; } return (jint) iterationId; - } /** @@ -553,22 +527,21 @@ Java_org_openafs_jafs_Server_getBosAdminsBegin (JNIEnv *env, jclass cls, * returns the name of the next admin of the server */ JNIEXPORT jstring JNICALL -Java_org_openafs_jafs_Server_getBosAdminsNextString (JNIEnv *env, - jclass cls, - jint iterationId) { +Java_org_openafs_jafs_Server_getBosAdminsNextString + (JNIEnv *env, jclass cls, jint iterationId) { afs_status_t ast; jstring jadmin; char *admin = (char *) malloc( sizeof(char)*BOS_MAX_NAME_LEN ); - if( !admin ) { + if ( !admin ) { throwAFSException( env, JAFSADMNOMEM ); return; } - if( !bos_AdminGetNext( (void *) iterationId, admin, &ast ) ) { - free(admin); - if( ast == ADMITERATORDONE ) { + if ( !bos_AdminGetNext( (void *) iterationId, admin, &ast ) ) { + free( admin ); + if ( ast == ADMITERATORDONE ) { return NULL; } else { throwAFSException( env, ast ); @@ -577,7 +550,7 @@ Java_org_openafs_jafs_Server_getBosAdminsNextString (JNIEnv *env, } jadmin = (*env)->NewStringUTF(env, admin); - free(admin); + free( admin ); return jadmin; } @@ -594,25 +567,24 @@ Java_org_openafs_jafs_Server_getBosAdminsNextString (JNIEnv *env, * returns 0 if no more admins, != 0 otherwise */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Server_getBosAdminsNext (JNIEnv *env, jclass cls, - jint cellHandle, - jint iterationId, - jobject juserObject ) { - +Java_org_openafs_jafs_Server_getBosAdminsNext + (JNIEnv *env, jclass cls, jint cellHandle, jint iterationId, + jobject juserObject ) +{ afs_status_t ast; char *admin; jstring jadmin; admin = (char *) malloc( sizeof(char)*BOS_MAX_NAME_LEN); - if( !admin ) { + if ( !admin ) { throwAFSException( env, JAFSADMNOMEM ); return; } - if( !bos_AdminGetNext( (void *) iterationId, admin, &ast ) ) { + if ( !bos_AdminGetNext( (void *) iterationId, admin, &ast ) ) { free( admin ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -622,7 +594,7 @@ Java_org_openafs_jafs_Server_getBosAdminsNext (JNIEnv *env, jclass cls, jadmin = (*env)->NewStringUTF(env, admin); - if( userCls == 0 ) { + if ( userCls == 0 ) { internal_getUserClass( env, juserObject ); } @@ -644,16 +616,15 @@ Java_org_openafs_jafs_Server_getBosAdminsNext (JNIEnv *env, jclass cls, * iterationId the iteration ID of this iteration */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_getBosAdminsDone (JNIEnv *env, jclass cls, - jint iterationId) { - +Java_org_openafs_jafs_Server_getBosAdminsDone + (JNIEnv *env, jclass cls, jint iterationId) +{ afs_status_t ast; - if( !bos_AdminGetDone( (void *) iterationId, &ast ) ) { + if ( !bos_AdminGetDone( (void *) iterationId, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -667,22 +638,22 @@ Java_org_openafs_jafs_Server_getBosAdminsDone (JNIEnv *env, jclass cls, * returns total number of keys */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Server_getKeyCount (JNIEnv *env, jclass cls, - jint serverHandle) { - +Java_org_openafs_jafs_Server_getKeyCount + (JNIEnv *env, jclass cls, jint serverHandle) +{ afs_status_t ast; void *iterationId; bos_KeyInfo_t keyEntry; int i = 0; - if( !bos_KeyGetBegin( (void *) serverHandle, &iterationId, &ast ) ) { + if ( !bos_KeyGetBegin( (void *) serverHandle, &iterationId, &ast ) ) { throwAFSException( env, ast ); return -1; } while ( bos_KeyGetNext( (void *) iterationId, &keyEntry, &ast ) ) i++; - if( ast != ADMITERATORDONE ) { + if ( ast != ADMITERATORDONE ) { throwAFSException( env, ast ); return -1; } @@ -701,19 +672,18 @@ Java_org_openafs_jafs_Server_getKeyCount (JNIEnv *env, jclass cls, * returns an iteration ID */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Server_getKeysBegin (JNIEnv *env, jclass cls, - jint serverHandle) { - +Java_org_openafs_jafs_Server_getKeysBegin + (JNIEnv *env, jclass cls, jint serverHandle) +{ afs_status_t ast; void *iterationId; - if( !bos_KeyGetBegin( (void *) serverHandle, &iterationId, &ast ) ) { + if ( !bos_KeyGetBegin( (void *) serverHandle, &iterationId, &ast ) ) { throwAFSException( env, ast ); return; } return (jint) iterationId; - } /** @@ -728,15 +698,15 @@ Java_org_openafs_jafs_Server_getKeysBegin (JNIEnv *env, jclass cls, * returns 0 if there are no more keys, != 0 otherwise */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Server_getKeysNext (JNIEnv *env, jclass cls, - jint iterationId, - jobject jkeyObject) { +Java_org_openafs_jafs_Server_getKeysNext + (JNIEnv *env, jclass cls, jint iterationId, jobject jkeyObject) +{ afs_status_t ast; bos_KeyInfo_t keyEntry; - if( !bos_KeyGetNext( (void *) iterationId, &keyEntry, &ast ) ) { - if( ast == ADMITERATORDONE ) { + if ( !bos_KeyGetNext( (void *) iterationId, &keyEntry, &ast ) ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -747,14 +717,13 @@ Java_org_openafs_jafs_Server_getKeysNext (JNIEnv *env, jclass cls, fillKeyInfo( env, jkeyObject, keyEntry ); // get the class fields if need be - if( keyCls == 0 ) { + if ( keyCls == 0 ) { internal_getKeyClass( env, jkeyObject ); } (*env)->SetBooleanField( env, jkeyObject, key_cachedInfoField, TRUE ); return 1; - } /** @@ -765,16 +734,15 @@ Java_org_openafs_jafs_Server_getKeysNext (JNIEnv *env, jclass cls, * iterationId the iteration ID of this iteration */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_getKeysDone (JNIEnv *env, jclass cls, - jint iterationId) { - +Java_org_openafs_jafs_Server_getKeysDone + (JNIEnv *env, jclass cls, jint iterationId) +{ afs_status_t ast; - if( !bos_KeyGetDone( (void *) iterationId, &ast ) ) { + if ( !bos_KeyGetDone( (void *) iterationId, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -788,23 +756,23 @@ Java_org_openafs_jafs_Server_getKeysDone (JNIEnv *env, jclass cls, * returns total number of processes */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Server_getProcessCount (JNIEnv *env, jclass cls, - jint serverHandle) { - +Java_org_openafs_jafs_Server_getProcessCount + (JNIEnv *env, jclass cls, jint serverHandle) +{ afs_status_t ast; void *iterationId; char *process; jstring jprocess; int i = 0; - if( !bos_ProcessNameGetBegin( (void *) serverHandle, &iterationId, &ast ) ) { + if ( !bos_ProcessNameGetBegin( (void *) serverHandle, &iterationId, &ast ) ) { throwAFSException( env, ast ); return -1; } process = (char *) malloc( sizeof(char)*BOS_MAX_NAME_LEN ); - if( !process ) { + if ( !process ) { throwAFSException( env, JAFSADMNOMEM ); return -1; } @@ -813,7 +781,7 @@ Java_org_openafs_jafs_Server_getProcessCount (JNIEnv *env, jclass cls, free( process ); - if( ast != ADMITERATORDONE ) { + if ( ast != ADMITERATORDONE ) { throwAFSException( env, ast ); return -1; } @@ -833,19 +801,18 @@ Java_org_openafs_jafs_Server_getProcessCount (JNIEnv *env, jclass cls, * returns an iteration ID */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Server_getProcessesBegin (JNIEnv *env, jclass cls, - jint serverHandle) { - +Java_org_openafs_jafs_Server_getProcessesBegin + (JNIEnv *env, jclass cls, jint serverHandle) +{ afs_status_t ast; void *iterationId; - if( !bos_ProcessNameGetBegin( (void *) serverHandle, &iterationId, &ast ) ) { + if ( !bos_ProcessNameGetBegin( (void *) serverHandle, &iterationId, &ast ) ) { throwAFSException( env, ast ); return; } return (jint) iterationId; - } /** @@ -858,22 +825,21 @@ Java_org_openafs_jafs_Server_getProcessesBegin (JNIEnv *env, jclass cls, * returns the name of the next process of the cell */ JNIEXPORT jstring JNICALL -Java_org_openafs_jafs_Server_getProcessesNextString (JNIEnv *env, - jclass cls, - jint iterationId) { - +Java_org_openafs_jafs_Server_getProcessesNextString + (JNIEnv *env, jclass cls, jint iterationId) +{ afs_status_t ast; jstring jprocess; char *process = (char *) malloc( sizeof(char)*BOS_MAX_NAME_LEN ); - if( !process ) { + if ( !process ) { throwAFSException( env, JAFSADMNOMEM ); return; } - if( !bos_ProcessNameGetNext( (void *) iterationId, process, &ast ) ) { + if ( !bos_ProcessNameGetNext( (void *) iterationId, process, &ast ) ) { free( process ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return NULL; } else { throwAFSException( env, ast ); @@ -884,7 +850,6 @@ Java_org_openafs_jafs_Server_getProcessesNextString (JNIEnv *env, jprocess = (*env)->NewStringUTF(env, process); free( process ); return jprocess; - } /** @@ -900,32 +865,31 @@ Java_org_openafs_jafs_Server_getProcessesNextString (JNIEnv *env, * returns 0 if there are no more processes, != otherwise */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Server_getProcessesNext (JNIEnv *env, jclass cls, - jint serverHandle, - jint iterationId, - jobject jprocessObject) { - +Java_org_openafs_jafs_Server_getProcessesNext + (JNIEnv *env, jclass cls, jint serverHandle, jint iterationId, + jobject jprocessObject) +{ afs_status_t ast; char *process = (char *) malloc( sizeof(char)*BOS_MAX_NAME_LEN ); jstring jprocess; - if( !process ) { + if ( !process ) { throwAFSException( env, JAFSADMNOMEM ); return; } - if( !bos_ProcessNameGetNext( (void *) iterationId, process, &ast ) ) { - if( ast == ADMITERATORDONE ) { + if ( !bos_ProcessNameGetNext( (void *) iterationId, process, &ast ) ) { + free( process ); + if ( ast == ADMITERATORDONE ) { return 0; } else { - free( process ); throwAFSException( env, ast ); return 0; } } // get the class fields if need be - if( processCls == 0 ) { + if ( processCls == 0 ) { internal_getProcessClass( env, jprocessObject ); } @@ -939,7 +903,6 @@ Java_org_openafs_jafs_Server_getProcessesNext (JNIEnv *env, jclass cls, free( process ); return 1; - } /** @@ -950,16 +913,15 @@ Java_org_openafs_jafs_Server_getProcessesNext (JNIEnv *env, jclass cls, * iterationId the iteration ID of this iteration */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_getProcessesDone (JNIEnv *env, jclass cls, - jint iterationId) { - +Java_org_openafs_jafs_Server_getProcessesDone + (JNIEnv *env, jclass cls, jint iterationId) +{ afs_status_t ast; - if( !bos_ProcessNameGetDone( (void *) iterationId, &ast ) ) { + if ( !bos_ProcessNameGetDone( (void *) iterationId, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -995,23 +957,27 @@ Java_org_openafs_jafs_Server_getProcessesDone (JNIEnv *env, jclass cls, * blocks. Use if partition has disk errors */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_salvage (JNIEnv *env, jclass cls, - jint cellHandle, jint serverHandle, - jstring jpartName, jstring jvolName, - jint numSalvagers, jstring jtempDir, - jstring jlogFile, - jboolean inspectAllVolumes, - jboolean removeBadlyDamaged, - jboolean writeInodes, - jboolean writeRootInodes, - jboolean forceDirectory, - jboolean forceBlockReads) { - +Java_org_openafs_jafs_Server_salvage + (JNIEnv *env, jclass cls, + jint cellHandle, + jint serverHandle, + jstring jpartName, + jstring jvolName, + jint numSalvagers, + jstring jtempDir, + jstring jlogFile, + jboolean inspectAllVolumes, + jboolean removeBadlyDamaged, + jboolean writeInodes, + jboolean writeRootInodes, + jboolean forceDirectory, + jboolean forceBlockReads) +{ afs_status_t ast; - const char *partName; - const char *volName; - const char *tempDir; - const char *logFile; + char *partName; + char *volName; + char *tempDir; + char *logFile; vos_force_t force; bos_SalvageDamagedVolumes_t sdv; bos_WriteInodes_t wi; @@ -1020,54 +986,45 @@ Java_org_openafs_jafs_Server_salvage (JNIEnv *env, jclass cls, bos_ForceBlockRead_t forceBR; // convert strings - if( jpartName != NULL ) { - partName = (*env)->GetStringUTFChars(env, jpartName, 0); - if( !partName ) { + if ( jpartName != NULL ) { + partName = getNativeString(env, jpartName); + if ( !partName ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { partName = NULL; } - if( jvolName != NULL ) { - volName = (*env)->GetStringUTFChars(env, jvolName, 0); - if( !volName ) { - if( partName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpartName, partName); - } + + if ( jvolName != NULL ) { + volName = getNativeString(env, jvolName); + if ( !volName ) { + if ( partName != NULL ) free( partName ); throwAFSException( env, JAFSADMNOMEM ); return; } } else { volName = NULL; } - if( jtempDir != NULL ) { - tempDir = (*env)->GetStringUTFChars(env, jtempDir, 0); - if( !tempDir ) { - if( partName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpartName, partName); - } - if( volName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jvolName, volName); - } + + if ( jtempDir != NULL ) { + tempDir = getNativeString(env, jtempDir); + if ( !tempDir ) { + if ( partName != NULL ) free( partName ); + if ( volName != NULL ) free( volName ); throwAFSException( env, JAFSADMNOMEM ); return; } } else { tempDir = NULL; } - if( jlogFile != NULL ) { - logFile = (*env)->GetStringUTFChars(env, jlogFile, 0); - if( !logFile ) { - if( partName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpartName, partName); - } - if( volName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jvolName, volName); - } - if( tempDir != NULL ) { - (*env)->ReleaseStringUTFChars(env, jtempDir, tempDir); - } + + if ( jlogFile != NULL ) { + logFile = getNativeString(env, jlogFile); + if ( !logFile ) { + if ( partName != NULL ) free( partName ); + if ( volName != NULL ) free( volName ); + if ( tempDir != NULL ) free( tempDir ); throwAFSException( env, JAFSADMNOMEM ); return; } @@ -1076,70 +1033,49 @@ Java_org_openafs_jafs_Server_salvage (JNIEnv *env, jclass cls, } // deal with booleans - if( inspectAllVolumes ) { + if ( inspectAllVolumes ) { force = VOS_FORCE; } else { force = VOS_NORMAL; } - if( removeBadlyDamaged ) { + if ( removeBadlyDamaged ) { sdv = BOS_DONT_SALVAGE_DAMAGED_VOLUMES; } else { sdv = BOS_SALVAGE_DAMAGED_VOLUMES; } - if( writeInodes ) { + if ( writeInodes ) { wi = BOS_SALVAGE_WRITE_INODES; } else { wi = BOS_SALVAGE_DONT_WRITE_INODES; } - if( writeRootInodes ) { + if ( writeRootInodes ) { wri = BOS_SALVAGE_WRITE_ROOT_INODES; } else { wri = BOS_SALVAGE_DONT_WRITE_ROOT_INODES; } - if( forceDirectory ) { + if ( forceDirectory ) { forceD = BOS_SALVAGE_FORCE_DIRECTORIES; } else { forceD = BOS_SALVAGE_DONT_FORCE_DIRECTORIES; } - if( forceBlockReads ) { + if ( forceBlockReads ) { forceBR = BOS_SALVAGE_FORCE_BLOCK_READS; } else { forceBR = BOS_SALVAGE_DONT_FORCE_BLOCK_READS; } //salvage! - if( !bos_Salvage( (void *) cellHandle, (void *) serverHandle, partName, + if ( !bos_Salvage( (void *) cellHandle, (void *) serverHandle, partName, volName, (int) numSalvagers, tempDir, logFile, force, sdv, wi, wri, forceD, forceBR, &ast ) ) { - if( partName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpartName, partName); - } - if( volName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jvolName, volName); - } - if( tempDir != NULL ) { - (*env)->ReleaseStringUTFChars(env, jtempDir, tempDir); - } - if( logFile != NULL ) { - (*env)->ReleaseStringUTFChars(env, jlogFile, logFile); - } throwAFSException( env, ast ); - return; } // release strings - if( partName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpartName, partName); - } - if( volName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jvolName, volName); - } - if( tempDir != NULL ) { - (*env)->ReleaseStringUTFChars(env, jtempDir, tempDir); - } - if( logFile != NULL ) { - (*env)->ReleaseStringUTFChars(env, jlogFile, logFile); - } + if ( partName != NULL ) free( partName ); + if ( volName != NULL ) free( volName ); + if ( tempDir != NULL ) free( tempDir ); + if ( logFile != NULL ) free( logFile ); } @@ -1172,11 +1108,11 @@ Java_org_openafs_jafs_Server_getRestartTime jfieldID nowField; // get the class fields if need be - if( exectimeCls == 0 ) { + if ( exectimeCls == 0 ) { internal_getExecTimeClass( env, exectime ); } - if( jtype == org_openafs_jafs_Server_RESTART_BINARY ) { + if ( jtype == org_openafs_jafs_Server_RESTART_BINARY ) { type = BOS_RESTART_DAILY; } else { type = BOS_RESTART_WEEKLY; @@ -1189,7 +1125,7 @@ Java_org_openafs_jafs_Server_getRestartTime neverField = exectime_NeverField; nowField = exectime_NowField; - if( !bos_ExecutableRestartTimeGet( (void *) serverHandle, type, + if ( !bos_ExecutableRestartTimeGet( (void *) serverHandle, type, &time, &ast ) ) { throwAFSException( env, ast ); return; @@ -1213,7 +1149,7 @@ Java_org_openafs_jafs_Server_getRestartTime (*env)->SetShortField(env, exectime, secField, time.sec ); // set day - if( time.mask & BOS_RESTART_TIME_DAY ) { + if ( time.mask & BOS_RESTART_TIME_DAY ) { (*env)->SetShortField(env, exectime, dayField, time.day ); } else { (*env)->SetShortField(env, exectime, dayField, (jshort) -1 ); @@ -1235,10 +1171,9 @@ Java_org_openafs_jafs_Server_getRestartTime * desired information */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_setRestartTime (JNIEnv *env, jclass cls, - jint serverHandle, jint jtype, - jobject exectime ) { - +Java_org_openafs_jafs_Server_setRestartTime + (JNIEnv *env, jclass cls, jint serverHandle, jint jtype, jobject exectime ) +{ afs_status_t ast; bos_Restart_t type; bos_RestartTime_t time; @@ -1260,11 +1195,11 @@ Java_org_openafs_jafs_Server_setRestartTime (JNIEnv *env, jclass cls, jfieldID nowField; // get the class fields if need be - if( exectimeCls == 0 ) { + if ( exectimeCls == 0 ) { internal_getExecTimeClass( env, exectime ); } - if( jtype == org_openafs_jafs_Server_RESTART_BINARY ) { + if ( jtype == org_openafs_jafs_Server_RESTART_BINARY ) { type = BOS_RESTART_DAILY; } else { type = BOS_RESTART_WEEKLY; @@ -1278,25 +1213,25 @@ Java_org_openafs_jafs_Server_setRestartTime (JNIEnv *env, jclass cls, nowField = exectime_NowField; hour = (*env)->GetShortField(env, exectime, hourField ); - if( hour != 0 ) { + if ( hour != 0 ) { doHour = TRUE; } else { doHour = FALSE; } minute = (*env)->GetShortField(env, exectime, minField ); - if( minute != 0 ) { + if ( minute != 0 ) { doMinute = TRUE; } else { doMinute = FALSE; } second = (*env)->GetShortField(env, exectime, secField ); - if( second != 0 ) { + if ( second != 0 ) { doSecond = TRUE; } else { doSecond = FALSE; } day = (*env)->GetShortField(env, exectime, dayField ); - if( day != -1 ) { + if ( day != -1 ) { doDay = TRUE; } else { doDay = FALSE; @@ -1306,28 +1241,28 @@ Java_org_openafs_jafs_Server_setRestartTime (JNIEnv *env, jclass cls, bzero(&time, sizeof(time)); - if( jtype == org_openafs_jafs_Server_RESTART_BINARY ) { + if ( jtype == org_openafs_jafs_Server_RESTART_BINARY ) { type = BOS_RESTART_DAILY; } else { type = BOS_RESTART_WEEKLY; } - if( doHour ) { + if ( doHour ) { time.mask |= BOS_RESTART_TIME_HOUR; } - if( doMinute ) { + if ( doMinute ) { time.mask |= BOS_RESTART_TIME_MINUTE; } - if( doSecond ) { + if ( doSecond ) { time.mask |= BOS_RESTART_TIME_SECOND; } - if( doDay ) { + if ( doDay ) { time.mask |= BOS_RESTART_TIME_DAY; } - if( doNever ) { + if ( doNever ) { time.mask |= BOS_RESTART_TIME_NEVER; } - if( doNow ) { + if ( doNow ) { time.mask |= BOS_RESTART_TIME_NOW; } @@ -1336,12 +1271,10 @@ Java_org_openafs_jafs_Server_setRestartTime (JNIEnv *env, jclass cls, time.sec = second; time.day = day; - if( !bos_ExecutableRestartTimeSet( (void *) serverHandle, type, + if ( !bos_ExecutableRestartTimeSet( (void *) serverHandle, type, time, &ast ) ) { throwAFSException( env, ast ); - return; } - } /** @@ -1354,26 +1287,22 @@ Java_org_openafs_jafs_Server_setRestartTime (JNIEnv *env, jclass cls, * partition the id of the partition to sync, can be -1 to ignore */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_syncServerWithVLDB (JNIEnv *env, jclass cls, - jint cellHandle, - jint serverHandle, - jint partition) { - +Java_org_openafs_jafs_Server_syncServerWithVLDB + (JNIEnv *env, jclass cls, jint cellHandle, jint serverHandle, jint partition) +{ afs_status_t ast; int *part; - if( partition == -1 ) { + if ( partition == -1 ) { part = NULL; } else { part = (int *) &partition; } - if( !vos_ServerSync( (void *) cellHandle, (void *) serverHandle, + if ( !vos_ServerSync( (void *) cellHandle, (void *) serverHandle, NULL, part, &ast ) ) { throwAFSException( env, ast ); - return; } - } /** @@ -1387,34 +1316,30 @@ Java_org_openafs_jafs_Server_syncServerWithVLDB (JNIEnv *env, jclass cls, * forceDeletion whether or not to force the deletion of bad volumes */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_syncVLDBWithServer (JNIEnv *env, jclass cls, - jint cellHandle, - jint serverHandle, - jint partition, - jboolean forceDeletion) { - +Java_org_openafs_jafs_Server_syncVLDBWithServer + (JNIEnv *env, jclass cls, jint cellHandle, jint serverHandle, jint partition, + jboolean forceDeletion) +{ afs_status_t ast; int *part; vos_force_t force; - if( partition == -1 ) { + if ( partition == -1 ) { part = NULL; } else { part = (int *) &partition; } - if( forceDeletion ) { + if ( forceDeletion ) { force = VOS_FORCE; } else { force = VOS_NORMAL; } - if( !vos_VLDBSync( (void *) cellHandle, (void *) serverHandle, NULL, part, + if ( !vos_VLDBSync( (void *) cellHandle, (void *) serverHandle, NULL, part, force, &ast ) ) { throwAFSException( env, ast ); - return; } - } /** @@ -1426,16 +1351,15 @@ Java_org_openafs_jafs_Server_syncVLDBWithServer (JNIEnv *env, jclass cls, * processes belong */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_startAllProcesses (JNIEnv *env, jclass cls, - jint serverHandle) { - +Java_org_openafs_jafs_Server_startAllProcesses + (JNIEnv *env, jclass cls, jint serverHandle) +{ afs_status_t ast; - if( !bos_ProcessAllStart( (void *) serverHandle, &ast ) ) { + if ( !bos_ProcessAllStart( (void *) serverHandle, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -1447,16 +1371,15 @@ Java_org_openafs_jafs_Server_startAllProcesses (JNIEnv *env, jclass cls, * processes belong */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_stopAllProcesses (JNIEnv *env, jclass cls, - jint serverHandle) { - +Java_org_openafs_jafs_Server_stopAllProcesses + (JNIEnv *env, jclass cls, jint serverHandle) +{ afs_status_t ast; - if( !bos_ProcessAllStop( (void *) serverHandle, &ast ) ) { + if ( !bos_ProcessAllStop( (void *) serverHandle, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -1469,24 +1392,22 @@ Java_org_openafs_jafs_Server_stopAllProcesses (JNIEnv *env, jclass cls, * restartBosServer whether or not to restart the bos server as well */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_restartAllProcesses (JNIEnv *env, jclass cls, - jint serverHandle, - jboolean restartBosServer) { - +Java_org_openafs_jafs_Server_restartAllProcesses + (JNIEnv *env, jclass cls, jint serverHandle, jboolean restartBosServer) +{ afs_status_t ast; bos_RestartBosServer_t rbs; - if( restartBosServer ) { + if ( restartBosServer ) { rbs = BOS_RESTART_BOS_SERVER; } else { rbs = BOS_DONT_RESTART_BOS_SERVER; } - if( !bos_ProcessAllStopAndRestart( (void *) serverHandle, rbs, &ast ) ) { + if ( !bos_ProcessAllStopAndRestart( (void *) serverHandle, rbs, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -1500,88 +1421,79 @@ Java_org_openafs_jafs_Server_restartAllProcesses (JNIEnv *env, jclass cls, * jlogFile the full path and name of the desired bos log */ JNIEXPORT jstring JNICALL -Java_org_openafs_jafs_Server_getLog(JNIEnv *env, jclass cls, - jint serverHandle, jstring jlogFile) { +Java_org_openafs_jafs_Server_getLog + (JNIEnv *env, jclass cls, jint serverHandle, jstring jlogFile) +{ + afs_status_t ast; + char *logFile; + char *logData; + unsigned long currInLogSize = 1; + unsigned long currOutLogSize = 0; + jstring logOut; - afs_status_t ast; - const char *logFile; - char *logData; - unsigned long currInLogSize = 1; - unsigned long currOutLogSize = 0; - jstring logOut; + logData = (char *) malloc( sizeof(char)*currInLogSize ); + if ( logData == NULL ) { + throwAFSException( env, JAFSADMNOMEM ); + return NULL; + } - if( jlogFile != NULL ) { - logFile = (*env)->GetStringUTFChars(env, jlogFile, 0); - if( !logFile ) { - throwAFSException( env, JAFSADMNOMEM ); - return; - } - } else { - logFile = NULL; - } - - logData = (char *) malloc( sizeof(char)*currInLogSize ); - if( !logData ) { + if ( jlogFile != NULL ) { + logFile = getNativeString(env, jlogFile); + if ( logFile == NULL ) { + free( logData ); throwAFSException( env, JAFSADMNOMEM ); - return; + return NULL; } - - // check how big the log is . . . - if( !bos_LogGet( (void *) serverHandle, logFile, - &currOutLogSize, logData, &ast ) ) { - // anything but not enough room in buffer - if( ast != ADMMOREDATA ) { - free( logData ); - if( logFile != NULL ) { - (*env)->ReleaseStringUTFChars(env, jlogFile, logFile); - } - throwAFSException( env, ast ); - return NULL; - } - } - + } else { free( logData ); + throwAFSException( env, JAFSNULLARG ); + return NULL; + } - // increase log size (plus one for terminator) - currInLogSize = currOutLogSize + 1; - // allocate buffer - logData = (char *) malloc( sizeof(char)*currInLogSize ); - if( !logData ) { - throwAFSException( env, JAFSADMNOMEM ); - return; - } - - if( !logData ) { - // memory exception - if( logFile != NULL ) { - (*env)->ReleaseStringUTFChars(env, jlogFile, logFile); - } + // check how big the log is . . . + if ( !bos_LogGet( (void *) serverHandle, logFile, + &currOutLogSize, logData, &ast ) ) { + // anything but not enough room in buffer + if ( ast != ADMMOREDATA ) { + free( logData ); + free( logFile ); throwAFSException( env, ast ); return NULL; } + } - // get the log for real - if( !bos_LogGet( (void *) serverHandle, logFile, &currOutLogSize, - logData, &ast ) ) { - free( logData ); - if( logFile != NULL ) { - (*env)->ReleaseStringUTFChars(env, jlogFile, logFile); - } - (*env)->ReleaseStringUTFChars(env, jlogFile, logFile); - throwAFSException( env, ast ); - return NULL; - } - - logData[currOutLogSize] == '\0'; + // free previous allocation + free( logData ); - logOut = (*env)->NewStringUTF(env, logData); - + // increase log size (plus one for terminator) + currInLogSize = currOutLogSize + 1; + + // allocate buffer + logData = (char *) malloc( sizeof(char)*currInLogSize ); + if ( logData == NULL ) { + free( logFile ); + throwAFSException( env, JAFSADMNOMEM ); + return NULL; + } + + // get the log for real + if ( !bos_LogGet( (void *) serverHandle, logFile, &currOutLogSize, + logData, &ast ) ) { free( logData ); - if( logFile != NULL ) { - (*env)->ReleaseStringUTFChars(env, jlogFile, logFile); - } - return logOut; + free( logFile ); + throwAFSException( env, ast ); + return NULL; + } + + // NULL-terminate + logData[currOutLogSize] == '\0'; + logOut = (*env)->NewStringUTF(env, logData); + + free( logData ); + free( logFile ); + + return logOut; } @@ -1594,64 +1506,37 @@ Java_org_openafs_jafs_Server_getLog(JNIEnv *env, jclass cls, * jcommand the text of the commmand to execute */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_executeCommand (JNIEnv *env, jclass cls, - jint serverHandle, - jstring jcommand) { - +Java_org_openafs_jafs_Server_executeCommand + (JNIEnv *env, jclass cls, jint serverHandle, jstring jcommand) +{ afs_status_t ast; - const char *command; + char *command; - if( jcommand != NULL ) { - command = (*env)->GetStringUTFChars(env, jcommand, 0); - if( !command ) { + if ( jcommand != NULL ) { + command = getNativeString(env, jcommand); + if ( command == NULL ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - command = NULL; - } - - if( !bos_CommandExecute( (void *) serverHandle, command, &ast ) ) { - if( command != NULL ) { - (*env)->ReleaseStringUTFChars(env, jcommand, command); - } - throwAFSException( env, ast ); + throwAFSException( env, JAFSNULLARG ); return; } - if( command != NULL ) { - (*env)->ReleaseStringUTFChars(env, jcommand, command); + if ( !bos_CommandExecute( (void *) serverHandle, command, &ast ) ) { + throwAFSException( env, ast ); } + free( command ); } // reclaim global memory being used by this portion JNIEXPORT void JNICALL -Java_org_openafs_jafs_Server_reclaimServerMemory (JNIEnv *env, jclass cls) { - - if( serverCls ) { - (*env)->DeleteGlobalRef(env, serverCls); - serverCls = 0; +Java_org_openafs_jafs_Server_reclaimServerMemory + (JNIEnv *env, jclass cls) +{ + if ( serverCls ) { + (*env)->DeleteGlobalRef(env, serverCls); + serverCls = 0; } - } - - - - - - - - - - - - - - - - - - - - diff --git a/src/JAVA/libjafs/User.c b/src/JAVA/libjafs/User.c index cf57acbd26..7a32bb65fb 100644 --- a/src/JAVA/libjafs/User.c +++ b/src/JAVA/libjafs/User.c @@ -68,7 +68,6 @@ extern jfieldID user_lockTimeField; extern jfieldID user_lockedUntilField; extern jclass groupCls; -//extern jfieldID group_cellHandleField; extern jfieldID group_nameField; extern jfieldID group_cachedInfoField; @@ -81,140 +80,113 @@ extern jfieldID group_cachedInfoField; * env the Java environment * cls the current Java class * cellHandle the handle of the cell to which the user belongs - * juserName the name of the user to create + * jusername the name of the user to create * jpassword the password for the new user * uid the user id to assign to the user (0 to have one * automatically assigned) */ JNIEXPORT void JNICALL Java_org_openafs_jafs_User_create - (JNIEnv *env, jclass cls, jint cellHandle, jstring juserName, + (JNIEnv *env, jclass cls, jint cellHandle, jstring jusername, jstring jpassword, jint uid ) { afs_status_t ast; - const char *userName; - const char *password; + char *username; + char *password; kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) ); - if( !who ) { + if ( !who ) { throwAFSException( env, JAFSADMNOMEM ); return; } // convert java strings - if( juserName != NULL ) { - userName = (*env)->GetStringUTFChars(env, juserName, 0); - if( !userName ) { + if ( jusername != NULL ) { + username = getNativeString(env, jusername); + if ( username == NULL ) { free( who ); throwAFSException( env, JAFSADMNOMEM ); return; } } else { - userName = NULL; + free( who ); + throwAFSException( env, JAFSNULLUSER ); + return; } - if( jpassword != NULL ) { - password = (*env)->GetStringUTFChars(env, jpassword, 0); - if( !password ) { + + if ( jpassword != NULL ) { + password = getNativeString(env, jpassword); + if ( password == NULL ) { free( who ); - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } + free( username ); throwAFSException( env, JAFSADMNOMEM ); return; } } else { - password = NULL; + free( who ); + free( username ); + throwAFSException( env, JAFSNULLPASS ); + return; } // make sure the name is within the allowed bounds - if( userName != NULL && strlen( userName ) > KAS_MAX_NAME_LEN ) { + if ( strlen( username ) > KAS_MAX_NAME_LEN ) { free( who ); - // release converted java strings - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( password != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpassword, password); - } + free( username ); + free( password ); throwAFSException( env, ADMPTSUSERNAMETOOLONG ); return; } // make sure name doesn't have ":" in it - if( userName != NULL && strchr( userName, ':' ) != (int) NULL ) { - free(who); - // release converted java strings - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( password != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpassword, password); - } - throwAFSException( env, PRBADNAM ); - return; + if ( strchr( username, ':' ) != (int) NULL ) { + free( who ); + free( username ); + free( password ); + throwAFSException( env, PRBADNAM ); + return; } // make sure the id isn't negative - if( uid < 0 ) { - free(who); - // release converted java strings - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( password != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpassword, password); - } - // use the "bad arg" error code even though it's an ID exception. - // There isn't a bad user ID error code - throwAFSException( env, PRBADARG ); - return; + if ( uid < 0 ) { + free( who ); + free( username ); + free( password ); + // use the "bad arg" error code even though it's an ID exception. + // There isn't a bad user ID error code + throwAFSException( env, PRBADARG ); + return; } - if( userName != NULL ) { - internal_makeKasIdentity( userName, who ); + if ( username != NULL ) { + internal_makeKasIdentity( username, who ); } // create the kas entry if (!kas_PrincipalCreate( (void *) cellHandle, NULL, who, password, &ast ) ) { - free(who); - // release converted java strings - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( password != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpassword, password); - } + free( who ); + free( username ); + free( password ); throwAFSException( env, ast ); return; } // create the pts entry - if there's an error, make sure to delete // the kas entry - if( !pts_UserCreate( (void *) cellHandle, userName, (int *) &uid, &ast ) ) { + if ( !pts_UserCreate( (void *) cellHandle, username, (int *) &uid, &ast ) ) { afs_status_t ast_kd; kas_PrincipalDelete( (void *) cellHandle, NULL, who, &ast_kd ); free( who ); - // release converted java strings - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( password != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpassword, password); - } + free( username ); + free( password ); throwAFSException( env, ast ); return; } free( who ); - // release converted java strings - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( password != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpassword, password); - } - + free( username ); + free( password ); } /** @@ -225,81 +197,72 @@ Java_org_openafs_jafs_User_create * env the Java environment * cls the current Java class * cellHandle the handle of the cell to which the user belongs - * juserName the name of the user to delete + * jusername the name of the user to delete */ JNIEXPORT void JNICALL Java_org_openafs_jafs_User_delete - (JNIEnv *env, jclass cls, jint cellHandle, jstring juserName ) + (JNIEnv *env, jclass cls, jint cellHandle, jstring jusername ) { afs_status_t ast; - const char *userName; + char *username; kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) ); int kas; - if( !who ) { + if ( !who ) { throwAFSException( env, JAFSADMNOMEM ); return; } - if( juserName != NULL ) { - userName = (*env)->GetStringUTFChars(env, juserName, 0); - if( !userName ) { + if ( jusername != NULL ) { + username = getNativeString(env, jusername); + if ( username == NULL ) { free( who ); throwAFSException( env, JAFSADMNOMEM ); return; - } + } } else { - userName = NULL; + free( who ); + throwAFSException( env, JAFSNULLUSER ); + return; } // make sure the name is within the allowed bounds - if( userName != NULL && strlen( userName ) > KAS_MAX_NAME_LEN ) { + if ( strlen( username ) > KAS_MAX_NAME_LEN ) { free( who ); - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } + free( username ); throwAFSException( env, ADMPTSUSERNAMETOOLONG ); return; } - if( userName != NULL ) { - internal_makeKasIdentity( userName, who ); - } + internal_makeKasIdentity( username, who ); // delete the kas entry - if( !kas_PrincipalDelete( (void *) cellHandle, NULL, who, &ast ) ) { - if( ast != KANOENT ) { - free(who); - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - throwAFSException( env, ast ); - return; - } else { - kas = FALSE; - } + if ( !kas_PrincipalDelete( (void *) cellHandle, NULL, who, &ast ) ) { + if ( ast != KANOENT ) { + free(who); + free( username ); + throwAFSException( env, ast ); + return; + } else { + kas = FALSE; + } } //delete the pts entry - if( !pts_UserDelete( (void *) cellHandle, userName, &ast ) ) { - // throw exception if there was no such pts user only if there was - // also no such kas user - if( (ast == ADMPTSFAILEDNAMETRANSLATE && !kas ) || - ast != ADMPTSFAILEDNAMETRANSLATE ) { - free( who ); - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - throwAFSException( env, ast ); - return; - } + if ( !pts_UserDelete( (void *) cellHandle, username, &ast ) ) { + // throw exception if there was no such pts user only if there was + // also no such kas user + if ( (ast == ADMPTSFAILEDNAMETRANSLATE && !kas ) || + ast != ADMPTSFAILEDNAMETRANSLATE ) { + free( who ); + free( username ); + throwAFSException( env, ast ); + return; + } } free( who ); - // release converted java strings - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } + free( username ); } /** @@ -308,60 +271,54 @@ Java_org_openafs_jafs_User_delete * env the Java environment * cls the current Java class * cellHandle the handle of the cell to which the user belongs - * juserName the name of the user to unlock + * jusername the name of the user to unlock */ JNIEXPORT void JNICALL Java_org_openafs_jafs_User_unlock - (JNIEnv *env, jclass cls, jint cellHandle, jstring juserName ) + (JNIEnv *env, jclass cls, jint cellHandle, jstring jusername ) { afs_status_t ast; - const char *userName; + char *username; kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) ); - if( !who ) { + if ( !who ) { throwAFSException( env, JAFSADMNOMEM ); return; } // convert java strings - if( juserName != NULL ) { - userName = (*env)->GetStringUTFChars(env, juserName, 0); - if( !userName ) { - throwAFSException( env, JAFSADMNOMEM ); + if ( jusername != NULL ) { + username = getNativeString(env, jusername); + if ( username == NULL ) { + free( who ); + throwAFSException( env, JAFSADMNOMEM ); return; } } else { - userName = NULL; + free( who ); + throwAFSException( env, JAFSNULLUSER ); + return; } // make sure the name is within the allowed bounds - if( userName != NULL && strlen( userName ) > KAS_MAX_NAME_LEN ) { + if ( strlen( username ) > KAS_MAX_NAME_LEN ) { free( who ); - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } + free( username ); throwAFSException( env, ADMPTSUSERNAMETOOLONG ); return; } - if( userName != NULL ) { - internal_makeKasIdentity( userName, who ); - } + internal_makeKasIdentity( username, who ); - if( !kas_PrincipalUnlock( (void *) cellHandle, NULL, who, &ast ) ) { + if ( !kas_PrincipalUnlock( (void *) cellHandle, NULL, who, &ast ) ) { free( who ); - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } + free( username ); throwAFSException( env, ast ); return; } free( who ); - // release converted java strings - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } + free( username ); } /** @@ -388,65 +345,65 @@ void getUserInfoChar kas_principalEntry_t kasEntry; unsigned int lockedUntil; - if( !who ) { + if ( !who ) { throwAFSException( env, JAFSADMNOMEM ); return; } // make sure the name is within the allowed bounds - if( name != NULL && strlen( name ) > KAS_MAX_NAME_LEN ) { + if ( name != NULL && strlen( name ) > KAS_MAX_NAME_LEN ) { free( who ); throwAFSException( env, ADMPTSUSERNAMETOOLONG ); return; } - if( name != NULL ) { - internal_makeKasIdentity( name, who ); + if ( name != NULL ) { + internal_makeKasIdentity( name, who ); } // get all the field ids, if you haven't done so already - if( userCls == 0 ) { + if ( userCls == 0 ) { internal_getUserClass( env, user ); } // get the pts entry if ( !pts_UserGet( (void *) cellHandle, name, &ptsEntry, &ast ) ) { // if the user has no pts ptsEntry - if( ast == ADMPTSFAILEDNAMETRANSLATE ) { + if ( ast == ADMPTSFAILEDNAMETRANSLATE ) { pts = FALSE; } else { - free( who ); + free( who ); throwAFSException( env, ast ); return; } } else { - pts = TRUE; + pts = TRUE; } // get the kas entry - if( !kas_PrincipalGet( (void *) cellHandle, NULL, who, &kasEntry, &ast ) ) { + if ( !kas_PrincipalGet( (void *) cellHandle, NULL, who, &kasEntry, &ast ) ) { // no kas entry - if( ast == KANOENT ) { - if( !pts ) { - free( who ); - throwAFSException( env, ast ); - return; + if ( ast == KANOENT ) { + if ( !pts ) { + free( who ); + throwAFSException( env, ast ); + return; } else { - kas = FALSE; + kas = FALSE; } - // other + // other } else { free( who ); throwAFSException( env, ast ); return; } } else { - kas = TRUE; + kas = TRUE; } // get the lock status - if( kas && !kas_PrincipalLockStatusGet( (void *) cellHandle, NULL, who, + if ( kas && !kas_PrincipalLockStatusGet( (void *) cellHandle, NULL, who, &lockedUntil, &ast ) ) { free( who ); throwAFSException( env, ast ); @@ -457,7 +414,7 @@ void getUserInfoChar (*env)->SetBooleanField(env, user, user_kasField, kas); // set the pts fields - if( pts ) { + if ( pts ) { (*env)->SetIntField(env, user, user_nameUidField, ptsEntry.nameUid); (*env)->SetIntField(env, user, user_ownerUidField, ptsEntry.ownerUid); (*env)->SetIntField(env, user, user_creatorUidField, @@ -467,21 +424,21 @@ void getUserInfoChar (*env)->SetIntField(env, user, user_groupMembershipCountField, ptsEntry.groupMembershipCount); - if( ptsEntry.listStatus == PTS_USER_OWNER_ACCESS ) { + if ( ptsEntry.listStatus == PTS_USER_OWNER_ACCESS ) { (*env)->SetIntField(env, user, user_listStatusField, org_openafs_jafs_User_USER_OWNER_ACCESS); } else { (*env)->SetIntField(env, user, user_listStatusField, org_openafs_jafs_User_USER_ANYUSER_ACCESS); } - if( ptsEntry.listGroupsOwned == PTS_USER_OWNER_ACCESS ) { + if ( ptsEntry.listGroupsOwned == PTS_USER_OWNER_ACCESS ) { (*env)->SetIntField(env, user, user_listGroupsOwnedField, org_openafs_jafs_User_USER_OWNER_ACCESS); } else { (*env)->SetIntField(env, user, user_listGroupsOwnedField, org_openafs_jafs_User_USER_ANYUSER_ACCESS); } - if( ptsEntry.listMembership == PTS_USER_OWNER_ACCESS ) { + if ( ptsEntry.listMembership == PTS_USER_OWNER_ACCESS ) { (*env)->SetIntField(env, user, user_listMembershipField, org_openafs_jafs_User_USER_OWNER_ACCESS); } else { @@ -498,38 +455,38 @@ void getUserInfoChar } // set the kas fields - if( kas ) { + if ( kas ) { char *convertedKey; int i; - if( kasEntry.adminSetting == KAS_ADMIN ) { + if ( kasEntry.adminSetting == KAS_ADMIN ) { (*env)->SetIntField(env, user, user_adminSettingField, org_openafs_jafs_User_ADMIN); } else { (*env)->SetIntField(env, user, user_adminSettingField, org_openafs_jafs_User_NO_ADMIN); } - if( kasEntry.tgsSetting == TGS ) { + if ( kasEntry.tgsSetting == TGS ) { (*env)->SetIntField(env, user, user_tgsSettingField, org_openafs_jafs_User_GRANT_TICKETS); } else { (*env)->SetIntField(env, user, user_tgsSettingField, org_openafs_jafs_User_NO_GRANT_TICKETS); } - if( kasEntry.encSetting != NO_ENCRYPT ) { + if ( kasEntry.encSetting != NO_ENCRYPT ) { (*env)->SetIntField(env, user, user_encSettingField, org_openafs_jafs_User_ENCRYPT); } else { (*env)->SetIntField(env, user, user_encSettingField, org_openafs_jafs_User_NO_ENCRYPT); } - if( kasEntry.cpwSetting == CHANGE_PASSWORD ) { + if ( kasEntry.cpwSetting == CHANGE_PASSWORD ) { (*env)->SetIntField(env, user, user_cpwSettingField, org_openafs_jafs_User_CHANGE_PASSWORD); } else { (*env)->SetIntField(env, user, user_cpwSettingField, org_openafs_jafs_User_NO_CHANGE_PASSWORD); } - if( kasEntry.rpwSetting == REUSE_PASSWORD ) { + if ( kasEntry.rpwSetting == REUSE_PASSWORD ) { (*env)->SetIntField(env, user, user_rpwSettingField, org_openafs_jafs_User_REUSE_PASSWORD); } else { @@ -561,19 +518,20 @@ void getUserInfoChar convertedKey = (char *) malloc( sizeof(char *)* (sizeof(kasEntry.key.key)*4+1) ); - if( !convertedKey ) { - throwAFSException( env, JAFSADMNOMEM ); - return; + if ( !convertedKey ) { + free( who ); + throwAFSException( env, JAFSADMNOMEM ); + return; } for( i = 0; i < sizeof(kasEntry.key.key); i++ ) { - sprintf( &(convertedKey[i*4]), "\\%0.3o", kasEntry.key.key[i] ); + sprintf( &(convertedKey[i*4]), "\\%0.3o", kasEntry.key.key[i] ); } jencryptionKey = (*env)->NewStringUTF(env, convertedKey); (*env)->SetObjectField(env, user, user_encryptionKeyField, - jencryptionKey); + jencryptionKey); free( convertedKey ); } - free(who); + free( who ); } /** @@ -591,31 +549,30 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_User_getUserInfo (JNIEnv *env, jclass cls, jint cellHandle, jstring jname, jobject user) { - const char *name; + char *name; - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( !name ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - name = NULL; + throwAFSException( env, JAFSNULLUSER ); + return; } getUserInfoChar( env, cellHandle, name, user ); // get class fields if need be - if( userCls == 0 ) { + if ( userCls == 0 ) { internal_getUserClass( env, user ); } // set name in case blank object (*env)->SetObjectField(env, user, user_nameField, jname); - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } + free( name ); } /** @@ -633,7 +590,7 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_User_setUserInfo (JNIEnv *env, jclass cls, jint cellHandle, jstring jname, jobject user ) { - const char *name; + char *name; kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) ); pts_UserUpdateEntry_t ptsEntry; afs_status_t ast; @@ -650,137 +607,130 @@ Java_org_openafs_jafs_User_setUserInfo int kas; int pts; - if( !who ) { + if ( !who ) { throwAFSException( env, JAFSADMNOMEM ); return; } - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( name == NULL ) { + free( who ); throwAFSException( env, JAFSADMNOMEM ); return; } } else { - name = NULL; + free( who ); + throwAFSException( env, JAFSNULLUSER ); + return; } // make sure the name is within the allowed bounds - if( name != NULL && strlen( name ) > KAS_MAX_NAME_LEN ) { + if ( strlen( name ) > KAS_MAX_NAME_LEN ) { free( who ); - (*env)->ReleaseStringUTFChars(env, jname, name); + free( name ); throwAFSException( env, ADMPTSUSERNAMETOOLONG ); return; } - if( name != NULL ) { - internal_makeKasIdentity( name, who ); - } + internal_makeKasIdentity( name, who ); // get class fields if need be - if( userCls == 0 ) { + if ( userCls == 0 ) { internal_getUserClass( env, user ); } kas = (*env)->GetBooleanField(env, user, user_kasField); pts = (*env)->GetBooleanField(env, user, user_ptsField); - if( pts ) { - // set the pts fields: - ptsEntry.flag = PTS_USER_UPDATE_GROUP_CREATE_QUOTA | + if ( pts ) { + // set the pts fields: + ptsEntry.flag = PTS_USER_UPDATE_GROUP_CREATE_QUOTA | PTS_USER_UPDATE_PERMISSIONS; - ptsEntry.groupCreationQuota = + ptsEntry.groupCreationQuota = (*env)->GetIntField(env, user, user_groupCreationQuotaField); - if( (*env)->GetIntField(env, user, user_listStatusField) == + if ( (*env)->GetIntField(env, user, user_listStatusField) == org_openafs_jafs_User_USER_OWNER_ACCESS ) { - ptsEntry.listStatus = PTS_USER_OWNER_ACCESS; - } else { - ptsEntry.listStatus = PTS_USER_ANYUSER_ACCESS; - } - if( (*env)->GetIntField(env, user, user_listGroupsOwnedField) == + ptsEntry.listStatus = PTS_USER_OWNER_ACCESS; + } else { + ptsEntry.listStatus = PTS_USER_ANYUSER_ACCESS; + } + if ( (*env)->GetIntField(env, user, user_listGroupsOwnedField) == org_openafs_jafs_User_USER_OWNER_ACCESS ) { - ptsEntry.listGroupsOwned = PTS_USER_OWNER_ACCESS; - } else { - ptsEntry.listGroupsOwned = PTS_USER_ANYUSER_ACCESS; - } - if( (*env)->GetIntField(env, user, user_listMembershipField) == + ptsEntry.listGroupsOwned = PTS_USER_OWNER_ACCESS; + } else { + ptsEntry.listGroupsOwned = PTS_USER_ANYUSER_ACCESS; + } + if ( (*env)->GetIntField(env, user, user_listMembershipField) == org_openafs_jafs_User_USER_OWNER_ACCESS ) { - ptsEntry.listMembership = PTS_USER_OWNER_ACCESS; - } else { - ptsEntry.listMembership = PTS_USER_ANYUSER_ACCESS; - } - if( !pts_UserModify( (void *) cellHandle, name, &ptsEntry, &ast ) ) { - free( who ); - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - throwAFSException( env, ast ); - return; - } + ptsEntry.listMembership = PTS_USER_OWNER_ACCESS; + } else { + ptsEntry.listMembership = PTS_USER_ANYUSER_ACCESS; + } + if ( !pts_UserModify( (void *) cellHandle, name, &ptsEntry, &ast ) ) { + free( who ); + free( name ); + throwAFSException( env, ast ); + return; + } } - if( kas ) { - // set the kas fields: - if( (*env)->GetIntField(env, user, user_adminSettingField) == + if ( kas ) { + // set the kas fields: + if ( (*env)->GetIntField(env, user, user_adminSettingField) == org_openafs_jafs_User_ADMIN ) { - isAdmin = KAS_ADMIN; - } else { - isAdmin = NO_KAS_ADMIN; - } - if( (*env)->GetIntField(env, user, user_tgsSettingField) == + isAdmin = KAS_ADMIN; + } else { + isAdmin = NO_KAS_ADMIN; + } + if ( (*env)->GetIntField(env, user, user_tgsSettingField) == org_openafs_jafs_User_GRANT_TICKETS ) { - grantTickets = TGS; - } else { - grantTickets = NO_TGS; - } - if( (*env)->GetIntField(env, user, user_encSettingField) == + grantTickets = TGS; + } else { + grantTickets = NO_TGS; + } + if ( (*env)->GetIntField(env, user, user_encSettingField) == org_openafs_jafs_User_ENCRYPT ) { - canEncrypt = 0; - } else { - canEncrypt = NO_ENCRYPT; - } - if( (*env)->GetIntField(env, user, user_cpwSettingField) == + canEncrypt = 0; + } else { + canEncrypt = NO_ENCRYPT; + } + if ( (*env)->GetIntField(env, user, user_cpwSettingField) == org_openafs_jafs_User_CHANGE_PASSWORD ) { - canChangePassword = CHANGE_PASSWORD; - } else { - canChangePassword = NO_CHANGE_PASSWORD; - } - if( (*env)->GetIntField(env, user, user_rpwSettingField) == + canChangePassword = CHANGE_PASSWORD; + } else { + canChangePassword = NO_CHANGE_PASSWORD; + } + if ( (*env)->GetIntField(env, user, user_rpwSettingField) == org_openafs_jafs_User_REUSE_PASSWORD ) { - passwordReuse = REUSE_PASSWORD; - } else { - passwordReuse = NO_REUSE_PASSWORD; - } - expirationDate = (*env)->GetIntField(env, user, - user_userExpirationField); - maxTicketLifetime = (*env)->GetIntField(env, user, - user_maxTicketLifetimeField); - passwordExpires = (*env)->GetIntField(env, user, - user_daysToPasswordExpireField); - failedPasswordAttempts = (*env)->GetIntField(env, user, - user_failLoginCountField); - failedPasswordLockTime = (*env)->GetIntField(env, user, - user_lockTimeField); + passwordReuse = REUSE_PASSWORD; + } else { + passwordReuse = NO_REUSE_PASSWORD; + } + expirationDate = (*env)->GetIntField(env, user, + user_userExpirationField); + maxTicketLifetime = (*env)->GetIntField(env, user, + user_maxTicketLifetimeField); + passwordExpires = (*env)->GetIntField(env, user, + user_daysToPasswordExpireField); + failedPasswordAttempts = (*env)->GetIntField(env, user, + user_failLoginCountField); + failedPasswordLockTime = (*env)->GetIntField(env, user, + user_lockTimeField); - if( !kas_PrincipalFieldsSet( (void *) cellHandle, NULL, who, &isAdmin, - &grantTickets, &canEncrypt, - &canChangePassword, &expirationDate, - &maxTicketLifetime, &passwordExpires, - &passwordReuse, &failedPasswordAttempts, - &failedPasswordLockTime, &ast ) ) { - free( who ); - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - throwAFSException( env, ast ); - return; - } + + if ( !kas_PrincipalFieldsSet( (void *) cellHandle, NULL, who, &isAdmin, + &grantTickets, &canEncrypt, + &canChangePassword, &expirationDate, + &maxTicketLifetime, &passwordExpires, + &passwordReuse, &failedPasswordAttempts, + &failedPasswordLockTime, &ast ) ) { + throwAFSException( env, ast ); + } } free( who ); - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } + free( name ); } /** @@ -797,192 +747,154 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_User_rename (JNIEnv *env, jclass cls, jint cellHandle, jstring joldName, jstring jnewName) { + char *oldName; + char *newName; + kas_identity_p whoOld = (kas_identity_p) malloc( sizeof(kas_identity_t) ); + kas_identity_p whoNew = (kas_identity_p) malloc( sizeof(kas_identity_t) ); + kas_principalEntry_t kasEntry; + pts_UserEntry_t ptsEntry; + afs_status_t ast; + int kas; - const char *oldName; - const char *newName; - kas_identity_p whoOld = (kas_identity_p) malloc( sizeof(kas_identity_t) ); - kas_identity_p whoNew = (kas_identity_p) malloc( sizeof(kas_identity_t) ); - kas_principalEntry_t kasEntry; - pts_UserEntry_t ptsEntry; - afs_status_t ast; - int kas; - - if( !whoOld || !whoNew ) { - if( whoOld ) { + if ( !whoOld || !whoNew ) { + if ( whoOld ) { free( whoOld ); - } - if( whoNew ) { + } + if ( whoNew ) { free( whoNew ); - } + } + throwAFSException( env, JAFSADMNOMEM ); + return; + } + + if ( joldName != NULL ) { + oldName = getNativeString(env, joldName); + if ( oldName == NULL ) { + free( whoOld ); + free( whoNew ); throwAFSException( env, JAFSADMNOMEM ); return; } + } else { + oldName = NULL; + } + if ( jnewName != NULL ) { + newName = getNativeString(env, jnewName); + if ( newName == NULL ) { + free( whoOld ); + free( whoNew ); + if ( oldName != NULL ) free ( oldName ); + throwAFSException( env, JAFSADMNOMEM ); + return; + } + } else { + newName = NULL; + } - if( joldName != NULL ) { - oldName = (*env)->GetStringUTFChars(env, joldName, 0); - if( !oldName ) { - throwAFSException( env, JAFSADMNOMEM ); - return; - } - } else { - oldName = NULL; - } - if( jnewName != NULL ) { - newName = (*env)->GetStringUTFChars(env, jnewName, 0); - if( !newName ) { - if( oldName != NULL ) { - (*env)->ReleaseStringUTFChars(env, joldName, oldName); - } - throwAFSException( env, JAFSADMNOMEM ); - return; - } - } else { - newName = NULL; - } - - // make sure the names are within the allowed bounds - if( oldName != NULL && strlen( oldName ) > KAS_MAX_NAME_LEN ) { - free( whoOld ); - free( whoNew ); - if( oldName != NULL ) { - (*env)->ReleaseStringUTFChars(env, joldName, oldName); - } - if( newName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewName, newName); - } - throwAFSException( env, ADMPTSUSERNAMETOOLONG ); - return; - } - if( newName != NULL && strlen( newName ) > KAS_MAX_NAME_LEN ) { - free( whoOld ); - free( whoNew ); - if( oldName != NULL ) { - (*env)->ReleaseStringUTFChars(env, joldName, oldName); - } - if( newName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewName, newName); - } - throwAFSException( env, ADMPTSUSERNAMETOOLONG ); - return; - } - - if( oldName != NULL ) { - internal_makeKasIdentity( oldName, whoOld ); - } - if( newName != NULL ) { - internal_makeKasIdentity( newName, whoNew ); - } - - // retrieve the old kas info - if( !kas_PrincipalGet( (void *) cellHandle, NULL, whoOld, - &kasEntry, &ast ) ) { - if( ast != KANOENT ) { - free( whoOld ); - free( whoNew ); - if( oldName != NULL ) { - (*env)->ReleaseStringUTFChars(env, joldName, oldName); - } - if( newName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewName, newName); - } - throwAFSException( env, ast ); - return; - } else { - kas = FALSE; - } - } else { - kas = TRUE; - } - - if( kas ) { - // create a new kas entry - // temporarily set the password equal to the new name - if (!kas_PrincipalCreate( (void *) cellHandle, NULL, whoNew, - newName, &ast ) ) { - free( whoOld ); - free( whoNew ); - if( oldName != NULL ) { - (*env)->ReleaseStringUTFChars(env, joldName, oldName); - } - if( newName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewName, newName); - } - throwAFSException( env, ast ); - return; - } - - // set the password - ast = 0; - // For some reason kas_PrincipalKeySet doesn't set the return code - // correctly. It always returns 0. - // So instead of checking the return code, we see if there's an - // error in the status variable. - kas_PrincipalKeySet( (void *) cellHandle, NULL, whoNew, 0, - &(kasEntry.key), &ast ); - if( ast ) { - afs_status_t ast_kd; - kas_PrincipalDelete( (void *) cellHandle, NULL, whoNew, &ast_kd ); - free( whoOld ); - free( whoNew ); - if( oldName != NULL ) { - (*env)->ReleaseStringUTFChars(env, joldName, oldName); - } - if( newName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewName, newName); - } - throwAFSException( env, ast ); - return; - } - } - - // rename the pts entry - if( !pts_UserRename( (void *) cellHandle, oldName, newName, &ast ) ) { - // throw exception if there was no such pts user only if - // there was also no such kas user - if( (ast == ADMPTSFAILEDNAMETRANSLATE && !kas ) || - ast != ADMPTSFAILEDNAMETRANSLATE ) { - afs_status_t ast_kd; - if( kas ) { - kas_PrincipalDelete( (void *) cellHandle, NULL, whoNew, - &ast_kd ); - } - free( whoOld ); - free( whoNew ); - if( oldName != NULL ) { - (*env)->ReleaseStringUTFChars(env, joldName, oldName); - } - if( newName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewName, newName); - } - throwAFSException( env, ast ); - return; - } - } - - if( kas ) { - // delete the old kas entry - if( !kas_PrincipalDelete( (void *) cellHandle, NULL, whoOld, &ast ) ) { - free( whoOld ); - free( whoNew ); - if( oldName != NULL ) { - (*env)->ReleaseStringUTFChars(env, joldName, oldName); - } - if( newName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewName, newName); - } - throwAFSException( env, ast ); - return; - } - } - + // make sure the names are within the allowed bounds + if ( (oldName != NULL && strlen( oldName ) > KAS_MAX_NAME_LEN) || + (newName != NULL && strlen( newName ) > KAS_MAX_NAME_LEN) ) + { free( whoOld ); free( whoNew ); - if( oldName != NULL ) { - (*env)->ReleaseStringUTFChars(env, joldName, oldName); + if ( oldName != NULL ) free( oldName ); + if ( newName != NULL ) free( newName ); + throwAFSException( env, ADMPTSUSERNAMETOOLONG ); + return; + } + + if ( oldName != NULL ) { + internal_makeKasIdentity( oldName, whoOld ); + } + if ( newName != NULL ) { + internal_makeKasIdentity( newName, whoNew ); + } + + // retrieve the old kas info + if ( !kas_PrincipalGet( (void *) cellHandle, NULL, whoOld, + &kasEntry, &ast ) ) { + if ( ast != KANOENT ) { + free( whoOld ); + free( whoNew ); + if ( oldName != NULL ) free( oldName ); + if ( newName != NULL ) free( newName ); + throwAFSException( env, ast ); + return; + } else { + kas = FALSE; } - if( newName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewName, newName); + } else { + kas = TRUE; + } + + if ( kas ) { + // create a new kas entry + // temporarily set the password equal to the new name + if (!kas_PrincipalCreate( (void *) cellHandle, NULL, whoNew, + newName, &ast ) ) { + free( whoOld ); + free( whoNew ); + if ( oldName != NULL ) free( oldName ); + if ( newName != NULL ) free( newName ); + throwAFSException( env, ast ); + return; + } + + // set the password + ast = 0; + // For some reason kas_PrincipalKeySet doesn't set the return code + // correctly. It always returns 0. + // So instead of checking the return code, we see if there's an + // error in the status variable. + kas_PrincipalKeySet( (void *) cellHandle, NULL, whoNew, 0, + &(kasEntry.key), &ast ); + if ( ast ) { + afs_status_t ast_kd; + kas_PrincipalDelete( (void *) cellHandle, NULL, whoNew, &ast_kd ); + free( whoOld ); + free( whoNew ); + if ( oldName != NULL ) free( oldName ); + if ( newName != NULL ) free( newName ); + throwAFSException( env, ast ); + return; } + } + + // rename the pts entry + if ( !pts_UserRename( (void *) cellHandle, oldName, newName, &ast ) ) { + // throw exception if there was no such pts user only if + // there was also no such kas user + if ( (ast == ADMPTSFAILEDNAMETRANSLATE && !kas ) || + ast != ADMPTSFAILEDNAMETRANSLATE ) { + afs_status_t ast_kd; + if ( kas ) { + kas_PrincipalDelete( (void *) cellHandle, NULL, whoNew, &ast_kd ); + } + free( whoOld ); + free( whoNew ); + if ( oldName != NULL ) free( oldName ); + if ( newName != NULL ) free( newName ); + throwAFSException( env, ast ); + return; + } + } + + if ( kas ) { + // delete the old kas entry + if ( !kas_PrincipalDelete( (void *) cellHandle, NULL, whoOld, &ast ) ) { + free( whoOld ); + free( whoNew ); + if ( oldName != NULL ) free( oldName ); + if ( newName != NULL ) free( newName ); + throwAFSException( env, ast ); + return; + } + } + + free( whoOld ); + free( whoNew ); + if ( oldName != NULL ) free( oldName ); + if ( newName != NULL ) free( newName ); } /** @@ -991,95 +903,94 @@ Java_org_openafs_jafs_User_rename * env the Java environment * cls the current Java class * cellHandle the handle of the cell to which the user belongs - * juserName the name of the user for which to set the password + * jusername the name of the user for which to set the password * jnewPassword the new password for the user */ JNIEXPORT void JNICALL Java_org_openafs_jafs_User_setPassword - (JNIEnv *env, jclass cls, jint cellHandle, jstring juserName, + (JNIEnv *env, jclass cls, jint cellHandle, jstring jusername, jstring jnewPassword) { afs_status_t ast; char *cellName; - const char *userName; - const char *newPassword; + char *username; + char *newPassword; kas_encryptionKey_p newKey = (kas_encryptionKey_p) malloc( sizeof(kas_encryptionKey_t) ); kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) ); - if( !who || !newKey ) { - if( who ) { + if ( !who || !newKey ) { + if ( who ) { free( who ); } - if( newKey ) { + if ( newKey ) { free( newKey ); } throwAFSException( env, JAFSADMNOMEM ); return; } - if( juserName != NULL ) { - userName = (*env)->GetStringUTFChars(env, juserName, 0); - if( !userName ) { - throwAFSException( env, JAFSADMNOMEM ); - return; - } + if ( jusername != NULL ) { + username = getNativeString(env, jusername); + if ( username == NULL ) { + free( who ); + free( newKey ); + throwAFSException( env, JAFSADMNOMEM ); + return; + } } else { - userName = NULL; + free( who ); + free( newKey ); + throwAFSException( env, JAFSNULLUSER ); + return; } - if( jnewPassword != NULL ) { - newPassword = (*env)->GetStringUTFChars(env, jnewPassword, 0); - if( !newPassword ) { - throwAFSException( env, JAFSADMNOMEM ); - return; - } + + if ( jnewPassword != NULL ) { + newPassword = getNativeString(env, jnewPassword); + if ( newPassword == NULL ) { + free( who ); + free( newKey ); + free( username ); + throwAFSException( env, JAFSADMNOMEM ); + return; + } } else { - newPassword = NULL; + free( who ); + free( newKey ); + free( username ); + throwAFSException( env, JAFSNULLPASS ); + return; } // make sure the name is within the allowed bounds - if( userName != NULL && strlen( userName ) > KAS_MAX_NAME_LEN ) { - free(who); + if ( strlen( username ) > KAS_MAX_NAME_LEN ) { + free( who ); free( newKey ); - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( newPassword != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword); - } + free( username ); + free( newPassword ); throwAFSException( env, ADMPTSUSERNAMETOOLONG ); return; } - if( !afsclient_CellNameGet( (void *) cellHandle, &cellName, &ast ) ) { - free(who); - free( newKey ); - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( newPassword != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword); - } - throwAFSException( env, ast ); - return; + if ( !afsclient_CellNameGet( (void *) cellHandle, &cellName, &ast ) ) { + free( who ); + free( newKey ); + free( username ); + free( newPassword ); + throwAFSException( env, ast ); + return; } - if( !kas_StringToKey( cellName, newPassword, newKey, &ast ) ) { - free(who); - free( newKey ); - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( newPassword != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword); - } - throwAFSException( env, ast ); - return; + if ( !kas_StringToKey( cellName, newPassword, newKey, &ast ) ) { + free( who ); + free( newKey ); + free( username ); + free( newPassword ); + throwAFSException( env, ast ); + return; } - if( userName != NULL ) { - internal_makeKasIdentity( userName, who ); - } + internal_makeKasIdentity( username, who ); ast = 0; // For some reason kas_PrincipalKeySet doesn't set the return code correctly. @@ -1087,28 +998,14 @@ Java_org_openafs_jafs_User_setPassword // So instead of checking the return code, we see if there's an error // in the status variable. kas_PrincipalKeySet( (void *) cellHandle, NULL, who, 0, newKey, &ast ); - if( ast ) { - free( who ); - free( newKey ); - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( newPassword != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword); - } + if ( ast ) { throwAFSException( env, ast ); - return; } free( who ); free( newKey ); - if( userName != NULL ) { - (*env)->ReleaseStringUTFChars(env, juserName, userName); - } - if( newPassword != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword); - } - + free( username ); + free( newPassword ); } /** @@ -1126,35 +1023,29 @@ JNIEXPORT jint JNICALL Java_org_openafs_jafs_User_getUserGroupsBegin (JNIEnv *env, jclass cls, jint cellHandle, jstring jname) { - const char *name; + char *name; afs_status_t ast; void *iterationId; - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { - throwAFSException( env, JAFSADMNOMEM ); - return; - } + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( name == NULL ) { + throwAFSException( env, JAFSADMNOMEM ); + return; + } } else { - name = NULL; + throwAFSException( env, JAFSNULLUSER ); + return; } - if( !pts_UserMemberListBegin( (void *) cellHandle, name, &iterationId, - &ast ) ) { - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - throwAFSException( env, ast ); - return; + if ( !pts_UserMemberListBegin( (void *) cellHandle, name, &iterationId, + &ast ) ) { + throwAFSException( env, ast ); } - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } + free( name ); return (jint) iterationId; - } /** @@ -1174,14 +1065,14 @@ Java_org_openafs_jafs_User_getUserGroupsNextString char *groupName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); jstring jgroup; - if( !groupName ) { + if ( !groupName ) { throwAFSException( env, JAFSADMNOMEM ); return; } - if( !pts_UserMemberListNext( (void *) iterationId, groupName, &ast ) ) { + if ( !pts_UserMemberListNext( (void *) iterationId, groupName, &ast ) ) { free( groupName ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return NULL; } else { throwAFSException( env, ast ); @@ -1217,14 +1108,14 @@ Java_org_openafs_jafs_User_getUserGroupsNext groupName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); - if( !groupName ) { + if ( !groupName ) { throwAFSException( env, JAFSADMNOMEM ); return; } - if( !pts_UserMemberListNext( (void *) iterationId, groupName, &ast ) ) { + if ( !pts_UserMemberListNext( (void *) iterationId, groupName, &ast ) ) { free( groupName ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -1234,7 +1125,7 @@ Java_org_openafs_jafs_User_getUserGroupsNext jgroup = (*env)->NewStringUTF(env, groupName); - if( groupCls == 0 ) { + if ( groupCls == 0 ) { internal_getGroupClass( env, jgroupObject ); } @@ -1261,7 +1152,7 @@ Java_org_openafs_jafs_User_getUserGroupsDone { afs_status_t ast; - if( !pts_UserMemberListDone( (void *) iterationId, &ast ) ) { + if ( !pts_UserMemberListDone( (void *) iterationId, &ast ) ) { throwAFSException( env, ast ); return; } @@ -1292,7 +1183,7 @@ Java_org_openafs_jafs_User_getGroupsOwnedCount groupName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); - if( !groupName ) { + if ( !groupName ) { throwAFSException( env, JAFSADMNOMEM ); return -1; } @@ -1302,7 +1193,7 @@ Java_org_openafs_jafs_User_getGroupsOwnedCount free( groupName ); - if( ast != ADMITERATORDONE ) { + if ( ast != ADMITERATORDONE ) { throwAFSException( env, ast ); return -1; } @@ -1325,35 +1216,29 @@ JNIEXPORT jint JNICALL Java_org_openafs_jafs_User_getGroupsOwnedBegin (JNIEnv *env, jclass cls, jint cellHandle, jstring jname) { - const char *name; + char *name; afs_status_t ast; void *iterationId; - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { - throwAFSException( env, JAFSADMNOMEM ); - return; - } + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( name == NULL ) { + throwAFSException( env, JAFSADMNOMEM ); + return -1; + } } else { - name = NULL; + throwAFSException( env, JAFSNULLUSER ); + return -1; } - if( !pts_OwnedGroupListBegin( (void *) cellHandle, name, - &iterationId, &ast ) ) { - if( jname != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } - throwAFSException( env, ast ); - return; + if ( !pts_OwnedGroupListBegin( (void *) cellHandle, name, + &iterationId, &ast ) ) { + throwAFSException( env, ast ); } - if( jname != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } + free( name ); return (jint) iterationId; - } /** @@ -1373,18 +1258,18 @@ Java_org_openafs_jafs_User_getGroupsOwnedNextString char *groupName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); jstring jgroup; - if( !groupName ) { + if ( !groupName ) { throwAFSException( env, JAFSADMNOMEM ); return; } - if( !pts_OwnedGroupListNext( (void *) iterationId, groupName, &ast ) ) { + if ( !pts_OwnedGroupListNext( (void *) iterationId, groupName, &ast ) ) { free( groupName ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return NULL; } else { throwAFSException( env, ast ); - return; + return NULL; } } @@ -1417,14 +1302,14 @@ Java_org_openafs_jafs_User_getGroupsOwnedNext groupName = (char *) malloc( sizeof(char)*PTS_MAX_NAME_LEN); - if( !groupName ) { + if ( !groupName ) { throwAFSException( env, JAFSADMNOMEM ); - return; + return 0; } - if( !pts_OwnedGroupListNext( (void *) iterationId, groupName, &ast ) ) { + if ( !pts_OwnedGroupListNext( (void *) iterationId, groupName, &ast ) ) { free( groupName ); - if( ast == ADMITERATORDONE ) { + if ( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); @@ -1434,7 +1319,7 @@ Java_org_openafs_jafs_User_getGroupsOwnedNext jgroup = (*env)->NewStringUTF(env, groupName); - if( groupCls == 0 ) { + if ( groupCls == 0 ) { internal_getGroupClass( env, jgroupObject ); } @@ -1461,11 +1346,10 @@ Java_org_openafs_jafs_User_getGroupsOwnedDone { afs_status_t ast; - if( !pts_OwnedGroupListDone( (void *) iterationId, &ast ) ) { + if ( !pts_OwnedGroupListDone( (void *) iterationId, &ast ) ) { throwAFSException( env, ast ); return; } - } // reclaim global memory being used by this portion @@ -1473,12 +1357,8 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_User_reclaimUserMemory (JNIEnv *env, jclass cls) { - if( userCls ) { - (*env)->DeleteGlobalRef(env, userCls); - userCls = 0; + if ( userCls ) { + (*env)->DeleteGlobalRef(env, userCls); + userCls = 0; } - } - - - diff --git a/src/JAVA/libjafs/UserToken.c b/src/JAVA/libjafs/UserToken.c index 86a91d2324..e8395a4ec7 100644 --- a/src/JAVA/libjafs/UserToken.c +++ b/src/JAVA/libjafs/UserToken.c @@ -19,6 +19,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include + #include "Internal.h" #include "org_openafs_jafs_Token.h" @@ -27,8 +29,8 @@ #include #include #include -#include -#include +/*#include + #include */ #include #ifdef DMALLOC @@ -36,7 +38,9 @@ #endif pthread_mutex_t jafs_init_lock; + extern pthread_mutex_t jafs_login_lock; + extern int readCacheParms(char *afsMountPoint, char *afsConfDir, char *afsCacheDir, int *cacheBlocks, int *cacheFiles, int *cacheStatEntries, @@ -47,7 +51,7 @@ extern int readCacheParms(char *afsMountPoint, char *afsConfDir, /** * Be carefull with the memory management: * - * - For every GetStringUTFChars call the corresponding ReleaseStringUTFChars. + * - For every getNativeString call the corresponding free(). * - For every GetArrayElements call the corresponding * ReleaseArrayElements * - For every malloc call the corresponding free. @@ -167,45 +171,48 @@ Java_org_openafs_jafs_Token_klog (JNIEnv *env, jobject obj, char *password; char *cell; char *reason; - jint rc = -1; - int code; + int code; + jint rc = -1; - if( jcell != NULL ) { - cell = (char*) (*env)->GetStringUTFChars(env, jcell, 0); - if( !cell ) { - char *error = "UserToken::klog(): failed to get cell name\n"; - fprintf(stderr, error); - throwMessageException( env, error ); + if ( jcell != NULL ) { + cell = getNativeString(env, jcell); + if ( !cell ) { + fprintf(stderr, "UserToken::klog(): failed to get cell name\n"); + throwMessageException( env, "Internal error, failed to translate cell name." ); return -1; } } else { cell = NULL; } - if( jusername != NULL ) { - username = (char*) (*env)->GetStringUTFChars(env, jusername, 0); - if( !username ) { - char *error = "UserToken::klog(): failed to get username\n"; - (*env)->ReleaseStringUTFChars(env, jcell, cell); - fprintf(stderr, error); - throwMessageException( env, error ); + if ( jusername != NULL ) { + username = getNativeString(env, jusername); + if ( !username ) { + if ( cell != NULL ) free( cell ); + fprintf(stderr, "UserToken::klog(): failed to get username\n"); + throwMessageException( env, "Internal error, failed to translate username." ); return -1; } } else { - username = NULL; + if ( cell != NULL ) free( cell ); + throwAFSException( env, JAFSNULLUSER ); + return -1; } - if( jpassword != NULL ) { - password = (char*) (*env)->GetStringUTFChars(env, jpassword, 0); - if( !password ) { - char *error = "UserToken::klog(): failed to get password\n"; - (*env)->ReleaseStringUTFChars(env, jcell, cell); - (*env)->ReleaseStringUTFChars(env, jusername, username); - fprintf(stderr, error); - throwMessageException( env, error ); + + if ( jpassword != NULL ) { + password = getNativeString(env, jpassword); + if ( !password ) { + if ( cell != NULL ) free( cell ); + free( username ); + fprintf(stderr, "UserToken::klog(): failed to get password\n"); + throwMessageException( env, "Internal error, failed to translate password." ); return -1; } } else { - password = NULL; + if ( cell != NULL ) free( cell ); + free( username ); + throwAFSException( env, JAFSNULLPASS ); + return -1; } if (id == 0) { @@ -218,34 +225,23 @@ Java_org_openafs_jafs_Token_klog (JNIEnv *env, jobject obj, } if (code != 0) { - if( cell != NULL ) { - (*env)->ReleaseStringUTFChars(env, jcell, cell); - } - if( username != NULL ) { - (*env)->ReleaseStringUTFChars(env, jusername, username); - } - if( password != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpassword, password); - } + if ( cell != NULL ) free( cell ); + if ( username != NULL ) free( username ); + if ( password != NULL ) free( password ); fprintf(stderr, "UserToken::klog(): uafs_klog failed to cell %s: %s\n", cell, reason); fprintf(stderr, "code = %d\n", code); throwAFSException( env, code ); + return -1; } /* Get the PAG we were assigned as the return value */ rc = afs_getpag_val(); /* clean up */ - if( cell != NULL ) { - (*env)->ReleaseStringUTFChars(env, jcell, cell); - } - if( username != NULL ) { - (*env)->ReleaseStringUTFChars(env, jusername, username); - } - if( password != NULL ) { - (*env)->ReleaseStringUTFChars(env, jpassword, password); - } + if ( cell != NULL ) free( cell ); + if ( username != NULL ) free( username ); + if ( password != NULL ) free( password ); /* return PAG ID */ return rc; @@ -315,7 +311,3 @@ JNIEXPORT void JNICALL Java_org_openafs_jafs_Token_shutdown { uafs_Shutdown(); } - - - - diff --git a/src/JAVA/libjafs/Volume.c b/src/JAVA/libjafs/Volume.c index de687b24cb..4cf74af54f 100644 --- a/src/JAVA/libjafs/Volume.c +++ b/src/JAVA/libjafs/Volume.c @@ -56,13 +56,13 @@ extern jfieldID volume_typeField; * volume the Volume object to populate with the info * volEntry the container of the volume's information */ -extern void fillVolumeInfo( JNIEnv *env, jobject volume, - vos_volumeEntry_t volEntry ) { - +extern void fillVolumeInfo + ( JNIEnv *env, jobject volume, vos_volumeEntry_t volEntry ) +{ jstring jvolume; // get the class fields if need be - if( volumeCls == 0 ) { + if ( volumeCls == 0 ) { internal_getVolumeClass( env, volume ); } @@ -236,12 +236,10 @@ extern void fillVolumeInfo( JNIEnv *env, jobject volume, * the information */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Volume_getVolumeInfo (JNIEnv *env, jclass cls, - jint cellHandle, - jint serverHandle, - jint partition, jint volID, - jobject jvolumeObject) { - +Java_org_openafs_jafs_Volume_getVolumeInfo + (JNIEnv *env, jclass cls, jint cellHandle, jint serverHandle, jint partition, + jint volID, jobject jvolumeObject) +{ afs_status_t ast; vos_volumeEntry_t volEntry; @@ -254,7 +252,6 @@ Java_org_openafs_jafs_Volume_getVolumeInfo (JNIEnv *env, jclass cls, } fillVolumeInfo( env, jvolumeObject, volEntry ); - } /** @@ -272,40 +269,34 @@ Java_org_openafs_jafs_Volume_getVolumeInfo (JNIEnv *env, jclass cls, * returns the numeric ID assigned to the volume */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Volume_create (JNIEnv *env, jclass cls, - jint cellHandle, jint serverHandle, - jint partition, jstring jvolName, - jint quota) { - +Java_org_openafs_jafs_Volume_create + (JNIEnv *env, jclass cls, jint cellHandle, jint serverHandle, + jint partition, jstring jvolName, jint quota) +{ afs_status_t ast; - const char *volName; + char *volName; int id; - if( jvolName != NULL ) { - volName = (*env)->GetStringUTFChars(env, jvolName, 0); - if( !volName ) { + if ( jvolName != NULL ) { + volName = getNativeString(env, jvolName); + if ( !volName ) { throwAFSException( env, JAFSADMNOMEM ); - return; + return -1; } } else { - volName = NULL; + throwAFSException( env, JAFSNULLVOLUME ); + return -1; } - if( !vos_VolumeCreate( (void *) cellHandle, (void *) serverHandle, NULL, + if ( !vos_VolumeCreate( (void *) cellHandle, (void *) serverHandle, NULL, (unsigned int) partition, volName, (unsigned int) quota, &id, &ast ) ) { - if( volName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jvolName, volName); - } throwAFSException( env, ast ); - return; } - if( volName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jvolName, volName); - } + free( volName ); + return (jint) id; - } /** @@ -321,19 +312,18 @@ Java_org_openafs_jafs_Volume_create (JNIEnv *env, jclass cls, * volId the numeric id of the volume to delete */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Volume_delete (JNIEnv *env, jclass cls, - jint cellHandle, jint serverHandle, - jint partition, jint volID) { - +Java_org_openafs_jafs_Volume_delete + (JNIEnv *env, jclass cls, jint cellHandle, jint serverHandle, + jint partition, jint volID) +{ afs_status_t ast; - if( !vos_VolumeDelete( (void *) cellHandle, (void *) serverHandle, NULL, + if ( !vos_VolumeDelete( (void *) cellHandle, (void *) serverHandle, NULL, (unsigned int) partition, (unsigned int) volID, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -346,18 +336,16 @@ Java_org_openafs_jafs_Volume_delete (JNIEnv *env, jclass cls, * volume */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Volume_createBackupVolume (JNIEnv *env, jclass cls, - jint cellHandle, - jint volID) { - +Java_org_openafs_jafs_Volume_createBackupVolume + (JNIEnv *env, jclass cls, jint cellHandle, jint volID) +{ afs_status_t ast; - if( !vos_BackupVolumeCreate( (void *) cellHandle, NULL, + if ( !vos_BackupVolumeCreate( (void *) cellHandle, NULL, (unsigned int) volID, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -374,21 +362,18 @@ Java_org_openafs_jafs_Volume_createBackupVolume (JNIEnv *env, jclass cls, * create a read-only volume */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Volume_createReadOnlyVolume (JNIEnv *env, jclass cls, - jint cellHandle, - jint serverHandle, - jint partition, - jint volID) { - +Java_org_openafs_jafs_Volume_createReadOnlyVolume + (JNIEnv *env, jclass cls, jint cellHandle, jint serverHandle, jint partition, + jint volID) +{ afs_status_t ast; - if( !vos_VLDBReadOnlySiteCreate( (void *) cellHandle, (void *) serverHandle, + if ( !vos_VLDBReadOnlySiteCreate( (void *) cellHandle, (void *) serverHandle, NULL, (unsigned int) partition, (unsigned int) volID, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -405,21 +390,18 @@ Java_org_openafs_jafs_Volume_createReadOnlyVolume (JNIEnv *env, jclass cls, * delete the read-only volume */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Volume_deleteReadOnlyVolume (JNIEnv *env, jclass cls, - jint cellHandle, - jint serverHandle, - jint partition, - jint volID) { - +Java_org_openafs_jafs_Volume_deleteReadOnlyVolume + (JNIEnv *env, jclass cls, jint cellHandle, jint serverHandle, jint partition, + jint volID) +{ afs_status_t ast; - if( !vos_VLDBReadOnlySiteDelete( (void *) cellHandle, (void *) serverHandle, + if ( !vos_VLDBReadOnlySiteDelete( (void *) cellHandle, (void *) serverHandle, NULL, (unsigned int) partition, (unsigned int) volID, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -436,22 +418,19 @@ Java_org_openafs_jafs_Volume_deleteReadOnlyVolume (JNIEnv *env, jclass cls, * newQuota the new quota (in KB) to assign the volume */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Volume_changeQuota (JNIEnv *env, jclass cls, - jint cellHandle, - jint serverHandle, - jint partition, jint volID, - jint newQuota) { - +Java_org_openafs_jafs_Volume_changeQuota + (JNIEnv *env, jclass cls, jint cellHandle, jint serverHandle, jint partition, + jint volID, jint newQuota) +{ afs_status_t ast; - if( !vos_VolumeQuotaChange( (void *) cellHandle, (void *) serverHandle, + if ( !vos_VolumeQuotaChange( (void *) cellHandle, (void *) serverHandle, NULL, (unsigned int) partition, (unsigned int) volID, (unsigned int) newQuota, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -477,14 +456,13 @@ Java_org_openafs_jafs_Volume_move { afs_status_t ast; - if( !vos_VolumeMove( (void *) cellHandle, NULL, (unsigned int) volID, + if ( !vos_VolumeMove( (void *) cellHandle, NULL, (unsigned int) volID, (void *) fromServerHandle, (unsigned int) fromPartition, (void *) toServerHandle, (unsigned int) toPartition, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -503,18 +481,17 @@ Java_org_openafs_jafs_Volume_release afs_status_t ast; vos_force_t force; - if( forceComplete ) { + if ( forceComplete ) { force = VOS_FORCE; } else { force = VOS_NORMAL; } - if( !vos_VolumeRelease( (void *) cellHandle, NULL, (unsigned int) volID, + if ( !vos_VolumeRelease( (void *) cellHandle, NULL, (unsigned int) volID, force, &ast )) { throwAFSException( env, ast ); return; } - } /** @@ -533,38 +510,31 @@ Java_org_openafs_jafs_Volume_release * jdumpFile the full path of the file to which to dump */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Volume_dump (JNIEnv *env, jclass cls, - jint cellHandle, jint serverHandle, - jint partition, jint volID, - jint startTime, jstring jdumpFile) { - +Java_org_openafs_jafs_Volume_dump + (JNIEnv *env, jclass cls, jint cellHandle, jint serverHandle, jint partition, + jint volID, jint startTime, jstring jdumpFile) +{ afs_status_t ast; - const char *dumpFile; + char *dumpFile; - if( jdumpFile != NULL ) { - dumpFile = (*env)->GetStringUTFChars(env, jdumpFile, 0); - if( !dumpFile ) { + if ( jdumpFile != NULL ) { + dumpFile = getNativeString(env, jdumpFile); + if ( !dumpFile ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - dumpFile = NULL; - } - - if( !vos_VolumeDump( (void *) cellHandle, (void *) serverHandle, NULL, - (unsigned int *) &partition, (unsigned int) volID, - (unsigned int) startTime, dumpFile, &ast ) ) { - if( dumpFile != NULL ) { - (*env)->ReleaseStringUTFChars(env, jdumpFile, dumpFile); - } - throwAFSException( env, ast ); + throwAFSException( env, JAFSNULLARG ); return; } - if( dumpFile != NULL ) { - (*env)->ReleaseStringUTFChars(env, jdumpFile, dumpFile); + if ( !vos_VolumeDump( (void *) cellHandle, (void *) serverHandle, NULL, + (unsigned int *) &partition, (unsigned int) volID, + (unsigned int) startTime, dumpFile, &ast ) ) { + throwAFSException( env, ast ); } + free( dumpFile ); } /** @@ -586,34 +556,31 @@ Java_org_openafs_jafs_Volume_dump (JNIEnv *env, jclass cls, * otherwise restores a full dump */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Volume_restore (JNIEnv *env, jclass cls, - jint cellHandle, jint serverHandle, - jint partition, jint volID, - jstring jvolName, jstring jdumpFile, - jboolean incremental) { - +Java_org_openafs_jafs_Volume_restore + (JNIEnv *env, jclass cls, jint cellHandle, jint serverHandle, jint partition, + jint volID, jstring jvolName, jstring jdumpFile, jboolean incremental) +{ afs_status_t ast; - const char *volName; - const char *dumpFile; - int *volumeIDp; + char *volName; + char *dumpFile; + int *volumeIDp; vos_volumeRestoreType_t vrt; - if( jvolName != NULL ) { - volName = (*env)->GetStringUTFChars(env, jvolName, 0); - if( !volName ) { + if ( jvolName != NULL ) { + volName = getNativeString(env, jvolName); + if ( !volName ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - volName = NULL; + throwAFSException( env, JAFSNULLVOLUME ); + return; } - if( jdumpFile != NULL ) { - dumpFile = (*env)->GetStringUTFChars(env, jdumpFile, 0); - if( !dumpFile ) { - if( volName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jvolName, volName); - } + if ( jdumpFile != NULL ) { + dumpFile = getNativeString(env, jdumpFile); + if ( !dumpFile ) { + free( volName ); throwAFSException( env, JAFSADMNOMEM ); return; } @@ -621,38 +588,26 @@ Java_org_openafs_jafs_Volume_restore (JNIEnv *env, jclass cls, dumpFile = NULL; } - if( volID == 0 ) { + if ( volID == 0 ) { volumeIDp = NULL; } else { volumeIDp = (int *) &volID; } - if( incremental ) { + if ( incremental ) { vrt = VOS_RESTORE_INCREMENTAL; } else { vrt = VOS_RESTORE_FULL; } - if( !vos_VolumeRestore( (void *) cellHandle, (void *) serverHandle, NULL, + if ( !vos_VolumeRestore( (void *) cellHandle, (void *) serverHandle, NULL, (unsigned int) partition, (unsigned int *) volumeIDp, volName, dumpFile, vrt, &ast ) ) { - if( volName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jvolName, volName); - } - if( dumpFile != NULL ) { - (*env)->ReleaseStringUTFChars(env, jdumpFile, dumpFile); - } throwAFSException( env, ast ); - return; - } - - if( dumpFile != NULL ) { - (*env)->ReleaseStringUTFChars(env, jdumpFile, dumpFile); - } - if( volName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jvolName, volName); } + if ( dumpFile != NULL ) free( dumpFile ); + free( volName ); } /** @@ -665,36 +620,29 @@ Java_org_openafs_jafs_Volume_restore (JNIEnv *env, jclass cls, * jnewName the new name for the volume */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Volume_rename (JNIEnv *env, jclass cls, - jint cellHandle, jint volID, - jstring jnewName) { - +Java_org_openafs_jafs_Volume_rename + (JNIEnv *env, jclass cls, jint cellHandle, jint volID, jstring jnewName) +{ afs_status_t ast; - const char *newName; + char *newName; - if( jnewName != NULL ) { - newName = (*env)->GetStringUTFChars(env, jnewName, 0); - if( !newName ) { + if ( jnewName != NULL ) { + newName = getNativeString(env, jnewName); + if ( !newName ) { throwAFSException( env, JAFSADMNOMEM ); return; } } else { - newName = NULL; - } - - if( !vos_VolumeRename( (void *) cellHandle, NULL, (unsigned int) volID, - newName, &ast ) ) { - if( newName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewName, newName); - } - throwAFSException( env, ast ); + throwAFSException( env, JAFSNULLVOLUME ); return; } - if( newName != NULL ) { - (*env)->ReleaseStringUTFChars(env, jnewName, newName); + if ( !vos_VolumeRename( (void *) cellHandle, NULL, (unsigned int) volID, + newName, &ast ) ) { + throwAFSException( env, ast ); } + free( newName ); } /** @@ -713,27 +661,25 @@ Java_org_openafs_jafs_Volume_rename (JNIEnv *env, jclass cls, * status of the volume -- busy or offline) */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Volume_mount (JNIEnv *env, jclass cls, - jint serverHandle, jint partition, - jint volID, jint sleepTime, - jboolean offline) { - +Java_org_openafs_jafs_Volume_mount + (JNIEnv *env, jclass cls, jint serverHandle, jint partition, jint volID, + jint sleepTime, jboolean offline) +{ afs_status_t ast; vos_volumeOnlineType_t volumeStatus; - if( offline ) { + if ( offline ) { volumeStatus = VOS_ONLINE_OFFLINE; } else { volumeStatus = VOS_ONLINE_BUSY; } - if( !vos_VolumeOnline( (void *) serverHandle, NULL, (unsigned int) partition, + if ( !vos_VolumeOnline( (void *) serverHandle, NULL, (unsigned int) partition, (unsigned int) volID, (unsigned int) sleepTime, volumeStatus, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -748,19 +694,17 @@ Java_org_openafs_jafs_Volume_mount (JNIEnv *env, jclass cls, * volId the numeric id of the volume to bring offline */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Volume_unmount (JNIEnv *env, jclass cls, - jint serverHandle, jint partition, - jint volID) { - +Java_org_openafs_jafs_Volume_unmount + (JNIEnv *env, jclass cls, jint serverHandle, jint partition, jint volID) +{ afs_status_t ast; - if( !vos_VolumeOffline( (void *) serverHandle, NULL, + if ( !vos_VolumeOffline( (void *) serverHandle, NULL, (unsigned int) partition, (unsigned int) volID, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -772,17 +716,16 @@ Java_org_openafs_jafs_Volume_unmount (JNIEnv *env, jclass cls, * volId the numeric id of the volume to lock */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Volume_lock (JNIEnv *env, jclass cls, - jint cellHandle, jint volID ) { - +Java_org_openafs_jafs_Volume_lock + (JNIEnv *env, jclass cls, jint cellHandle, jint volID ) +{ afs_status_t ast; - if( !vos_VLDBEntryLock( (void *) cellHandle, NULL, (unsigned int) volID, + if ( !vos_VLDBEntryLock( (void *) cellHandle, NULL, (unsigned int) volID, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -794,17 +737,16 @@ Java_org_openafs_jafs_Volume_lock (JNIEnv *env, jclass cls, * volId the numeric id of the volume to unlock */ JNIEXPORT void JNICALL -Java_org_openafs_jafs_Volume_unlock (JNIEnv *env, jclass cls, - jint cellHandle, jint volID) { - +Java_org_openafs_jafs_Volume_unlock + (JNIEnv *env, jclass cls, jint cellHandle, jint volID) +{ afs_status_t ast; - if( !vos_VLDBEntryUnlock( (void *) cellHandle, NULL, (unsigned int) volID, + if ( !vos_VLDBEntryUnlock( (void *) cellHandle, NULL, (unsigned int) volID, &ast ) ) { throwAFSException( env, ast ); return; } - } /** @@ -823,41 +765,37 @@ Java_org_openafs_jafs_Volume_unlock (JNIEnv *env, jclass cls, * returns the id of the volume in question */ JNIEXPORT jint JNICALL -Java_org_openafs_jafs_Volume_translateNameToID (JNIEnv *env, jclass cls, - jint cellHandle, - jstring jname, jint type) { - +Java_org_openafs_jafs_Volume_translateNameToID + (JNIEnv *env, jclass cls, jint cellHandle, jstring jname, jint type) +{ afs_status_t ast; - const char *name; + char *name; vos_vldbEntry_t vldbEntry; - if( jname != NULL ) { - name = (*env)->GetStringUTFChars(env, jname, 0); - if( !name ) { + if ( jname != NULL ) { + name = getNativeString(env, jname); + if ( !name ) { throwAFSException( env, JAFSADMNOMEM ); - return; - } + return -1; + } } else { - name = NULL; + throwAFSException( env, JAFSNULLVOLUME ); + return -1; } // get the id - if( !vos_VLDBGet( (void *) cellHandle, NULL, NULL, name, + if ( !vos_VLDBGet( (void *) cellHandle, NULL, NULL, name, &vldbEntry, &ast ) ) { - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } + free( name ); throwAFSException( env, ast ); return -1; } - if( name != NULL ) { - (*env)->ReleaseStringUTFChars(env, jname, name); - } + free( name ); - if( type == org_openafs_jafs_Volume_VOLUME_TYPE_READ_WRITE ) { + if ( type == org_openafs_jafs_Volume_VOLUME_TYPE_READ_WRITE ) { return vldbEntry.volumeId[VOS_READ_WRITE_VOLUME]; - } else if( type == org_openafs_jafs_Volume_VOLUME_TYPE_READ_ONLY ) { + } else if ( type == org_openafs_jafs_Volume_VOLUME_TYPE_READ_ONLY ) { return vldbEntry.volumeId[VOS_READ_ONLY_VOLUME]; } else { return vldbEntry.volumeId[VOS_BACKUP_VOLUME]; @@ -868,34 +806,11 @@ Java_org_openafs_jafs_Volume_translateNameToID (JNIEnv *env, jclass cls, // reclaim global memory being used by this portion JNIEXPORT void JNICALL -Java_org_openafs_jafs_Volume_reclaimVolumeMemory (JNIEnv *env, jclass cls) { - - if( volumeCls ) { - (*env)->DeleteGlobalRef(env, volumeCls); - volumeCls = 0; +Java_org_openafs_jafs_Volume_reclaimVolumeMemory + (JNIEnv *env, jclass cls) +{ + if ( volumeCls ) { + (*env)->DeleteGlobalRef(env, volumeCls); + volumeCls = 0; } - } - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/afs/UKERNEL/afs_usrops.c b/src/afs/UKERNEL/afs_usrops.c index 210badacf6..5c5367692a 100644 --- a/src/afs/UKERNEL/afs_usrops.c +++ b/src/afs/UKERNEL/afs_usrops.c @@ -1581,10 +1581,14 @@ void uafs_Init( } else { if (afsd_verbose) - printf("%s: My home cell is '%s'\n", - rn, afs_LclCellName); + printf("%s: My home cell is '%s'\n", rn, afs_LclCellName); } + /* + * Set the primary cell name. + */ + call_syscall(AFSOP_SET_THISCELL, afs_LclCellName, 0, 0, 0, 0); + if ((logfd = fopen(fullpn_AFSLogFile,"r+")) == 0) { if (afsd_verbose) printf("%s: Creating '%s'\n", rn, fullpn_AFSLogFile); if (CreateCacheFile(fullpn_AFSLogFile)) { @@ -1657,6 +1661,10 @@ void uafs_Init( preallocs = cacheStatEntries+50; fork_syscall(AFSCALL_CALL, AFSOP_START_RXCALLBACK, preallocs); + if (afsd_verbose) + printf("%s: Initializing AFS daemon.\n", rn); + fork_syscall(AFSCALL_CALL, AFSOP_BASIC_INIT); + if (afsd_verbose) printf("%s: Forking AFS daemon.\n", rn); fork_syscall(AFSCALL_CALL, AFSOP_START_AFS); diff --git a/src/afs/afs_cell.c b/src/afs/afs_cell.c index f90c1cf947..595d4b5465 100644 --- a/src/afs/afs_cell.c +++ b/src/afs/afs_cell.c @@ -488,7 +488,15 @@ static void *afs_TraverseCells_nl(void *(*cb)(struct cell *, void *), void *arg) void *ret = NULL; for (cq = CellLRU.next; cq != &CellLRU; cq = tq) { - tc = QTOC(cq); tq = QNext(cq); + tc = QTOC(cq); + + /* This is assuming that a NULL return is acceptable. */ + if (cq) { + tq = QNext(cq); + } else { + return NULL; + } + ret = cb(tc, arg); if (ret) break; } @@ -509,7 +517,12 @@ void *afs_TraverseCells(void *(*cb)(struct cell *, void *), void *arg) static void *afs_choose_cell_by_name(struct cell *cell, void *arg) { - return strcmp(cell->cellName, (char *) arg) ? NULL : cell; + if ( !arg ) { + /* Safety net */ + return cell; + } else { + return strcmp(cell->cellName, (char *) arg) ? NULL : cell; + } } static void *afs_choose_cell_by_num(struct cell *cell, void *arg) @@ -597,7 +610,18 @@ struct cell *afs_GetPrimaryCell(afs_int32 locktype) int afs_IsPrimaryCell(struct cell *cell) { - return strcmp(cell->cellName, afs_thiscell) ? 0 : 1; + /* Simple safe checking */ + if (!cell) { + return 0; + } else if ( !afs_thiscell ) { + /* This is simply a safety net to avoid seg faults especially when + * using a user-space library. afs_SetPrimaryCell() should be set + * prior to this call. */ + afs_SetPrimaryCell( cell->cellName ); + return 1; + } else { + return strcmp(cell->cellName, afs_thiscell) ? 0 : 1; + } } int afs_IsPrimaryCellNum(afs_int32 cellnum) diff --git a/src/libuafs/README b/src/libuafs/README index c096c3b358..ca345809ec 100644 --- a/src/libuafs/README +++ b/src/libuafs/README @@ -5,7 +5,7 @@ This software has been released under the terms of the IBM Public License. For details, see the LICENSE file in the top-level source directory or online at http://www.openafs.org/dl/license10.html. -README file for libuafs and libjuafs, Version 1.0 05/13/2002. +README file for libuafs and libjuafs, Version 1.2 06/04/2003. ### INTRODUCTION ### @@ -77,7 +77,5 @@ contains output files respective to libjuafs.a. ### CONSIDERATIONS ### -The libjuafs.a library has only been tested using RedHat Linux 7.1 and -OpenAFS 1.2.3 and OpenAFS 1.2.4. - - +The libjuafs.a library has only been tested using RedHat Linux 7.3 and +OpenAFS 1.2.6, OpenAFS 1.2.7, OpenAFS 1.2.8, and OpenAFS 1.2.9.